/// <summary> /// Returns a paged result of media items known to be of a "Folder" type /// </summary> /// <param name="id"></param> /// <param name="pageNumber"></param> /// <param name="pageSize"></param> /// <returns></returns> public PagedResult <ContentItemBasic <ContentPropertyBasic> > GetChildFolders(int id, int pageNumber = 1, int pageSize = 1000) { //Suggested convention for folder mediatypes - we can make this more or less complicated as long as we document it... //if you create a media type, which has an alias that ends with ...Folder then its a folder: ex: "secureFolder", "bannerFolder", "Folder" var folderTypes = _mediaTypeService .GetAll() .Where(x => x.Alias.EndsWith("Folder")) .Select(x => x.Id) .ToArray(); if (folderTypes.Length == 0) { return(new PagedResult <ContentItemBasic <ContentPropertyBasic> >(0, pageNumber, pageSize)); } long total; var children = _mediaService.GetPagedChildren(id, pageNumber - 1, pageSize, out total, //lookup these content types _sqlContext.Query <IMedia>().Where(x => folderTypes.Contains(x.ContentTypeId)), Ordering.By("Name", Direction.Ascending)); return(new PagedResult <ContentItemBasic <ContentPropertyBasic> >(total, pageNumber, pageSize) { Items = children.Select(_umbracoMapper.Map <IMedia, ContentItemBasic <ContentPropertyBasic> >) }); }
public IList <TypeModel> GetAllTypes() { var types = new List <TypeModel>(); types.AddRange(GetTypes(PublishedItemType.Content, _contentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes(PublishedItemType.Media, _mediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes(PublishedItemType.Member, _memberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); return(EnsureDistinctAliases(types)); }
public IList <TypeModel> GetAllTypes() { var types = new List <TypeModel>(); // TODO: this will require 3 rather large SQL queries on startup in PureLive. I know that these will be cached after lookup but it will slow // down startup time ... BUT these queries are also used in NuCache on startup so we can't really avoid them. Maybe one day we can // load all of these in in one query and still have them cached per service, and/or somehow improve the perf of these since they are used on startup // in more than one place. types.AddRange(GetTypes(PublishedItemType.Content, _contentTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes(PublishedItemType.Media, _mediaTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); types.AddRange(GetTypes(PublishedItemType.Member, _memberTypeService.GetAll().Cast <IContentTypeComposition>().ToArray())); return(EnsureDistinctAliases(types)); }
/// <summary> /// Returns the references (usages) for the data type /// </summary> /// <param name="id"></param> /// <returns></returns> public DataTypeReferences GetReferences(int id) { var result = new DataTypeReferences(); var usages = _dataTypeService.GetReferences(id); foreach (var groupOfEntityType in usages.GroupBy(x => x.Key.EntityType)) { //get all the GUIDs for the content types to find var guidsAndPropertyAliases = groupOfEntityType.ToDictionary(i => ((GuidUdi)i.Key).Guid, i => i.Value); if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.DocumentType)) { result.DocumentTypes = GetContentTypeUsages(_contentTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MediaType)) { result.MediaTypes = GetContentTypeUsages(_mediaTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } else if (groupOfEntityType.Key == ObjectTypes.GetUdiType(UmbracoObjectTypes.MemberType)) { result.MemberTypes = GetContentTypeUsages(_memberTypeService.GetAll(guidsAndPropertyAliases.Keys), guidsAndPropertyAliases); } } return(result); }
protected override ActionResult <TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings) { if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId)) { throw new InvalidOperationException("Id must be an integer"); } var nodes = new TreeNodeCollection(); nodes.AddRange( _entityService.GetChildren(intId, UmbracoObjectTypes.MediaTypeContainer) .OrderBy(entity => entity.Name) .Select(dt => { TreeNode node = CreateTreeNode(dt.Id.ToString(), id, queryStrings, dt.Name, Constants.Icons.Folder, dt.HasChildren, ""); node.Path = dt.Path; node.NodeType = "container"; // TODO: This isn't the best way to ensure a no operation process for clicking a node but it works for now. node.AdditionalData["jsClickCallback"] = "javascript:void(0);"; return(node); })); // if the request is for folders only then just return if (queryStrings["foldersonly"].ToString().IsNullOrWhiteSpace() == false && queryStrings["foldersonly"].ToString() == "1") { return(nodes); } IEnumerable <IMediaType> mediaTypes = _mediaTypeService.GetAll(); nodes.AddRange( _entityService.GetChildren(intId, UmbracoObjectTypes.MediaType) .OrderBy(entity => entity.Name) .Select(dt => { // since 7.4+ child type creation is enabled by a config option. It defaults to on, but can be disabled if we decide to. // need this check to keep supporting sites where children have already been created. var hasChildren = dt.HasChildren; IMediaType?mt = mediaTypes.FirstOrDefault(x => x.Id == dt.Id); TreeNode node = CreateTreeNode(dt, Constants.ObjectTypes.MediaType, id, queryStrings, mt?.Icon ?? Constants.Icons.MediaType, hasChildren); node.Path = dt.Path; return(node); })); return(nodes); }
private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e) { switch (sender.TreeAlias) { case Constants.Trees.DocumentTypes: UpdateNodeIcons(e, _contentTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.DocumentTypes); break; case Constants.Trees.MemberTypes: UpdateNodeIcons(e, _memberTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.MemberTypes); break; case Constants.Trees.MediaTypes: UpdateNodeIcons(e, _mediaTypeService.GetAll()?.ToDictionary(c => c.Id, c => c.Icon), Constants.Trees.MediaTypes); break; } }
/// <summary> /// Checks the tree alias and node alias to see if we should update the icon /// Gets the types from the type services and calls the method to update the node icons /// </summary> /// <param name="sender">Tree controller base</param> /// <param name="e">Event args</param> private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e) { switch (sender.TreeAlias) { case "documentTypes": var contentTypeIcons = _contentTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, contentTypeIcons, "documentTypes"); break; case "memberTypes": var memberTypeIcons = _memberTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, memberTypeIcons, "memberTypes"); break; case "mediaTypes": var mediaTypeIcons = _mediaTypeService.GetAll().ToDictionary(c => c.Id, c => c.Icon); UpdateNodeIcons(e, mediaTypeIcons, "mediaTypes"); break; default: // don't change the icon break; } }
public IEnumerable <ContentTypeBasic> GetAll() => _mediaTypeService.GetAll() .Select(_umbracoMapper.Map <IMediaType, ContentTypeBasic>);