From 2c43bf1724bca76e283315065936e229a84cfd0e Mon Sep 17 00:00:00 2001 From: leekelleher Date: Wed, 6 Jul 2022 01:05:03 +0100 Subject: [PATCH] ConfigurationEditor - deprecated name/description template properties Introduced `Expressions`, to define additional AngularJS expression templates. Refactored the name/description/icon templates to use new Expressions property. --- .../ConfigurationEditorModel.cs | 9 ++- .../ConfigurationEditorUtility.cs | 7 +- .../configuration-editor.js | 71 +++++++++---------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs index 6010f521..1426d0ee 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs @@ -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; @@ -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 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; } } } diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs index b3a39a22..66cf6899 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs @@ -79,8 +79,11 @@ public ConfigurationEditorModel GetConfigurationEditorModel(T item, IShortStr if (item is IContentmentListTemplateItem lti) { - model.NameTemplate = lti.NameTemplate; - model.DescriptionTemplate = lti.DescriptionTemplate; + model.Expressions = new Dictionary + { + { "name", lti.NameTemplate }, + { "description", lti.DescriptionTemplate }, + }; } return model; diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/configuration-editor.js b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/configuration-editor.js index 9b312776..48e5bb26 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/configuration-editor.js +++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/configuration-editor.js @@ -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); + } } }); @@ -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]; }; @@ -269,7 +262,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors. } else { vm.allowAdd = true; } - emit(); + setDirty(); }; function setDirty() {