Skip to content

Commit

Permalink
v10/11 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Dec 2, 2022
1 parent 33fcf0a commit e01eaaf
Show file tree
Hide file tree
Showing 21 changed files with 337 additions and 438 deletions.
11 changes: 0 additions & 11 deletions build/build.ps1

This file was deleted.

40 changes: 40 additions & 0 deletions dist/build-package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
param(
# Version to build
[Parameter(Mandatory)]
[string]
[Alias("v")]
$version,

# Optional suffix for the version
[string]
$suffix,

# configuration to build against
[string]
$config = 'release',

# push to azure nightly feed ?
[switch]
$push = $false
)

$versionString = $version
if (![string]::IsNullOrWhiteSpace($suffix)) {
$versionString = -join($version, '-', $suffix)
}

$package = "Our.Umbraco.LinkedPages";
$project = "..\src\$package\$package.csproj"
$outFolder = ".\$versionString"
$buildParams = "ContinuousIntegrationBuild=true,version=$versionString"

# pack the thing
dotnet pack $project -c $config -o $outFolder /p:$buildParams

if ($push) {
# push to a nightly .
$feedUrl = "https://pkgs.dev.azure.com/jumoo/Public/_packaging/nightly/nuget/v3/index.json";
&nuget.exe push "$outfolder\*.nupkg" -ApiKey AzureDevOps -src $feedUrl
}

XCOPY "$outfolder\*.nupkg" "c:\source\localgit" /y

This file was deleted.

213 changes: 101 additions & 112 deletions src/Our.Umbraco.LinkedPages/Controllers/LinkedPagesApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc;

using Umbraco.Cms.Core;
Expand All @@ -11,149 +10,139 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Extensions;
#else
using System.Web.Http;

using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Services;
using Umbraco.Web.Editors;
#endif
namespace Our.Umbraco.LinkedPages.Controllers;

