diff --git a/zero.Backoffice/BackofficeJsonSerlializerSettings.cs b/zero.Backoffice/BackofficeJsonSerlializerSettings.cs index 9fb28d33..4bde72ef 100644 --- a/zero.Backoffice/BackofficeJsonSerlializerSettings.cs +++ b/zero.Backoffice/BackofficeJsonSerlializerSettings.cs @@ -1,26 +1,24 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; -using zero.Core.Utils; -namespace zero.Core.Options +namespace zero.Backoffice; + +internal class BackofficeJsonSerlializerSettings : JsonSerializerSettings { - public class BackofficeJsonSerlializerSettings : JsonSerializerSettings + public BackofficeJsonSerlializerSettings() { - public BackofficeJsonSerlializerSettings() - { - Setup(this); - } - - - public static void Setup(JsonSerializerSettings settings) - { - settings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy())); - //settings.Converters.Add(new RefJsonConverter()); - //settings.ContractResolver = new ZeroJsonContractResolver(); - settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - settings.TypeNameHandling = TypeNameHandling.Objects; - //settings.SerializationBinder = new ZeroInterfaceBinder(); - } + Setup(this); } -} + + + public static void Setup(JsonSerializerSettings settings) + { + settings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy())); + //settings.Converters.Add(new RefJsonConverter()); + //settings.ContractResolver = new ZeroJsonContractResolver(); + settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + settings.TypeNameHandling = TypeNameHandling.Objects; + //settings.SerializationBinder = new ZeroInterfaceBinder(); + } +} \ No newline at end of file diff --git a/zero.Backoffice/Configuration/BackofficeOptions.cs b/zero.Backoffice/Configuration/BackofficeOptions.cs index b10fbc24..80b3d59b 100644 --- a/zero.Backoffice/Configuration/BackofficeOptions.cs +++ b/zero.Backoffice/Configuration/BackofficeOptions.cs @@ -1,4 +1,6 @@ -namespace zero.Backoffice.Configuration; +using zero.Backoffice.Modules.Search; + +namespace zero.Backoffice.Configuration; public class BackofficeOptions { diff --git a/zero.Backoffice/Controllers/Filters/BackofficeFilterAttribute.cs b/zero.Backoffice/Controllers/Filters/BackofficeFilterAttribute.cs index a4ae8893..18120a4a 100644 --- a/zero.Backoffice/Controllers/Filters/BackofficeFilterAttribute.cs +++ b/zero.Backoffice/Controllers/Filters/BackofficeFilterAttribute.cs @@ -15,7 +15,7 @@ public class BackofficeFilterAttribute : IActionFilter { if (context.HttpContext.Request.Query.TryGetValue(SCOPE_KEY, out var scope)) { - (context.Controller as ZeroBackofficeController).OnScopeChanged(scope.ToString()); + //(context.Controller as ZeroBackofficeController).OnScopeChanged(scope.ToString()); } } } diff --git a/zero.Backoffice/Controllers/ZeroBackofficeController.cs b/zero.Backoffice/Controllers/ZeroBackofficeController.cs index 481cfe17..bf9a4042 100644 --- a/zero.Backoffice/Controllers/ZeroBackofficeController.cs +++ b/zero.Backoffice/Controllers/ZeroBackofficeController.cs @@ -6,33 +6,5 @@ namespace zero.Backoffice.Controllers; [DisableBrowserCache] public abstract class ZeroBackofficeController : ControllerBase { - /// - /// Create an edit model with associated metadata and permissions from a model - /// - protected DisplayModel GetEditModel(T model) - { - return GetEditModel>(new DisplayModel() { Entity = model }); - } - - - /// - /// Create an edit model with associated metadata and permissions from a model - /// - protected TWrapper GetEditModel(TWrapper editModel) where TWrapper : DisplayModel, new() - { - editModel.Meta = new() - { - Token = null, - IsShared = false - }; - - editModel.Permissions = new() - { - CanCreate = true, - CanEdit = true, - CanDelete = true - }; - - return editModel; - } + } diff --git a/zero.Backoffice/Controllers/ZeroSetupController.cs b/zero.Backoffice/Controllers/ZeroSetupController.cs index 51dd4088..e94f4dd2 100644 --- a/zero.Backoffice/Controllers/ZeroSetupController.cs +++ b/zero.Backoffice/Controllers/ZeroSetupController.cs @@ -1,50 +1,49 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using zero.Core.Api; -using zero.Setup; +//using Microsoft.AspNetCore.Hosting; +//using Microsoft.AspNetCore.Mvc; +//using zero.Setup; -namespace zero.Backoffice.Endpoints; +//namespace zero.Backoffice.Endpoints; -[ZeroAuthorize(false)] -public class ZeroSetupController : Controller -{ - ISetupApi Api; - IWebHostEnvironment Env; - IZeroOptions Options; +//[ZeroAuthorize(false)] +//public class ZeroSetupController : Controller +//{ +// ISetupApi Api; +// IWebHostEnvironment Env; +// IZeroOptions Options; - public ZeroSetupController(ISetupApi api, IWebHostEnvironment env, IZeroOptions options) - { - Api = api; - Env = env; - Options = options; - } +// public ZeroSetupController(ISetupApi api, IWebHostEnvironment env, IZeroOptions options) +// { +// Api = api; +// Env = env; +// Options = options; +// } - public IActionResult Index() - { - //if (!Options.ZeroVersion.IsNullOrEmpty()) - //{ - // return Redirect(Options.BackofficePath); - //} +// public IActionResult Index() +// { +// //if (!Options.ZeroVersion.IsNullOrEmpty()) +// //{ +// // return Redirect(Options.BackofficePath); +// //} - return View("/Views/Zero/Setup.cshtml"); - } +// return View("/Views/Zero/Setup.cshtml"); +// } - [HttpPost] - public async Task Install([FromBody] SetupModel model) - { - model.ContentRootPath = Env.ContentRootPath; +// [HttpPost] +// public async Task Install([FromBody] SetupModel model) +// { +// model.ContentRootPath = Env.ContentRootPath; - Result result = await Api.Install(model); +// Result result = await Api.Install(model); - if (result.IsSuccess) - { - return Json(result); - } +// if (result.IsSuccess) +// { +// return Json(result); +// } - object value = String.Join("\n\n", result.Errors.Select(error => error.Message + "\n(property: " + error.Property + ")")); - return StatusCode(500, value); - } -} \ No newline at end of file +// object value = String.Join("\n\n", result.Errors.Select(error => error.Message + "\n(property: " + error.Property + ")")); +// return StatusCode(500, value); +// } +//} \ No newline at end of file diff --git a/zero.Backoffice/Controllers/_ZeroBackofficeCollectionController.cs b/zero.Backoffice/Controllers/_ZeroBackofficeCollectionController.cs index e956509e..c2333c64 100644 --- a/zero.Backoffice/Controllers/_ZeroBackofficeCollectionController.cs +++ b/zero.Backoffice/Controllers/_ZeroBackofficeCollectionController.cs @@ -1,71 +1,71 @@ -using Microsoft.AspNetCore.Mvc; -using Raven.Client.Documents.Linq; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using zero.Core; -using zero.Core.Entities; +//using Microsoft.AspNetCore.Mvc; +//using Raven.Client.Documents.Linq; +//using System; +//using System.Collections.Generic; +//using System.Threading.Tasks; +//using zero.Core; +//using zero.Core.Entities; -namespace zero.Backoffice; +//namespace zero.Backoffice; -public abstract class _ZeroBackofficeCollectionController : ZeroBackofficeController - where TEntity : ZeroIdEntity, new() - where TCollection : IStoreOperations -{ - protected TCollection Collection { get; private set; } +//public abstract class _ZeroBackofficeCollectionController : ZeroBackofficeController +// where TEntity : ZeroIdEntity, new() +// where TCollection : IStoreOperations +//{ +// protected TCollection Collection { get; private set; } - [Obsolete] - protected Func, IRavenQueryable> DefaultQuery { get; set; } +// [Obsolete] +// protected Func, IRavenQueryable> DefaultQuery { get; set; } - protected Action PreviewTransform { get; set; } +// protected Action PreviewTransform { get; set; } - protected Action PickerTransform { get; set; } +// protected Action PickerTransform { get; set; } - public ZeroBackofficeCollectionController(TCollection collection) - { - Collection = collection; - } +// public ZeroBackofficeCollectionController(TCollection collection) +// { +// Collection = collection; +// } - public override void OnScopeChanged(string scope) - { - //Collection.ApplyScope(scope); - } +// public override void OnScopeChanged(string scope) +// { +// //Collection.ApplyScope(scope); +// } - public virtual async Task> GetById([FromQuery] string id, [FromQuery] string changeVector = null) => Edit(await Collection.Load(id, changeVector)); +// public virtual async Task> GetById([FromQuery] string id, [FromQuery] string changeVector = null) => Edit(await Collection.Load(id, changeVector)); - public virtual async Task> GetByIds([FromQuery] string[] ids) => await Collection.Load(ids); +// public virtual async Task> GetByIds([FromQuery] string[] ids) => await Collection.Load(ids); - public virtual async Task> GetEmpty() => Edit(await Collection.Empty()); +// public virtual async Task> GetEmpty() => Edit(await Collection.Empty()); - public virtual async Task> GetByQuery([FromQuery] ListQuery query) - { - return await Collection.Load(query); - } +// public virtual async Task> GetByQuery([FromQuery] ListQuery query) +// { +// return await Collection.Load(query); +// } - public virtual async Task> GetRevisions([FromQuery] string id, [FromQuery] ListQuery query) - { - return null; // TODO - //return await Collection.GetRevisions(id, query.Page, query.PageSize); - } +// public virtual async Task> GetRevisions([FromQuery] string id, [FromQuery] ListQuery query) +// { +// return null; // TODO +// //return await Collection.GetRevisions(id, query.Page, query.PageSize); +// } - public virtual async Task> GetForPicker() => await SelectList(Collection.Stream(), PickerTransform); +// public virtual async Task> GetForPicker() => await SelectList(Collection.Stream(), PickerTransform); - public virtual async Task> GetPreviews([FromQuery] List ids) => Previews(await Collection.Load(ids), PreviewTransform); +// public virtual async Task> GetPreviews([FromQuery] List ids) => Previews(await Collection.Load(ids), PreviewTransform); - [HttpPost] - public virtual async Task> Save([FromBody] TEntity model) => await Collection.Save(model); +// [HttpPost] +// public virtual async Task> Save([FromBody] TEntity model) => await Collection.Save(model); - [HttpDelete] - public virtual async Task> Delete([FromQuery] string id) => await Collection.Delete(id); -} \ No newline at end of file +// [HttpDelete] +// public virtual async Task> Delete([FromQuery] string id) => await Collection.Delete(id); +//} \ No newline at end of file diff --git a/zero.Backoffice/Models/ListQuery/ListQueryExtensions.cs b/zero.Backoffice/Models/ListQuery/ListQueryExtensions.cs index c192c665..84060ccd 100644 --- a/zero.Backoffice/Models/ListQuery/ListQueryExtensions.cs +++ b/zero.Backoffice/Models/ListQuery/ListQueryExtensions.cs @@ -61,10 +61,4 @@ public static class ListQueryExtensions return queryable; } - - - public static Paged Convert(this Paged result, ListQueryDisplayType displayType) where T : ZeroIdEntity - { - - } } \ No newline at end of file diff --git a/zero.Backoffice/Models/PickerModel.cs b/zero.Backoffice/Models/PickerModel.cs index cd862845..c3e918ed 100644 --- a/zero.Backoffice/Models/PickerModel.cs +++ b/zero.Backoffice/Models/PickerModel.cs @@ -1,6 +1,6 @@ namespace zero.Backoffice.Models; -public class PickerModel +public struct PickerModel { public string Id { get; set; } diff --git a/zero.Backoffice/Models/PickerPreviewModel.cs b/zero.Backoffice/Models/PickerPreviewModel.cs index 9e2dafb7..a3a6709f 100644 --- a/zero.Backoffice/Models/PickerPreviewModel.cs +++ b/zero.Backoffice/Models/PickerPreviewModel.cs @@ -1,6 +1,6 @@ namespace zero.Backoffice.Models; -public class PickerPreviewModel +public struct PickerPreviewModel { public string Id { get; set; } diff --git a/zero.Backoffice/Models/TreeItem.cs b/zero.Backoffice/Models/TreeItem.cs index d82c7027..082f2fbf 100644 --- a/zero.Backoffice/Models/TreeItem.cs +++ b/zero.Backoffice/Models/TreeItem.cs @@ -3,7 +3,7 @@ /// /// Represents an item in a tree /// -public class TreeItem +public struct TreeItem { /// /// Id of the item @@ -43,7 +43,7 @@ public class TreeItem /// /// Displays a small icon (with hover text) next to the main item icon /// - public TreeItemModifier Modifier { get; set; } + public TreeItemModifier? Modifier { get; set; } /// /// Whether this item has children diff --git a/zero.Backoffice/Models/TreeItemModifier.cs b/zero.Backoffice/Models/TreeItemModifier.cs index 90b0afec..b4ad653b 100644 --- a/zero.Backoffice/Models/TreeItemModifier.cs +++ b/zero.Backoffice/Models/TreeItemModifier.cs @@ -3,7 +3,7 @@ /// /// The modifier displays a small icon (with hover text) next to the main item icon /// -public class TreeItemModifier +public struct TreeItemModifier { /// /// Name of the modifier @@ -15,8 +15,6 @@ public class TreeItemModifier /// public string Icon { get; set; } - public TreeItemModifier() { } - public TreeItemModifier(string name, string icon) { Name = name; diff --git a/zero.Backoffice/Models/_legacy/ListItemModel.cs b/zero.Backoffice/Models/_legacy/ListItemModel.cs index b15e6131..b42a8ef7 100644 --- a/zero.Backoffice/Models/_legacy/ListItemModel.cs +++ b/zero.Backoffice/Models/_legacy/ListItemModel.cs @@ -1,11 +1,11 @@ -using System; +//using System; -namespace zero.Web.Models -{ - public class ListItemModel : ListModel - { - public string Name { get; set; } +//namespace zero.Web.Models +//{ +// public class ListItemModel : ListModel +// { +// public string Name { get; set; } - public bool IsActive { get; set; } - } -} +// public bool IsActive { get; set; } +// } +//} diff --git a/zero.Backoffice/Models/_legacy/PageEditModel.cs b/zero.Backoffice/Models/_legacy/PageEditModel.cs index b8203d12..0e52057e 100644 --- a/zero.Backoffice/Models/_legacy/PageEditModel.cs +++ b/zero.Backoffice/Models/_legacy/PageEditModel.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using zero.Core.Entities; +//using System.Collections.Generic; +//using zero.Core.Entities; -namespace zero.Web.Models -{ - public class PageEditModel : EditModel where T : Page - { - public PageType PageType { get; set; } +//namespace zero.Web.Models +//{ +// public class PageEditModel : EditModel where T : Page +// { +// public PageType PageType { get; set; } - public Paged Revisions { get; set; } +// public Paged Revisions { get; set; } - public List Urls { get; set; } = new(); - } -} +// public List Urls { get; set; } = new(); +// } +//} diff --git a/zero.Backoffice/Models/_legacy/ZeroBackofficeModel.cs b/zero.Backoffice/Models/_legacy/ZeroBackofficeModel.cs index b430efd2..7da23af6 100644 --- a/zero.Backoffice/Models/_legacy/ZeroBackofficeModel.cs +++ b/zero.Backoffice/Models/_legacy/ZeroBackofficeModel.cs @@ -1,9 +1,8 @@ -namespace zero.Web.Models -{ - public class ZeroBackofficeModel - { - public int Port { get; set; } +namespace zero.Backoffice; - public IZeroVue Vue { get; set; } - } -} +public class ZeroBackofficeModel +{ + public int Port { get; set; } + + public IZeroVue Vue { get; set; } +} \ No newline at end of file diff --git a/zero.Backoffice/Modules/Pages/PageTreeService.cs b/zero.Backoffice/Modules/Pages/PageTreeService.cs index 46fd3899..16d210f2 100644 --- a/zero.Backoffice/Modules/Pages/PageTreeService.cs +++ b/zero.Backoffice/Modules/Pages/PageTreeService.cs @@ -2,7 +2,7 @@ using Raven.Client.Documents.Linq; using Raven.Client.Documents.Session; -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Pages; public class PageTreeService : IPageTreeService { @@ -18,16 +18,14 @@ public class PageTreeService : IPageTreeService Pages = pages; Routes = routes; PageOptions = options.For(); - IMediaManagement media; } /// public async Task> GetChildren(string parentId = null, string activeId = null, string search = null) { - IList items = new List(); - IReadOnlyCollection pageTypes = PageOptions.GetAllItems(); - string[] openIds = new string[0] { }; + List items = new(); + string[] openIds = Array.Empty(); Paged pages = null; IList children = null; bool isSearch = !search.IsNullOrWhiteSpace(); @@ -79,7 +77,7 @@ public class PageTreeService : IPageTreeService // function to get modifier icon - TreeItemModifier GetModifier(Page page) + TreeItemModifier? GetModifier(Page page) { if (page.PublishDate > DateTimeOffset.Now || page.UnpublishDate > DateTimeOffset.Now) { @@ -96,7 +94,7 @@ public class PageTreeService : IPageTreeService // build tree foreach (Page page in pages.Items) { - PageType pageType = pageTypes.FirstOrDefault(x => x.Alias == page.PageTypeAlias); + PageType pageType = PageOptions.FirstOrDefault(x => x.Alias == page.PageTypeAlias); if (pageType == null) { diff --git a/zero.Backoffice/Modules/Search/BackofficeSearchService.cs b/zero.Backoffice/Modules/Search/BackofficeSearchService.cs index 191757ca..2511e1b5 100644 --- a/zero.Backoffice/Modules/Search/BackofficeSearchService.cs +++ b/zero.Backoffice/Modules/Search/BackofficeSearchService.cs @@ -2,7 +2,7 @@ using Raven.Client.Documents.Queries; using Raven.Client.Documents.Session; -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Search; public class BackofficeSearchService : IBackofficeSearchService { @@ -35,7 +35,7 @@ public class BackofficeSearchService : IBackofficeSearchService List items = new(); - IReadOnlyCollection maps = Options.For().GetAllItems(); + IEnumerable maps = Options.For(); foreach (ZeroEntity result in results) { diff --git a/zero.Backoffice/Modules/Search/Module.cs b/zero.Backoffice/Modules/Search/Module.cs deleted file mode 100644 index ae64de72..00000000 --- a/zero.Backoffice/Modules/Search/Module.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace zero.Backoffice.Modules; - -internal class SearchModule : ZeroModule -{ - /// - public override void Register(IZeroModuleConfiguration config) - { - config.Services.AddScoped(); - } - - - /// - public override void Configure(IZeroOptions options) - { - options.For().Indexes.Add(); - } -} \ No newline at end of file diff --git a/zero.Backoffice/Modules/Search/SearchEndpoint.cs b/zero.Backoffice/Modules/Search/SearchEndpoint.cs index ce3351c4..b63042ee 100644 --- a/zero.Backoffice/Modules/Search/SearchEndpoint.cs +++ b/zero.Backoffice/Modules/Search/SearchEndpoint.cs @@ -1,16 +1,16 @@ -using Microsoft.AspNetCore.Mvc; +//using Microsoft.AspNetCore.Mvc; -namespace zero.Backoffice.Modules; +//namespace zero.Backoffice.Modules; -[ZeroAuthorize] -public class SearchController : BackofficeController -{ - IBackofficeSearchService SearchService; +//[ZeroAuthorize] +//public class SearchController : BackofficeController +//{ +// IBackofficeSearchService SearchService; - public SearchController(IBackofficeSearchService searchService) - { - SearchService = searchService; - } +// public SearchController(IBackofficeSearchService searchService) +// { +// SearchService = searchService; +// } - public async Task> Query([FromQuery] string query) => await SearchService.Query(query); -} \ No newline at end of file +// public async Task> Query([FromQuery] string query) => await SearchService.Query(query); +//} \ No newline at end of file diff --git a/zero.Backoffice/Modules/Search/SearchIndexMap.cs b/zero.Backoffice/Modules/Search/SearchIndexMap.cs index 65dfae9d..8ae32291 100644 --- a/zero.Backoffice/Modules/Search/SearchIndexMap.cs +++ b/zero.Backoffice/Modules/Search/SearchIndexMap.cs @@ -1,6 +1,6 @@ using Raven.Client.Documents; -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Search; public class SearchIndexMap { diff --git a/zero.Backoffice/Modules/Search/SearchOptions.cs b/zero.Backoffice/Modules/Search/SearchOptions.cs index b3e425f6..16af622d 100644 --- a/zero.Backoffice/Modules/Search/SearchOptions.cs +++ b/zero.Backoffice/Modules/Search/SearchOptions.cs @@ -1,13 +1,13 @@ -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Search; -public class SearchOptions : OptionsEnumerable, IOptionsEnumerable +public class SearchOptions : List { public bool Enabled { get; set; } public SearchIndexMap Map(string icon = null) where T : ZeroEntity, new() { SearchIndexMap map = new(icon); - Items.Add(map); + Add(map); return map; } } \ No newline at end of file diff --git a/zero.Backoffice/Modules/Search/SearchResult.cs b/zero.Backoffice/Modules/Search/SearchResult.cs index c0d5b958..d7ee76bd 100644 --- a/zero.Backoffice/Modules/Search/SearchResult.cs +++ b/zero.Backoffice/Modules/Search/SearchResult.cs @@ -1,4 +1,4 @@ -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Search; public class SearchResult { diff --git a/zero.Backoffice/Modules/Search/zero_Backoffice_Search.cs b/zero.Backoffice/Modules/Search/zero_Backoffice_Search.cs index e3be9821..18b1c88f 100644 --- a/zero.Backoffice/Modules/Search/zero_Backoffice_Search.cs +++ b/zero.Backoffice/Modules/Search/zero_Backoffice_Search.cs @@ -1,6 +1,6 @@ using Raven.Client.Documents; -namespace zero.Backoffice.Modules; +namespace zero.Backoffice.Modules.Search; public class zero_Backoffice_Search : ZeroJavascriptIndex { @@ -8,7 +8,7 @@ public class zero_Backoffice_Search : ZeroJavascriptIndex { // TODO index.Conventions is null, but needed for collection name retrieval - foreach (var map in options.For().GetAllItems()) + foreach (var map in options.For()) { Maps.Add(map.BuildInstruction(store)); } diff --git a/zero.Backoffice/Modules/ServiceCollectionExtensions.cs b/zero.Backoffice/Modules/ServiceCollectionExtensions.cs index d7078218..acfb8dab 100644 --- a/zero.Backoffice/Modules/ServiceCollectionExtensions.cs +++ b/zero.Backoffice/Modules/ServiceCollectionExtensions.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using zero.Backoffice.Modules.Countries; +using zero.Backoffice.Modules.Pages; +using zero.Backoffice.Modules.Search; namespace zero.Backoffice.Modules; @@ -9,6 +11,7 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddZeroBackofficeModules(this IServiceCollection services, IConfiguration config) { services.AddScoped(); + services.AddScoped(); services.AddScoped, CountryPickerProvider>(); services.AddSingleton(); @@ -16,6 +19,7 @@ public static class ServiceCollectionExtensions services.Configure(opts => { opts.Indexes.Add(); + opts.Indexes.Add(); }); return services; diff --git a/zero.Backoffice/Modules/Applications/ApplicationEditModel.cs b/zero.Backoffice/Modules_legacy/Applications/ApplicationEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Applications/ApplicationEditModel.cs rename to zero.Backoffice/Modules_legacy/Applications/ApplicationEditModel.cs diff --git a/zero.Backoffice/Modules/Applications/ApplicationListModel.cs b/zero.Backoffice/Modules_legacy/Applications/ApplicationListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Applications/ApplicationListModel.cs rename to zero.Backoffice/Modules_legacy/Applications/ApplicationListModel.cs diff --git a/zero.Backoffice/Modules/Applications/ApplicationsController.cs b/zero.Backoffice/Modules_legacy/Applications/ApplicationsController.cs similarity index 100% rename from zero.Backoffice/Modules/Applications/ApplicationsController.cs rename to zero.Backoffice/Modules_legacy/Applications/ApplicationsController.cs diff --git a/zero.Backoffice/Modules/Blueprints/BlueprintController.cs b/zero.Backoffice/Modules_legacy/Blueprints/BlueprintController.cs similarity index 100% rename from zero.Backoffice/Modules/Blueprints/BlueprintController.cs rename to zero.Backoffice/Modules_legacy/Blueprints/BlueprintController.cs diff --git a/zero.Backoffice/Modules/Integrations/IntegrationsController.cs b/zero.Backoffice/Modules_legacy/Integrations/IntegrationsController.cs similarity index 100% rename from zero.Backoffice/Modules/Integrations/IntegrationsController.cs rename to zero.Backoffice/Modules_legacy/Integrations/IntegrationsController.cs diff --git a/zero.Backoffice/Modules/Languages/LanguageEditModel.cs b/zero.Backoffice/Modules_legacy/Languages/LanguageEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Languages/LanguageEditModel.cs rename to zero.Backoffice/Modules_legacy/Languages/LanguageEditModel.cs diff --git a/zero.Backoffice/Modules/Languages/LanguageListModel.cs b/zero.Backoffice/Modules_legacy/Languages/LanguageListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Languages/LanguageListModel.cs rename to zero.Backoffice/Modules_legacy/Languages/LanguageListModel.cs diff --git a/zero.Backoffice/Modules/Languages/LanguagesController.cs b/zero.Backoffice/Modules_legacy/Languages/LanguagesController.cs similarity index 100% rename from zero.Backoffice/Modules/Languages/LanguagesController.cs rename to zero.Backoffice/Modules_legacy/Languages/LanguagesController.cs diff --git a/zero.Backoffice/Modules/Languages/zero_Languages.cs b/zero.Backoffice/Modules_legacy/Languages/zero_Languages.cs similarity index 100% rename from zero.Backoffice/Modules/Languages/zero_Languages.cs rename to zero.Backoffice/Modules_legacy/Languages/zero_Languages.cs diff --git a/zero.Backoffice/Modules/Links/LinksController.cs b/zero.Backoffice/Modules_legacy/Links/LinksController.cs similarity index 100% rename from zero.Backoffice/Modules/Links/LinksController.cs rename to zero.Backoffice/Modules_legacy/Links/LinksController.cs diff --git a/zero.Backoffice/Modules/Mails/MailTemplatesController.cs b/zero.Backoffice/Modules_legacy/Mails/MailTemplatesController.cs similarity index 100% rename from zero.Backoffice/Modules/Mails/MailTemplatesController.cs rename to zero.Backoffice/Modules_legacy/Mails/MailTemplatesController.cs diff --git a/zero.Backoffice/Modules/Mails/zero_MailTemplates.cs b/zero.Backoffice/Modules_legacy/Mails/zero_MailTemplates.cs similarity index 100% rename from zero.Backoffice/Modules/Mails/zero_MailTemplates.cs rename to zero.Backoffice/Modules_legacy/Mails/zero_MailTemplates.cs diff --git a/zero.Backoffice/Modules/Media/MediaController.cs b/zero.Backoffice/Modules_legacy/Media/MediaController.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaController.cs rename to zero.Backoffice/Modules_legacy/Media/MediaController.cs diff --git a/zero.Backoffice/Modules/Media/MediaEditModel.cs b/zero.Backoffice/Modules_legacy/Media/MediaEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaEditModel.cs rename to zero.Backoffice/Modules_legacy/Media/MediaEditModel.cs diff --git a/zero.Backoffice/Modules/Media/MediaFolderController.cs b/zero.Backoffice/Modules_legacy/Media/MediaFolderController.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaFolderController.cs rename to zero.Backoffice/Modules_legacy/Media/MediaFolderController.cs diff --git a/zero.Backoffice/Modules/Media/MediaFolderEditModel.cs b/zero.Backoffice/Modules_legacy/Media/MediaFolderEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaFolderEditModel.cs rename to zero.Backoffice/Modules_legacy/Media/MediaFolderEditModel.cs diff --git a/zero.Backoffice/Modules/Media/MediaListModel.cs b/zero.Backoffice/Modules_legacy/Media/MediaListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaListModel.cs rename to zero.Backoffice/Modules_legacy/Media/MediaListModel.cs diff --git a/zero.Backoffice/Modules/Media/MediaListResultModel.cs b/zero.Backoffice/Modules_legacy/Media/MediaListResultModel.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaListResultModel.cs rename to zero.Backoffice/Modules_legacy/Media/MediaListResultModel.cs diff --git a/zero.Backoffice/Modules/Media/MediaTreeService.cs b/zero.Backoffice/Modules_legacy/Media/MediaTreeService.cs similarity index 100% rename from zero.Backoffice/Modules/Media/MediaTreeService.cs rename to zero.Backoffice/Modules_legacy/Media/MediaTreeService.cs diff --git a/zero.Backoffice/Modules/Pages/ModulesController.cs b/zero.Backoffice/Modules_legacy/Pages/ModulesController.cs similarity index 100% rename from zero.Backoffice/Modules/Pages/ModulesController.cs rename to zero.Backoffice/Modules_legacy/Pages/ModulesController.cs diff --git a/zero.Backoffice/Modules/Pages/PagesController.cs b/zero.Backoffice/Modules_legacy/Pages/PagesController.cs similarity index 100% rename from zero.Backoffice/Modules/Pages/PagesController.cs rename to zero.Backoffice/Modules_legacy/Pages/PagesController.cs diff --git a/zero.Backoffice/Modules/Pages/_PagesController.cs b/zero.Backoffice/Modules_legacy/Pages/_PagesController.cs similarity index 100% rename from zero.Backoffice/Modules/Pages/_PagesController.cs rename to zero.Backoffice/Modules_legacy/Pages/_PagesController.cs diff --git a/zero.Backoffice/Modules/Previews/PreviewController.cs b/zero.Backoffice/Modules_legacy/Previews/PreviewController.cs similarity index 100% rename from zero.Backoffice/Modules/Previews/PreviewController.cs rename to zero.Backoffice/Modules_legacy/Previews/PreviewController.cs diff --git a/zero.Backoffice/Modules/RecycleBin/RecycleBinController.cs b/zero.Backoffice/Modules_legacy/RecycleBin/RecycleBinController.cs similarity index 100% rename from zero.Backoffice/Modules/RecycleBin/RecycleBinController.cs rename to zero.Backoffice/Modules_legacy/RecycleBin/RecycleBinController.cs diff --git a/zero.Backoffice/Modules/Security/AuthenticationController.cs b/zero.Backoffice/Modules_legacy/Security/AuthenticationController.cs similarity index 100% rename from zero.Backoffice/Modules/Security/AuthenticationController.cs rename to zero.Backoffice/Modules_legacy/Security/AuthenticationController.cs diff --git a/zero.Backoffice/Modules/Spaces/SpaceContentEditModel.cs b/zero.Backoffice/Modules_legacy/Spaces/SpaceContentEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Spaces/SpaceContentEditModel.cs rename to zero.Backoffice/Modules_legacy/Spaces/SpaceContentEditModel.cs diff --git a/zero.Backoffice/Modules/Spaces/SpacePermissions.cs b/zero.Backoffice/Modules_legacy/Spaces/SpacePermissions.cs similarity index 100% rename from zero.Backoffice/Modules/Spaces/SpacePermissions.cs rename to zero.Backoffice/Modules_legacy/Spaces/SpacePermissions.cs diff --git a/zero.Backoffice/Modules/Spaces/SpacesController.cs b/zero.Backoffice/Modules_legacy/Spaces/SpacesController.cs similarity index 100% rename from zero.Backoffice/Modules/Spaces/SpacesController.cs rename to zero.Backoffice/Modules_legacy/Spaces/SpacesController.cs diff --git a/zero.Backoffice/Modules/Spaces/zero_Spaces.cs b/zero.Backoffice/Modules_legacy/Spaces/zero_Spaces.cs similarity index 100% rename from zero.Backoffice/Modules/Spaces/zero_Spaces.cs rename to zero.Backoffice/Modules_legacy/Spaces/zero_Spaces.cs diff --git a/zero.Backoffice/Modules/Translations/Module.cs b/zero.Backoffice/Modules_legacy/Translations/Module.cs similarity index 100% rename from zero.Backoffice/Modules/Translations/Module.cs rename to zero.Backoffice/Modules_legacy/Translations/Module.cs diff --git a/zero.Backoffice/Modules/Translations/TranslationEditModel.cs b/zero.Backoffice/Modules_legacy/Translations/TranslationEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Translations/TranslationEditModel.cs rename to zero.Backoffice/Modules_legacy/Translations/TranslationEditModel.cs diff --git a/zero.Backoffice/Modules/Translations/TranslationListModel.cs b/zero.Backoffice/Modules_legacy/Translations/TranslationListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Translations/TranslationListModel.cs rename to zero.Backoffice/Modules_legacy/Translations/TranslationListModel.cs diff --git a/zero.Backoffice/Modules/Translations/TranslationsController.cs b/zero.Backoffice/Modules_legacy/Translations/TranslationsController.cs similarity index 100% rename from zero.Backoffice/Modules/Translations/TranslationsController.cs rename to zero.Backoffice/Modules_legacy/Translations/TranslationsController.cs diff --git a/zero.Backoffice/Modules/Translations/zero_Backoffice_Translations.cs b/zero.Backoffice/Modules_legacy/Translations/zero_Backoffice_Translations.cs similarity index 100% rename from zero.Backoffice/Modules/Translations/zero_Backoffice_Translations.cs rename to zero.Backoffice/Modules_legacy/Translations/zero_Backoffice_Translations.cs diff --git a/zero.Backoffice/Modules/UI/SectionsController.cs b/zero.Backoffice/Modules_legacy/UI/SectionsController.cs similarity index 100% rename from zero.Backoffice/Modules/UI/SectionsController.cs rename to zero.Backoffice/Modules_legacy/UI/SectionsController.cs diff --git a/zero.Backoffice/Modules/UI/SettingsController.cs b/zero.Backoffice/Modules_legacy/UI/SettingsController.cs similarity index 100% rename from zero.Backoffice/Modules/UI/SettingsController.cs rename to zero.Backoffice/Modules_legacy/UI/SettingsController.cs diff --git a/zero.Backoffice/Modules/Users/UserEditModel.cs b/zero.Backoffice/Modules_legacy/Users/UserEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserEditModel.cs rename to zero.Backoffice/Modules_legacy/Users/UserEditModel.cs diff --git a/zero.Backoffice/Modules/Users/UserListModel.cs b/zero.Backoffice/Modules_legacy/Users/UserListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserListModel.cs rename to zero.Backoffice/Modules_legacy/Users/UserListModel.cs diff --git a/zero.Backoffice/Modules/Users/UserPasswordEditModel.cs b/zero.Backoffice/Modules_legacy/Users/UserPasswordEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserPasswordEditModel.cs rename to zero.Backoffice/Modules_legacy/Users/UserPasswordEditModel.cs diff --git a/zero.Backoffice/Modules/Users/UserRoleEditModel.cs b/zero.Backoffice/Modules_legacy/Users/UserRoleEditModel.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserRoleEditModel.cs rename to zero.Backoffice/Modules_legacy/Users/UserRoleEditModel.cs diff --git a/zero.Backoffice/Modules/Users/UserRoleListModel.cs b/zero.Backoffice/Modules_legacy/Users/UserRoleListModel.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserRoleListModel.cs rename to zero.Backoffice/Modules_legacy/Users/UserRoleListModel.cs diff --git a/zero.Backoffice/Modules/Users/UserRolesController.cs b/zero.Backoffice/Modules_legacy/Users/UserRolesController.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UserRolesController.cs rename to zero.Backoffice/Modules_legacy/Users/UserRolesController.cs diff --git a/zero.Backoffice/Modules/Users/UsersController.cs b/zero.Backoffice/Modules_legacy/Users/UsersController.cs similarity index 100% rename from zero.Backoffice/Modules/Users/UsersController.cs rename to zero.Backoffice/Modules_legacy/Users/UsersController.cs diff --git a/zero.Backoffice/ServiceCollectionExtensions.cs b/zero.Backoffice/ServiceCollectionExtensions.cs index ad4ea2b6..fd1a617f 100644 --- a/zero.Backoffice/ServiceCollectionExtensions.cs +++ b/zero.Backoffice/ServiceCollectionExtensions.cs @@ -16,10 +16,9 @@ public static class ServiceCollectionExtensions public static ZeroBuilder AddBackoffice(this ZeroBuilder builder, Action options) where T : ZeroBackofficePlugin, IZeroPlugin, new() { - return builder.AddPlugin(services => + return builder.AddPlugin(services => { - T plugin = new T(); - + T plugin = new(); plugin.PostConfigureServices = (services, configuration) => { services.Configure(opts => options(opts)); diff --git a/zero.Backoffice/Usings.cs b/zero.Backoffice/Usings.cs index 22b5775b..99cfaef8 100644 --- a/zero.Backoffice/Usings.cs +++ b/zero.Backoffice/Usings.cs @@ -11,6 +11,7 @@ global using zero.Stores; global using zero.Configuration; global using zero.Context; global using zero.Extensions; +global using zero.FileStorage; global using zero.Identity; global using zero.Localization; global using zero.Media; diff --git a/zero.Backoffice/ZeroBackofficeMvcOptions.cs b/zero.Backoffice/ZeroBackofficeMvcOptions.cs index c37f2aea..a720074e 100644 --- a/zero.Backoffice/ZeroBackofficeMvcOptions.cs +++ b/zero.Backoffice/ZeroBackofficeMvcOptions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Options; namespace zero.Backoffice; -class ZeroBackofficeMvcOptions : IConfigureOptions +internal class ZeroBackofficeMvcOptions : IConfigureOptions { IZeroOptions Options { get; set; } @@ -14,7 +14,6 @@ class ZeroBackofficeMvcOptions : IConfigureOptions public void Configure(MvcOptions options) { - string backofficePath = Options.For().Path; - options.Conventions.Add(new ZeroBackofficeControllerModelConvention(backofficePath)); + options.Conventions.Add(new ZeroBackofficeControllerModelConvention(Options.ZeroPath)); } } \ No newline at end of file diff --git a/zero.Backoffice/ZeroVue.cs b/zero.Backoffice/ZeroVue.cs index 2a03ebea..e3feec75 100644 --- a/zero.Backoffice/ZeroVue.cs +++ b/zero.Backoffice/ZeroVue.cs @@ -1,593 +1,584 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using System.Text.Json; -using System.Threading.Tasks; using System.Xml.Linq; -using zero.Core; -using zero.Core.Api; -using zero.Core.Blueprints; -using zero.Core.Database; -using zero.Core.Entities; -using zero.Core.Extensions; -using zero.Core.Identity; -using zero.Core.Options; -using zero.Core.Plugins; -using zero.Web.Models; -namespace zero.Backoffice +namespace zero.Backoffice; + +public class ZeroVue : IZeroVue { - public class ZeroVue : IZeroVue + protected IZeroOptions Options { get; private set; } + + protected IPaths Paths { get; private set; } + + protected IApplicationStore ApplicationStore { get; private set; } + + protected IAuthenticationService AuthenticationApi { get; private set; } + + protected IEnumerable Plugins { get; private set; } + + protected IEnumerable Sections { get; private set; } + + protected IEnumerable SettingsGroups { get; private set; } + + protected IZeroContext Context { get; private set; } + + protected ILogger Logger { get; private set; } + + protected IZeroStore Store { get; private set; } + + string IconSymbolsSvg { get; set; } + + + public ZeroVue(IZeroOptions options, IPaths paths, IApplicationStore applicationStore, IAuthenticationService authenticationApi, + IEnumerable plugins, IZeroContext context, ILogger logger, IZeroStore store, + IEnumerable sections, IEnumerable settingsGroups) { - protected IZeroOptions Options { get; private set; } - - protected IPaths Paths { get; private set; } - - protected IApplicationsApi ApplicationsApi { get; private set; } - - protected IAuthenticationService AuthenticationApi { get; private set; } - - protected IEnumerable Plugins { get; private set; } - - protected IZeroContext Context { get; private set; } - - protected ILogger Logger { get; private set; } - - protected IZeroStore Store { get; private set; } - - string IconSymbolsSvg { get; set; } + Paths = paths; + Options = options; + ApplicationStore = applicationStore; + AuthenticationApi = authenticationApi; + Plugins = plugins; + Context = context; + Logger = logger; + Store = store; + Sections = sections; + SettingsGroups = settingsGroups; + } - public ZeroVue(IZeroOptions options, IPaths paths, IApplicationsApi applicationsApi, IAuthenticationService authenticationApi, IEnumerable plugins, IZeroContext context, ILogger logger, IZeroStore store) + /// + public async Task Config() + { + ZeroVueConfig config = new ZeroVueConfig(); + + config.Path = Options.ZeroPath.EnsureEndsWith('/'); + config.ApiPath = config.Path + "api/"; + config.PluginPath = "@/Plugins"; + config.Version = Options.Version; + config.PluginCount = Plugins.Count(); + config.ErrorFieldNone = Constants.ErrorFieldNone; + config.Alias = CreateAliases(); + config.AppId = Context.AppId; + //config.SharedAppId = Constants.Database.SharedAppId; // TODO appx + config.Icons = CreateIconSets(); + config.MultiApps = Options.For().EnableMultiple; + + ZeroUser user = await AuthenticationApi.GetUser(); + + config.Translations = CreateTranslations(user?.LanguageId); + + if (user != null) { - Paths = paths; - Options = options; - ApplicationsApi = applicationsApi; - AuthenticationApi = authenticationApi; - Plugins = plugins; - Context = context; - Logger = logger; - Store = store; - } - - - /// - public async Task Config() - { - ZeroVueConfig config = new ZeroVueConfig(); - - config.Path = Options.BackofficePath.EnsureEndsWith('/'); - config.ApiPath = config.Path + "api/"; - config.PluginPath = "@/Plugins"; - config.Version = Options.Version; - config.PluginCount = Plugins.Count(); - config.ErrorFieldNone = Constants.ErrorFieldNone; - config.Alias = CreateAliases(); - config.AppId = Context.AppId; - //config.SharedAppId = Constants.Database.SharedAppId; // TODO appx - config.Icons = CreateIconSets(); - config.MultiApps = Options.Applications.EnableMultiple; - - ZeroUser user = await AuthenticationApi.GetUser(); - - config.Translations = CreateTranslations(user?.LanguageId); - - if (user != null) + config.User = new { - config.User = new UserEditModel() - { - Id = user.Id, - AvatarId = user.AvatarId, - Email = user.Email, - IsSuper = user.IsSuper, - Name = user.Name, - Roles = user.RoleIds - }; + Id = user.Id, + AvatarId = user.AvatarId, + Email = user.Email, + IsSuper = user.IsSuper, + Name = user.Name, + Roles = user.RoleIds + }; - config.Sections = CreateSections(); - config.Applications = await CreateApplications(); - config.SettingsAreas = CreateSettingsAreas(); + config.Sections = CreateSections(); + config.Applications = await CreateApplications(); + config.SettingsAreas = CreateSettingsAreas(); - config.Plugins = Plugins.Select(x => new ZeroVuePlugin() - { - Name = x.Options.Name, - Description = x.Options.Description, - PluginPath = x.Options.PluginPath - }).ToList(); - - config.Services = new() - { - YouTubeApiKey = Options.Services.YouTubeApiKey - }; - - config.Blueprints = CreateBlueprints(); - } - - return config; - } - - - /// - public async Task ConfigAsJson() - { - return JsonSerializer.Serialize(await Config(), new JsonSerializerOptions() + config.Plugins = Plugins.Select(x => new ZeroVuePlugin() { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); - } - - - /// - public string GetIconSvg() - { - return IconSymbolsSvg; - } - - - /// - /// Creates the sections - /// - IList CreateSections() - { - bool isSuperUser = AuthenticationApi.IsSuper(); - IList permissions = AuthenticationApi.GetPermissions(Permissions.Sections.PREFIX); - - List sections = new List(); - - foreach (ISection section in Options.Sections.GetAllItems()) - { - if (!isSuperUser && !Permission.CanReadKey(permissions, section.Alias, true)) - { - continue; - } - - bool isExternal = !(section is IInternalSection); - string url = Safenames.Alias(section.Alias).EnsureStartsWith('/'); - - if (section.Alias == Constants.Sections.Dashboard) - { - url = "/"; - } - - ZeroVueSection vueSection = new ZeroVueSection() - { - Alias = section.Alias, - Name = section.Name, - Icon = section.Icon, - Color = section.Color, - Url = url, - Children = new List(), - IsExternal = isExternal - }; - - foreach (ISection child in section.Children) - { - vueSection.Children.Add(new ZeroVueSection() - { - Alias = child.Alias, - Name = child.Name, - Url = vueSection.Url.EnsureEndsWith('/') + Safenames.Alias(child.Alias), - IsExternal = isExternal - }); - } - - sections.Add(vueSection); - } - - return sections; - } - - - /// - /// Create aliases - /// - Dictionary> CreateAliases() - { - Dictionary> aliases = new Dictionary>(); - - Dictionary sections = new Dictionary(); - sections.Add("dashboard", Constants.Sections.Dashboard); - sections.Add("pages", Constants.Sections.Pages); - sections.Add("spaces", Constants.Sections.Spaces); - sections.Add("media", Constants.Sections.Media); - sections.Add("settings", Constants.Sections.Settings); - - Dictionary settings = new Dictionary(); - settings.Add("applications", Constants.Settings.Applications); - settings.Add("countries", Constants.Settings.Countries); - settings.Add("logging", Constants.Settings.Logging); - settings.Add("languages", Constants.Settings.Languages); - settings.Add("translations", Constants.Settings.Translations); - settings.Add("mails", Constants.Settings.Mails); - settings.Add("updates", Constants.Settings.Updates); - settings.Add("users", Constants.Settings.Users); - settings.Add("integrations", Constants.Settings.Integrations); - - aliases.Add("sections", sections); - aliases.Add("settings", settings); - aliases.Add("pages", new Dictionary() - { - { "folder", Constants.Pages.FolderAlias } - }); - - return aliases; - } - - - /// - /// Creates the areas in the settings section - /// - IList CreateSettingsAreas() - { - bool isSuperUser = AuthenticationApi.IsSuper(); - IList permissions = AuthenticationApi.GetPermissions(Permissions.Settings.PREFIX); - - List groups = new List(); - - bool hasIntegrations = Options.Integrations.GetAllItems().Any(); - - foreach (SettingsGroup group in Options.Settings.GetAllItems()) - { - List areas = new List(); - - foreach (SettingsArea area in group.Items) - { - if (!isSuperUser && !Permission.CanReadKey(permissions, area.Alias, true)) - { - continue; - } - if (area.Alias == Constants.Settings.Integrations && !hasIntegrations) - { - continue; - } - - bool isPlugin = !(area is InternalSettingsArea); - - ZeroVueSettingsArea vueArea = new ZeroVueSettingsArea() - { - Alias = area.Alias, - Name = area.Name, - Description = area.Description, - Icon = area.Icon, - Url = Constants.Sections.Settings.EnsureStartsWith('/') + Safenames.Alias(area.Alias).EnsureStartsWith('/'), - IsPlugin = isPlugin - }; - - areas.Add(vueArea); - } - - if (areas.Count > 0) - { - groups.Add(new ZeroVueSettingsGroup() - { - Name = group.Name, - Items = areas - }); - } - } - - return groups; - } - - - /// - /// Get all visible applications - /// - async Task> CreateApplications() - { - IList applications = await ApplicationsApi.GetAll(); - - string[] mediaIds = applications.Select(x => x.IconId).Where(x => x != null).ToArray(); - Dictionary media = await Store.Session().LoadAsync(mediaIds); - - return applications.OrderBy(app => app.Sort).Select(app => new ZeroVueApplication() - { - Id = app.Id, - Name = app.Name, - Image = app.IconId.IsNullOrEmpty() ? null : media.GetValueOrDefault(app.IconId)?.ThumbnailSource + Name = x.Options.Name, + Description = x.Options.Description, + PluginPath = x.Options.PluginPath }).ToList(); + + config.Services = new() + { + YouTubeApiKey = Options.For().YouTubeApiKey + }; + + config.Blueprints = CreateBlueprints(); } + return config; + } - /// - /// Creates all translations for the project - /// - Dictionary CreateTranslations(string culture) + + /// + public async Task ConfigAsJson() + { + return JsonSerializer.Serialize(await Config(), new JsonSerializerOptions() { - var zeroTranslations = CreateTranslationsForFile("O:/zero/zero.Web/Resources/Localization/zero.en-us.json", culture); // TODO - - foreach (IZeroPlugin plugin in Plugins) - { - if (plugin.Options.LocalizationPaths.Count > 0) - { - foreach (string path in plugin.Options.LocalizationPaths) - { - Dictionary translations = CreateTranslationsForFile(path, culture); - - foreach (var translation in translations) - { - zeroTranslations.Add(translation.Key, translation.Value); - } - } - } - } - - return zeroTranslations; - } + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }); + } - Dictionary CreateTranslationsForFile(string path, string culture) + /// + public string GetIconSvg() + { + return IconSymbolsSvg; + } + + + /// + /// Creates the sections + /// + IList CreateSections() + { + bool isSuperUser = AuthenticationApi.IsSuper(); + //IList permissions = AuthenticationApi.GetPermissions(Permissions.Sections.PREFIX); + + List sections = new List(); + + foreach (IBackofficeSection section in Sections) { - Dictionary items = new(); - culture = culture?.ToLower(); + //if (!isSuperUser && !Permission.CanReadKey(permissions, section.Alias, true)) + //{ + // continue; + //} - if (!culture.IsNullOrEmpty() && culture != "en-us") + string url = Safenames.Alias(section.Alias).EnsureStartsWith('/'); + + if (section.Alias == Constants.Sections.Dashboard) { - items = CreateTranslationsForFile(path, "en-us"); - path = path.Replace("en-us", culture); + url = "/"; } - if (!File.Exists(path)) + ZeroVueSection vueSection = new() { - return items; - } + Alias = section.Alias, + Name = section.Name, + Icon = section.Icon, + Color = section.Color, + Url = url, + Children = new List(), + IsExternal = false + }; - string text = File.ReadAllText(path, Encoding.GetEncoding("ISO-8859-1")); - - JObject json = JObject.Parse(text); - IEnumerable tokens = json.Descendants().Where(p => p.Count() == 0); - - Dictionary translationItems = tokens.Aggregate(new Dictionary(), (properties, token) => + foreach (IBackofficeSection child in section.Children) { - properties.Add(token.Path.ToLowerInvariant(), token.ToString()); - return properties; - }); - - foreach (var translation in translationItems) - { - items[translation.Key] = translation.Value; - } - - return items; - } - - - IList CreateIconSets() - { - List result = new(); - IReadOnlyCollection sets = Options.Icons.GetAllItems(); - - StringBuilder svg = new(); - - foreach (IconSet set in sets) - { - string path = Paths.Map(set.SpritePath.TrimStart('/')); - - if (!File.Exists(path)) + vueSection.Children.Add(new() { - Logger.LogWarning("Could not load icon set {alias} from path {path}", set.Alias, path); - continue; - } - - string svgContent = File.ReadAllText(path, Encoding.UTF8); - XDocument xml = XDocument.Parse(svgContent); - IEnumerable symbols = xml.Descendants().Where(x => x.Name.LocalName == "symbol"); // ("symbol"); - - if (!symbols.Any()) - { - Logger.LogWarning("Icon set {alias} does not contain any ", set.Alias); - continue; - } - - ZeroVueIconSet iconSet = new() - { - Alias = set.Alias, - Name = set.Name, - Prefix = set.Prefix - }; - - foreach (XElement symbol in symbols) - { - string symbolAlias = set.Prefix + "-" + symbol.Attribute("id").Value.ToString(); - symbol.SetAttributeValue("id", symbolAlias); - svg.Append(symbol.ToString().RemoveNewLines()); - iconSet.Icons.Add(symbolAlias); - } - - result.Add(iconSet); - } - - IconSymbolsSvg = svg.ToString(); - - return result; - } - - - List CreateBlueprints() - { - List items = new(); - - if (!Options.Blueprints.Enabled) - { - return items; - } - - foreach (Blueprint blueprint in Options.Blueprints.GetAllItems()) - { - string[] unlocked = blueprint.GetUnlockedFieldNames().ToArray(); - - items.Add(new() - { - Alias = blueprint.Alias, - Enabled = true, - Unlocked = unlocked + Alias = child.Alias, + Name = child.Name, + Url = vueSection.Url.EnsureEndsWith('/') + Safenames.Alias(child.Alias), + IsExternal = false }); } + sections.Add(vueSection); + } + + return sections; + } + + + /// + /// Create aliases + /// + Dictionary> CreateAliases() + { + Dictionary> aliases = new Dictionary>(); + + Dictionary sections = new Dictionary(); + sections.Add("dashboard", Constants.Sections.Dashboard); + sections.Add("pages", Constants.Sections.Pages); + sections.Add("spaces", Constants.Sections.Spaces); + sections.Add("media", Constants.Sections.Media); + sections.Add("settings", Constants.Sections.Settings); + + Dictionary settings = new Dictionary(); + settings.Add("applications", Constants.Settings.Applications); + settings.Add("countries", Constants.Settings.Countries); + settings.Add("logging", Constants.Settings.Logging); + settings.Add("languages", Constants.Settings.Languages); + settings.Add("translations", Constants.Settings.Translations); + settings.Add("mails", Constants.Settings.Mails); + settings.Add("updates", Constants.Settings.Updates); + settings.Add("users", Constants.Settings.Users); + settings.Add("integrations", Constants.Settings.Integrations); + + aliases.Add("sections", sections); + aliases.Add("settings", settings); + aliases.Add("pages", new Dictionary() + { + { "folder", Constants.Pages.FolderAlias } + }); + + return aliases; + } + + + /// + /// Creates the areas in the settings section + /// + IList CreateSettingsAreas() + { + bool isSuperUser = AuthenticationApi.IsSuper(); + //IList permissions = AuthenticationApi.GetPermissions(Permissions.Settings.PREFIX); + + List groups = new List(); + + bool hasIntegrations = Options.For().Any(); + + foreach (SettingsGroup group in SettingsGroups) + { + List areas = new(); + + foreach (SettingsArea area in group.Areas) + { + //if (!isSuperUser && !Permission.CanReadKey(permissions, area.Alias, true)) + //{ + // continue; + //} + if (area.Alias == Constants.Settings.Integrations && !hasIntegrations) + { + continue; + } + + //bool isPlugin = !(area is InternalSettingsArea); + + ZeroVueSettingsArea vueArea = new ZeroVueSettingsArea() + { + Alias = area.Alias, + Name = area.Name, + Description = area.Description, + Icon = area.Icon, + Url = Constants.Sections.Settings.EnsureStartsWith('/') + Safenames.Alias(area.Alias).EnsureStartsWith('/'), + IsPlugin = true + }; + + areas.Add(vueArea); + } + + if (areas.Count > 0) + { + groups.Add(new ZeroVueSettingsGroup() + { + Name = group.Name, + Items = areas + }); + } + } + + return groups; + } + + + /// + /// Get all visible applications + /// + async Task> CreateApplications() + { + IEnumerable applications = await ApplicationStore.LoadAll(); + + string[] mediaIds = applications.Select(x => x.IconId).Where(x => x != null).ToArray(); + Dictionary media = await Store.Session().LoadAsync(mediaIds); + + return applications.OrderBy(app => app.Sort).Select(app => new ZeroVueApplication() + { + Id = app.Id, + Name = app.Name, + Image = app.IconId.IsNullOrEmpty() ? null : media.GetValueOrDefault(app.IconId)?.Thumbnails.GetValueOrDefault("thumb") + }).ToList(); + } + + + /// + /// Creates all translations for the project + /// + Dictionary CreateTranslations(string culture) + { + var zeroTranslations = CreateTranslationsForFile("O:/zero/zero.Web/Resources/Localization/zero.en-us.json", culture); // TODO + + foreach (IZeroPlugin plugin in Plugins) + { + if (plugin.Options.LocalizationPaths.Count > 0) + { + foreach (string path in plugin.Options.LocalizationPaths) + { + Dictionary translations = CreateTranslationsForFile(path, culture); + + foreach (var translation in translations) + { + zeroTranslations.Add(translation.Key, translation.Value); + } + } + } + } + + return zeroTranslations; + } + + + Dictionary CreateTranslationsForFile(string path, string culture) + { + Dictionary items = new(); + culture = culture?.ToLower(); + + if (!culture.IsNullOrEmpty() && culture != "en-us") + { + items = CreateTranslationsForFile(path, "en-us"); + path = path.Replace("en-us", culture); + } + + if (!File.Exists(path)) + { return items; } + + string text = File.ReadAllText(path, Encoding.GetEncoding("ISO-8859-1")); + + JObject json = JObject.Parse(text); + IEnumerable tokens = json.Descendants().Where(p => p.Count() == 0); + + Dictionary translationItems = tokens.Aggregate(new Dictionary(), (properties, token) => + { + properties.Add(token.Path.ToLowerInvariant(), token.ToString()); + return properties; + }); + + foreach (var translation in translationItems) + { + items[translation.Key] = translation.Value; + } + + return items; } - public interface IZeroVue + IList CreateIconSets() { - /// - /// Creates the zero configuration for vue - /// - Task Config(); + List result = new(); + IEnumerable sets = Options.For().IconSets; - ///// - ///// Creates the zero configuration for vue - ///// - //Task> Translations(); + StringBuilder svg = new(); - ///// - ///// Creates the zero configuration for vue - ///// - //Task IconSets(); + foreach (BackofficeIconSet set in sets) + { + string path = Paths.Map(set.SpritePath.TrimStart('/')); - /// - /// Creates the zero configuration for vue - /// - Task ConfigAsJson(); + if (!File.Exists(path)) + { + Logger.LogWarning("Could not load icon set {alias} from path {path}", set.Alias, path); + continue; + } - /// - /// Get SVG for icon sets - /// - string GetIconSvg(); + string svgContent = File.ReadAllText(path, Encoding.UTF8); + XDocument xml = XDocument.Parse(svgContent); + IEnumerable symbols = xml.Descendants().Where(x => x.Name.LocalName == "symbol"); // ("symbol"); + + if (!symbols.Any()) + { + Logger.LogWarning("Icon set {alias} does not contain any ", set.Alias); + continue; + } + + ZeroVueIconSet iconSet = new() + { + Alias = set.Alias, + Name = set.Name, + Prefix = set.Prefix + }; + + foreach (XElement symbol in symbols) + { + string symbolAlias = set.Prefix + "-" + symbol.Attribute("id").Value.ToString(); + symbol.SetAttributeValue("id", symbolAlias); + svg.Append(symbol.ToString().RemoveNewLines()); + iconSet.Icons.Add(symbolAlias); + } + + result.Add(iconSet); + } + + IconSymbolsSvg = svg.ToString(); + + return result; } - public class ZeroVueConfig + List CreateBlueprints() { - public string Path { get; set; } + List items = new(); - public string ApiPath { get; set; } + if (!Options.For().Enabled) + { + return items; + } - public string PluginPath { get; set; } + foreach (Blueprint blueprint in Options.For()) + { + string[] unlocked = blueprint.GetUnlockedFieldNames().ToArray(); - public IList Plugins { get; set; } = new List(); + items.Add(new() + { + Alias = blueprint.Alias, + Enabled = true, + Unlocked = unlocked + }); + } - public string Version { get; set; } - - public int PluginCount { get; set; } - - public string ErrorFieldNone { get; set; } - - public string AppId { get; set; } - - public bool MultiApps { get; set; } - - public UserEditModel User { get; set; } - - public IList Sections { get; set; } = new List(); - - public IList Applications { get; set; } = new List(); - - public IList SettingsAreas { get; set; } = new List(); - - public Dictionary> Alias { get; set; } = new Dictionary>(); - - public Dictionary Translations { get; set; } = new Dictionary(); - - public Dictionary Overrides { get; set; } = new Dictionary(); - - public IList Icons { get; set; } = new List(); - - public ZeroVueServices Services { get; set; } = new(); - - public IList Blueprints { get; set; } = new List(); - } - - - public class ZeroVueSection - { - public string Alias { get; set; } - - public string Name { get; set; } - - public string Icon { get; set; } - - public string Color { get; set; } - - public string Url { get; set; } - - public bool IsExternal { get; set; } - - public IList Children { get; set; } - } - - - public class ZeroVuePlugin - { - public string Name { get; set; } - - public string Description { get; set; } - - public string PluginPath { get; set; } - } - - - public class ZeroVueSettingsGroup - { - public string Name { get; set; } - - public IList Items { get; set; } - } - - - public class ZeroVueSettingsArea - { - public string Alias { get; set; } - - public string Name { get; set; } - - public string Description { get; set; } - - public string Icon { get; set; } - - public string Url { get; set; } - - public bool IsPlugin { get; set; } - } - - - public class ZeroVueApplication - { - public string Id { get; set; } - - public string Name { get; set; } - - public string Image { get; set; } - } - - public class ZeroVueIconSet - { - public string Alias { get; set; } - - public string Name { get; set; } - - public string Prefix { get; set; } - - public HashSet Icons { get; set; } = new(); - } - - public class ZeroVueServices - { - public string YouTubeApiKey { get; set; } - } - - public class ZeroVueBlueprint - { - public string Alias { get; set; } - - public bool Enabled { get; set; } - - public string[] Unlocked { get; set; } = Array.Empty(); + return items; } } + + +public interface IZeroVue +{ + /// + /// Creates the zero configuration for vue + /// + Task Config(); + + ///// + ///// Creates the zero configuration for vue + ///// + //Task> Translations(); + + ///// + ///// Creates the zero configuration for vue + ///// + //Task IconSets(); + + /// + /// Creates the zero configuration for vue + /// + Task ConfigAsJson(); + + /// + /// Get SVG for icon sets + /// + string GetIconSvg(); +} + + +public class ZeroVueConfig +{ + public string Path { get; set; } + + public string ApiPath { get; set; } + + public string PluginPath { get; set; } + + public IList Plugins { get; set; } = new List(); + + public string Version { get; set; } + + public int PluginCount { get; set; } + + public string ErrorFieldNone { get; set; } + + public string AppId { get; set; } + + public bool MultiApps { get; set; } + + public dynamic User { get; set; } + + public IList Sections { get; set; } = new List(); + + public IList Applications { get; set; } = new List(); + + public IList SettingsAreas { get; set; } = new List(); + + public Dictionary> Alias { get; set; } = new Dictionary>(); + + public Dictionary Translations { get; set; } = new Dictionary(); + + public Dictionary Overrides { get; set; } = new Dictionary(); + + public IList Icons { get; set; } = new List(); + + public ZeroVueServices Services { get; set; } = new(); + + public IList Blueprints { get; set; } = new List(); +} + + +public class ZeroVueSection +{ + public string Alias { get; set; } + + public string Name { get; set; } + + public string Icon { get; set; } + + public string Color { get; set; } + + public string Url { get; set; } + + public bool IsExternal { get; set; } + + public IList Children { get; set; } +} + + +public class ZeroVuePlugin +{ + public string Name { get; set; } + + public string Description { get; set; } + + public string PluginPath { get; set; } +} + + +public class ZeroVueSettingsGroup +{ + public string Name { get; set; } + + public IList Items { get; set; } +} + + +public class ZeroVueSettingsArea +{ + public string Alias { get; set; } + + public string Name { get; set; } + + public string Description { get; set; } + + public string Icon { get; set; } + + public string Url { get; set; } + + public bool IsPlugin { get; set; } +} + + +public class ZeroVueApplication +{ + public string Id { get; set; } + + public string Name { get; set; } + + public string Image { get; set; } +} + +public class ZeroVueIconSet +{ + public string Alias { get; set; } + + public string Name { get; set; } + + public string Prefix { get; set; } + + public HashSet Icons { get; set; } = new(); +} + +public class ZeroVueServices +{ + public string YouTubeApiKey { get; set; } +} + +public class ZeroVueBlueprint +{ + public string Alias { get; set; } + + public bool Enabled { get; set; } + + public string[] Unlocked { get; set; } = Array.Empty(); +} \ No newline at end of file diff --git a/zero.Backoffice/zero.Backoffice.csproj b/zero.Backoffice/zero.Backoffice.csproj index 1dfbad92..021cdec6 100644 --- a/zero.Backoffice/zero.Backoffice.csproj +++ b/zero.Backoffice/zero.Backoffice.csproj @@ -8,6 +8,12 @@ true + + + + + + @@ -19,4 +25,8 @@ + + + + \ No newline at end of file