Add localized maintenances description
This commit is contained in:
@@ -2,27 +2,33 @@
|
||||
<maintenances>
|
||||
<maintenance>
|
||||
<id>1</id>
|
||||
<localizedNames>
|
||||
<localizedName>
|
||||
<lang langKey="en">Manutenzione scaduta</lang>
|
||||
<lang langKey="it">Manutenzione scaduta</lang>
|
||||
</localizedNames>
|
||||
</localizedName>
|
||||
<interval>10</interval>
|
||||
<deadline>15/06/2018 13:00</deadline>
|
||||
<type>EXP_DATE</type>
|
||||
<description>DescriptionUNO</description>
|
||||
<localizedDescription>
|
||||
<lang langKey="en">Test 2 </lang>
|
||||
<lang langKey="it">Ita 2</lang>
|
||||
</localizedDescription>
|
||||
<unitOfMeasure>D</unitOfMeasure>
|
||||
<counterId>2</counterId>
|
||||
</maintenance>
|
||||
<maintenance>
|
||||
<id>2</id>
|
||||
<localizedNames>
|
||||
<localizedName>
|
||||
<lang langKey="en">Test 2 </lang>
|
||||
<lang langKey="it">Ita 2</lang>
|
||||
</localizedNames>
|
||||
</localizedName>
|
||||
<interval>1000</interval>
|
||||
<deadline>15/07/2018 13:00</deadline>
|
||||
<type>MACHINE_INTERVAL</type>
|
||||
<description>Description</description>
|
||||
<localizedDescription>
|
||||
<lang langKey="en">Test 2 </lang>
|
||||
<lang langKey="it">Ita 2</lang>
|
||||
</localizedDescription>
|
||||
<unitOfMeasure>mm</unitOfMeasure>
|
||||
<counterId>1</counterId>
|
||||
</maintenance>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="id" type="xs:int" />
|
||||
<xs:element name="localizedNames">
|
||||
<xs:element name="localizedName">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="lang" type="langType" minOccurs="0" maxOccurs="unbounded">
|
||||
@@ -19,7 +19,14 @@
|
||||
</xs:element>
|
||||
<xs:element name="interval" type="xs:string" />
|
||||
<xs:element name="deadline" type="xs:string" />
|
||||
<xs:element name="description" type="xs:string" />
|
||||
<xs:element name="localizedDescription">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="lang" type="langType" minOccurs="0" maxOccurs="unbounded">
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="unitOfMeasure" type="unitOfMeasureType" />
|
||||
<xs:element name="type" type="maintenanceType" />
|
||||
<xs:element name="counterId" type="xs:unsignedInt"/>
|
||||
|
||||
@@ -206,14 +206,16 @@ namespace Step.Config
|
||||
new MaintenanceConfigModel()
|
||||
{
|
||||
Id = Convert.ToInt32(x.Element("id").Value),
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read names list
|
||||
LocalizedName = x.Element("localizedName").Elements().ToDictionary( // Read localized names
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
Intervall = TimeSpan.FromMinutes(Convert.ToDouble(x.Element("interval").Value)),
|
||||
Deadline = DateTime.Parse(x.Element("deadline").Value),
|
||||
Type = x.Element("type").Value,
|
||||
CouterId = Convert.ToInt32(x.Element("counterId").Value),
|
||||
Description = x.Element("description").Value,
|
||||
LocalizedDescription = x.Element("localizedDescription").Elements().ToDictionary( // Read localization of description
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
UnitOfMeasure = x.Element("unitOfMeasure").Value
|
||||
})
|
||||
.ToList();
|
||||
|
||||
@@ -165,7 +165,6 @@ namespace Step.Database.Controllers
|
||||
old.Interval = x.Intervall.TotalMinutes;
|
||||
old.Type = (MAINTENANCE_TYPE) Enum.Parse(typeof(MAINTENANCE_TYPE), x.Type);
|
||||
old.CounterId = x.CouterId;
|
||||
old.Description = x.Description;
|
||||
old.UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE)Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE), x.UnitOfMeasure);
|
||||
return old;
|
||||
}).FirstOrDefault();
|
||||
@@ -184,7 +183,6 @@ namespace Step.Database.Controllers
|
||||
Type = (MAINTENANCE_TYPE)Enum.Parse(typeof(MAINTENANCE_TYPE), x.Type),
|
||||
CounterId = x.CouterId,
|
||||
CreationDate = DateTime.Now,
|
||||
Description = x.Description,
|
||||
UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE) Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE),x.UnitOfMeasure),
|
||||
UserId = null,
|
||||
LastExpirationDate = null
|
||||
|
||||
@@ -6,13 +6,13 @@ namespace Step.Model.ConfigModels
|
||||
public class MaintenanceConfigModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Dictionary<string, string> LocalizedNames { get; set; }
|
||||
public Dictionary<string, string> LocalizedName { get; set; }
|
||||
public TimeSpan Intervall { get; set; }
|
||||
public DateTime Deadline { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int CouterId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Dictionary<string, string> LocalizedDescription { get; set; }
|
||||
public string UnitOfMeasure { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,7 @@ namespace Step.Model
|
||||
|
||||
// ID prefix
|
||||
public const string MAINTENANCE_PREFIX_ID = "maint_";
|
||||
public const string MAINTENANCE_DESC_PREFIX_ID = "maint_desc_";
|
||||
public const string SOFTKEY_PREFIX_ID = "softkey_";
|
||||
public const string ALARM_PREFIX = "alarm_";
|
||||
|
||||
|
||||
@@ -52,11 +52,23 @@ namespace Step.Controllers.WebApi
|
||||
|
||||
private static Dictionary<string, string> GetLocalizeMaintenanceName(string language)
|
||||
{
|
||||
return MaintenancesConfig
|
||||
Dictionary<string, string> localizedStrings = new Dictionary<string, string>();
|
||||
|
||||
// Get localized name
|
||||
localizedStrings = MaintenancesConfig
|
||||
.ToDictionary(
|
||||
x => MAINTENANCE_PREFIX_ID + x.Id.ToString(), // Prefix + maintenance id
|
||||
x => GetValueFromMaintenanceNameList(x.LocalizedNames, language, "Maintenance_" + x.Id)
|
||||
x => GetValueFromLocalizationList(x.LocalizedName, language, "Maintenance_" + x.Id)
|
||||
);
|
||||
|
||||
// Get localized description
|
||||
localizedStrings = localizedStrings.Concat( MaintenancesConfig
|
||||
.ToDictionary(
|
||||
x => MAINTENANCE_DESC_PREFIX_ID + x.Id.ToString(), // Description Prefix + maintenance id
|
||||
x => GetValueFromLocalizationList(x.LocalizedDescription, language, "Maintenance_" + x.Id)
|
||||
)).ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
return localizedStrings;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> GetLocalizedSoftKeysNames(string language)
|
||||
@@ -64,11 +76,11 @@ namespace Step.Controllers.WebApi
|
||||
return SoftKeysConfig
|
||||
.ToDictionary(
|
||||
x => SOFTKEY_PREFIX_ID + x.Id.ToString(), // PREFIX + softkey Id
|
||||
x => GetValueFromMaintenanceNameList(x.LocalizedNames, language, "SoftKey_" + x.Id)
|
||||
x => GetValueFromLocalizationList(x.LocalizedNames, language, "SoftKey_" + x.Id)
|
||||
);
|
||||
}
|
||||
|
||||
private static string GetValueFromMaintenanceNameList(Dictionary<string, string> localizedNames, string language, string defaultString)
|
||||
private static string GetValueFromLocalizationList(Dictionary<string, string> localizedNames, string language, string defaultString)
|
||||
{
|
||||
// Find text from names by language id
|
||||
var value = localizedNames.Where(y => y.Key == language).FirstOrDefault();
|
||||
|
||||
Reference in New Issue
Block a user