Browse Source

refactor: 把内部方法移出actions

qufenxi
alan 6 years ago
parent
commit
e7f6c4c143
  1. 7
      src/app/app.model.ts
  2. 151
      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: { actions: {
setLinkList(value: LinkType[]) {
this.model.linkList = value;
this.model.tab = TAB_LINK_SET;
},
initData(callback: Function) { initData(callback: Function) {
fetchLinkList((linkList: LinkType[]) => { fetchLinkList((linkList: LinkType[]) => {
this.setLinkList(linkList); this.model.linkList = linkList;
this.model.tab = TAB_LINK_SET;
callback(); callback();
}); });
}, },

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

@ -1,4 +1,3 @@
import {ModelType} from '@ui/index';
import {LinkType} from '@ui/type'; import {LinkType} from '@ui/type';
import {deleteConnection, testConnection} from '@shared/crud/crud.request'; import {deleteConnection, testConnection} from '@shared/crud/crud.request';
import {getCnnectionName} from './select/select.service'; 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 dialog from '@shared/service/dialog.service';
import {saveConnection} from './link_set.service'; import {saveConnection} from './link_set.service';
const className = 'dec.dcm.model.linkset'; const className = 'dec.dcm.model.linkset';
const Model: ModelType = { const Model = {
context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'], context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'],
actions: { actions: {
/** /**
@ -14,23 +13,10 @@ const Model: ModelType = {
* @param name * @param name
*/ */
setLinkSelected(name: string) { setLinkSelected(name: string) {
this.noSaveConfirm(() => { this._noSaveConfirm(() => {
this._setLinkSelected(name); 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) { onIconClick(title: string, id: string) {
switch (title) { switch (title) {
case BI.i18nText('Dec-Dcm_Delete'): case BI.i18nText('Dec-Dcm_Delete'):
@ -44,7 +30,7 @@ const Model: ModelType = {
this._textLink(id); this._textLink(id);
break; break;
case BI.i18nText('Dec-Dcm_Copy'): case BI.i18nText('Dec-Dcm_Copy'):
this.noSaveConfirm(() => { this._noSaveConfirm(() => {
this.copyLink(id); this.copyLink(id);
}); });
break; break;
@ -52,20 +38,7 @@ const Model: ModelType = {
break; 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) { copyLink(id: string) {
const connectionName = BI.find(this.model.linkList, (index: number, item: LinkType) => item.connectionId === id).connectionName; const connectionName = BI.find(this.model.linkList, (index: number, item: LinkType) => item.connectionId === id).connectionName;
const name = getCnnectionName(this.model.linkList, connectionName); const name = getCnnectionName(this.model.linkList, connectionName);
@ -129,56 +102,14 @@ const Model: ModelType = {
return; return;
} }
this.noSaveConfirm(() => { this._noSaveConfirm(() => {
this._setNewLink(value); this._setNewLink(value);
}); });
}, },
_setNewLink(value: string) {
const name = getCnnectionName(this.model.linkList, value);
let data = {};
DATA_BASE_TYPE.forEach(item => {
if (item.text === value) {
data = item;
}
});
this.model.linkList = [
{
connectionName: name,
isSelected: true,
...data,
text: value,
},
...this.model.linkList,
];
this.model.linkSelected = {
...data,
connectionName: name,
isSelected: true,
text: value,
};
this.model.linkUpdate = {
...data,
connectionName: name,
text: value,
};
},
setConnectionNameErr(err: string) { setConnectionNameErr(err: string) {
this.model.connectionNameErr = err; this.model.connectionNameErr = err;
}, },
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) {
this.saveLink();
} else {
this.setCancel();
}
cb();
});
} else {
cb();
}
},
saveLink() { saveLink() {
const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {}; const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {};
const update = { const update = {
@ -190,6 +121,76 @@ const Model: ModelType = {
}); });
}, },
}, },
_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 = {};
DATA_BASE_TYPE.forEach(item => {
if (item.text === value) {
data = item;
}
});
this.model.linkList = [
{
connectionName: name,
isSelected: true,
...data,
text: value,
},
...this.model.linkList,
];
this.model.linkSelected = {
...data,
connectionName: name,
isSelected: true,
text: value,
};
this.model.linkUpdate = {
...data,
connectionName: name,
text: value,
};
},
_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) {
this.saveLink();
} else {
this.setCancel();
}
cb();
});
} else {
cb();
}
},
}; };
BI.model(className, BI.inherit(Fix.Model, Model)); BI.model(className, BI.inherit(Fix.Model, Model));
export default className; export default className;

3
src/app/title/title.ts

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

Loading…
Cancel
Save