Beispiel #1
0
        /// <summary>
        /// Loads the drop down items.
        /// </summary>
        /// <param name="picker">The picker.</param>
        /// <param name="includeEmptyOption">if set to <c>true</c> [include empty option].</param>
        internal static void LoadDropDownItems(IAssessmentTypePicker picker, bool includeEmptyOption)
        {
            var selectedItems = picker.Items.Cast <ListItem>()
                                .Where(i => i.Selected)
                                .Select(i => i.Value).AsIntegerList();

            picker.Items.Clear();

            if (includeEmptyOption)
            {
                // add Empty option first
                picker.Items.Add(new ListItem());
            }

            var assessmentTypes = AssessmentTypeCache.All()
                                  .Where(at => at.IsActive)
                                  .OrderBy(at => at.Title)
                                  .ThenBy(at => at.Id)
                                  .ToList();

            foreach (var assessmentType in assessmentTypes)
            {
                var li = new ListItem(assessmentType.Title, assessmentType.Id.ToString());
                li.Selected = selectedItems.Contains(assessmentType.Id);
                picker.Items.Add(li);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Renders the specified writer.
        /// </summary>
        /// <param name="badge">The badge.</param>
        /// <param name="writer">The writer.</param>
        public override void Render(BadgeCache badge, HtmlTextWriter writer)
        {
            if (Person == null)
            {
                return;
            }

            var assessmentTypes = new List <AssessmentTypeCache>();

            // Create a list of assessments that should be included in the badge
            if (!string.IsNullOrEmpty(GetAttributeValue(badge, AttributeKeys.AssessmentsToShow)))
            {
                // Get from attribute if available
                var assessmentTypesGuidString = GetAttributeValue(badge, AttributeKeys.AssessmentsToShow);
                var assessmentTypeGuids       = assessmentTypesGuidString.IsNullOrWhiteSpace() ? null : assessmentTypesGuidString.Split(new char[] { ',' });
                foreach (var assessmentGuid in assessmentTypeGuids)
                {
                    assessmentTypes.Add(AssessmentTypeCache.Get(assessmentGuid));
                }
            }
            else
            {
                // If none are selected then all are used.
                assessmentTypes = AssessmentTypeCache.All();
            }

            // Need a list of primitive types for assessmentTestsTaken linq
            var availableTypes = assessmentTypes.Select(t => t.Id).ToList();

            var assessmentTestsTaken = new AssessmentService(new RockContext())
                                       .Queryable()
                                       .AsNoTracking()
                                       .Where(a => a.PersonAlias != null &&
                                              a.PersonAlias.PersonId == Person.Id &&
                                              availableTypes.Contains(a.AssessmentTypeId))
                                       .OrderByDescending(a => a.CompletedDateTime ?? a.RequestedDateTime)
                                       .Select(a => new PersonBadgeAssessment {
                AssessmentTypeId = a.AssessmentTypeId, RequestedDateTime = a.RequestedDateTime, Status = a.Status
            })
                                       .ToList();

            StringBuilder toolTipText = new StringBuilder();
            StringBuilder badgeRow1   = new StringBuilder($@"<div class='badge-row'>");
            StringBuilder badgeRow2   = new StringBuilder();

            if (assessmentTypes.Count > 1)
            {
                badgeRow2.AppendLine($@"<div class='badge-row'>");
            }

            for (int i = 0; i < assessmentTypes.Count; i++)
            {
                StringBuilder badgeIcons = new StringBuilder();

                badgeIcons = i % 2 == 0 ? badgeRow1 : badgeRow2;

                var assessmentType         = assessmentTypes[i];
                var resultsPageUrl         = System.Web.VirtualPathUtility.ToAbsolute($"~{assessmentType.AssessmentResultsPath}?Person={this.Person.GetPersonActionIdentifier( "Assessment" ) }");
                var assessmentTitle        = assessmentType.Title;
                var mergeFields            = new Dictionary <string, object>();
                var mergedBadgeSummaryLava = "Not requested";

                switch (assessmentType.Guid.ToString().ToUpper())
                {
                case Rock.SystemGuid.AssessmentType.CONFLICT:

                    var conflictsThemes = new Dictionary <string, decimal>
                    {
                        { "Winning", Person.GetAttributeValue("core_ConflictThemeWinning").AsDecimalOrNull() ?? 0 },
                        { "Solving", Person.GetAttributeValue("core_ConflictThemeSolving").AsDecimalOrNull() ?? 0 },
                        { "Accommodating", Person.GetAttributeValue("core_ConflictThemeAccommodating").AsDecimalOrNull() ?? 0 }
                    };

                    string highestScoringTheme = conflictsThemes.Where(x => x.Value == conflictsThemes.Max(v => v.Value)).Select(x => x.Key).FirstOrDefault() ?? string.Empty;
                    mergeFields.Add("ConflictTheme", highestScoringTheme);
                    assessmentTitle = "Conflict Theme";
                    break;

                case Rock.SystemGuid.AssessmentType.EQ:
                    assessmentTitle = "EQ Self Aware";
                    break;
                }

                string assessmentTypeClass   = AssessmentBadgeCssClasses.AssessmentTypePrefix + assessmentTitle.RemoveSpaces().ToLower();
                string assessmentStatusClass = AssessmentBadgeCssClasses.NotRequested;
                PersonBadgeAssessment previouslyCompletedAssessmentTest = null;

                // Get the status of the assessment
                var assessmentTests = assessmentTestsTaken.Where(t => t.AssessmentTypeId == assessmentType.Id).ToList();
                PersonBadgeAssessment assessmentTest = null;
                if (assessmentTests.Count > 0)
                {
                    assessmentTest        = assessmentTests.First();
                    assessmentStatusClass = assessmentTest.Status == AssessmentRequestStatus.Pending ? AssessmentBadgeCssClasses.Requested : AssessmentBadgeCssClasses.Taken;
                }

                if (assessmentTests.Count > 1)
                {
                    // If the most recent one is completed then it is already set as the test and we can move on, the initial query ordered them by RequestedDateTime. Otherwise check if there are previoulsy completed assessments.
                    if (assessmentTests[0].Status != AssessmentRequestStatus.Complete)
                    {
                        // If the most recent one is pending then check for a completed one prior, if found then we need to display the competed text and note that an the assessment has been requested. The link should go to the completed assessment.
                        previouslyCompletedAssessmentTest = assessmentTests.Where(a => a.Status == AssessmentRequestStatus.Complete).FirstOrDefault();
                        if (previouslyCompletedAssessmentTest != null)
                        {
                            // There is a new pending assessment and a previously completed assessment, display both classes
                            assessmentStatusClass = $"{AssessmentBadgeCssClasses.Requested} {AssessmentBadgeCssClasses.Taken}";
                        }
                    }
                }

                // Only set the color if the test has been taken.
                string badgeColorHtml = string.Empty;

                // If there is a completed request we want to link to it and provide a Lava merged summary
                if (assessmentTest != null)
                {
                    if (assessmentTest.Status == AssessmentRequestStatus.Complete || previouslyCompletedAssessmentTest != null)
                    {
                        badgeColorHtml = assessmentType.BadgeColor.IsNotNullOrWhiteSpace() ? $"style='color:{assessmentType.BadgeColor};' " : string.Empty;

                        badgeIcons.AppendLine($@"<div {badgeColorHtml} class='badge {assessmentTypeClass} {assessmentStatusClass}'>");
                        badgeIcons.AppendLine($@"<a href='{resultsPageUrl}' target='_blank'>");

                        mergeFields.Add("Person", Person);
                        mergedBadgeSummaryLava = assessmentType.BadgeSummaryLava.ResolveMergeFields(mergeFields);
                    }

                    if (assessmentTest.Status == AssessmentRequestStatus.Pending && previouslyCompletedAssessmentTest == null)
                    {
                        badgeIcons.AppendLine($@"<div class='badge {assessmentTypeClass} {assessmentStatusClass}'>");

                        // set the request string and requested datetime to the merged lava
                        mergedBadgeSummaryLava = $"Requested: {assessmentTest.RequestedDateTime.ToShortDateString()}";
                    }
                }
                else
                {
                    badgeIcons.AppendLine($@"<div class='badge {assessmentTypeClass} {assessmentStatusClass}'>");
                }

                badgeIcons.AppendLine($@"
                        <span class='fa-stack'>
                            <i class='fa fa-circle fa-stack-2x'></i>
                            <i class='{assessmentType.IconCssClass} fa-stack-1x {AssessmentBadgeCssClasses.AssessmentIcon}'></i>
                        </span>");

                // Close the anchor for the linked assessment test
                if (assessmentTest != null)
                {
                    badgeIcons.AppendLine("</a>");
                }

                badgeIcons.AppendLine($@"</div>");

                string badgeToolTipColorHtml = assessmentType.BadgeColor.IsNotNullOrWhiteSpace() ? $"style='color:{assessmentType.BadgeColor};'" : string.Empty;
                toolTipText.AppendLine($@"
                    <p class='margin-b-sm'>
                        <span {badgeToolTipColorHtml} class='{assessmentTypeClass}'>
                            <span class='fa-stack'>
                                <i class='fa fa-circle fa-stack-2x'></i>
                                <i class='{assessmentType.IconCssClass} fa-stack-1x {AssessmentBadgeCssClasses.AssessmentIcon}'></i>
                            </span>
                        </span>
                        <strong>{assessmentTitle}:</strong> {mergedBadgeSummaryLava}
                    </p>");
            }

            badgeRow1.AppendLine($@"</div>");

            if (assessmentTypes.Count > 1)
            {
                badgeRow2.AppendLine($@"</div>");
            }

            writer.Write($@" <div class='badge badge-id-{badge.Id}'><div class='badge-grid' data-toggle='tooltip' data-html='true' data-sanitize='false' data-original-title=""{toolTipText.ToString()}"">");
            writer.Write(badgeRow1.ToString());
            writer.Write(badgeRow2.ToString());
            writer.Write("</div></div>");
        }