Rename logic in place

This commit is contained in:
Robert
2017-09-12 08:28:18 +02:00
parent fb60647b5a
commit 9fd0e7771d
5 changed files with 80 additions and 35 deletions

View File

@@ -156,6 +156,11 @@ namespace Umbraco.Core.Services
return RenameTypeContainer(id, name, Constants.ObjectTypes.MediaTypeContainerGuid);
}
public Attempt<OperationStatus<EntityContainer, OperationStatusType>> RenameDataTypeContainer(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(
@@ -253,7 +258,7 @@ namespace Umbraco.Core.Services
public IEnumerable<EntityContainer> GetMediaTypeContainers(IMediaType mediaType)
{
var ancestorIds = mediaType.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
var ancestorIds = mediaType.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x =>
{
var asInt = x.TryConvertTo<int>();
@@ -282,7 +287,7 @@ namespace Umbraco.Core.Services
public IEnumerable<EntityContainer> GetContentTypeContainers(IContentType contentType)
{
var ancestorIds = contentType.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
var ancestorIds = contentType.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x =>
{
var asInt = x.TryConvertTo<int>();
@@ -479,7 +484,7 @@ namespace Umbraco.Core.Services
clone.Name = name;
var compositionAliases = clone.CompositionAliases().Except(new[] {alias}).ToList();
var compositionAliases = clone.CompositionAliases().Except(new[] { alias }).ToList();
//remove all composition that is not it's current alias
foreach (var a in compositionAliases)
{
@@ -902,7 +907,7 @@ namespace Umbraco.Core.Services
{
using (var uow = UowProvider.GetUnitOfWork())
{
var deleteEventArgs = new DeleteEventArgs<IContentType>(contentType);
var deleteEventArgs = new DeleteEventArgs<IContentType>(contentType);
if (uow.Events.DispatchCancelable(DeletingContentType, this, deleteEventArgs))
{
uow.Commit();
@@ -912,7 +917,7 @@ namespace Umbraco.Core.Services
var repository = RepositoryFactory.CreateContentTypeRepository(uow);
//If we are deleting this content type, we are also deleting it's descendents!
var deletedContentTypes = new List<IContentType> {contentType};
var deletedContentTypes = new List<IContentType> { contentType };
deletedContentTypes.AddRange(GetDescendants(contentType));
_contentService.DeleteContentOfTypes(deletedContentTypes.Select(x => x.Id), userId);

View File

@@ -30,6 +30,7 @@ namespace Umbraco.Core.Services
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>> RenameDataTypeContainer(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);

View File

@@ -357,6 +357,14 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
"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("dataTypeApiBaseUrl",
"PostRenameContainer",
{ id: id, name: name })),
"Failed to rename the folder with id " + id);
}
};
}

View File

@@ -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('dataTypeResource', 'datatypes')"
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>

View File

@@ -22,8 +22,8 @@ using System.Net.Http;
using System.Text;
namespace Umbraco.Web.Editors
{
{
/// <summary>
/// The API controller used for editing data types
/// </summary>
@@ -75,8 +75,8 @@ namespace Umbraco.Web.Editors
if (foundType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
}
Services.DataTypeService.Delete(foundType, Security.CurrentUser.Id);
return Request.CreateResponse(HttpStatusCode.OK);
@@ -111,17 +111,17 @@ namespace Umbraco.Web.Editors
/// <returns></returns>
public DataTypeDisplay PostCreateCustomListView(string contentTypeAlias)
{
var dt = Services.DataTypeService.GetDataTypeDefinitionByName(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias);
//if it doesnt exist yet, we will create it.
var dt = Services.DataTypeService.GetDataTypeDefinitionByName(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias);
//if it doesnt exist yet, we will create it.
if (dt == null)
{
dt = new DataTypeDefinition( Constants.PropertyEditors.ListViewAlias );
dt = new DataTypeDefinition(Constants.PropertyEditors.ListViewAlias);
dt.Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias;
Services.DataTypeService.Save(dt);
}
return Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dt);
return Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dt);
}
/// <summary>
@@ -161,7 +161,7 @@ namespace Umbraco.Web.Editors
}
//these are new pre-values, so just return the field editors with default values
return Mapper.Map<PropertyEditor, IEnumerable<PreValueFieldDisplay>>(propEd);
return Mapper.Map<PropertyEditor, IEnumerable<PreValueFieldDisplay>>(propEd);
}
/// <summary>
@@ -243,31 +243,40 @@ namespace Umbraco.Web.Editors
return Request.CreateResponse(HttpStatusCode.NotFound);
}
var result = Services.DataTypeService.Move(toMove, move.ParentId);
if (result.Success)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json");
return response;
}
switch (result.Result.StatusType)
{
case MoveOperationStatusType.FailedParentNotFound:
return Request.CreateResponse(HttpStatusCode.NotFound);
var result = Services.DataTypeService.Move(toMove, move.ParentId);
if (result.Success)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json");
return response;
}
switch (result.Result.StatusType)
{
case MoveOperationStatusType.FailedParentNotFound:
return Request.CreateResponse(HttpStatusCode.NotFound);
case MoveOperationStatusType.FailedCancelledByEvent:
//returning an object of INotificationModel will ensure that any pending
// notification messages are added to the response.
return Request.CreateValidationErrorResponse(new SimpleNotificationModel());
case MoveOperationStatusType.FailedNotAllowedByPath:
return Request.CreateValidationErrorResponse(new SimpleNotificationModel());
case MoveOperationStatusType.FailedNotAllowedByPath:
var notificationModel = new SimpleNotificationModel();
notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), "");
notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), "");
return Request.CreateValidationErrorResponse(notificationModel);
default:
throw new ArgumentOutOfRangeException();
default:
throw new ArgumentOutOfRangeException();
}
}
public HttpResponseMessage PostRenameContainer(int id, string name)
{
var result = Services.ContentTypeService.RenameDataTypeContainer(id, name, Security.CurrentUser.Id);
return result
? Request.CreateResponse(HttpStatusCode.OK, result.Result)
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
#region ReadOnly actions to return basic data - allow access for: content ,media, members, settings, developer
/// <summary>
/// Gets the content json for all data types
@@ -308,7 +317,7 @@ namespace Umbraco.Web.Editors
foreach (var dataType in dataTypes)
{
var propertyEditor = propertyEditors.SingleOrDefault(x => x.Alias == dataType.Alias);
if(propertyEditor != null)
if (propertyEditor != null)
dataType.HasPrevalues = propertyEditor.PreValueEditor.Fields.Any(); ;
}
@@ -331,8 +340,8 @@ namespace Umbraco.Web.Editors
Constants.Applications.Settings, Constants.Applications.Developer)]
public IDictionary<string, IEnumerable<DataTypeBasic>> GetGroupedPropertyEditors()
{
var datatypes = new List<DataTypeBasic>();
var datatypes = new List<DataTypeBasic>();
var propertyEditors = PropertyEditorResolver.Current.PropertyEditors;
foreach (var propertyEditor in propertyEditors)
{