Merge branch 'temp-U4-9481' into dev-v7.6
# Conflicts: # src/Umbraco.Core/Services/FileService.cs
This commit is contained in:
@@ -735,6 +735,26 @@ namespace Umbraco.Core.Services
|
||||
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)
|
||||
{
|
||||
using (var uow = _fileUowProvider.GetUnitOfWork())
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Umbraco.Core.Services
|
||||
public interface IFileService : IService
|
||||
{
|
||||
IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames);
|
||||
void CreatePartialViewFolder(string folderPath);
|
||||
void CreatePartialViewMacroFolder(string folderPath);
|
||||
void DeletePartialViewFolder(string folderPath);
|
||||
void DeletePartialViewMacroFolder(string folderPath);
|
||||
IPartialView GetPartialView(string path);
|
||||
|
||||
@@ -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
|
||||
* <pre>
|
||||
* codefileResource.createContainer("partialViews", "folder%2ffolder", "folder")
|
||||
* .then(function(data) {
|
||||
* alert('its here!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @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: encodeURIComponent(name) })),
|
||||
'Failed to create a folder under parent id ' + parentId);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService) {
|
||||
function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService, appState) {
|
||||
|
||||
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 (saved) {
|
||||
|
||||
navigationService.hideMenu();
|
||||
|
||||
navigationService.syncTree({
|
||||
tree: "partialViewMacros",
|
||||
path: saved.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() {
|
||||
|
||||
@@ -47,12 +47,12 @@
|
||||
<!-- Create folder -->
|
||||
<div class="umb-pane" ng-if="vm.creatingFolder">
|
||||
<form novalidate name="createFolderForm"
|
||||
ng-submit="vm.createFolder()"
|
||||
val-form-manager>
|
||||
ng-submit="vm.createFolder(createFolderForm)"
|
||||
val-form-manager>
|
||||
|
||||
<div ng-show="error">
|
||||
<h5 class="text-error">{{error.errorMsg}}</h5>
|
||||
<p class="text-error">{{error.data.message}}</p>
|
||||
<div ng-show="vm.createFolderError">
|
||||
<h5 class="text-error">{{vm.createFolderError.errorMsg}}</h5>
|
||||
<p class="text-error">{{vm.createFolderError.data.message}}</p>
|
||||
</div>
|
||||
|
||||
<umb-control-group label="Enter a folder name" hide-label="false">
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function PartialViewsCreateController($scope, codefileResource, $location, navigationService) {
|
||||
function PartialViewsCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService, appState) {
|
||||
|
||||
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(saved) {
|
||||
|
||||
navigationService.hideMenu();
|
||||
|
||||
navigationService.syncTree({
|
||||
tree: "partialViews",
|
||||
path: saved.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() {
|
||||
|
||||
@@ -47,12 +47,12 @@
|
||||
<!-- Create folder -->
|
||||
<div class="umb-pane" ng-if="vm.creatingFolder">
|
||||
<form novalidate name="createFolderForm"
|
||||
ng-submit="vm.createFolder()"
|
||||
val-form-manager>
|
||||
ng-submit="vm.createFolder(createFolderForm)"
|
||||
val-form-manager>
|
||||
|
||||
<div ng-show="error">
|
||||
<h5 class="text-error">{{error.errorMsg}}</h5>
|
||||
<p class="text-error">{{error.data.message}}</p>
|
||||
<div ng-show="vm.createFolderError">
|
||||
<h5 class="text-error">{{vm.createFolderError.errorMsg}}</h5>
|
||||
<p class="text-error">{{vm.createFolderError.data.message}}</p>
|
||||
</div>
|
||||
|
||||
<umb-control-group label="Enter a folder name" hide-label="false">
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function ScriptsCreateController($scope, $location, navigationService) {
|
||||
function ScriptsCreateController($scope, $location, navigationService, formHelper, codefileResource, localizationService, appState) {
|
||||
|
||||
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 (saved) {
|
||||
|
||||
navigationService.hideMenu();
|
||||
|
||||
navigationService.syncTree({
|
||||
tree: "scripts",
|
||||
path: saved.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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
<div class="umb-pane" ng-if="vm.creatingFolder">
|
||||
<form novalidate name="createFolderForm"
|
||||
ng-submit="vm.createFolder()"
|
||||
ng-submit="vm.createFolder(createFolderForm)"
|
||||
val-form-manager>
|
||||
|
||||
<div ng-show="error">
|
||||
<h5 class="text-error">{{error.errorMsg}}</h5>
|
||||
<p class="text-error">{{error.data.message}}</p>
|
||||
<div ng-show="vm.createFolderError">
|
||||
<h5 class="text-error">{{vm.createFolderError.errorMsg}}</h5>
|
||||
<p class="text-error">{{vm.createFolderError.data.message}}</p>
|
||||
</div>
|
||||
|
||||
<umb-control-group label="Enter a folder name" hide-label="false">
|
||||
|
||||
@@ -56,6 +56,61 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to create a container/folder in 'partialViews', 'partialViewMacros' or 'scripts'
|
||||
/// </summary>
|
||||
/// <param name="type">'partialViews', 'partialViewMacros' or 'scripts'</param>
|
||||
/// <param name="parentId">The virtual path of the parent.</param>
|
||||
/// <param name="name">The name of the container/folder</param>
|
||||
/// <returns></returns>
|
||||
[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)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to get a specific file from disk via the FileService
|
||||
/// </summary>
|
||||
@@ -70,7 +125,6 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
|
||||
virtualPath = System.Web.HttpUtility.UrlDecode(virtualPath);
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user