//Function to call to switch to the task page and update its elements private void GotoTaskpage() { if (TaskStack.SelectedItem is Firefly.FullTask) { TaskTitleText.Text = ((Firefly.FullTask)TaskStack.SelectedItem).title; TaskSetByText.Text = ((Firefly.FullTask)TaskStack.SelectedItem).setter.name; TaskSetLbl.Content = ((Firefly.FullTask)TaskStack.SelectedItem).setDate.ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss"); TaskDueLbl.Content = ((Firefly.FullTask)TaskStack.SelectedItem).dueDate.ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss"); TaskIdText.Text = ((Firefly.FullTask)TaskStack.SelectedItem).id.ToString(); TaskClassKeysListBox.ItemsSource = ((Firefly.FullTask)TaskStack.SelectedItem).ClassKeys; //Check if Uri is acceptable if (Uri.IsWellFormedUriString(FF.SchoolUrl + "/set-tasks/" + ((Firefly.FullTask)TaskStack.SelectedItem).id, UriKind.Absolute)) { TaskHyperLink.NavigateUri = new Uri(FF.SchoolUrl + "/set-tasks/" + ((Firefly.FullTask)TaskStack.SelectedItem).id); } TaskStackPanel.Children.Clear(); if (((Firefly.FullTask)TaskStack.SelectedItem).descriptionDetails.htmlContent != null) { try { HtmlDocument html = new HtmlDocument(); html.LoadHtml(((Firefly.FullTask)TaskStack.SelectedItem).descriptionDetails.htmlContent); foreach (HtmlNode item in html.DocumentNode.ChildNodes) { try { TextBlock text = new TextBlock(); text.FontSize = 16; text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 102, 102, 102)); text.FontFamily = new System.Windows.Media.FontFamily("Source Sans Pro"); text.TextWrapping = TextWrapping.Wrap; switch (item.Name) { case "h1": //size 36px text.FontSize = 36; PopulateTextblockHtmlToXaml(item, ref text); TaskStackPanel.Children.Add(text); break; case "h2": //size 26px text.FontSize = 26; PopulateTextblockHtmlToXaml(item, ref text); TaskStackPanel.Children.Add(text); break; case "h3": //size 24px text.FontSize = 24; PopulateTextblockHtmlToXaml(item, ref text); TaskStackPanel.Children.Add(text); break; case "p": //size 16px if (item.HasClass("ff-style-highlight")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xFD, 0xEB, 0x75)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Star; icon.Height = 30; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x7e, 0x6d, 0x02)); grid.Children.Add(text); TaskStackPanel.Children.Add(border); } else if (item.HasClass("ff-style-guidance")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xB3, 0xEC, 0xCE)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Shapes; icon.Height = 30; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x18, 0x66, 0x3e)); grid.Children.Add(text); TaskStackPanel.Children.Add(border); } else if (item.HasClass("ff-style-important")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xff, 0xbd, 0xbf)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Exclamation; icon.Height = 30; icon.Margin = new Thickness(12, 3, 0, 0); icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x80, 0x00, 0x04)); grid.Children.Add(text); TaskStackPanel.Children.Add(border); } else { PopulateTextblockHtmlToXaml(item, ref text); TaskStackPanel.Children.Add(text); } break; } } catch { //Do Nothing } } } catch { //Do nothing } } TaskStackPanel.Children.Add(new Separator()); try { if (((Firefly.FullTask)TaskStack.SelectedItem).recipientsResponses.Count() > 0) { foreach (Firefly.Response item in ((Firefly.FullTask)TaskStack.SelectedItem).recipientsResponses.First().responses.OrderByDescending(pv => pv.sentTimestamp)) { try { ResponseControl resp = new ResponseControl(); resp.Datet = item.sentTimestamp.ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss"); switch (item.eventType) { case "set-task": resp.Titlet = item.authorName + " set task"; TaskStackPanel.Children.Add(resp); break; case "archive-task": resp.Titlet = item.authorName + " archived task"; TaskStackPanel.Children.Add(resp); break; case "add-file": resp.Titlet = item.authorName + " added a file"; TaskStackPanel.Children.Add(resp); break; case "mark-as-done": resp.Titlet = item.authorName + " marked as done"; TaskStackPanel.Children.Add(resp); break; case "mark-as-undone": resp.Titlet = item.authorName + " marked as undone"; TaskStackPanel.Children.Add(resp); break; case "mark-and-grade": resp.Titlet = item.authorName + " added a mark"; Border bb = new Border(); Label text = new Label(); text.Foreground = Brushes.White; bb.CornerRadius = new CornerRadius(5); bb.Background = new SolidColorBrush(Color.FromRgb(89, 121, 146)); bb.Child = text; bb.HorizontalAlignment = HorizontalAlignment.Left; bb.VerticalAlignment = VerticalAlignment.Top; bb.MaxHeight = 50; bb.MaxWidth = 200; if (item.message != null) { Grid grid2 = new Grid(); grid2.ColumnDefinitions.Add(new ColumnDefinition()); grid2.ColumnDefinitions.Add(new ColumnDefinition()); TextBlock textbl2 = new TextBlock(); textbl2.TextWrapping = TextWrapping.Wrap; textbl2.Text = item.message; textbl2.SetValue(Grid.ColumnProperty, 1); grid2.Children.Add(textbl2); grid2.Children.Add(bb); resp.Content = grid2; } else { resp.Content = bb; } if (((Firefly.FullTask)TaskStack.SelectedItem).totalMarkOutOf != 0) { text.Content = item.mark + "/" + ((Firefly.FullTask)TaskStack.SelectedItem).totalMarkOutOf + " " + Math.Round(item.mark * 100 / ((Firefly.FullTask)TaskStack.SelectedItem).totalMarkOutOf) + "%"; TaskStackPanel.Children.Add(resp); } else if (item.outOf != 0) { text.Content = item.mark + "/" + item.outOf + " " + Math.Round(item.mark * 100 / item.outOf) + "%"; TaskStackPanel.Children.Add(resp); } else if (item.taskAssessmentDetails.assessmentMarkMax != 0) { text.Content = item.mark + "/" + item.taskAssessmentDetails.assessmentMarkMax + " " + Math.Round(item.mark * 100 / item.taskAssessmentDetails.assessmentMarkMax) + "%"; TaskStackPanel.Children.Add(resp); } break; case "comment": resp.Titlet = item.authorName + " added a comment"; TextBlock textbl = new TextBlock(); textbl.TextWrapping = TextWrapping.Wrap; if (item.message != null) { textbl.Text = item.message; } resp.Content = textbl; TaskStackPanel.Children.Add(resp); break; default: break; } } catch { //Do nothing } } } } catch { //Do nothing } } MainTabControl.SelectedIndex = 5; }
//Will convert the html of the dashboard message to a similar grid //<div[\S\s]*?data-ff-component-type="html"[\S\s]*?>([\S\s]*?)<\/div> private void DashboardMessageToXaml(HtmlNode html) { DashboardMessagePanel.Children.Clear(); if (html == null) { Label lbl = new Label(); lbl.Content = "**Error Processing Dashboard Format"; lbl.Foreground = System.Windows.Media.Brushes.Red; lbl.FontSize = 16; DashboardMessagePanel.Children.Insert(0, lbl); return; } bool errors = false; try { foreach (HtmlNode item in html.ChildNodes) { try { TextBlock text = new TextBlock(); text.FontSize = 16; text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 102, 102, 102)); text.FontFamily = new System.Windows.Media.FontFamily("Source Sans Pro"); text.TextWrapping = TextWrapping.Wrap; switch (item.Name) { case "h1": //size 36px text.FontSize = 36; PopulateTextblockHtmlToXaml(item, ref text); DashboardMessagePanel.Children.Add(text); break; case "h2": //size 26px text.FontSize = 26; PopulateTextblockHtmlToXaml(item, ref text); DashboardMessagePanel.Children.Add(text); break; case "h3": //size 24px text.FontSize = 24; PopulateTextblockHtmlToXaml(item, ref text); DashboardMessagePanel.Children.Add(text); break; case "p": //size 16px if (item.HasClass("ff-style-highlight")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xFD, 0xEB, 0x75)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Star; icon.Height = 30; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x7e, 0x6d, 0x02)); grid.Children.Add(text); DashboardMessagePanel.Children.Add(border); } else if (item.HasClass("ff-style-guidance")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xB3, 0xEC, 0xCE)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Shapes; icon.Height = 30; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x18, 0x66, 0x3e)); grid.Children.Add(text); DashboardMessagePanel.Children.Add(border); } else if (item.HasClass("ff-style-important")) { Border border = new Border(); border.CornerRadius = new CornerRadius(10); border.Padding = new Thickness(5); border.VerticalAlignment = VerticalAlignment.Top; border.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xff, 0xbd, 0xbf)); Grid grid = new Grid(); border.Child = grid; FontAwesome5.SvgAwesome icon = new FontAwesome5.SvgAwesome(); icon.Icon = FontAwesome5.EFontAwesomeIcon.Solid_Exclamation; icon.Height = 30; icon.Margin = new Thickness(12, 3, 0, 0); icon.HorizontalAlignment = HorizontalAlignment.Left; icon.VerticalAlignment = VerticalAlignment.Top; icon.Foreground = System.Windows.Media.Brushes.White; grid.Children.Add(icon); PopulateTextblockHtmlToXaml(item, ref text); text.Margin = new Thickness(40, 0, 0, 0); text.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x80, 0x00, 0x04)); grid.Children.Add(text); DashboardMessagePanel.Children.Add(border); } else { PopulateTextblockHtmlToXaml(item, ref text); DashboardMessagePanel.Children.Add(text); } break; } } catch { errors = true; } } } catch { Label lbl = new Label(); lbl.Content = "**Unable to process Dashboard Message"; lbl.Foreground = System.Windows.Media.Brushes.Red; lbl.FontSize = 16; DashboardMessagePanel.Children.Insert(0, lbl); } if (errors) { Label lbl = new Label(); lbl.Content = "**Error Processing Dashboard - Parts may be missing"; lbl.Foreground = System.Windows.Media.Brushes.Red; lbl.FontSize = 16; DashboardMessagePanel.Children.Insert(0, lbl); } }