My Searches Widget

The My Searches widget displays Search Builders queries that the user has saved or searches an Admin has saved in the user’s name.

The widget utilizes an HTML file, SQL script and Python script as shown below. Since the saved searches list is different for each user, Caching should be set to each user.

HTML Code

Below is the HTML code for the My Searches widget. As supplied by TouchPoint, the file name is WidgetSearchesHTML.

 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
<div class="box">
    <div class="box-title hidden-xs">
        <h5><a href="/SavedQueryList">{{WidgetName}}</a></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>
            {{#ifGT results.Count 0}}
                <div class="pull-right">
                    <span class="badge badge-primary">{{results.Count}}</span>
                </div>
            {{/ifGT}}
        </div>
    </a>
    <div class="collapse in" id="{{WidgetId}}-section">
        {{#ifGT results.Count 0}}
            <ul class="list-group">
                {{#each results}}
                    <li class="list-group-item"><a href="/Query/{{QueryId}}">{{Name}}</a></li>
                {{/each}}
            </ul>
        {{else}}
            <div class="box-content"></div>
        {{/ifGT}}
    </div>
</div>

SQL Script

Below is the SQL script for the My Searches widget. As supplied by TouchPoint, the file name is WidgetSearchesSQL.

1
2
3
4
select QueryId, Name from Query
where owner like @uname
and Name != 'scratchpad'
order by Name

Python Script

Below is the Python script for the My Searches widget. As supplied by TouchPoint, the file name is WidgetSearchesPython.

1
2
3
4
5
6
7
8
def Get():
    sql = Data.SQLContent
    template = Data.HTMLContent
    params = { 'uname': Data.CurrentUser.Username }
    Data.results = q.QuerySql(sql, params)
    print model.RenderTemplate(template)

Get()


Latest Update 04/30/2020

Added this article.

© 2020 TouchPoint Software, LLC.  All rights reserved.