-
Notifications
You must be signed in to change notification settings - Fork 28
/
Dashboard.xaml.cs
198 lines (163 loc) · 6.22 KB
/
Dashboard.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Xml.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ViewManagement;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ITATKWinUI;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public class ScriptCard
{
public ScriptCard()
{
CardData = new ObservableCollection<Card>();
}
public ObservableCollection<Card> CardData { get; private set; }
}
public class Card
{
public string Title { get; set; }
public string SubTitle { get; set; }
public string Path { get; set; }
public string psVersion { get; set; }
public string featured { get; set; }
public string pictureAssetName { get; set; }
public DateTime dateAdded { get; set; }
}
public sealed partial class Dashboard : Page
{
public static XDocument guiConfig;
public Dashboard()
{
this.InitializeComponent();
DashboardHeaderText.Text = MainWindow.MainTitle;
DashboardSubHeaderText.Text = MainWindow.MainSubTitle;
PopulateFeaturedTiles();
PopulateRecentlyAdded();
}
private void PopulateFeaturedTiles()
{
List<ScriptCard> Cards = new List<ScriptCard>();
var MaxCount = 6; //TODO: FeaturedTiles MaxCount should be a configurable setting
var CurrentCount = 0;
guiConfig = XDocument.Load(@"XML\Scripts.xml");
foreach (XElement item in from y in guiConfig.Descendants("Item") select y)
{
if (item.Attribute("featured").Value == "true" && CurrentCount < MaxCount)
{
CurrentCount++;
var picAssetName = "";
if (item.Attribute("pictureAssetName").Value == "default" || item.Attribute("pictureAssetName").Value == "Default")
{
picAssetName = "Assets/FeaturedBg.jpg";
} else {
picAssetName = "Assets/" + item.Attribute("pictureAssetName").Value;
}
ScriptCard c = new ScriptCard();
c.CardData.Add(new Card() { Title = item.Attribute("name").Value, SubTitle = item.Attribute("description").Value, pictureAssetName = picAssetName });
Cards.Add(c);
}
}
featuredCards.Source= Cards;
}
private void PopulateRecentlyAdded()
{
List<ScriptCard> Cards = new List<ScriptCard>();
//Get recently added scripts then create cards from them
var MaxCount = 6; //TODO: RecentlyAdded MaxCount should be a configurable setting
//Create a List that we can sort later
List<Card> CardList = new List<Card>();
guiConfig = XDocument.Load(@"XML\Scripts.xml");
foreach (XElement item in from y in guiConfig.Descendants("Item") select y)
{
var PSVersion = "";
if (item.Attribute("psVersion").Value == "PS7")
{
PSVersion = "Assets/Powershell7.ico";
}
else if (item.Attribute("psVersion").Value == "PS5")
{
PSVersion = "Assets/Powershell5.png";
}
Card c = new Card()
{
Title = item.Attribute("name").Value,
SubTitle= item.Attribute("description").Value,
dateAdded = DateTime.Parse(item.Attribute("dateAdded").Value),
psVersion = PSVersion
};
CardList.Add(c);
}
//Sort the list descending by dateAdded and get the maximum amount allowed
CardList = CardList.OrderByDescending(x => x.dateAdded).ToList();
var actualMax = 0;
//This prevents us from going out of the max range if there aren't that many scripts
if(CardList.Count < MaxCount)
{
actualMax = CardList.Count;
} else
{
actualMax = MaxCount;
}
CardList = CardList.GetRange(0,actualMax);
foreach (Card item in from y in CardList select y)
{
ScriptCard c = new ScriptCard();
c.CardData.Add(new Card() { Title = item.Title, SubTitle = item.SubTitle, psVersion = item.psVersion });
Cards.Add(c);
}
scriptCards.Source = Cards;
}
private void NavigateMainFrame(string Page)
{
//Main Window contentPane should navigate to either item page or category page
var window = (Application.Current as App)?.Window as MainWindow;
//Find the category for the provided Page
guiConfig = XDocument.Load(@"XML\Scripts.xml");
var PageName = "";
foreach (XElement item in from y in guiConfig.Descendants("Item") select y)
{
if (item.Attribute("name").Value == Page)
{
PageName = item.Attribute("category").Value;
}
}
//Loop through the NavigationViewItem categories and navigate to the proper index
for (var i = 0; i < window.NavigationViews.Count; i++)
{
if (window.NavigationViews[i].Content.ToString() == PageName)
{
window.mNav.SelectedItem = window.mNav.MenuItems.ElementAt(i + 3); //Add 3 to skip Dashboard, separator, and Categories header
}
}
}
private void FeaturedItemGridView_ItemClick(object sender, ItemClickEventArgs e)
{
FeaturedItemsTextHeader.Text = "test";
Card c = e.ClickedItem as Card;
NavigateMainFrame(c.Title);
}
private void RecentlyAddedGridview_ItemClick(object sender, ItemClickEventArgs e)
{
Card c = e.ClickedItem as Card;
NavigateMainFrame(c.Title);
}
}