示例#1
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);
        }
示例#2
0
        public async void buildTranscripts()
        {
            Courses.Children.Clear();
            Courses c = new Courses();
            List <Models.Record> courses = await c.CheckForCourses();



            if (courses.Count() > 0)
            {
                foreach (Models.Record course in courses)
                {
                    Frame         card;
                    Models.Record courseRecord = await App.Database.GetCourseByID(course.CourseID);

                    card = new MaterialFrame
                    {
                        ClassId = "course_" + course.CourseID
                    };
                    Label title = new Label
                    {
                        Text  = course.CourseName,
                        Style = (Style)Application.Current.Resources["headerStyle"]
                    };


                    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(course.CourseDescription) + "</body></html>";
                    var    description = new CustomWebview
                    {
                        HeightRequest = 300,
                        Source        = new HtmlWebViewSource
                        {
                            Html = htmlText
                        },
                        Style = (Style)Application.Current.Resources["descriptionWebView"]
                    };

                    Grid chartGrid = new Grid()
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        Padding           = 0,
                        Margin            = 0
                    };

                    chartGrid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(100)
                    });
                    chartGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                    chartGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    });



                    string completion = (course.CompletionStatus == "") ? (course.CompletionStatus == "unknown") ? "In Progress" : "Not Attempted" : course.CompletionStatus;
                    string success    = (course.SuccessStatus == "" || course.SuccessStatus == "unknown") ? "" : "/" + course.SuccessStatus;

                    string score;
                    float  score_a = 0;
                    float  score_b = 0;
                    float  perc_complete;
                    float  perc_incomplete;
                    if (String.IsNullOrEmpty(course.ProgressMeasure))
                    {
                        perc_complete   = (course.CompletionStatus == "") ? 0 : (course.CompletionStatus == "Completed") ? 100 : 50;
                        perc_incomplete = 100 - perc_complete;
                    }
                    else
                    {
                        perc_complete   = (float.Parse(courseRecord.ProgressMeasure) < 0) ? float.Parse(courseRecord.ProgressMeasure) * 100 : float.Parse(courseRecord.ProgressMeasure);
                        perc_incomplete = 100 - perc_complete;
                    }
                    bool hasScore = false;

                    if (!String.IsNullOrEmpty(course.ScoreRaw) && String.IsNullOrEmpty(course.Score))
                    {
                        int raw    = Convert.ToInt32(course.ScoreRaw);
                        int max    = Convert.ToInt32(course.ScoreMax);
                        int min    = Convert.ToInt32(course.ScoreMin);
                        int scaled = ((raw - min) / (max - min)) * 100;
                        score    = scaled.ToString();
                        score_a  = scaled;
                        score_b  = (scaled < 100) ? 100 - score_a : 0;
                        hasScore = true;
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(course.Score))
                        {
                            score    = (course.Score == "") ? "" : "  " + Math.Round(double.Parse(course.Score)).ToString() + "%";
                            score_a  = (double.Parse(course.Score) < 1) ? (float)Math.Round(double.Parse(course.Score) * 100, 0, MidpointRounding.AwayFromZero) : (float)double.Parse(course.Score);
                            score_b  = ((Math.Round(score_a)) < 100) ? 100 - score_a : 0;
                            hasScore = true;
                        }
                    }



                    Doughnut doughnut = new Doughnut();

                    Grid doughnutContainer = (hasScore == false) ? null : doughnut.CompletionChart("Score", (float)Math.Round(score_a, 0, MidpointRounding.AwayFromZero), score_b);

                    Label status = new Label
                    {
                        Text  = completion + success,
                        Style = (Style)Application.Current.Resources["headerStyle"]
                    };

                    Doughnut completeDoughnut          = new Doughnut();
                    Grid     completeDoughnutContainer = completeDoughnut.CompletionChart("Complete", (float)Math.Round(perc_complete, 0, MidpointRounding.AwayFromZero), perc_incomplete);
                    if (doughnutContainer != null)
                    {
                        doughnutContainer.VerticalOptions   = LayoutOptions.CenterAndExpand;
                        doughnutContainer.HorizontalOptions = LayoutOptions.CenterAndExpand;
                        chartGrid.Children.Add(doughnutContainer, 0, 0);
                    }
                    StackLayout layout = new StackLayout();
                    card.Content = layout;
                    layout.Children.Add(title);

                    completeDoughnutContainer.VerticalOptions   = LayoutOptions.CenterAndExpand;
                    completeDoughnutContainer.HorizontalOptions = LayoutOptions.CenterAndExpand;

                    chartGrid.Children.Add(completeDoughnutContainer, 1, 0);
                    layout.Children.Add(chartGrid);

                    Courses.Children.Add(card);
                }
            }
            else
            {
                Label message = new Label
                {
                    Text  = "You have not started any courses on this device.",
                    Style = (Style)Application.Current.Resources["headerStyle"]
                };
                Courses.Children.Add(message);
            }
        }
