diff --git a/Manager.Interfaces/DTO/ConfigurationDTO.cs b/Manager.Interfaces/DTO/ConfigurationDTO.cs index 47dfc66..5f4a318 100644 --- a/Manager.Interfaces/DTO/ConfigurationDTO.cs +++ b/Manager.Interfaces/DTO/ConfigurationDTO.cs @@ -8,6 +8,9 @@ namespace Manager.Interfaces.DTO { public string id { get; set; } public string label { get; set; } + public List 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 languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application ! diff --git a/Manager.Interfaces/DTO/ExportConfigurationDTO.cs b/Manager.Interfaces/DTO/ExportConfigurationDTO.cs index e0727cf..0f38b93 100644 --- a/Manager.Interfaces/DTO/ExportConfigurationDTO.cs +++ b/Manager.Interfaces/DTO/ExportConfigurationDTO.cs @@ -1,5 +1,4 @@ -using DevExpress.Xpo; -using System; +using System; using System.Collections.Generic; namespace Manager.Interfaces.DTO diff --git a/Manager.Interfaces/Manager.Interfaces.csproj b/Manager.Interfaces/Manager.Interfaces.csproj index 4382621..f53c8b1 100644 --- a/Manager.Interfaces/Manager.Interfaces.csproj +++ b/Manager.Interfaces/Manager.Interfaces.csproj @@ -5,7 +5,6 @@ - diff --git a/Manager.Interfaces/Models/Configuration.cs b/Manager.Interfaces/Models/Configuration.cs index 86e3c98..d7ad02f 100644 --- a/Manager.Interfaces/Models/Configuration.cs +++ b/Manager.Interfaces/Models/Configuration.cs @@ -19,6 +19,16 @@ namespace Manager.Interfaces.Models [BsonRequired] public string Label { get; set; } + [BsonElement("Title")] + [BsonRequired] + public List 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, diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index c02eeea..04dd18e 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -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 _logger; + private readonly IConfiguration _configuration; - public ConfigurationController(ILogger logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService) + public ConfigurationController(IConfiguration configuration, ILogger 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(); + configuration.ImageId = newConfiguration.imageId; + configuration.ImageSource = newConfiguration.imageSource; configuration.PrimaryColor = newConfiguration.primaryColor; configuration.SecondaryColor = newConfiguration.secondaryColor; - configuration.Languages = new List { "FR", "NL", "EN", "DE" }; // by default all languages + + configuration.Languages = _configuration.GetSection("SupportedLanguages").Get>(); + + //configuration.Languages = new List { "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 sectionDTOs = _sectionService.GetAllFromConfiguration(configuration.Id).Select(s => s.ToDTO()).ToList(); List resourceDTOs = new List(); + 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; diff --git a/ManagerService/Controllers/DeviceController.cs b/ManagerService/Controllers/DeviceController.cs index 4601688..bf041d3 100644 --- a/ManagerService/Controllers/DeviceController.cs +++ b/ManagerService/Controllers/DeviceController.cs @@ -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()); } diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index fa7f276..0b974fc 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -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 _logger; + private readonly IConfiguration _configuration; - public SectionController(ILogger logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService) + public SectionController(IConfiguration configuration, ILogger logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService) { _logger = logger; + _configuration = configuration; _sectionService = sectionService; _configurationService = configurationService; } @@ -241,14 +244,18 @@ namespace ManagerService.Controllers section.Description = new List(); section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count; // Preparation - List languages = new List { "FR", "NL", "EN", "DE" };//_configurationService.GetById(newSection.ConfigurationId).Languages; + List languages = _configuration.GetSection("SupportedLanguages").Get>(); var contentArticle = new List(); 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 }; diff --git a/ManagerService/Helpers/LanguageInit.cs b/ManagerService/Helpers/LanguageInit.cs new file mode 100644 index 0000000..57920df --- /dev/null +++ b/ManagerService/Helpers/LanguageInit.cs @@ -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 Init(string label, List languages) + { + List translations = new List(); + + foreach (var language in languages) + { + translations.Add(new TranslationDTO() { language = language.ToUpper(), value = $"{language} - {label}" }); + } + return translations; + } + + } +} diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index b848b5a..e2492af 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -139,6 +139,7 @@ namespace ManagerService services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); } diff --git a/ManagerService/appsettings.json b/ManagerService/appsettings.json index 100e584..1b96860 100644 --- a/ManagerService/appsettings.json +++ b/ManagerService/appsettings.json @@ -34,5 +34,6 @@ "UserName": "admin", "Password": "mdlf2021!" }, + "SupportedLanguages": [ "FR", "NL", "EN", "DE", "IT", "ES", "PL", "CN" ], "Urls": "http://localhost:5002" }