namespace Our.Umbraco.LinkedPages.Controllers
public class LinkedPagesApiController : UmbracoAuthorizedJsonController
{
public class LinkedPagesApiController : UmbracoAuthorizedJsonController
private readonly IRelationService _relationService;
private readonly IEntityService _entityService;
private readonly LinkedPagesConfig _config;

private string defaultRelationType = Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias;
private int relationTypeId = 0;
private int[] _ignoredTypeIds;

public LinkedPagesApiController(
IRelationService relationService,
IEntityService entityService,
LinkedPagesConfig config)
{
private readonly IRelationService _relationService;
private readonly IEntityService _entityService;
private readonly LinkedPagesConfig _config;

private string defaultRelationType = Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias;
private int relationTypeId = 0;
private int[] _ignoredTypeIds;

public LinkedPagesApiController(
IRelationService relationService,
IEntityService entityService,
LinkedPagesConfig config)
{
_relationService = relationService;
_entityService = entityService;
_config = config;
_relationService = relationService;
_entityService = entityService;
_config = config;

_ignoredTypeIds = GetIgnoredTypeIds();
}
_ignoredTypeIds = GetIgnoredTypeIds();
}

private int[] GetIgnoredTypeIds()
{
var ignore = _config.ignoredTypes.ToDelimitedList();
var types = _relationService.GetAllRelationTypes();
private int[] GetIgnoredTypeIds()
{
var ignore = _config.ignoredTypes.ToDelimitedList();
var types = _relationService.GetAllRelationTypes();

return types.Where(x => ignore.InvariantContains(x.Alias))
.Select(x => x.Id)
.ToArray();
}
return types.Where(x => ignore.InvariantContains(x.Alias))
.Select(x => x.Id)
.ToArray();
}

/// <summary>
/// API endpoint - used for discovery in ServerVariablesParser.
/// </summary>
[HttpGet]
public bool GetApi() => true;
/// <summary>
/// API endpoint - used for discovery in ServerVariablesParser.
/// </summary>
[HttpGet]
public bool GetApi() => true;


[HttpGet]
public IEnumerable<LinkedPageInfo> GetChildLinks(int id)
{
var relations = _relationService.GetByParentId(id);
if (!relations.Any())
return Enumerable.Empty<LinkedPageInfo>();
[HttpGet]
public IEnumerable<LinkedPageInfo> GetChildLinks(int id)
{
var relations = _relationService.GetByParentId(id);
if (!relations.Any())
return Enumerable.Empty<LinkedPageInfo>();

return GetRelations(relations, true);
}
return GetRelations(relations, true);
}

[HttpGet]
public IEnumerable<LinkedPageInfo> GetParentLinks(int id)
{
var relations = _relationService.GetByChildId(id);
if (!relations.Any())
return Enumerable.Empty<LinkedPageInfo>();
[HttpGet]
public IEnumerable<LinkedPageInfo> GetParentLinks(int id)
{
var relations = _relationService.GetByChildId(id);
if (!relations.Any())
return Enumerable.Empty<LinkedPageInfo>();

return GetRelations(relations, false);
}
return GetRelations(relations, false);
}

[HttpPost]
public IEnumerable<LinkedPageInfo> CreateLink(int parent, int child)
{
var parentNode = _entityService.Get(parent);
var childNode = _entityService.Get(child);
[HttpPost]
public IEnumerable<LinkedPageInfo> CreateLink(int parent, int child)
{
var parentNode = _entityService.Get(parent);
var childNode = _entityService.Get(child);

if (parentNode == null || childNode == null)
throw new KeyNotFoundException();
if (parentNode == null || childNode == null)
throw new KeyNotFoundException();

var relationType = _relationService.GetRelationTypeByAlias(defaultRelationType);
if (relationType == null)
throw new ApplicationException($"Cannot create relation of type {defaultRelationType}");
var relationType = _relationService.GetRelationTypeByAlias(defaultRelationType);
if (relationType == null)
throw new ApplicationException($"Cannot create relation of type {defaultRelationType}");

var relation = new Relation(parent, child, relationType);
_relationService.Save(relation);
var relation = new Relation(parent, child, relationType);
_relationService.Save(relation);

return GetChildLinks(parent);
}
return GetChildLinks(parent);
}

[HttpDelete]
public IEnumerable<LinkedPageInfo> RemoveLink(int id, int currentPage)
{
var relation = _relationService.GetById(id);
if (relation == null)
throw new ArgumentOutOfRangeException($"Cannot find relation with id {id}");
[HttpDelete]
public IEnumerable<LinkedPageInfo> RemoveLink(int id, int currentPage)
{
var relation = _relationService.GetById(id);
if (relation == null)
throw new ArgumentOutOfRangeException($"Cannot find relation with id {id}");

_relationService.Delete(relation);
_relationService.Delete(relation);

return GetChildLinks(currentPage);
}
return GetChildLinks(currentPage);
}


private IEnumerable<LinkedPageInfo> GetRelations(IEnumerable<IRelation> relations, bool linkChild)
private IEnumerable<LinkedPageInfo> GetRelations(IEnumerable<IRelation> relations, bool linkChild)
{
foreach (var relation in relations.Where(x => !_ignoredTypeIds.Contains(x.RelationTypeId)))
{
foreach(var relation in relations.Where(x => !_ignoredTypeIds.Contains(x.RelationTypeId)))
if (relationTypeId == 0 || relation.RelationType.Id == this.relationTypeId)
{
if (relationTypeId == 0 || relation.RelationType.Id == this.relationTypeId)
var nodeId = linkChild ? relation.ChildId : relation.ParentId;
var node = _entityService.Get(nodeId);
if (node == null) continue;

yield return new LinkedPageInfo
{
var nodeId = linkChild ? relation.ChildId : relation.ParentId;
var node = _entityService.Get(nodeId);
if (node == null) continue;

yield return new LinkedPageInfo
{
RelationId = relation.Id,
PageId = nodeId,
Name = node.Name,
Path = GetContentPath(node),
RelationType = relation.RelationType.Alias,
RelationTypeId = relation.RelationTypeId
};
}
RelationId = relation.Id,
PageId = nodeId,
Name = node.Name,
Path = GetContentPath(node),
RelationType = relation.RelationType.Alias,
RelationTypeId = relation.RelationTypeId
};
}
}
}

private string GetContentPath(IEntitySlim node)
{
if (node == null) return string.Empty;
private string GetContentPath(IEntitySlim node)
{
if (node == null) return string.Empty;

var path = string.Empty;
if (node.ParentId > -1)
{
var parent = _entityService.GetParent(node.Id);
if (parent != null)
path += GetContentPath(parent);
}
var path = string.Empty;
if (node.ParentId > -1)
{
var parent = _entityService.GetParent(node.Id);
if (parent != null)
path += GetContentPath(parent);
}


if (!string.IsNullOrWhiteSpace(path))
return path + " > " + node.Name;
if (!string.IsNullOrWhiteSpace(path))
return path + " > " + node.Name;

return node.Name;
}
return node.Name;
}
}
30 changes: 9 additions & 21 deletions src/Our.Umbraco.LinkedPages/LinikedAction.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Cms.Core.Actions;

namespace Our.Umbraco.LinkedPages;

#if NETCOREAPP
using Umbraco.Cms.Core.Actions;
#else
using Umbraco.Web.Actions;
#endif

namespace Our.Umbraco.LinkedPages
public class LinikedAction : IAction
{
public class LinikedAction : IAction
{
public char Letter => LinkedPages.ActionLetter[0];
public char Letter => LinkedPages.ActionLetter[0];

public bool ShowInNotifier => true;
public bool ShowInNotifier => true;

public bool CanBePermissionAssigned => true;
public bool CanBePermissionAssigned => true;

public string Icon => "link";
public string Icon => "link";

public string Alias => LinkedPages.Alias;
public string Alias => LinkedPages.Alias;

public string Category => LinkedPages.Category;
}
public string Category => LinkedPages.Category;
}
Loading

0 comments on commit e01eaaf

Please sign in to comment.