Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rollback new class on diagrams #632

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions addon/components/fd-sheets/fd-class-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ export default FdBaseSheet.extend({
deactivateListItem() {
let selectedValue = this.get('selectedValue');
if (!isNone(selectedValue)) {
let model = get(selectedValue, 'data');
model.rollbackAll();
set(selectedValue, 'active', false);
}
},
Expand Down
103 changes: 62 additions & 41 deletions addon/components/fd-sheets/fd-edit-diagram-object-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,41 +153,32 @@ export default FdBaseSheet.extend({
@param {Object} currentItem Current list item.
*/
openSheet(sheetName, currentItem) {
let store = this.get('store');
let objectId = currentItem.get('repositoryObject').slice(1, -1);

let selectedValue, stereotype;
let modelName = 'fd-dev-association';
let isLink = false;

switch (currentItem.get('primitive.$type')) {
case 'STORMCASE.UML.cad.Composition, UMLCAD':
modelName = 'fd-dev-aggregation';
// eslint-disable-next-line no-fallthrough
case 'STORMCASE.UML.cad.Association, UMLCAD':
isLink = true;
stereotype = currentItem.get('primitive.$type').slice(18, -8).toLocaleLowerCase();
selectedValue = store.peekRecord(`${modelName}`, objectId);

updateLinkByStr(selectedValue);
this.set('_endRoleStr', selectedValue.get('endRoleStr'));
this.set('_startRoleStr', selectedValue.get('startRoleStr'));
this.set('_endMultiplicity', selectedValue.get('endMultiplicity'));
this.set('_startMultiplicity', selectedValue.get('startMultiplicity'));
break;
default:
stereotype = currentItem.getWithDefault('stereotype', '').trim().slice(1, -1) || 'implementation';
selectedValue = store.peekRecord('fd-dev-class', objectId);

updateObjectByStr(selectedValue, store);
this.set('_attributesStr', selectedValue.get('attributesStr'));
this.set('_methodsStr', selectedValue.get('methodsStr'));
this.rollbackSelectedValue();

let stereotype;
let isLink = currentItem.isLink;
let selectedValue = currentItem.data;
let selectedValueModel = currentItem.selectedValueModel;
if (isLink) {
stereotype = selectedValueModel.get('primitive.$type').slice(18, -8).toLocaleLowerCase();

updateLinkByStr(selectedValue);
this.set('_endRoleStr', selectedValue.get('endRoleStr'));
this.set('_startRoleStr', selectedValue.get('startRoleStr'));
this.set('_endMultiplicity', selectedValue.get('endMultiplicity'));
this.set('_startMultiplicity', selectedValue.get('startMultiplicity'));
} else {
stereotype = selectedValueModel.getWithDefault('stereotype', '').trim().slice(1, -1) || 'implementation';

updateObjectByStr(selectedValue, this.get('store'));
this.set('_attributesStr', selectedValue.get('attributesStr'));
this.set('_methodsStr', selectedValue.get('methodsStr'));
}

this.set('isLink', isLink);
this.set('selectedValue', selectedValue);
this.set('objectEditFormNamePart', stereotype);
this.set('selectedValueModel', currentItem);
this.set('selectedValueModel', selectedValueModel);
},

/**
Expand All @@ -196,23 +187,13 @@ export default FdBaseSheet.extend({
@method closeSheet
*/
closeSheet() {
let selectedValue = this.get('selectedValue');
if (!selectedValue.get('isNew')) {
selectedValue.rollbackAll();
}

this.rollbackSelectedValue();
if (this.get('isLink')) {
selectedValue.set('endRoleStr', this.get('_endRoleStr'));
selectedValue.set('startRoleStr', this.get('_startRoleStr'));
selectedValue.set('endMultiplicity', this.get('_endMultiplicity'));
selectedValue.set('startMultiplicity', this.get('_startMultiplicity'));
this.set('_endRoleStr', undefined);
this.set('_startRoleStr', undefined);
this.set('_endMultiplicity', undefined);
this.set('_startMultiplicity', undefined);
} else {
selectedValue.set('attributesStr', this.get('_attributesStr'));
selectedValue.set('methodsStr', this.get('_methodsStr'));
this.set('_attributesStr', undefined);
this.set('_methodsStr', undefined);
}
Expand All @@ -225,6 +206,46 @@ export default FdBaseSheet.extend({
this.set('readonlyMode', true);
},

/**
Rollback 'selectedValue'.

@method rollbackSelectedValue
*/
rollbackSelectedValue() {
let selectedValue = this.get('selectedValue');
if (!isNone(selectedValue)) {
let isLink = this.get('isLink');
if (!selectedValue.get('isNew')) {
//selectedValue.rollbackAll();
if (isLink) {
selectedValue.set('endRoleStr', this.get('_endRoleStr'));
selectedValue.set('startRoleStr', this.get('_startRoleStr'));
selectedValue.set('endMultiplicity', this.get('_endMultiplicity'));
selectedValue.set('startMultiplicity', this.get('_startMultiplicity'));
} else {
selectedValue.set('attributesStr', this.get('_attributesStr'));
selectedValue.set('methodsStr', this.get('_methodsStr'));
}
} else {
let objectModel = this.get('selectedValueModel');
if (isLink) {
updateStrByLink(selectedValue);
objectModel.set('endRoleTxt', selectedValue.get('endRoleStr'));
objectModel.set('startRoleTxt', selectedValue.get('startRoleStr'));
objectModel.set('endMultiplicity', selectedValue.get('endMultiplicity'));
objectModel.set('startMultiplicity', selectedValue.get('startMultiplicity'));
} else {
updateStrByObjects(selectedValue);
objectModel.set('name', selectedValue.get('nameStr'));
objectModel.set('attributes', selectedValue.get('attributesStr').split('\n'));
objectModel.set('methods', selectedValue.get('methodsStr').split('\n'));
}

this.get('fdDiagramService').updateJointObjectOnDiagram(objectModel.get('id'));
}
}
},

/**
Check data for correctness.

Expand Down
1 change: 0 additions & 1 deletion addon/components/fd-sheets/fd-view-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default FdBaseSheet.extend({
closeSheet() {
let selectedValue = this.get('selectedValue');
if (!isNone(selectedValue)) {
selectedValue.rollbackAll();
this.set('readonlyMode', true);
this.set('selectedValue', undefined);
}
Expand Down
24 changes: 23 additions & 1 deletion addon/components/fd-uml-diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,29 @@ export default Component.extend({
@param {joint.dia.Element} cellView.model
*/
_elementOpenEditForm({ model }) {
this.get('openEditFormAction')(model.get('objectModel'));
let object = {
data: undefined,
selectedValueModel: model.get('objectModel'),
isLink: false
};

let store = this.get('store');
let modelName = 'fd-dev-association';
let objectId = object.selectedValueModel.get('repositoryObject').slice(1, -1);

switch (object.selectedValueModel.get('primitive.$type')) {
case 'STORMCASE.UML.cad.Composition, UMLCAD':
modelName = 'fd-dev-aggregation';
// eslint-disable-next-line no-fallthrough
case 'STORMCASE.UML.cad.Association, UMLCAD':
object.isLink = true;
object.data = store.peekRecord(`${modelName}`, objectId);
break;
default:
object.data = store.peekRecord('fd-dev-class', objectId);
}

this.get('openEditFormAction')(object);
},

/**
Expand Down
6 changes: 6 additions & 0 deletions addon/services/fd-sheet-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default Service.extend(Evented, {
this.trigger('closeSheetTriggered', sheetName);
this.set(`sheetSettings.visibility.${sheetName}`, false);
this.set(`sheetSettings.expanded.${sheetName}`, false);
this.set(`sheetSettings.currentItem.${sheetName}`, undefined);
let currentSheet = $(`.fd-sheet.${sheetName}`);

if ($('.fd-sheet.visible').length < 2) {
Expand Down Expand Up @@ -218,6 +219,11 @@ export default Service.extend(Evented, {

if (!isNone(currentItemModel)) {
isDirty = hasChanges(currentItemModel) && !currentItemModel.get('isDeleted');

// TODO: в будущем можно сделать для каждого листа свой rollbackAll и в нем проверять на isNew.
if (currentItemModel.get('isNew') && sheetName === 'edit-diagram-object-sheet') {
isDirty = false;
}
}

return isDirty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
{{fd-sheets/fd-sheets-tool-bar
sheetComponentName=sheetComponentName
readonlyMode=readonlyMode
isNewModel=selectedValue.isNew
sheetButtons=(array 'save' 'share')
shareSheetValue=selectedValue
saveSheet=(action 'save')
}}
{{flexberry-textbox
value=computedTitle
placeholder=(t "components.fd-sheets-tool-bar.placeholder-caption")
readonly=readonlyMode
readonly=(and (not selectedValue.isNew) readonlyMode)
class='form-header fluid'
maxlength=maxlength
}}
Expand Down