aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/templates/gsearch_pheno.html
blob: af9740ae06ae70771a33f222d6222db44fcccfc0 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
{% extends "base.html" %}
{% block title %}Search Results{% endblock %}
{% block css %}
    <link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='DataTables/css/jquery.dataTables.css') }}" />
    <link rel="stylesheet" type="text/css" href="/static/new/css/show_trait.css" />
{% endblock %}
{% block content %}
<!-- Start of body -->

    <div class="container">

        <h3>GN searched for the term(s) <b>"{{ terms }}"</b> in 51 datasets and 13763 traits across 10 species<br/>
            and found <b>{{ trait_count }}</b> results that match your query.<br/>
            You can filter these results by adding key words in the fields below<br/>
            and you can also sort results on most columns.</h3>
        <p>To study a record, click on its ID below.<br />Check records below and click Add button to add to selection.</p>

        <div>
            <br />
            <button class="btn btn-default" id="select_all"><span class="glyphicon glyphicon-ok"></span> Select All</button>
            <button class="btn btn-default" id="deselect_all"><span class="glyphicon glyphicon-remove"></span> Deselect All</button>
            <button class="btn btn-default" id="invert"><span class="glyphicon glyphicon-resize-vertical"></span> Invert</button>
            <button class="btn btn-success" id="add" disabled ><span class="glyphicon glyphicon-plus-sign"></span> Add</button>
            <input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ...">
            <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ...">
            <form id="export_form" method="POST" action="/export_traits_csv" style="display: inline;">
              <input type="hidden" name="headers" id="headers" value="{% for field in header_fields %}{{ field }},{% endfor %}">
              <input type="hidden" name="database_name" id="database_name" value="None">
              <input type="hidden" name="export_data" id="export_data" value="">
              <button class="btn btn-default" id="export_traits">Download CSV</button>
            </form>
            <br />
            <br />
            <div style="min-width: 2000px; width: 100%;">
              <table id="trait_table" class="table-hover table-striped cell-border" style="float: left;">
                <tbody>
                 <td colspan="100%" align="center"><br><b><font size="15">Loading...</font></b><br></td>
                </tbody>
            </table>
            </div>
        </div>
    </div>

<!-- End of body -->

{% endblock %}

