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 59dcb26
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 101 deletions.
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.
125 changes: 41 additions & 84 deletions assets/js/desktop/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,94 +58,51 @@ 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 = "";
function showNotification(title, message, type) {
var icon = '/public/img/icon-256x256.png';
if (type === 'error') {
icon = '/public/img/icon-error.png';
}
new Notification(title, {
body: message,
icon: 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';
/**
* 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 (Notification.permission === 'granted') {
showNotification(title, message, type);
}

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 () {
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
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
13 changes: 6 additions & 7 deletions src/Helpers/PrepareView.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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 +177,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

0 comments on commit 59dcb26

Please sign in to comment.