diff --git a/zero.Core/Api/LanguagesApi.cs b/zero.Core/Api/LanguagesApi.cs deleted file mode 100644 index 3eb321e8..00000000 --- a/zero.Core/Api/LanguagesApi.cs +++ /dev/null @@ -1,131 +0,0 @@ -using FluentValidation; -using Raven.Client.Documents; -using Raven.Client.Documents.Linq; -using Raven.Client.Documents.Session; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Entities; -using zero.Core.Extensions; - -namespace zero.Core.Api -{ - public class LanguagesApi : BackofficeApi, ILanguagesApi - { - IValidator Validator; - - - public LanguagesApi(IBackofficeStore store, IValidator validator) : base(store) - { - Validator = validator; - } - - - /// - public async Task GetById(string id) - { - return await GetById(id); - } - - - /// - public async Task> GetByIds(params string[] ids) - { - return await GetByIds(ids); - } - - - /// - public async Task> GetAll() - { - using IAsyncDocumentSession session = Store.OpenAsyncSession(); - - return await session.Query() - .OrderByDescending(x => x.CreatedDate) - .ToListAsync(); - } - - - /// - public IList GetAllCultures(params string[] codes) - { - return CultureInfo.GetCultures(CultureTypes.AllCultures) - .Where(x => !x.Name.IsNullOrWhiteSpace()) - .Select(x => new CultureInfo(x.Name)) - .Where(x => codes.Length > 0 ? codes.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase) : true) - .OrderBy(x => x.DisplayName) - .Select(x => new Culture() - { - Code = x.Name, - Name = x.DisplayName - }) - .ToList(); - } - - - /// - public async Task> GetByQuery(ListQuery query) - { - query.SearchFor(entity => entity.Name); - - using IAsyncDocumentSession session = Store.OpenAsyncSession(); - - return await session.Query().ToQueriedListAsync(query); - } - - - /// - public async Task> Save(ILanguage model) - { - return await SaveModel(model, Validator); - } - - - /// - public async Task> Delete(string id) - { - return await DeleteById(id); - } - } - - - public interface ILanguagesApi - { - /// - /// Get language by Id - /// - Task GetById(string id); - - /// - /// Get countries by ids - /// - Task> GetByIds(params string[] ids); - - /// - /// Get all available languages - /// - Task> GetAll(); - - /// - /// Get all available cultures - /// - IList GetAllCultures(params string[] codes); - - /// - /// Get all available languages (with query) - /// - Task> GetByQuery(ListQuery query); - - /// - /// Creates or updates a language - /// - Task> Save(ILanguage model); - - /// - /// Deletes a language by Id - /// - Task> Delete(string id); - } -} diff --git a/zero.Core/Api/MailTemplatesApi.cs b/zero.Core/Api/MailTemplatesApi.cs deleted file mode 100644 index da7c70db..00000000 --- a/zero.Core/Api/MailTemplatesApi.cs +++ /dev/null @@ -1,122 +0,0 @@ -using FluentValidation; -using Raven.Client.Documents; -using Raven.Client.Documents.Session; -using System.Collections.Generic; -using System.Threading.Tasks; -using zero.Core.Api; -using zero.Core.Entities; -using zero.Core.Extensions; - -namespace zero.Core.Api -{ - public class MailTemplatesApi : BackofficeApi, IMailTemplatesApi - { - protected IValidator Validator { get; private set; } - - public MailTemplatesApi(IBackofficeStore store, IValidator validator) : base(store) - { - Validator = validator; - } - - - - /// - public async Task GetById(string id) - { - return await GetById(id); - } - - - /// - public async Task GetByKey(string key) - { - using IAsyncDocumentSession session = Store.OpenAsyncSession(); - return await session.Query().FirstOrDefaultAsync(x => x.Key == key); - } - - - /// - public async Task> GetByIds(params string[] ids) - { - return await GetByIds(ids); - } - - - /// - /// Get all available currencies - /// - public async Task> GetAll() - { - using (IAsyncDocumentSession session = Store.OpenAsyncSession()) - { - return await session.Query().ToListAsync(); - } - } - - - /// - public async Task> GetByQuery(ListQuery query) - { - query.SearchSelector = entity => entity.Name; - - using (IAsyncDocumentSession session = Store.OpenAsyncSession()) - { - return await session.Query() - .ToQueriedListAsync(query); - } - } - - - /// - public async Task> Save(IMailTemplate model) - { - return await SaveModel(model, Validator); - } - - - /// - public async Task> Delete(string id) - { - return await DeleteById(id); - } - } - - - public interface IMailTemplatesApi - { - /// - /// Get mail template by id - /// - Task GetById(string id); - - /// - /// Get mail template by associated key - /// - Task GetByKey(string key); - - /// - /// Get mail templates by ids - /// - Task> GetByIds(params string[] ids); - - /// - /// Get all available mail templates - /// - Task> GetAll(); - - /// - /// Get all available mail templates (with query) - /// - Task> GetByQuery(ListQuery query); - - /// - /// Creates or updates a mail template - /// - Task> Save(IMailTemplate model); - - /// - /// Deletes a mail template by id - /// - Task> Delete(string id); - } -} diff --git a/zero.Core/Api/TranslationsApi.cs b/zero.Core/Api/TranslationsApi.cs deleted file mode 100644 index fa6680ea..00000000 --- a/zero.Core/Api/TranslationsApi.cs +++ /dev/null @@ -1,103 +0,0 @@ -using FluentValidation; -using Raven.Client.Documents; -using Raven.Client.Documents.Linq; -using Raven.Client.Documents.Session; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using zero.Core.Entities; -using zero.Core.Extensions; - -namespace zero.Core.Api -{ - public class TranslationsApi : BackofficeApi, ITranslationsApi - { - IValidator Validator; - - - public TranslationsApi(IBackofficeStore store, IValidator validator) : base(store) - { - Validator = validator; - } - - - /// - public async Task GetStringById(string id) - { - return (await GetById(id))?.Value; - } - - - /// - public async Task GetById(string id) - { - return await GetById(id); - } - - - /// - public async Task> GetAll() - { - using IAsyncDocumentSession session = Store.OpenAsyncSession(); - return await session.Query().OrderByDescending(x => x.CreatedDate).ToListAsync(); - } - - - /// - public async Task> GetByQuery(ListQuery query) - { - query.SearchFor(entity => entity.Key, entity => entity.Value); - - using IAsyncDocumentSession session = Store.OpenAsyncSession(); - return await session.Query().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); - } - - - /// - public async Task> Save(ITranslation model) - { - return await SaveModel(model, Validator); - } - - - /// - public async Task> Delete(string id) - { - return await DeleteById(id); - } - } - - - public interface ITranslationsApi - { - /// - /// Get translation by id - /// - Task GetById(string id); - - /// - /// Get a translated string by id - /// - Task GetStringById(string id); - - /// - /// Get all available translations - /// - Task> GetAll(); - - /// - /// Get all available translations (with query) - /// - Task> GetByQuery(ListQuery query); - - /// - /// Creates or updates a translation - /// - Task> Save(ITranslation model); - - /// - /// Deletes a translation by id - /// - Task> Delete(string id); - } -} diff --git a/zero.Core/Collections/CollectionBase.cs b/zero.Core/Collections/CollectionBase.cs index e900d6b9..d11d9512 100644 --- a/zero.Core/Collections/CollectionBase.cs +++ b/zero.Core/Collections/CollectionBase.cs @@ -127,7 +127,7 @@ namespace zero.Core.Collections /// public virtual async Task> GetByQuery(ListQuery query) { - return await Session.Query().ToQueriedListAsync(query); + return await Session.Query().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); } diff --git a/zero.Core/Validation/LanguageValidator.cs b/zero.Core/Collections/Languages/LanguageValidator.cs similarity index 95% rename from zero.Core/Validation/LanguageValidator.cs rename to zero.Core/Collections/Languages/LanguageValidator.cs index 2a1b9c37..e7f6d215 100644 --- a/zero.Core/Validation/LanguageValidator.cs +++ b/zero.Core/Collections/Languages/LanguageValidator.cs @@ -3,8 +3,9 @@ using System; using zero.Core.Api; using zero.Core.Entities; using zero.Core.Extensions; +using zero.Core.Validation; -namespace zero.Core.Validation +namespace zero.Core.Collections { public class LanguageValidator : ZeroValidator { diff --git a/zero.Core/Collections/Languages/LanguagesCollection.cs b/zero.Core/Collections/Languages/LanguagesCollection.cs new file mode 100644 index 00000000..591612e1 --- /dev/null +++ b/zero.Core/Collections/Languages/LanguagesCollection.cs @@ -0,0 +1,50 @@ +using FluentValidation; +using Raven.Client.Documents; +using Raven.Client.Documents.Linq; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using zero.Core.Entities; +using zero.Core.Extensions; + +namespace zero.Core.Collections +{ + public class LanguagesCollection : CollectionBase, ILanguagesCollection + { + public LanguagesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + + + /// + public override IAsyncEnumerable Stream() + { + return base.Stream(q => q.OrderByDescending(x => x.CreatedDate)); + } + + + /// + public IList GetAllCultures(params string[] codes) + { + return CultureInfo.GetCultures(CultureTypes.AllCultures) + .Where(x => !x.Name.IsNullOrWhiteSpace()) + .Select(x => new CultureInfo(x.Name)) + .Where(x => codes.Length > 0 ? codes.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase) : true) + .OrderBy(x => x.DisplayName) + .Select(x => new Culture() + { + Code = x.Name, + Name = x.DisplayName + }) + .ToList(); + } + } + + + public interface ILanguagesCollection : ICollectionBase + { + /// + /// Get all available cultures + /// + IList GetAllCultures(params string[] codes); + } +} diff --git a/zero.Core/Validation/MailTemplateValidator.cs b/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs similarity index 60% rename from zero.Core/Validation/MailTemplateValidator.cs rename to zero.Core/Collections/MailTemplates/MailTemplateValidator.cs index a481e72e..6a641afa 100644 --- a/zero.Core/Validation/MailTemplateValidator.cs +++ b/zero.Core/Collections/MailTemplates/MailTemplateValidator.cs @@ -1,7 +1,7 @@ -using FluentValidation; -using zero.Core.Entities; +using zero.Core.Entities; +using zero.Core.Validation; -namespace zero.Core.Validation +namespace zero.Core.Collections { public class MailTemplateValidator : ZeroValidator { diff --git a/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs b/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs new file mode 100644 index 00000000..d02f415e --- /dev/null +++ b/zero.Core/Collections/MailTemplates/MailTemplatesCollection.cs @@ -0,0 +1,28 @@ +using FluentValidation; +using Raven.Client.Documents; +using System.Threading.Tasks; +using zero.Core.Entities; + +namespace zero.Core.Collections +{ + public class MailTemplatesCollection : CollectionBase, IMailTemplatesCollection + { + public MailTemplatesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + + + /// + public async Task GetByKey(string key) + { + return await Query.FirstOrDefaultAsync(x => x.Key == key); + } + } + + + public interface IMailTemplatesCollection : ICollectionBase + { + /// + /// Get mail template by associated key + /// + Task GetByKey(string key); + } +} diff --git a/zero.Core/Validation/TranslationValidator.cs b/zero.Core/Collections/Translations/TranslationValidator.cs similarity index 85% rename from zero.Core/Validation/TranslationValidator.cs rename to zero.Core/Collections/Translations/TranslationValidator.cs index ebaaff94..00be69eb 100644 --- a/zero.Core/Validation/TranslationValidator.cs +++ b/zero.Core/Collections/Translations/TranslationValidator.cs @@ -2,8 +2,9 @@ using zero.Core.Api; using zero.Core.Entities; using zero.Core.Extensions; +using zero.Core.Validation; -namespace zero.Core.Validation +namespace zero.Core.Collections { public class TranslationValidator : ZeroValidator { diff --git a/zero.Core/Collections/Translations/TranslationsCollection.cs b/zero.Core/Collections/Translations/TranslationsCollection.cs new file mode 100644 index 00000000..678e65ed --- /dev/null +++ b/zero.Core/Collections/Translations/TranslationsCollection.cs @@ -0,0 +1,36 @@ +using FluentValidation; +using Raven.Client.Documents; +using Raven.Client.Documents.Linq; +using System.Collections.Generic; +using System.Threading.Tasks; +using zero.Core.Entities; + +namespace zero.Core.Collections +{ + public class TranslationsCollection : CollectionBase, ITranslationsCollection + { + public TranslationsCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator validator) : base(context, interceptor, validator) { } + + + /// + public async Task GetStringById(string id) + { + return (await GetById(id))?.Value; + } + + /// + public override IAsyncEnumerable Stream() + { + return base.Stream(q => q.OrderByDescending(x => x.Name)); + } + } + + + public interface ITranslationsCollection : ICollectionBase + { + /// + /// Get a translated string by id + /// + Task GetStringById(string id); + } +} diff --git a/zero.Core/Mails/MailSender.cs b/zero.Core/Mails/MailSender.cs index 0e0cbf9f..4341a877 100644 --- a/zero.Core/Mails/MailSender.cs +++ b/zero.Core/Mails/MailSender.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using zero.Core.Api; +using zero.Core.Collections; using zero.Core.Entities; using zero.Core.Extensions; @@ -12,7 +13,7 @@ namespace zero.Core.Mails { public class MailSender : IMailSender { - protected IMailTemplatesApi TemplatesApi { get; set; } + protected IMailTemplatesCollection Collection { get; set; } protected SmtpClient Client { get; set; } @@ -23,10 +24,10 @@ namespace zero.Core.Mails private Encoding encoding = Encoding.UTF8; - public MailSender(IZeroContext zero, IMailTemplatesApi templatesApi, ILogger logger) + public MailSender(IZeroContext zero, IMailTemplatesCollection collection, ILogger logger) { Zero = zero; - TemplatesApi = templatesApi; + Collection = collection; Logger = logger; Client = new SmtpClient(); } @@ -114,7 +115,7 @@ namespace zero.Core.Mails /// protected virtual async Task GetMailTemplate(string key) { - return await TemplatesApi.GetByKey(key); + return await Collection.GetByKey(key); } } } diff --git a/zero.Web.UI/App/components/overlays/confirm.vue b/zero.Web.UI/App/components/overlays/confirm.vue index 2c64a458..4b564da4 100644 --- a/zero.Web.UI/App/components/overlays/confirm.vue +++ b/zero.Web.UI/App/components/overlays/confirm.vue @@ -51,12 +51,14 @@ if (!errors) { - instance.$refs.error.clear(); + instance.$refs.error.clearErrors(); } else { - instance.$refs.error.set(errors); + instance.$refs.error.setErrors(errors); } + + setTimeout(() => instance.state = 'default', 1500); }, success: true }); diff --git a/zero.Web.UI/App/components/tables/table.vue b/zero.Web.UI/App/components/tables/table.vue index 730394c8..4f1129bb 100644 --- a/zero.Web.UI/App/components/tables/table.vue +++ b/zero.Web.UI/App/components/tables/table.vue @@ -3,7 +3,7 @@
- {{ column.label | localize }} + diff --git a/zero.Web.UI/App/renderers/lists/countries.js b/zero.Web.UI/App/renderers/lists/countries.js index a8868577..778eb9dd 100644 --- a/zero.Web.UI/App/renderers/lists/countries.js +++ b/zero.Web.UI/App/renderers/lists/countries.js @@ -8,7 +8,7 @@ const prefix = '@country.fields.'; list.templateLabel = x => prefix + x; list.link = zero.alias.settings.countries + '-edit'; -list.onFetch(filter => CountriesApi.getAll(filter)); +list.onFetch(filter => CountriesApi.getByQuery(filter)); list.column('flag', { width: 62, canSort: false, hideLabel: true }).custom((value, model) => ``, true, 'flag'); list.column('name').name(); diff --git a/zero.Web.UI/App/renderers/lists/languages.js b/zero.Web.UI/App/renderers/lists/languages.js index 3cf726bb..b69a62db 100644 --- a/zero.Web.UI/App/renderers/lists/languages.js +++ b/zero.Web.UI/App/renderers/lists/languages.js @@ -8,7 +8,7 @@ const prefix = '@language.fields.'; list.templateLabel = x => prefix + x; list.link = zero.alias.settings.languages + '-edit'; -list.onFetch(filter => LanguagesApi.getAll(filter)); +list.onFetch(filter => LanguagesApi.getByQuery(filter)); list.column('name').name(); list.column('code').text(); diff --git a/zero.Web.UI/App/renderers/lists/mails.js b/zero.Web.UI/App/renderers/lists/mails.js index e5ec072a..0b6ce4d3 100644 --- a/zero.Web.UI/App/renderers/lists/mails.js +++ b/zero.Web.UI/App/renderers/lists/mails.js @@ -7,7 +7,7 @@ const list = new List('mailTemplates'); list.templateLabel = x => '@mailTemplate.fields.' + x; list.link = zero.alias.settings.mails + '-edit'; -list.onFetch(filter => MailTemplatesApi.getAll(filter)); +list.onFetch(filter => MailTemplatesApi.getByQuery(filter)); list.column('name').name(); list.column('subject').text(); diff --git a/zero.Web.UI/App/renderers/lists/translations.js b/zero.Web.UI/App/renderers/lists/translations.js index 08f996a9..9ad54182 100644 --- a/zero.Web.UI/App/renderers/lists/translations.js +++ b/zero.Web.UI/App/renderers/lists/translations.js @@ -8,7 +8,7 @@ const prefix = '@translation.fields.'; list.templateLabel = x => prefix + x; list.link = zero.alias.settings.translations + '-edit'; -list.onFetch(filter => TranslationsApi.getAll(filter)); +list.onFetch(filter => TranslationsApi.getByQuery(filter)); list.column('key').name(); list.column('value').text(); diff --git a/zero.Web.UI/App/resources/languages.js b/zero.Web.UI/App/resources/languages.js index d72a7951..da637a7d 100644 --- a/zero.Web.UI/App/resources/languages.js +++ b/zero.Web.UI/App/resources/languages.js @@ -20,6 +20,12 @@ export default { return Axios.get('languages/getAll').then(res => Promise.resolve(res.data)); }, + // get all languages + getByQuery(query) + { + return Axios.get('languages/getByQuery', { params: query }).then(res => Promise.resolve(res.data)); + }, + // get all available cultures getAllCultures() { diff --git a/zero.Web.UI/App/resources/mailTemplates.js b/zero.Web.UI/App/resources/mailTemplates.js index 646339ae..bff60710 100644 --- a/zero.Web.UI/App/resources/mailTemplates.js +++ b/zero.Web.UI/App/resources/mailTemplates.js @@ -14,6 +14,11 @@ export default { return Axios.get(base + 'getEmpty').then(res => Promise.resolve(res.data)); }, + getByQuery(query) + { + return Axios.get(base + 'getByQuery', { params: query }).then(res => Promise.resolve(res.data)); + }, + getAll(query) { return Axios.get(base + 'getAll', query ? { params: { query } } : undefined).then(res => Promise.resolve(res.data)); diff --git a/zero.Web.UI/App/resources/translations.js b/zero.Web.UI/App/resources/translations.js index 5fa723e7..6349609d 100644 --- a/zero.Web.UI/App/resources/translations.js +++ b/zero.Web.UI/App/resources/translations.js @@ -14,6 +14,12 @@ export default { return Axios.get('translations/getEmpty').then(res => Promise.resolve(res.data)); }, + // get all translations + getByQuery(query) + { + return Axios.get('translations/getByQuery', { params: query }).then(res => Promise.resolve(res.data)); + }, + // get all translations getAll(query) { diff --git a/zero.Web.UI/app/core/list-column.ts b/zero.Web.UI/app/core/list-column.ts index 7db886e2..1c06a62b 100644 --- a/zero.Web.UI/app/core/list-column.ts +++ b/zero.Web.UI/app/core/list-column.ts @@ -156,7 +156,7 @@ class ListColumn this.#type = 'boolean'; this.#asHtml = true; this.#funcOptions = { colored: false, ...options }; - this.#func = (value, opts) => ''; + this.#func = (value, opts) => ''; return this; } diff --git a/zero.Web.UI/app/core/list.ts b/zero.Web.UI/app/core/list.ts index 7e05bb7b..a5882a96 100644 --- a/zero.Web.UI/app/core/list.ts +++ b/zero.Web.UI/app/core/list.ts @@ -73,8 +73,18 @@ class List */ column(path, options) { - const column = new ListColumn(path, options); - this.columns.push(column); + let column = this.columns.find(x => x.path === path); + + if (!column) + { + column = new ListColumn(path, options); + this.columns.push(column); + } + else + { + column.options = { ...column.options, ...(options || {}) }; + } + return column; } diff --git a/zero.Web/Controllers/BackofficeCollectionController.cs b/zero.Web/Controllers/BackofficeCollectionController.cs new file mode 100644 index 00000000..4c6e97e2 --- /dev/null +++ b/zero.Web/Controllers/BackofficeCollectionController.cs @@ -0,0 +1,66 @@ +using Microsoft.AspNetCore.Mvc; +using Raven.Client.Documents.Linq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using zero.Core.Collections; +using zero.Core.Entities; +using zero.Core.Extensions; +using zero.Web.Models; + + +namespace zero.Web.Controllers +{ + public abstract class BackofficeCollectionController : BackofficeController + where TEntity : IZeroEntity + where TCollection : ICollectionBase + { + protected TCollection Collection { get; private set; } + + protected Func, IRavenQueryable> DefaultQuery { get; set; } + + protected Action PreviewTransform { get; set; } + + + public BackofficeCollectionController(TCollection collection) + { + Collection = collection; + } + + public override void OnScopeChanged(string scope) + { + Collection.ApplyScope(scope); + } + + + public virtual async Task> GetById([FromQuery] string id) => Edit(await Collection.GetById(id)); + + + public virtual EditModel GetEmpty([FromServices] TEntity blueprint) => Edit(blueprint); + + + public virtual async Task> GetByQuery([FromQuery] ListQuery query) + { + query.SearchSelector = model => model.Name; + IRavenQueryable ravenQuery = Collection.Query; + if (DefaultQuery != null) + { + ravenQuery = DefaultQuery(ravenQuery); + } + + return await ravenQuery.ToQueriedListAsync(query); + } + + + public virtual async Task> GetForPicker() => await SelectList(Collection.Stream()); + + + public virtual async Task> GetPreviews([FromQuery] List ids) => Previews(await Collection.GetByIds(ids.ToArray()), PreviewTransform); + + + public virtual async Task> Save([FromBody] TEntity model) => await Collection.Save(model); + + + public virtual async Task> Delete([FromQuery] string id) => await Collection.DeleteById(id); + } +} diff --git a/zero.Web/Controllers/CountriesController.cs b/zero.Web/Controllers/CountriesController.cs index d7da9680..074eac63 100644 --- a/zero.Web/Controllers/CountriesController.cs +++ b/zero.Web/Controllers/CountriesController.cs @@ -1,58 +1,18 @@ -using Microsoft.AspNetCore.Mvc; -using Raven.Client.Documents.Linq; -using System.Collections.Generic; -using System.Threading.Tasks; +using Raven.Client.Documents.Linq; using zero.Core.Collections; using zero.Core.Entities; using zero.Core.Extensions; using zero.Core.Identity; -using zero.Web.Models; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Read)] - public class CountriesController : BackofficeController + public class CountriesController : BackofficeCollectionController { - ICountriesCollection Service; - - public CountriesController(ICountriesCollection service) + public CountriesController(ICountriesCollection collection) : base(collection) { - Service = service; + DefaultQuery = q => q.OrderByDescending(x => x.IsPreferred).ThenBy(x => x.Name); + PreviewTransform = (item, model) => model.Icon = "flag flag-" + item.Code.ToLowerInvariant(); } - - public override void OnScopeChanged(string scope) - { - Service.ApplyScope(scope); - } - - - public async Task> GetById([FromQuery] string id) => Edit(await Service.GetById(id)); - - - public EditModel GetEmpty([FromServices] ICountry blueprint) => Edit(blueprint); - - - public async Task> GetByQuery([FromQuery] ListQuery query) - { - query.SearchSelector = country => country.Name; - return await Service.Query.OrderByDescending(x => x.IsPreferred).ThenBy(x => x.Name).ToQueriedListAsync(query); - } - - - public async Task> GetForPicker() => await SelectList(Service.Stream()); - - - public async Task> GetPreviews([FromQuery] List ids) - { - return Previews(await Service.GetByIds(ids.ToArray()), (item, model) => model.Icon = "flag flag-" + item.Code.ToLowerInvariant()); - } - - - [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Update)] - public async Task> Save([FromBody] ICountry model) => await Service.Save(model); - - - [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Service.DeleteById(id); } } diff --git a/zero.Web/Controllers/LanguagesController.cs b/zero.Web/Controllers/LanguagesController.cs index 4f775745..fdfd84ea 100644 --- a/zero.Web/Controllers/LanguagesController.cs +++ b/zero.Web/Controllers/LanguagesController.cs @@ -1,64 +1,17 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Api; +using Raven.Client.Documents.Linq; +using zero.Core.Collections; using zero.Core.Entities; using zero.Core.Identity; -using zero.Web.Models; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Read)] - public class LanguagesController : BackofficeController + public class LanguagesController : BackofficeCollectionController { - ILanguagesApi Api; - - public LanguagesController(ILanguagesApi api) + public LanguagesController(ILanguagesCollection collection) : base(collection) { - Api = api; + DefaultQuery = q => q.OrderByDescending(x => x.CreatedDate); + PreviewTransform = (item, model) => model.Icon = "fth-globe"; } - - - public EditModel GetEmpty([FromServices] ILanguage blueprint) => Edit(blueprint); - - - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - - - public async Task> GetAll([FromQuery] ListQuery query) => await Api.GetByQuery(query); - - - public IList GetAllCultures() => Api.GetAllCultures(); - - - public IList GetSupportedCultures() => Api.GetAllCultures(Options.SupportedLanguages); - - - public async Task> GetForPicker() => (await Api.GetAll()).Select(x => new SelectModel() - { - Id = x.Id, - Name = x.Name, - IsActive = x.IsActive - }); - - - public async Task> GetPreviews([FromQuery] List ids) - { - return Previews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel() - { - Id = item.Id, - Icon = "fth-globe", - Name = item.Name - }); - } - - - [ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)] - public async Task> Save([FromBody] ILanguage model) => await Api.Save(model); - - - [ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/MailTemplatesController.cs b/zero.Web/Controllers/MailTemplatesController.cs index e601c916..7b114491 100644 --- a/zero.Web/Controllers/MailTemplatesController.cs +++ b/zero.Web/Controllers/MailTemplatesController.cs @@ -1,50 +1,15 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Api; -using zero.Core; +using zero.Core.Collections; using zero.Core.Entities; -using zero.Web.Controllers; -using zero.Web.Models; +using zero.Core.Identity; -namespace zero.Commerce.Backoffice +namespace zero.Web.Controllers { - public class MailTemplatesController : BackofficeController + [ZeroAuthorize(Permissions.Settings.Mails, PermissionsValue.Read)] + public class MailTemplatesController : BackofficeCollectionController { - IMailTemplatesApi Api; - - public MailTemplatesController(IMailTemplatesApi api) + public MailTemplatesController(IMailTemplatesCollection collection) : base(collection) { - Api = api; + PreviewTransform = (item, model) => model.Icon = "fth-mail"; } - - - public EditModel GetEmpty([FromServices] IMailTemplate blueprint) => Edit(blueprint); - - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - - public async Task> GetAll([FromQuery] ListQuery query) => await Api.GetByQuery(query); - - public async Task> GetForPicker() => (await Api.GetAll()).Select(x => new SelectModel() - { - Id = x.Id, - Name = x.Name, - IsActive = x.IsActive - }); - - - public async Task> GetPreviews([FromQuery] List ids) => Previews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel() - { - Id = item.Id, - Icon = "fth-mail", - Name = item.Name - }); - - - public async Task> Save([FromBody] IMailTemplate model) => await Api.Save(model); - - - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); } } diff --git a/zero.Web/Controllers/TranslationsController.cs b/zero.Web/Controllers/TranslationsController.cs index 9840d5e9..78f569db 100644 --- a/zero.Web/Controllers/TranslationsController.cs +++ b/zero.Web/Controllers/TranslationsController.cs @@ -1,37 +1,25 @@ using Microsoft.AspNetCore.Mvc; +using Raven.Client.Documents.Linq; +using System.Linq; using System.Threading.Tasks; -using zero.Core.Api; +using zero.Core.Collections; using zero.Core.Entities; +using zero.Core.Extensions; using zero.Core.Identity; -using zero.Web.Models; namespace zero.Web.Controllers { [ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Read)] - public class TranslationsController : BackofficeController + public class TranslationsController : BackofficeCollectionController { - ITranslationsApi Api; - - public TranslationsController(ITranslationsApi api) + public TranslationsController(ITranslationsCollection collection) : base(collection) { - Api = api; } - - public EditModel GetEmpty([FromServices] ITranslation blueprint) => Edit(blueprint); - - - public async Task> GetById([FromQuery] string id) => Edit(await Api.GetById(id)); - - - public async Task> GetAll([FromQuery] ListQuery query) => await Api.GetByQuery(query); - - - [ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)] - public async Task> Save([FromBody] ITranslation model) => await Api.Save(model); - - - [ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)] - public async Task> Delete([FromQuery] string id) => await Api.Delete(id); + public override async Task> GetByQuery([FromQuery] ListQuery query) + { + query.SearchFor(entity => entity.Key, entity => entity.Value); + return await Collection.Query.OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); + } } } diff --git a/zero.Web/Defaults/ZeroBackofficePlugin.cs b/zero.Web/Defaults/ZeroBackofficePlugin.cs index c17295da..6d525347 100644 --- a/zero.Web/Defaults/ZeroBackofficePlugin.cs +++ b/zero.Web/Defaults/ZeroBackofficePlugin.cs @@ -72,13 +72,13 @@ namespace zero.Web.Defaults services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient();