Skip to content

Commit

Permalink
Add new duplicate modal to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonbsn committed Apr 24, 2024
1 parent d51fa53 commit c461d2f
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions app/angular/workspace/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import shareModelModal from "../components/shareModelModal";
import iconConceptual from "../components/icons/conceptual";
import iconLogic from "../components/icons/logic";


const ListController = function (
$state,
$rootScope,
Expand Down Expand Up @@ -48,16 +47,18 @@ const ListController = function (
ctrl.loading = loading;
};

const mapData = (model) => {
if (model.type == "conceptual") {
model.typeName = $filter('translate')("Conceptual");
} else {
model.typeName = $filter('translate')("Logical");
}
model.authorName = AuthService.loggeduserName;
return model;
};

const mapListData = (models) => {
return models.map((model) => {
if (model.type == "conceptual") {
model.typeName = $filter('translate')("Conceptual");
} else {
model.typeName = $filter('translate')("Logical");
}
model.authorName = AuthService.loggeduserName;
return model;
});
return models.map(mapData);
};

const doDelete = (model) => {
Expand Down Expand Up @@ -150,28 +151,26 @@ const ListController = function (
ctrl.duplicateModel = (model) => {
const modalInstance = $uibModal.open({
animation: true,
template: '<duplicate-model-modal suggested-name="$ctrl.suggestedName" close="$close(result)" dismiss="$dismiss(reason)"></duplicate-model-modal>',
template: `<duplicate-model-modal
suggested-name="$ctrl.suggestedName"
close="$close(result)"
dismiss="$dismiss(reason)"
user-id=$ctrl.userId
model-id=$ctrl.modelId>
</duplicate-model-modal>`,
controller: function() {
const $ctrl = this;
$ctrl.suggestedName = $filter('translate')("MODEL_NAME (copy)", { name: model.name });
$ctrl.modelId = model._id;
$ctrl.userId = model.who;
},
controllerAs: '$ctrl',
});
modalInstance.result.then((newName) => {
showLoading(true);
const duplicatedModel = {
id: "",
name: newName,
type: model.type,
model: model.model,
user: model.who,
};
ModelAPI.saveModel(duplicatedModel).then((newModel) => {
newModel.authorName = model.authorName;
newModel.typeName = model.typeName;
ctrl.models.push(newModel);
showLoading(false);
});
}).result;
modalInstance.then((newModel) => {
ctrl.models.push(mapData(newModel));
ctrl.showFeedback($filter('translate')("Successfully duplicated!"), true, 'success');
}).catch(error => {
console.error(error);
});
};

Expand All @@ -188,7 +187,6 @@ const ListController = function (
controllerAs: '$ctrl',
}).result;
modalInstance.then(() => {
console.log("Successfully share config saved!");
ctrl.showFeedback($filter('translate')("Sharing configuration has been updated successfully!"), true, 'success');
}).catch((reason) => {
console.log("Modal dismissed with reason", reason);
Expand Down

0 comments on commit c461d2f

Please sign in to comment.