Vital Stats Widget

The Vital Stats widget displays counts for categories you define. Each row has a count derived from status flags or saved searches. This is a highly customizable widget. You can determine how many rows are displayed and what each row reports. Each row is configured with a name (to describe what is being counted), a Status Flag (or comma-separated list) or the name of a single saved search, and optionally a URL that points to search results. The count will be the number of distinct people records included in the results of all the searches configured.

Note

As noted above, multiple Status Flags can be configured in a comma-separated list, but only one saved search can included in the configuration.

To customize the widget for your own use, modify lines 8-12 of the Python script below, adding or deleting lines as necessary. Please note that, until you customize it, this widget is likely to fail on your database since you may not have the same status flags, saved searches, and queries used in the supplied sample code.

For each row, the first two parameters (name and status flag or saved search) are required. Optionally, if you want the name and count in the widget to be links to the search results, provide a URL as the third parameter. To get the URL, run the search and copy the second half of the URL – the part that follows your church database domain name. It will begin with /Query/ and conclude with a system-generated number. An example is provided in line 10 of the sample Python code below.

Tip

To form the URL for a list of status flags, create a search that uses the Status Flag search condition for each included status flag. The help article for that condition provides instructions for creating a search of multiple status flags.

The widget utilizes an HTML file and a Python script as shown below. (No SQL script is needed.) Since the information in this widget is the same for all users, Caching should be set to all users.

Video

Below is a short video demonstrating some of the features of this widget.


HTML Code

Below is the HTML code for the Vital Stats widget. As supplied by TouchPoint, the file name is WidgetVitalStatsHTML.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<div class="box">
    <div class="box-title hidden-xs" style="border:0;">
        <h5>{{WidgetName}}</h5>
    </div>
    <a class="visible-xs-block" id="{{WidgetId}}-collapse" data-toggle="collapse" href="#{{WidgetId}}-section" aria-expanded="true" aria-controls="{{WidgetId}}-section">
        <div class="box-title">
            <h5><i class="fa fa-chevron-circle-right"></i>&nbsp;&nbsp;{{WidgetName}}</h5>
        </div>
    </a>
    <div class="collapse in" id="{{WidgetId}}-section">
        {{#ifGT results.Count 0}}
            <ul class="list-group bordered">
                {{#each results}}
                    {{#ifEqual name "Total"}}
                        <li class="list-group-item"><strong>{{name}}</strong><a href="{{url}}" class="badge badge-primary" style="float:right;font-weight:bold;">{{count}}</a></li>
                    {{else}}
                        <li class="list-group-item"><a href="{{url}}">{{name}}</a><a href="{{url}}" style="float:right;">{{count}}</a></li>
                    {{/ifEqual}}
                {{/each}}
            </ul>
        {{else}}
            <div class="box-content"></div>
        {{/ifGT}}
    </div>
</div>

Python Script

Below is the Python script for the Vital Stats widget. As supplied by TouchPoint, the file name is WidgetVitalStatsPython.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
# You can report summary numbers for any status flag or saved search you have set up with this widget
# Example data is below, to use put the name you want to appear in the widget, followed by the status flag code or saved search name on each line
# You can also use multiple status flag codes in a line by separating them by a comma - this will show the number of people that have ALL of the specified flags
# You can link the number to any url as well with a third parameter

statusFlags = [
    ("Community Group", "F8"),
    ("Leaders", "F16"),
    ("Volunteers", "Volunteers", "/Query/f9449433-f972-46b0-95ab-ce142b5d54cb"),
    ("New Visitors", "F31"),
    ("Total", "F20"),
]

def Get():
    results = []
    template = Data.HTMLContent

    for item in statusFlags:
        flag = model.DynamicData()
        flag.name = item[0]
        flag.flag = item[1]
        if re.search('^F\d+(,F\d+)*$', item[1]) is None:
            flag.count = q.QueryCount(item[1])
        else:
            flag.count = q.StatusCount(item[1])
        if len(item) > 2:
            flag.url = item[2]
        else:
            flag.url = '#'
        results.append(flag)

    Data.results = results
    print
    model.RenderTemplate(template)

Get()


Latest Update 08/12/2020

Added video.

© 2020 TouchPoint Software, LLC.  All rights reserved.