diff --git a/definitions/base.js b/definitions/base.js index 128e0ee8..0ea408c1 100644 --- a/definitions/base.js +++ b/definitions/base.js @@ -140,38 +140,15 @@ module.exports = function(s,config,lang){ }, "Presets": { id: "monSectionPresets", - "section-class": "am_notice am_notice_edit", "name": lang.Presets, "color": "purple", isSection: true, "info": [ { - "name": lang['Add New'], - "color": "grey", - isFormGroupGroup: true, - "info": [ - { - "id": "monitorPresetsName", - "field": lang['Preset Name'], - }, - { - "fieldType": "btn", - "class": `btn-success add-new`, - "btnContent": `   ${lang['Add']}`, - }, - ] - }, - { - "fieldType": 'div', - "id": "monitorPresetsSelection", - "style": "max-height:400px;overflow:auto;", - "class": "mdl-list" - }, - { - "fieldType": "btn", - "attribute": `page-open="schedules"`, + "fieldType": "a", + "attribute": `page-open="monitorStates"`, "class": `btn-info`, - "btnContent": `   ${lang['Schedules']}`, + "btnContent": `   ${lang['Monitor States']}`, }, ], }, diff --git a/web/assets/js/bs5.monitorSettings.js b/web/assets/js/bs5.monitorSettings.js index dd4d420a..e2faab13 100644 --- a/web/assets/js/bs5.monitorSettings.js +++ b/web/assets/js/bs5.monitorSettings.js @@ -711,8 +711,6 @@ function importIntoMonitorEditor(options){ }; copySettingsSelector.val('0').change() - drawPresetsSection() - var tmp = ''; $.each(loadedMonitors,function(n,monitor){ if(monitor.ke === $user.ke){ @@ -1113,194 +1111,6 @@ editorForm.find('[name="type"]').change(function(e){ drawMonitorSettingsSubMenu() } } - // presets - var loadPresets = function(callback){ - $.getJSON(getApiPrefix() + '/monitorStates/' + $user.ke,function(d){ - var presets = d.presets - loadedPresets = {} - $.each(presets,function(n,preset){ - loadedPresets[preset.name] = preset - }) - drawPresetsSection() - if(callback)callback(presets) - }) - } - var drawPresetsSection = function(){ - var html = '' - var selectedMonitor = getSelectedMonitorInfo() - $.each(loadedPresets,function(n,preset){ - var hasSelectedMonitor = false - var humanizedMonitorKeys - var presetMonitors = preset.details.monitors || [] - $.each(presetMonitors,function(n,monitor){ - if(monitor.mid === selectedMonitor.mid){ - hasSelectedMonitor = true - humanizedMonitorKeys = getHumanizedMonitorConfig(monitor) - } - }) - html += `
-
-
- ${preset.name} -
-
- ${presetMonitors.length} Monitor${presetMonitors.length > 1 ? 's' : ''} - ${hasSelectedMonitor ? `
    ${jsonToHtmlBlock(humanizedMonitorKeys)}
` : ''} -
-
- -
-
- -
-
-
` - }) - monitorPresetsSelection.html(html) - console.log(`!!!!!!!\ncomponentHandler.upgradeAllRegistered\n!!!!!!!`) - } - var addNewPreset = function(callback){ - var newName = monitorPresetsNameField.val() - if(newName === ''){ - return new PNotify({title:lang['Invalid Data'],text:lang['Name cannot be empty.'],type:'error'}) - } - var data = JSON.stringify({ - monitors: [] - }) - $.post(getApiPrefix() + '/monitorStates/' + $user.ke + '/' + newName + '/insert',{data:data},function(d){ - debugLog(d) - if(d.ok === true){ - loadPresets(function(presets){ - if(callback)callback(d) - }) - new PNotify({title:lang.Success,text:d.msg,type:'success'}) - } - }) - } - var deletePreset = function(presetName,callback){ - var preset = loadedPresets[presetName] - var monitorsAssociated = `${lang.Presets}

` - $.each(preset.details.monitors,function(n,monitorConfigPartial){ - monitorsAssociated += `
${jsonToHtmlBlock(getHumanizedMonitorConfig(monitorConfigPartial))}
` - }) - monitorsAssociated += '
' - $.confirm.create({ - title: lang['Delete Monitor States Preset'], - body: lang.deleteMonitorStateText1 + `

` + monitorsAssociated, - clickOptions: { - title:'Delete', - class:'btn-danger' - }, - clickCallback: function(){ - $.post(getApiPrefix() + '/monitorStates/' + $user.ke + '/' + presetName + '/delete',function(d){ - debugLog(d) - if(d.ok === true){ - loadPresets(function(presets){ - if(callback)callback(d) - }) - new PNotify({title:lang.Success,text:d.msg,type:'success'}) - } - }) - } - }) - } - var validateMonitorPreset = function(monitorPartialToAdd){ - var response = {ok: true} - var numberOfKeys = Object.keys(monitorPartialToAdd) - if(numberOfKeys.length < 2){ - response.ok = false - response.msg = lang.monitorStateNotEnoughChanges - return response - } - return response - } - var addMonitorToPreset = function(presetName,callback){ - var validation = getMonitorEditFormFields() - if(!validation.ok){ - callback(true) - return - } - var monitorConfig = validation.monitorConfig - console.log(monitorConfig.mid) - var inMemoryMonitorConfig = Object.assign({},loadedMonitors[monitorConfig.mid]); - var currentPreset = loadedPresets[presetName] - var presetMonitors = currentPreset.details.monitors || [] - var newMonitorsArray = [].concat(presetMonitors) - var monitorIndexInPreset = newMonitorsArray.findIndex(monitor => monitor.mid === monitorConfig.mid) - delete(inMemoryMonitorConfig.ke) - delete(monitorConfig.ke) - var monitorPartialToAdd = differentiateMonitorConfig(inMemoryMonitorConfig,monitorConfig) - monitorPartialToAdd.mid = monitorConfig.mid - //validateMonitorPreset - var monitorPresetValidation = validateMonitorPreset(monitorPartialToAdd) - if(!monitorPresetValidation.ok){ - new PNotify({title:lang.monitorStatesError,text:monitorPresetValidation.msg,type:'warning'}) - callback(true) - return - } - // - if(monitorIndexInPreset > -1){ - newMonitorsArray[monitorIndexInPreset] = monitorPartialToAdd - }else{ - newMonitorsArray.push(monitorPartialToAdd) - } - var data = JSON.stringify({ - monitors: newMonitorsArray - }) - $.post(getApiPrefix() + '/monitorStates/' + $user.ke + '/' + presetName + '/edit',{data:data},function(d){ - debugLog(d) - if(d.ok === true){ - loadPresets(function(presets){ - callback(null,d) - }) - new PNotify({title:lang.Success,text:d.msg,type:'success'}) - } - }) - } - var removeMonitorFromPreset = function(presetName,callback){ - var validation = getMonitorEditFormFields() - if(!validation.ok){ - return - } - var monitorConfig = validation.monitorConfig - var currentPreset = loadedPresets[presetName] - var presetMonitors = currentPreset.details.monitors || [] - var newMonitorsArray = [].concat(presetMonitors) - var monitorIndexInPreset = newMonitorsArray.findIndex(monitor => monitor.mid === monitorConfig.mid) - if(monitorIndexInPreset > -1){ - delete(newMonitorsArray[monitorIndexInPreset]) - newMonitorsArray = newMonitorsArray.filter(function () { return true }) - } - var data = JSON.stringify({ - monitors: newMonitorsArray - }) - $.post(getApiPrefix() + '/monitorStates/' + $user.ke + '/' + presetName + '/edit',{data:data},function(d){ - debugLog(d) - if(d.ok === true){ - loadPresets(function(presets){ - callback(d) - }) - new PNotify({title:lang.Success,text:d.msg,type:'success'}) - } - }) - } - var loadMonitorPartialFromPreset = function(preset,monitorId){ - $.confirm.create({ - title: lang['Import Monitor Configuration'], - body: lang.undoAllUnsaveChanges, - clickOptions: { - title: 'Import', - class: 'btn-primary' - }, - clickCallback: function(){ - var monitorConfigPartial = preset.details.monitors.find(monitor => monitor.mid === monitorId) || {}; - var copyCurrentConfig = loadedMonitors[monitorConfig.mid] - copyCurrentConfig.details = safeJsonParse(copyCurrentConfig.details) - var monitorObjectToLoad = mergeDeep(copyCurrentConfig,monitorConfigPartial); - importIntoMonitorEditor(monitorObjectToLoad) - } - }) - } window.openMonitorEditorPage = function(monitorId){ var monitorConfigToLoad; monitorEditorWindow.find('.am_notice').hide() @@ -1409,7 +1219,6 @@ editorForm.find('[name="type"]').change(function(e){ } }) } - loadPresets() monSectionPresets.find('.add-new').click(function(){ addNewPreset() })