|
|
@@ -13,7 +13,7 @@ $(document).on('click', '#HEALTHCHECKS-settings-button', function() {
|
|
|
$('#HEALTHCHECKS-settings-items').html(buildFormGroup(response.data));
|
|
|
var elAddButtonStart = $('#HEALTHCHECKS-settings-page [id*="Services"] .row.start');
|
|
|
var items = $('#HEALTHCHECKS-settings-page [id*="Services"] .row.m-b-40 span');
|
|
|
- $(elAddButtonStart).after('<div class="row"><button type="button" class="btn btn-info pull-right m-r-20 addNewHCService" ><i class="fa fa-plus"></i> Add New Service</button></div>');
|
|
|
+ $(elAddButtonStart).after('<div class="row"><button type="button" class="btn btn-info pull-right m-r-20 addNewHCService" ><i class="fa fa-plus"></i> Add New Service</button><button type="button" class="btn btn-primary pull-right m-r-20 importNewHCService" ><i class="fa fa-database"></i> Import Services</button></div>');
|
|
|
$.each(items, function(key,val) {
|
|
|
var el = $(val);
|
|
|
var text = el.text();
|
|
|
@@ -26,6 +26,59 @@ $(document).on('click', '#HEALTHCHECKS-settings-button', function() {
|
|
|
});
|
|
|
ajaxloader();
|
|
|
});
|
|
|
+$(document).on('click', '.importNewHCService', function() {
|
|
|
+ messageSingle('',' Grabbing checks...',activeInfo.settings.notifications.position,'#FFF','info','10000');
|
|
|
+ var apiUrl = 'api/v2/homepage/healthchecks';
|
|
|
+ organizrAPI2('GET',apiUrl).success(function(data) {
|
|
|
+ try {
|
|
|
+ let response = data.response;
|
|
|
+ if(response.data !== null){
|
|
|
+ if(response.data === false){ return ''; }
|
|
|
+ let checks = (typeof response.data.content.checks !== 'undefined') ? response.data.content.checks : false;
|
|
|
+ if(checks){
|
|
|
+ let checksAlreadySetup = $('#HEALTHCHECKS-settings-page').serializeToJSON();
|
|
|
+ if(typeof checksAlreadySetup['HEALTHCHECKS-all-items'] !== 'undefined'){
|
|
|
+ checksAlreadySetup = checksAlreadySetup['HEALTHCHECKS-all-items'];
|
|
|
+ }else{
|
|
|
+ checksAlreadySetup = null;
|
|
|
+ }
|
|
|
+ $.each(checks, function(i,v) {
|
|
|
+ let alreadySetup = false;
|
|
|
+ let uuid = v.ping_url;
|
|
|
+ uuid = uuid.match(/([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})/g);
|
|
|
+ uuid = uuid[0];
|
|
|
+ if(uuid){
|
|
|
+ if(checksAlreadySetup){
|
|
|
+ $.each(checksAlreadySetup, function(index,val) {
|
|
|
+ if(val.uuid == uuid){
|
|
|
+ alreadySetup = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(alreadySetup == false){
|
|
|
+ $('.addNewHCService').click();
|
|
|
+ let nameElement = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-6).attr('name');
|
|
|
+ let uuidElement = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-5).attr('name');
|
|
|
+ $('#HEALTHCHECKS-settings-page [name*="'+nameElement+'"]').val(v.name);
|
|
|
+ $('#HEALTHCHECKS-settings-page [name*="'+uuidElement+'"]').val(uuid);
|
|
|
+ $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-6).parent().parent().parent().parent().attr('style', 'background: #707cd2; color:white');
|
|
|
+ }else{
|
|
|
+ console.log(v.name + ' is ALREADY SETUP');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ messageSingle('Import',' Import has completed...',activeInfo.settings.notifications.position,'#FFF','info','10000');
|
|
|
+ }else{
|
|
|
+ messageSingle('',' No HealthChecks were setup',activeInfo.settings.notifications.position,'#FFF','error','10000');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ organizrCatchError(e,data);
|
|
|
+ }
|
|
|
+ }).fail(function(xhr) {
|
|
|
+ OrganizrApiError(xhr);
|
|
|
+ });
|
|
|
+});
|
|
|
$(document).on('click', '.addNewHCService', function() {
|
|
|
var lastEl = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').last().attr('name');
|
|
|
var newNum = 0;
|