Browse Source

refactor: 逻辑代码放到model中

qufenxi
alan 6 years ago
parent
commit
c0466eb0b2
  1. 50
      src/app/connection/link_set.mixin.ts
  2. 46
      src/app/connection/link_set.model.ts
  3. 4
      src/app/connection/right/right_detail/right_detail.model.ts
  4. 20
      src/app/connection/right/right_title/right_title.model.ts
  5. 9
      src/app/connection/right/right_title/right_title.ts

50
src/app/connection/link_set.mixin.ts

@ -0,0 +1,50 @@
import {LinkType} from '@ui/type';
import {saveConnection} from './link_set.service';
const mixinName = 'dec.dcm.minxin.linkset';
const Mixin = {
setConnectionNameErr(err: string) {
this.model.connectionNameErr = err;
},
setEdit(type: boolean) {
this.model.linkSelected = {
...this.model.linkSelected,
isSelected: type,
};
this.model.linkUpdate = this.model.linkSelected;
},
setCancel() {
const linkSelected: LinkType = this.model.linkSelected;
const linkList: LinkType[] = this.model.linkList;
if (linkSelected.connectionId) {
this.setEdit(false);
} else {
this.model.linkList = [
...linkList.filter(item => !!item.connectionId),
];
if (this.model.linkList.length > 0) {
this.model.linkList[0].isSelected = true;
this.model.linkSelected = {
...this.model.linkList[0],
isSelected: false,
};
} else {
this.model.linkSelected = {};
}
this.model.linkUpdate = this.model.linkSelected;
}
},
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);
});
},
};
Fix.mixin(mixinName, Mixin);
export default mixinName;

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

@ -3,10 +3,11 @@ import {deleteConnection, testConnection} from '@shared/crud/crud.request';
import {getCnnectionName} from './select/select.service';
import {DATA_BASE_TYPE} from '@private/constants';
import dialog from '@shared/service/dialog.service';
import {saveConnection} from './link_set.service';
import Mixin from './link_set.mixin';
const className = 'dec.dcm.model.linkset';
const Model = {
context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'],
mixins: [Mixin],
actions: {
/**
*
@ -38,7 +39,6 @@ const Model = {
break;
}
},
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);
@ -68,34 +68,6 @@ const Model = {
setLinkUpdate(value: any) {
this.model.linkUpdate = value;
},
setEdit(type: boolean) {
this.model.linkSelected = {
...this.model.linkSelected,
isSelected: type,
};
this.model.linkUpdate = this.model.linkSelected;
},
setCancel() {
const linkSelected: LinkType = this.model.linkSelected;
const linkList: LinkType[] = this.model.linkList;
if (linkSelected.connectionId) {
this.setEdit(false);
} else {
this.model.linkList = [
...linkList.filter(item => !!item.connectionId),
];
if (this.model.linkList.length > 0) {
this.model.linkList[0].isSelected = true;
this.model.linkSelected = {
...this.model.linkList[0],
isSelected: false,
};
} else {
this.model.linkSelected = {};
}
this.model.linkUpdate = this.model.linkSelected;
}
},
setNewLink(value: string) {
if (!DATA_BASE_TYPE.some(item => item.text === value) && !BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${value.toLowerCase()}.edit`)) {
dialog.error(BI.i18nText('Dec-Dcm_Connection_Option_Cannot_Find'));
@ -106,20 +78,6 @@ const Model = {
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) => {

4
src/app/connection/right/right_detail/right_detail.model.ts

@ -1,10 +1,6 @@
const className = 'dec.dcm.model.link.set.right.detail';
export const Model = BI.inherit(Fix.Model, {
context: ['linkSelected'],
actions: {
},
});
BI.model(className, Model);
export default className;

20
src/app/connection/right/right_title/right_title.model.ts

@ -0,0 +1,20 @@
import LinksetMixin from '../../link_set.mixin';
import {LinkType} from '@ui/type';
const modelName = 'dec.dcm.model.component.right.title';
export const Model = BI.inherit(Fix.Model, {
context: ['linkSelected', 'linkList', 'linkUpdate'],
mixins: [LinksetMixin],
actions: {
onSave() {
const linkList: LinkType[] = this.model.linkList;
const result = BI.find(linkList, (idx: number, value: LinkType) => this.model.linkUpdate.connectionName === value.connectionName && value.connectionId !== this.model.linkUpdate.connectionId);
if (result) {
this.setConnectionNameErr(BI.i18nText('Dec-Dcm_Connection_Is_Existence'));
} else {
this.saveLink();
}
},
},
});
BI.model(modelName, Model);
export default modelName;

9
src/app/connection/right/right_title/right_title.ts

@ -1,5 +1,5 @@
import {WidgetType, Label, Button, LeftRightVerticalAdapt} from '@ui/index';
import RightTitleModel from '../../link_set.model';
import RightTitleModel from './right_title.model';
import {LinkType} from '@ui/type';
import {OTHER_CONNECT} from '@private/constants';
const className = 'dec.dcm.component.right.title';
@ -56,12 +56,7 @@ const Widget: WidgetType = {
invisible: !isEdit,
text: BI.i18nText('Dec-Dcm_Save'),
handler() {
const result = BI.find(linkList, (idx: number, value: LinkType) => that.model.linkUpdate.connectionName === value.connectionName && value.connectionId !== that.model.linkUpdate.connectionId);
if (result) {
that.store.setConnectionNameErr(BI.i18nText('Dec-Dcm_Connection_Is_Existence'));
} else {
that.store.saveLink();
}
that.store.onSave();
},
},
],

Loading…
Cancel
Save