Refactor Schedules js, add Scheduler launcher in Preset section

merge-requests/198/head
Moe 2020-05-27 17:46:37 -07:00
parent 994fcd5766
commit c2a9633cc1
4 changed files with 50 additions and 50 deletions

View File

@ -102,6 +102,12 @@ module.exports = function(s,config,lang){
"id": "monitorPresetsSelection",
"class": "mdl-list"
},
{
"fieldType": "btn",
"attribute": `data-toggle="modal" data-target="#schedules"`,
"class": `btn-info`,
"btnContent": `<i class="fa fa-clock"></i> &nbsp; ${lang['Schedules']}`,
},
],
},
"Connection": {

View File

@ -191,15 +191,13 @@ module.exports = function(s,config,lang,app,io){
theQueryValues.push(req.params.name)
}
s.sqlQuery(theQuery,theQueryValues,function(err,schedules){
if(schedules && schedules[0]){
endData.ok = true
schedules.forEach(function(schedule){
s.checkDetails(schedule)
})
endData.schedules = schedules
}else{
endData.msg = user.lang['Not Found']
}
endData.ok = true
schedules = schedules || []
schedules.forEach(function(schedule){
s.checkDetails(schedule)
})
endData.schedules = schedules
s.closeJsonResponse(res,endData)
})
})

View File

