Browse Source

refactor: 把内部方法移出actions

qufenxi
alan 6 years ago
parent
commit
e7f6c4c143
  1. 7
      src/app/app.model.ts
  2. 95
      src/app/connection/link_set.model.ts
  3. 3
      src/app/title/title.ts

7
src/app/app.model.ts

@ -24,13 +24,10 @@ const Model: ModelType = {
},
actions: {
setLinkList(value: LinkType[]) {
this.model.linkList = value;
this.model.tab = TAB_LINK_SET;
},
initData(callback: Function) {
fetchLinkList((linkList: LinkType[]) => {
this.setLinkList(linkList);
this.model.linkList = linkList;
this.model.tab = TAB_LINK_SET;
callback();
});
},

95
src/app/connection/link_set.model.ts

@ -1,4 +1,3 @@
import {ModelType} from '@ui/index';
import {LinkType} from '@ui/type';
import {deleteConnection, testConnection} from '@shared/crud/crud.request';
import {getCnnectionName} from './select/select.service';
@ -6,7 +5,7 @@ import {DATA_BASE_TYPE} from '@private/constants';
import dialog from '@shared/service/dialog.service';
import {saveConnection} from './link_set.service';
const className = 'dec.dcm.model.linkset';
const Model: ModelType = {
const Model = {
context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'],
actions: {
/**
@ -14,23 +13,10 @@ const Model: ModelType = {
* @param name
*/
setLinkSelected(name: string) {
this.noSaveConfirm(() => {
this._noSaveConfirm(() => {
this._setLinkSelected(name);
});
},
_setLinkSelected(name: string) {
this.model.linkList.forEach((item: LinkType) => {
item.isSelected = item.connectionName === name;
if (item.connectionName === name) {
this.model.linkSelected = {
...item,
isSelected: false,
};
}
});
this.model.linkList = [...this.model.linkList];
this.model.linkUpdate = this.model.linkSelected;
},
onIconClick(title: string, id: string) {
switch (title) {
case BI.i18nText('Dec-Dcm_Delete'):
@ -44,7 +30,7 @@ const Model: ModelType = {
this._textLink(id);
break;
case BI.i18nText('Dec-Dcm_Copy'):
this.noSaveConfirm(() => {
this._noSaveConfirm(() => {
this.copyLink(id);
});
break;
@ -52,20 +38,7 @@ const Model: ModelType = {
break;
}
},
_textLink(id: string) {
const link = this.model.linkList.find((item: LinkType) => item.connectionId === id);
const loadingId = dialog.loading(BI.i18nText('Dec-Dcm_Connection_Testing'));
testConnection(link, (res: any) => {
dialog.remove(loadingId);
if (res && res.errorCode) {
dialog.linkFail(`${link.connectionName}${BI.i18nText('Dec-Dcm_Connection_Test_Fail')}`, res.errorMsg, () => {
this._textLink(id);
});
} else {
dialog.success(BI.i18nText('Dec-Dcm_Connection_Test_Success'));
}
});
},
copyLink(id: string) {
const connectionName = BI.find(this.model.linkList, (index: number, item: LinkType) => item.connectionId === id).connectionName;
const name = getCnnectionName(this.model.linkList, connectionName);
@ -129,10 +102,52 @@ const Model: ModelType = {
return;
}
this.noSaveConfirm(() => {
this._noSaveConfirm(() => {
this._setNewLink(value);
});
},
setConnectionNameErr(err: string) {
this.model.connectionNameErr = err;
},
saveLink() {
const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {};
const update = {
...this.model.linkUpdate,
...pluginData,
};
saveConnection(update).then(() => {
this.setEdit(false);
});
},
},
_setLinkSelected(name: string) {
this.model.linkList.forEach((item: LinkType) => {
item.isSelected = item.connectionName === name;
if (item.connectionName === name) {
this.model.linkSelected = {
...item,
isSelected: false,
};
}
});
this.model.linkList = [...this.model.linkList];
this.model.linkUpdate = this.model.linkSelected;
},
_textLink(id: string) {
const link = this.model.linkList.find((item: LinkType) => item.connectionId === id);
const loadingId = dialog.loading(BI.i18nText('Dec-Dcm_Connection_Testing'));
testConnection(link, (res: any) => {
dialog.remove(loadingId);
if (res && res.errorCode) {
dialog.linkFail(`${link.connectionName}${BI.i18nText('Dec-Dcm_Connection_Test_Fail')}`, res.errorMsg, () => {
this._textLink(id);
});
} else {
dialog.success(BI.i18nText('Dec-Dcm_Connection_Test_Success'));
}
});
},
_setNewLink(value: string) {
const name = getCnnectionName(this.model.linkList, value);
let data = {};
@ -162,10 +177,7 @@ const Model: ModelType = {
text: value,
};
},
setConnectionNameErr(err: string) {
this.model.connectionNameErr = err;
},
noSaveConfirm(cb: Function) {
_noSaveConfirm(cb: Function) {
if (this.model.linkSelected && this.model.linkSelected.isSelected) {
dialog.confirm(BI.i18nText('Dec-Dcm_Connection_Config_No_Save'), (isConfirm: boolean) => {
if (isConfirm) {
@ -179,17 +191,6 @@ const Model: ModelType = {
cb();
}
},
saveLink() {
const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {};
const update = {
...this.model.linkUpdate,
...pluginData,
};
saveConnection(update).then(() => {
this.setEdit(false);
});
},
},
};
BI.model(className, BI.inherit(Fix.Model, Model));
export default className;

3
src/app/title/title.ts

@ -35,9 +35,6 @@ const Widget: WidgetType = {
handler() {
closeWindow();
},
ref: _ref => {
this.CloseButton = _ref;
},
},
],
},

Loading…
Cancel
Save