public Models.statusObject lpStatus(List <Objective> objective) { int count = objective.Count; int completed = 0; int score = 0; foreach (var o in objective) { if (o.Status.ToLower() == "completed") { completed++; } if (o.Score != "" && o.Score != "N/A") { score += Int32.Parse(o.Score); } } Models.statusObject st = new Models.statusObject(); st.completion = (count == completed) ? "completed" : "incomplete"; st.percentage = (score / count) * 100; return(st); }
public async void buildLPCard(string id, string lptitle, string lpdescription, FlexLayout LP, EventHandler detailsClicked) { StudentActivityMap map = null; MaterialFrame frame; StackLayout layout; Label status = new Label(); LearningPath lpObj = new LearningPath(); int completionPercent = await lpObj.GetCompletion(id); Models.LPDBRecord lp = await getMap(id); if (lp.LPMap != "") { map = JsonConvert.DeserializeObject <StudentActivityMap>(lp.LPMap); if (map != null) { LP learningPath = new LP(); Models.statusObject completionStatus = learningPath.lpStatus(map.Objective); status.Text = completionStatus.completion; } else { status.Text = "not started"; } } else { status.Text = "not started"; } frame = new MaterialFrame { HasShadow = true, Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(0, 8, 0, 24), CornerRadius = 0 }; // need to add doughnut Doughnut doughnut = new Doughnut(); int percentIncomplete = 100 - completionPercent; Grid doughnutContainer = doughnut.CompletionChart("Completed", completionPercent, percentIncomplete); Label lbl = new Label() { Text = "more info", HorizontalOptions = LayoutOptions.Center }; DownloadImageButton moreBtn = new DownloadImageButton { //Text = "more", Source = "outline_info_black_48.png", //Style = (Style)Application.Current.Resources["buttonStyle"], ClassId = id, CourseID = id, BackgroundColor = Color.Transparent, BorderColor = Color.Transparent, }; moreBtn.Clicked += detailsClicked; layout = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand }; StackLayout cardBody = new StackLayout { Padding = new Thickness(16, 0, 16, 0), ClassId = "course_" + id, VerticalOptions = LayoutOptions.FillAndExpand }; Label title = new Label { Text = lptitle, Style = (Style)Application.Current.Resources["headerStyle"] }; // html description StackLayout cardFooter = new StackLayout { Padding = new Thickness(16, 0, 16, 8), ClassId = "course_" + id }; string htmlText = @"<html> <head> <meta name='viewport' content='width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'/> <style type='text/css'> body{font-family:Segoe UI, Helvetica Neue,'Lucida Sans Unicode', Skia, sans-serif; border:0px;padding:0px;margin:0px; background-color:transparent; overflow:hidden; } </style> </head> <body>" + HttpUtility.HtmlDecode(lpdescription) + "</body></html>"; CustomWebview description = new CustomWebview { HeightRequest = 300, Source = new HtmlWebViewSource { Html = htmlText }, Style = (Style)Application.Current.Resources["descriptionWebView"] }; Grid btnGrid = new Grid() { HorizontalOptions = LayoutOptions.Center }; btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(20) }); btnGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(80) }); btnGrid.Children.Add(moreBtn, 0, 0); btnGrid.Children.Add(lbl, 0, 1); cardFooter.Children.Add(doughnutContainer); cardFooter.Children.Add(btnGrid); cardBody.Children.Add(title); cardBody.Children.Add(status); cardBody.Children.Add(description); layout.Children.Add(cardBody); layout.Children.Add(cardFooter); frame.Content = layout; LP.Children.Add(frame); }