Giving staff easy access to their favorite reports and dataviews

  • By Michael Garrison 5 Months Ago

Let's face it: no matter how organized you are in filing reports and data views away in their proper containers, at some point your users are going to complain there are just "too many" for them to find what they want.


This post is going to be an easy way to be a hero at your church, by providing them a simple list of their favorite dataviews and favorite reports, right above the normal menus.


We need to start off by creating a new page. I recommend starting at the main internal page (/page/12) and then navigating down using the "Child Pages" button on the admin toolbar to go to Support Pages. Open up "Child Pages" here and create your new page- now you can rest assurred this page won't be linked to from any navigation menus unexpectedly.

I called my new page "Set Favorite" and set the description to something like Custom page for marking Data Views and Reports as "Favorite"

Add a single HTML block to the Main zone on this new page.

Here's the content for that block:

{% if PageParameter.DataViewId %}
    {% assign currpref = CurrentPerson | GetUserPreference:'MyFavoriteDVs' %}
    {% assign currprefLength = currpref | Size %}
    {% if currprefLength < 1 %}{{ CurrentPerson | SetUserPreference:'MyFavoriteDVs','|' }}{% endif %}
    {% if PageParameter.Action == 'Unset' %}
        {% capture PageToRemove %}{{ PageParameter.DataViewId }}|{% endcapture %}
        {% assign newFavorites = CurrentPerson | GetUserPreference:'MyFavoriteDVs' | Remove: PageToRemove %}
        {{ CurrentPerson | SetUserPreference:'MyFavoriteDVs',newFavorites }}
    {% elseif PageParameter.Action == 'Set' %}
        {% capture PageToRemove %}{{ PageParameter.DataViewId }}|{% endcapture %}
        {% assign safeFavorites = CurrentPerson | GetUserPreference:'MyFavoriteDVs' | Remove: PageToRemove %}
        {% capture newFavorites %}{{ safeFavorites }}{{ PageParameter.DataViewId }}|{% endcapture %}
        {{ CurrentPerson | SetUserPreference:'MyFavoriteDVs',newFavorites }}
    {% endif %}
    {% capture goback %}/page/145?DataViewId={{ PageParameter.DataViewId }}{% endcapture %}
    {{ goback | PageRedirect }}
{% endif %}

{% if PageParameter.ReportId %} {% assign currpref = CurrentPerson | GetUserPreference:'MyFavoriteReports' %} {% assign currprefLength = currpref | Size %} {% if currprefLength < 1 %}{{ CurrentPerson | SetUserPreference:'MyFavoriteReports','|' }}{% endif %} {% if PageParameter.Action == 'Unset' %} {% capture PageToRemove %}{{ PageParameter.ReportId }}|{% endcapture %} {% assign newFavorites = CurrentPerson | GetUserPreference:'MyFavoriteReports' | Remove: PageToRemove %} {{ CurrentPerson | SetUserPreference:'MyFavoriteReports',newFavorites }} {% elseif PageParameter.Action == 'Set' %} {% capture PageToRemove %}{{ PageParameter.ReportId }}|{% endcapture %} {% assign safeFavorites = CurrentPerson | GetUserPreference:'MyFavoriteReports' | Remove: PageToRemove %} {% capture newFavorites %}{{ safeFavorites }}{{ PageParameter.ReportId }}|{% endcapture %} {{ CurrentPerson | SetUserPreference:'MyFavoriteReports',newFavorites }} {% endif %} {% capture goback %}/page/149?ReportId={{ PageParameter.ReportId }}{% endcapture %} {{ goback | PageRedirect }} {% endif %}

(Most Rock installations have Data View at /page/145 and Reports at /page/149 - if that's not the case for you, you'll need to update that path at the bottom of each of those two code blocks).

Now, take note of this new page's ID by looking at the address bar. My page, for instance, is rock.rocksolidchurchdemo.com/page/715. I'm going to need that number (715) in the rest of this article.


Now it's time to go to your Data View page. Click the "Zones" button on the admin toolbar, and then on the Sidebar 1 flyout that appears above the list of Data Views, click the "Blocks" button.

You'll see the default "Category Tree" block here. Click the (+) button to add a new block. Call it "Favorite Data Views" and make it an HTML Content block.

Once you click "Done", drag it above the Category Tree block

FavoriteDataViewBlock.PNG

Now click "Done" again and the page will reload.

On the Admin Toolbar, click "Blocks" and on the Block Properties menu, enable "RockEntity" Lava Commands.