{% block js %}
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='js_alt/md5.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.dataTables.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='jszip/jszip.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/plugins/sorting/natural.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/colReorder/js/dataTables.colReorder.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/colResize/dataTables.colResize.js') }}"></script>
    <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script>

    <script type='text/javascript'>
      var getParams = function(url) {
        let parser = document.createElement('a');
        parser.href = url;
        let params = parser.search.substring(1);
        if(params.length > 0) {
          return ('?'+params);
        }
        return params;
      };
    </script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready( function () {

            $('#trait_table tr').click(function(event) {
                if (event.target.type !== 'checkbox') {
                    $(':checkbox', this).trigger('click');
                }
            });

            function change_buttons() {
                buttons = ["#add", "#remove"];
                num_checked = $('.trait_checkbox:checked').length;
                if (num_checked === 0) {
                    for (_i = 0, _len = buttons.length; _i < _len; _i++) {
                        button = buttons[_i];
                        $(button).prop("disabled", true);
                    }
                } else {
                    for (_j = 0, _len2 = buttons.length; _j < _len2; _j++) {
                        button = buttons[_j];
                        $(button).prop("disabled", false);
                    }
                }
                         //});
                if ($(this).is(":checked")) {
                    if (!$(this).closest('tr').hasClass('selected')) {
                        $(this).closest('tr').addClass('selected')
                    }
                }
                else {
                    if ($(this).closest('tr').hasClass('selected')) {
                        $(this).closest('tr').removeClass('selected')
                    }
                }
            }

            console.time("Creating table");
            $('#trait_table').DataTable( {
                'drawCallback': function( settings ) {
                     $('#trait_table tr').click(function(event) {
                         if (event.target.type !== 'checkbox' && event.target.tagName.toLowerCase() !== 'a') {
                             $(':checkbox', this).trigger('click');
                         }
                     });
                     $('.trait_checkbox:checkbox').on("change", change_buttons);
                },
                "createdRow": function ( row, data, index ) {
                    $('td', row).eq(0).attr("style", "text-align: center; padding: 4px 10px 2px 10px;");
                    $('td', row).eq(1).attr("align", "right");
                    $('td', row).eq(5).attr('title', $('td', row).eq(5).text());
                    if ($('td', row).eq(5).text().length > 150) {
                        $('td', row).eq(5).text($('td', row).eq(5).text().substring(0, 150));
                        $('td', row).eq(5).text($('td', row).eq(5).text() + '...')
                    }
                    $('td', row).eq(6).attr('title', $('td', row).eq(6).text());
                    if ($('td', row).eq(6).text().length > 150) {
                        $('td', row).eq(6).text($('td', row).eq(6).text().substring(0, 150));
                        $('td', row).eq(6).text($('td', row).eq(6).text() + '...')
                    }
                    $('td', row).eq(6).attr("align", "right");
                    $('td', row).slice(8,11).attr("align", "right");
                    $('td', row).eq(1).attr('data-export', $('td', row).eq(1).text());
                    $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text());
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text());
                    $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text());
                    $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text());
                    $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text());
                    $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text());
                    $('td', row).eq(9).attr('data-export', $('td', row).eq(9).text());
                    $('td', row).eq(10).attr('data-export', $('td', row).eq(10).text());
                },
                'columns': [
                    {
                      'data': null,
                      'orderDataType': "dom-checkbox",
                      'render': function(data, type, row, meta) {
                        return '<input type="checkbox" name="searchResult" class="trait_checkbox checkbox" value="' + data.hmac + '">'
                      }
                    },
                    {
                      'title': "Index",
                      'type': "natural",
                      'data': "index"
                    },
                    {
                      'title': "Species",
                      'type': "natural",
                      'data': "species"
                    },
                    {
                      'title': "Group",
                      'type': "natural",
                      'width': "10%",
                      'data': "group"
                    },
                    {
                      'title': "Record",
                      'type': "natural",
                      'data': null,
                      'orderDataType': "dom-inner-text",
                      'render': function(data, type, row, meta) {
                        return '<a target="_blank" href="/show_trait?trait_id=' + data.name + '&dataset=' + data.dataset + '">' + data.display_name + '</a>'
                      }
                    },
                    {
                      'title': "Description",
                      'type': "natural",
                      'width': "25%",
                      'data': null,
                      'render': function(data, type, row, meta) {
			                  try {
                            return decodeURIComponent(escape(data.description))
			                  } catch(err) {
			                      return data.description
                        }
                      }
                    },
                    {
                      'title': "Mean",
                      'type': "natural-minus-na",
                      'width': "10%",
                      'data': "mean"
                    },
                    {
                      'title': "Authors",
                      'type': "natural",
                      'width': "25%",
                      'data': null,
                      'render': function(data, type, row, meta) {
                        author_list = data.authors.split(",")
                        if (author_list.length >= 6) {
                          author_string = author_list.slice(0, 6).join(",") + ", et al."
                        } else{
                          author_string = data.authors
                        }

			                  try {
                            return decodeURIComponent(escape(author_string))
			                  } catch(err) {
			                      return author_string
                        }

                      }
                    },
                    {
                      'title': "Year",
                      'type': "natural-minus-na",
                      'data': null,
                      'orderDataType': "dom-inner-text",
                      'render': function(data, type, row, meta) {
                        if (data.pubmed_id != "N/A"){
                          return '<a href="' + data.pubmed_link + '">' + data.pubmed_text + '</a>'
                        } else {
                          return data.pubmed_text
                        }
                      },
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "Max LRS<a href=\"{{ url_for('glossary_blueprint.glossary') }}#LRS\" target=\"_blank\" style=\"color: white;\"><sup>?</sup></a>",
                      'type': "natural-minus-na",
                      'data': "LRS_score_repr",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "Max LRS Location",
                      'type': "natural-minus-na",
                      'width': "10%",
                      'data': "max_lrs_text"
                    },
                    {
                      'title': "Additive Effect<a href=\"{{ url_for('glossary_blueprint.glossary') }}#A\" target=\"_blank\" style=\"color: white;\"><sup>?</sup></a>",
                      'type': "natural-minus-na",
                      'data': "additive",
                      'orderSequence': [ "desc", "asc"]
                    }
                ],
                'order': [[1, "asc" ]],
                'sDom': "pitirp",
                'autoWidth': false,
                'deferRender': false,
                'paging': true,
                'orderClasses': true,
                'processing': true,
                'iDisplayLength': 100,
                'bServerSide': true,
                'sAjaxSource': '/gsearch_table'+getParams(window.location.href),
                'language': {
                  'loadingRecords': '&nbsp;',
                  'processing': 'Loading...'
                }
            } );

            $('#trait_table').append(
              '<tfoot>' +
                '<tr>' +
                  '<th></th>' +
                  '<th>Index</th>' +
                  '<th>Species</th> ' +
                  '<th>Group</th>' +
                  '<th>Record</th>' +
                  '<th>Description</th>' +
                  '<th>Authors</th>' +
                  '<th>Year</th>' +
                  '<th>Max LRS</th>' +
                  '<th>Max LRS Location</th>' +
                  '<th>Additive Effect</th>' +
                '</tr>' +
              '</tfoot>'
            );

            console.timeEnd("Creating table");
        });
        
    </script>
    <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script>
{% endblock %}