#3417 retreive data for edit screen
This commit is contained in:
@@ -101,6 +101,12 @@ function macroResource($q, $http, umbRequestHelper) {
|
||||
$http.get(umbRequestHelper.getApiUrl("macroApiBaseUrl", "GetParameterEditors"),
|
||||
"Failed to get parameter editors")
|
||||
);
|
||||
},
|
||||
|
||||
getById: function(id) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(umbRequestHelper.getApiUrl("macroApiBaseUrl", "GetById", { "id" : id}), "Failed to get macro")
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</umb-control-group>
|
||||
|
||||
<umb-control-group label="Editor" description="">
|
||||
<select class="input-block-level" ng-model="model.parameter.editor" ng-options="i.alias as (i.name) for i in model.editors"></select>
|
||||
<select required class="input-block-level" ng-model="model.parameter.editor" ng-options="i.alias as (i.name) for i in model.editors"></select>
|
||||
</umb-control-group>
|
||||
|
||||
|
||||
|
||||
@@ -83,11 +83,24 @@ function MacrosEditController($scope, $q, $routeParams, macroResource, editorSta
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function getMacro() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
macroResource.getById($routeParams.id).then(function (data) {
|
||||
deferred.resolve(data);
|
||||
}, function () {
|
||||
deferred.reject();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function init() {
|
||||
vm.page.loading = true;
|
||||
|
||||
vm.promises['partialViews'] = getPartialViews();
|
||||
vm.promises['parameterEditors'] = getParameterEditors();
|
||||
vm.promises['macro'] = getMacro();
|
||||
|
||||
$q.all(vm.promises).then(function (values) {
|
||||
var keys = Object.keys(values);
|
||||
@@ -102,12 +115,20 @@ function MacrosEditController($scope, $q, $routeParams, macroResource, editorSta
|
||||
if (keys[i] === 'parameterEditors') {
|
||||
vm.parameterEditors = values[key];
|
||||
}
|
||||
|
||||
if (keys[i] === 'macro') {
|
||||
vm.macro = values[key];
|
||||
editorState.set(vm.macro);
|
||||
|
||||
navigationService.syncTree({ tree: "macros", path: vm.macro.path, forceReload: true }).then(function (syncArgs) {
|
||||
vm.page.menu.currentNode = syncArgs.node;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
vm.page.loading = false;
|
||||
});
|
||||
|
||||
|
||||
vm.page.navigation = [
|
||||
{
|
||||
"name": "Settings",
|
||||
@@ -123,31 +144,6 @@ function MacrosEditController($scope, $q, $routeParams, macroResource, editorSta
|
||||
"view": "views/macros/views/parameters.html"
|
||||
}
|
||||
];
|
||||
|
||||
vm.macro = {
|
||||
"name": "Test macro",
|
||||
"alias": "testMacro",
|
||||
"id": 1,
|
||||
"key": "unique key goes here",
|
||||
"useInEditor": true,
|
||||
"renderInEditor": false,
|
||||
"cachePeriod": 2400,
|
||||
"cacheByPage": true,
|
||||
"cacheByUser": false,
|
||||
"view": "Second",
|
||||
"parameters": [
|
||||
{
|
||||
"key": "title",
|
||||
"label": "Label",
|
||||
"editor": "editor"
|
||||
},
|
||||
{
|
||||
"key": "link",
|
||||
"label": "Link",
|
||||
"editor": "Link picker"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
<umb-box-header title="Macro partial view"></umb-box-header>
|
||||
<umb-box-content>
|
||||
<umb-control-group label="Macro partial view">
|
||||
<select class="input-block-level" ng-model="model.macro.view" ng-options="i as i for i in model.views"></select>
|
||||
<select class="input-block-level" ng-model="model.macro.view" ng-options="i as i for i in model.views" required>
|
||||
</select>
|
||||
</umb-control-group>
|
||||
</umb-box-content>
|
||||
</umb-box>
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
/// <summary>
|
||||
/// The API controller used for editing dictionary items
|
||||
@@ -41,33 +40,75 @@ namespace Umbraco.Web.Editors
|
||||
public HttpResponseMessage Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Request
|
||||
.CreateNotificationValidationErrorResponse("Name can not be empty;");
|
||||
{
|
||||
return this.ReturnErrorResponse("Name can not be empty");
|
||||
}
|
||||
|
||||
var alias = name.ToSafeAlias();
|
||||
|
||||
var existingMacro = this.Services.MacroService.GetByAlias(alias);
|
||||
|
||||
if (existingMacro != null)
|
||||
if (this.Services.MacroService.GetByAlias(alias) != null)
|
||||
{
|
||||
return Request.CreateNotificationValidationErrorResponse("Macro with this name already exists");
|
||||
return this.ReturnErrorResponse("Macro with this name already exists");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var macro = new Macro { Alias = alias, Name = name, MacroSource = string.Empty };
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
MacroSource = string.Empty,
|
||||
MacroType = MacroTypes.PartialView
|
||||
};
|
||||
|
||||
this.Services.MacroService.Save(macro, this.Security.CurrentUser.Id);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, macro.Id);
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, macro.Id);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
this.Logger.Error<MacrosController>(exception, "Error creating macro");
|
||||
return Request.CreateNotificationValidationErrorResponse("Error creating dictionary item");
|
||||
return this.ReturnErrorResponse("Error creating macro", true, exception);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public HttpResponseMessage GetById(int id)
|
||||
{
|
||||
var macro = this.Services.MacroService.GetById(id);
|
||||
|
||||
if (macro == null)
|
||||
{
|
||||
return this.ReturnErrorResponse($"Macro with id {id} does not exist");
|
||||
}
|
||||
|
||||
var macroDisplay = new MacroDisplay
|
||||
{
|
||||
Alias = macro.Alias, Id = macro.Id, Key = macro.Key, Name = macro.Name,
|
||||
CacheByPage = macro.CacheByPage, CacheByUser = macro.CacheByMember,
|
||||
CachePeriod = macro.CacheDuration,
|
||||
View = macro.MacroSource,
|
||||
RenderInEditor = !macro.DontRender,
|
||||
UseInEditor = macro.UseInEditor,
|
||||
Path = $"-1,{macro.Id}"
|
||||
};
|
||||
|
||||
var parameters = new List<MacroParameterDisplay>();
|
||||
|
||||
foreach (var param in macro.Properties.Values.OrderBy(x => x.SortOrder))
|
||||
{
|
||||
parameters.Add(new MacroParameterDisplay
|
||||
{
|
||||
Editor = param.EditorAlias,
|
||||
Key = param.Alias,
|
||||
Label = param.Name
|
||||
});
|
||||
}
|
||||
|
||||
macroDisplay.Parameters = parameters;
|
||||
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, macroDisplay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of available macro partials
|
||||
/// </summary>
|
||||
@@ -94,6 +135,31 @@ namespace Umbraco.Web.Editors
|
||||
return this.Request.CreateResponse(HttpStatusCode.OK, Current.ParameterEditors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a error response and optionally logs it
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// The error message.
|
||||
/// </param>
|
||||
/// <param name="logError">
|
||||
/// Value to indicate if the error needs to be logged
|
||||
/// </param>
|
||||
/// <param name="exception">
|
||||
/// The exception to log
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="HttpResponseMessage"/>.
|
||||
/// </returns>
|
||||
private HttpResponseMessage ReturnErrorResponse(string message, bool logError = false, Exception exception = null)
|
||||
{
|
||||
if (logError && exception != null)
|
||||
{
|
||||
this.Logger.Error<MacrosController>(exception, message);
|
||||
}
|
||||
|
||||
return this.Request.CreateNotificationValidationErrorResponse(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all the macro partials
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// The macro display model
|
||||
/// </summary>
|
||||
[DataContract(Name = "dictionary", Namespace = "")]
|
||||
public class MacroDisplay : EntityBasic, INotificationModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MacroDisplay"/> class.
|
||||
/// </summary>
|
||||
public MacroDisplay()
|
||||
{
|
||||
this.Notifications = new List<Notification>();
|
||||
this.Parameters = new List<MacroParameterDisplay>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[DataMember(Name = "notifications")]
|
||||
public List<Notification> Notifications { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the macro can be used in a rich text editor.
|
||||
/// </summary>
|
||||
[DataMember(Name = "useInEditor")]
|
||||
public bool UseInEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the macro should be rendered a rich text editor.
|
||||
/// </summary>
|
||||
[DataMember(Name = "renderInEditor")]
|
||||
public bool RenderInEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cache period.
|
||||
/// </summary>
|
||||
[DataMember(Name = "cachePeriod")]
|
||||
public int CachePeriod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the macro should be cached by page
|
||||
/// </summary>
|
||||
[DataMember(Name = "cacheByPage")]
|
||||
public bool CacheByPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the macro should be cached by user
|
||||
/// </summary>
|
||||
[DataMember(Name = "cacheByUser")]
|
||||
public bool CacheByUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the view.
|
||||
/// </summary>
|
||||
[DataMember(Name = "view")]
|
||||
public string View { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parameters.
|
||||
/// </summary>
|
||||
[DataMember(Name = "parameters")]
|
||||
public IEnumerable<MacroParameterDisplay> Parameters { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// The macro parameter display.
|
||||
/// </summary>
|
||||
[DataContract(Name = "parameter", Namespace = "")]
|
||||
public class MacroParameterDisplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the key.
|
||||
/// </summary>
|
||||
[DataMember(Name = "key")]
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the label.
|
||||
/// </summary>
|
||||
[DataMember(Name = "label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the editor.
|
||||
/// </summary>
|
||||
[DataMember(Name = "editor")]
|
||||
public string Editor { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,8 @@
|
||||
<Compile Include="Media\TypeDetector\SvgDetector.cs" />
|
||||
<Compile Include="Media\TypeDetector\TIFFDetector.cs" />
|
||||
<Compile Include="Media\UploadAutoFillProperties.cs" />
|
||||
<Compile Include="Models\ContentEditing\MacroDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\MacroParameterDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\PublicAccess.cs" />
|
||||
<Compile Include="Models\ContentEditing\ObjectType.cs" />
|
||||
<Compile Include="Models\ContentEditing\RelationDisplay.cs" />
|
||||
|
||||
Reference in New Issue
Block a user