Fixes: U4-3737 macro container make sure you can define the allowed macros + the max number

This commit is contained in:
Shannon
2014-11-13 17:44:03 +11:00
parent 9019c49ee8
commit 6df6e3bdad
9 changed files with 68 additions and 18 deletions

View File

@@ -136,7 +136,16 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi
entityResource.getAll("Macro", ($scope.dialogData && $scope.dialogData.richTextEditor && $scope.dialogData.richTextEditor === true) ? "UseInEditor=true" : null) entityResource.getAll("Macro", ($scope.dialogData && $scope.dialogData.richTextEditor && $scope.dialogData.richTextEditor === true) ? "UseInEditor=true" : null)
.then(function (data) { .then(function (data) {
$scope.macros = data; //if 'allowedMacros' is specified, we need to filter
if (angular.isArray($scope.dialogData.allowedMacros) && $scope.dialogData.allowedMacros.length > 0) {
$scope.macros = _.filter(data, function(d) {
return _.contains($scope.dialogData.allowedMacros, d.alias);
});
}
else {
$scope.macros = data;
}
//check if there's a pre-selected macro and if it exists //check if there's a pre-selected macro and if it exists
if ($scope.dialogData && $scope.dialogData.macroData && $scope.dialogData.macroData.macroAlias) { if ($scope.dialogData && $scope.dialogData.macroData && $scope.dialogData.macroData.macroAlias) {

View File

@@ -15,7 +15,11 @@
<div class="umb-panel-body no-header umb-scrollable" auto-scale="90" ng-switch="wizardStep"> <div class="umb-panel-body no-header umb-scrollable" auto-scale="90" ng-switch="wizardStep">
<umb-control-group label="Choose a macro" ng-switch-when="macroSelect"> <umb-control-group label="Choose a macro" ng-switch-when="macroSelect">
<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> <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>
<option value=""><localize key="choose" />...</option> <option value=""><localize key="choose" />...</option>
</select> </select>
<span class="help-inline" val-msg-for="selectedMacro" val-toggle-msg="required"><localize key="required" /></span> <span class="help-inline" val-msg-for="selectedMacro" val-toggle-msg="required"><localize key="required" /></span>

View File

@@ -2,7 +2,7 @@
angular.module('umbraco') angular.module('umbraco')
.controller("Umbraco.PropertyEditors.MacroContainerController", .controller("Umbraco.PropertyEditors.MacroContainerController",
function($scope, dialogService, entityResource, macroService, macroResource){ function($scope, dialogService, entityResource, macroService){
$scope.renderModel = []; $scope.renderModel = [];
if($scope.model.value){ if($scope.model.value){
@@ -35,11 +35,13 @@ angular.module('umbraco')
} }
function openDialog(index){ function openDialog(index){
var dialogData = {}; var dialogData = {
allowedMacros: $scope.model.config.allowed
};
if(index !== null && $scope.renderModel[index]) { if(index !== null && $scope.renderModel[index]) {
var macro = $scope.renderModel[index]; var macro = $scope.renderModel[index];
dialogData = {macroData: macro}; dialogData[macroData] = macro;
} }
dialogService.macroPicker({ dialogService.macroPicker({

View File

@@ -0,0 +1,15 @@
function MacroListController($scope, entityResource) {
$scope.items = [];
entityResource.getAll("Macro").then(function(items) {
_.each(items, function(i) {
$scope.items.push({ name: i.name, alias: i.alias });
});
});
}
angular.module("umbraco").controller("Umbraco.PrevalueEditors.MacroList", MacroListController);

View File

@@ -0,0 +1,7 @@
<div ng-controller="Umbraco.PrevalueEditors.MacroList">
<select multiple ng-multiple="true"
ng-model="model.value"
ng-options="i.alias as i.name for i in items"></select>
</div>

View File

@@ -12,6 +12,15 @@ namespace Umbraco.Web.PropertyEditors
[PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer")] [PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer")]
public class MacroContainerPropertyEditor : PropertyEditor public class MacroContainerPropertyEditor : PropertyEditor
{ {
/// <summary>
/// Creates a pre value editor instance
/// </summary>
/// <returns></returns>
protected override PreValueEditor CreatePreValueEditor()
{
return new MacroContainerPreValueEditor();
}
protected override PropertyValueEditor CreateValueEditor() protected override PropertyValueEditor CreateValueEditor()
{ {
//TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists! //TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists!
@@ -19,5 +28,14 @@ namespace Umbraco.Web.PropertyEditors
return base.CreateValueEditor(); return base.CreateValueEditor();
} }
internal class MacroContainerPreValueEditor : PreValueEditor
{
[PreValueField("max", "Max items", "number", Description = "The maximum number of macros that are allowed in the container")]
public int MaxItems { get; set; }
[PreValueField("allowed", "Allowed items", "views/propertyeditors/macrocontainer/macrolist.prevalues.html", Description = "The macro types allowed, if none are selected all macros will be allowed")]
public object AllowedItems { get; set; }
}
} }
} }

View File

@@ -59,8 +59,7 @@ namespace Umbraco.Web.Scheduling
wc.Headers.Set("Authorization", AdminTokenAuthorizeAttribute.GetAuthHeaderTokenVal(_appContext)); wc.Headers.Set("Authorization", AdminTokenAuthorizeAttribute.GetAuthHeaderTokenVal(_appContext));
var result = wc.UploadString(url, ""); var result = wc.UploadString(url, "");
} }
}
} }
} }
catch (Exception ee) catch (Exception ee)

View File

@@ -53,16 +53,14 @@ namespace Umbraco.Web.Trees
//convert them to ApplicationTree instances //convert them to ApplicationTree instances
var legacyItems = legacyTreeTypes var legacyItems = legacyTreeTypes
.Select(x => .Select(x =>
new Tuple<Type, global::umbraco.businesslogic.TreeAttribute, ObsoleteAttribute>( new Tuple<Type, global::umbraco.businesslogic.TreeAttribute, ObsoleteAttribute>(
new Tuple<Type, global::umbraco.businesslogic.TreeAttribute>( x,
x, x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault(),
x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault(), x.GetCustomAttributes<ObsoleteAttribute>(false).SingleOrDefault()))
x.GetCustomAttributes<global::umbraco.businesslogic.TreeAttribute>(false).SingleOrDefault())) //ensure that the legacy tree attribute exists
x.GetCustomAttributes<ObsoleteAttribute>(false).SingleOrDefault()))
//ensure that the legacy tree attribute exists
.Where(x => x.Item2 != null) .Where(x => x.Item2 != null)
//ensure that it's not obsoleted, any obsoleted tree will not be auto added to the config //ensure that it's not obsoleted, any obsoleted tree will not be auto added to the config
.Where(x => x.Item3 == null) .Where(x => x.Item3 == null)
//make sure the legacy tree isn't added on top of the controller tree! //make sure the legacy tree isn't added on top of the controller tree!
.Where(x => added.InvariantContains(x.Item2.Alias) == false) .Where(x => added.InvariantContains(x.Item2.Alias) == false)
.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())); .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()));

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Examine.LuceneEngine.Config; using Examine.LuceneEngine.Config;
@@ -13,7 +12,6 @@ using Examine;
using System.IO; using System.IO;
using UmbracoExamine.DataServices; using UmbracoExamine.DataServices;
using Lucene.Net.Analysis; using Lucene.Net.Analysis;
using Member = umbraco.cms.businesslogic.member.Member;
namespace UmbracoExamine namespace UmbracoExamine
{ {