/* * Admin - Home page scripts. */ (function (win, doc, undef) { "use strict"; let ah = sax.adminHome = {}; let $pnl = ah.$pnl = {}, $dlg = ah.$dlg = {}, $frm = ah.$frm = {}; sax.itemIdPrefix = 'Itm_'; //-------------------------------------------------------------- ah.refreshApplicationStats = function (delay) { clearTimeout(ah.toStats); if (sax.awaitingLogin) return; if (!ah.awaitingStatsResponse) { var $items = $('.sax-panel-item-list', $pnl.appStats).fadeOut(200).empty(); var $msgs = $('.sax-panel-messages', $pnl.appStats).hide().empty().append($('
' + sax.msg.dataQuerying + '
')).fadeIn(200); } sax.ajax.awaitAct = sax.ajax.awaitAct || { url: sax.url.base + 'Home/Ajax/GetApplicationStats', formId: 'frmNavigate', callbackFn: ah.handleStatsResponse, noWaitIcon: true }; sax.doAjaxRequest(sax.ajax.awaitAct, delay || 50); ah.awaitingStatsResponse = true; } ah.handleStatsResponse = function (response) { //sax.debug('handleAwaitActivateResponse', response); delete ah.awaitingStatsResponse; var $msgs = $('.sax-panel-messages', $pnl.appStats).hide().empty(); var $items = $('.sax-panel-item-list', $pnl.appStats).hide().empty(); ah.toStats = setTimeout(ah.refreshApplicationStats, 60000); if (!response.success) return; //return $msgs.append($('
' + sax.msg.noItemsAwaitAct + '
')).fadeIn(500); // Users. let usr = response.stats.user; let $usr = sax.getAppStatItemTemplate(); $('.sax-header .sax-caption', $usr).text(usr.caption || 'Users').on('click', function () { win.location = usr.usersLink; }).addClass("sax-action"); ah.populateAppStat($usr, usr.awaiting.label, usr.awaiting.value, usr.awaitingLink) for (let item of usr.onlineStats) ah.populateAppStat($usr, item.label, item.value, usr.onlineLink) $items.append($usr); // Organisations. let org = response.stats.organisation; let $org = sax.getAppStatItemTemplate(); $('.sax-header .sax-caption', $org).text(org.caption || 'Organisations').on('click', function () { win.location = org.organisationsLink; }).addClass("sax-action"); ah.populateAppStat($org, org.awaiting.label, org.awaiting.value, org.awaitingLink) $items.append($org); $items.slideDown(750); } ah.populateAppStat = function ($item, label, value, link) { let $stat = sax.getAppStatStatTemplate(); $stat.on('click', function () { win.location = link; }); $('.sax-label', $stat).text(label + ':'); $('.sax-value', $stat).text(value); $('table.sax-item-stats', $item).append($stat); return $item; } sax.getAppStatItemTemplate = function () { return $('.sax-panel-item-template .sax-panel-item.sax-item-stats', $pnl.appStats).clone(); } sax.getAppStatStatTemplate = function () { return $('.sax-panel-item-template .sax-item-stat', $pnl.appStats).clone(); } //-------------------------------------------------------------- ah.refreshDbSchema = function (instance, delay) { if (sax.awaitingLogin) return; if (!ah.awaitingSchemaResponse) { let $pnlSchema = $('.sax-panel-results .sax-panel-info.DbSchema.' + instance); var $items = $('.sax-panel-item-list', $pnlSchema).fadeOut(200).empty(); var $msgs = $('.sax-panel-messages', $pnlSchema).hide().empty().append($('
' + sax.msg.dataQuerying + '
')).fadeIn(200); } $('.DatabaseInstance', $frm.dbSchema).val(instance); sax.ajax.dbSchema = sax.ajax.dbSchema || { url: sax.url.base + 'System/Ajax/ValidateDatabaseSchema', formId: $frm.dbSchema.prop('id'), callbackFn: ah.handleDbSchemaResponse, noWaitIcon: true }; sax.doAjaxRequest(sax.ajax.dbSchema, delay || 50); ah.awaitingSchemaResponse = true; } ah.handleDbSchemaResponse = function (response) { //sax.debug('handleDbSchemaResponse', response); delete ah.awaitingSchemaResponse; let $pnlSchema = $('.sax-panel-results .sax-panel-info.DbSchema.' + response.instance); var $msgs = $('.sax-panel-messages', $pnlSchema).hide().empty(); var $tablePanel = $('.sax-panel-item-table', $pnlSchema).hide(); var $table = $('table.sax-item-list', $tablePanel); $('tbody tr', $table).remove(); if (!response.success) return; if (response.instance == 'Core') ah.toSchema = setTimeout(function () { ah.refreshDbSchema('Reference'); }, 250); if (response.instance == 'Reference') ah.toSchema = setTimeout(function () { ah.refreshDbSchema('Support'); }, 250); // Items. var items = response.items; if (!items.length) return $msgs.append($('
' + sax.msg.dbSchemaValid + '
')).fadeIn(500); for (let itemIdx = 0; itemIdx < items.length; itemIdx++) $table.append(ah.populateDbSchemaItem(ah.getDbSchemaRowTemplate(), items[itemIdx])); $tablePanel.show(); } ah.getDbSchemaTableTemplate = function () { return $('.sax-panel-results .sax-panel-item-template .sax-panel-item-table.DbSchema').clone(); } ah.getDbSchemaRowTemplate = function () { return $('.sax-panel-results .sax-panel-item-template .sax-row-item.DbSchemaItem').clone(); } ah.populateDbSchemaItem = function ($item, item) { if (!item) return; $item.prop('id', sax.itemIdPrefix + item.id); $('.SchemaName', $item).text(item.schemaName); $('.TableName', $item).text(item.tableName); $('.IndexName', $item).text(item.indexName); $('.ColumnName', $item).text(item.columnName); $('.Comment', $item).text(item.comment); return $item; } //-------------------------------------------------------------- $(function () { $pnl.appStats = $('.sax-panel-results.ApplicationStats'); $frm.dbSchema = $('#frmDatabaseSchema'); $pnl.dbSchemaCore = $('.sax-panel-info.DbSchema.Core').append(ah.getDbSchemaTableTemplate()); $pnl.dbSchemaReference = $('.sax-panel-info.DbSchema.Reference'); $pnl.dbSchemaReference.append(ah.getDbSchemaTableTemplate()); $pnl.dbSchemaSupport = $('.sax-panel-info.DbSchema.Support').append(ah.getDbSchemaTableTemplate()); ah.toStats = setTimeout(ah.refreshApplicationStats, 400); ah.toSchema = setTimeout(function () { ah.refreshDbSchema('Core'); }, 600); // NB Can only request one of the database schemas at a time as they share the same ajax config. }); //-------------------------------------------------------------- }(window, window.document)); /* The End */