Skip to content

Commit

Permalink
Native notifications
Browse files Browse the repository at this point in the history
Fix gen_assets
  • Loading branch information
Sylvaner committed Jan 24, 2020
1 parent b872afa commit 4663e85
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 125 deletions.
1 change: 0 additions & 1 deletion assets/config/default.config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ developer::exceptionhandler = 0

;Notification
notify::status = 1
notify::position = bottomCenter
notify::timeout = 5

;Api
Expand Down
1 change: 0 additions & 1 deletion assets/config/dist/default.config.ini.dev
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ developer::exceptionhandler = 1

;Notification
notify::status = 1
notify::position = bottomCenter
notify::timeout = 5

;Api
Expand Down
1 change: 0 additions & 1 deletion assets/config/dist/default.config.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ developer::exceptionhandler = 0

;Notification
notify::status = 1
notify::position = bottomCenter
notify::timeout = 5

;Api
Expand Down
Binary file added assets/img/icon-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 48 additions & 87 deletions assets/js/desktop/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,94 +58,56 @@ jQuery.fn.findAtDepth = function (selector, maxDepth) {
};

/**
* Floating notification
*
* @param _title title of the notification
* @param _text text of the notification
* @param _class_name equivalent to the color of notification (success, warning, error, nextdom color)
* Show notification
* @param title Title of the notification
* @param message Message of the notification
* @param type Type of notification (success, error)
*/
function notify(_title, _text, _class_name) {
if (typeof notify_status != 'undefined' && isset(notify_status) && notify_status == 1) {
var _backgroundColor = "";
var _icon = "";

if (_title == "") {
_title = "Core";
}
if (_text == "") {
_text = "Erreur inconnue";
}
if (_class_name == "success") {
_backgroundColor = '#00a65a';
_icon = 'far fa-check-circle fa-3x';
} else if (_class_name == "warning") {
_backgroundColor = '#f39c12';
_icon = 'fas fa-exclamation-triangle fa-3x';
} else if (_class_name == "error") {
_backgroundColor = '#dd4b39';
_icon = 'fas fa-times fa-3x';
} else {
_backgroundColor = '#33B8CC';
_icon = 'fas fa-info fa-3x';
}
function showNotification(title, message, type) {
var icon = '/public/img/icon-256x256.png';
if (type === 'error') {
icon = '/public/img/icon-error.png';
}
var notification = new Notification(title, {
body: message.replace(/(<([^>]+)>)/ig, ''),
icon: icon
});
if (typeof(notify_timeout) !== 'undefined') {
setTimeout(notification.close.bind(notification), notify_timeout);
}
}

iziToast.show({
id: null,
class: '',
title: _title,
titleColor: 'white',
titleSize: '1.5em',
titleLineHeight: '30px',
message: _text,
messageColor: 'white',
messageSize: '',
messageLineHeight: '',
theme: 'dark', // dark
iconText: '',
backgroundColor: _backgroundColor,
icon: _icon,
iconColor: 'white',
iconUrl: null,
image: '',
imageWidth: 50,
maxWidth: jQuery(window).width() - 500,
zindex: null,
layout: 2,
balloon: false,
close: true,
closeOnEscape: false,
closeOnClick: false,
displayMode: 0, // once, replace
position: notify_position, // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
target: '',
targetFirst: true,
timeout: notify_timeout * 1000,
rtl: false,
animateInside: true,
drag: true,
pauseOnHover: true,
resetOnHover: false,
progressBar: true,
progressBarColor: '',
progressBarEasing: 'linear',
overlay: false,
overlayClose: false,
overlayColor: 'rgba(0, 0, 0, 0.6)',
transitionIn: 'fadeInUp',
transitionOut: 'fadeOut',
transitionInMobile: 'fadeInUp',
transitionOutMobile: 'fadeOutDown',
buttons: {},
inputs: {},
onOpening: function () {
},
onOpened: function () {
},
onClosing: function () {
},
onClosed: function () {
/**
* Check notification permission and show if granted
* @param title Title of the notification
* @param message Message of the notification
* @param type Type of notification (success, error)
*/
function notify(title, message, type) {
var currentDate = new Date();
if (!window.Notification) {
console.error('You\'re browser doesn\'t support notifications');
}
else {
if (!(typeof(notify_status) !== 'undefined' && notify_status == 0)) {
if (Notification.permission === 'granted') {
showNotification(title, message, type);
}
});
else {
var lastRequest = parseInt(localStorage.getItem('notification'));
// 2 weeks
if (lastRequest + 1209600000 > currentDate.getTime()) {
Notification.requestPermission().then(function(result) {
if (result === 'granted') {
showNotification(title, message, type);
}
else {
localStorage.setItem('notification', currentDate.getTime().toString());
}
});
}
}
}
}
}

Expand Down Expand Up @@ -235,7 +197,6 @@ function saveWidgetDisplay(_params){
}
var cmds = [];
var eqLogics = [];
var scenarios = [];
$('.eqLogic-widget:not(.eqLogic_layout_table)').each(function(){
var eqLogic = $(this);
order = 1;
Expand Down Expand Up @@ -709,7 +670,7 @@ function passwordScore(password, progressbar=null, spanLevel=null) {

/**
* Decode HTML entities in string like &eacute;
* @param string message
* @param message Message to decode
*/
function decodeHtmlEntities(message)
{
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"highcharts": "^7.0.1",
"inputmask": "^4.0.2",
"isotope-layout": "^3.0.6",
"izitoast": "^1.4.0",
"jquery-contextmenu": "^2.5.0",
"jquery-cron": "^1.0.0",
"jquery-datetimepicker": "^2.5.20",
Expand Down
6 changes: 2 additions & 4 deletions scripts/gen_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function gen_css {
mkdir -p assets/css/builded
# Build adminlte
node vendor/node_modules/less/bin/lessc assets/css/compiled/AdminLTE.less assets/css/builded/AdminLTE.scss
#
#
cat vendor/node_modules/bootstrap/dist/css/bootstrap.css \
vendor/node_modules/roboto-fontface/css/roboto/roboto-fontface.css \
vendor/node_modules/jquery-ui/themes/base/core.css \
Expand Down Expand Up @@ -58,12 +58,11 @@ function gen_css {
vendor/node_modules/jquery-contextmenu/dist/jquery.contextMenu.css \
vendor/node_modules/tablesorter/dist/css/theme.bootstrap.min.css \
vendor/node_modules/codemirror/lib/codemirror.css \
vendor/node_modules/izitoast/dist/css/iziToast.css \
vendor/node_modules/@fortawesome/fontawesome-free/css/all.css \
vendor/node_modules/font-awesome/css/font-awesome.css \
vendor/node_modules/jquery-datetimepicker/jquery.datetimepicker.css \
vendor/node_modules/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css \
assets/icon/animal/style.css \
assets/icon/animal/style.css \
assets/icon/divers/style.css \
assets/icon/fashion/style.css \
assets/icon/loisir/style.css \
Expand Down Expand Up @@ -116,7 +115,6 @@ function gen_js {
vendor/node_modules/bootstrap/dist/js/bootstrap.min.js \
vendor/node_modules/pace-js/pace.min.js \
vendor/node_modules/admin-lte/dist/js/adminlte.min.js \
vendor/node_modules/izitoast/dist/js/iziToast.min.js \
assets/3rdparty/jquery.utils/jquery.utils.js \
assets/3rdparty/jquery.at.caret/jquery.at.caret.min.js \
assets/3rdparty/jquery.multi-column-select/multi-column-select.js \
Expand Down
2 changes: 0 additions & 2 deletions src/Controller/Pages/FirstUseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function get(&$pageData): string
{
$configs = ConfigManager::byKeys([
'notify::status',
'notify::position',
'notify::timeout',
'nextdom::firstUse']);
if ($configs['nextdom::firstUse'] == 0) {
Expand All @@ -59,7 +58,6 @@ public static function get(&$pageData): string
$pageData[ControllerData::TITLE] = '1ère Connexion';
$pageData[ControllerData::JS_VARS] = [
'notify_status' => $configs['notify::status'],
'notify_position' => $configs['notify::position'],
'notify_timeout' => $configs['notify::timeout'],
'serverTZoffsetMin' => Utils::getTZoffsetMin(),
'serverDatetime' => Utils::getMicrotime()
Expand Down
15 changes: 6 additions & 9 deletions src/Helpers/PrepareView.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function initConfig()
'nextdom::firstUse',
'nextdom::Welcome',
'notify::status',
'notify::position',
'notify::timeout',
'widget::size',
'widget::margin',
Expand Down Expand Up @@ -139,7 +138,6 @@ private function initJsPool(&$pageData)
$pageData[ControllerData::JS_POOL][] = '/vendor/node_modules/bootstrap/dist/js/bootstrap.min.js';
$pageData[ControllerData::JS_POOL][] = '/vendor/node_modules/admin-lte/dist/js/adminlte.min.js';
$pageData[ControllerData::JS_POOL][] = '/vendor/node_modules/pace-js/pace.min.js';
$pageData[ControllerData::JS_POOL][] = '/vendor/node_modules/izitoast/dist/js/iziToast.min.js';
$pageData[ControllerData::JS_POOL][] = '/assets/3rdparty/jquery.utils/jquery.utils.js';
$pageData[ControllerData::JS_POOL][] = '/assets/3rdparty/jquery.at.caret/jquery.at.caret.min.js';
$pageData[ControllerData::JS_POOL][] = '/assets/3rdparty/jquery.multi-column-select/multi-column-select.js';
Expand Down Expand Up @@ -178,12 +176,12 @@ private function initJsPool(&$pageData)
$pageData[ControllerData::JS_POOL][] = '/assets/js/core/jeedom.class.js';

// Then NextDom JS files
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/conflicts.js';
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/loads.js';
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/inits.js';
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/gui.js';
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/utils.js';
$pageData[ControllerData::JS_POOL][] = '/public/js/desktop/search.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/conflicts.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/loads.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/inits.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/gui.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/utils.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/search.js';
$pageData[ControllerData::JS_POOL][] = '/assets/js/desktop/jeedomCompatibility.js';

// And libraries JS
Expand Down Expand Up @@ -438,7 +436,6 @@ public function showContent()
'user_login' => UserManager::getStoredUser()->getLogin(),
'nextdom_Welcome' => $this->currentConfig['nextdom::Welcome'],
'notify_status' => $this->currentConfig['notify::status'],
'notify_position' => $this->currentConfig['notify::position'],
'notify_timeout' => $this->currentConfig['notify::timeout'],
'widget_size' => $this->currentConfig['widget::size'],
'widget_margin' => $this->currentConfig['widget::margin'],
Expand Down
14 changes: 0 additions & 14 deletions views/desktop/params/profils.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,6 @@
<fieldset>
<legend>{{ 'Notifications système' }}</legend>
<div class="row">
<div class="form-group col-lg-6 col-sm-6 col-xs-12 col-padding">
<label class="control-label">{{ 'Position des notifications' }}</label>
<div class="input-group" data-toggle="tooltip" title="" data-original-title="{{ 'Position sur l\'écran des notifications' }}">
<a class="input-group-addon cursor bt_resetConfigParam" data-l1key="notify::position" data-toggle="tooltip" title="" data-original-title="Par défaut"><i class="fas fa-times"></i></a>
<select class="configKey form-control" data-l1key="notify::position">
<option value="topRight" selected="selected">Haut droite</option>
<option value="topLeft">Haut gauche</option>
<option value="bottomRight">Bas droite</option>
<option value="bottomLeft">Bas gauche</option>
<option value="topCenter">Haut centre</option>
<option value="bottomCenter">Bas centre</option>
</select>
</div>
</div>
<div class="form-group col-lg-6 col-sm-6 col-xs-12 col-padding">
<label class="control-label">{{ 'Durée des notifications' }}</label>
<div class="input-group">
Expand Down

0 comments on commit 4663e85

Please sign in to comment.