covid19-dashboard
Version:
Dashboard App displaying COVID-19 numbers by country
232 lines (198 loc) • 6.89 kB
JavaScript
import Component from '../../../node_modules/neo.mjs/src/controller/Component.mjs';
import NeoArray from '../../../node_modules/neo.mjs/src/util/Array.mjs';
/**
* @class Docs.view.MainContainerController
* @extends Neo.controller.Component
*/
class MainContainerController extends Component {
static getConfig() {return {
/**
* @member {String} className='Docs.view.MainContainerController'
* @protected
*/
className: 'Docs.view.MainContainerController',
/**
* @member {String} ntype='docs-maincontainer-controller'
* @protected
*/
ntype: 'docs-maincontainer-controller'
}}
/**
*
* @param {Object} record
*/
onApiListLeafClick(record) {
let me = this,
contentTabContainer = me.getReference('content-tabcontainer');
contentTabContainer.add({
ntype : 'classdetails-maincontainer',
id : record.className,
structureData: record,
tabButtonConfig: {
iconCls: record.singleton ? 'fa fa-arrow-alt-circle-right' : 'fa fa-copyright',
text : record.name
}
});
}
/**
*
* @param {Object} record
*/
onExamplesListLeafClick(record) {
let me = this,
contentTabContainer = me.getReference('content-tabcontainer'),
name = record.name,
pathArray = [],
store = me.getReference('examples-treelist').store,
tmpRecord = record,
tabButtonConfig;
while (tmpRecord.parentId !== null) {
tmpRecord = store.get(tmpRecord.parentId);
name = tmpRecord.name + '.' + name;
}
name = 'examples_' + name;
tabButtonConfig = {
iconCls: 'fa fa-desktop',
text : record.name
};
if (!Array.isArray(record.path)) {
import(
/* webpackIgnore: true */
record.path).then((module) => {
contentTabContainer.add({
module : module.default,
id : name,
tabButtonConfig: tabButtonConfig
});
}
);
} else {
record.path.forEach(path => {
pathArray.push(import(/* webpackIgnore: true */ path));
});
Promise.all(pathArray).then(function(modules) {
let items = [];
modules.forEach(module => {
items.push({
module: module.default
});
});
contentTabContainer.add({
ntype : 'container',
id : name,
items : items,
style : {padding: '10px'},
tabButtonConfig: tabButtonConfig
});
})
}
}
/**
*
* @param {Object} value
* @param {Object} oldValue
*/
onHashChange(value, oldValue) {
let me = this,
hash = value && value.hash,
contentTabContainer = me.getReference('content-tabcontainer'),
structureStore = me.getReference('api-treelist').store,
record, tab;
if (hash && hash.hasOwnProperty('viewSource')) {
record = structureStore.find('className', hash.viewSource)[0];
if (record) {
tab = contentTabContainer.add({
ntype : 'classdetails-sourceviewcomponent',
id : hash.viewSource + '__source',
line : hash.line,
structureData: record,
tabButtonConfig: {
iconCls: 'fa fa-code',
text : record.name
}
});
// adjust the highlighted line for already added source view tabs
tab.line = hash.line;
}
}
}
/**
*
* @param {Object} data
*/
onNavigationSearchFieldChange(data) {
let me = this,
value = data.value;
me.getReference('examples-treelist') .filter('name', value, null);
me.getReference('api-treelist') .filter('name', value, null);
me.getReference('tutorials-treelist').filter('name', value, null);
}
/**
*
*/
onSwitchSourceViewThemeButtonClick() {
let me = this,
button = me.getReference('source-view-theme-button'),
buttonText, href;
if (button.text === 'Source View Theme Light') {
buttonText = 'Source View Theme Dark';
href = './resources/highlightjs-custom-github-theme.css';
} else {
buttonText = 'Source View Theme Light';
href = './resources/highlightjs-custom-dark-theme.css';
}
Neo.main.addon.Stylesheet.swapStyleSheet({
href: href,
id : 'hljs-theme'
}).then(data => {
button.text = buttonText;
});
}
/**
*
*/
onSwitchThemeButtonClick() {
let me = this,
button = me.getReference('theme-button'),
view = me.component,
buttonText, cls, theme;
if (button.text === 'Theme Light') {
buttonText = 'Theme Dark';
theme = 'neo-theme-light';
} else {
buttonText = 'Theme Light';
theme = 'neo-theme-dark';
}
if (Neo.config.useCssVars) {
cls = [...view.cls];
view.cls.forEach((item, index) => {
if (item.includes('neo-theme')) {
NeoArray.remove(cls, item);
}
});
NeoArray.add(cls, theme);
view.cls = cls;
button.text = buttonText;
}
}
/**
*
* @param {Object} record
*/
onTutorialListLeafClick(record) {
let me = this,
contentTabContainer = me.getReference('content-tabcontainer');
contentTabContainer.add({
ntype : 'classdetails-tutorialcomponent',
fileName: record.fileName,
fileType: record.type,
id : record.name,
tabButtonConfig: {
iconCls: 'fa fa-hands-helping',
text : record.name
}
});
}
}
Neo.applyClassConfig(MainContainerController);
export {MainContainerController as default};