Refactor of ContentTypeContainerConfiguration to use a collection instead of multiple delimited strings
This commit is contained in:
@@ -39,9 +39,10 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
|
||||
allowBulkPublish: true,
|
||||
allowBulkUnpublish: true,
|
||||
allowBulkDelete: true,
|
||||
additionalColumnAliases: ['UpdateDate', 'Owner'],
|
||||
additionalColumnHeaders: ['Last edited', 'Updated by'],
|
||||
additionalColumnLocalizationKeys: ['defaultdialogs_lastEdited', 'content_updatedBy']
|
||||
additionalColumns: [
|
||||
{ alias: 'UpdateDate', header: 'Last edited', localizationKey: 'defaultdialogs_lastEdited' },
|
||||
{ alias: 'Owner', header: 'Last edited', localizationKey: 'content_updatedBy' }
|
||||
]
|
||||
};
|
||||
|
||||
// Retrieve the container configuration for the content type and set options before presenting initial view
|
||||
@@ -50,10 +51,8 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
|
||||
if (typeof config.pageSize !== 'undefined') {
|
||||
$scope.options.pageSize = config.pageSize;
|
||||
}
|
||||
if (typeof config.additionalColumnAliases !== 'undefined') {
|
||||
$scope.options.additionalColumnAliases = config.additionalColumnAliases.split(',');
|
||||
$scope.options.additionalColumnHeaders = config.additionalColumnHeaders.split(',');
|
||||
$scope.options.additionalColumnLocalizationKeys = config.additionalColumnLocalizationKeys.split(',');
|
||||
if (typeof config.additionalColumns !== 'undefined') {
|
||||
$scope.options.additionalColumns = config.additionalColumns;
|
||||
}
|
||||
if (typeof config.orderBy !== 'undefined') {
|
||||
$scope.options.orderBy = config.orderBy;
|
||||
@@ -138,11 +137,11 @@ function listViewController($rootScope, $scope, $routeParams, $injector, notific
|
||||
};
|
||||
|
||||
$scope.getColumnName = function (index) {
|
||||
return $scope.options.additionalColumnHeaders[index];
|
||||
return $scope.options.additionalColumns[index].header;
|
||||
};
|
||||
|
||||
$scope.getColumnLocalizationKey = function (index) {
|
||||
return $scope.options.additionalColumnLocalizationKeys[index];
|
||||
return $scope.options.additionalColumns[index].localizationKey;
|
||||
};
|
||||
|
||||
$scope.getPropertyValue = function (alias, result) {
|
||||
|
||||
@@ -58,10 +58,10 @@
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<td ng-repeat="alias in options.additionalColumnAliases">
|
||||
<a href="#" ng-click="sort(alias)" prevent-default>
|
||||
<localize ng-if="getColumnLocalizationKey($index) !== ''" key="{{getColumnLocalizationKey($index)}}">{{getColumnName($index)}}</localize>
|
||||
<span ng-if="getColumnLocalizationKey($index) === ''">{{getColumnName($index)}}</span>
|
||||
<td ng-repeat="column in options.additionalColumns">
|
||||
<a href="#" ng-click="sort(column.alias)" prevent-default>
|
||||
<localize ng-if="getColumnLocalizationKey($index) !== ''" key="{{getColumnLocalizationKey($index)}}">{{getColumnName($index)}}</localize>
|
||||
<span ng-if="getColumnLocalizationKey($index) === ''">{{getColumnName($index)}}</span>
|
||||
<i class="icon-sort"></i>
|
||||
</a>
|
||||
</td>
|
||||
@@ -87,8 +87,8 @@
|
||||
<a ng-class="{inactive: (entityType === 'content' && !result.published) || isTrashed}" href="#/{{entityType}}/{{entityType}}/edit/{{result.id}}">{{result.name}}</a>
|
||||
</td>
|
||||
|
||||
<td ng-repeat="alias in options.additionalColumnAliases">
|
||||
{{getPropertyValue(alias, result)}}
|
||||
<td ng-repeat="column in options.additionalColumns">
|
||||
{{getPropertyValue(column.alias, result)}}
|
||||
</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -48,14 +49,11 @@ namespace Umbraco.Web.Editors
|
||||
if (!string.IsNullOrEmpty(contentItem.ContentType.ContainerConfig))
|
||||
{
|
||||
var containerConfig = JsonConvert.DeserializeObject<ContentTypeContainerConfiguration>(contentItem.ContentType.ContainerConfig);
|
||||
containerConfig.AdditionalColumns = new List<ContentTypeContainerConfiguration.AdditionalColumnDetail>();
|
||||
|
||||
// Populate the column headings and localization keys
|
||||
// Populate the column headings and localization keys
|
||||
if (!string.IsNullOrEmpty(containerConfig.AdditionalColumnAliases))
|
||||
{
|
||||
var aliases = containerConfig.AdditionalColumnAliases.Split(',');
|
||||
var headings = new string[aliases.Length];
|
||||
var localizationKeys = new string[aliases.Length];
|
||||
|
||||
// Find all the properties for doc types that might be in the list
|
||||
var allowedContentTypeIds = contentItem.ContentType.AllowedContentTypes
|
||||
.Select(x => x.Id.Value)
|
||||
@@ -65,38 +63,43 @@ namespace Umbraco.Web.Editors
|
||||
.SelectMany(x => x.PropertyTypes)
|
||||
.ToList();
|
||||
|
||||
for (int i = 0; i < aliases.Length; i++)
|
||||
foreach (var alias in containerConfig.AdditionalColumnAliases.Split(','))
|
||||
{
|
||||
var column = new ContentTypeContainerConfiguration.AdditionalColumnDetail
|
||||
{
|
||||
Alias = alias,
|
||||
};
|
||||
|
||||
// Try to find heading from custom property (getting the name from the alias)
|
||||
// - need to look in children of the current content's content type
|
||||
var property = allPropertiesOfAllowedContentTypes
|
||||
.FirstOrDefault(x => x.Alias == aliases[i].ToFirstLower());
|
||||
.FirstOrDefault(x => x.Alias == alias.ToFirstLower());
|
||||
if (property != null)
|
||||
{
|
||||
headings[i] = property.Name;
|
||||
column.Header = property.Name;
|
||||
column.LocalizationKey = string.Empty;
|
||||
}
|
||||
else if (aliases[i] == "UpdateDate")
|
||||
else if (alias == "UpdateDate")
|
||||
{
|
||||
// Special case to restore hard-coded column titles
|
||||
headings[i] = "Last edited";
|
||||
localizationKeys[i] = "defaultdialogs_lastEdited";
|
||||
column.Header = "Last edited";
|
||||
column.LocalizationKey = "defaultdialogs_lastEdited";
|
||||
}
|
||||
else if (aliases[i] == "Owner")
|
||||
else if (alias == "Owner")
|
||||
{
|
||||
// Special case to restore hard-coded column titles (2)
|
||||
headings[i] = "Updated by";
|
||||
localizationKeys[i] = "content_updatedBy";
|
||||
column.Header = "Updated by";
|
||||
column.LocalizationKey = "content_updatedBy";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just sentence case the alias
|
||||
headings[i] = aliases[i].ToFirstUpper().SplitPascalCasing();
|
||||
localizationKeys[i] = "content_" + aliases[i].ToFirstLower();
|
||||
column.Header = alias.ToFirstUpper().SplitPascalCasing();
|
||||
column.LocalizationKey = "content_" + alias.ToFirstLower();
|
||||
}
|
||||
}
|
||||
|
||||
containerConfig.AdditionalColumnHeaders = string.Join(",", headings);
|
||||
containerConfig.AdditionalColumnLocalizationKeys = string.Join(",", localizationKeys);
|
||||
containerConfig.AdditionalColumns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
return containerConfig;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
@@ -20,20 +21,6 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
/// </summary>
|
||||
[DataMember(Name = "additionalColumnAliases")]
|
||||
public string AdditionalColumnAliases { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The headers for the additional columns displayed after the node name in the list
|
||||
/// </summary>
|
||||
/// <remarks>This isn't persisted, but is calculated from the aliases when passed to the UI</remarks>
|
||||
[DataMember(Name = "additionalColumnHeaders")]
|
||||
public string AdditionalColumnHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The localization keys for the additional columns displayed after the node name in the list
|
||||
/// </summary>
|
||||
/// <remarks>This isn't persisted, but is calculated from the aliases when passed to the UI</remarks>
|
||||
[DataMember(Name = "additionalColumnLocalizationKeys")]
|
||||
public string AdditionalColumnLocalizationKeys { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The default order by column for the list
|
||||
@@ -64,5 +51,25 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
/// </summary>
|
||||
[DataMember(Name = "allowBulkDelete")]
|
||||
public bool AllowBulkDelete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The column details for the additional columns displayed after the node name in the list
|
||||
/// </summary>
|
||||
/// <remarks>This isn't persisted, but is calculated from the aliases when passed to the UI</remarks>
|
||||
[DataMember(Name = "additionalColumns")]
|
||||
public IList<AdditionalColumnDetail> AdditionalColumns { get; set; }
|
||||
|
||||
[DataContract(Namespace = "")]
|
||||
public class AdditionalColumnDetail
|
||||
{
|
||||
[DataMember(Name = "alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[DataMember(Name = "header")]
|
||||
public string Header { get; set; }
|
||||
|
||||
[DataMember(Name = "localizationKey")]
|
||||
public string LocalizationKey { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user