Add title and image to configuration
This commit is contained in:
parent
afdd538a3b
commit
1725376623
@ -8,6 +8,9 @@ namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string label { get; set; }
|
||||
public List<TranslationDTO> title { get; set; }
|
||||
public string imageId { get; set; } // == ResourceId
|
||||
public string imageSource { get; set; } // == Image url
|
||||
public string primaryColor { get; set; }
|
||||
public string secondaryColor { get; set; }
|
||||
public List<string> languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application !
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using DevExpress.Xpo;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DevExpress.Xpo" Version="20.1.8" />
|
||||
<PackageReference Include="MongoDB.Bson" Version="2.12.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -19,6 +19,16 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string Label { get; set; }
|
||||
|
||||
[BsonElement("Title")]
|
||||
[BsonRequired]
|
||||
public List<TranslationDTO> Title { get; set; }
|
||||
|
||||
[BsonElement("ImageId")]
|
||||
public string ImageId { get; set; }
|
||||
|
||||
[BsonElement("ImageSource")]
|
||||
public string ImageSource { get; set; }
|
||||
|
||||
[BsonElement("PrimaryColor")]
|
||||
public string PrimaryColor { get; set; }
|
||||
|
||||
@ -46,6 +56,9 @@ namespace Manager.Interfaces.Models
|
||||
{
|
||||
id = Id,
|
||||
label = Label,
|
||||
title = Title,
|
||||
imageId = ImageId,
|
||||
imageSource = ImageSource,
|
||||
dateCreation = DateCreation,
|
||||
primaryColor = PrimaryColor,
|
||||
languages = Languages,
|
||||
@ -61,6 +74,9 @@ namespace Manager.Interfaces.Models
|
||||
{
|
||||
id = Id,
|
||||
label = Label,
|
||||
title= Title,
|
||||
imageId = ImageId,
|
||||
imageSource = ImageSource,
|
||||
dateCreation = DateCreation,
|
||||
primaryColor = PrimaryColor,
|
||||
languages = Languages,
|
||||
|
||||
@ -9,6 +9,7 @@ using Manager.Services;
|
||||
using ManagerService.Service.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Mqtt.Client.AspNetCore.Services;
|
||||
using Newtonsoft.Json;
|
||||
@ -26,10 +27,12 @@ namespace ManagerService.Controllers
|
||||
private ResourceDatabaseService _resourceService;
|
||||
private DeviceDatabaseService _deviceService;
|
||||
private readonly ILogger<ConfigurationController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ConfigurationController(ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService)
|
||||
public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_configurationService = configurationService;
|
||||
_sectionService = sectionService;
|
||||
_resourceService = resourceService;
|
||||
@ -107,9 +110,17 @@ namespace ManagerService.Controllers
|
||||
// Todo add some verification ?
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.Label = newConfiguration.label;
|
||||
configuration.Title = new List<TranslationDTO>();
|
||||
configuration.ImageId = newConfiguration.imageId;
|
||||
configuration.ImageSource = newConfiguration.imageSource;
|
||||
configuration.PrimaryColor = newConfiguration.primaryColor;
|
||||
configuration.SecondaryColor = newConfiguration.secondaryColor;
|
||||
configuration.Languages = new List<string> { "FR", "NL", "EN", "DE" }; // by default all languages
|
||||
|
||||
configuration.Languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||
|
||||
//configuration.Languages = new List<string> { "FR", "NL", "EN", "DE" }; // by default all languages
|
||||
configuration.Title = LanguageInit.Init("Title", configuration.Languages);
|
||||
|
||||
configuration.DateCreation = DateTime.Now;
|
||||
configuration.IsMobile = newConfiguration.isMobile;
|
||||
configuration.IsTablet = newConfiguration.isTablet;
|
||||
@ -157,6 +168,9 @@ namespace ManagerService.Controllers
|
||||
|
||||
// Todo add some verification ?
|
||||
configuration.Label = updatedConfiguration.label;
|
||||
configuration.Title = updatedConfiguration.title;
|
||||
configuration.ImageId = updatedConfiguration.imageId;
|
||||
configuration.ImageSource = updatedConfiguration.imageSource;
|
||||
configuration.PrimaryColor = updatedConfiguration.primaryColor;
|
||||
configuration.SecondaryColor = updatedConfiguration.secondaryColor;
|
||||
configuration.Languages = updatedConfiguration.languages;
|
||||
@ -166,7 +180,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
Configuration configurationModified = _configurationService.Update(updatedConfiguration.id, configuration);
|
||||
|
||||
MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
// TODO HANDLE MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
|
||||
return new OkObjectResult(configurationModified.ToDTO());
|
||||
}
|
||||
@ -216,7 +230,7 @@ namespace ManagerService.Controllers
|
||||
_deviceService.Update(device.Id, device);
|
||||
}
|
||||
|
||||
MqttClientService.PublishMessage($"config/{id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true, isDeleted = true }));
|
||||
// TODO MqttClientService.PublishMessage($"config/{id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true, isDeleted = true }));
|
||||
|
||||
return new ObjectResult("The configuration has been deleted") { StatusCode = 202 };
|
||||
|
||||
@ -254,12 +268,18 @@ namespace ManagerService.Controllers
|
||||
throw new ArgumentNullException("Configuration param is null");
|
||||
|
||||
Configuration configuration = _configurationService.GetById(id);
|
||||
|
||||
if (configuration == null)
|
||||
throw new KeyNotFoundException("Configuration does not exist");
|
||||
|
||||
List<SectionDTO> sectionDTOs = _sectionService.GetAllFromConfiguration(configuration.Id).Select(s => s.ToDTO()).ToList();
|
||||
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
|
||||
|
||||
if (configuration.ImageId != null)
|
||||
{
|
||||
addResourceToList(resourceDTOs, configuration.ImageId);
|
||||
}
|
||||
|
||||
foreach (var section in sectionDTOs)
|
||||
{
|
||||
if (section.imageId != null) {
|
||||
@ -400,6 +420,15 @@ namespace ManagerService.Controllers
|
||||
configuration = new Configuration();
|
||||
configuration.Id = exportConfiguration.id;
|
||||
configuration.Label = exportConfiguration.label;
|
||||
configuration.Title = exportConfiguration.title;
|
||||
configuration.ImageId = exportConfiguration.imageId;
|
||||
configuration.ImageSource = exportConfiguration.imageSource;
|
||||
|
||||
if (configuration.ImageId != null)
|
||||
{
|
||||
createResource(exportConfiguration.resources.Where(r => r.id == configuration.ImageId).FirstOrDefault());
|
||||
}
|
||||
|
||||
configuration.DateCreation = exportConfiguration.dateCreation;
|
||||
configuration.PrimaryColor = exportConfiguration.primaryColor;
|
||||
configuration.SecondaryColor = exportConfiguration.secondaryColor;
|
||||
|
||||
@ -239,7 +239,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
Device deviceModified = _deviceService.Update(device.Id, device);
|
||||
|
||||
MqttClientService.PublishMessage($"player/{device.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
// TODO MqttClientService.PublishMessage($"player/{device.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
|
||||
return new OkObjectResult(deviceModified.ToDTO());
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using Manager.Interfaces.Models;
|
||||
using Manager.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Mqtt.Client.AspNetCore.Services;
|
||||
using Newtonsoft.Json;
|
||||
@ -21,10 +22,12 @@ namespace ManagerService.Controllers
|
||||
private SectionDatabaseService _sectionService;
|
||||
private ConfigurationDatabaseService _configurationService;
|
||||
private readonly ILogger<SectionController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public SectionController(ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
||||
public SectionController(IConfiguration configuration, ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_sectionService = sectionService;
|
||||
_configurationService = configurationService;
|
||||
}
|
||||
@ -241,14 +244,18 @@ namespace ManagerService.Controllers
|
||||
section.Description = new List<TranslationDTO>();
|
||||
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
|
||||
// Preparation
|
||||
List<string> languages = new List<string> { "FR", "NL", "EN", "DE" };//_configurationService.GetById(newSection.ConfigurationId).Languages;
|
||||
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||
|
||||
var contentArticle = new List<TranslationDTO>();
|
||||
|
||||
var mapDTO = new MapDTO(); // For menu dto
|
||||
var sliderDTO = new SliderDTO(); // For menu dto
|
||||
|
||||
foreach (var language in languages)
|
||||
section.Title = LanguageInit.Init("Title", languages);
|
||||
section.Description = LanguageInit.Init("Description", languages);
|
||||
contentArticle = LanguageInit.Init("Content", languages);
|
||||
|
||||
/*foreach (var language in languages)
|
||||
{
|
||||
TranslationDTO title = new TranslationDTO();
|
||||
TranslationDTO description = new TranslationDTO();
|
||||
@ -282,7 +289,7 @@ namespace ManagerService.Controllers
|
||||
section.Title.Add(title);
|
||||
section.Description.Add(description);
|
||||
contentArticle.Add(content);
|
||||
}
|
||||
}*/
|
||||
|
||||
section.Title = section.Title.OrderBy(t => t.language).ToList();
|
||||
section.Description = section.Description.OrderBy(d => d.language).ToList();
|
||||
@ -461,7 +468,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
Section sectionModified = _sectionService.Update(updatedSection.id, section);
|
||||
|
||||
MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
// TODO MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
|
||||
return new OkObjectResult(sectionModified.ToDTO());
|
||||
}
|
||||
@ -510,7 +517,7 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
|
||||
if (updatedSectionsOrder.Count > 0) {
|
||||
MqttClientService.PublishMessage($"config/{updatedSectionsOrder[0].configurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
// TODO MqttClientService.PublishMessage($"config/{updatedSectionsOrder[0].configurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
}
|
||||
|
||||
return new ObjectResult("Sections order has been successfully modified") { StatusCode = 200 };
|
||||
|
||||
26
ManagerService/Helpers/LanguageInit.cs
Normal file
26
ManagerService/Helpers/LanguageInit.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Manager.Interfaces.DTO;
|
||||
using Manager.Interfaces.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Manager.Services
|
||||
{
|
||||
public class LanguageInit
|
||||
{
|
||||
public static List<TranslationDTO> Init(string label, List<string> languages)
|
||||
{
|
||||
List<TranslationDTO> translations = new List<TranslationDTO>();
|
||||
|
||||
foreach (var language in languages)
|
||||
{
|
||||
translations.Add(new TranslationDTO() { language = language.ToUpper(), value = $"{language} - {label}" });
|
||||
}
|
||||
return translations;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -139,6 +139,7 @@ namespace ManagerService
|
||||
services.AddScoped<SectionDatabaseService>();
|
||||
services.AddScoped<ConfigurationDatabaseService>();
|
||||
services.AddScoped<ResourceDatabaseService>();
|
||||
services.AddScoped<LanguageInit>();
|
||||
services.AddScoped<DeviceDatabaseService>();
|
||||
}
|
||||
|
||||
|
||||
@ -34,5 +34,6 @@
|
||||
"UserName": "admin",
|
||||
"Password": "mdlf2021!"
|
||||
},
|
||||
"SupportedLanguages": [ "FR", "NL", "EN", "DE", "IT", "ES", "PL", "CN" ],
|
||||
"Urls": "http://localhost:5002"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user