Item tracking fixes (#12146)
* Cleanup; Fix lang keys * Documentation * Typos * Distinct the results * Changed GetPagedRelationsForItems to GetPagedRelationsForItem as we would only expect a single id to be passed when calling this + fix more docs * Changed to the correct reference * Unused code * Only load references when info tab is clicked Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Cms.Core.Persistence.Repositories
|
||||
{
|
||||
public interface ITrackedReferencesRepository
|
||||
{
|
||||
IEnumerable<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
|
||||
IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
|
||||
IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
|
||||
/// <summary>
|
||||
/// Gets a page of items which are in relation with the current item.
|
||||
/// Basically, shows the items which depend on the current item.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the entity to retrieve relations for.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <param name="totalRecords">The total count of the items with reference to the current item.</param>
|
||||
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
|
||||
IEnumerable<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a page of items used in any kind of relation from selected integer ids.
|
||||
/// </summary>
|
||||
/// <param name="ids">The identifiers of the entities to check for relations.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <param name="totalRecords">The total count of the items in any kind of relation.</param>
|
||||
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
|
||||
IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a page of the descending items that have any references, given a parent id.
|
||||
/// </summary>
|
||||
/// <param name="parentId">The unique identifier of the parent to retrieve descendants for.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <param name="totalRecords">The total count of descending items.</param>
|
||||
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
|
||||
IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,35 @@ namespace Umbraco.Cms.Core.Services
|
||||
{
|
||||
public interface ITrackedReferencesService
|
||||
{
|
||||
PagedResult<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paged result of items which are in relation with the current item.
|
||||
/// Basically, shows the items which depend on the current item.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the entity to retrieve relations for.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
|
||||
PagedResult<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paged result of the descending items that have any references, given a parent id.
|
||||
/// </summary>
|
||||
/// <param name="parentId">The unique identifier of the parent to retrieve descendants for.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
|
||||
PagedResult<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paged result of items used in any kind of relation from selected integer ids.
|
||||
/// </summary>
|
||||
/// <param name="ids">The identifiers of the entities to check for relations.</param>
|
||||
/// <param name="pageIndex">The page index.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
|
||||
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
|
||||
PagedResult<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,6 +659,12 @@ namespace Umbraco.Extensions
|
||||
return sql;
|
||||
}
|
||||
|
||||
public static Sql<ISqlContext> SelectDistinct(this Sql<ISqlContext> sql, params object[] columns)
|
||||
{
|
||||
sql.Append("SELECT DISTINCT " + string.Join(", ", columns));
|
||||
return sql;
|
||||
}
|
||||
|
||||
//this.Append("SELECT " + string.Join(", ", columns), new object[0]);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -198,22 +198,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildIds(int[] childIds, long pageIndex, int pageSize, out long totalRecords, int[] relationTypes, params Guid[] entityTypes)
|
||||
{
|
||||
return _entityRepository.GetPagedResultsByQuery(Query<IUmbracoEntity>(), entityTypes, pageIndex, pageSize, out totalRecords, null, null, sql =>
|
||||
{
|
||||
SqlJoinRelations(sql);
|
||||
|
||||
sql.WhereIn<RelationDto>(rel => rel.ChildId, childIds);
|
||||
sql.WhereAny(s => s.WhereIn<RelationDto>(rel => rel.ParentId, childIds), s => s.WhereNotIn<NodeDto>(node => node.NodeId, childIds));
|
||||
|
||||
if (relationTypes != null && relationTypes.Any())
|
||||
{
|
||||
sql.WhereIn<RelationDto>(rel => rel.RelationType, relationTypes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int parentId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
|
||||
{
|
||||
return GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
|
||||
@@ -241,21 +225,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<IUmbracoEntity> GetPagedEntitiesForItemsInRelation(int[] itemIds, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
|
||||
{
|
||||
return _entityRepository.GetPagedResultsByQuery(Query<IUmbracoEntity>(), entityTypes, pageIndex, pageSize, out totalRecords, null, null, sql =>
|
||||
{
|
||||
SqlJoinRelations(sql);
|
||||
|
||||
sql.WhereIn<RelationDto>(rel => rel.ChildId, itemIds);
|
||||
sql.Where<RelationDto, NodeDto>((rel, node) => rel.ChildId == node.NodeId);
|
||||
sql.Where<RelationTypeDto>(type => type.IsDependency);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void Save(IEnumerable<IRelation> relations)
|
||||
{
|
||||
foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity))
|
||||
@@ -475,8 +444,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
[Column(Name = "contentTypeName")]
|
||||
public string ChildContentTypeName { get; set; }
|
||||
|
||||
|
||||
|
||||
[Column(Name = "relationTypeName")]
|
||||
public string RelationTypeName { get; set; }
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NPoco;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
||||
@@ -20,10 +19,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
_scopeAccessor = scopeAccessor;
|
||||
}
|
||||
|
||||
public IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize,
|
||||
bool filterMustBeIsDependency, out long totalRecords)
|
||||
/// <summary>
|
||||
/// Gets a page of items used in any kind of relation from selected integer ids.
|
||||
/// </summary>
|
||||
public IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords)
|
||||
{
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().Select(
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().SelectDistinct(
|
||||
"[pn].[id] as nodeId",
|
||||
"[pn].[uniqueId] as nodeKey",
|
||||
"[pn].[text] as nodeName",
|
||||
@@ -36,12 +37,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
"[umbracoRelationType].[isDependency] as relationTypeIsDependency",
|
||||
"[umbracoRelationType].[dual] as relationTypeIsBidirectional")
|
||||
.From<RelationDto>("r")
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight:"umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId )), aliasLeft: "r", aliasRight:"cn", aliasOther: "umbracoRelationType" )
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight:"pn", aliasOther:"cn" )
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"pn", aliasRight:"c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft:"c", aliasRight:"ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"ct", aliasRight:"ctn");
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId)), aliasLeft: "r", aliasRight: "cn", aliasOther: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight: "pn", aliasOther: "cn")
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "pn", aliasRight: "c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft: "c", aliasRight: "ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "ct", aliasRight: "ctn");
|
||||
|
||||
if (ids.Any())
|
||||
{
|
||||
@@ -57,13 +58,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
sql = sql.OrderBy<RelationTypeDto>(x => x.Alias);
|
||||
|
||||
var pagedResult = _scopeAccessor.AmbientScope.Database.Page<RelationItemDto>(pageIndex + 1, pageSize, sql);
|
||||
totalRecords = Convert.ToInt32(pagedResult.TotalItems);
|
||||
totalRecords = pagedResult.TotalItems;
|
||||
|
||||
return pagedResult.Items.Select(MapDtoToEntity);
|
||||
}
|
||||
|
||||
public IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency,
|
||||
out long totalRecords)
|
||||
/// <summary>
|
||||
/// Gets a page of the descending items that have any references, given a parent id.
|
||||
/// </summary>
|
||||
public IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords)
|
||||
{
|
||||
var syntax = _scopeAccessor.AmbientScope.Database.SqlContext.SqlSyntax;
|
||||
|
||||
@@ -73,13 +76,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
.From<NodeDto>("node")
|
||||
.Where<NodeDto>(x => x.NodeId == parentId, "node");
|
||||
|
||||
|
||||
// Gets the descendants of the parent node
|
||||
Sql<ISqlContext> subQuery;
|
||||
|
||||
if (_scopeAccessor.AmbientScope.Database.DatabaseType.IsSqlCe())
|
||||
{
|
||||
// SqlCE do not support nested selects that returns a scalar. So we need to do this in multiple queries
|
||||
// SqlCE does not support nested selects that returns a scalar. So we need to do this in multiple queries
|
||||
|
||||
var pathForLike = _scopeAccessor.AmbientScope.Database.ExecuteScalar<string>(subsubQuery);
|
||||
|
||||
@@ -96,10 +98,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
.WhereLike<NodeDto>(x => x.Path, subsubQuery);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get all relations where parent is in the sub query
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().Select(
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().SelectDistinct(
|
||||
"[pn].[id] as nodeId",
|
||||
"[pn].[uniqueId] as nodeKey",
|
||||
"[pn].[text] as nodeName",
|
||||
@@ -112,29 +112,35 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
"[umbracoRelationType].[isDependency] as relationTypeIsDependency",
|
||||
"[umbracoRelationType].[dual] as relationTypeIsBidirectional")
|
||||
.From<RelationDto>("r")
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight:"umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId )), aliasLeft: "r", aliasRight:"cn", aliasOther: "umbracoRelationType" )
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight:"pn", aliasOther:"cn" )
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"pn", aliasRight:"c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft:"c", aliasRight:"ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"ct", aliasRight:"ctn")
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId)), aliasLeft: "r", aliasRight: "cn", aliasOther: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight: "pn", aliasOther: "cn")
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "pn", aliasRight: "c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft: "c", aliasRight: "ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "ct", aliasRight: "ctn")
|
||||
.WhereIn((System.Linq.Expressions.Expression<Func<NodeDto, object>>)(x => x.NodeId), subQuery, "pn");
|
||||
|
||||
if (filterMustBeIsDependency)
|
||||
{
|
||||
sql = sql.Where<RelationTypeDto>(rt => rt.IsDependency, "umbracoRelationType");
|
||||
}
|
||||
|
||||
// Ordering is required for paging
|
||||
sql = sql.OrderBy<RelationTypeDto>(x => x.Alias);
|
||||
|
||||
var pagedResult = _scopeAccessor.AmbientScope.Database.Page<RelationItemDto>(pageIndex + 1, pageSize, sql);
|
||||
totalRecords = Convert.ToInt32(pagedResult.TotalItems);
|
||||
totalRecords = pagedResult.TotalItems;
|
||||
|
||||
return pagedResult.Items.Select(MapDtoToEntity);
|
||||
}
|
||||
|
||||
public IEnumerable<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords)
|
||||
/// <summary>
|
||||
/// Gets a page of items which are in relation with the current item.
|
||||
/// Basically, shows the items which depend on the current item.
|
||||
/// </summary>
|
||||
public IEnumerable<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords)
|
||||
{
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().Select(
|
||||
var sql = _scopeAccessor.AmbientScope.Database.SqlContext.Sql().SelectDistinct(
|
||||
"[cn].[id] as nodeId",
|
||||
"[cn].[uniqueId] as nodeKey",
|
||||
"[cn].[text] as nodeName",
|
||||
@@ -147,17 +153,13 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
"[umbracoRelationType].[isDependency] as relationTypeIsDependency",
|
||||
"[umbracoRelationType].[dual] as relationTypeIsBidirectional")
|
||||
.From<RelationDto>("r")
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight:"umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId )), aliasLeft: "r", aliasRight:"cn", aliasOther: "umbracoRelationType" )
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight:"pn", aliasOther:"cn" )
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"cn", aliasRight:"c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft:"c", aliasRight:"ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft:"ct", aliasRight:"ctn");
|
||||
|
||||
if (ids.Any())
|
||||
{
|
||||
sql = sql.Where<NodeDto>(x => ids.Contains(x.NodeId), "pn");
|
||||
}
|
||||
.InnerJoin<RelationTypeDto>("umbracoRelationType").On<RelationDto, RelationTypeDto>((left, right) => left.RelationType == right.Id, aliasLeft: "r", aliasRight: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("cn").On<RelationDto, NodeDto, RelationTypeDto>((r, cn, rt) => (!rt.Dual && r.ParentId == cn.NodeId) || (rt.Dual && (r.ChildId == cn.NodeId || r.ParentId == cn.NodeId)), aliasLeft: "r", aliasRight: "cn", aliasOther: "umbracoRelationType")
|
||||
.InnerJoin<NodeDto>("pn").On<RelationDto, NodeDto, NodeDto>((r, pn, cn) => (pn.NodeId == r.ChildId && cn.NodeId == r.ParentId) || (pn.NodeId == r.ParentId && cn.NodeId == r.ChildId), aliasLeft: "r", aliasRight: "pn", aliasOther: "cn")
|
||||
.LeftJoin<ContentDto>("c").On<NodeDto, ContentDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "cn", aliasRight: "c")
|
||||
.LeftJoin<ContentTypeDto>("ct").On<ContentDto, ContentTypeDto>((left, right) => left.ContentTypeId == right.NodeId, aliasLeft: "c", aliasRight: "ct")
|
||||
.LeftJoin<NodeDto>("ctn").On<ContentTypeDto, NodeDto>((left, right) => left.NodeId == right.NodeId, aliasLeft: "ct", aliasRight: "ctn")
|
||||
.Where<NodeDto>(x => x.NodeId == id, "pn");
|
||||
|
||||
if (filterMustBeIsDependency)
|
||||
{
|
||||
@@ -168,14 +170,13 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
sql = sql.OrderBy<RelationTypeDto>(x => x.Alias);
|
||||
|
||||
var pagedResult = _scopeAccessor.AmbientScope.Database.Page<RelationItemDto>(pageIndex + 1, pageSize, sql);
|
||||
totalRecords = Convert.ToInt32(pagedResult.TotalItems);
|
||||
totalRecords = pagedResult.TotalItems;
|
||||
|
||||
return pagedResult.Items.Select(MapDtoToEntity);
|
||||
}
|
||||
|
||||
private RelationItem MapDtoToEntity(RelationItemDto dto)
|
||||
{
|
||||
var type = ObjectTypes.GetUdiType(dto.ChildNodeObjectType);
|
||||
return new RelationItem()
|
||||
{
|
||||
NodeId = dto.ChildNodeId,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
@@ -18,22 +17,32 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
_entityService = entityService;
|
||||
}
|
||||
|
||||
public PagedResult<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency)
|
||||
/// <summary>
|
||||
/// Gets a paged result of items which are in relation with the current item.
|
||||
/// Basically, shows the items which depend on the current item.
|
||||
/// </summary>
|
||||
public PagedResult<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency)
|
||||
{
|
||||
using IScope scope = _scopeProvider.CreateScope(autoComplete: true);
|
||||
var items = _trackedReferencesRepository.GetPagedRelationsForItems(ids, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems);
|
||||
var items = _trackedReferencesRepository.GetPagedRelationsForItem(id, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems);
|
||||
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex+1, pageSize) { Items = items };
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex + 1, pageSize) { Items = items };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paged result of items used in any kind of relation from selected integer ids.
|
||||
/// </summary>
|
||||
public PagedResult<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency)
|
||||
{
|
||||
using IScope scope = _scopeProvider.CreateScope(autoComplete: true);
|
||||
var items = _trackedReferencesRepository.GetPagedItemsWithRelations(ids, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems);
|
||||
var items = _trackedReferencesRepository.GetPagedItemsWithRelations(ids, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems);
|
||||
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex+1, pageSize) { Items = items };
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex + 1, pageSize) { Items = items };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paged result of the descending items that have any references, given a parent id.
|
||||
/// </summary>
|
||||
public PagedResult<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency)
|
||||
{
|
||||
using IScope scope = _scopeProvider.CreateScope(autoComplete: true);
|
||||
@@ -44,7 +53,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
pageSize,
|
||||
filterMustBeIsDependency,
|
||||
out var totalItems);
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex+1, pageSize) { Items = items };
|
||||
return new PagedResult<RelationItem>(totalItems, pageIndex + 1, pageSize) { Items = items };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1082,7 +1082,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
return new ActionResult<IMedia>(toMove);
|
||||
}
|
||||
|
||||
[Obsolete("Please use TrackedReferencesController.GetPagedReferences() instead. Scheduled for removal in V11.")]
|
||||
[Obsolete("Please use TrackedReferencesController.GetPagedRelationsForItem() instead. Scheduled for removal in V11.")]
|
||||
public PagedResult<EntityBasic> GetPagedReferences(int id, string entityType, int pageNumber = 1, int pageSize = 100)
|
||||
{
|
||||
if (pageNumber <= 0 || pageSize <= 0)
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Web.BackOffice.ModelBinders;
|
||||
using Umbraco.Cms.Web.Common.Attributes;
|
||||
@@ -19,28 +14,36 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
public class TrackedReferencesController : BackOfficeNotificationsController
|
||||
{
|
||||
private readonly ITrackedReferencesService _relationService;
|
||||
private readonly IEntityService _entityService;
|
||||
|
||||
public TrackedReferencesController(ITrackedReferencesService relationService,
|
||||
IEntityService entityService)
|
||||
public TrackedReferencesController(ITrackedReferencesService relationService)
|
||||
{
|
||||
_relationService = relationService;
|
||||
_entityService = entityService;
|
||||
}
|
||||
|
||||
// Used by info tabs on content, media etc. So this is basically finding childs of relations.
|
||||
public ActionResult<PagedResult<RelationItem>> GetPagedReferences(int id, int pageNumber = 1,
|
||||
int pageSize = 100, bool filterMustBeIsDependency = false)
|
||||
/// <summary>
|
||||
/// Gets a page list of tracked references for the current item, so you can see where an item is being used.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used by info tabs on content, media etc. and for the delete and unpublish of single items.
|
||||
/// This is basically finding parents of relations.
|
||||
/// </remarks>
|
||||
public ActionResult<PagedResult<RelationItem>> GetPagedReferences(int id, int pageNumber = 1, int pageSize = 100, bool filterMustBeIsDependency = false)
|
||||
{
|
||||
if (pageNumber <= 0 || pageSize <= 0)
|
||||
{
|
||||
return BadRequest("Both pageNumber and pageSize must be greater than zero");
|
||||
}
|
||||
|
||||
return _relationService.GetPagedRelationsForItems(new []{id}, pageNumber - 1, pageSize, filterMustBeIsDependency);
|
||||
return _relationService.GetPagedRelationsForItem(id, pageNumber - 1, pageSize, filterMustBeIsDependency);
|
||||
}
|
||||
|
||||
// Used on delete, finds
|
||||
/// <summary>
|
||||
/// Gets a page list of the child nodes of the current item used in any kind of relation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used when deleting and unpublishing a single item to check if this item has any descending items that are in any kind of relation.
|
||||
/// This is basically finding the descending items which are children in relations.
|
||||
/// </remarks>
|
||||
public ActionResult<PagedResult<RelationItem>> GetPagedDescendantsInReferences(int parentId, int pageNumber = 1, int pageSize = 100, bool filterMustBeIsDependency = true)
|
||||
{
|
||||
if (pageNumber <= 0 || pageSize <= 0)
|
||||
@@ -48,12 +51,16 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
return BadRequest("Both pageNumber and pageSize must be greater than zero");
|
||||
}
|
||||
|
||||
|
||||
return _relationService.GetPagedDescendantsInReferences(parentId, pageNumber - 1, pageSize, filterMustBeIsDependency);
|
||||
|
||||
}
|
||||
|
||||
// Used by unpublish content. So this is basically finding parents of relations.
|
||||
/// <summary>
|
||||
/// Gets a page list of the items used in any kind of relation from selected integer ids.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used when bulk deleting content/media and bulk unpublishing content (delete and unpublish on List view).
|
||||
/// This is basically finding children of relations.
|
||||
/// </remarks>
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public ActionResult<PagedResult<RelationItem>> GetPagedReferencedItems([FromJsonPath] int[] ids, int pageNumber = 1, int pageSize = 100, bool filterMustBeIsDependency = true)
|
||||
@@ -64,8 +71,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
}
|
||||
|
||||
return _relationService.GetPagedItemsWithRelations(ids, pageNumber - 1, pageSize, filterMustBeIsDependency);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
scope.publishStatus = [];
|
||||
scope.currentVariant = null;
|
||||
scope.currentUrls = [];
|
||||
scope.loadingReferences = false;
|
||||
|
||||
scope.disableTemplates = Umbraco.Sys.ServerVariables.features.disabledFeatures.disableTemplates;
|
||||
scope.allowChangeDocumentType = false;
|
||||
@@ -229,6 +230,10 @@
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function loadReferences(){
|
||||
scope.loadingReferences = true;
|
||||
}
|
||||
function loadRedirectUrls() {
|
||||
scope.loadingRedirectUrls = true;
|
||||
//check if Redirect URL Management is enabled
|
||||
@@ -335,6 +340,7 @@
|
||||
loadRedirectUrls();
|
||||
setNodePublishStatus();
|
||||
formatDatesToLocal();
|
||||
loadReferences();
|
||||
} else {
|
||||
isInfoTab = false;
|
||||
}
|
||||
@@ -352,6 +358,7 @@
|
||||
loadRedirectUrls();
|
||||
setNodePublishStatus();
|
||||
formatDatesToLocal();
|
||||
loadReferences();
|
||||
}
|
||||
updateCurrentUrls();
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ function trackedReferencesResource($q, $http, umbRequestHelper) {
|
||||
$http.post(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"trackedReferencesApiBaseUrl",
|
||||
"getPagedReferencedItems",
|
||||
"GetPagedReferencedItems",
|
||||
query),
|
||||
{
|
||||
ids: ids,
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</umb-box-content>
|
||||
</umb-box>
|
||||
|
||||
<umb-tracked-references id="node.id"></umb-tracked-references>
|
||||
<umb-tracked-references id="node.id" ng-if="loadingReferences" ></umb-tracked-references>
|
||||
|
||||
<umb-box data-element="node-info-redirects" ng-cloak ng-show="!urlTrackerDisabled && hasRedirects">
|
||||
<umb-box-header title-key="redirectUrls_redirectUrlManagement"></umb-box-header>
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
<div class="umb-table-head">
|
||||
<div class="umb-table-row">
|
||||
<div class="umb-table-cell"></div>
|
||||
<div class="umb-table-cell umb-table__name not-fixed"><localize key="general_nodename">Node Name</localize></div>
|
||||
<div ng-if="vm.showTypeName" class="umb-table-cell"><localize key="general_typename">Type Name</localize></div>
|
||||
<div class="umb-table-cell umb-table__name not-fixed"><localize key="general_nodeName">Node Name</localize></div>
|
||||
<div ng-if="vm.showTypeName" class="umb-table-cell"><localize key="general_typeName">Type Name</localize></div>
|
||||
<div ng-if="vm.showType" class="umb-table-cell"><localize key="general_type">Type</localize></div>
|
||||
<div ng-if="vm.showRelationTypeName" class="umb-table-cell"><localize key="relationType_relation">Relation</localize></div>
|
||||
</div>
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
</div>
|
||||
|
||||
<div ng-if="vm.hasReferencesInDescendants">
|
||||
<umb-tracked-references-table items="vm.referencedDescendants.items"
|
||||
total-pages="vm.referencedDescendants.totalPages"
|
||||
page-number="vm.referencedDescendants.pageNumber"
|
||||
headline="vm.referencedDescendantsTitle"
|
||||
on-page-changed="vm.changeDescendantsPageNumber(pageNumber)">
|
||||
<umb-tracked-references-table items="vm.referencedDescendants.items"
|
||||
total-pages="vm.referencedDescendants.totalPages"
|
||||
page-number="vm.referencedDescendants.pageNumber"
|
||||
headline="vm.referencedDescendantsTitle"
|
||||
on-page-changed="vm.changeDescendantsPageNumber(pageNumber)">
|
||||
</umb-tracked-references-table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -374,7 +374,7 @@
|
||||
}
|
||||
|
||||
function enableUser() {
|
||||
vm.enableUserButtonState = "busfy";
|
||||
vm.enableUserButtonState = "busy";
|
||||
usersResource.enableUsers([vm.user.id]).then(function (data) {
|
||||
vm.user.userState = "Active";
|
||||
setUserDisplayState();
|
||||
|
||||
@@ -788,6 +788,7 @@
|
||||
<key alias="new">New</key>
|
||||
<key alias="next">Next</key>
|
||||
<key alias="no">No</key>
|
||||
<key alias="nodeName">Node Name</key>
|
||||
<key alias="of">of</key>
|
||||
<key alias="off">Off</key>
|
||||
<key alias="ok">OK</key>
|
||||
@@ -829,6 +830,7 @@
|
||||
<key alias="submit">Submit</key>
|
||||
<key alias="success">Success</key>
|
||||
<key alias="type">Type</key>
|
||||
<key alias="typeName">Type Name</key>
|
||||
<key alias="typeToSearch">Type to search...</key>
|
||||
<key alias="under">under</key>
|
||||
<key alias="up">Up</key>
|
||||
@@ -2390,6 +2392,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
|
||||
<key alias="parent">Parent</key>
|
||||
<key alias="child">Child</key>
|
||||
<key alias="count">Count</key>
|
||||
<key alias="relation">Relation</key>
|
||||
<key alias="relations">Relations</key>
|
||||
<key alias="created">Created</key>
|
||||
<key alias="comment">Comment</key>
|
||||
@@ -2470,18 +2473,13 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
|
||||
<area alias="references">
|
||||
<key alias="tabName">References</key>
|
||||
<key alias="DataTypeNoReferences">This Data Type has no references.</key>
|
||||
<key alias="itemHasNoReferences">This item has no references.</key>
|
||||
<key alias="labelUsedByDocumentTypes">Used in Document Types</key>
|
||||
<key alias="labelUsedByMediaTypes">Used in Media Types</key>
|
||||
<key alias="labelUsedByMemberTypes">Used in Member Types</key>
|
||||
<key alias="usedByProperties">Used by</key>
|
||||
<key alias="labelUsedByDocuments">Used in Documents</key>
|
||||
<key alias="labelUsedByMembers">Used in Members</key>
|
||||
<key alias="labelUsedByMedia">Used in Media</key>
|
||||
<key alias="labelUsedItems">Items in use</key>
|
||||
<key alias="labelUsedDescendants">Descendants in use</key>
|
||||
<key alias="labelUsedInMediaDescendants">One or more of this item's descendants is being used in a media item.</key>
|
||||
<key alias="labelUsedInContentDescendants">One or more of this item's descendants is being used in a content item.</key>
|
||||
<key alias="labelUsedInMemberDescendants">One or more of this item's descendants is being used in a member.</key>
|
||||
<key alias="deleteWarning">This item or its descendants is being used. Deletion can lead to broken links on your website.</key>
|
||||
<key alias="unpublishWarning">This item or its descendants is being used. Unpublishing can lead to broken links on your website. Please take the appropriate actions.</key>
|
||||
<key alias="deleteDisabledWarning">This item or its descendants is being used. Therefore, deletion has been disabled.</key>
|
||||
|
||||
@@ -809,7 +809,7 @@
|
||||
<key alias="new">New</key>
|
||||
<key alias="next">Next</key>
|
||||
<key alias="no">No</key>
|
||||
<key alias="nodename">Node Name</key>
|
||||
<key alias="nodeName">Node Name</key>
|
||||
<key alias="of">of</key>
|
||||
<key alias="off">Off</key>
|
||||
<key alias="ok">OK</key>
|
||||
@@ -850,7 +850,7 @@
|
||||
<key alias="submit">Submit</key>
|
||||
<key alias="success">Success</key>
|
||||
<key alias="type">Type</key>
|
||||
<key alias="typename">Type Name</key>
|
||||
<key alias="typeName">Type Name</key>
|
||||
<key alias="typeToSearch">Type to search...</key>
|
||||
<key alias="under">under</key>
|
||||
<key alias="up">Up</key>
|
||||
@@ -1495,7 +1495,7 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
|
||||
<key alias="umbracoForum">Visit our.umbraco.com</key>
|
||||
<key alias="umbracoTv">Visit umbraco.tv</key>
|
||||
<key alias="umbracoLearningBase">Watch our free tutorial videos</key>
|
||||
<key alias="umbracoLearningBaseDescription">on the Umbraco Learning Base</key>
|
||||
<key alias="umbracoLearningBaseDescription">on the Umbraco Learning Base</key>
|
||||
</area>
|
||||
<area alias="settings">
|
||||
<key alias="defaulttemplate">Default template</key>
|
||||
@@ -2562,15 +2562,9 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
|
||||
<key alias="usedByProperties">Referenced by</key>
|
||||
<key alias="labelUsedByItems">Referenced by the following items</key>
|
||||
<key alias="labelDependsOnThis">The following items depend on this</key>
|
||||
<key alias="labelUsedByDocuments">Referenced by the following Documents</key>
|
||||
<key alias="labelUsedByMembers">Referenced by the following Members</key>
|
||||
<key alias="labelUsedByMedia">Referenced by the following Media</key>
|
||||
<key alias="labelUsedItems">The following items are referenced</key>
|
||||
<key alias="labelUsedDescendants">The following descendant items have dependencies</key>
|
||||
<key alias="labelDependentDescendants">The following descending items has dependencies</key>
|
||||
<key alias="labelUsedInMediaDescendants">One or more of this item's descendants is being referenced in a media item.</key>
|
||||
<key alias="labelUsedInContentDescendants">One or more of this item's descendants is being referenced in a content item.</key>
|
||||
<key alias="labelUsedInMemberDescendants">One or more of this item's descendants is being referenced in a member.</key>
|
||||
<key alias="labelDependentDescendants">The following descending items have dependencies</key>
|
||||
<key alias="deleteWarning">This item or its descendants is being referenced. Deletion can lead to broken links on your website.</key>
|
||||
<key alias="unpublishWarning">This item or its descendants is being referenced. Unpublishing can lead to broken links on your website. Please take the appropriate actions.</key>
|
||||
<key alias="deleteDisabledWarning">This item or its descendants is being referenced. Therefore, deletion has been disabled.</key>
|
||||
|
||||
Reference in New Issue
Block a user