better queue render
This commit is contained in:
132
src/renderer/scripts/NotificationConfig.js
Normal file
132
src/renderer/scripts/NotificationConfig.js
Normal file
@@ -0,0 +1,132 @@
|
||||
const NotificationConfig = {
|
||||
is_notify_each_image: false,
|
||||
is_notify_all_done: true,
|
||||
obj_modal: null,
|
||||
|
||||
init: () => {
|
||||
NotificationConfig._create_badge();
|
||||
NotificationConfig._create_modal();
|
||||
NotificationConfig._bind_events();
|
||||
NotificationConfig._load_config();
|
||||
},
|
||||
|
||||
_create_badge: () => {
|
||||
let obj_nav_right = document.querySelector("nav .d-flex.gap-2");
|
||||
let obj_badge = document.createElement("button");
|
||||
obj_badge.id = "btn_notification_config";
|
||||
obj_badge.className = "btn btn-sm btn-outline-secondary";
|
||||
obj_badge.title = "Notifications";
|
||||
obj_badge.innerHTML = '<i class="mdi mdi-bell-outline"></i>';
|
||||
let obj_blender_btn = document.getElementById("btn_blender_status");
|
||||
if (obj_blender_btn) {
|
||||
obj_nav_right.insertBefore(obj_badge, obj_blender_btn.nextSibling);
|
||||
} else {
|
||||
obj_nav_right.insertBefore(obj_badge, obj_nav_right.firstChild);
|
||||
}
|
||||
|
||||
obj_badge.addEventListener("click", () => {
|
||||
NotificationConfig._open_modal();
|
||||
});
|
||||
},
|
||||
|
||||
_create_modal: () => {
|
||||
let obj_modal_el = document.createElement("div");
|
||||
obj_modal_el.id = "modal_notification_config";
|
||||
obj_modal_el.className = "modal fade";
|
||||
obj_modal_el.tabIndex = -1;
|
||||
obj_modal_el.innerHTML =
|
||||
'<div class="modal-dialog modal-dialog-centered modal-sm">' +
|
||||
'<div class="modal-content bg-dark text-light border-secondary">' +
|
||||
'<div class="modal-header border-secondary">' +
|
||||
'<h6 class="modal-title"><i class="mdi mdi-bell-outline me-2"></i>Notifications</h6>' +
|
||||
'<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>' +
|
||||
'</div>' +
|
||||
'<div class="modal-body">' +
|
||||
'<p class="text-light-emphasis mb-3" style="font-size: 0.85rem;">' +
|
||||
'Configurez les notifications systeme.' +
|
||||
'</p>' +
|
||||
'<div class="form-check mb-2">' +
|
||||
'<input class="form-check-input" type="checkbox" id="check_notify_each_image">' +
|
||||
'<label class="form-check-label" for="check_notify_each_image">' +
|
||||
'A chaque image rendue' +
|
||||
'</label>' +
|
||||
'</div>' +
|
||||
'<div class="form-check">' +
|
||||
'<input class="form-check-input" type="checkbox" id="check_notify_all_done" checked>' +
|
||||
'<label class="form-check-label" for="check_notify_all_done">' +
|
||||
'Quand tous les rendus sont termines' +
|
||||
'</label>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="modal-footer border-secondary">' +
|
||||
'<button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Annuler</button>' +
|
||||
'<button id="btn_save_notification" type="button" class="btn btn-sm btn-primary">' +
|
||||
'<i class="mdi mdi-check me-1"></i>Valider' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
document.body.appendChild(obj_modal_el);
|
||||
NotificationConfig.obj_modal = new bootstrap.Modal(obj_modal_el);
|
||||
},
|
||||
|
||||
_bind_events: () => {
|
||||
let obj_btn_save = document.getElementById("btn_save_notification");
|
||||
obj_btn_save.addEventListener("click", () => {
|
||||
NotificationConfig._save_config();
|
||||
});
|
||||
},
|
||||
|
||||
_open_modal: () => {
|
||||
document.getElementById("check_notify_each_image").checked = NotificationConfig.is_notify_each_image;
|
||||
document.getElementById("check_notify_all_done").checked = NotificationConfig.is_notify_all_done;
|
||||
NotificationConfig.obj_modal.show();
|
||||
},
|
||||
|
||||
_load_config: () => {
|
||||
window.api.get_notification_config()
|
||||
.then((obj_config) => {
|
||||
if (obj_config) {
|
||||
NotificationConfig.is_notify_each_image = obj_config.is_notify_each_image || false;
|
||||
NotificationConfig.is_notify_all_done = obj_config.is_notify_all_done !== undefined ? obj_config.is_notify_all_done : true;
|
||||
NotificationConfig._update_badge();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Config non trouvee, valeurs par defaut
|
||||
});
|
||||
},
|
||||
|
||||
_save_config: () => {
|
||||
NotificationConfig.is_notify_each_image = document.getElementById("check_notify_each_image").checked;
|
||||
NotificationConfig.is_notify_all_done = document.getElementById("check_notify_all_done").checked;
|
||||
|
||||
let obj_config = {
|
||||
is_notify_each_image: NotificationConfig.is_notify_each_image,
|
||||
is_notify_all_done: NotificationConfig.is_notify_all_done,
|
||||
};
|
||||
|
||||
window.api.set_notification_config(obj_config)
|
||||
.then(() => {
|
||||
NotificationConfig._update_badge();
|
||||
NotificationConfig.obj_modal.hide();
|
||||
ConsoleLog.add("Configuration notifications sauvegardee.");
|
||||
})
|
||||
.catch((obj_err) => {
|
||||
ConsoleLog.add("Erreur sauvegarde notifications : " + obj_err.message);
|
||||
});
|
||||
},
|
||||
|
||||
_update_badge: () => {
|
||||
let obj_badge = document.getElementById("btn_notification_config");
|
||||
let is_any_active = NotificationConfig.is_notify_each_image || NotificationConfig.is_notify_all_done;
|
||||
if (is_any_active) {
|
||||
obj_badge.className = "btn btn-sm btn-outline-success";
|
||||
obj_badge.title = "Notifications activees";
|
||||
} else {
|
||||
obj_badge.className = "btn btn-sm btn-outline-secondary";
|
||||
obj_badge.title = "Notifications desactivees";
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user