Move logic to tree service and navigarion service

This commit is contained in:
David Sheiles
2019-02-28 17:29:40 +11:00
parent 45dfef78bd
commit d3fb614d25
12 changed files with 25 additions and 70 deletions

View File

@@ -13,7 +13,7 @@
* Section navigation and search, and maintain their state for the entire application lifetime
*
*/
function navigationService($routeParams, $location, $q, $timeout, $injector, eventsService, umbModelMapper, treeService, appState) {
function navigationService($routeParams, $location, $q, $timeout, $injector, eventsService, umbModelMapper, treeService, appState, editorState) {
//the promise that will be resolved when the navigation is ready
var navReadyPromise = $q.defer();
@@ -26,6 +26,19 @@ function navigationService($routeParams, $location, $q, $timeout, $injector, eve
navReadyPromise.resolve(mainTreeApi);
});
eventsService.on("treeService.removeNode", function (e, args) {
//check to see if the current page has been removed
var currentEditorState = editorState.getCurrent()
console.log("currentEditorState", currentEditorState);
if (currentEditorState != null && currentEditorState.id === args.node.id) {
//current page is loaded, so navigate to root
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
//A list of query strings defined that when changed will not cause a reload of the route
var nonRoutingQueryStrings = ["mculture", "cculture", "lq"];
var retainedQueryStrings = ["mculture"];

View File

@@ -350,6 +350,9 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
parent.children.splice(parent.children.indexOf(treeNode), 1);
parent.hasChildren = parent.children.length !== 0;
//Notify that the node has been removed
eventsService.emit("treeService.removeNode", { node: treeNode });
},
/**

View File

@@ -22,13 +22,6 @@ function DataTypeDeleteController($scope, $location, dataTypeResource, treeServi
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
});
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted DataType is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
};
$scope.performContainerDelete = function () {

View File

@@ -6,8 +6,8 @@
* @description
* The controller for deleting content
*/
function DocumentTypesDeleteController($scope, $location, dataTypeResource, contentTypeResource, treeService, navigationService, appState) {
function DocumentTypesDeleteController($scope, dataTypeResource, contentTypeResource, treeService, navigationService) {
$scope.performDelete = function() {
//mark it for deletion (used in the UI)
@@ -22,11 +22,6 @@ function DocumentTypesDeleteController($scope, $location, dataTypeResource, cont
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted doctype is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section );
}
});
};

View File

@@ -18,14 +18,6 @@ function MacrosDeleteController($scope, $location, macroResource, navigationServ
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted Macro is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
}

View File

@@ -21,12 +21,6 @@ function MediaTypesDeleteController($scope, $location, dataTypeResource, mediaTy
// TODO: Need to sync tree, etc...
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted MediaType is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
};

View File

@@ -6,7 +6,7 @@
* @description
* The controller for deleting member types
*/
function MemberTypesDeleteController($scope, $location, memberTypeResource, treeService, navigationService, appState) {
function MemberTypesDeleteController($scope, memberTypeResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -22,11 +22,6 @@ function MemberTypesDeleteController($scope, $location, memberTypeResource, tree
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted MemberType is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
};

View File

@@ -6,7 +6,7 @@
* @description
* The controller for deleting partial view macros
*/
function PartialViewMacrosDeleteController($scope, $location, codefileResource, treeService, navigationService, appState) {
function PartialViewMacrosDeleteController($scope, codefileResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -22,11 +22,6 @@ function PartialViewMacrosDeleteController($scope, $location, codefileResource,
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted PartialViewMacro is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
};

View File

@@ -6,7 +6,7 @@
* @description
* The controller for deleting partial views
*/
function PartialViewsDeleteController($scope, $location, codefileResource, treeService, navigationService, appState) {
function PartialViewsDeleteController($scope, codefileResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -25,12 +25,6 @@ function PartialViewsDeleteController($scope, $location, codefileResource, treeS
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted PartialView is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
}, function (err) {
$scope.currentNode.loading = false;
$scope.error = err;

View File

@@ -6,7 +6,7 @@
* @description
* The controller for deleting scripts
*/
function ScriptsDeleteController($scope, $location, codefileResource, treeService, navigationService, appState) {
function ScriptsDeleteController($scope, codefileResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -22,12 +22,6 @@ function ScriptsDeleteController($scope, $location, codefileResource, treeServic
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted Script is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
};

View File

@@ -6,7 +6,7 @@
* @description
* The controller for deleting stylesheets
*/
function StyleSheetsDeleteController($scope, $location, codefileResource, treeService, navigationService, appState) {
function StyleSheetsDeleteController($scope, codefileResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -18,12 +18,6 @@ function StyleSheetsDeleteController($scope, $location, codefileResource, treeSe
$scope.currentNode.loading = false;
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted StyleSheet is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
});
};

View File

@@ -6,7 +6,7 @@
* @description
* The controller for the template delete dialog
*/
function TemplatesDeleteController($scope, $location, templateResource, treeService, navigationService, appState) {
function TemplatesDeleteController($scope, templateResource, treeService, navigationService) {
$scope.performDelete = function() {
@@ -26,13 +26,6 @@ function TemplatesDeleteController($scope, $location, templateResource, treeServ
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
if ("/" + $scope.currentNode.routePath.toLowerCase() === $location.path().toLowerCase()) {
//The deleted Template is open, so redirect
var section = appState.getSectionState("currentSection");
$location.path("/" + section);
}
}, function (err) {
$scope.currentNode.loading = false;
$scope.error = err;