Skip to content

Commit 78f2ef1

Browse files
committed
Added check for merging themes in to the DMA
1 parent 811b9a8 commit 78f2ef1

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"__type": "Skyline.DataMiner.Web.Common.v1.Dashboards.DMADashboardThemes",
3+
"Themes": [
4+
{
5+
"__type": "Skyline.DataMiner.Web.Common.v1.Dashboards.DMADashboardTheme",
6+
"ID": 1,
7+
"IsDefault": false,
8+
"IsCustom": false,
9+
"ComponentBackgroundColor": "rgb(255,255,255)",
10+
"ComponentThemes": [
11+
{
12+
"__type": "Skyline.DataMiner.Web.Common.v1.Dashboards.DMADashboardComponentTheme",
13+
"Name": "Transparant",
14+
"Inherit": null,
15+
"BackgroundColor": "rgba(238,238,238,0)",
16+
"FontColor": "#000000",
17+
"MarginHorizontal": 5,
18+
"Colors": [
19+
"rgb(76,84,84)",
20+
"rgb(255,113,91)",
21+
"rgb(138,79,255)",
22+
"rgb(30,168,150)",
23+
"rgb(82,63,56)"
24+
],
25+
"MarginVertical": 5,
26+
"PaddingHorizontal": 5,
27+
"PaddingVertical": 5,
28+
"BorderWidth": 1,
29+
"BorderStyle": "none",
30+
"BorderSide": 15,
31+
"BorderRadius": 0,
32+
"BorderColor": "#000000",
33+
"TitleAlignment": "left",
34+
"TitleFontSize": 16,
35+
"TitleFontFamily": "inherit",
36+
"TitleBold": false,
37+
"TitleItalic": false,
38+
"IncludeTitleBorder": false,
39+
"ShadowColor": "#000000",
40+
"ShadowStyle": 0
41+
}
42+
],
43+
"Name": "Kata 19",
44+
"Inherit": null,
45+
"BackgroundColor": "rgb(240,240,240)",
46+
"FontColor": "#000000",
47+
"MarginHorizontal": 5,
48+
"Colors": [
49+
"rgb(76,84,84)",
50+
"rgb(255,113,91)",
51+
"rgb(138,79,255)",
52+
"rgb(30,168,150)",
53+
"rgb(82,63,56)"
54+
],
55+
"MarginVertical": 5,
56+
"PaddingHorizontal": 5,
57+
"PaddingVertical": 5,
58+
"BorderWidth": 1,
59+
"BorderStyle": "none",
60+
"BorderSide": 15,
61+
"BorderRadius": 0,
62+
"BorderColor": "#000000",
63+
"TitleAlignment": "left",
64+
"TitleFontSize": 16,
65+
"TitleFontFamily": "inherit",
66+
"TitleBold": false,
67+
"TitleItalic": false,
68+
"IncludeTitleBorder": false,
69+
"ShadowColor": "#000000",
70+
"ShadowStyle": 0
71+
}
72+
],
73+
"DefaultThemeID": 0
74+
}

Low Code App Editor_1Tests/Controllers/ExportControllerTests.cs

+55
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System.IO;
44
using System.Linq;
5+
using System.Runtime.Remoting.Contexts;
56

67
using Low_Code_App_Editor_1.Json;
78
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -33,5 +34,59 @@ public void ExtractThemeFromFile()
3334

3435
Assert.IsTrue(JToken.DeepEquals(usedThemesJson, correct));
3536
}
37+
38+
[TestMethod]
39+
public void MergeThemeFromFile()
40+
{
41+
// Original themes
42+
var themesJson = JObject.Parse(File.ReadAllText(@"CompanionFiles\Themes_Merged.json"));
43+
var allThemes = themesJson["Themes"] as JArray;
44+
var allThemeIds = allThemes.Select(t => t["ID"].Value<int>()).ToList();
45+
46+
// Themes to be imported
47+
var appThemesJson = JObject.Parse(File.ReadAllText(@"CompanionFiles\Themes_Extracted.json"));
48+
var appThemes = appThemesJson["Themes"] as JArray;
49+
50+
// Merge the themes
51+
for (int i = 0; i < appThemes.Count; i++)
52+
{
53+
var theme = appThemes[i];
54+
var appThemeId = theme["ID"].Value<int>();
55+
var appThemeName = theme["Name"].Value<string>();
56+
57+
var existingTheme = allThemes.FirstOrDefault(t => t["Name"].Value<string>() == appThemeName);
58+
if (existingTheme != null)
59+
{
60+
var existingThemeId = existingTheme["ID"].Value<int>();
61+
if (existingThemeId != appThemeId && allThemeIds.Exists(x => x == appThemeId))
62+
{
63+
var newId = allThemeIds.Max() + 1;
64+
theme["ID"] = newId;
65+
appThemeId = newId;
66+
allThemeIds.Add(newId);
67+
}
68+
69+
var existingThemeIndex = allThemes.IndexOf(existingTheme);
70+
allThemes[existingThemeIndex] = theme;
71+
}
72+
else
73+
{
74+
if (allThemeIds.Exists(x => x == appThemeId))
75+
{
76+
var newId = allThemeIds.Max() + 1;
77+
theme["ID"] = newId;
78+
appThemeId = newId;
79+
allThemeIds.Add(newId);
80+
}
81+
82+
allThemes.Add(theme);
83+
}
84+
}
85+
86+
// Grab the solution
87+
var correct = JObject.Parse(File.ReadAllText(@"CompanionFiles\Themes.json"));
88+
89+
Assert.IsTrue(JToken.DeepEquals(themesJson, correct));
90+
}
3691
}
3792
}

Low Code App Editor_1Tests/Low Code App Editor_1Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<None Update="CompanionFiles\Themes_Extracted.json">
3939
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4040
</None>
41+
<None Update="CompanionFiles\Themes_Merged.json">
42+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43+
</None>
4144
</ItemGroup>
4245

4346
</Project>

0 commit comments

Comments
 (0)