make Presets forward to Monitor States
parent
2a4f6c0573
commit
fc1d8232b4
|
@ -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": `<i class="fa fa-plus"></i> ${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": `<i class="fa fa-clock-o"></i> ${lang['Schedules']}`,
|
||||
"btnContent": `<i class="fa fa-align-right"></i> ${lang['Monitor States']}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -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 += `<div class="mdl-list__item card btn-default mb-2" preset-name="${preset.name}">
|
||||
<div class="card-body d-flex flex-row">
|
||||
<div class="flex-grow-1 pr-3">
|
||||
${preset.name}
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
<small class="text-muted">${presetMonitors.length} Monitor${presetMonitors.length > 1 ? 's' : ''}</small>
|
||||
${hasSelectedMonitor ? `<ul class="json-to-block striped import-monitor-preset cursor-pointer">${jsonToHtmlBlock(humanizedMonitorKeys)}</ul>` : ''}
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
<span><input class="form-check-input no-abs" type="checkbox" value="${preset.name}" ${hasSelectedMonitor ? 'checked' : ''}/></span>
|
||||
</div>
|
||||
<div>
|
||||
<a class="badge btn btn-sm btn-danger delete-preset"><i class="fa fa-trash-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
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 = `<code>${lang.Presets}</code><br><br><div class="row">`
|
||||
$.each(preset.details.monitors,function(n,monitorConfigPartial){
|
||||
monitorsAssociated += `<div class="col-md-6 json-to-block striped">${jsonToHtmlBlock(getHumanizedMonitorConfig(monitorConfigPartial))}</div>`
|
||||
})
|
||||
monitorsAssociated += '</div>'
|
||||
$.confirm.create({
|
||||
title: lang['Delete Monitor States Preset'],
|
||||
body: lang.deleteMonitorStateText1 + `<br><br>` + 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()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue