Skip to content

Commit

Permalink
ConfigurationEditor - deprecated name/description template properties
Browse files Browse the repository at this point in the history
Introduced `Expressions`, to define additional AngularJS expression templates.
Refactored the name/description/icon templates to use new Expressions property.
  • Loading branch information
leekelleher committed Jul 6, 2022
1 parent 8526cf5 commit 2c43bf1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;
Expand Down Expand Up @@ -38,12 +39,14 @@ public sealed class ConfigurationEditorModel : IConfigurationEditorItem
public OverlaySize OverlaySize { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string NameTemplate { get; set; }
public Dictionary<string, string> Expressions { get; set; }

[Obsolete("Please use Expressions instead. e.g. { \"name\", \"{{ AngularJS expression }}\" }", false)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string DescriptionTemplate { get; set; }
public string NameTemplate { get; set; }

[Obsolete("Please use Expressions instead. e.g. { \"description\", \"{{ AngularJS expression }}\" }", false)]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string IconTemplate { get; set; }
public string DescriptionTemplate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ public ConfigurationEditorModel GetConfigurationEditorModel<T>(T item, IShortStr

if (item is IContentmentListTemplateItem lti)
{
model.NameTemplate = lti.NameTemplate;
model.DescriptionTemplate = lti.DescriptionTemplate;
model.Expressions = new Dictionary<string, string>
{
{ "name", lti.NameTemplate },
{ "description", lti.DescriptionTemplate },
};
}

return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,36 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.

config.itemLookup = {};
config.allowEdit = {};
config.nameTemplates = {};
config.descriptionTemplates = {};
config.iconTemplates = {};
config.expressions = {};
config.missingItem = {};

config.items.forEach(item => {
config.itemLookup[item.key] = item;

config.allowEdit[item.key] = item.fields && item.fields.length > 0;

if (item.nameTemplate) {
config.nameTemplates[item.key] = $interpolate(item.nameTemplate);
if (config.itemLookup.hasOwnProperty(item.key) === false) {
config.itemLookup[item.key] = item;
}

if (item.descriptionTemplate) {
config.descriptionTemplates[item.key] = $interpolate(item.descriptionTemplate);
if (config.allowEdit.hasOwnProperty(item.key) === false) {
config.allowEdit[item.key] = item.fields && item.fields.length > 0;
}

if (item.iconTemplate) {
config.iconTemplates[item.key] = $interpolate(item.iconTemplate);
if (config.expressions.hasOwnProperty(item.key) === false) {

config.expressions[item.key] = {};

if (item.expressions) {
for (let [alias, value] of Object.entries(item.expressions)) {
config.expressions[item.key][alias] = $interpolate(value);
}
}

if (item.nameTemplate) { // TODO: [LK:2022-07-05] Deprecated.
config.expressions[item.key]["name"] = $interpolate(item.nameTemplate);
}

if (item.descriptionTemplate) { // TODO: [LK:2022-07-05] Deprecated.
config.expressions[item.key]["description"] = $interpolate(item.descriptionTemplate);
}
}
});

Expand Down Expand Up @@ -204,33 +214,16 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
return config.missingItem[propertyName] || propertyName;
}

if (propertyName === "name" && config.nameTemplates.hasOwnProperty(item.key) === true) {
var expression = config.nameTemplates[item.key];
if (expression) {
item.value.$index = $index + 1;
label = expression(item.value);
delete item.value.$index;
}
}

if (propertyName === "description" && config.descriptionTemplates.hasOwnProperty(item.key) === true) {
var expression = config.descriptionTemplates[item.key];
if (expression) {
item.value.$index = $index + 1;
label = expression(item.value);
delete item.value.$index;
}
}

if (propertyName === "icon" && config.iconTemplates.hasOwnProperty(item.key) === true) {
var expression = config.iconTemplates[item.key];
if (expression) {
item.value.$index = $index + 1;
label = expression(item.value);
delete item.value.$index;
if (config.expressions.hasOwnProperty(item.key) === true) {
var expressions = config.expressions[item.key];
if (expressions.hasOwnProperty(propertyName) === true) {
var expression = expressions[propertyName];
if (expression) {
item.value.$index = $index + 1;
label = expression(item.value);
delete item.value.$index;
}
}
}

return label || config.itemLookup[item.key][propertyName];
};

Expand Down Expand Up @@ -269,7 +262,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
} else {
vm.allowAdd = true;
}
emit();
setDirty();
};

function setDirty() {
Expand Down

0 comments on commit 2c43bf1

Please sign in to comment.