Skip to content

Commit 6df6e3b

Browse files
committed
Fixes: U4-3737 macro container make sure you can define the allowed macros + the max number
1 parent 9019c49 commit 6df6e3b

File tree

9 files changed

+68
-18
lines changed

9 files changed

+68
-18
lines changed

src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,16 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi
136136
entityResource.getAll("Macro", ($scope.dialogData && $scope.dialogData.richTextEditor && $scope.dialogData.richTextEditor === true) ? "UseInEditor=true" : null)
137137
.then(function (data) {
138138

139-
$scope.macros = data;
139+
//if 'allowedMacros' is specified, we need to filter
140+
if (angular.isArray($scope.dialogData.allowedMacros) && $scope.dialogData.allowedMacros.length > 0) {
141+
$scope.macros = _.filter(data, function(d) {
142+
return _.contains($scope.dialogData.allowedMacros, d.alias);
143+
});
144+
}
145+
else {
146+
$scope.macros = data;
147+
}
148+
140149

141150
//check if there's a pre-selected macro and if it exists
142151
if ($scope.dialogData && $scope.dialogData.macroData && $scope.dialogData.macroData.macroAlias) {

src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
<div class="umb-panel-body no-header umb-scrollable" auto-scale="90" ng-switch="wizardStep">
1616

1717
<umb-control-group label="Choose a macro" ng-switch-when="macroSelect">
18-
<select class="umb-editor" ng-change="submitForm()" name="selectedMacro" ng-model="$parent.$parent.selectedMacro" ng-options="m as m.name for m in macros" required>
18+
<select class="umb-editor" ng-change="submitForm()"
19+
name="selectedMacro"
20+
ng-model="$parent.$parent.selectedMacro"
21+
ng-options="m as m.name for m in macros"
22+
required>
1923
<option value=""><localize key="choose" />...</option>
2024
</select>
2125
<span class="help-inline" val-msg-for="selectedMacro" val-toggle-msg="required"><localize key="required" /></span>

src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.controller.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
angular.module('umbraco')
33
.controller("Umbraco.PropertyEditors.MacroContainerController",
44

5-
function($scope, dialogService, entityResource, macroService, macroResource){
5+
function($scope, dialogService, entityResource, macroService){
66
$scope.renderModel = [];
77

88
if($scope.model.value){
@@ -35,11 +35,13 @@ angular.module('umbraco')
3535
}
3636

3737
function openDialog(index){
38-
var dialogData = {};
38+
var dialogData = {
39+
allowedMacros: $scope.model.config.allowed
40+
};
3941

4042
if(index !== null && $scope.renderModel[index]) {
4143
var macro = $scope.renderModel[index];
42-
dialogData = {macroData: macro};
44+
dialogData[macroData] = macro;
4345
}
4446

4547
dialogService.macroPicker({
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function MacroListController($scope, entityResource) {
2+
3+
$scope.items = [];
4+
5+
entityResource.getAll("Macro").then(function(items) {
6+
_.each(items, function(i) {
7+
$scope.items.push({ name: i.name, alias: i.alias });
8+
});
9+
10+
});
11+
12+
13+
}
14+
15+
angular.module("umbraco").controller("Umbraco.PrevalueEditors.MacroList", MacroListController);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div ng-controller="Umbraco.PrevalueEditors.MacroList">
2+
3+
<select multiple ng-multiple="true"
4+
ng-model="model.value"
5+
ng-options="i.alias as i.name for i in items"></select>
6+
7+
</div>

src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@ namespace Umbraco.Web.PropertyEditors
1212
[PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer")]
1313
public class MacroContainerPropertyEditor : PropertyEditor
1414
{
15+
/// <summary>
16+
/// Creates a pre value editor instance
17+
/// </summary>
18+
/// <returns></returns>
19+
protected override PreValueEditor CreatePreValueEditor()
20+
{
21+
return new MacroContainerPreValueEditor();
22+
}
23+
1524
protected override PropertyValueEditor CreateValueEditor()
1625
{
1726
//TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists!
1827

1928
return base.CreateValueEditor();
2029
}
2130

31+
internal class MacroContainerPreValueEditor : PreValueEditor
32+
{
33+
[PreValueField("max", "Max items", "number", Description = "The maximum number of macros that are allowed in the container")]
34+
public int MaxItems { get; set; }
35+
36+
[PreValueField("allowed", "Allowed items", "views/propertyeditors/macrocontainer/macrolist.prevalues.html", Description = "The macro types allowed, if none are selected all macros will be allowed")]
37+
public object AllowedItems { get; set; }
38+
}
39+
2240
}
2341
}

src/Umbraco.Web/Scheduling/ScheduledPublishing.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void Run()
5959
wc.Headers.Set("Authorization", AdminTokenAuthorizeAttribute.GetAuthHeaderTokenVal(_appContext));
6060

6161
var result = wc.UploadString(url, "");
62-
}
63-
}
62+
}
6463
}
6564
}
6665
catch (Exception ee)

src/Umbraco.Web/Trees/ApplicationTreeRegistrar.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ public LazyEnumerableTrees()
5353
//convert them to ApplicationTree instances
5454
var legacyItems = legacyTreeTypes
5555
.Select(x =>
56-
new Tuple<Type, global::umbraco.businesslogic.TreeAttribute, ObsoleteAttribute>(
57-
new Tuple<Type, global::umbraco.businesslogic.TreeAttribute>(
58-
x,
59-
x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault(),
60-
x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault()))
61-
x.GetCustomAttributes<ObsoleteAttribute>(false).SingleOrDefault()))
62-
//ensure that the legacy tree attribute exists
56+
new Tuple<Type, global::umbraco.businesslogic.TreeAttribute, ObsoleteAttribute>(
57+
x,
58+
x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault(),
59+
x.GetCustomAttributes<ObsoleteAttribute>(false).SingleOrDefault()))
60+
//ensure that the legacy tree attribute exists
6361
.Where(x => x.Item2 != null)
64-
//ensure that it's not obsoleted, any obsoleted tree will not be auto added to the config
65-
.Where(x => x.Item3 == null)
62+
//ensure that it's not obsoleted, any obsoleted tree will not be auto added to the config
63+
.Where(x => x.Item3 == null)
6664
//make sure the legacy tree isn't added on top of the controller tree!
6765
.Where(x => added.InvariantContains(x.Item2.Alias) == false)
6866
.Select(x => new ApplicationTree(x.Item2.Initialize, x.Item2.SortOrder, x.Item2.ApplicationAlias, x.Item2.Alias, x.Item2.Title, x.Item2.IconClosed, x.Item2.IconOpen, x.Item1.GetFullNameWithAssembly()));

src/UmbracoExamine/UmbracoMemberIndexer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Specialized;
32
using System.Linq;
43
using System.Xml.Linq;
54
using Examine.LuceneEngine.Config;
@@ -13,7 +12,6 @@
1312
using System.IO;
1413
using UmbracoExamine.DataServices;
1514
using Lucene.Net.Analysis;
16-
using Member = umbraco.cms.businesslogic.member.Member;
1715

1816
namespace UmbracoExamine
1917
{

0 commit comments

Comments
 (0)