Merge pull request #4167 from umbraco/temp8-3417-macro-crud
Macro delete stuff
This commit is contained in:
@@ -115,6 +115,12 @@ function macroResource($q, $http, umbRequestHelper) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("macroApiBaseUrl", "Save"), macro)
|
||||
);
|
||||
},
|
||||
|
||||
deleteById: function(id) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("macroApiBaseUrl", "deleteById", { "id": id }))
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
10
src/Umbraco.Web.UI.Client/src/views/macros/delete.html
Normal file
10
src/Umbraco.Web.UI.Client/src/views/macros/delete.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.Macros.DeleteController as vm">
|
||||
<div class="umb-dialog-body" auto-scale="90">
|
||||
|
||||
<p class="umb-abstract">
|
||||
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize> <strong>{{vm.name}}</strong> ?
|
||||
</p>
|
||||
|
||||
<umb-confirm on-confirm="vm.performDelete" on-cancel="cancel"></umb-confirm>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @ngdoc controller
|
||||
* @name Umbraco.Editors.Macros.DeleteController
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* The controller for deleting macro items
|
||||
*/
|
||||
function MacrosDeleteController($scope, $location, macroResource, navigationService, treeService) {
|
||||
var vm = this;
|
||||
|
||||
vm.name = $scope.currentNode.name;
|
||||
function performDelete() {
|
||||
$scope.currentNode.loading = true;
|
||||
macroResource.deleteById($scope.currentNode.id).then(function () {
|
||||
$scope.currentNode.loading = false;
|
||||
|
||||
treeService.removeNode($scope.currentNode);
|
||||
|
||||
navigationService.hideMenu();
|
||||
});
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
navigationService.hideDialog();
|
||||
}
|
||||
|
||||
vm.performDelete = performDelete;
|
||||
vm.cancel = cancel;
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Macros.DeleteController", MacrosDeleteController);
|
||||
@@ -15,6 +15,7 @@ using Umbraco.Web.Macros;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -29,11 +30,14 @@ namespace Umbraco.Web.Editors
|
||||
[PluginController("UmbracoApi")]
|
||||
public class MacroRenderingController : UmbracoAuthorizedJsonController, IRequiresSessionState
|
||||
{
|
||||
private readonly IMacroService _macroService;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
|
||||
public MacroRenderingController(IVariationContextAccessor variationContextAccessor)
|
||||
public MacroRenderingController(IVariationContextAccessor variationContextAccessor, IMacroService macroService, IContentService contentService)
|
||||
{
|
||||
_variationContextAccessor = variationContextAccessor;
|
||||
_macroService = macroService;
|
||||
_contentService = contentService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,12 +45,12 @@ namespace Umbraco.Web.Editors
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Note that ALL logged in users have access to this method because editors will need to isnert macros into rte (content/media/members) and it's used for
|
||||
/// Note that ALL logged in users have access to this method because editors will need to insert macros into rte (content/media/members) and it's used for
|
||||
/// inserting into templates/views/etc... it doesn't expose any sensitive data.
|
||||
/// </remarks>
|
||||
public IEnumerable<MacroParameter> GetMacroParameters(int macroId)
|
||||
{
|
||||
var macro = Services.MacroService.GetById(macroId);
|
||||
var macro = _macroService.GetById(macroId);
|
||||
if (macro == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
@@ -97,13 +101,13 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
// note - here we should be using the cache, provided that the preview content is in the cache...
|
||||
|
||||
var doc = Services.ContentService.GetById(pageId);
|
||||
var doc = _contentService.GetById(pageId);
|
||||
if (doc == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
var m = Services.MacroService.GetByAlias(macroAlias);
|
||||
var m = _macroService.GetByAlias(macroAlias);
|
||||
if (m == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
var macro = new MacroModel(m);
|
||||
@@ -166,7 +170,7 @@ namespace Umbraco.Web.Editors
|
||||
MacroSource = model.VirtualPath.EnsureStartsWith("~")
|
||||
};
|
||||
|
||||
Services.MacroService.Save(macro); // may throw
|
||||
_macroService.Save(macro); // may throw
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Umbraco.Web.Editors
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -28,6 +30,13 @@
|
||||
[UmbracoTreeAuthorize(Constants.Trees.Macros)]
|
||||
public class MacrosController : BackOfficeNotificationsController
|
||||
{
|
||||
private readonly IMacroService _macroService;
|
||||
|
||||
public MacrosController(IMacroService macroService)
|
||||
{
|
||||
_macroService = macroService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new macro
|
||||
/// </summary>
|
||||
@@ -47,7 +56,7 @@
|
||||
|
||||
var alias = name.ToSafeAlias();
|
||||
|
||||
if (this.Services.MacroService.GetByAlias(alias) != null)
|
||||
if (_macroService.GetByAlias(alias) != null)
|
||||
{
|
||||
return this.ReturnErrorResponse("Macro with this alias already exists");
|
||||
}
|
||||
@@ -62,7 +71,7 @@
|
||||
MacroType = MacroTypes.PartialView
|
||||
};
|
||||
|
||||
this.Services.MacroService.Save(macro, this.Security.CurrentUser.Id);
|
||||
_macroService.Save(macro, this.Security.CurrentUser.Id);
|
||||
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, macro.Id);
|
||||
}
|
||||
@@ -75,7 +84,7 @@
|
||||
[HttpGet]
|
||||
public HttpResponseMessage GetById(int id)
|
||||
{
|
||||
var macro = this.Services.MacroService.GetById(id);
|
||||
var macro = _macroService.GetById(id);
|
||||
|
||||
if (macro == null)
|
||||
{
|
||||
@@ -115,6 +124,22 @@
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, macroDisplay);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage DeleteById(int id)
|
||||
{
|
||||
var macro = _macroService.GetById(id);
|
||||
|
||||
if (macro == null)
|
||||
{
|
||||
return this.ReturnErrorResponse($"Macro with id {id} does not exist");
|
||||
}
|
||||
|
||||
_macroService.Delete(macro);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Save(MacroDisplay macroDisplay)
|
||||
{
|
||||
@@ -123,7 +148,7 @@
|
||||
return this.ReturnErrorResponse($"No macro data found in request");
|
||||
}
|
||||
|
||||
var macro = this.Services.MacroService.GetById(int.Parse(macroDisplay.Id.ToString()));
|
||||
var macro = _macroService.GetById(int.Parse(macroDisplay.Id.ToString()));
|
||||
|
||||
if (macro == null)
|
||||
{
|
||||
@@ -132,7 +157,7 @@
|
||||
|
||||
if (macroDisplay.Alias != macro.Alias)
|
||||
{
|
||||
var macroByAlias = this.Services.MacroService.GetByAlias(macroDisplay.Alias);
|
||||
var macroByAlias = _macroService.GetByAlias(macroDisplay.Alias);
|
||||
|
||||
if (macroByAlias != null)
|
||||
{
|
||||
@@ -153,7 +178,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
this.Services.MacroService.Save(macro, this.Security.CurrentUser.Id);
|
||||
_macroService.Save(macro, this.Security.CurrentUser.Id);
|
||||
|
||||
macroDisplay.Notifications.Clear();
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Umbraco.Web.Trees
|
||||
{
|
||||
//Create the normal create action
|
||||
menu.Items.Add<ActionNew>(Services.TextService);
|
||||
|
||||
|
||||
//refresh action
|
||||
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
||||
|
||||
@@ -65,16 +65,7 @@ namespace Umbraco.Web.Trees
|
||||
if (macro == null) return new MenuItemCollection();
|
||||
|
||||
//add delete option for all macros
|
||||
menu.Items.Add<ActionDelete>(Services.TextService, opensDialog: true)
|
||||
//Since we haven't implemented anything for macros in angular, this needs to be converted to
|
||||
//use the legacy format
|
||||
.ConvertLegacyMenuItem(new EntitySlim
|
||||
{
|
||||
Id = macro.Id,
|
||||
Level = 1,
|
||||
ParentId = -1,
|
||||
Name = macro.Name
|
||||
}, "macros", queryStrings.GetValue<string>("application"));
|
||||
menu.Items.Add<ActionDelete>(Services.TextService, opensDialog: true);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user