allow fallback + optional languages
This commit is contained in:
@@ -31,16 +31,22 @@ namespace zero.Core.Api
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<string, T>> GetByIds(params string[] ids)
|
||||
{
|
||||
return await GetByIds<T>(ids);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IList<T>> GetAll()
|
||||
{
|
||||
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<T>()
|
||||
.Scope(Scope)
|
||||
.OrderByDescending(x => x.CreatedDate)
|
||||
.ToListAsync();
|
||||
}
|
||||
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
|
||||
|
||||
return await session.Query<T>()
|
||||
.Scope(Scope)
|
||||
.OrderByDescending(x => x.CreatedDate)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +72,9 @@ namespace zero.Core.Api
|
||||
{
|
||||
query.SearchFor(entity => entity.Name);
|
||||
|
||||
using (IAsyncDocumentSession session = Raven.OpenAsyncSession())
|
||||
{
|
||||
return await session.Query<T>()
|
||||
.Scope(Scope)
|
||||
.ToQueriedListAsync(query);
|
||||
}
|
||||
using IAsyncDocumentSession session = Raven.OpenAsyncSession();
|
||||
|
||||
return await session.Query<T>().Scope(Scope).ToQueriedListAsync(query);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +100,11 @@ namespace zero.Core.Api
|
||||
/// </summary>
|
||||
Task<T> GetById(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Get countries by ids
|
||||
/// </summary>
|
||||
Task<Dictionary<string, T>> GetByIds(params string[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Get all available languages
|
||||
/// </summary>
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace zero.Core.Entities
|
||||
/// <inheritdoc />
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsOptional { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string InheritedLanguageId { get; set; }
|
||||
}
|
||||
@@ -30,6 +33,11 @@ namespace zero.Core.Entities
|
||||
/// </summary>
|
||||
bool IsDefault { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this language is optional and does not have to be filled out
|
||||
/// </summary>
|
||||
bool IsOptional { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this language is inherited it gets all missing properties from its parent
|
||||
/// </summary>
|
||||
|
||||
@@ -99,11 +99,11 @@
|
||||
transform: translateX(14px);
|
||||
}
|
||||
|
||||
.is-primary &
|
||||
/*.is-primary &
|
||||
{
|
||||
background: var(--color-primary);
|
||||
box-shadow: 0 0 0 4px var(--color-primary-low);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<template>
|
||||
<div class="ui-native-select">
|
||||
<select :value="value" @input="onChange($event)" :disabled="disabled">
|
||||
<option :value="null"></option>
|
||||
<option v-for="item in items" :value="item.id">{{item.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
import LanguagesApi from 'zero/resources/languages';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: String
|
||||
},
|
||||
config: Object,
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data: () => ({
|
||||
items: []
|
||||
}),
|
||||
|
||||
mounted()
|
||||
{
|
||||
LanguagesApi.getForPicker().then(res =>
|
||||
{
|
||||
this.items = res;
|
||||
});
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
onChange(e)
|
||||
{
|
||||
this.$emit('input', e.target.value || null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -20,11 +20,20 @@
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
display: 'text'
|
||||
display: 'text',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
field: 'inheritedLanguageId',
|
||||
display: 'language'
|
||||
},
|
||||
{
|
||||
field: 'isDefault',
|
||||
display: 'toggle'
|
||||
},
|
||||
{
|
||||
field: 'isOptional',
|
||||
display: 'toggle'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -32,6 +32,16 @@ export default {
|
||||
return Axios.get('languages/getSupportedCultures').then(res => Promise.resolve(res.data));
|
||||
},
|
||||
|
||||
getPreviews(ids)
|
||||
{
|
||||
return Axios.get('languages/getPreviews', { params: { ids } }).then(res => Promise.resolve(res.data));
|
||||
},
|
||||
|
||||
getForPicker()
|
||||
{
|
||||
return Axios.get('languages/getForPicker').then(res => Promise.resolve(res.data));
|
||||
},
|
||||
|
||||
// save a language
|
||||
save(model)
|
||||
{
|
||||
|
||||
@@ -61,6 +61,7 @@ textarea
|
||||
-webkit-appearance: none;
|
||||
border: none;
|
||||
font-size: var(--font-size);
|
||||
background: none;
|
||||
}
|
||||
|
||||
&:after
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Entities;
|
||||
@@ -49,6 +51,25 @@ namespace zero.Web.Controllers
|
||||
public IActionResult GetSupportedCultures() => Json(Api.GetAllCultures(Options.SupportedLanguages));
|
||||
|
||||
|
||||
public async Task<IActionResult> GetForPicker() => Json((await Api.GetAll()).Select(x => new SelectModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
IsActive = x.IsActive
|
||||
}));
|
||||
|
||||
|
||||
public async Task<IActionResult> GetPreviews(List<string> ids)
|
||||
{
|
||||
return JsonPreviews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
|
||||
{
|
||||
Id = item.Id,
|
||||
Icon = "fth-globe",
|
||||
Name = item.Name
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Save language
|
||||
/// </summary>
|
||||
|
||||
@@ -331,7 +331,9 @@
|
||||
"code_text": "Code in ISO 3166-1 format",
|
||||
"isDefault": "Default",
|
||||
"isDefault_text": "Use as default language",
|
||||
"inheritedLanguageId": "Inherit from",
|
||||
"isOptional": "Optional",
|
||||
"isOptional_text": "Values for an optional language must not be entered, even if the field is required",
|
||||
"inheritedLanguageId": "Fallback",
|
||||
"inheritedLanguageId_text": "To allow multi-lingual content to fall back to another language if not present in the requested language, select it here"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user