From 1100c66ce03a059ebe7ece9734e799b49b3a5a9e Mon Sep 17 00:00:00 2001 From: WuKong Date: Sat, 23 Dec 2017 21:49:35 +0100 Subject: moonv4 cleanup Change-Id: Icef927f3236d985ac13ff7376f6ce6314b2b39b0 Signed-off-by: WuKong --- .../app/model/edit/metadata/metadata-edit.tpl.html | 99 +++++ .../app/model/edit/metadata/metadata-list.tpl.html | 491 +++++++++++++++++++++ .../app/model/edit/metadata/metadata.edit.dir.js | 332 ++++++++++++++ .../app/model/edit/metadata/metadata.list.dir.js | 372 ++++++++++++++++ 4 files changed, 1294 insertions(+) create mode 100755 moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html create mode 100755 moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html create mode 100755 moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js create mode 100755 moon_gui/static/app/model/edit/metadata/metadata.list.dir.js (limited to 'moon_gui/static/app/model/edit/metadata') diff --git a/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html b/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html new file mode 100755 index 00000000..2616be1c --- /dev/null +++ b/moon_gui/static/app/model/edit/metadata/metadata-edit.tpl.html @@ -0,0 +1,99 @@ +
+ + + +
+ +
+ +
+ + + + + +
+
+ +
+ +
+ + + + + +
+ +
+ +
+ + + +
+ + + +
+ Name is required +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ + + + Create + + + + +
+ +
+ +
+ +
+ +
\ No newline at end of file diff --git a/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html b/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html new file mode 100755 index 00000000..30a42dbc --- /dev/null +++ b/moon_gui/static/app/model/edit/metadata/metadata-list.tpl.html @@ -0,0 +1,491 @@ +
+ +
+ +
+ +
+ +

List of associated Subject Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdNameDescription
+ + + + Remove + + + + +
+ + + +
+ +
There is no Subjects
+ +
+ +
+ +
+ +
+ +
+ +

Add a Subject Category

+ +
+ +
+ + + +
+ +
+ +
+ +
+ +

List associated of Object Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdNameDescription
+ + + + Remove + + + + + +
+ + + +
+ +
There is no Objects
+ +
+ +
+ +
+ +
+ +
+ +

Add an Object Category

+ +
+ +
+ + + +
+ +
+ +
+ +
+ +

List associated of Action Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdNameDescription
+ + + + Remove + + + + +
+ + + +
+ +
There is no Actions
+ +
+ +
+ +
+ +
+ +
+ +

Add an Action Category

+ +
+ +
. + + + +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +

List of associated Subject Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Name
There is no Subjects
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

List associated of Object Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Name
There is no Objects
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +

