import { shortcut, store } from '@core/core'; import { Htape, Vtape, Label, Layout, CenterAdapt, Loader } from 'ui'; import { ConnectionPoolModel, ConnectionPoolModelXtype } from './connection_pool.model'; import { ListItemXtype } from './list_item/list_item'; import { PoolXtype } from './pool/pool'; import { PAGE_SIZE } from '@constants/constant'; export const ConnectionPoolXtype = 'dec.dcm.connection_pool'; @shortcut(ConnectionPoolXtype) @store(ConnectionPoolModelXtype) export class ConnectionPool extends BI.Widget { title: any; model: ConnectionPoolModel['model']; store: ConnectionPoolModel['store']; watch = { selected: (selected: string) => { this.title.setText(selected); }, } mounted() { const defaultSelected = this.model.connectionJDBC.length > 0 ? this.model.connectionJDBC[0].connectionName : ''; this.store.setSelected(defaultSelected); } render() { if (BI.size(this.model.connectionJDBC) === 0) { return this.renderNoConnection(); } return { type: Htape, items: [ { el: { type: Vtape, cls: 'bi-border-right', items: [ { el: { type: Label, cls: 'bi-border-bottom', textAlign: 'left', text: BI.i18nText('Dec-Dcm_Data_Connections'), lgap: 10, }, height: 40, }, { type: Loader, itemsCreator: (options: {times: number}, populate) => { populate(this.renderList((options.times - 1) * PAGE_SIZE, options.times * PAGE_SIZE)); }, hasNext: options => options.times * PAGE_SIZE < BI.size(this.model.connectionJDBC), }, ], }, width: 275, }, this.renderPool(), ], }; } private renderPool() { return { type: Vtape, items: [ { el: { type: Label, cls: 'bi-border-bottom', textAlign: 'left', lgap: 10, ref: (_ref: any) => { this.title = _ref; }, }, height: 40, }, { type: PoolXtype, }, ], }; } private renderNoConnection() { return { type: CenterAdapt, items: [ { type: Vtape, width: 260, height: 150, items: [ { el: { type: Layout, cls: 'data-connection-background', }, height: 130, }, { type: Label, cls: 'bi-tips', text: BI.i18nText('Dec-Dcm_Connection_NO_Connection_Pool'), }, ], }, ], }; } private renderList(start = 0, end = 0) { const defaultSelected = this.model.connectionJDBC.length > 0 ? this.model.connectionJDBC[0].connectionName : ''; return this.model.connectionJDBC.slice(start, end).map(item => { return { type: ListItemXtype, name: item.connectionName, value: item.connectionName, selected: item.connectionName === defaultSelected, }; }); } }