Merge pull request #2225 from umbraco/temp-U4-10473
Moved documentType and mediaLink to root node for media section
This commit is contained in:
@@ -10,53 +10,19 @@
|
||||
scope.allowOpenMediaType = true;
|
||||
|
||||
// get document type details
|
||||
scope.mediaType = getMediaType(scope.node);
|
||||
scope.mediaType = scope.node.contentType;
|
||||
|
||||
// get node url
|
||||
scope.nodeUrl = getNodeUrl(scope.node);
|
||||
scope.nodeUrl = scope.node.mediaLink;
|
||||
|
||||
}
|
||||
|
||||
scope.openMediaType = function (mediaType) {
|
||||
// remove first "#" from url if it is prefixed else the path won't work
|
||||
var url = mediaType.url.replace(/^#/, "");
|
||||
var url = "/settings/mediaTypes/edit/" + mediaType.id;
|
||||
$location.path(url);
|
||||
};
|
||||
|
||||
function getMediaType(node) {
|
||||
|
||||
var mediaType = {};
|
||||
|
||||
// find the document type in the properties array
|
||||
angular.forEach(node.properties, function (property) {
|
||||
if (property.alias === "_umb_doctype") {
|
||||
if (property.value && property.value.length > 0) {
|
||||
mediaType = property.value[0];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return mediaType;
|
||||
|
||||
}
|
||||
|
||||
function getNodeUrl(node) {
|
||||
|
||||
var nodeUrl = "";
|
||||
|
||||
// find the document type in the properties array
|
||||
angular.forEach(node.properties, function (property) {
|
||||
if (property.alias === "_umb_urls") {
|
||||
if (property.value) {
|
||||
nodeUrl = property.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return nodeUrl;
|
||||
|
||||
}
|
||||
|
||||
onInit();
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<umb-node-preview
|
||||
style="max-width: 100%; margin-bottom: 0px;"
|
||||
icon="mediaType.icon"
|
||||
name="mediaType.linkText"
|
||||
name="mediaType.name"
|
||||
allow-open="allowOpenMediaType"
|
||||
on-open="openMediaType(mediaType)">
|
||||
</umb-node-preview>
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
[DataContract(Name = "content", Namespace = "")]
|
||||
public class MediaItemDisplay : ListViewAwareContentItemDisplayBase<ContentPropertyDisplay, IMedia>
|
||||
{
|
||||
|
||||
[DataMember(Name = "contentType")]
|
||||
public ContentTypeBasic ContentType { get; set; }
|
||||
|
||||
[DataMember(Name = "mediaLink")]
|
||||
public string MediaLink { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,9 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(display => display.IsContainer, expression => expression.Ignore())
|
||||
.ForMember(display => display.HasPublishedVersion, expression => expression.Ignore())
|
||||
.ForMember(display => display.Tabs, expression => expression.ResolveUsing(new TabsAndPropertiesResolver(applicationContext.Services.TextService)))
|
||||
.ForMember(display => display.ContentType, expression => expression.ResolveUsing<MediaTypeBasicResolver>())
|
||||
.ForMember(display => display.MediaLink, expression => expression.ResolveUsing(
|
||||
content => string.Join(",", content.GetUrls(UmbracoConfig.For.UmbracoSettings().Content, applicationContext.ProfilingLogger.Logger))))
|
||||
.AfterMap((media, display) => AfterMap(media, display, applicationContext.Services.DataTypeService, applicationContext.Services.TextService, applicationContext.Services.ContentTypeService, applicationContext.ProfilingLogger.Logger));
|
||||
|
||||
//FROM IMedia TO ContentItemBasic<ContentPropertyBasic, IMedia>
|
||||
@@ -64,7 +67,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(dto => dto.Updater, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.Icon, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.Alias, expression => expression.Ignore())
|
||||
.ForMember(dto => dto.HasPublishedVersion, expression => expression.Ignore());
|
||||
.ForMember(dto => dto.HasPublishedVersion, expression => expression.Ignore());
|
||||
}
|
||||
|
||||
private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService, ILocalizedTextService localizedText, IContentTypeService contentTypeService, ILogger logger)
|
||||
@@ -87,53 +90,32 @@ namespace Umbraco.Web.Models.Mapping
|
||||
TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService, localizedText);
|
||||
}
|
||||
|
||||
var genericProperties = new List<ContentPropertyDisplay>
|
||||
TabsAndPropertiesResolver.MapGenericProperties(media, display, localizedText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves a <see cref="ContentTypeBasic"/> from the <see cref="IContent"/> item and checks if the current user
|
||||
/// has access to see this data
|
||||
/// </summary>
|
||||
private class MediaTypeBasicResolver : ValueResolver<IMedia, ContentTypeBasic>
|
||||
{
|
||||
protected override ContentTypeBasic ResolveCore(IMedia source)
|
||||
{
|
||||
new ContentPropertyDisplay
|
||||
//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)))
|
||||
{
|
||||
Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
|
||||
Label = localizedText.Localize("content/mediatype"),
|
||||
Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
|
||||
View = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View
|
||||
var contentTypeBasic = Mapper.Map<ContentTypeBasic>(source.ContentType);
|
||||
return contentTypeBasic;
|
||||
}
|
||||
};
|
||||
//no access
|
||||
return null;
|
||||
}
|
||||
|
||||
TabsAndPropertiesResolver.MapGenericProperties(media, display, localizedText, genericProperties, properties =>
|
||||
{
|
||||
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 mediaTypeLink = string.Format("#/settings/mediatypes/edit/{0}", media.ContentTypeId);
|
||||
|
||||
//Replace the doctype property
|
||||
var docTypeProperty = properties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix));
|
||||
docTypeProperty.Value = new List<object>
|
||||
{
|
||||
new
|
||||
{
|
||||
linkText = media.ContentType.Name,
|
||||
url = mediaTypeLink,
|
||||
target = "_self",
|
||||
icon = "icon-item-arrangement"
|
||||
}
|
||||
};
|
||||
docTypeProperty.View = "urllist";
|
||||
}
|
||||
|
||||
// inject 'Link to media' as the first generic property
|
||||
var links = media.GetUrls(UmbracoConfig.For.UmbracoSettings().Content, logger);
|
||||
if (links.Any())
|
||||
{
|
||||
var link = new ContentPropertyDisplay
|
||||
{
|
||||
Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
|
||||
Label = localizedText.Localize("media/urls"),
|
||||
Value = string.Join(",", links),
|
||||
View = "urllist"
|
||||
};
|
||||
properties.Insert(0, link);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user