Files
BusinessMgr-2019/SaBusinessMgrCoreWebControl/wwwroot/js/sbc-ins-rep-sch.js
T

128 lines
4.8 KiB
JavaScript

/*
* SBM - Control - Instance - Core Database.
*/
(function (win, doc, undef)
{
"use strict";
let rs = sbc.mdl.repoSchema = { env: {} };
//--------------------------------------------------------------
rs.refreshDbSchema = function (env, delay)
{
if (sbc.awaitingLogin) return;
if (!env.$frm.filter.find('.FilterContext').val()) return;
if (!rs.awaitingSchemaResponse)
{
env.$pnl.bgr.invisible();
rs.clearItems(env);
env.$pnl.msgs.hide().empty().append($('<div class="sbc-message">' + sbc.msg.dataQuerying + '</div>')).fadeIn(200);
}
env.ajax.dbSchema = env.ajax.dbSchema || { url: sbc.url.base + 'System/Ajax/ValidateDatabaseSchema', formSel: env.$frm.filter, callbackFn: function (response) { rs.handleDbSchemaResponse(env, response); }, noWaitIcon: true };
sbc.doAjaxRequest(env.ajax.dbSchema, delay || 50);
rs.awaitingSchemaResponse = true;
}
rs.handleDbSchemaResponse = function (env, response)
{
//sbc.debug('handleDbSchemaResponse', response);
delete rs.awaitingSchemaResponse;
env.$pnl.msgs.hide().empty();
var $table = env.$pnl.table.find('table.sbc-item-list');
rs.clearItems(env);
if (!response.success) return;
// Menu.
if (env.$pnl.bgr.length)
{
env.$pnl.mnu.empty();
env.$pnl.mnu.append(rs.getFilterMenuOption(env, sbc.lbl.refresh, function () { rs.refreshDbSchema(env); }, 'sbc-refresh'));
env.$pnl.mnu.append(rs.getFilterMenuOption(env, sbc.lbl.popIndices, function () { rs.populateIndices(env); }, 'sbc-process'));
env.$pnl.bgr.toggleVisibility(!!env.$pnl.mnu.find('.sbc-dropdown-item').length);
}
// Items.
var items = response.items;
if (!items.length)
return env.$pnl.msgs.append($('<div class="sbc-message">' + sbc.msg.dbSchemaValid + '</div>')).fadeIn(500);
for (const item of items)
$table.append(rs.populateDbSchemaItem(env, rs.getItemTemplate(env), item));
}
rs.populateDbSchemaItem = function (env, $item, item)
{
if (!item) return;
$item.prop('id', sbc.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);
let $bgr = $item.find('.sbc-burger').invisible();
return $item;
}
rs.clearItems = function (env)
{
env.$pnl.table.find('table.sbc-item-list').find('tbody tr').remove();
}
//--------------------------------------------------------------
rs.getFilterDropdownTemplate = function (env)
{
return env.$pnl.tmpl.find('.sbc-dropdown-menu.SchemaFilter li.sbc-dropdown-item').clone();
}
rs.getItemTemplate = function (env)
{
return env.$pnl.tmpl.find('.sbc-row-item.SchemaItem').clone();
}
rs.getItemDropdownTemplate = function (env)
{
return env.$pnl.tmpl.find('.sbc-dropdown-menu.SchemaItem li.sbc-dropdown-item').clone();
}
rs.getFilterMenuOption = function (env, lbl, fn, cls)
{
return rs.getMenuOption(rs.getFilterDropdownTemplate(env), lbl, fn, cls);
}
rs.getItemMenuOption = function (env, lbl, fn, cls)
{
return rs.getMenuOption(rs.getItemDropdownTemplate(env), lbl, fn, cls);
}
rs.getMenuOption = function ($opt, lbl, fn, cls)
{
return $opt.find('div.sbc-label').text(lbl).end().on('click', fn).addClass(cls);
}
//--------------------------------------------------------------
rs.populateIndices = function (env, delay)
{
env.ajax.popIndices = env.ajax.popIndices || { url: sbc.url.base + 'Instance/Repository/Ajax/PopulateIndices', formSel: env.$frm.filter, callbackFn: function (response) { rs.onPopulateIndices(env, response); }, noWaitIcon: true };
sbc.doAjaxRequest(env.ajax.popIndices, delay || 50);
}
rs.onPopulateIndices = function (env, response)
{
//sbc.debug('onPopulateIndices', response);
rs.refreshDbSchema(env);
}
//--------------------------------------------------------------
$(function ()
{
let env = { mode: { search: 1 }, data: {}, ajax: {}, $pnl: {}, $frm: {}, $ctrl: {}, $dlg: {} };
env.$pnl.items = $('.sbc-panel.Schema');
env.$pnl.hdr = env.$pnl.items.find('.sbc-panel-header');
env.$pnl.bgr = env.$pnl.hdr.find('.sbc-burger').invisible();
env.$pnl.mnu = env.$pnl.bgr.find('ul.sbc-dropdown-menu');
env.$frm.filter = env.$pnl.items.find('#frmSchemaFilter');
env.$frm.filter.on('change', '.FilterContext', function () { rs.refreshDbSchema(env); });
env.$frm.filter.on('input', '.FilterSearch', function () { rs.refreshDbSchema(env); });
env.$frm.filter.find('.FilterInstance').val('BusMgr');
env.$pnl.table = env.$pnl.items.find('.sbc-panel-item-table');
env.$pnl.msgs = env.$pnl.items.find('.sbc-panel-messages');
env.$pnl.tmpl = env.$pnl.items.find('.sbc-panel-item-template');
rs.env.schema = env;
if (rs.env.schema.$pnl.table.length)
setTimeout(function () { rs.refreshDbSchema(env); }, 500);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */