import { model, Model } from '@core/core'; import { AppModel } from '../../app.model'; import { ApiFactory } from 'src/modules/crud/apiFactory'; import { PAGE_INDEX } from '@constants/constant'; const api = new ApiFactory().create(); @model() export class ConnectionModel extends Model<{ types: { pageIndex: AppModel['TYPE']['pageIndex']; connections: AppModel['TYPE']['connections']; connectionSelected: AppModel['TYPE']['connectionSelected']; connectionSelectedOne: AppModel['TYPE']['connectionSelectedOne']; datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected']; }, childContext: ConnectionModel['childContext']; context: ConnectionModel['context']; }> { static xtype = 'dec.dcm.model.connection'; state() { return { connectionLicInfo: { currentConnectionNum: 0, maxConnectionNum: 0, }, }; } childContext: ['connectionLicInfo']; context = ['pageIndex', 'connectionSelected', 'connectionSelectedOne', 'datebaseTypeSelected']; actions = { initConnectionLicInfo: (cb: Function) => { return api.getConnectionLicInfo() .then(res => { this.model.connectionLicInfo = res.data; if (res.data.currentConnectionNum > res.data.maxConnectionNum) { BI.Services.getService('dec.service.component.icon_text.msg').alert({ text: BI.i18nText('Dec-Connection_Lic_Limit_Approach_Tip', res.data.maxConnectionNum), }); } cb(); }); }, createNewConnection: () => { if (this.model.connectionLicInfo.currentConnectionNum < this.model.connectionLicInfo.maxConnectionNum) { this.setPageIndex(PAGE_INDEX.DATEBASE); } else { BI.Services.getService('dec.service.component.icon_text.msg').alert({ text: BI.i18nText('Dec-Connection_Lic_Limit_Approach_Prevent_Tip', this.model.connectionLicInfo.maxConnectionNum), }); } }, setPageIndex: (index: string) => { this.model.pageIndex = index; }, setDatebaseTypeSelected(name: string) { this.model.datebaseTypeSelected = name; }, setConnectionSelected(name: string) { this.model.connectionSelected = name; }, getConnectionStatus() { return api.getConnectionStatus(this.model.connectionSelected); }, checkConnectionLic() { return this.model.connectionLicInfo.currentConnectionNum > this.model.connectionLicInfo.maxConnectionNum; }, }; }