aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/main/resources/rest/options.ftl
blob: e1c904d03e5f6d5f42ab86a289ff5cf14dadd4f8 (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
<#--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<#include "*/generic.ftl">
<#macro page_head>
    <script type="text/javascript" language="javascript"  src="/static/js/jquery.dataTables-1.10.16.min.js"> </script>
    <script type="text/javascript" language="javascript" src="/static/js/dataTables.colVis-1.1.0.min.js"></script>
    <script>
    //Alter System Values
    function alterSysOption(optionName, optionValue, optionKind) {
        var currHref = location.href;
        var redirectHref = currHref.replace(/(.?filter=).*/,"");
        //Read filter value and apply to reload with new filter
        var reApplyFilter = $("#searchBox").val();
        if (reApplyFilter != null && reApplyFilter.trim().length > 0) {
            redirectHref = redirectHref + "?filter=" + reApplyFilter.trim();
        } else { //Apply filter for updated field
            redirectHref = redirectHref + "?filter=" + optionName;
        }
        $.post("/option/"+optionName, {kind: optionKind, name: optionName, value: optionValue}, function () {
            //Remove existing filters
            location.href=redirectHref;
        });
    }

    //Read Values and apply
    function alterSysOptionUsingId(optionRawName) {
        //Escaping '.' for id search
        let optionName = optionRawName.replace(/\./gi, "\\.");
        //Extracting datatype from the form
        let optionKind = $("#"+optionName+" input[name='kind']").attr("value");
        //Extracting value from the form's INPUT element
        let optionValue = $("#"+optionName+" input[name='value']").val();
        if (optionKind == "BOOLEAN") {
            //Extracting boolean value from the form's SELECT element (since this is a dropdown input)
            optionValue = $("#"+optionName+" select[name='value']").val();
        } else if (optionKind != "STRING") { //i.e. it is a number (FLOAT/DOUBLE/LONG)
            if (isNaN(optionValue)) {
                alert(optionValue+" is not a valid number for option: "+optionName);
                return;
            }
        }
        alterSysOption(optionRawName, optionValue, optionKind);
    }
    </script>
    <!-- List of Option Descriptions -->
    <script src="/dynamic/options.describe.js"></script>
    <link href="/static/css/dataTables.colVis-1.1.0.min.css" rel="stylesheet">
    <link href="/static/css/dataTables.jqueryui.css" rel="stylesheet">
    <link href="/static/css/jquery-ui-1.10.3.min.css" rel="stylesheet">
    <link href="/static/css/drill-dataTables.sortable.css" rel="stylesheet">
</#macro>

<#macro page_body>
  <div class="page-header">
  </div>
  <div class="col-xs-4">
    <div class="input-group input-sm" >
      <input id="searchBox" name="searchBox" class="form-control" type="text" value="" placeholder="Search options...">
        <div class="input-group-btn">
          <button class="btn btn-default" type="button" onclick="$('#searchBox').val('').focus();" title="Clear search" style="font-weight:bold">&times;</button>
        </div> 
    </div>
  </div>
  <div class="btn-group btn-group-sm" style="padding-top:0.5%;">
  <button type="button" class="btn" style="cursor:default;font-weight:bold;" > Quick Filters </button>
  <#list model.getFilters() as filter>
  <button type="button" class="btn btn-info" onclick="inject(this.innerHTML);">${filter}</button>
  </#list>
  </div>

  <div class="table-responsive">
    <table id='optionsTbl' class="table table-striped table-condensed display sortable" style="table-layout: auto; width=100%;">
      <thead>
        <tr>
          <th style="width:30%">OPTION</th>
          <th style="width:25%">VALUE</th>
          <th style="width:45%">DESCRIPTION</th>
        </tr>
      </thead>
      <tbody><#assign i = 1><#list model.getOptions() as option>
          <tr id="row-${i}">
            <td style="font-family:Courier New; vertical-align:middle" id='optionName'>${option.getName()}</td>
            <td>
              <form class="form-inline" role="form" id="${option.getName()}">
                <div class="form-group">
                <input type="hidden" class="form-control" name="kind" value="${option.getKind()}">
                <input type="hidden" class="form-control" name="name" value="${option.getName()}">
                  <div class="input-group input-sm">
                  <#if option.getKind() == "BOOLEAN" >
                  <select class="form-control" name="value">
                    <option value="false" ${(option.getValueAsString() == "false")?string("selected", "")}>false</option>
                    <option value="true" ${(option.getValueAsString() == "true")?string("selected", "")}>true</option>
                  </select>
                  <#else>
                    <input type="text" class="form-control" placeholder="${option.getValueAsString()}" name="value" value="${option.getValueAsString()}">
                  </#if>
                    <div class="input-group-btn">
                      <button class="btn btn-default" type="button" onclick="alterSysOptionUsingId('${option.getName()}')">Update</button>
                      <button class="btn btn-default" type="button" onclick="alterSysOption('${option.getName()}','${option.getDefaultValue()}', '${option.getKind()}')" <#if option.getDefaultValue() == option.getValueAsString()>disabled="true" style="pointer-events:none" <#else>
                      title="Reset to ${option.getDefaultValue()}"</#if>>Default</button>
                    </div>
                  </div>
                </div>
              </form>
            </td>
            <td id='description'></td>
          </tr>
          <#assign i = i + 1>
        </#list>
      </tbody>
    </table>
  </div>
  <script>
   //Defining the DataTable with a handle
   var optTable = $('#optionsTbl').DataTable( {
        "lengthChange": false,
         "pageLength": -1,
        "dom": 'lrit',
        "jQueryUI" : true,
        "searching": true,
        "language": {
            "lengthMenu": "Display _MENU_ records per page",
            "zeroRecords": "No matching options found. Check search entry",
            "info": "Found _END_ matches out of _MAX_ options",
            "infoEmpty": "No options available",
            "infoFiltered": ""
        }
      });

    //Draw when the table is ready
    $(document).ready(function() {
      //Inject Descriptions for table
      let size = $('#optionsTbl tbody tr').length;
      for (i = 1; i <= size; i++) {
        let currRow = $("#row-"+i);
        let optionName = currRow.find("#optionName").text();
        let setOptDescrip = currRow.find("#description").text(getDescription(optionName));
      }

      // Draw DataTable
      optTable.rows().invalidate().draw();

      //Re-Inject Filter keyword here
      let explicitFltr = "";
      if (window.location.search.indexOf("filter=") >= 1) {
        //Select 1st occurrence (Chrome accepts 1st of duplicates)
        let kvPair=window.location.search.substr(1).split('&')[0];
        explicitFltr=kvPair.split('=')[1]
        inject(explicitFltr);
      }
    });

    //EventListener to update table when changes are detected
    $('#searchBox').on('keyup focus change', function () {
      optTable.search(this.value).draw().toString();
    });

    //Inject word and force table redraw
    function inject(searchTerm) {
      $('#searchBox').val(searchTerm);
      optTable.search(searchTerm).draw().toString();
    }
  </script>
</#macro>
<@page_html/>