private IEnumerable <GroupType> GetSelectedGroupTypes()
        {
            var rockContext      = new RockContext();
            var groupTypeService = new GroupTypeService(rockContext);

            // Get group types from checkboxes, default to all if none selected
            var checkInGroupTypes = cblCheckInTemplates.SelectedValuesAsInt.Any()
                ? cblCheckInTemplates.SelectedValuesAsInt.Select(i => groupTypeService.Get(i)).ToList()
                : CheckInGroupsHelper.GetCheckInTemplatesGroupTypes();

            return(checkInGroupTypes);
        }
        /// <summary>
        /// Renders the specified writer.
        /// </summary>
        /// <param name="badge">The badge.</param>
        /// <param name="writer">The writer.</param>
        public override void Render(PersonBadgeCache badge, HtmlTextWriter writer)
        {
            string badgeColour = GetAttributeValue(badge, "badgeColour");

            if (String.IsNullOrEmpty(badgeColour))
            {
                badgeColour = "#ECC759";
            }

            int  duration       = GetAttributeValue(badge, "Duration").AsIntegerOrNull() ?? 16;
            var  groupTypeGuids = GetAttributeValue(badge, "groupTypes").Split(',').AsGuidList();
            bool recursive      = GetAttributeValue(badge, "recursive").AsBoolean();

            var groupTypes = groupTypeGuids.Select(groupTypeGuid => GroupTypeCache.Get(groupTypeGuid)).Distinct().ToList();

            var    ids            = groupTypes.Select(gt => gt.Id).ToList();
            string groupTypeNames = CheckInGroupsHelper.CreateGroupListString(groupTypes);

            writer.Write(string.Format("<style>#badge-id-{0}::before {{ color: {1};}}</style>", badge.Id, badgeColour));
            writer.Write(string.Format("<div class='badge badge-weeksattendanceduration badge-id-{0}' data-toggle='tooltip' data-original-title='Individual attendance for the last {1} weeks to {2}.'>", badge.Id, duration, groupTypeNames.Truncate(150)));

            writer.Write("</div>");

            writer.Write(string.Format(@"
                <script>
                    Sys.Application.add_load(function () {{
                                                
                        $.ajax({{
                                type: 'GET',
                                url: Rock.settings.get('baseUrl') + 'api/PersonBadges/IndividualWeeksAttendedInDuration/{1}/{0}/{3}/{4}' ,
                                statusCode: {{
                                    200: function (data, status, xhr) {{
                                            var badgeHtml = '<div class=\'weeks-metric\' id=\'badge-id-{2}\'>';
                                            
                                            badgeHtml += '<span class=\'weeks-attended\' >' + data + '</span><span class=\'week-duration\'>/{0}</span>';                
                                            badgeHtml += '</div>';
                                            
                                            $('.badge-weeksattendanceduration.badge-id-{2}').html(badgeHtml);

                                        }}
                                }},
                        }});
                    }});
                </script>
                
            ", duration, Person.Id.ToString(), badge.Id, string.Join(",", ids), recursive));
        }
        private void SetupSettings()
        {
            // Create checkboxes for each possible group template
            var groupTypes = CheckInGroupsHelper.GetCheckInTemplatesGroupTypes().ToList();

            foreach (var groupType in groupTypes)
            {
                var listItem = new ListItem
                {
                    Value = groupType.Id.ToString(),
                    Text  = groupType.Name
                };
                cblCheckInTemplates.Items.Add(listItem);
            }
            cblCheckInTemplates.SetValues(groupTypes.Select(g => g.Id));

            // Ensure first item in current year dropdown is current year
            ddlCurrentYear.Items.Add(new ListItem()
            {
                Value = string.Empty, Text = RockDateTime.Now.Year.ToString()
            });

            // Create dropdown of number of historical years in block settings
            int currentYear = RockDateTime.Now.Year;
            int maxYears    = GetAttributeValue("HistoricYears").AsInteger();

            for (int i = 1; i <= maxYears; i++)
            {
                var listItem = new ListItem();
                listItem.Value = (currentYear - i).ToString();
                listItem.Text  = (currentYear - i).ToString();
                ddlComparisonYear.Items.Add(listItem);
                ddlCurrentYear.Items.Add(listItem);
            }

            ddlCurrentYear.SelectedIndex = 0;
        }
コード例 #4
0
        /// <summary>
        /// Renders the specified writer.
        /// </summary>
        /// <param name="badge">The badge.</param>
        /// <param name="writer">The writer.</param>
        public override void Render(PersonBadgeCache badge, HtmlTextWriter writer)
        {
            string badgeColour = "#817b72";

            if (!String.IsNullOrEmpty(GetAttributeValue(badge, "BarColour")))
            {
                badgeColour = GetAttributeValue(badge, "BarColour");
            }
            int  minBarHeight    = GetAttributeValue(badge, "MinimumBarHeight").AsIntegerOrNull() ?? 2;
            int  monthsToDisplay = GetAttributeValue(badge, "MonthsToDisplay").AsIntegerOrNull() ?? 24;
            var  groupTypeGuids  = GetAttributeValue(badge, "groupTypes").Split(',').AsGuidList();
            bool recursive       = GetAttributeValue(badge, "recursive").AsBoolean();

            var groupTypes = groupTypeGuids.Select(groupTypeGuid => GroupTypeCache.Get(groupTypeGuid)).Distinct().ToList();

            var ids = groupTypes.Select(gt => gt.Id).ToList();

            string groupTypeNames = CheckInGroupsHelper.CreateGroupListString(groupTypes);

            string animateClass = string.Empty;

            if (GetAttributeValue(badge, "AnimateBars") == null || GetAttributeValue(badge, "AnimateBars").AsBoolean())
            {
                animateClass = " animate";
            }

            writer.Write(String.Format("<div class='badge badge-attendance{0} badge-id-{1}' data-toggle='tooltip' data-original-title='Individual attendance for the last 24 months to {2}. Each bar is a month.'>", animateClass, badge.Id, groupTypeNames.Truncate(100)));

            writer.Write("</div>");

            writer.Write(String.Format(@"
                <script>
                    Sys.Application.add_load(function () {{
                        
                        var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
                        
                        
                        $.ajax({{
                                type: 'GET',
                                url: Rock.settings.get('baseUrl') + 'api/PersonBadges/IndividualAttendanceGraph/{0}/{1}/{2}/{5}' ,
                                statusCode: {{
                                    200: function (data, status, xhr) {{
                                            var chartHtml = '<ul class=\'badge-attendance-chart list-unstyled\'>';
                                            $.each(data, function() {{
                                                var barHeight = (this.AttendanceCount / this.SundaysInMonth) * 100;
                                                if (barHeight < {3}) {{
                                                    barHeight = {3};
                                                }}
                                
                                                chartHtml += '<li title=\'' + monthNames[this.Month -1] + ' ' + this.Year +'\'><span style=\'height: ' + barHeight + '%; background-color: {6}\'></span></li>';                
                                            }});
                                            chartHtml += '</ul>';
                                            
                                            $('.badge-attendance.badge-id-{4}').html(chartHtml);

                                        }}
                                }},
                        }});
                    }});
                </script>
                
            ", Person.Id, monthsToDisplay, string.Join(",", ids), minBarHeight, badge.Id, recursive, badgeColour));
        }