Blame view

controllets/filters-controllet/filters-controllet.html 8.32 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">
  
39d5ab70   Renato De Donato   update filters
109
              <div id="filters_header" class="filters_header" on-click="_showFiltersPanel"><span id="filters">ADD FILTERS</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
119
120
121
122
123
124
125
                                      <template is="dom-repeat" items={{fields}}>
                                          <paper-item id={{index}} on-tap="">{{_fieldName(item)}}</paper-item>
                                      </template>
                                  </paper-menu>
                              </paper-dropdown-menu>
                          </th>
                          <th>
                              <paper-dropdown-menu id="filter_operation" label="Operation">
39d5ab70   Renato De Donato   update filters
126
                                  <paper-menu id="filter_operation_menu" class="dropdown-content">
0af843be   Renato De Donato   filters + alasql
127
128
129
130
131
132
133
                                      <template is="dom-repeat" items={{operations}}>
                                          <paper-item id={{index}} on-tap="">{{item}}</paper-item>
                                      </template>
                                  </paper-menu>
                              </paper-dropdown-menu>
                          </th>
                          <th>
39d5ab70   Renato De Donato   update filters
134
                              <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
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
                          </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
171
                      value : ["=", "!=", ">", ">=", "<", "<=", "contains", "start", "ends"]
0af843be   Renato De Donato   filters + alasql
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
                  },
  
                  filters : {
                      type : Array,
                      value : []
                  },
  
                  show : {
                      type  : Boolean,
                      value : false
                  }
  
              },
  
              ready : function() {
                  $(this.$.filters_panel).perfectScrollbar();
              },
  
0af843be   Renato De Donato   filters + alasql
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
              setFields : function(fields) {
                  this.fields = this._copy(fields);
              },
  
              getFilters : function() {
                  return this.filters;
              },
  
              _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() {
0af843be   Renato De Donato   filters + alasql
218
219
220
221
222
                  var field = this.$.filter_field.value;
                  var operation = this.$.filter_operation.value;
                  var value = this.$.filter_value.value;
  
                  var filters = this.filters;
98d9d8a5   Renato De Donato   filters+groupby
223
                  filters.push({"field": field, "operation": operation, "value": value});
0af843be   Renato De Donato   filters + alasql
224
                  this.filters = this._copy(filters);
98d9d8a5   Renato De Donato   filters+groupby
225
  
39d5ab70   Renato De Donato   update filters
226
227
228
229
                  this.$.filter_field_menu.select(-1);
                  this.$.filter_operation_menu.select(-1);
                  this.$.filter_value.value = "";
  
98d9d8a5   Renato De Donato   filters+groupby
230
                  this.fire('filters-controllet_filters', {filters: this.filters});
0af843be   Renato De Donato   filters + alasql
231
232
233
234
235
236
237
238
              },
  
              _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
239
240
  
                  this.fire('filters-controllet_filters', {filters: this.filters});
0af843be   Renato De Donato   filters + alasql
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
              },
  
              _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>