Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.1.0 #32

Merged
merged 7 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,473 changes: 2,237 additions & 2,236 deletions src/Umbraco.Community.BackOfficeOrganiser.Client/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@hey-api/openapi-ts": "^0.46.3",
"@umbraco-cms/backoffice": "^14.0.0",
"typescript": "^5.0.2",
"vite": "^4.4.5"
"vite": "^4.5.3"
},
"volta": {
"node": "21.7.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task HandleAsync(ContentTypeSavedNotification notification, Cancell

foreach (var item in notification.SavedEntities)
{
await contentTypeOrganiser.OrganiseTypeAsync(item);
await contentTypeOrganiser.OrganiseAsync(item);
}
}

Expand All @@ -58,7 +58,7 @@ public async Task HandleAsync(MediaTypeSavedNotification notification, Cancellat

foreach (var item in notification.SavedEntities)
{
await mediaTypeOrganiser.OrganiseTypeAsync(item);
await mediaTypeOrganiser.OrganiseAsync(item);
}
}

Expand All @@ -71,7 +71,7 @@ public async Task HandleAsync(MemberTypeSavedNotification notification, Cancella

foreach (var item in notification.SavedEntities)
{
await memberTypeOrganiser.OrganiseTypeAsync(item);
await memberTypeOrganiser.OrganiseAsync(item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models;

namespace Umbraco.Community.BackOfficeOrganiser.Organisers;

public abstract class BackOfficeOrganiserBase<T>(ILogger logger) : IBackOfficeOrganiser<T>
{
protected readonly ILogger Logger = logger;
public readonly ILogger Logger = logger;

public async Task OrganiseTypeAsync()
protected virtual void PostOrganiseAll()
{
}

public async Task OrganiseAllAsync()
{
Logger.LogInformation("BackOfficeOrganiser: Cleanup for {Type} Started", typeof(T).Name);

try
{
await OrganiseAsync();
var items = await GetAllAsync();
foreach (var item in items)
{
await OrganiseAsync(item);
}

PostOrganiseAll();
}
catch (Exception ex)
{
Expand All @@ -23,5 +34,7 @@ public async Task OrganiseTypeAsync()
Logger.LogInformation("BackOfficeOrganiser: Cleanup for {Type} Complete", typeof(T).Name);
}

protected abstract Task OrganiseAsync();
public abstract Task OrganiseAsync(T item);

protected abstract Task<IEnumerable<T>> GetAllAsync();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections;
using jcdcdev.Umbraco.Core.Extensions;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models;
Expand All @@ -11,23 +12,19 @@ public class ContentTypeOrganiser(
ContentTypeOrganiseActionCollection organiseActions)
: BackOfficeOrganiserBase<IContentType>(logger)
{
protected override async Task OrganiseAsync()
{
var contentTypes = contentTypeService.GetAll().ToList();
foreach (var contentType in contentTypes)
{
await OrganiseTypeAsync(contentType);
}

contentTypeService.DeleteAllEmptyContainers();
}
protected override Task<IEnumerable<IContentType>> GetAllAsync() => Task.FromResult(contentTypeService.GetAll());

public async Task OrganiseTypeAsync(IContentType contentType)
public override async Task OrganiseAsync(IContentType contentType)
{
var organiser = organiseActions.FirstOrDefault(x => x.CanMove(contentType, contentTypeService));
if (organiser != null)
{
await organiser.MoveAsync(contentType, contentTypeService);
}
}

protected override void PostOrganiseAll()
{
contentTypeService.DeleteAllEmptyContainers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ public class DataTypeOrganiser(
DataTypeOrganiseActionCollection organiseActions)
: BackOfficeOrganiserBase<IDataType>(logger)
{
protected override async Task OrganiseAsync()
{
var dataTypes = await dataTypeService.GetAllAsync();
foreach (var dataType in dataTypes)
{
await OrganiseAsync(dataType);
}

dataTypeService.DeleteAllEmptyContainers();
}

public async Task OrganiseAsync(IDataType dataType)
public override async Task OrganiseAsync(IDataType dataType)
{
var organiser = organiseActions.FirstOrDefault(x => x.CanMove(dataType, dataTypeService));
if (organiser != null)
{
await organiser.MoveAsync(dataType, dataTypeService);
}
}

protected override async Task<IEnumerable<IDataType>> GetAllAsync() => await dataTypeService.GetAllAsync();

protected override void PostOrganiseAll()
{
dataTypeService.DeleteAllEmptyContainers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace Umbraco.Community.BackOfficeOrganiser.Organisers;

public interface IBackOfficeOrganiser<T>
{
Task OrganiseTypeAsync();
Task OrganiseAllAsync();
Task OrganiseAsync(T item);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ public class MediaTypeOrganiser(
MediaTypeOrganiseActionCollection organiseActions)
: BackOfficeOrganiserBase<IMediaType>(logger)
{
protected override async Task OrganiseAsync()
{
var mediaTypes = mediaTypeService.GetAll().ToList();

foreach (var mediaType in mediaTypes)
{
await OrganiseTypeAsync(mediaType);
}

mediaTypeService.DeleteAllEmptyContainers();
}
protected override Task<IEnumerable<IMediaType>> GetAllAsync() => Task.FromResult(mediaTypeService.GetAll());

public async Task OrganiseTypeAsync(IMediaType mediaType)
public override async Task OrganiseAsync(IMediaType mediaType)
{
var organiser = organiseActions.FirstOrDefault(x => x.CanMove(mediaType, mediaTypeService));
if (organiser != null)
{
await organiser.MoveAsync(mediaType, mediaTypeService);
}
}

protected override void PostOrganiseAll()
{
mediaTypeService.DeleteAllEmptyContainers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ public class MemberTypeOrganiser(
MemberTypeOrganiseActionCollection organiseActions)
: BackOfficeOrganiserBase<IMemberType>(logger)
{
protected override async Task OrganiseAsync()
public override async Task OrganiseAsync(IMemberType item)
{
var memberTypes = memberTypeService.GetAll().ToList();

foreach (var memberType in memberTypes)
var organiser = organiseActions.FirstOrDefault(x => x.CanMove(item, memberTypeService));
if (organiser != null)
{
await OrganiseTypeAsync(memberType);
await organiser.MoveAsync(item, memberTypeService);
}

memberTypeService.DeleteAllEmptyContainers();
}

public async Task OrganiseTypeAsync(IMemberType memberType)
protected override Task<IEnumerable<IMemberType>> GetAllAsync() => Task.FromResult<IEnumerable<IMemberType>>(memberTypeService.GetAll().ToList());

protected override void PostOrganiseAll()
{
var organiser = organiseActions.FirstOrDefault(x => x.CanMove(memberType, memberTypeService));
if (organiser != null)
{
await organiser.MoveAsync(memberType, memberTypeService);
}
memberTypeService.DeleteAllEmptyContainers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@

namespace Umbraco.Community.BackOfficeOrganiser.Services;

public class BackOfficeOrganiserService(
ILogger<BackOfficeOrganiserService> logger,
ContentTypeOrganiser contentTypeOrganiser,
MediaTypeOrganiser mediaTypeOrganiser,
MemberTypeOrganiser memberTypeOrganiser,
DataTypeOrganiser dataTypeOrganiser)
: IBackOfficeOrganiserService
public class BackOfficeOrganiserService : IBackOfficeOrganiserService
{
private readonly ILogger _logger = logger;
private readonly ContentTypeOrganiser _contentTypeOrganiser;
private readonly DataTypeOrganiser _dataTypeOrganiser;
private readonly ILogger _logger;
private readonly MediaTypeOrganiser _mediaTypeOrganiser;
private readonly MemberTypeOrganiser _memberTypeOrganiser;

public BackOfficeOrganiserService(
ILogger<BackOfficeOrganiserService> logger,
ContentTypeOrganiser contentTypeOrganiser,
MediaTypeOrganiser mediaTypeOrganiser,
MemberTypeOrganiser memberTypeOrganiser,
DataTypeOrganiser dataTypeOrganiser)
{
_logger = logger;
_contentTypeOrganiser = contentTypeOrganiser;
_mediaTypeOrganiser = mediaTypeOrganiser;
_memberTypeOrganiser = memberTypeOrganiser;
_dataTypeOrganiser = dataTypeOrganiser;
}

public async Task<Attempt<OrganiseType>> OrganiseAsync(OrganiseType organise)
{
Expand Down Expand Up @@ -55,7 +67,7 @@ public async Task<Attempt<OrganiseType>> OrganiseDataTypesAsync()
{
try
{
await dataTypeOrganiser.OrganiseTypeAsync();
await _dataTypeOrganiser.OrganiseAllAsync();
}
catch (Exception ex)
{
Expand All @@ -69,7 +81,7 @@ public async Task<Attempt<OrganiseType>> OrganiseMemberTypesAsync()
{
try
{
await memberTypeOrganiser.OrganiseTypeAsync();
await _memberTypeOrganiser.OrganiseAllAsync();
}
catch (Exception ex)
{
Expand All @@ -83,7 +95,7 @@ public async Task<Attempt<OrganiseType>> OrganiseMediaTypesAsync()
{
try
{
await mediaTypeOrganiser.OrganiseTypeAsync();
await _mediaTypeOrganiser.OrganiseAllAsync();
}
catch (Exception ex)
{
Expand All @@ -97,7 +109,7 @@ public async Task<Attempt<OrganiseType>> OrganiseContentTypesAsync()
{
try
{
await contentTypeOrganiser.OrganiseTypeAsync();
await _contentTypeOrganiser.OrganiseAllAsync();
}
catch (Exception ex)
{
Expand Down
Loading