From 62cda02dedc9f84d1b98c101479b3acb7664ea75 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 27 Sep 2017 16:02:32 +0200 Subject: [PATCH] Some clean up in ContentModelMapper.cs --- .../Models/Mapping/ContentModelMapper.cs | 116 +++++++++--------- .../Mapping/TabsAndPropertiesResolver.cs | 2 +- 2 files changed, 57 insertions(+), 61 deletions(-) diff --git a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs index 1d187110a8..330823be96 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentModelMapper.cs @@ -119,67 +119,63 @@ namespace Umbraco.Web.Models.Mapping { TabsAndPropertiesResolver.AddListView(display, "content", dataTypeService, localizedText); } - - var properties = new List(); - - TabsAndPropertiesResolver.MapGenericProperties(content, display, localizedText, properties.ToArray(), - genericProperties => - { - //TODO: This would be much nicer with the IUmbracoContextAccessor so we don't use singletons - //If this is a web request and there's a user signed in and the - // user has access to the settings section, we will - if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null - && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) - { - var currentDocumentType = contentTypeService.GetContentType(display.ContentTypeAlias); - var currentDocumentTypeName = currentDocumentType == null ? string.Empty : localizedText.UmbracoDictionaryTranslate(currentDocumentType.Name); - - var currentDocumentTypeId = currentDocumentType == null ? string.Empty : currentDocumentType.Id.ToString(CultureInfo.InvariantCulture); - //TODO: Hard coding this is not good - var docTypeLink = string.Format("#/settings/documenttypes/edit/{0}", currentDocumentTypeId); - - var templateProperty = new ContentPropertyDisplay - { - Alias = string.Format("{0}template", - Constants.PropertyEditors.InternalGenericPropertiesPrefix), - Label = localizedText.Localize("template/template"), - Value = display.TemplateAlias, - View = - "dropdown", //TODO: Hard coding until we make a real dropdown property editor to lookup - Config = new Dictionary - { - {"items", templateItemConfig} - } - }; - - //Replace the doc type property - var docTypeProperty = new ContentPropertyDisplay - { - Alias = string.Format("{0}doctype", - Constants.PropertyEditors.InternalGenericPropertiesPrefix), - Label = localizedText.Localize("content/documentType"), - Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName), - View = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias) - .ValueEditor.View - }; - docTypeProperty.Value = new List - { - new - { - linkText = currentDocumentTypeName, - url = docTypeLink, - target = "_self", - icon = "icon-item-arrangement" - } - }; - //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor - docTypeProperty.View = "urllist"; - //Moving template and docType properties to the root node (issue U4-10311) - display.AllowedTemplates = templateProperty.Config; - display.DocTypeValue = docTypeProperty.Value; - } - }); + //TODO: This would be much nicer with the IUmbracoContextAccessor so we don't use singletons + //If this is a web request and there's a user signed in and the + // user has access to the settings section, we will + if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null + && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) + { + var currentDocumentType = contentTypeService.GetContentType(display.ContentTypeAlias); + var currentDocumentTypeName = currentDocumentType == null ? string.Empty : localizedText.UmbracoDictionaryTranslate(currentDocumentType.Name); + + var currentDocumentTypeId = currentDocumentType == null ? string.Empty : currentDocumentType.Id.ToString(CultureInfo.InvariantCulture); + //TODO: Hard coding this is not good + var docTypeLink = string.Format("#/settings/documenttypes/edit/{0}", currentDocumentTypeId); + + var templateProperty = new ContentPropertyDisplay + { + Alias = string.Format("{0}template", + Constants.PropertyEditors.InternalGenericPropertiesPrefix), + Label = localizedText.Localize("template/template"), + Value = display.TemplateAlias, + View = + "dropdown", //TODO: Hard coding until we make a real dropdown property editor to lookup + Config = new Dictionary + { + {"items", templateItemConfig} + } + }; + + //Replace the doc type property + var docTypeProperty = new ContentPropertyDisplay + { + Alias = string.Format("{0}doctype", + Constants.PropertyEditors.InternalGenericPropertiesPrefix), + Label = localizedText.Localize("content/documentType"), + Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName), + View = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias) + .ValueEditor.View + }; + docTypeProperty.Value = new List + { + new + { + linkText = currentDocumentTypeName, + url = docTypeLink, + target = "_self", + icon = "icon-item-arrangement" + } + }; + //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor + docTypeProperty.View = "urllist"; + + //Moving template and docType properties to the root node (issue U4-10311) + display.AllowedTemplates = templateProperty.Config; + display.DocTypeValue = docTypeProperty.Value; + } + + TabsAndPropertiesResolver.MapGenericProperties(content, display, localizedText); } /// diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs index b5f219a072..f49c2893b8 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs @@ -81,7 +81,7 @@ namespace Umbraco.Web.Models.Mapping //re-assign genericProps.Properties = contentProps; - //Show or hide properties tab if it has any properties + //Show or hide properties tab based on wether it has or not any properties if (genericProps.Properties.Any() == false) { display.Tabs = display.Tabs.Where(x => x.Id != 0);