cm-admin 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +21 -20
- data/README.md +24 -1
- data/app/assets/stylesheets/cm_admin/base/auth.scss +0 -12
- data/app/assets/stylesheets/cm_admin/base/filters.scss +8 -7
- data/app/assets/stylesheets/cm_admin/base/form.scss +7 -72
- data/app/assets/stylesheets/cm_admin/base/navbar.scss +1 -3
- data/app/assets/stylesheets/cm_admin/base/quicksearch.scss +7 -0
- data/app/assets/stylesheets/cm_admin/base/scaffold.scss +38 -3
- data/app/assets/stylesheets/cm_admin/base/show.scss +24 -2
- data/app/assets/stylesheets/cm_admin/base/table.scss +270 -253
- data/app/assets/stylesheets/cm_admin/components/_dropdown-popup.scss +22 -10
- data/app/assets/stylesheets/cm_admin/components/_range.scss +13 -2
- data/app/assets/stylesheets/cm_admin/components/_status-tag.scss +2 -1
- data/app/assets/stylesheets/cm_admin/helpers/_variable.scss +1 -0
- data/app/controllers/cm_admin/application_controller.rb +5 -0
- data/app/controllers/cm_admin/exports_controller.rb +1 -1
- data/app/controllers/cm_admin/static_controller.rb +12 -0
- data/app/helpers/cm_admin/custom_helper.rb +4 -0
- data/app/javascript/packs/cm_admin/application.js +14 -1
- data/app/javascript/packs/cm_admin/filters.js +331 -16
- data/app/javascript/packs/cm_admin/quick_search.js +67 -0
- data/app/javascript/packs/cm_admin/scaffolds.js +30 -1
- data/app/javascript/stylesheets/cm_admin/application.scss +3 -0
- data/app/views/cm_admin/main/_associated_table.html.slim +60 -0
- data/app/views/cm_admin/main/_cm_pagy_nav.html.slim +6 -6
- data/app/views/cm_admin/main/_filters.html.slim +1 -10
- data/app/views/cm_admin/main/_nested_fields.html.slim +7 -0
- data/app/views/cm_admin/main/_nested_table_form.html.slim +6 -0
- data/app/views/cm_admin/main/_table.html.slim +5 -4
- data/app/views/cm_admin/main/_tabs.html.slim +5 -0
- data/app/views/cm_admin/main/_top_navbar.html.slim +4 -4
- data/app/views/cm_admin/main/associated_index.html.slim +6 -0
- data/app/views/cm_admin/main/associated_show.html.slim +6 -0
- data/app/views/cm_admin/main/index.html.slim +11 -8
- data/app/views/cm_admin/main/show.html.slim +12 -13
- data/app/views/cm_admin/static/error_401.html.slim +4 -0
- data/app/views/layouts/_left_sidebar_nav.html.slim +7 -3
- data/app/views/layouts/_quick_links.html.slim +25 -0
- data/app/views/layouts/cm_admin.html.slim +24 -1
- data/app/views/layouts/static.html.slim +18 -0
- data/bin/console +0 -1
- data/cm_admin.gemspec +1 -0
- data/config/routes.rb +2 -1
- data/config/webpack/environment.js +3 -2
- data/lib/.DS_Store +0 -0
- data/lib/cm_admin/model.rb +57 -167
- data/lib/cm_admin/models/action.rb +15 -1
- data/lib/cm_admin/models/cm_show_section.rb +20 -0
- data/lib/cm_admin/models/column.rb +49 -4
- data/lib/cm_admin/models/controller_method.rb +75 -0
- data/lib/cm_admin/models/dsl_method.rb +122 -0
- data/lib/cm_admin/models/export.rb +16 -5
- data/lib/cm_admin/models/field.rb +2 -1
- data/lib/cm_admin/models/filter.rb +67 -2
- data/lib/cm_admin/models/form_field.rb +21 -0
- data/lib/cm_admin/models/tab.rb +13 -0
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/column_field_helper.rb +29 -0
- data/lib/cm_admin/view_helpers/field_display_helper.rb +65 -0
- data/lib/cm_admin/view_helpers/filter_helper.rb +190 -0
- data/lib/cm_admin/view_helpers/form_field_helper.rb +21 -4
- data/lib/cm_admin/view_helpers/form_helper.rb +22 -12
- data/lib/cm_admin/view_helpers/manage_column_popup_helper.rb +75 -0
- data/lib/cm_admin/view_helpers/navigation_helper.rb +22 -6
- data/lib/cm_admin/view_helpers/page_info_helper.rb +36 -0
- data/lib/cm_admin/view_helpers.rb +3 -1
- data/lib/cm_admin.rb +3 -1
- data/lib/generators/cm_admin/install_generator.rb +20 -8
- data/package.json +6 -1
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -0
- data/yarn.lock +35 -5
- metadata +41 -7
- data/app/controllers/cm_admin/main_controller.rb +0 -8
- data/lib/c.png +0 -0
- data/lib/cm_admin/view_helpers/field_column_helper.rb +0 -23
- data/lib/generators/cm_admin/templates/cm_admin_initializer.rb +0 -4
- data/yarn-error.log +0 -44
@@ -1,10 +1,10 @@
|
|
1
1
|
@import "../helpers/index.scss";
|
2
2
|
|
3
3
|
.dropdown-popup {
|
4
|
-
|
4
|
+
border: none !important;
|
5
5
|
.popup-base {
|
6
6
|
position: absolute;
|
7
|
-
width: 256px;
|
7
|
+
min-width: 256px;
|
8
8
|
height: 56px;
|
9
9
|
padding: 8px;
|
10
10
|
background: $white;
|
@@ -14,7 +14,7 @@
|
|
14
14
|
}
|
15
15
|
.popup-inner {
|
16
16
|
position: relative;
|
17
|
-
width: 240px;
|
17
|
+
min-width: 240px;
|
18
18
|
margin: 0 auto;
|
19
19
|
background-color: $white;
|
20
20
|
border: 1px solid #e0e0e0;
|
@@ -24,14 +24,16 @@
|
|
24
24
|
input {
|
25
25
|
width: 100%;
|
26
26
|
min-height: 40px;
|
27
|
-
padding: 9px 16px
|
27
|
+
padding: 9px 16px;
|
28
28
|
font-size: $t4-text;
|
29
29
|
border: none;
|
30
|
+
border-radius: 4px 4px 0 0;
|
30
31
|
&::placeholder {
|
31
32
|
color: $ink-lightest-clr;
|
32
33
|
}
|
33
34
|
&:focus {
|
34
|
-
outline:
|
35
|
+
outline: none;
|
36
|
+
border: 1px solid $brand-color;
|
35
37
|
}
|
36
38
|
}
|
37
39
|
}
|
@@ -47,11 +49,11 @@
|
|
47
49
|
background: $grey-lighter-clr;
|
48
50
|
border-radius: $radius-4;
|
49
51
|
span:nth-child(1) {
|
50
|
-
@include font($size: $t4-text, $color: $primary-text-clr);
|
52
|
+
@include font($size: $t4-text, $color: $primary-text-clr);
|
51
53
|
line-height: 22px;
|
52
54
|
}
|
53
55
|
span:nth-child(2) {
|
54
|
-
@include font($size: 10px, $color: $ink-lightest-clr);
|
56
|
+
@include font($size: 10px, $color: $ink-lightest-clr);
|
55
57
|
margin-left: 4px;
|
56
58
|
cursor: pointer;
|
57
59
|
}
|
@@ -73,11 +75,20 @@
|
|
73
75
|
display: flex;
|
74
76
|
align-items: center;
|
75
77
|
padding: 9px 16px;
|
78
|
+
@include font($size: $t4-text, $color: $primary-text-clr);
|
79
|
+
line-height: 22px;
|
76
80
|
label {
|
77
|
-
@include font($size: $t4-text, $color: $primary-text-clr);
|
78
|
-
line-height: 22px;
|
79
81
|
margin: 0 0 0 8px;
|
80
82
|
}
|
83
|
+
&:hover {
|
84
|
+
background: $grey-lighter-clr;
|
85
|
+
&:nth-last-child(1) {
|
86
|
+
border-radius: 0 0 4px 4px;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
.selected {
|
91
|
+
color: $brand-color;
|
81
92
|
}
|
82
93
|
}
|
83
94
|
.apply-area {
|
@@ -86,8 +97,9 @@
|
|
86
97
|
text-align: center;
|
87
98
|
padding: 9px 16px;
|
88
99
|
box-shadow: inset 0px 1px 0px rgba(148, 151, 155, 0.15);
|
89
|
-
cursor:
|
100
|
+
cursor: not-allowed;
|
90
101
|
&.active {
|
102
|
+
cursor: pointer;
|
91
103
|
color: $blue-regular-clr;
|
92
104
|
}
|
93
105
|
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
.range-container {
|
4
4
|
display: flex;
|
5
|
-
width:
|
5
|
+
width: 424px;
|
6
6
|
height: 54px;
|
7
7
|
padding: 8px;
|
8
8
|
background: $white;
|
@@ -10,11 +10,22 @@
|
|
10
10
|
box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.16);
|
11
11
|
border-radius: $radius-4;
|
12
12
|
.range-item {
|
13
|
+
width: 200px;
|
14
|
+
border: 1px solid $grey-light-clr;
|
15
|
+
border-radius: $radius-4;
|
16
|
+
padding: 8px 0 8px 16px;
|
13
17
|
&:nth-child(1) {
|
14
18
|
margin-right: 4px;
|
15
19
|
}
|
16
20
|
&:nth-child(2) {
|
17
21
|
margin-left: 4px;
|
18
22
|
}
|
23
|
+
&:hover {
|
24
|
+
border: 1px solid $grey-dark-clr;
|
25
|
+
}
|
26
|
+
&:focus {
|
27
|
+
outline: none;
|
28
|
+
border: 1px solid $brand-color;
|
29
|
+
}
|
19
30
|
}
|
20
|
-
}
|
31
|
+
}
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module CmAdmin
|
2
2
|
class ApplicationController < ::ActionController::Base
|
3
|
+
# before_action :check_cm_admin
|
3
4
|
layout 'cm_admin'
|
4
5
|
helper CmAdmin::ViewHelpers
|
6
|
+
|
7
|
+
def check_cm_admin
|
8
|
+
redirect_to CmAdmin::Engine.mount_path + '/access-denied' unless defined?(::Current) && ::Current.cm_admin_user
|
9
|
+
end
|
5
10
|
end
|
6
11
|
end
|
@@ -8,7 +8,7 @@ module CmAdmin
|
|
8
8
|
class ExportsController < ApplicationController
|
9
9
|
|
10
10
|
def export
|
11
|
-
file_path = CmAdmin::Models::Export.generate_excel(params[:class_name], params[:columns])
|
11
|
+
file_path = CmAdmin::Models::Export.generate_excel(params[:class_name], params[:columns], helpers)
|
12
12
|
send_file file_path, disposition: 'attachment'
|
13
13
|
end
|
14
14
|
|
@@ -1,9 +1,22 @@
|
|
1
1
|
require("@rails/ujs").start()
|
2
2
|
require("turbolinks").start()
|
3
3
|
require("@rails/activestorage").start()
|
4
|
+
require("stylesheets/cm_admin/application")
|
4
5
|
require("jquery")
|
6
|
+
require("moment")
|
7
|
+
require("bootstrap")
|
8
|
+
require('flatpickr')
|
5
9
|
require('./scaffolds.js')
|
10
|
+
require('./quick_search.js')
|
6
11
|
require('./filters.js')
|
7
12
|
|
13
|
+
import jQuery from 'jquery'
|
14
|
+
window.$ = jQuery
|
15
|
+
window.jQuery = jQuery
|
16
|
+
|
17
|
+
require("@nathanvda/cocoon")
|
8
18
|
import "@fortawesome/fontawesome-free/css/all"
|
9
|
-
import "
|
19
|
+
import "daterangepicker"
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -1,27 +1,58 @@
|
|
1
|
-
var
|
1
|
+
var currentRequest = null;
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
// Main method which will structure the existing filter values with the newly
|
4
|
+
// applied filter. Send and receive the value from the backend.
|
5
|
+
var getFilteredData = function(filterType, filterValue, filterColumn=null) {
|
5
6
|
var url = window.location.pathname
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
|
8
|
+
// Based on the value changed for recent filter generate the filterParams hash
|
9
|
+
var filterParams = {};
|
10
|
+
if (filterColumn) {
|
11
|
+
filterParams[filterType] = {};
|
12
|
+
filterParams[filterType][filterColumn] = filterValue
|
13
|
+
} else {
|
14
|
+
filterParams[filterType] = filterValue
|
15
|
+
}
|
16
|
+
|
17
|
+
// TODO add sort params in the queryString
|
18
|
+
// page params is reinitialized to 1 when any new filter value is applied so
|
19
|
+
// that it won't throw the error when the user doesn't have sufficent data
|
20
|
+
// to display on the table.
|
21
|
+
var queryString = {
|
22
|
+
filters: filterParams,
|
23
|
+
page: 1
|
14
24
|
};
|
15
|
-
|
25
|
+
|
26
|
+
// Generate the queryString by concatenating the filterParams and
|
27
|
+
// searchParams that are already applied, if searchParams are present.
|
28
|
+
var searchParams = window.location.search
|
29
|
+
if (searchParams.length > 0) {
|
30
|
+
// Delete the previous applied value for multi_select filter from the
|
31
|
+
// searchParams as altering the array with new and old value will create
|
32
|
+
// more complicated logic. The new value is passed and structured in
|
33
|
+
// filterParams and will be concadinated with the searchParams post deletion
|
34
|
+
if (filterType == 'multi_select') {
|
35
|
+
searchParams = getParamsAsObject(searchParams)
|
36
|
+
if (searchParams['filters'][filterType] != undefined) {
|
37
|
+
delete(searchParams['filters'][filterType][filterColumn])
|
38
|
+
}
|
39
|
+
searchParams = jQuery.param(searchParams)
|
40
|
+
}
|
41
|
+
filterParams = jQuery.param(queryString)
|
42
|
+
var availableParams = searchParams + '&' + filterParams
|
43
|
+
queryString = getParamsAsObject(availableParams)
|
44
|
+
}
|
45
|
+
|
46
|
+
return currentRequest = $.ajax(url, {
|
16
47
|
type: 'GET',
|
17
|
-
data:
|
48
|
+
data: queryString,
|
18
49
|
beforeSend: function() {
|
19
|
-
if (
|
20
|
-
|
50
|
+
if (currentRequest !== null) {
|
51
|
+
currentRequest.abort();
|
21
52
|
}
|
22
53
|
},
|
23
54
|
success: function(data) {
|
24
|
-
var queryParam = jQuery.param(
|
55
|
+
var queryParam = jQuery.param(queryString)
|
25
56
|
window.history.pushState("", "", url + '?' + queryParam);
|
26
57
|
$('.index-page__table-container').html(data);
|
27
58
|
},
|
@@ -29,4 +60,288 @@ $(document).on('keyup', '.search-input', function(e) {
|
|
29
60
|
console.log(errorThrown, textStatus);
|
30
61
|
}
|
31
62
|
});
|
63
|
+
}
|
64
|
+
|
65
|
+
$(document).on('change', '[data-behaviour="filter"]', function(e) {
|
66
|
+
var filterType = $(this).data('filter-type')
|
67
|
+
var filterColumn = $(this).data('db-column')
|
68
|
+
|
69
|
+
if (filterType == 'range') {
|
70
|
+
var rangeElements = $(this).parent().children()
|
71
|
+
var filterValue = $(rangeElements[0]).val() + ' to ' + $(rangeElements[1]).val()
|
72
|
+
} else {
|
73
|
+
var filterValue = $(this).val()
|
74
|
+
}
|
75
|
+
|
76
|
+
$(this).parents(':nth(1)').children(':first').children(':nth(1)').text(filterValue)
|
77
|
+
$(this).parents(':nth(1)').children(':first').children(':last').removeClass('hidden')
|
78
|
+
|
79
|
+
unhideClearFilterBtn(filterValue)
|
80
|
+
getFilteredData(filterType, filterValue, filterColumn)
|
81
|
+
});
|
82
|
+
|
83
|
+
$(document).on('keyup', '[data-behaviour="input-search"]', function(e) {
|
84
|
+
e.stopPropagation();
|
85
|
+
|
86
|
+
var searchValue = $(this).val();
|
87
|
+
unhideClearFilterBtn(searchValue)
|
88
|
+
getFilteredData('search', searchValue)
|
89
|
+
});
|
90
|
+
|
91
|
+
$(document).on('click', '[data-behaviour="filter-option"]', function(e) {
|
92
|
+
var filterType = $(this).data('filter-type')
|
93
|
+
var filterColumn = $(this).data('db-column')
|
94
|
+
|
95
|
+
// Clear the search value post selection and regenerate the dropdown elements.
|
96
|
+
var searchInputElement = $(this).parents(':nth(1)').children(':first').children()
|
97
|
+
searchInputElement.val('')
|
98
|
+
CmFilter.dropdown_search(searchInputElement)
|
99
|
+
|
100
|
+
unhideFilter(filterType, filterColumn)
|
101
|
+
});
|
102
|
+
|
103
|
+
var unhideFilter = function(filterType, filterColumn) {
|
104
|
+
var filterInputElement = $('[data-behaviour="filter-input"][data-filter-type=' + filterType + '][data-db-column='+ filterColumn + ']')
|
105
|
+
|
106
|
+
filterInputElement.parent().removeClass('hidden');
|
107
|
+
filterInputElement.click()
|
108
|
+
};
|
109
|
+
|
110
|
+
// Search inside the dropdowns
|
111
|
+
$(document).on('keyup', '[data-behaviour="dropdown-filter-search"]', function(e) {
|
112
|
+
CmFilter.dropdown_search($(this))
|
113
|
+
});
|
114
|
+
|
115
|
+
// Method to decode the encoded nested and/or complex hash and convert it to
|
116
|
+
// object that is used for filters while sending the data to the backend.
|
117
|
+
var getParamsAsObject = function (query) {
|
118
|
+
query = query.substring(query.indexOf('?') + 1);
|
119
|
+
|
120
|
+
var re = /([^&=]+)=?([^&]*)/g;
|
121
|
+
var decodeRE = /\+/g;
|
122
|
+
|
123
|
+
var decode = function (str) {
|
124
|
+
return decodeURIComponent(str.replace(decodeRE, " "));
|
125
|
+
};
|
126
|
+
|
127
|
+
var params = {}, e;
|
128
|
+
while (e = re.exec(query)) {
|
129
|
+
var k = decode(e[1]), v = decode(e[2]);
|
130
|
+
if (k.substring(k.length - 2) === '[]') {
|
131
|
+
k = k.substring(0, k.length - 2);
|
132
|
+
(params[k] || (params[k] = [])).push(v);
|
133
|
+
}
|
134
|
+
else params[k] = v;
|
135
|
+
}
|
136
|
+
|
137
|
+
var assign = function (obj, keyPath, value) {
|
138
|
+
var lastKeyIndex = keyPath.length - 1;
|
139
|
+
for (var i = 0; i < lastKeyIndex; ++i) {
|
140
|
+
var key = keyPath[i];
|
141
|
+
if (!(key in obj))
|
142
|
+
obj[key] = {}
|
143
|
+
obj = obj[key];
|
144
|
+
}
|
145
|
+
obj[keyPath[lastKeyIndex]] = value;
|
146
|
+
}
|
147
|
+
|
148
|
+
for (var prop in params) {
|
149
|
+
var structure = prop.split('[');
|
150
|
+
if (structure.length > 1) {
|
151
|
+
var levels = [];
|
152
|
+
structure.forEach(function (item, i) {
|
153
|
+
var key = item.replace(/[?[\]\\ ]/g, '');
|
154
|
+
levels.push(key);
|
155
|
+
});
|
156
|
+
assign(params, levels, params[prop]);
|
157
|
+
delete(params[prop]);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return params;
|
161
|
+
};
|
162
|
+
|
163
|
+
$(document).on('click', '[data-behaviour="filter-input"]', function(e) {
|
164
|
+
var filterType = $(this).data('filter-type')
|
165
|
+
var filterColumn = $(this).data('db-column')
|
166
|
+
|
167
|
+
var filterElement = $('[data-behaviour="filter"][data-filter-type=' + filterType + '][data-db-column=' + filterColumn +']')
|
168
|
+
|
169
|
+
if (filterType == 'range') {
|
170
|
+
filterElement.parent().toggleClass('hidden')
|
171
|
+
} else if (filterType == 'multi_select') {
|
172
|
+
$(this).parent().children(':last').toggleClass('hidden')
|
173
|
+
} else if (filterType == 'date') {
|
174
|
+
filterElement.click()
|
175
|
+
}
|
176
|
+
})
|
177
|
+
|
178
|
+
// Remove all the applied filters and reload the page
|
179
|
+
$(document).on('click', '.clear-btn', function(e) {
|
180
|
+
window.location.href = window.location.href.split("?")[0]
|
181
|
+
})
|
182
|
+
|
183
|
+
var unhideClearFilterBtn = function(filterValue) {
|
184
|
+
if (filterValue) {
|
185
|
+
$('.clear-btn').removeClass('hidden')
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
// Selecting options for single and multi select filters
|
190
|
+
$(document).on('click', '[data-behaviour="select-option"]', function(e) {
|
191
|
+
var filterType = $(this).data('filter-type')
|
192
|
+
var filterColumn = $(this).data('db-column')
|
193
|
+
|
194
|
+
if (filterType == 'single_select') {
|
195
|
+
var filterValue = $(this).data('value')
|
196
|
+
if (!this.classList.contains('selected')) {
|
197
|
+
if (this.parentNode.querySelector('.list-item.selected') != null) {
|
198
|
+
this.parentNode.querySelector('.list-item.selected').classList.remove('selected');
|
199
|
+
}
|
200
|
+
$(this).addClass('selected')
|
201
|
+
}
|
202
|
+
|
203
|
+
$(this).parents(':nth(4)').children(':first').children(':nth(1)').text(filterValue)
|
204
|
+
$(this).parents(':nth(4)').children(':first').children(':last').removeClass('hidden')
|
205
|
+
|
206
|
+
// Clear the search value post selection and regenerate the dropdown elements.
|
207
|
+
var searchInputElement = $(this).parents(':nth(1)').children(':first').children()
|
208
|
+
searchInputElement.val('')
|
209
|
+
CmFilter.dropdown_search(searchInputElement)
|
210
|
+
|
211
|
+
unhideClearFilterBtn(filterValue)
|
212
|
+
getFilteredData(filterType, filterValue, filterColumn)
|
213
|
+
}
|
214
|
+
else if (filterType == 'multi_select') {
|
215
|
+
var parentChip = $(this).parent().siblings(':first')
|
216
|
+
var checkboxElement = $(this).find('.cm-checkbox')
|
217
|
+
checkboxElement.prop('checked', !checkboxElement.prop('checked'))
|
218
|
+
var checkedCount = $(this).parent().find('.cm-checkbox').filter(':checked').length
|
219
|
+
|
220
|
+
if (checkboxElement.prop('checked')) {
|
221
|
+
var chip = $('<div class="chip"></div>')
|
222
|
+
var firstSpan = $('<span></span>').text($(this).data('value'))
|
223
|
+
var secondSpan = $('<span data-behaviour="selected-chip"><i class="fa fa-times"></i></span>')
|
224
|
+
parentChip.prepend(chip.append(firstSpan).append(secondSpan))
|
225
|
+
} else {
|
226
|
+
var chipElement = parentChip.find('.chip')
|
227
|
+
for(var i = 0; i < chipElement.length; i++) {
|
228
|
+
if ($(chipElement[i]).text() == $(this).data('value')) {
|
229
|
+
$(chipElement[i]).remove()
|
230
|
+
break
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
if (checkedCount > 0) {
|
236
|
+
parentChip.addClass('search-with-chips').removeClass('search-area')
|
237
|
+
$(this).parents(':nth(1)').children(':last').addClass('active')
|
238
|
+
} else {
|
239
|
+
parentChip.addClass('search-area').removeClass('search-with-chips')
|
240
|
+
$(this).parents(':nth(1)').children(':last').removeClass('active')
|
241
|
+
}
|
242
|
+
}
|
243
|
+
});
|
244
|
+
|
245
|
+
// Apply button for multi select filters
|
246
|
+
$(document).on('click', '.apply-area', function(e) {
|
247
|
+
var filterInputElement = $(this).parents(':nth(3)').children(':first')
|
248
|
+
var filterType = filterInputElement.data('filter-type')
|
249
|
+
var filterColumn = filterInputElement.data('db-column')
|
250
|
+
var filterValue = []
|
251
|
+
|
252
|
+
var selectFilterElement = $('[data-behaviour="select-option"][data-filter-type=' + filterType + '][data-db-column=' + filterColumn + ']')
|
253
|
+
var checkedElements = selectFilterElement.find('.cm-checkbox').filter(':checked')
|
254
|
+
|
255
|
+
if (checkedElements.length > 0) {
|
256
|
+
for(var i = 0; i < checkedElements.length; i++) {
|
257
|
+
filterValue.push($(checkedElements[i]).parent().data('value'))
|
258
|
+
}
|
259
|
+
|
260
|
+
truncatedFilterValue = filterValue[0]
|
261
|
+
if (filterValue.length > 1) {
|
262
|
+
truncatedFilterValue += ' + ' + (filterValue.length - 1) + ' more'
|
263
|
+
}
|
264
|
+
|
265
|
+
filterInputElement.children(':nth(1)').text(truncatedFilterValue)
|
266
|
+
filterInputElement.children(':last').removeClass('hidden')
|
267
|
+
selectFilterElement.parents(':nth(3)').addClass('hidden')
|
268
|
+
|
269
|
+
// Clear the search value post selection and regenerate the dropdown elements.
|
270
|
+
var searchInputElement = $(this).parent().children(':first').children(':last')
|
271
|
+
searchInputElement.val('')
|
272
|
+
CmFilter.dropdown_search(searchInputElement)
|
273
|
+
|
274
|
+
unhideClearFilterBtn(filterValue)
|
275
|
+
getFilteredData(filterType, filterValue, filterColumn)
|
276
|
+
}
|
277
|
+
});
|
278
|
+
|
279
|
+
// Remove single applied filter.
|
280
|
+
$(document).on('click', '.filter-chip-remove', function(e) {
|
281
|
+
var url = window.location.pathname
|
282
|
+
var filterType = $(this).parent().data('filter-type')
|
283
|
+
var filterColumn = $(this).parent().data('db-column')
|
284
|
+
|
285
|
+
var searchParams = window.location.search
|
286
|
+
if (searchParams.length > 0) {
|
287
|
+
queryString = getParamsAsObject(searchParams)
|
288
|
+
if (queryString['filters'][filterType] != undefined) {
|
289
|
+
delete(queryString['filters'][filterType][filterColumn])
|
290
|
+
var queryParam = jQuery.param(queryString)
|
291
|
+
window.history.pushState("", "", url + '?' + queryParam);
|
292
|
+
window.location.reload()
|
293
|
+
}
|
294
|
+
}
|
32
295
|
});
|
296
|
+
|
297
|
+
$(document).on('click', '[data-behaviour="selected-chip"]', function(e) {
|
298
|
+
var filterType = $(this).parents(':nth(5)').find('.filter-chip').data('filter-type')
|
299
|
+
var filterColumn = $(this).parents(':nth(5)').find('.filter-chip').data('db-column')
|
300
|
+
var filterValue = $(this).siblings().text()
|
301
|
+
|
302
|
+
var selectElement = $('[data-behaviour="select-option"][data-filter-type=' + filterType + '][data-db-column=' + filterColumn + ']')
|
303
|
+
$(this).parent().remove()
|
304
|
+
|
305
|
+
for(var i = 0; i < selectElement.length; i++) {
|
306
|
+
if ($(selectElement[i]).data('value') == filterValue) {
|
307
|
+
var checkboxElement = $(selectElement[i]).find('.cm-checkbox')
|
308
|
+
checkboxElement.prop('checked', !checkboxElement.prop('checked'))
|
309
|
+
break
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
var checkedCount = $(selectElement).find('.cm-checkbox').filter(':checked').length
|
314
|
+
if (checkedCount < 1) {
|
315
|
+
$(selectElement).parent().siblings(':first').addClass('search-area').removeClass('search-with-chips')
|
316
|
+
$(selectElement).parent().siblings(':last').removeClass('active')
|
317
|
+
}
|
318
|
+
})
|
319
|
+
|
320
|
+
CmFilter = {
|
321
|
+
// Generate or remove elements of the dropdown based on the search value.
|
322
|
+
dropdown_search: function(element) {
|
323
|
+
var filter = element.val().toUpperCase();
|
324
|
+
var dropdownElements = element.parents(':nth(1)').find('.list-area').children();
|
325
|
+
for (var i = 0; i < dropdownElements.length; i++) {
|
326
|
+
txtValue = $(dropdownElements[i]).children().text();
|
327
|
+
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
328
|
+
$(dropdownElements[i]).css('display', 'flex');
|
329
|
+
} else {
|
330
|
+
$(dropdownElements[i]).css('display', 'none');
|
331
|
+
}
|
332
|
+
}
|
333
|
+
},
|
334
|
+
quick_input_search: function(element) {
|
335
|
+
var filter = element.val().toUpperCase();
|
336
|
+
var searchElements = element.parents(':nth(3)').find('.list-area').children();
|
337
|
+
searchElements.removeClass('visible').addClass('hidden')
|
338
|
+
console.log("Filter is ", filter)
|
339
|
+
console.log("Search elements are ", searchElements)
|
340
|
+
for (var i = 0; i < searchElements.length; i++) {
|
341
|
+
txtValue = $(searchElements[i]).children().text();
|
342
|
+
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
343
|
+
$(searchElements[i]).removeClass('hidden').addClass('visible');
|
344
|
+
}
|
345
|
+
}
|
346
|
+
}
|
347
|
+
}
|