@ -423,9 +423,6 @@ $(document).ready(function(e){
e.d=JSON.parse(e.mon.details);
$.loadRegionEditor(e.d)
break;
case'detector_filters':
$.detectorFilters.e.modal('show');
break;
case'snapshot':
$.ccio.snapshot(e,function(url){
$('#temp').html('<a href="'+url+'" download="'+$.ccio.init('tf')+'_'+e.ke+'_'+e.mid+'.jpg">a</a>').find('a')[0].click();

View File

@ -1,79 +1,79 @@
$(document).ready(function(){
$.schedules = {
e: $('#schedules'),
selector: $('#schedulesSelector'),
loadedMonitorStates: {},
loadedSchedules: {}
e: $('#schedules')
}
$.schedules.f = $.schedules.e.find('form')
$.schedules.selectedStates = $.schedules.e.find('[name="monitorStates"]')
$.schedules.selectedDays = $.schedules.e.find('[name="days"]')
$.schedules.loadSchedules = function(callback){
$.get($.ccio.init('location',$user) + $user.auth_token + '/schedule/' + $user.ke,function(d){
console.log(d)
var loadedMonitorStates = {}
var loadedSchedules = {}
var schedulerWindow = $('#schedules')
var scheduleSelector = $('#schedulesSelector')
var schedulerForm = schedulerWindow.find('form')
var selectedStates = schedulerWindow.find('[name="monitorStates"]')
var selectedDays = schedulerWindow.find('[name="days"]')
var loadSchedules = function(callback){
$.get(getApiPrefix() + '/schedule/' + $user.ke,function(d){
var html = ''
$.each(d.schedules,function(n,v){
$.schedules.loadedSchedules[v.name] = v
loadedSchedules[v.name] = v
html += $.ccio.tm('option',{
id: v.name,
name: v.name
})
})
$.schedules.selector.find('optgroup').html(html)
scheduleSelector.find('optgroup').html(html)
if(callback)callback()
})
}
$.schedules.loadMonitorStates = function(){
$.get($.ccio.init('location',$user) + $user.auth_token + '/monitorStates/' + $user.ke,function(d){
var loadMonitorStates = function(){
$.get(getApiPrefix() + '/monitorStates/' + $user.ke,function(d){
var html = ''
$.each(d.presets,function(n,v){
$.schedules.loadedMonitorStates[v.name] = v
loadedMonitorStates[v.name] = v
html += $.ccio.tm('option',{
id: v.name,
name: v.name
})
})
$.schedules.selectedStates.html(html)
selectedStates.html(html)
})
}
$.schedules.e.on('shown.bs.modal', function (e) {
$.schedules.loadMonitorStates()
$.schedules.loadSchedules()
schedulerWindow.on('shown.bs.modal', function (e) {
loadMonitorStates()
loadSchedules()
})
$.schedules.e.on('click','.delete',function(e){
schedulerWindow.on('click','.delete',function(e){
$.confirm.e.modal('show');
$.confirm.title.text(lang['Delete Monitor States Preset']);
$.confirm.body.html(lang.deleteMonitorStateText1);
$.confirm.click({title:'Delete',class:'btn-danger'},function(){
var form = $.schedules.f.serializeObject()
$.post($.ccio.init('location',$user) + $user.auth_token + '/schedule/' + $user.ke + '/' + form.name + '/delete',function(d){
var form = schedulerForm.serializeObject()
$.post(getApiPrefix() + '/schedule/' + $user.ke + '/' + form.name + '/delete',function(d){
$.ccio.log(d)
if(d.ok === true){
$.schedules.loadSchedules()
loadSchedules()
$.ccio.init('note',{title:lang.Success,text:d.msg,type:'success'})
}
})
})
})
$.schedules.selector.change(function(e){
scheduleSelector.change(function(e){
var selected = $(this).val()
var loaded = $.schedules.loadedSchedules[selected]
var namespace = $.schedules.e.find('[name="name"]')
var deleteButton = $.schedules.e.find('.delete')
var tzEl = $.schedules.e.find('[name="timezone"]')
$.schedules.selectedStates.find('option:selected').removeAttr('selected')
$.schedules.selectedDays.find('option:selected').removeAttr('selected')
var loaded = loadedSchedules[selected]
var namespace = schedulerWindow.find('[name="name"]')
var deleteButton = schedulerWindow.find('.delete')
var tzEl = schedulerWindow.find('[name="timezone"]')
selectedStates.find('option:selected').removeAttr('selected')
selectedDays.find('option:selected').removeAttr('selected')
if(loaded){
namespace.val(loaded.name)
var html = ''
$.each(loaded,function(n,v){
$.schedules.f.find('[name="' + n + '"]').val(v)
schedulerForm.find('[name="' + n + '"]').val(v)
})
$.each(loaded.details.monitorStates,function(n,v){
$.schedules.selectedStates.find('option[value="' + v + '"]').prop('selected',true)
selectedStates.find('option[value="' + v + '"]').prop('selected',true)
})
$.each(loaded.details.days,function(n,v){
$.schedules.selectedDays.find('option[value="' + v + '"]').prop('selected',true)
selectedDays.find('option[value="' + v + '"]').prop('selected',true)
})
tzEl.val(loaded.details.timezone || '+0')
deleteButton.show()
@ -83,13 +83,12 @@ $(document).ready(function(){
deleteButton.hide()
}
})
$.schedules.f.submit(function(e){
schedulerForm.submit(function(e){
e.preventDefault()
var el = $(this)
var form = el.serializeObject()
var monitors = []
var failedToParseAJson = false
var rows = $.monitorStates.monitors.find('.state-monitor-row')
if(form.name === ''){
return $.ccio.init('note',{title:lang['Invalid Data'],text:lang['Name cannot be empty.'],type:'error'})
}
@ -114,11 +113,11 @@ $(document).ready(function(){
timezone: form.timezone,
}
}
$.post($.ccio.init('location',$user) + $user.auth_token + '/schedule/' + $user.ke + '/' + form.name + '/insert',{data:data},function(d){
$.post(getApiPrefix() + '/schedule/' + $user.ke + '/' + form.name + '/insert',{data:data},function(d){
$.ccio.log(d)
if(d.ok === true){
$.schedules.loadSchedules(function(){
$.schedules.selector.val(form.name)
loadSchedules(function(){
scheduleSelector.val(form.name)
})
$.ccio.init('note',{title:lang.Success,text:d.msg,type:'success'})
}