Exemplo n.º 1
0
        public async Task <int> GetCompletion(string id)
        {
            Courses l = new Courses();

            Models.LPDBRecord lp = await l.GetActivityMap(id);

            int completionPercent = 0;

            if (lp != null && lp.LPMap != null && lp.LPMap != "")
            {
                JsonSerializerSettings ser = new JsonSerializerSettings();
                ser.DefaultValueHandling = DefaultValueHandling.Populate;
                StudentActivityMap lpMap = JsonConvert.DeserializeObject <StudentActivityMap>(lp.LPMap, ser);
                int objectiveCount       = lpMap.Objective.Count;
                int completeCount        = 0;

                foreach (Objective obj in lpMap.Objective)
                {
                    string status = obj.Status;
                    if (obj.Status.ToLower() == "completed")
                    {
                        completeCount++;
                    }
                }
                decimal p = (completeCount / objectiveCount) * 100;
                completionPercent = (int)Math.Round(p, 0, MidpointRounding.AwayFromZero);
            }
            return(completionPercent);
        }
Exemplo n.º 2
0
        public static async Task <bool> SaveMap(string lpid, StudentActivityMap activitymap)
        {
            Models.LPDBRecord learningPath = await App.Database.GetLPByID(lpid);

            if (learningPath != null && learningPath.LPMap == "")
            {
                string map = JsonConvert.SerializeObject(activitymap);
                learningPath.LPMap = map;
                await App.Database.SaveLPAsync(learningPath);
            }
            return(true);
        }
Exemplo n.º 3
0
        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);
        }