active_admin_filters_visibility 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba40a984e58c7a130d4095d252e8cca24ae6fc61a113ddcf0e47054e50e0dff2
4
+ data.tar.gz: 17b98e349a820b26b492fa09d5b5aef630fabeb86034558f9ac6fcb0cd3f9e68
5
+ SHA512:
6
+ metadata.gz: 2cb4576be45526b17a2ac122288316f19a86fa9aa91e80bea89caa02af212d10974d95c1151b41da48c72dfae2a85a0be46ffd5dc9a7225c371d4aa8bea2e575
7
+ data.tar.gz: 47dd06a5e6c3828607d4e9049350275a0793d0efc4c0ccdca11fe1e62772898809c4bf26d4514a49d8dd159178a5f6c9d602596cbb563089b4a75c12637dd26c
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Gena M. <workgena@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,145 @@
1
+ # ActiveAdminFiltersVisibility
2
+
3
+ ActiveAdmin plugin allows to hide any filter from Filters Sidebar.
4
+ Useful when page has many filters, but admin user needs only some of them.
5
+ Every filter saves its state using browser's LocalStorage.
6
+
7
+ ![Demonstration](https://raw.githubusercontent.com/activeadmin-plugins/active_admin_filters_visibility/master/screen/example_aa_filters_visibility.gif "Visibility example")
8
+
9
+ Also you can use drag&drop to change filters order
10
+
11
+ ![Demonstration](https://raw.githubusercontent.com/activeadmin-plugins/active_admin_filters_visibility/master/screen/example_aa_filters_ordering.gif "Ordering example")
12
+
13
+ ## Install
14
+
15
+ In Gemfile add
16
+
17
+ ```ruby
18
+ gem 'active_admin_filters_visibility', git: 'https://github.com/activeadmin-plugins/active_admin_filters_visibility'
19
+ ```
20
+
21
+ in the
22
+ ```
23
+ app/assets/javascript/active_admin.coffee
24
+ ```
25
+
26
+ and
27
+
28
+ ```coffeescript
29
+ #= require active_admin_filters_visibility
30
+ ```
31
+
32
+ and initialize it with:
33
+
34
+ ```javascript
35
+ $(document).ready(function() {
36
+ $('#filters_sidebar_section').activeAdminFiltersVisibility();
37
+ });
38
+ ```
39
+
40
+ ## Customization
41
+
42
+ ```coffeescript
43
+ $('.jquery-selector').activeAdminFiltersVisibility(options)
44
+ ```
45
+
46
+ ActiveAdminFiltersVisibility is a standard jQuery Plugin, and accepts some "options" as a hash.
47
+ Default is:
48
+
49
+ ```javascript
50
+ {
51
+ sidebarUniqId: function() {
52
+ return window.location.pathname;
53
+ },
54
+ icon: '&#9782;',
55
+ iconClass: '',
56
+ iconStyle: '',
57
+ skipDefaultCss: false,
58
+ title: 'Visibility:',
59
+ ordering: false,
60
+ orderHint: 'Drag&Drop to reorder filters',
61
+ resetButtonTitle: 'Reset'
62
+ }
63
+ ```
64
+
65
+ You can change icon - this is a HTML text or symbol. You can pass empty string and customize it with your CSS.
66
+ Or you can set class("iconClass") for icon or inline styles("iconStyle").
67
+
68
+ This plugin has minimal CSS styling.
69
+ In case you want to use custom CSS, default styling can be ignored:
70
+ set ```skipDefaultCss``` to ```true```
71
+
72
+
73
+ ### Ordering
74
+
75
+ By default ordering is disabled. You can turn it: set option ```ordering``` to ```true```.
76
+
77
+
78
+ ### Texts
79
+ Change text in options: ```title```, ```orderHint``` and ```resetButtonTitle```
80
+
81
+
82
+ ### Dont hide filters which has selected value
83
+
84
+ If filter has selected value - that filter will not be hidden on page reload. Even if "visibility checkbox" is unchecked.
85
+ This was made for preventing unpredictable filtering: for example when user came to page by some link with predefined filtering params.
86
+ All default filters types(string, numeric, date range, etc.) are implemented.
87
+ But if you have some specific filter, you need to add custom handler.
88
+
89
+ For example you have customized filter by ID.
90
+ And you want to consider "1" as default value and allow hiding it.
91
+ In this case you should add uniq class to wrapper.
92
+
93
+ ```ruby
94
+ filter :id, wrapper_html: { class: 'filter_customized_id' }
95
+ ```
96
+
97
+ ```javascript
98
+ // return TRUE if this filter has value
99
+ // elWrapper is jQuery element "div.filter_form_field.filter_customized_id"
100
+ // if not "1" then consider this filter as active, and return TRUE to prevent hiding
101
+ $.fn.activeAdminFiltersVisibility.registerFilterType('customized_id', function(elWrapper) {
102
+ var inputValue = elWrapper.find('input').val();
103
+ return inputValue != '1';
104
+ });
105
+ ```
106
+
107
+
108
+ ### Saving state
109
+
110
+ Plugin saves list of hidden filters in LocalStorage, using jQuery plugin "Lockr" https://github.com/tsironis/lockr
111
+ If you need to save this in cookies or user profile, you should write your own implementation - rewrite "$.fn.activeAdminFiltersVisibility.storage".
112
+ For example:
113
+
114
+ ```javascript
115
+ $.fn.activeAdminFiltersVisibility.storage = function(storageUniqId) {
116
+ // initialize storage with "storageUniqId"
117
+ // every page(sidebar filters) must has its uniq storageUniqId
118
+ var myStorage = new MyCustomizedStorage(storageUniqId);
119
+
120
+ return {
121
+ add: function(labelText) {
122
+ // add hidden filter "labelText" to storage myStorage
123
+ myStorage.add(labelText);
124
+ },
125
+ remove: function(labelText) {
126
+ // drop hidden filter "labelText" to storage myStorage
127
+ // makes filter visible again
128
+ myStorage.remove(labelText);
129
+ },
130
+ has: function(labelText) {
131
+ // check if labelText already hidden(in storage)
132
+ // should return true if exists
133
+ return myStorage.find(labelText) ? true : false;
134
+ },
135
+ all: function() {
136
+ // return array of hidden labels(filters)
137
+ return myStorage.getAll(); // ['Id', 'Name', 'Created At']
138
+ },
139
+ any: function() {
140
+ // check if current Sidebar Filter has some hidden elements
141
+ return this.all().length > 0;
142
+ }
143
+ }
144
+ };
145
+ ```
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'active_admin_filters_visibility/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'active_admin_filters_visibility'
7
+ s.version = ActiveAdminFiltersVisibility::VERSION
8
+ s.authors = ['Gena M.']
9
+ s.email = ['workgena@gmail.com']
10
+ s.homepage = 'https://github.com/workgena/active_admin_filters_visibility'
11
+ s.summary = %q{active_admin_filters_visibility gem}
12
+ s.description = %q{extension for activeadmin gem to hide any filters from sidebar-filters panel}
13
+
14
+ s.add_dependency 'activeadmin'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+ end
@@ -0,0 +1,517 @@
1
+ (function($) {
2
+
3
+ // Plugin definition
4
+ $.fn.activeAdminFiltersVisibility = function(options) {
5
+ var settings = $.extend({}, $.fn.activeAdminFiltersVisibility.defaults, options || {});
6
+
7
+ var storageKey = settings.sidebarUniqId(),
8
+ storage = $.fn.activeAdminFiltersVisibility.storage(storageKey),
9
+ panel = $(this);
10
+
11
+ if (panel.length > 1) {
12
+ console.log('Cant be applied to multiple sidebars');
13
+ return panel;
14
+ }
15
+
16
+
17
+ function diffArray(arr1, arr2) {
18
+ return arr1.concat(arr2).filter(function (val) {
19
+ if (!(arr1.includes(val) && arr2.includes(val)))
20
+ return val;
21
+ });
22
+ }
23
+
24
+
25
+
26
+ function findFilterWrapperByLabelText(labelText) {
27
+ return panel.find(".filter_form_field label").filter(function() {
28
+ var nodeText = $(this)[0].childNodes[0].textContent;
29
+ return nodeText === labelText;
30
+ }).closest('.filter_form_field');
31
+ }
32
+
33
+ function buildCheckboxesHtml() {
34
+ var html = '';
35
+
36
+ var labels = panel.find('.filter_form_field label:first-child').map(function() {
37
+ var text = $(this)[0].childNodes[0].textContent.trim()
38
+ $(this).closest('.filter_form_field').attr('data-pseudo-id', encodeURIComponent(text));
39
+ return text;
40
+ }).get();
41
+
42
+ var orderedLabels = storage.getOrder();
43
+
44
+ //diffArray
45
+ if (orderedLabels.length > 0) {
46
+ if (diffArray(labels, orderedLabels).length) {
47
+ storage.reset();
48
+ } else {
49
+ labels = orderedLabels;
50
+ }
51
+ }
52
+
53
+ $.each(labels, function(i, text) {
54
+ var checked = storage.has(text) ? '' : 'checked="checked"';
55
+ html += '<div><label data-pseudo-id="'+encodeURIComponent(text)+'"><input type="checkbox" value="'+text+'" ' + checked +'> ' + text + '</label></div>';
56
+ });
57
+
58
+ return html;
59
+ }
60
+
61
+ function renderNotice() {
62
+ var btn = panel.find('.filters-visibility-button');
63
+ if (storage.any()) {
64
+ btn.addClass('active');
65
+ } else {
66
+ btn.removeClass('active');
67
+ }
68
+ }
69
+
70
+ function render() {
71
+ // Button
72
+ panel.find('h3:first')
73
+ .append('<span class="filters-visibility-button" class="' + settings.iconClass + '" style="' + settings.iconStyle + '">' + settings.icon + '</span>');
74
+
75
+ // Settings Panel
76
+ panel.find('.panel_contents').prepend(
77
+ '<div class="filters-visibility-panel">' +
78
+ '<div><strong>' + settings.title + '</strong></div>' +
79
+ buildCheckboxesHtml() +
80
+ '</div>'
81
+ );
82
+
83
+ // Hide filters
84
+ $.each(storage.all(), function(i, labelText) {
85
+ var elWrapper = findFilterWrapperByLabelText(labelText);
86
+ if ( false == isFilterFilled(elWrapper) ) {
87
+ elWrapper.hide();
88
+ }
89
+ });
90
+
91
+ // Mark button if some filters are hidden
92
+ renderNotice();
93
+ }
94
+
95
+
96
+
97
+ function hide(labelText) {
98
+ findFilterWrapperByLabelText(labelText).hide();
99
+ storage.add(labelText);
100
+ renderNotice();
101
+ }
102
+
103
+ function show(labelText) {
104
+ findFilterWrapperByLabelText(labelText).show();
105
+ storage.remove(labelText);
106
+ renderNotice();
107
+ }
108
+
109
+ // prevent hiding filter if it is no empty (triggers only on page render)
110
+ function isFilterFilled(elWrapper) {
111
+ if (elWrapper.length == 0) {
112
+ return false;
113
+ }
114
+ var klasses = elWrapper.attr('class').split(' ');
115
+
116
+ var filterTypeName = $.grep(klasses, function(v) {
117
+ return v != 'filter_form_field' && /^filter_/.test(v)
118
+ })[0].replace(/^filter_/, "");
119
+
120
+ function _detectIsFilled(filterTypeName, elWrapper) {
121
+ var functionOrString = $.fn.activeAdminFiltersVisibility.filtersTypesDefinitions[filterTypeName];
122
+
123
+ if (typeof functionOrString == 'string' && functionOrString != filterTypeName) {
124
+ return $.fn.activeAdminFiltersVisibility.filtersTypesDefinitions[functionOrString].call(this, elWrapper);
125
+ } else if (typeof functionOrString == 'function') {
126
+ return functionOrString.call(this, elWrapper);
127
+ } else {
128
+ return $.fn.activeAdminFiltersVisibility.filtersTypesDefinitions['default'].call(this, elWrapper);
129
+ }
130
+ }
131
+
132
+ return _detectIsFilled(filterTypeName, elWrapper);
133
+ }
134
+
135
+
136
+ // apply styles
137
+ if (settings.skipDefaultCss == false) {
138
+ $.fn.activeAdminFiltersVisibility.css();
139
+ }
140
+
141
+
142
+ panel.on('click', '.filters-visibility-button', function() {
143
+ panel.find('.filters-visibility-panel').toggle();
144
+ });
145
+
146
+ panel.on('change', '.filters-visibility-panel input[type=checkbox]', function() {
147
+ var $this = $(this),
148
+ labelText = $this.parent().text().trim();
149
+
150
+ if ($this.prop('checked')) {
151
+ show(labelText);
152
+ } else {
153
+ hide(labelText);
154
+ }
155
+ });
156
+
157
+ render();
158
+
159
+ if (settings.ordering) {
160
+ $.fn.activeAdminFiltersVisibility.applyOrder(panel, storage);
161
+ var resetButtonHtml = '<a href="#" class="filters-visibility-reset-btn">' + settings.resetButtonTitle + '</a>';
162
+ panel.find('.filters-visibility-panel div:first')
163
+ .append(resetButtonHtml)
164
+ .after('<div><i>' + settings.orderHint + '</i></div>');
165
+
166
+ panel.on('click', '.filters-visibility-reset-btn', function(e) {
167
+ e.preventDefault();
168
+ storage.reset();
169
+ window.location.reload();
170
+ });
171
+ }
172
+
173
+ return panel;
174
+ };
175
+
176
+ // Ordering
177
+ $.fn.activeAdminFiltersVisibility.applyOrder = function(panel, storage) {
178
+
179
+ // re-render sidebar filters(even if they are not visible, show/hide event is independent and knows nothing about order)
180
+ function renderReorderedFilters() {
181
+ var wrapper = panel.find('form');
182
+ var order = storage.getOrder();
183
+
184
+ var existingOrder = panel.find('.filter_form_field label:first-child').map(function() {
185
+ return $(this)[0].childNodes[0].textContent.trim();
186
+ }).get();
187
+
188
+ if (order.length > 0 && JSON.stringify(order) != JSON.stringify(existingOrder)) {
189
+ var pos = 0;
190
+ $.each(order, function(i, text) {
191
+ var textEncoded = encodeURIComponent(text);
192
+ var el = wrapper.find('div[data-pseudo-id="' + textEncoded + '"]');
193
+ if (el.length > 0) {
194
+ var elOnThisPosition = wrapper.find('.filter_form_field').eq(pos);
195
+ if (elOnThisPosition.data('pseudo-id') != textEncoded) {
196
+ wrapper[0].insertBefore(el[0], elOnThisPosition[0]);
197
+ }
198
+ pos++;
199
+ }
200
+ });
201
+ }
202
+ }
203
+
204
+
205
+ var isOrdered = storage.getOrder().length > 0;
206
+
207
+ // define draggable elements
208
+
209
+ panel.find('.filters-visibility-panel label').attr('draggable', 'true');
210
+
211
+ // Attach events
212
+ panel.on('drop', '.filters-visibility-panel label', function(e) {
213
+ e.preventDefault();
214
+ var drag_el_id = e.originalEvent.dataTransfer.getData("text"),
215
+ drag_el = panel.find('label[data-pseudo-id="' + drag_el_id + '"]'),
216
+ drop_el = $(this),
217
+ wrapper = panel.find('.filters-visibility-panel');
218
+
219
+ if (drag_el != drop_el) {
220
+ wrapper[0].insertBefore(drag_el.parent()[0], drop_el.parent()[0]);
221
+
222
+ var orderedList = wrapper.find('label').map(function() {
223
+ return $(this).text().trim();
224
+ }).get();
225
+
226
+ storage.setOrder(orderedList);
227
+
228
+ renderReorderedFilters();
229
+ }
230
+ });
231
+
232
+ panel.on('dragover', '.filters-visibility-panel', function(e) {
233
+ e.preventDefault();
234
+ });
235
+
236
+ panel.find('.filters-visibility-panel label').on('dragstart', function(e) {
237
+ var key = $(this).data('pseudo-id');
238
+ e.originalEvent.dataTransfer.setData("text", key);
239
+ });
240
+
241
+
242
+ // Apply Order
243
+ if (isOrdered) {
244
+ // Apply reorder !!!
245
+ renderReorderedFilters();
246
+ }
247
+
248
+ return panel;
249
+ };
250
+
251
+
252
+
253
+ // Plugin Storage method
254
+ $.fn.activeAdminFiltersVisibility.storage = function(storageUniqId) {
255
+ // https://github.com/tsironis/lockr
256
+ var Lockr = function(){
257
+ if (!Array.prototype.indexOf) {
258
+ Array.prototype.indexOf = function(elt)
259
+ {
260
+ var len = this.length >>> 0;
261
+
262
+ var from = Number(arguments[1]) || 0;
263
+ from = (from < 0)
264
+ ? Math.ceil(from)
265
+ : Math.floor(from);
266
+ if (from < 0)
267
+ from += len;
268
+
269
+ for (; from < len; from++)
270
+ {
271
+ if (from in this &&
272
+ this[from] === elt)
273
+ return from;
274
+ }
275
+ return -1;
276
+ };
277
+ }
278
+
279
+ var Lockr = {};
280
+
281
+ Lockr.prefix = "";
282
+
283
+ Lockr._getPrefixedKey = function(key, options) {
284
+ options = options || {};
285
+
286
+ if (options.noPrefix) {
287
+ return key;
288
+ } else {
289
+ return this.prefix + key;
290
+ }
291
+
292
+ };
293
+
294
+ Lockr.set = function (key, value, options) {
295
+ var query_key = this._getPrefixedKey(key, options);
296
+
297
+ try {
298
+ localStorage.setItem(query_key, JSON.stringify({"data": value}));
299
+ } catch (e) {
300
+ if (console) console.warn("Lockr didn't successfully save the '{"+ key +": "+ value +"}' pair, because the localStorage is full.");
301
+ }
302
+ };
303
+
304
+ Lockr.get = function (key, missing, options) {
305
+ var query_key = this._getPrefixedKey(key, options),
306
+ value;
307
+
308
+ try {
309
+ value = JSON.parse(localStorage.getItem(query_key));
310
+ } catch (e) {
311
+ if(localStorage[query_key]) {
312
+ value = {data: localStorage.getItem(query_key)};
313
+ } else{
314
+ value = null;
315
+ }
316
+ }
317
+ if(value === null) {
318
+ return missing;
319
+ } else if (typeof value === 'object' && typeof value.data !== 'undefined') {
320
+ return value.data;
321
+ } else {
322
+ return missing;
323
+ }
324
+ };
325
+
326
+ Lockr.sadd = function(key, value, options) {
327
+ var query_key = this._getPrefixedKey(key, options),
328
+ json;
329
+
330
+ var values = Lockr.smembers(key);
331
+
332
+ if (values.indexOf(value) > -1) {
333
+ return null;
334
+ }
335
+
336
+ try {
337
+ values.push(value);
338
+ json = JSON.stringify({"data": values});
339
+ localStorage.setItem(query_key, json);
340
+ } catch (e) {
341
+ console.log(e);
342
+ if (console) console.warn("Lockr didn't successfully add the "+ value +" to "+ key +" set, because the localStorage is full.");
343
+ }
344
+ };
345
+
346
+ Lockr.smembers = function(key, options) {
347
+ var query_key = this._getPrefixedKey(key, options),
348
+ value;
349
+
350
+ try {
351
+ value = JSON.parse(localStorage.getItem(query_key));
352
+ } catch (e) {
353
+ value = null;
354
+ }
355
+
356
+ if (value === null)
357
+ return [];
358
+ else
359
+ return (value.data || []);
360
+ };
361
+
362
+ Lockr.sismember = function(key, value, options) {
363
+ return Lockr.smembers(key).indexOf(value) > -1;
364
+ };
365
+
366
+ Lockr.keys = function() {
367
+ var keys = [];
368
+ var allKeys = Object.keys(localStorage);
369
+
370
+ if (Lockr.prefix.length === 0) {
371
+ return allKeys;
372
+ }
373
+
374
+ allKeys.forEach(function (key) {
375
+ if (key.indexOf(Lockr.prefix) !== -1) {
376
+ keys.push(key.replace(Lockr.prefix, ''));
377
+ }
378
+ });
379
+
380
+ return keys;
381
+ };
382
+
383
+ Lockr.getAll = function () {
384
+ var keys = Lockr.keys();
385
+ return keys.map(function (key) {
386
+ return Lockr.get(key);
387
+ });
388
+ };
389
+
390
+ Lockr.srem = function(key, value, options) {
391
+ var query_key = this._getPrefixedKey(key, options),
392
+ json,
393
+ index;
394
+
395
+ var values = Lockr.smembers(key, value);
396
+
397
+ index = values.indexOf(value);
398
+
399
+ if (index > -1)
400
+ values.splice(index, 1);
401
+
402
+ json = JSON.stringify({"data": values});
403
+
404
+ try {
405
+ localStorage.setItem(query_key, json);
406
+ } catch (e) {
407
+ if (console) console.warn("Lockr couldn't remove the "+ value +" from the set "+ key);
408
+ }
409
+ };
410
+
411
+ Lockr.rm = function (key) {
412
+ localStorage.removeItem(key);
413
+ };
414
+
415
+ Lockr.flush = function () {
416
+ if (Lockr.prefix.length) {
417
+ Lockr.keys().forEach(function(key) {
418
+ localStorage.removeItem(Lockr._getPrefixedKey(key));
419
+ });
420
+ } else {
421
+ localStorage.clear();
422
+ }
423
+ };
424
+ return Lockr;
425
+
426
+ }();
427
+
428
+ var storageIdForOrder = '__ordered__' + storageUniqId;
429
+
430
+ return {
431
+ setOrder: function(orderedList) {
432
+ Lockr.set(storageIdForOrder, orderedList);
433
+ },
434
+ getOrder: function() {
435
+ return Lockr.get(storageIdForOrder) || [];
436
+ },
437
+ reset: function() {
438
+ Lockr.rm(storageIdForOrder);
439
+ Lockr.rm(storageUniqId);
440
+ },
441
+ add: function(key) {
442
+ Lockr.sadd(storageUniqId, key);
443
+ },
444
+ remove: function(key) {
445
+ Lockr.srem(storageUniqId, key);
446
+ },
447
+ has: function(key) {
448
+ return Lockr.sismember(storageUniqId, key);
449
+ },
450
+ all: function() {
451
+ return Lockr.smembers(storageUniqId);
452
+ },
453
+ any: function() {
454
+ return this.all().length > 0;
455
+ }
456
+ }
457
+ };
458
+
459
+
460
+ // Style
461
+ $.fn.activeAdminFiltersVisibility.css = function() {
462
+ var lines = [];
463
+
464
+ lines.push('.filters-visibility-button { margin: 0 5px 0 5px; padding: 0 4px 0 4px; background-color: rgba(0, 0, 0, 0.05); float: right; cursor: pointer; }');
465
+ lines.push('.filters-visibility-button.active { color: #007ab8; }');
466
+ lines.push('.filters-visibility-panel { display: none; border-left: 10px solid rgba(0, 0, 0, 0.1); background-color: rgba(0, 0, 0, 0.02); margin-bottom: 10px; }');
467
+ lines.push('.filters-visibility-panel > div { margin-left: 5px; }');
468
+ lines.push('.filters-visibility-panel > div:first-child { display: flex; }');
469
+ lines.push('.filters-visibility-panel .filters-visibility-reset-btn { display: inline-block; margin-left: auto; }');
470
+
471
+ var sheet = document.createElement('style');
472
+ sheet.type = 'text/css';
473
+ sheet.innerHTML = lines.join(' ');
474
+ document.body.appendChild(sheet);
475
+ };
476
+
477
+
478
+ // Prevent filter from being hidden this filter is was used for filtering data
479
+ $.fn.activeAdminFiltersVisibility.filtersTypesDefinitions = {
480
+ 'default': function (elWrapper) {
481
+ var notEmptyInput = elWrapper.find('input[id!=""][type!="hidden"][value][value!=""]');
482
+ return notEmptyInput.length > 0;
483
+ }
484
+ };
485
+
486
+ $.fn.activeAdminFiltersVisibility.registerFilterType = function(name, filterTypeDefinitionFunc) {
487
+ $.fn.activeAdminFiltersVisibility.filtersTypesDefinitions[name] = filterTypeDefinitionFunc;
488
+ };
489
+
490
+ $.fn.activeAdminFiltersVisibility.registerFilterType('check_boxes', function(elWrapper) {
491
+ return elWrapper.find('input[id!=""][type!="hidden"][value][value!=""]:checked').length > 0;
492
+ });
493
+
494
+ $.fn.activeAdminFiltersVisibility.registerFilterType('select', function(elWrapper) {
495
+ return elWrapper.find('select[id]:first').val().length > 0;
496
+ });
497
+
498
+ $.fn.activeAdminFiltersVisibility.registerFilterType('boolean', 'select');
499
+
500
+
501
+
502
+ // Plugin defaults
503
+ $.fn.activeAdminFiltersVisibility.defaults = {
504
+ sidebarUniqId: function() {
505
+ return window.location.pathname;
506
+ },
507
+ icon: '&#9782;',
508
+ iconClass: '',
509
+ iconStyle: '',
510
+ skipDefaultCss: false,
511
+ ordering: false,
512
+ title: 'Visibility:',
513
+ orderHint: 'Drag&Drop to reorder filters',
514
+ resetButtonTitle: 'Reset'
515
+ };
516
+
517
+ })(jQuery);
@@ -0,0 +1,9 @@
1
+ require 'activeadmin'
2
+ require 'active_admin_filters_visibility/version'
3
+
4
+ module ActiveAdminFiltersVisibility
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminFiltersVisibility
2
+ VERSION = '1.2.0'
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_filters_visibility
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Gena M.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: extension for activeadmin gem to hide any filters from sidebar-filters
28
+ panel
29
+ email:
30
+ - workgena@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - active_admin_filters_visibility.gemspec
40
+ - app/assets/javascripts/active_admin_filters_visibility.js
41
+ - lib/active_admin_filters_visibility.rb
42
+ - lib/active_admin_filters_visibility/version.rb
43
+ - screen/example_aa_filters_ordering.gif
44
+ - screen/example_aa_filters_visibility.gif
45
+ homepage: https://github.com/workgena/active_admin_filters_visibility
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.7.7
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: active_admin_filters_visibility gem
68
+ test_files: []