From cda47ed5368be1061cd3edc96ce14eb06f60dfcf Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 6 Feb 2017 14:46:48 +0100 Subject: [PATCH 1/4] add client side logic for scripts folder creation --- .../src/common/resources/codefile.resource.js | 32 +++++++++++++++ .../src/views/scripts/create.controller.js | 40 +++++++++++++++++-- .../src/views/scripts/create.html | 8 ++-- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js index e83bb4f14e..b6a56d336b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js @@ -205,6 +205,38 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) { "codeFileApiBaseUrl", "GetScaffold?type=" + type + "&id=" + id + "&snippetName=" + snippetName)), "Failed to get scaffold for" + type); + }, + + /** + * @ngdoc method + * @name umbraco.resources.codefileResource#createContainer + * @methodOf umbraco.resources.codefileResource + * + * @description + * Creates a container/folder + * + * ##usage + *
+         * codefileResource.createContainer("partialViews", "folder%2ffolder", "folder")
+         *    .then(function(data) {
+         *        alert('its here!');
+         *    });
+         * 
+ * + * @param {string} File type: (scripts, partialViews, partialViewMacros). + * @param {string} Parent Id: url encoded path + * @param {string} Container name + * @returns {Promise} resourcePromise object. + * + */ + + createContainer: function(type, parentId, name) { + return umbRequestHelper.resourcePromise( + $http.post(umbRequestHelper.getApiUrl( + "codeFileApiBaseUrl", + "PostCreateContainer", + { type: type, parentId: parentId, name: name })), + 'Failed to create a folder under parent id ' + parentId); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js index 1729693d83..89ff9e6643 100644 --- a/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js @@ -1,13 +1,15 @@ (function () { "use strict"; - function ScriptsCreateController($scope, $location, navigationService) { + function ScriptsCreateController($scope, $location, navigationService, formHelper, codefileResource, localizationService) { var vm = this; var node = $scope.dialogOptions.currentNode; + var localizeCreateFolder = localizationService.localize("defaultdialog_createFolder"); vm.creatingFolder = false; vm.folderName = ""; + vm.createFolderError = ""; vm.fileExtension = ""; vm.createFile = createFile; @@ -23,8 +25,40 @@ vm.creatingFolder = true; } - function createFolder() { - + function createFolder(form) { + + if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { + + codefileResource.createContainer("scripts", node.id, vm.folderName).then(function(path) { + + navigationService.hideMenu(); + + navigationService.syncTree({ + tree: "scripts", + path: path, + forceReload: true, + activate: true + }); + + formHelper.resetForm({ + scope: $scope + }); + + var section = appState.getSectionState("currentSection"); + + }, function(err) { + + vm.createFolderError = err; + + //show any notifications + if (angular.isArray(err.data.notifications)) { + for (var i = 0; i < err.data.notifications.length; i++) { + notificationsService.showNotification(err.data.notifications[i]); + } + } + }); + } + } } diff --git a/src/Umbraco.Web.UI.Client/src/views/scripts/create.html b/src/Umbraco.Web.UI.Client/src/views/scripts/create.html index d57ead3b15..22b238606d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/scripts/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/scripts/create.html @@ -22,12 +22,12 @@
-
-
{{error.errorMsg}}
-

{{error.data.message}}

+
+
{{vm.createFolderError.errorMsg}}
+

{{vm.createFolderError.data.message}}

From 00982d4278e293a06adb8a3fa70c75eafe7c937c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 6 Feb 2017 15:04:46 +0100 Subject: [PATCH 2/4] add client side logic for partial views folder creation --- .../views/partialviews/create.controller.js | 37 ++++++++++++++++++- .../src/views/partialviews/create.html | 10 ++--- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js index 5aeaa28935..6fc2fff3a7 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js @@ -1,14 +1,17 @@ (function () { "use strict"; - function PartialViewsCreateController($scope, codefileResource, $location, navigationService) { + function PartialViewsCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService) { var vm = this; var node = $scope.dialogOptions.currentNode; + var localizeCreateFolder = localizationService.localize("defaultdialog_createFolder"); vm.snippets = []; vm.showSnippets = false; vm.creatingFolder = false; + vm.createFolderError = ""; + vm.folderName = ""; vm.createPartialView = createPartialView; vm.showCreateFolder = showCreateFolder; @@ -39,8 +42,38 @@ vm.creatingFolder = true; } - function createFolder() { + function createFolder(form) { + if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { + codefileResource.createContainer("partialViews", node.id, vm.folderName).then(function(path) { + + navigationService.hideMenu(); + + navigationService.syncTree({ + tree: "partialViews", + path: path, + forceReload: true, + activate: true + }); + + formHelper.resetForm({ + scope: $scope + }); + + var section = appState.getSectionState("currentSection"); + + }, function(err) { + + vm.createFolderError = err; + + //show any notifications + if (angular.isArray(err.data.notifications)) { + for (var i = 0; i < err.data.notifications.length; i++) { + notificationsService.showNotification(err.data.notifications[i]); + } + } + }); + } } function showCreateFromSnippet() { diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.html b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.html index fc9bf98c4f..7aae1f871a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.html @@ -47,12 +47,12 @@
+ ng-submit="vm.createFolder(createFolderForm)" + val-form-manager> -
-
{{error.errorMsg}}
-

{{error.data.message}}

+
+
{{vm.createFolderError.errorMsg}}
+

{{vm.createFolderError.data.message}}

From 999de5ae1ddab5e429d26804f4b3e738d201ee1b Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 6 Feb 2017 15:05:13 +0100 Subject: [PATCH 3/4] add client side logic for partial view macros folder creation --- .../partialviewmacros/create.controller.js | 37 ++++++++++++++++++- .../src/views/partialviewmacros/create.html | 10 ++--- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js index 3b3fb0f9f5..46d2e1d648 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js @@ -1,14 +1,17 @@ (function () { "use strict"; - function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService) { + function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService) { var vm = this; var node = $scope.dialogOptions.currentNode; + var localizeCreateFolder = localizationService.localize("defaultdialog_createFolder"); vm.snippets = []; vm.showSnippets = false; vm.creatingFolder = false; + vm.createFolderError = ""; + vm.folderName = ""; vm.createPartialViewMacro = createPartialViewMacro; vm.showCreateFolder = showCreateFolder; @@ -39,8 +42,38 @@ vm.creatingFolder = true; } - function createFolder() { + function createFolder(form) { + if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { + codefileResource.createContainer("partialViewMacros", node.id, vm.folderName).then(function(path) { + + navigationService.hideMenu(); + + navigationService.syncTree({ + tree: "partialViewMacros", + path: path, + forceReload: true, + activate: true + }); + + formHelper.resetForm({ + scope: $scope + }); + + var section = appState.getSectionState("currentSection"); + + }, function(err) { + + vm.createFolderError = err; + + //show any notifications + if (angular.isArray(err.data.notifications)) { + for (var i = 0; i < err.data.notifications.length; i++) { + notificationsService.showNotification(err.data.notifications[i]); + } + } + }); + } } function showCreateFromSnippet() { diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.html b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.html index aa8796ae7a..0c5a74c4b0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.html +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.html @@ -47,12 +47,12 @@
+ ng-submit="vm.createFolder(createFolderForm)" + val-form-manager> -
-
{{error.errorMsg}}
-

{{error.data.message}}

+
+
{{vm.createFolderError.errorMsg}}
+

{{vm.createFolderError.data.message}}

From c36000c4ddb50d52286718dba4559426231dec40 Mon Sep 17 00:00:00 2001 From: Emil Wangaa Date: Tue, 7 Feb 2017 10:55:38 +0100 Subject: [PATCH 4/4] Adds create container endpoint for creation folders for scripts, partialviews, partialviewmacros --- src/Umbraco.Core/Services/FileService.cs | 22 +++++++- src/Umbraco.Core/Services/IFileService.cs | 2 + .../src/common/resources/codefile.resource.js | 2 +- .../partialviewmacros/create.controller.js | 6 +- .../views/partialviews/create.controller.js | 6 +- .../src/views/scripts/create.controller.js | 6 +- src/Umbraco.Web/Editors/CodeFileController.cs | 56 ++++++++++++++++++- 7 files changed, 88 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 2105f7af2c..3b842e6875 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -667,7 +667,27 @@ namespace Umbraco.Core.Services .ToArray(); return empty.Union(files.Except(empty)); - } + } + + public void CreatePartialViewFolder(string folderPath) + { + var uow = _fileUowProvider.GetUnitOfWork(); + using (var repository = RepositoryFactory.CreatePartialViewRepository(uow)) + { + ((PartialViewRepository)repository).AddFolder(folderPath); + uow.Commit(); + } + } + + public void CreatePartialViewMacroFolder(string folderPath) + { + var uow = _fileUowProvider.GetUnitOfWork(); + using (var repository = RepositoryFactory.CreatePartialViewMacroRepository(uow)) + { + ((PartialViewMacroRepository)repository).AddFolder(folderPath); + uow.Commit(); + } + } public void DeletePartialViewFolder(string folderPath) { diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs index 453d199bfe..e8f1065219 100644 --- a/src/Umbraco.Core/Services/IFileService.cs +++ b/src/Umbraco.Core/Services/IFileService.cs @@ -11,6 +11,8 @@ namespace Umbraco.Core.Services public interface IFileService : IService { IEnumerable GetPartialViewSnippetNames(params string[] filterNames); + void CreatePartialViewFolder(string folderPath); + void CreatePartialViewMacroFolder(string folderPath); void DeletePartialViewFolder(string folderPath); void DeletePartialViewMacroFolder(string folderPath); IPartialView GetPartialView(string path); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js index b6a56d336b..44454f21e3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/codefile.resource.js @@ -235,7 +235,7 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) { $http.post(umbRequestHelper.getApiUrl( "codeFileApiBaseUrl", "PostCreateContainer", - { type: type, parentId: parentId, name: name })), + { type: type, parentId: parentId, name: encodeURIComponent(name) })), 'Failed to create a folder under parent id ' + parentId); } diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js index 46d2e1d648..6132ba3f89 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/create.controller.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService) { + function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService, appState) { var vm = this; var node = $scope.dialogOptions.currentNode; @@ -45,13 +45,13 @@ function createFolder(form) { if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { - codefileResource.createContainer("partialViewMacros", node.id, vm.folderName).then(function(path) { + codefileResource.createContainer("partialViewMacros", node.id, vm.folderName).then(function (saved) { navigationService.hideMenu(); navigationService.syncTree({ tree: "partialViewMacros", - path: path, + path: saved.path, forceReload: true, activate: true }); diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js index 6fc2fff3a7..95d224b890 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviews/create.controller.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function PartialViewsCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService) { + function PartialViewsCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService, appState) { var vm = this; var node = $scope.dialogOptions.currentNode; @@ -45,13 +45,13 @@ function createFolder(form) { if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { - codefileResource.createContainer("partialViews", node.id, vm.folderName).then(function(path) { + codefileResource.createContainer("partialViews", node.id, vm.folderName).then(function(saved) { navigationService.hideMenu(); navigationService.syncTree({ tree: "partialViews", - path: path, + path: saved.path, forceReload: true, activate: true }); diff --git a/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js b/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js index 89ff9e6643..bb3aedeb4a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/scripts/create.controller.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function ScriptsCreateController($scope, $location, navigationService, formHelper, codefileResource, localizationService) { + function ScriptsCreateController($scope, $location, navigationService, formHelper, codefileResource, localizationService, appState) { var vm = this; var node = $scope.dialogOptions.currentNode; @@ -29,13 +29,13 @@ if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) { - codefileResource.createContainer("scripts", node.id, vm.folderName).then(function(path) { + codefileResource.createContainer("scripts", node.id, vm.folderName).then(function (saved) { navigationService.hideMenu(); navigationService.syncTree({ tree: "scripts", - path: path, + path: saved.path, forceReload: true, activate: true }); diff --git a/src/Umbraco.Web/Editors/CodeFileController.cs b/src/Umbraco.Web/Editors/CodeFileController.cs index bcb6630c0a..6775f84a61 100644 --- a/src/Umbraco.Web/Editors/CodeFileController.cs +++ b/src/Umbraco.Web/Editors/CodeFileController.cs @@ -56,6 +56,61 @@ namespace Umbraco.Web.Editors } } + /// + /// Used to create a container/folder in 'partialViews', 'partialViewMacros' or 'scripts' + /// + /// 'partialViews', 'partialViewMacros' or 'scripts' + /// The virtual path of the parent. + /// The name of the container/folder + /// + [HttpPost] + public CodeFileDisplay PostCreateContainer(string type, string parentId, string name) + { + if (string.IsNullOrWhiteSpace(type) || string.IsNullOrWhiteSpace(name)) + { + throw new HttpResponseException(HttpStatusCode.BadRequest); + } + + // if the parentId is root (-1) then we just need an empty string as we are + // creating the path below and we don't wan't -1 in the path + if (parentId == Core.Constants.System.Root.ToInvariantString()) + { + parentId = string.Empty; + } + + name = System.Web.HttpUtility.UrlDecode(name); + + if (parentId.IsNullOrWhiteSpace() == false) + { + parentId = System.Web.HttpUtility.UrlDecode(parentId); + name = parentId.EnsureEndsWith("/") + name; + } + + var virtualPath = string.Empty; + switch (type) + { + case Core.Constants.Trees.PartialViews: + virtualPath = NormalizeVirtualPath(name, SystemDirectories.PartialViews); + Services.FileService.CreatePartialViewFolder(virtualPath); + break; + case Core.Constants.Trees.PartialViewMacros: + virtualPath = NormalizeVirtualPath(name, SystemDirectories.MacroPartials); + Services.FileService.CreatePartialViewMacroFolder(virtualPath); + break; + case Core.Constants.Trees.Scripts: + virtualPath = NormalizeVirtualPath(name, SystemDirectories.Scripts); + Services.FileService.CreateScriptFolder(virtualPath); + break; + + } + + return new CodeFileDisplay + { + VirtualPath = virtualPath, + Path = Url.GetTreePathFromFilePath(virtualPath) + }; + } + /// /// Used to get a specific file from disk via the FileService /// @@ -70,7 +125,6 @@ namespace Umbraco.Web.Editors } virtualPath = System.Web.HttpUtility.UrlDecode(virtualPath); - switch (type) {