Blame view

controllets/filters-controllet/filters-controllet.html 9.58 KB
0af843be   Renato De Donato   filters + alasql
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
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
  <link rel="import" href="../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
  <link rel="import" href="../../bower_components/paper-menu/paper-menu.html">
  <link rel="import" href="../../bower_components/paper-item/paper-item.html">
  
  <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
  <link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
  <link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
  
  <dom-module id="filters-controllet">
  
      <template>
  
          <style is="custom-style">
  
              :host {
              --paper-dropdown-menu-icon: {
                   color: #2196F3;
               };
              }
  
              #filters_container {
                  height: 100%;
                  width: 100%;
  
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
              }
  
              #filters_panel {
                  display: none;
                  position: relative;
                  height: calc(100% - 48px);
              }
  
              .filters_header {
                  height: 32px;
                  padding-top: 16px;
                  text-align: center;
                  font-weight: 700;
  
                  color: #00BCD4;
                  cursor: pointer;
              }
  
              paper-dropdown-menu {
                  height: 48px;
                  width: 248px;;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
              paper-icon-button {
                  color: #2196F3;
                  --paper-icon-button-ink-color: #2196F3;
                  margin: 0px;
              }
  
              paper-icon-button.cancel {
                  color: #F44336;
                  --paper-icon-button-ink-color: #F44336;
                  margin-bottom: -6px;
                  margin-left: -8px;
              }
              paper-icon-button.add {
                  margin-bottom: -6px;
                  margin-left: -8px;
              }
  
              paper-input {
                  display: inline-block;
                  height: 48px;
                  width: 248px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              td {
                  height: 48px;
                  padding: 0px;
                  padding-bottom: 4px;
                  margin: 0px;
                  width: 248px;
                  border-bottom: 1px solid  #2196F3;
                  vertical-align: bottom;
              }
  
              th {
                  height: 48px;
                  padding: 0px;
                  margin: 0px;
                  vertical-align: bottom;
                  text-align: left ;
              }
  
              .filters_cell_button {
                  width: 24px;
                  border-bottom: none;
              }
  
      </style>
  
          <div id="filters_container">
  
e94f9513   Renato De Donato   filter ln
109
              <div id="filters_header" class="filters_header" on-click="_showFiltersPanel"><span id="filters"><span id="addFilters"></span></span></div>
0af843be   Renato De Donato   filters + alasql
110
111
112
113
114
115
116
  
              <div id="filters_panel">
  
                  <table cellspacing="12px">
                      <tr>
                          <th>
                              <paper-dropdown-menu id="filter_field" label="Field">
39d5ab70   Renato De Donato   update filters
117
                                  <paper-menu id="filter_field_menu" class="dropdown-content">
0af843be   Renato De Donato   filters + alasql
118
                                      <template is="dom-repeat" items={{fields}}>
e94f9513   Renato De Donato   filter ln
119
120
                                          <paper-item id={{index}}>{{_fieldName(item)}}</paper-item>
                                          <!--on-tap=""-->
0af843be   Renato De Donato   filters + alasql
121
122
123
124
125
126
                                      </template>
                                  </paper-menu>
                              </paper-dropdown-menu>
                          </th>
                          <th>
                              <paper-dropdown-menu id="filter_operation" label="Operation">
39d5ab70   Renato De Donato   update filters
127
                                  <paper-menu id="filter_operation_menu" class="dropdown-content">
0af843be   Renato De Donato   filters + alasql
128
                                      <template is="dom-repeat" items={{operations}}>
e94f9513   Renato De Donato   filter ln
129
                                          <paper-item id={{index}}>{{_getOperationlName(item)}}</paper-item>
0af843be   Renato De Donato   filters + alasql
130
131
132
133
134
                                      </template>
                                  </paper-menu>
                              </paper-dropdown-menu>
                          </th>
                          <th>
39d5ab70   Renato De Donato   update filters
135
                              <paper-input id="filter_value" label="Value" class="base_input" maxlength="16" auto-validate pattern="^[_a-zA-Z0-9]*" error-message="Invalid value!"></paper-input>
0af843be   Renato De Donato   filters + alasql
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
                          </th>
                          <th class="filters_cell_button">
                              <paper-icon-button on-click="_addFilter" icon="add-circle" class="add"></paper-icon-button>
                          </th>
                      </tr>
                      <template is="dom-repeat" items={{filters}}>
                          <tr>
                              <td>{{item.field}}</td>
                              <td>{{item.operation}}</td>
                              <td class="filters_cell_value">{{item.value}}</td>
                              <td class="filters_cell_button"><paper-icon-button on-click="_deleteFilter" icon="cancel" class="cancel"></paper-icon-button></td>
                          </tr>
                      </template>
                  </table>
  
              </div>
  
          </div>
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'filters-controllet',
  
              properties : {
  
                  fields : {
                      type : Array,
                      value : []
                  },
  
                  operations : {
                      type : Array,
98d9d8a5   Renato De Donato   filters+groupby
172
                      value : ["=", "!=", ">", ">=", "<", "<=", "contains", "start", "ends"]
0af843be   Renato De Donato   filters + alasql
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
                  },
  
                  filters : {
                      type : Array,
                      value : []
                  },
  
                  show : {
                      type  : Boolean,
                      value : false
                  }
  
              },
  
              ready : function() {
                  $(this.$.filters_panel).perfectScrollbar();
              },
  
e94f9513   Renato De Donato   filter ln
191
192
193
194
              attached : function() {
                  this._translate();
              },
  
0af843be   Renato De Donato   filters + alasql
195
196
197
198
199
200
201
202
              setFields : function(fields) {
                  this.fields = this._copy(fields);
              },
  
              getFilters : function() {
                  return this.filters;
              },
  
e94f9513   Renato De Donato   filter ln
203
204
205
206
207
208
209
              _translate : function() {
                  this.$.addFilters.innerHTML = ln["addFilters_" + ln["localization"]];
                  this.$.filter_field.setAttribute("label", ln["filterField_" + ln["localization"]]);
                  this.$.filter_operation.setAttribute("label", ln["filterOperation_" + ln["localization"]]);
                  this.$.filter_value.setAttribute("label", ln["filterValue_" + ln["localization"]]);
              },
  
0af843be   Renato De Donato   filters + alasql
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
              _fieldName : function(field) {
                  return field.substring(field.lastIndexOf(",")+1, field.length);
              },
  
              _showFiltersPanel : function() {
                  if(!this.show) {
                      this.$.filters_header.style.color = "#000000";
                      this.$.filters_header.style.background = "#B6B6B6";
                      this.$.filters_panel.style.display = "block";
                  }
                  else {
                      this.$.filters_header.style.color = "#00BCD4";
                      this.$.filters_header.style.background = "#FFFFFF";
                      this.$.filters_panel.style.display = "none";
                  }
  
                  this.show = !this.show;
              },
  
              _addFilter : function() {
e94f9513   Renato De Donato   filter ln
230
231
232
233
                  if (this.$.filter_field.selectedItem && this.$.filter_operation_menu.selectedItem && this.$.filter_value.value != "" && !this.$.filter_value.invalid) {
                      var field = this.$.filter_field.value;
                      var operation = this.$.filter_operation.value;
                      var value = this.$.filter_value.value;
0af843be   Renato De Donato   filters + alasql
234
  
e94f9513   Renato De Donato   filter ln
235
236
237
                      var filters = this.filters;
                      filters.push({"field": field, "operation": operation, "value": value});
                      this.filters = this._copy(filters);
98d9d8a5   Renato De Donato   filters+groupby
238
  
e94f9513   Renato De Donato   filter ln
239
240
241
                      this.$.filter_field_menu.select(-1);
                      this.$.filter_operation_menu.select(-1);
                      this.$.filter_value.value = "";
39d5ab70   Renato De Donato   update filters
242
  
e94f9513   Renato De Donato   filter ln
243
244
                      this.fire('filters-controllet_filters', {filters: this.filters});
                  }
0af843be   Renato De Donato   filters + alasql
245
246
247
248
249
250
251
252
              },
  
              _deleteFilter : function(e) {
                  var index = e.model.index;
  
                  var filters = this.filters;
                  filters.splice(index, 1);
                  this.filters = this._copy(filters);
98d9d8a5   Renato De Donato   filters+groupby
253
254
  
                  this.fire('filters-controllet_filters', {filters: this.filters});
0af843be   Renato De Donato   filters + alasql
255
256
              },
  
e94f9513   Renato De Donato   filter ln
257
258
259
260
261
262
263
264
265
266
              _getOperationlName: function(operation) {
                  if(operation.indexOf("contains") > -1)
                      return ln["contains_" + ln["localization"]];
                  if(operation.indexOf("start") > -1)
                      return ln["start_" + ln["localization"]];
                  if(operation.indexOf("ends") > -1)
                      return ln["ends_" + ln["localization"]];
                  return operation;
              },
  
0af843be   Renato De Donato   filters + alasql
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
              _copy : function(o) {
                  var out, v, key;
                  out = Array.isArray(o) ? [] : {};
                  for (key in o) {
                      v = o[key];
                      out[key] = (typeof v === "object") ? this._copy(v) : v;
                  }
                  return out;
              }
  
          });
  
      </script>
  
  </dom-module>