From c461d2f87e704990e4b490b8ae0d6b243cc7c0d1 Mon Sep 17 00:00:00 2001 From: Milton Bittencourt Date: Wed, 24 Apr 2024 15:10:28 -0300 Subject: [PATCH] Add new duplicate modal to workspace --- app/angular/workspace/workspace.js | 54 ++++++++++++++---------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/app/angular/workspace/workspace.js b/app/angular/workspace/workspace.js index e6ca48cb..db0ecace 100644 --- a/app/angular/workspace/workspace.js +++ b/app/angular/workspace/workspace.js @@ -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, @@ -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) => { @@ -150,28 +151,26 @@ const ListController = function ( ctrl.duplicateModel = (model) => { const modalInstance = $uibModal.open({ animation: true, - template: '', + template: ` + `, 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); }); }; @@ -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);