|
|
|
import { model, Model } from '@core/core';
|
|
|
|
import { AppModel } from 'src/modules/app.model';
|
|
|
|
import { Connection } from 'src/modules/crud/crud.typings';
|
|
|
|
import { ApiFactory } from 'src/modules/crud/apiFactory';
|
|
|
|
import { PAGE_INDEX } from '@constants/constant';
|
|
|
|
const api = new ApiFactory().create();
|
|
|
|
export const MaintainFormModelXtype = 'dec.dcm.model.maintain_form';
|
|
|
|
@model(MaintainFormModelXtype)
|
|
|
|
export class MaintainFormModel extends Model<{
|
|
|
|
context : {
|
|
|
|
datebaseTypeSelected: AppModel['$$childContext']['datebaseTypeSelected'];
|
|
|
|
datebaseTypeSelectedOne: AppModel['$$childContext']['datebaseTypeSelectedOne'];
|
|
|
|
connectionSelectedOne: AppModel['$$childContext']['connectionSelectedOne'];
|
|
|
|
saveEvent: AppModel['$$childContext']['saveEvent'];
|
|
|
|
testEvent: AppModel['$$childContext']['testEvent'];
|
|
|
|
pageIndex: AppModel['$$childContext']['pageIndex'];
|
|
|
|
connections: AppModel['$$childContext']['connections'];
|
|
|
|
isCopy: AppModel['$$childContext']['isCopy'];
|
|
|
|
}
|
|
|
|
}> {
|
|
|
|
context = ['datebaseTypeSelected', 'datebaseTypeSelectedOne', 'connectionSelectedOne', 'saveEvent', 'pageIndex', 'testEvent', 'connections', 'isCopy'];
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
addConnection: (data: Connection) => {
|
|
|
|
api.addConnection(data).then(result => {
|
|
|
|
if (result.errorCode) {
|
|
|
|
BI.Msg.toast(BI.i18nText(result.errorMsg), {
|
|
|
|
level: 'error',
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.model.pageIndex = PAGE_INDEX.CONNECTION;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateConnection: (name: string, data: Connection) => {
|
|
|
|
data.connectionId = name;
|
|
|
|
api.updateConnection(data).then(() => {
|
|
|
|
this.model.pageIndex = PAGE_INDEX.CONNECTION;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
testConnection: (connection: Connection) => api.testConnection(connection),
|
|
|
|
setIsCopy(isCopy: boolean) {
|
|
|
|
this.model.isCopy = isCopy;
|
|
|
|
},
|
|
|
|
isDriverError(errorCode: string) {
|
|
|
|
return api.isDriverError(errorCode);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|