-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Autocomplete to Stereotype (#16025)
--------- Co-authored-by: Mike Alhayek <[email protected]>
- Loading branch information
1 parent
649b740
commit b96bcc1
Showing
17 changed files
with
164 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/DefaultStereotypesProvider.cs
This file was deleted.
Oops, something went wrong.
36 changes: 31 additions & 5 deletions
36
src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/StereotypeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
using OrchardCore.Modules; | ||
|
||
namespace OrchardCore.ContentTypes.Services | ||
{ | ||
public class StereotypeService : IStereotypeService | ||
{ | ||
private readonly IEnumerable<IStereotypesProvider> _providers; | ||
private readonly IContentDefinitionService _contentDefinitionService; | ||
private readonly ILogger<StereotypeService> _logger; | ||
|
||
public StereotypeService(IEnumerable<IStereotypesProvider> providers) | ||
public StereotypeService( | ||
IEnumerable<IStereotypesProvider> providers, | ||
IContentDefinitionService contentDefinitionService, | ||
ILogger<StereotypeService> logger) | ||
{ | ||
_providers = providers; | ||
_contentDefinitionService = contentDefinitionService; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<IEnumerable<StereotypeDescription>> GetStereotypesAsync() | ||
{ | ||
var descriptions = new List<StereotypeDescription>(); | ||
var providerStereotypes = (await _providers.InvokeAsync(provider => provider.GetStereotypesAsync(), _logger)).ToList(); | ||
|
||
foreach (var provider in _providers) | ||
var stereotypes = providerStereotypes.Select(providerStereotype => providerStereotype.Stereotype) | ||
.ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
|
||
foreach (var contentType in await _contentDefinitionService.GetTypesAsync()) | ||
{ | ||
descriptions.AddRange(await provider.GetStereotypesAsync()); | ||
if (!contentType.TypeDefinition.TryGetStereotype(out var stereotype) || | ||
stereotypes.Contains(stereotype)) | ||
{ | ||
continue; | ||
} | ||
|
||
providerStereotypes.Add(new StereotypeDescription | ||
{ | ||
Stereotype = stereotype, | ||
DisplayName = stereotype | ||
}); | ||
} | ||
|
||
return descriptions; | ||
return providerStereotypes.OrderBy(x => x.DisplayName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...hardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsStereotypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.CustomSettings.Services; | ||
|
||
public class CustomSettingsStereotypesProvider : IStereotypesProvider | ||
{ | ||
protected readonly IStringLocalizer S; | ||
|
||
public CustomSettingsStereotypesProvider(IStringLocalizer<CustomSettingsStereotypesProvider> stringLocalizer) | ||
{ | ||
S = stringLocalizer; | ||
} | ||
|
||
public Task<IEnumerable<StereotypeDescription>> GetStereotypesAsync() | ||
=> Task.FromResult<IEnumerable<StereotypeDescription>>( | ||
[new StereotypeDescription { Stereotype = "CustomSettings", DisplayName = S["Custom Settings"] }]); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/OrchardCore.Modules/OrchardCore.Menu/Services/MenuItemStereotypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.Menu.Services; | ||
|
||
public class MenuItemStereotypesProvider : IStereotypesProvider | ||
{ | ||
protected readonly IStringLocalizer S; | ||
|
||
public MenuItemStereotypesProvider(IStringLocalizer<MenuItemStereotypesProvider> stringLocalizer) | ||
{ | ||
S = stringLocalizer; | ||
} | ||
|
||
public Task<IEnumerable<StereotypeDescription>> GetStereotypesAsync() | ||
=> Task.FromResult<IEnumerable<StereotypeDescription>>( | ||
[new StereotypeDescription { Stereotype = "MenuItem", DisplayName = S["Menu Item"] }]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsStereotypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.Users.Services; | ||
|
||
public class CustomUserSettingsStereotypesProvider : IStereotypesProvider | ||
{ | ||
protected readonly IStringLocalizer S; | ||
|
||
public CustomUserSettingsStereotypesProvider(IStringLocalizer<CustomUserSettingsStereotypesProvider> stringLocalizer) | ||
{ | ||
S = stringLocalizer; | ||
} | ||
|
||
public Task<IEnumerable<StereotypeDescription>> GetStereotypesAsync() | ||
=> Task.FromResult<IEnumerable<StereotypeDescription>>( | ||
[new StereotypeDescription { Stereotype = "CustomUserSettings", DisplayName = S["Custom User Settings"] }]); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/OrchardCore.Modules/OrchardCore.Widgets/Services/WidgetStereotypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.Widgets.Services; | ||
|
||
public class WidgetStereotypesProvider : IStereotypesProvider | ||
{ | ||
protected readonly IStringLocalizer S; | ||
|
||
public WidgetStereotypesProvider(IStringLocalizer<WidgetStereotypesProvider> stringLocalizer) | ||
{ | ||
S = stringLocalizer; | ||
} | ||
|
||
public Task<IEnumerable<StereotypeDescription>> GetStereotypesAsync() | ||
=> Task.FromResult<IEnumerable<StereotypeDescription>>( | ||
[new StereotypeDescription { Stereotype = "Widget", DisplayName = S["Widget"] }]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ntentTypes/Services/IStereotypeService.cs → ...gement.Abstractions/IStereotypeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...entTypes/Services/IStereotypesProvider.cs → ...ment.Abstractions/IStereotypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.