List associated of Action Categories

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Name
There is no Actions
+ +
+ +
+ +
+ +
+ +
+
+
\ No newline at end of file diff --git a/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js b/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js new file mode 100755 index 00000000..10df83b0 --- /dev/null +++ b/moon_gui/static/app/model/edit/metadata/metadata.edit.dir.js @@ -0,0 +1,332 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonMetaDataEdit', moonMetaDataEdit); + + moonMetaDataEdit.$inject = []; + + function moonMetaDataEdit() { + + return { + templateUrl : 'html/model/edit/metadata/metadata-edit.tpl.html', + bindToController : true, + controller : moonMetaDataEditController, + controllerAs : 'edit', + scope : { + //Type can be 'ACTION', 'OBJECT', 'SUBJECT' + metaDataType: '=', + metaRule : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonMetaDataEditController', moonMetaDataEditController); + + moonMetaDataEditController.$inject = ['$scope', 'metaDataService', 'META_DATA_CST', 'alertService', + '$translate', 'formService', 'metaRuleService', 'utilService']; + + function moonMetaDataEditController($scope, metaDataService, META_DATA_CST, alertService, + $translate, formService, metaRuleService, utilService) { + + var edit = this; + + edit.metaDataType = $scope.edit.metaDataType; + edit.metaRule = $scope.edit.metaRule; + + edit.fromList = true; + + edit.laoading = false; + + edit.form = {}; + + edit.metaData = { name: null, description: null}; + + edit.list = []; + + edit.create = createMetaData; + edit.addToMetaRule = addToMetaRule; + edit.deleteMetaData = deleteMetaData; + + activate(); + + /* + * + */ + + function activate(){ + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.findAllWithCallback(callBackList); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.findAllWithCallback(callBackList); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.findAllWithCallback(callBackList); + break; + + default : + + edit.list = []; + break; + + } + + function callBackList(list){ + + edit.list = list; + + } + + } + + /** + * Add + */ + + function addToMetaRule(){ + + if(!edit.selectedMetaData){ + + return; + + } + + var metaRuleToSend = edit.metaRule; + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaRuleToSend.subject_categories.push(edit.selectedMetaData.id); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaRuleToSend.object_categories.push(edit.selectedMetaData.id); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaRuleToSend.action_categories.push(edit.selectedMetaData.id); + break; + } + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: metaRuleToSend.name }).then( function(translatedValue) { + + alertService.alertSuccess(translatedValue); + + }); + + metaRuleToSend = utilService.transformOne(data, 'meta_rules'); + + $scope.$emit('event:updateMetaRuleFromMetaDataAddSuccess', metaRuleToSend); + + stopLoading(); + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: metaRuleToSend.name, reason: reason.message}).then( function(translatedValue) { + + alertService.alertError(translatedValue); + + }); + + stopLoading(); + + } + + } + + /** + * Create + */ + + function createMetaData() { + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + } else { + + startLoading(); + + var metaDataToSend = angular.copy(edit.metaData); + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.add(metaDataToSend, createSuccess, createError); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.add(metaDataToSend, createSuccess, createError); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.add(metaDataToSend, createSuccess, createError); + break; + } + + } + + function createSuccess(data) { + + var created = {}; + + switch(edit.metaDataType){ + + case META_DATA_CST.TYPE.SUBJECT: + + created = utilService.transformOne(data, 'subject_categories'); + break; + + case META_DATA_CST.TYPE.OBJECT: + + created = utilService.transformOne(data, 'object_categories'); + break; + + case META_DATA_CST.TYPE.ACTION: + + created = utilService.transformOne(data, 'action_categories'); + break; + } + + $translate('moon.model.metadata.edit.create.success', { name: created.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + stopLoading(); + + edit.list.push(created); + + displayList(); + + } + + function createError(reason) { + + $translate('moon.model.metadata.edit.create.error', { name: metaDataToSend.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + function deleteMetaData(){ + + if(!edit.selectedMetaData){ + + return; + + } + + startLoading(); + + var metaDataToDelete = angular.copy(edit.selectedMetaData); + + switch(edit.metaDataType){ + case META_DATA_CST.TYPE.SUBJECT: + + metaDataService.subject.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + + case META_DATA_CST.TYPE.OBJECT: + + metaDataService.object.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + + case META_DATA_CST.TYPE.ACTION: + + metaDataService.action.delete(metaDataToDelete, deleteSuccess, deleteError); + break; + } + + + function deleteSuccess(data) { + + $translate('moon.model.metadata.edit.delete.success', { name: metaDataToDelete.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + metaRuleService.findOneWithMetaData(edit.metaRule.id).then( function(metaRule){ + + edit.metaRule = metaRule; + + cleanSelectedValue(); + + activate(); + + stopLoading(); + + $scope.$emit('event:deleteMetaDataFromMetaDataAddSuccess', edit.metaRule); + + }); + + } + + function deleteError(reason) { + + $translate('moon.model.metadata.edit.delete.error', { name: metaDataToDelete.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + } + + function cleanSelectedValue(){ + + delete edit.selectedMetaData; + + } + + function startLoading(){ + + edit.loading = true; + + } + + function stopLoading(){ + + edit.loading = false; + + } + + function displayList(){ + + edit.fromList = true; + + } + + } + +})(); \ No newline at end of file diff --git a/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js b/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js new file mode 100755 index 00000000..beb2ed86 --- /dev/null +++ b/moon_gui/static/app/model/edit/metadata/metadata.list.dir.js @@ -0,0 +1,372 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonMetaDataList', moonMetaDataList); + + moonMetaDataList.$inject = []; + + function moonMetaDataList() { + + return { + templateUrl : 'html/model/edit/metadata/metadata-list.tpl.html', + bindToController : true, + controller : moonMetaDataListController, + controllerAs : 'list', + scope : { + metaRule: '=', + editMode: '=', + // shortDisplay : boolean value + shortDisplay: '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonMetaDataListController', moonMetaDataListController); + + moonMetaDataListController.$inject = ['$scope', '$rootScope', 'metaDataService', '$translate', 'alertService', 'metaRuleService', 'META_DATA_CST', 'utilService']; + + function moonMetaDataListController($scope, $rootScope, metaDataService, $translate, alertService, metaRuleService, META_DATA_CST, utilService){ + + var list = this; + + list.metaRule = $scope.list.metaRule; + list.editMode = $scope.list.editMode; + list.shortDisplay = $scope.list.shortDisplay; + + list.typeOfSubject = META_DATA_CST.TYPE.SUBJECT; + list.typeOfObject = META_DATA_CST.TYPE.OBJECT; + list.typeOfAction = META_DATA_CST.TYPE.ACTION; + + list.unMapSub = unMapSub; + list.unMapObj = unMapObj; + list.unMapAct = unMapAct; + + // list.deleteSub = deleteSub; + // list.deleteObj = deleteObj; + // list.deleteAct = deleteAct; + + list.getSubjectCategories = getSubjectCategories; + list.getObjectCategories = getObjectCategories; + list.getActionCategories = getActionCategories; + + activate(); + + function activate(){ + + manageSubjectCategories(); + + manageObjectCategories(); + + manageActionCategories(); + + } + + var rootListeners = { + + 'event:updateMetaRuleFromMetaDataAddSuccess': $rootScope.$on('event:updateMetaRuleFromMetaDataAddSuccess', updateMetaRuleCategories), + + 'event:deleteMetaDataFromMetaDataAddSuccess': $rootScope.$on('event:deleteMetaDataFromMetaDataAddSuccess', deleteMetaRuleCategories) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + + function manageSubjectCategories(){ + + list.loadingCatSub = true; + + metaDataService.subject.findSomeWithCallback(list.metaRule.subject_categories, function(categories){ + + list.catSub = categories; + list.loadingCatSub = false; + + }); + } + + function manageObjectCategories(){ + + list.loadingCatObj = true; + + metaDataService.object.findSomeWithCallback(list.metaRule.object_categories, function(categories){ + + list.catObj = categories; + list.loadingCatObj = false; + + }); + + } + + function manageActionCategories(){ + + list.loadingCatAct = true; + + metaDataService.action.findSomeWithCallback(list.metaRule.action_categories, function(categories){ + + list.catAct = categories; + list.loadingCatAct = false; + + }); + + } + + + /** + * UnMap + */ + + function unMapSub(subject){ + + subject.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.subject_categories = _.without(metaRuleToSend.subject_categories, subject.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + subject.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + subject.loader = false; + + } + + } + + function unMapObj(object){ + + object.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.object_categories = _.without(metaRuleToSend.object_categories, object.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + object.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + object.loader = false; + + } + + } + + function unMapAct(action){ + + action.loader = true; + + var metaRuleToSend = angular.copy(list.metaRule); + + metaRuleToSend.action_categories = _.without(metaRuleToSend.action_categories, action.id); + + metaRuleService.update(metaRuleToSend, updateMetaRuleSuccess, updateMetaRuleError); + + function updateMetaRuleSuccess(data){ + + $translate('moon.model.metarules.update.success', { metaRuleName: list.metaRule.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + list.metaRule = metaRuleService.findMetaDataFromMetaRule(utilService.transformOne(data, 'meta_rules')); + + activate(); + + action.loader = false; + + } + + function updateMetaRuleError(reason){ + + $translate('moon.model.metarules.update.error', { metaRuleName: list.metaRule.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + action.loader = false; + + } + + } + + // /** + // * Delete + // */ + // + // function deleteSub(subject){ + // + // subject.loader = true; + // + // metaDataService.subject.delete(subject, deleteSubSuccess, deleteSubError); + // + // function deleteSubSuccess(data){ + // + // $translate('moon.model.metadata.subject.delete.success', { subjectName: subject.name }).then( function(translatedValue) { + // alertService.alertSuccess(translatedValue); + // }); + // + // removeSubFromSubList(subject); + // + // subject.loader = false; + // + // } + // + // function deleteSubError(reason){ + // + // $translate('moon.model.metadata.subject.delete.error', + // { subjectName: subject.name, reason: reason.message}).then( function(translatedValue) { + // alertService.alertError(translatedValue); + // }); + // + // subject.loader = false; + // + // } + // } + // + // function deleteObj(object){ + // + // object.loader = true; + // + // metaDataService.object.delete(object, deleteObjSuccess, deleteObjError); + // + // function deleteObjSuccess(data){ + // + // $translate('moon.model.metadata.object.delete.success', { objectName: object.name }).then( function(translatedValue) { + // alertService.alertSuccess(translatedValue); + // }); + // + // removeObjFromObjList(object); + // /*list.catSub = metaDataService.subject.findSome(list.metaRule.subject_categories); + // list.catObj = metaDataService.object.findSome(list.metaRule.object_categories); + // list.catAct = metaDataService.action.findSome(list.metaRule.action_categories);*/ + // + // object.loader = false; + // + // } + // + // function deleteObjError(reason){ + // + // $translate('moon.model.metadata.object.delete.error', { objectName: object.name, reason: reason.message}).then( function(translatedValue) { + // alertService.alertError(translatedValue); + // }); + // + // object.loader = false; + // } + // } + // + // function deleteAct(action){ + // + // action.loader = true; + // + // metaDataService.action.delete(action, deleteActSuccess, deleteActError); + // + // function deleteActSuccess(data){ + // + // $translate('moon.model.metadata.action.delete.success', { actionName: action.name }).then( function(translatedValue) { + // alertService.alertSuccess(translatedValue); + // }); + // + // removeActFromActList(action); + // + // action.loader = false; + // + // } + // + // function deleteActError(reason){ + // + // $translate('moon.model.metadata.action.delete.error', { actionName: action.name, reason: reason.message}).then( function(translatedValue) { + // alertService.alertError(translatedValue); + // }); + // + // action.loader = false; + // + // } + // } + + function getSubjectCategories(){ + return list.catSub ? list.catSub : []; + } + + function getObjectCategories(){ + return list.catObj ? list.catObj : []; + } + + function getActionCategories(){ + return list.catAct ? list.catAct : []; + } + + // function removeSubFromSubList(subject){ + // list.catSub = _.without(list.catSub, subject); + // } + // + // function removeObjFromObjList(object){ + // list.catObj = _.without(list.catObj, object); + // } + // + // function removeActFromActList(action){ + // list.catAct = _.without(list.catAct, action); + // } + + function updateMetaRuleCategories( event, metaRule){ + + list.metaRule = metaRule; + + activate(); + + } + + + function deleteMetaRuleCategories( event, metaRule){ + + list.metaRule = metaRule; + + activate(); + + } + + } + +})(); \ No newline at end of file -- cgit 1.2.3-korg