Merge pull request #2166 from umbraco/lars-erik-U4-7580-rename-containers

Make U4-7580 (DocTypes/MediaTypes folder re-nameable feature) work with Deploy
This commit is contained in:
Robert
2017-09-11 11:19:30 +02:00
committed by GitHub
12 changed files with 202 additions and 1 deletions
@@ -77,6 +77,37 @@ namespace Umbraco.Core.Services
}
}
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameContentTypeContainer(int id, string name, int userId = 0)
{
return RenameTypeContainer(id, name, Constants.ObjectTypes.DocumentTypeContainerGuid);
}
private Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameTypeContainer(int id, string name, Guid typeCode)
{
var evtMsgs = EventMessagesFactory.Get();
var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateEntityContainerRepository(uow, typeCode))
{
try
{
var container = repo.Get(id);
container.Name = name;
repo.AddOrUpdate(container);
uow.Commit();
uow.Events.Dispatch(SavedContentTypeContainer, this, new SaveEventArgs<EntityContainer>(container, evtMsgs), "RenamedContainer");
return Attempt.Succeed(new OperationStatus<EntityContainer, OperationStatusType>(container, OperationStatusType.Success, evtMsgs));
}
catch (Exception ex)
{
return Attempt.Fail(new OperationStatus<EntityContainer, OperationStatusType>(null, OperationStatusType.FailedExceptionThrown, evtMsgs), ex);
}
}
}
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateMediaTypeContainer(int parentId, string name, int userId = 0)
{
var evtMsgs = EventMessagesFactory.Get();
@@ -116,6 +147,11 @@ namespace Umbraco.Core.Services
}
}
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameMediaTypeContainer(int id, string name, int userId = 0)
{
return RenameTypeContainer(id, name, Constants.ObjectTypes.MediaTypeContainerGuid);
}
public Attempt<OperationStatus> SaveContentTypeContainer(EntityContainer container, int userId = 0)
{
return SaveContainer(
@@ -29,6 +29,7 @@ namespace Umbraco.Core.Services
Attempt<string[]> ValidateComposition(IContentTypeComposition compo);
Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateContentTypeContainer(int parentId, string name, int userId = 0);
Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameContentTypeContainer(int id, string name, int userId = 0);
Attempt<OperationStatus<EntityContainer, OperationStatusType>> CreateMediaTypeContainer(int parentId, string name, int userId = 0);
Attempt<OperationStatus> SaveContentTypeContainer(EntityContainer container, int userId = 0);
Attempt<OperationStatus> SaveMediaTypeContainer(EntityContainer container, int userId = 0);
@@ -307,5 +308,6 @@ namespace Umbraco.Core.Services
Attempt<OperationStatus<MoveOperationStatusType>> MoveContentType(IContentType toMove, int containerId);
Attempt<OperationStatus<IMediaType, MoveOperationStatusType>> CopyMediaType(IMediaType toCopy, int containerId);
Attempt<OperationStatus<IContentType, MoveOperationStatusType>> CopyContentType(IContentType toCopy, int containerId);
Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameMediaTypeContainer(int id, string name, int userId = 0);
}
}
@@ -266,6 +266,17 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateContainer", { parentId: parentId, name: name })),
'Failed to create a folder under parent id ' + parentId);
},
renameContainer: function(id, name) {
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl",
"PostRenameContainer",
{ id: id, name: name })),
"Failed to rename the folder with id " + id
);
}
};
@@ -203,6 +203,17 @@ function mediaTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
"PostCreateContainer",
{ parentId: parentId, name: name })),
'Failed to create a folder under parent id ' + parentId);
},
renameContainer: function (id, name) {
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("mediaTypeApiBaseUrl",
"PostRenameContainer",
{ id: id, name: name })),
"Failed to rename the folder with id " + id
);
}
};
@@ -0,0 +1,63 @@
angular.module("umbraco")
.controller("Umbraco.Editors.ContentTypeContainers.RenameController",
[
"$scope",
"$injector",
"navigationService",
"notificationsService",
"localizationService",
function (scope, injector, navigationService, notificationsService, localizationService) {
var notificationHeader;
function reportSuccessAndClose(treeName) {
var lastComma = scope.currentNode.path.lastIndexOf(","),
path = lastComma === -1
? scope.currentNode.path
: scope.currentNode.path.substring(0, lastComma - 1);
navigationService.syncTree({
tree: treeName,
path: path,
forceReload: true,
activate: true
});
localizationService.localize(
"renamecontainer_folderWasRenamed",
[scope.currentNode.name, scope.model.folderName])
.then(function (msg) {
notificationsService.showNotification({
type: 0,
header: notificationHeader,
message: msg
});
});
navigationService.hideMenu();
}
localizationService.localize("renamecontainer_renamed")
.then(function (s) { notificationHeader = s; });
scope.model = {
folderName: scope.currentNode.name
}
scope.renameContainer = function (resourceKey, treeName) {
var resource = injector.get(resourceKey);
resource.renameContainer(scope.currentNode.id, scope.model.folderName)
.then(function () {
reportSuccessAndClose(treeName);
}, function (err) {
scope.error = err;
if (angular.isArray(err.data.notifications)) {
for (var i = 0; i < err.data.notifications.length; i++) {
notificationsService.showNotification(err.data.notifications[i]);
}
}
});
}
}
]);
@@ -0,0 +1,22 @@
<div class="umbracoDialog umb-dialog-body with-footer" ng-controller="Umbraco.Editors.ContentTypeContainers.RenameController" ng-cloak>
<div class="umb-pane">
<form novalidate name="renameFolderForm"
ng-submit="renameContainer('contentTypeResource', 'documenttypes')"
val-form-manager>
<div ng-show="error">
<h5 class="text-error">{{error.errorMsg}}</h5>
<p class="text-error">{{error.data.message}}</p>
</div>
<umb-control-group label="@renamecontainer_enterNewFolderName" hide-label="false">
<input type="text" name="folderName" ng-model="model.folderName" class="umb-textstring textstring input-block-level" umb-auto-focus required />
</umb-control-group>
<button type="submit" class="btn btn-primary"><localize key="general_rename">Rename</localize></button>
</form>
</div>
</div>
@@ -0,0 +1,21 @@
<div class="umbracoDialog umb-dialog-body with-footer" ng-controller="Umbraco.Editors.ContentTypeContainers.RenameController" ng-cloak>
<div class="umb-pane">
<form novalidate name="renameFolderForm"
ng-submit="renameContainer('mediaTypeResource', 'mediatypes')"
val-form-manager>
<div ng-show="error">
<h5 class="text-error">{{error.errorMsg}}</h5>
<p class="text-error">{{error.data.message}}</p>
</div>
<umb-control-group label="@renamecontainer_enterNewFolderName" hide-label="false">
<input type="text" name="folderName" ng-model="model.folderName" class="umb-textstring textstring input-block-level" umb-auto-focus required />
</umb-control-group>
<button type="submit" class="btn btn-primary"><localize key="general_rename">Rename</localize></button>
</form>
</div>
</div>
@@ -29,6 +29,7 @@
<key alias="unpublish">Unpublish</key>
<key alias="refreshNode">Reload</key>
<key alias="republish">Republish entire site</key>
<key alias="rename" version="7.3.0">Rename</key>
<key alias="restore" version="7.3.0">Restore</key>
<key alias="SetPermissionsForThePage">Set permissions for the page %0%</key>
<key alias="chooseWhereToMove">Choose where to move</key>
@@ -431,6 +432,11 @@
<key alias="createListView" version="7.2">Create custom list view</key>
<key alias="removeListView" version="7.2">Remove custom list view</key>
</area>
<area alias="renamecontainer">
<key alias="renamed">Renamed</key>
<key alias="enterNewFolderName">Enter a new folder name here</key>
<key alias="folderWasRenamed">%0% was renamed to %1%</key>
</area>
<area alias="editdatatype">
<key alias="addPrevalue">Add prevalue</key>
<key alias="dataBaseDatatype">Database datatype</key>
@@ -182,6 +182,15 @@ namespace Umbraco.Web.Editors
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public HttpResponseMessage PostRenameContainer(int id, string name)
{
var result = Services.ContentTypeService.RenameContentTypeContainer(id, name, Security.CurrentUser.Id);
return result
? Request.CreateResponse(HttpStatusCode.OK, result.Result) //return the id
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public DocumentTypeDisplay PostSave(DocumentTypeSave contentTypeSave)
{
var savedCt = PerformPostSave<IContentType, DocumentTypeDisplay, DocumentTypeSave, PropertyTypeBasic>(
@@ -170,6 +170,16 @@ namespace Umbraco.Web.Editors
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public HttpResponseMessage PostRenameContainer(int id, string name)
{
var result = Services.ContentTypeService.RenameMediaTypeContainer(id, name, Security.CurrentUser.Id);
return result
? Request.CreateResponse(HttpStatusCode.OK, result.Result) //return the id
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public MediaTypeDisplay PostSave(MediaTypeSave contentTypeSave)
{
var savedCt = PerformPostSave<IMediaType, MediaTypeDisplay, MediaTypeSave, PropertyTypeBasic>(
@@ -100,7 +100,12 @@ namespace Umbraco.Web.Trees
//can delete doc type
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)), true);
}
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true);
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true);
menu.Items.Add(new MenuItem("rename", Services.TextService.Localize(String.Format("actions/{0}", "rename")))
{
Icon = "icon icon-edit"
});
}
else
{
@@ -94,6 +94,11 @@ namespace Umbraco.Web.Trees
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)));
}
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), hasSeparator: true);
menu.Items.Add(new MenuItem("rename", Services.TextService.Localize(String.Format("actions/{0}", "rename")))
{
Icon = "icon icon-edit"
});
}
else
{