示例#3
0
        public async Task <bool> buildCourseCard(string courseid, string coursetitle, string coursedescription, StackLayout container, EventHandler downloadClicked, EventHandler launchCourse, string duedate)
        {
            MaterialFrame frame;
            StackLayout   layout;
            // let's try to sync all the courses
            var current = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                API api = new API();
                Device.BeginInvokeOnMainThread(async() => await api.SyncCourse(courseid));
            }
            // DownloadButton launchBtn;
            ActivityIndicator spinner;
            // Image marquee;
            StackLayout marqueeContainer;

            // See if there is a course record so we can display the proper navigation (download, launch etc...)
            Models.Record courseRecord = await App.Database.GetCourseByID(courseid);

            CachedImage marquee = BuildMarquee(courseid, true);

            // wrap the course Marquee in a stack layout so we have more control with the layout
            marqueeContainer = new StackLayout
            {
            };


            Image marqueePlaceholder = new Image
            {
                Source = ImageSource.FromResource("TCMobile.Images.placeholder.png")
            };

            marqueeContainer.Children.Add(marquee);
            // marqueeContainer.Children.Add(marqueePlaceholder);
            marqueePlaceholder.SetBinding(Image.IsVisibleProperty, "IsLoading");
            marqueePlaceholder.BindingContext = marquee;


            frame = new MaterialFrame
            {
                HasShadow    = true,
                Padding      = new Thickness(0, 0, 0, 0),
                Margin       = new Thickness(0, 8, 0, 24),
                CornerRadius = 0
            };

            layout = new StackLayout
            {
                ClassId = "course_" + courseid
            };

            StackLayout cardBody = new StackLayout
            {
                Padding         = new Thickness(16, 0, 16, 0),
                ClassId         = "course_" + courseid,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            Label title = new Label
            {
                Text  = coursetitle,
                Style = (Style)Application.Current.Resources["headerStyle"]
            };

            Grid titleGrid = new Grid()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = 0,
                Margin            = 15
            };

            if (courseRecord != null && courseRecord.Downloaded != false)
            {
                titleGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(40)
                });
                titleGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                titleGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(80)
                });
            }
            else
            {
                titleGrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(40)
                });
                titleGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Auto)
                });
            }
            string duedateText = "";

            //ChartView chartView = null;
            if (!String.IsNullOrEmpty(duedate))
            {
                DateTime dt = Convert.ToDateTime(duedate);
                duedateText = "Due: " + String.Format("{0:ddd, MMM d, yyyy}", dt);
            }
            float perc_complete   = 0;
            float perc_incomplete = 0;

            if (courseRecord != null && courseRecord.Downloaded == true)
            {
                if (courseRecord.ProgressMeasure != null && courseRecord.ProgressMeasure != "")
                {
                    perc_complete   = (float)Math.Round(float.Parse(courseRecord.ProgressMeasure), 0, MidpointRounding.AwayFromZero);
                    perc_incomplete = 100 - perc_complete;
                }
                else
                {
                    perc_complete   = (courseRecord != null && courseRecord.CompletionStatus.ToLower() == "completed") ?  100 :(courseRecord != null) ? 50 : 0;
                    perc_incomplete = (courseRecord != null && courseRecord.CompletionStatus.ToLower() != "completed") ? (courseRecord != null) ? 50 : 0 : 100;
                }
            }
            Label dueDate = new Label
            {
                Text = duedateText
            };

            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(coursedescription) + "</body></html>";
            var    description = new CustomWebview
            {
                HeightRequest   = 250,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Source          = new HtmlWebViewSource
                {
                    Html = htmlText
                },
                Style = (Style)Application.Current.Resources["descriptionWebView"]
            };

            // ViewCell webViewViewCell = new ViewCell();
            Grid webViewGrid = new Grid();

            webViewGrid.Children.Add(description);

            spinner = new ActivityIndicator
            {
                IsVisible     = false,
                Style         = (Style)Application.Current.Resources["spinnerStyle"],
                HeightRequest = 20
            };
            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)
            });


            Label lbl = new Label()
            {
                Text = (courseRecord == null || courseRecord.Downloaded == false) ? "download" :
                       (courseRecord.CompletionStatus.ToLower() == "completed") ? "review" :
                       (courseRecord.CMI == "") ? "open" : "resume",
                HorizontalOptions = LayoutOptions.Center
            };
            DownloadImageButton downloadBtn = BuildImageDownload(courseid, courseRecord, spinner, lbl);

            downloadBtn.CourseID = courseid;



            StackLayout cardFooter = new StackLayout
            {
                Padding = new Thickness(16, 0, 16, 8),
                ClassId = "course_" + courseid
            };

            DownloadImageButton launchBtn = BuildImageLaunch(courseid, courseRecord, spinner, lbl);

            downloadBtn.LaunchButton = launchBtn;
            launchBtn.Clicked       += launchCourse;
            downloadBtn.Clicked     += downloadClicked;
            btnGrid.Children.Add(downloadBtn, 0, 0);
            btnGrid.Children.Add(launchBtn, 0, 0);
            btnGrid.Children.Add(spinner, 0, 0);
            btnGrid.Children.Add(lbl, 0, 1);
            //titleGrid.Children.Add(title, 0, 0);


            if (courseRecord != null && courseRecord.Downloaded != false)
            {
                Doughnut doughnut          = new Doughnut();
                Grid     doughnutContainer = doughnut.CompletionChart("Completed", perc_complete, perc_incomplete);
                titleGrid.Children.Add(doughnutContainer, 1, 0);
            }
            cardBody.Children.Add(titleGrid);
            cardBody.Children.Add(dueDate);
            //string x = (courseRecord == null || courseRecord.Deleted == "true") ? "download" :
            //             (courseRecord.CompletionStatus.ToLower() == "completed") ? "review" :
            //             (courseRecord.CMI == "") ? "open" : "resume";

            cardBody.Children.Add(webViewGrid);
            layout.Children.Add(title);
            layout.Children.Add(marqueeContainer);
            layout.Children.Add(cardBody);
            layout.Children.Add(cardFooter);
            //cardFooter.Children.Add(launchBtn);
            // cardFooter.Children.Add(downloadBtn);
            //cardFooter.Children.Add(lbl);
            cardFooter.Children.Add(btnGrid);
            //cardFooter.Children.Add(spinner);
            frame.Content = layout;
            container.Children.Add(frame);

            return(true);
        }