create collections for translation, langauge, mails
This commit is contained in:
@@ -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<ILanguage> Validator;
|
||||
|
||||
|
||||
public LanguagesApi(IBackofficeStore store, IValidator<ILanguage> validator) : base(store)
|
||||
{
|
||||
Validator = validator;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ILanguage> GetById(string id)
|
||||
{
|
||||
return await GetById<ILanguage>(id);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<string, ILanguage>> GetByIds(params string[] ids)
|
||||
{
|
||||
return await GetByIds<ILanguage>(ids);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IList<ILanguage>> GetAll()
|
||||
{
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
|
||||
return await session.Query<ILanguage>()
|
||||
.OrderByDescending(x => x.CreatedDate)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public IList<Culture> 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();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ListResult<ILanguage>> GetByQuery(ListQuery<ILanguage> query)
|
||||
{
|
||||
query.SearchFor(entity => entity.Name);
|
||||
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
|
||||
return await session.Query<ILanguage>().ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<ILanguage>> Save(ILanguage model)
|
||||
{
|
||||
return await SaveModel(model, Validator);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<ILanguage>> Delete(string id)
|
||||
{
|
||||
return await DeleteById<ILanguage>(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ILanguagesApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Get language by Id
|
||||
/// </summary>
|
||||
Task<ILanguage> GetById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get countries by ids
|
||||
/// </summary>
|
||||
Task<Dictionary<string, ILanguage>> GetByIds(params string[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available languages
|
||||
/// </summary>
|
||||
Task<IList<ILanguage>> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Get all available cultures
|
||||
/// </summary>
|
||||
IList<Culture> GetAllCultures(params string[] codes);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available languages (with query)
|
||||
/// </summary>
|
||||
Task<ListResult<ILanguage>> GetByQuery(ListQuery<ILanguage> query);
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates a language
|
||||
/// </summary>
|
||||
Task<EntityResult<ILanguage>> Save(ILanguage model);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a language by Id
|
||||
/// </summary>
|
||||
Task<EntityResult<ILanguage>> Delete(string id);
|
||||
}
|
||||
}
|
||||
@@ -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<IMailTemplate> Validator { get; private set; }
|
||||
|
||||
public MailTemplatesApi(IBackofficeStore store, IValidator<IMailTemplate> validator) : base(store)
|
||||
{
|
||||
Validator = validator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IMailTemplate> GetById(string id)
|
||||
{
|
||||
return await GetById<IMailTemplate>(id);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IMailTemplate> GetByKey(string key)
|
||||
{
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
return await session.Query<IMailTemplate>().FirstOrDefaultAsync(x => x.Key == key);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<string, IMailTemplate>> GetByIds(params string[] ids)
|
||||
{
|
||||
return await GetByIds<IMailTemplate>(ids);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all available currencies
|
||||
/// </summary>
|
||||
public async Task<IList<IMailTemplate>> GetAll()
|
||||
{
|
||||
using (IAsyncDocumentSession session = Store.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<IMailTemplate>().ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ListResult<IMailTemplate>> GetByQuery(ListQuery<IMailTemplate> query)
|
||||
{
|
||||
query.SearchSelector = entity => entity.Name;
|
||||
|
||||
using (IAsyncDocumentSession session = Store.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<IMailTemplate>()
|
||||
.ToQueriedListAsync(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<IMailTemplate>> Save(IMailTemplate model)
|
||||
{
|
||||
return await SaveModel(model, Validator);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<IMailTemplate>> Delete(string id)
|
||||
{
|
||||
return await DeleteById<IMailTemplate>(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IMailTemplatesApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Get mail template by id
|
||||
/// </summary>
|
||||
Task<IMailTemplate> GetById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get mail template by associated key
|
||||
/// </summary>
|
||||
Task<IMailTemplate> GetByKey(string key);
|
||||
|
||||
/// <summary>
|
||||
/// Get mail templates by ids
|
||||
/// </summary>
|
||||
Task<Dictionary<string, IMailTemplate>> GetByIds(params string[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available mail templates
|
||||
/// </summary>
|
||||
Task<IList<IMailTemplate>> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Get all available mail templates (with query)
|
||||
/// </summary>
|
||||
Task<ListResult<IMailTemplate>> GetByQuery(ListQuery<IMailTemplate> query);
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates a mail template
|
||||
/// </summary>
|
||||
Task<EntityResult<IMailTemplate>> Save(IMailTemplate model);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a mail template by id
|
||||
/// </summary>
|
||||
Task<EntityResult<IMailTemplate>> Delete(string id);
|
||||
}
|
||||
}
|
||||
@@ -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<ITranslation> Validator;
|
||||
|
||||
|
||||
public TranslationsApi(IBackofficeStore store, IValidator<ITranslation> validator) : base(store)
|
||||
{
|
||||
Validator = validator;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetStringById(string id)
|
||||
{
|
||||
return (await GetById<ITranslation>(id))?.Value;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ITranslation> GetById(string id)
|
||||
{
|
||||
return await GetById<ITranslation>(id);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IList<ITranslation>> GetAll()
|
||||
{
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
return await session.Query<ITranslation>().OrderByDescending(x => x.CreatedDate).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ListResult<ITranslation>> GetByQuery(ListQuery<ITranslation> query)
|
||||
{
|
||||
query.SearchFor(entity => entity.Key, entity => entity.Value);
|
||||
|
||||
using IAsyncDocumentSession session = Store.OpenAsyncSession();
|
||||
return await session.Query<ITranslation>().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<ITranslation>> Save(ITranslation model)
|
||||
{
|
||||
return await SaveModel(model, Validator);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<EntityResult<ITranslation>> Delete(string id)
|
||||
{
|
||||
return await DeleteById<ITranslation>(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ITranslationsApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Get translation by id
|
||||
/// </summary>
|
||||
Task<ITranslation> GetById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get a translated string by id
|
||||
/// </summary>
|
||||
Task<string> GetStringById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available translations
|
||||
/// </summary>
|
||||
Task<IList<ITranslation>> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Get all available translations (with query)
|
||||
/// </summary>
|
||||
Task<ListResult<ITranslation>> GetByQuery(ListQuery<ITranslation> query);
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates a translation
|
||||
/// </summary>
|
||||
Task<EntityResult<ITranslation>> Save(ITranslation model);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a translation by id
|
||||
/// </summary>
|
||||
Task<EntityResult<ITranslation>> Delete(string id);
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace zero.Core.Collections
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<ListResult<T>> GetByQuery(ListQuery<T> query)
|
||||
{
|
||||
return await Session.Query<T>().ToQueriedListAsync(query);
|
||||
return await Session.Query<T>().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -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<ILanguage>
|
||||
{
|
||||
@@ -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<ILanguage>, ILanguagesCollection
|
||||
{
|
||||
public LanguagesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator<ILanguage> validator) : base(context, interceptor, validator) { }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IAsyncEnumerable<ILanguage> Stream()
|
||||
{
|
||||
return base.Stream(q => q.OrderByDescending(x => x.CreatedDate));
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public IList<Culture> 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<ILanguage>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all available cultures
|
||||
/// </summary>
|
||||
IList<Culture> GetAllCultures(params string[] codes);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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<IMailTemplate>
|
||||
{
|
||||
@@ -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<IMailTemplate>, IMailTemplatesCollection
|
||||
{
|
||||
public MailTemplatesCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator<IMailTemplate> validator) : base(context, interceptor, validator) { }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IMailTemplate> GetByKey(string key)
|
||||
{
|
||||
return await Query.FirstOrDefaultAsync(x => x.Key == key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IMailTemplatesCollection : ICollectionBase<IMailTemplate>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get mail template by associated key
|
||||
/// </summary>
|
||||
Task<IMailTemplate> GetByKey(string key);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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<ITranslation>
|
||||
{
|
||||
@@ -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<ITranslation>, ITranslationsCollection
|
||||
{
|
||||
public TranslationsCollection(IZeroContext context, ICollectionInterceptorHandler interceptor, IValidator<ITranslation> validator) : base(context, interceptor, validator) { }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetStringById(string id)
|
||||
{
|
||||
return (await GetById(id))?.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IAsyncEnumerable<ITranslation> Stream()
|
||||
{
|
||||
return base.Stream(q => q.OrderByDescending(x => x.Name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ITranslationsCollection : ICollectionBase<ITranslation>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a translated string by id
|
||||
/// </summary>
|
||||
Task<string> GetStringById(string id);
|
||||
}
|
||||
}
|
||||
@@ -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<IMailSender> logger)
|
||||
public MailSender(IZeroContext zero, IMailTemplatesCollection collection, ILogger<IMailSender> logger)
|
||||
{
|
||||
Zero = zero;
|
||||
TemplatesApi = templatesApi;
|
||||
Collection = collection;
|
||||
Logger = logger;
|
||||
Client = new SmtpClient();
|
||||
}
|
||||
@@ -114,7 +115,7 @@ namespace zero.Core.Mails
|
||||
/// <inheritdoc />
|
||||
protected virtual async Task<IMailTemplate> GetMailTemplate(string key)
|
||||
{
|
||||
return await TemplatesApi.GetByKey(key);
|
||||
return await Collection.GetByKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="ui-table" :class="{'is-inline': inline }">
|
||||
<header class="ui-table-row ui-table-head">
|
||||
<div v-for="column in columns" :key="column.path" class="ui-table-cell" :table-field="column.path" :style="column.flex" :class="column.options.class">
|
||||
{{ column.label | localize }}
|
||||
<span v-localize:html="column.label"></span>
|
||||
<button :disabled="!column.canSort" @click="sort(column)" type="button" class="ui-table-sort" :class="query.orderBy == column.path ? 'sort-' + (query.orderIsDescending ? 'desc' : 'asc') : null">
|
||||
<i class="arrow arrow-down"></i>
|
||||
</button>
|
||||
|
||||
@@ -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) => `<i class="flag flag-${model.code.toLowerCase()}"></i>`, true, 'flag');
|
||||
list.column('name').name();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -156,7 +156,7 @@ class ListColumn
|
||||
this.#type = 'boolean';
|
||||
this.#asHtml = true;
|
||||
this.#funcOptions = { colored: false, ...options };
|
||||
this.#func = (value, opts) => '<span class="ui-table-field-bool' + (value === true ? ' is-checked' : '') + (opts.colored ? ' is-colored' : '') + '"></span>';
|
||||
this.#func = (value, opts) => '<span class="ui-table-field-bool' + (!!value ? ' is-checked' : '') + (opts.colored ? ' is-colored' : '') + '"></span>';
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TEntity, TCollection> : BackofficeController
|
||||
where TEntity : IZeroEntity
|
||||
where TCollection : ICollectionBase<TEntity>
|
||||
{
|
||||
protected TCollection Collection { get; private set; }
|
||||
|
||||
protected Func<IRavenQueryable<TEntity>, IRavenQueryable<TEntity>> DefaultQuery { get; set; }
|
||||
|
||||
protected Action<TEntity, PreviewModel> PreviewTransform { get; set; }
|
||||
|
||||
|
||||
public BackofficeCollectionController(TCollection collection)
|
||||
{
|
||||
Collection = collection;
|
||||
}
|
||||
|
||||
public override void OnScopeChanged(string scope)
|
||||
{
|
||||
Collection.ApplyScope(scope);
|
||||
}
|
||||
|
||||
|
||||
public virtual async Task<EditModel<TEntity>> GetById([FromQuery] string id) => Edit(await Collection.GetById(id));
|
||||
|
||||
|
||||
public virtual EditModel<TEntity> GetEmpty([FromServices] TEntity blueprint) => Edit(blueprint);
|
||||
|
||||
|
||||
public virtual async Task<ListResult<TEntity>> GetByQuery([FromQuery] ListQuery<TEntity> query)
|
||||
{
|
||||
query.SearchSelector = model => model.Name;
|
||||
IRavenQueryable<TEntity> ravenQuery = Collection.Query;
|
||||
if (DefaultQuery != null)
|
||||
{
|
||||
ravenQuery = DefaultQuery(ravenQuery);
|
||||
}
|
||||
|
||||
return await ravenQuery.ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
public virtual async Task<IEnumerable<SelectModel>> GetForPicker() => await SelectList(Collection.Stream());
|
||||
|
||||
|
||||
public virtual async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> ids) => Previews(await Collection.GetByIds(ids.ToArray()), PreviewTransform);
|
||||
|
||||
|
||||
public virtual async Task<EntityResult<TEntity>> Save([FromBody] TEntity model) => await Collection.Save(model);
|
||||
|
||||
|
||||
public virtual async Task<EntityResult<TEntity>> Delete([FromQuery] string id) => await Collection.DeleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -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<ICountry, ICountriesCollection>
|
||||
{
|
||||
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<EditModel<ICountry>> GetById([FromQuery] string id) => Edit(await Service.GetById(id));
|
||||
|
||||
|
||||
public EditModel<ICountry> GetEmpty([FromServices] ICountry blueprint) => Edit(blueprint);
|
||||
|
||||
|
||||
public async Task<ListResult<ICountry>> GetByQuery([FromQuery] ListQuery<ICountry> query)
|
||||
{
|
||||
query.SearchSelector = country => country.Name;
|
||||
return await Service.Query.OrderByDescending(x => x.IsPreferred).ThenBy(x => x.Name).ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<SelectModel>> GetForPicker() => await SelectList(Service.Stream());
|
||||
|
||||
|
||||
public async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> 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<EntityResult<ICountry>> Save([FromBody] ICountry model) => await Service.Save(model);
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Update)]
|
||||
public async Task<EntityResult<ICountry>> Delete([FromQuery] string id) => await Service.DeleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ILanguage, ILanguagesCollection>
|
||||
{
|
||||
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<ILanguage> GetEmpty([FromServices] ILanguage blueprint) => Edit(blueprint);
|
||||
|
||||
|
||||
public async Task<EditModel<ILanguage>> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
||||
|
||||
|
||||
public async Task<ListResult<ILanguage>> GetAll([FromQuery] ListQuery<ILanguage> query) => await Api.GetByQuery(query);
|
||||
|
||||
|
||||
public IList<Culture> GetAllCultures() => Api.GetAllCultures();
|
||||
|
||||
|
||||
public IList<Culture> GetSupportedCultures() => Api.GetAllCultures(Options.SupportedLanguages);
|
||||
|
||||
|
||||
public async Task<IEnumerable<SelectModel>> GetForPicker() => (await Api.GetAll()).Select(x => new SelectModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
IsActive = x.IsActive
|
||||
});
|
||||
|
||||
|
||||
public async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> 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<EntityResult<ILanguage>> Save([FromBody] ILanguage model) => await Api.Save(model);
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)]
|
||||
public async Task<EntityResult<ILanguage>> Delete([FromQuery] string id) => await Api.Delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IMailTemplate, IMailTemplatesCollection>
|
||||
{
|
||||
IMailTemplatesApi Api;
|
||||
|
||||
public MailTemplatesController(IMailTemplatesApi api)
|
||||
public MailTemplatesController(IMailTemplatesCollection collection) : base(collection)
|
||||
{
|
||||
Api = api;
|
||||
PreviewTransform = (item, model) => model.Icon = "fth-mail";
|
||||
}
|
||||
|
||||
|
||||
public EditModel<IMailTemplate> GetEmpty([FromServices] IMailTemplate blueprint) => Edit(blueprint);
|
||||
|
||||
public async Task<EditModel<IMailTemplate>> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
||||
|
||||
public async Task<ListResult<IMailTemplate>> GetAll([FromQuery] ListQuery<IMailTemplate> query) => await Api.GetByQuery(query);
|
||||
|
||||
public async Task<IEnumerable<SelectModel>> GetForPicker() => (await Api.GetAll()).Select(x => new SelectModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
IsActive = x.IsActive
|
||||
});
|
||||
|
||||
|
||||
public async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> ids) => Previews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
|
||||
{
|
||||
Id = item.Id,
|
||||
Icon = "fth-mail",
|
||||
Name = item.Name
|
||||
});
|
||||
|
||||
|
||||
public async Task<EntityResult<IMailTemplate>> Save([FromBody] IMailTemplate model) => await Api.Save(model);
|
||||
|
||||
|
||||
public async Task<EntityResult<IMailTemplate>> Delete([FromQuery] string id) => await Api.Delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ITranslation, ITranslationsCollection>
|
||||
{
|
||||
ITranslationsApi Api;
|
||||
|
||||
public TranslationsController(ITranslationsApi api)
|
||||
public TranslationsController(ITranslationsCollection collection) : base(collection)
|
||||
{
|
||||
Api = api;
|
||||
}
|
||||
|
||||
|
||||
public EditModel<ITranslation> GetEmpty([FromServices] ITranslation blueprint) => Edit(blueprint);
|
||||
|
||||
|
||||
public async Task<EditModel<ITranslation>> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
||||
|
||||
|
||||
public async Task<ListResult<ITranslation>> GetAll([FromQuery] ListQuery<ITranslation> query) => await Api.GetByQuery(query);
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)]
|
||||
public async Task<EntityResult<ITranslation>> Save([FromBody] ITranslation model) => await Api.Save(model);
|
||||
|
||||
|
||||
[ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)]
|
||||
public async Task<EntityResult<ITranslation>> Delete([FromQuery] string id) => await Api.Delete(id);
|
||||
public override async Task<ListResult<ITranslation>> GetByQuery([FromQuery] ListQuery<ITranslation> query)
|
||||
{
|
||||
query.SearchFor(entity => entity.Key, entity => entity.Value);
|
||||
return await Collection.Query.OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ namespace zero.Web.Defaults
|
||||
|
||||
services.AddTransient<IApplicationsApi, ApplicationsApi>();
|
||||
services.AddTransient<ICountriesCollection, CountriesCollection>();
|
||||
services.AddTransient<ILanguagesApi, LanguagesApi>();
|
||||
services.AddTransient<ITranslationsApi, TranslationsApi>();
|
||||
services.AddTransient<ILanguagesCollection, LanguagesCollection>();
|
||||
services.AddTransient<ITranslationsCollection, TranslationsCollection>();
|
||||
services.AddTransient<IUserApi, UserApi>();
|
||||
services.AddTransient<IPagesApi, PagesApi>();
|
||||
services.AddTransient<IPageTreeApi, PageTreeApi>();
|
||||
services.AddTransient<IPreviewApi, PreviewApi>();
|
||||
services.AddTransient<IMailTemplatesApi, MailTemplatesApi>();
|
||||
services.AddTransient<IMailTemplatesCollection, MailTemplatesCollection>();
|
||||
|
||||
services.AddTransient<ISetupApi, SetupApi>();
|
||||
services.AddTransient<ISectionsApi, SectionsApi>();
|
||||
|
||||
Reference in New Issue
Block a user