Click Save, and then using the block flyout menu again, get into "Edit HTML"

Here's your content for that block:

<h4><span class="label label-default"><i class="fa fa-star"></i> My favorite Dataviews:</span></h4>
{% assign favs = CurrentPerson | GetUserPreference:'MyFavoriteDVs' | Split:'|' %}
{% for fav in favs %}
    {% assign valid = fav | Size %}
    {% if valid > 0 %}
        {% dataview where:'Id == "{{ fav }}"' %}
            <a href="/page/{{ PageParameter.PageId }}?DataViewId={{ dataview.Id }}&ExpandedIds=C{{ dataview.Category.Id }}">{{ dataview.Name }}</a><br />
        {% enddataview %}
    {% endif %}
{% endfor %}
<br />

So far so good. Now you'll see where their favorite dataviews will be listed.

One step left: Get into the Block Settings for the Data Views block, and flip over to the Advanced Settings tab.

Add this to Post-HTML:

{% if PageParameter.DataViewId > 0 %}
    {% capture pattern %}\|{{ PageParameter.DataViewId }}\|{% endcapture %}
    {% assign IsFav = CurrentPerson | GetUserPreference:'MyFavoriteDVs' | RegExMatch:pattern %}
    {% if IsFav %}
        <script>$('div.actions').append('<a href="/page/715?DataViewId={{ PageParameter.DataViewId }}&Action=Unset" class="btn btn-default"><i class="fa fa-star-exclamation"></i> Un-Favorite</a>');</script>
    {% else %}
        <script>$('div.actions').append('<a href="/page/715?DataViewId={{ PageParameter.DataViewId }}&Action=Set" class="btn btn-default"><i class="fa fa-star"></i> Favorite</a>');</script>
    {% endif %}
{% endif %}

Remember where I had you remember the PageId of the page we created at the beginning? Use that number to replace both places I list 715 in this code (highlighted in red).

Save, and the dialogue will close.

Reload the page, and you'll see that your DataViews have a new "Favorite" button next to the "Edit" button:

FavoriteDataViewButton.PNG

Best of all, it works! Click the button and you'll see this dataview added to your "Favorites" list on the left, and the button changes to an "Un-Favorite" button.

And everyone's favorites menu is personal to them; when you mark a dataview as a favorite, your pastor won't see it on his favorites menu, and vice-versa.

FavoriteList.PNG


So, let's do the same thing for Reports


Load the Reports page. Add another block above the list of reports, enable RockEntity commands, and add this content:

<h4><span class="label label-default"><i class="fa fa-star"></i> My favorite Reports:</span></h4>
{% assign favs = CurrentPerson | GetUserPreference:'MyFavoriteReports' | Split:'|' %}
{% for fav in favs %}
{% assign valid = fav | Size %}
{% if valid > 0 %}
{% report where:'Id == "{{ fav }}"' %}
<a href="/page/{{ PageParameter.PageId }}?ReportId={{ report.Id }}&ExpandedIds=C{{ report.Category.Id }}">{{ report.Name }}</a><br />
{% endreport %}
{% endif %}
{% endfor %}
<br />


Then in the Report Detail block Advanced Settings, here is your Post-HTML:

{% if PageParameter.ReportId > 0 %}
    {% capture pattern %}\|{{ PageParameter.ReportId }}\|{% endcapture %}
    {% assign IsFav = CurrentPerson | GetUserPreference:'MyFavoriteReports' | RegExMatch:pattern %}
    {% if IsFav %}
        <script>$('div.actions').append('<a href="/page/715?ReportId={{ PageParameter.ReportId }}&Action=Unset" class="btn btn-default"><i class="fa fa-star-exclamation"></i> Un-Favorite</a>');</script>
    {% else %}
        <script>$('div.actions').append('<a href="/page/715?ReportId={{ PageParameter.ReportId }}&Action=Set" class="btn btn-default"><i class="fa fa-star"></i> Favorite</a>');</script>
    {% endif %}
{% endif %}

Once again, replace the two red 715 numbers in this markup with the actual Page ID of the new page we created at the beginning of this exercise.

That's it!


Now, never tell your staff how easy this was to do... you're a hero!


@mikejed
Spark Development Network
Flagstaff, AZ

Michael Garrison recently left his job in Architecture to become one of the "new guys" at Spark (the "Core Team"), but he's still helping out Christ's Church of Flagstaff and other non-profits with tech needs in his off-hours, trying to make computers do what computers do best, so that people are freed to do what we do best: relate with people!