mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using Squidex.Domain.Apps.Entities.Apps;
|
|
using Squidex.Web;
|
|
|
|
namespace Squidex.Areas.Api.Controllers.Apps.Models
|
|
{
|
|
public sealed class AppLanguagesDto : Resource
|
|
{
|
|
/// <summary>
|
|
/// The languages.
|
|
/// </summary>
|
|
[Required]
|
|
public AppLanguageDto[] Items { get; set; }
|
|
|
|
public static AppLanguagesDto FromApp(IAppEntity app, Resources resources)
|
|
{
|
|
var config = app.LanguagesConfig;
|
|
|
|
var result = new AppLanguagesDto
|
|
{
|
|
Items = config.Languages
|
|
.Select(x => AppLanguageDto.FromLanguage(x.Key, x.Value, config))
|
|
.Select(x => x.WithLinks(resources, app))
|
|
.OrderByDescending(x => x.IsMaster).ThenBy(x => x.Iso2Code)
|
|
.ToArray()
|
|
};
|
|
|
|
return result.CreateLinks(resources);
|
|
}
|
|
|
|
private AppLanguagesDto CreateLinks(Resources resources)
|
|
{
|
|
var values = new { app = resources.App };
|
|
|
|
AddSelfLink(resources.Url<AppLanguagesController>(x => nameof(x.GetLanguages), values));
|
|
|
|
if (resources.CanCreateLanguage)
|
|
{
|
|
AddPostLink("create", resources.Url<AppLanguagesController>(x => nameof(x.PostLanguage), values));
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
}
|
|
|