activeadmin_addons 1.10.0 → 2.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -17
- data/app/inputs/active_admin/inputs/select_input.rb +9 -5
- data/app/inputs/nested_level_input.rb +13 -7
- data/app/inputs/nested_select_input.rb +19 -13
- data/app/inputs/search_select_filter_input.rb +15 -1
- data/app/inputs/search_select_input.rb +6 -5
- data/app/inputs/tags_input.rb +5 -34
- data/app/javascript/activeadmin_addons/addons/slim-select-interactive-tag.js +78 -0
- data/app/javascript/activeadmin_addons/all.js +2 -7
- data/app/javascript/activeadmin_addons/config.js +8 -5
- data/app/javascript/activeadmin_addons/inputs/slim-select-nested.js +95 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select-search.js +37 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select-selected-list.js +103 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select-simple-tags.js +22 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select-tags.js +28 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select-utils.js +70 -0
- data/app/javascript/activeadmin_addons/inputs/slim-select.js +93 -0
- data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/all.scss +4 -10
- data/app/javascript/activeadmin_addons/stylesheets/imports/slimselect.css +1 -0
- data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/selected-list.scss +0 -1
- data/app/javascript/activeadmin_addons/stylesheets/inputs/slim-select.scss +9 -0
- data/lib/activeadmin_addons/addons/image_builder.rb +2 -9
- data/lib/activeadmin_addons/addons/state_builder.rb +1 -0
- data/lib/activeadmin_addons/addons/tag_builder.rb +3 -22
- data/lib/activeadmin_addons/engine.rb +1 -6
- data/lib/activeadmin_addons/support/custom_builder.rb +1 -1
- data/lib/activeadmin_addons/support/input_base.rb +0 -42
- data/lib/activeadmin_addons/support/input_helpers/filter_input_methods.rb +1 -0
- data/lib/activeadmin_addons/support/input_helpers/input_html_helpers.rb +42 -0
- data/lib/activeadmin_addons/support/input_helpers/select_helpers.rb +10 -12
- data/lib/activeadmin_addons/support/select_filter_input_extension.rb +1 -3
- data/lib/activeadmin_addons/support/select_input_base.rb +11 -0
- data/lib/activeadmin_addons/version.rb +1 -1
- data/lib/activeadmin_addons.rb +4 -1
- data/lib/generators/activeadmin_addons/install/install_generator.rb +2 -1
- data/lib/generators/activeadmin_addons/install/templates/initializer.rb +2 -2
- data/lib/generators/activeadmin_addons/webpacker/webpacker_generator.rb +3 -6
- metadata +82 -196
- data/app/assets/images/fileicons/file_extension_3gp.png +0 -0
- data/app/assets/images/fileicons/file_extension_7z.png +0 -0
- data/app/assets/images/fileicons/file_extension_ace.png +0 -0
- data/app/assets/images/fileicons/file_extension_ai.png +0 -0
- data/app/assets/images/fileicons/file_extension_aif.png +0 -0
- data/app/assets/images/fileicons/file_extension_aiff.png +0 -0
- data/app/assets/images/fileicons/file_extension_amr.png +0 -0
- data/app/assets/images/fileicons/file_extension_asf.png +0 -0
- data/app/assets/images/fileicons/file_extension_asx.png +0 -0
- data/app/assets/images/fileicons/file_extension_bat.png +0 -0
- data/app/assets/images/fileicons/file_extension_bin.png +0 -0
- data/app/assets/images/fileicons/file_extension_bmp.png +0 -0
- data/app/assets/images/fileicons/file_extension_bup.png +0 -0
- data/app/assets/images/fileicons/file_extension_cab.png +0 -0
- data/app/assets/images/fileicons/file_extension_cbr.png +0 -0
- data/app/assets/images/fileicons/file_extension_cda.png +0 -0
- data/app/assets/images/fileicons/file_extension_cdl.png +0 -0
- data/app/assets/images/fileicons/file_extension_cdr.png +0 -0
- data/app/assets/images/fileicons/file_extension_chm.png +0 -0
- data/app/assets/images/fileicons/file_extension_dat.png +0 -0
- data/app/assets/images/fileicons/file_extension_divx.png +0 -0
- data/app/assets/images/fileicons/file_extension_dll.png +0 -0
- data/app/assets/images/fileicons/file_extension_dmg.png +0 -0
- data/app/assets/images/fileicons/file_extension_doc.png +0 -0
- data/app/assets/images/fileicons/file_extension_docx.png +0 -0
- data/app/assets/images/fileicons/file_extension_dss.png +0 -0
- data/app/assets/images/fileicons/file_extension_dvf.png +0 -0
- data/app/assets/images/fileicons/file_extension_dwg.png +0 -0
- data/app/assets/images/fileicons/file_extension_eml.png +0 -0
- data/app/assets/images/fileicons/file_extension_eps.png +0 -0
- data/app/assets/images/fileicons/file_extension_exe.png +0 -0
- data/app/assets/images/fileicons/file_extension_fla.png +0 -0
- data/app/assets/images/fileicons/file_extension_flv.png +0 -0
- data/app/assets/images/fileicons/file_extension_gif.png +0 -0
- data/app/assets/images/fileicons/file_extension_gz.png +0 -0
- data/app/assets/images/fileicons/file_extension_hqx.png +0 -0
- data/app/assets/images/fileicons/file_extension_htm.png +0 -0
- data/app/assets/images/fileicons/file_extension_html.png +0 -0
- data/app/assets/images/fileicons/file_extension_ifo.png +0 -0
- data/app/assets/images/fileicons/file_extension_indd.png +0 -0
- data/app/assets/images/fileicons/file_extension_iso.png +0 -0
- data/app/assets/images/fileicons/file_extension_jar.png +0 -0
- data/app/assets/images/fileicons/file_extension_jpeg.png +0 -0
- data/app/assets/images/fileicons/file_extension_jpg.png +0 -0
- data/app/assets/images/fileicons/file_extension_lnk.png +0 -0
- data/app/assets/images/fileicons/file_extension_log.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4a.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4b.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4p.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4v.png +0 -0
- data/app/assets/images/fileicons/file_extension_mcd.png +0 -0
- data/app/assets/images/fileicons/file_extension_mdb.png +0 -0
- data/app/assets/images/fileicons/file_extension_mid.png +0 -0
- data/app/assets/images/fileicons/file_extension_mov.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp2.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp3.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp4.png +0 -0
- data/app/assets/images/fileicons/file_extension_mpeg.png +0 -0
- data/app/assets/images/fileicons/file_extension_mpg.png +0 -0
- data/app/assets/images/fileicons/file_extension_msi.png +0 -0
- data/app/assets/images/fileicons/file_extension_mswmm.png +0 -0
- data/app/assets/images/fileicons/file_extension_ogg.png +0 -0
- data/app/assets/images/fileicons/file_extension_pdf.png +0 -0
- data/app/assets/images/fileicons/file_extension_png.png +0 -0
- data/app/assets/images/fileicons/file_extension_pps.png +0 -0
- data/app/assets/images/fileicons/file_extension_ppt.png +0 -0
- data/app/assets/images/fileicons/file_extension_pptx.png +0 -0
- data/app/assets/images/fileicons/file_extension_ps.png +0 -0
- data/app/assets/images/fileicons/file_extension_psd.png +0 -0
- data/app/assets/images/fileicons/file_extension_pst.png +0 -0
- data/app/assets/images/fileicons/file_extension_ptb.png +0 -0
- data/app/assets/images/fileicons/file_extension_pub.png +0 -0
- data/app/assets/images/fileicons/file_extension_qbb.png +0 -0
- data/app/assets/images/fileicons/file_extension_qbw.png +0 -0
- data/app/assets/images/fileicons/file_extension_qxd.png +0 -0
- data/app/assets/images/fileicons/file_extension_ram.png +0 -0
- data/app/assets/images/fileicons/file_extension_rar.png +0 -0
- data/app/assets/images/fileicons/file_extension_rm.png +0 -0
- data/app/assets/images/fileicons/file_extension_rmvb.png +0 -0
- data/app/assets/images/fileicons/file_extension_rtf.png +0 -0
- data/app/assets/images/fileicons/file_extension_sea.png +0 -0
- data/app/assets/images/fileicons/file_extension_ses.png +0 -0
- data/app/assets/images/fileicons/file_extension_sit.png +0 -0
- data/app/assets/images/fileicons/file_extension_sitx.png +0 -0
- data/app/assets/images/fileicons/file_extension_ss.png +0 -0
- data/app/assets/images/fileicons/file_extension_swf.png +0 -0
- data/app/assets/images/fileicons/file_extension_tgz.png +0 -0
- data/app/assets/images/fileicons/file_extension_thm.png +0 -0
- data/app/assets/images/fileicons/file_extension_tif.png +0 -0
- data/app/assets/images/fileicons/file_extension_tmp.png +0 -0
- data/app/assets/images/fileicons/file_extension_torrent.png +0 -0
- data/app/assets/images/fileicons/file_extension_ttf.png +0 -0
- data/app/assets/images/fileicons/file_extension_txt.png +0 -0
- data/app/assets/images/fileicons/file_extension_unknown.png +0 -0
- data/app/assets/images/fileicons/file_extension_vcd.png +0 -0
- data/app/assets/images/fileicons/file_extension_vob.png +0 -0
- data/app/assets/images/fileicons/file_extension_wav.png +0 -0
- data/app/assets/images/fileicons/file_extension_wma.png +0 -0
- data/app/assets/images/fileicons/file_extension_wmv.png +0 -0
- data/app/assets/images/fileicons/file_extension_wps.png +0 -0
- data/app/assets/images/fileicons/file_extension_xls.png +0 -0
- data/app/assets/images/fileicons/file_extension_xlsx.png +0 -0
- data/app/assets/images/fileicons/file_extension_xpi.png +0 -0
- data/app/assets/images/fileicons/file_extension_zip.png +0 -0
- data/app/assets/images/material/icons/keyboard_arrow_down.svg +0 -4
- data/app/assets/images/material/icons/keyboard_arrow_left.svg +0 -4
- data/app/assets/images/material/icons/keyboard_arrow_right.svg +0 -4
- data/app/assets/images/material/icons/keyboard_arrow_up.svg +0 -4
- data/app/assets/images/material/icons/today.svg +0 -4
- data/app/assets/javascripts/activeadmin_addons/all.js +0 -753
- data/app/assets/stylesheets/activeadmin_addons/addons/material-datepicker.scss +0 -173
- data/app/assets/stylesheets/activeadmin_addons/addons/material-toggle_bool.scss +0 -52
- data/app/assets/stylesheets/activeadmin_addons/inputs/select2.scss +0 -3
- data/app/assets/stylesheets/activeadmin_addons/material.scss +0 -53
- data/app/javascript/activeadmin_addons/addons/interactive_select_tag.js +0 -95
- data/app/javascript/activeadmin_addons/inputs/nested-select.js +0 -170
- data/app/javascript/activeadmin_addons/inputs/search-select.js +0 -76
- data/app/javascript/activeadmin_addons/inputs/select2.js +0 -52
- data/app/javascript/activeadmin_addons/inputs/selected-list.js +0 -107
- data/app/javascript/activeadmin_addons/inputs/tags.js +0 -76
- data/lib/activeadmin_addons/addons/attachment_builder.rb +0 -60
- data/lib/activeadmin_addons/support/enumerize_formtastic_support.rb +0 -18
- data/lib/generators/activeadmin_addons/assets/assets_generator.rb +0 -53
- data/vendor/assets/select2/select2.css +0 -481
- data/vendor/assets/select2/select2.full.js +0 -6820
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/addons/interactive_select_tag.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/addons/toggle_bool.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/imports/jquery-datepicker.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/color-picker.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/date-time-picker-filter.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/date-time-picker.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/numeric-range-filter.scss +0 -0
- /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/vendor/palette-color-picker.scss +0 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
const classes = ['tags-input'];
|
2
|
+
|
3
|
+
// eslint-disable-next-line max-statements
|
4
|
+
function settings(el) {
|
5
|
+
const isRelation = el.dataset.relation === 'true';
|
6
|
+
const collection = el.dataset.collection ? JSON.parse(el.dataset.collection) : null;
|
7
|
+
|
8
|
+
const parsedCollection = collection && collection.map((item) => {
|
9
|
+
const { id, ...rest } = item;
|
10
|
+
|
11
|
+
return { ...rest, value: id, selected: !!item.selected };
|
12
|
+
});
|
13
|
+
|
14
|
+
const events = {};
|
15
|
+
if (!isRelation) {
|
16
|
+
events.addable = (value) => value;
|
17
|
+
}
|
18
|
+
|
19
|
+
return {
|
20
|
+
data: parsedCollection,
|
21
|
+
events,
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
export {
|
26
|
+
settings,
|
27
|
+
classes,
|
28
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import merge from 'lodash.merge';
|
2
|
+
|
3
|
+
function parseObjectToQuery(obj, prefix) {
|
4
|
+
let queryArray = [];
|
5
|
+
Object.keys(obj).forEach(key => {
|
6
|
+
const value = obj[key];
|
7
|
+
const prefixedKey = prefix ? `${prefix}[${key}]` : key;
|
8
|
+
if (Array.isArray(value)) {
|
9
|
+
value.forEach((v, i) => {
|
10
|
+
queryArray = [...queryArray, parseObjectToQuery(v, `${prefixedKey}[${i}]`)];
|
11
|
+
});
|
12
|
+
} else if (typeof value === 'object') {
|
13
|
+
queryArray = [...queryArray, parseObjectToQuery(value, prefixedKey)];
|
14
|
+
} else {
|
15
|
+
queryArray.push(`${prefixedKey}=${encodeURIComponent(value)}`);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
return queryArray.join('&');
|
20
|
+
}
|
21
|
+
|
22
|
+
export function ransackSearch(search, currentData, settings) {
|
23
|
+
return new Promise((resolve, reject) => {
|
24
|
+
if (search.length < settings.minimumInputLength) {
|
25
|
+
reject(`Please enter ${settings.minimumInputLength} or more characters`);
|
26
|
+
}
|
27
|
+
|
28
|
+
const defaultQuery = {
|
29
|
+
order: settings.order,
|
30
|
+
q: {
|
31
|
+
groupings: [settings.textQuery],
|
32
|
+
combinator: 'and',
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
const finalQuery = merge({}, defaultQuery, settings.query);
|
37
|
+
const csrfTokenEl = document.querySelector('meta[name="csrf-token"]');
|
38
|
+
const csrfToken = csrfTokenEl ? csrfTokenEl.getAttribute('content') : null;
|
39
|
+
|
40
|
+
const queryString = parseObjectToQuery(finalQuery);
|
41
|
+
fetch(`${settings.url}?${queryString}`, {
|
42
|
+
method: 'GET',
|
43
|
+
headers: {
|
44
|
+
'X-CSRF-TOKEN': csrfToken,
|
45
|
+
'Accept': 'application/json',
|
46
|
+
'Content-Type': 'application/json',
|
47
|
+
},
|
48
|
+
})
|
49
|
+
.then((response) => response.json())
|
50
|
+
.then((res) => {
|
51
|
+
let data = res;
|
52
|
+
if (data.constructor === Object) {
|
53
|
+
data = data[settings.responseRoot];
|
54
|
+
}
|
55
|
+
|
56
|
+
const options = data.map(resource => {
|
57
|
+
if (!resource[settings.displayName]) {
|
58
|
+
resource[settings.displayName] = `No display name for id #${resource.id.toString()}`;
|
59
|
+
}
|
60
|
+
|
61
|
+
return {
|
62
|
+
value: resource.id,
|
63
|
+
text: resource[settings.displayName],
|
64
|
+
};
|
65
|
+
});
|
66
|
+
|
67
|
+
resolve(options);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import SlimSelect from 'slim-select';
|
2
|
+
import merge from 'lodash.merge';
|
3
|
+
|
4
|
+
import * as searchSelect from './slim-select-search';
|
5
|
+
import * as simpleTagsSelect from './slim-select-simple-tags';
|
6
|
+
import * as nestedSelect from './slim-select-nested';
|
7
|
+
import * as selectedListSelect from './slim-select-selected-list';
|
8
|
+
import * as tagsSelect from './slim-select-tags';
|
9
|
+
|
10
|
+
const SELECT_CLASS = 'select:not(.default-select)';
|
11
|
+
const SLIM_SELECT_CLASS = 'select.slim-select';
|
12
|
+
|
13
|
+
const selectTypes = {
|
14
|
+
searchSelect,
|
15
|
+
simpleTagsSelect,
|
16
|
+
nestedSelect,
|
17
|
+
selectedListSelect,
|
18
|
+
tagsSelect,
|
19
|
+
};
|
20
|
+
|
21
|
+
// eslint-disable-next-line max-statements, complexity
|
22
|
+
function setupSelect(el) {
|
23
|
+
let settings = {
|
24
|
+
select: el,
|
25
|
+
settings: {
|
26
|
+
allowDeselect: true,
|
27
|
+
placeholderText: 'Select Value',
|
28
|
+
},
|
29
|
+
};
|
30
|
+
|
31
|
+
const selectStyles = window.getComputedStyle(el);
|
32
|
+
el.style.width = el.dataset.width;
|
33
|
+
el.style.fontSize = selectStyles.fontSize;
|
34
|
+
|
35
|
+
const searchSelectFilter = el.closest('.filter_form_field');
|
36
|
+
if (searchSelectFilter) {
|
37
|
+
if (searchSelectFilter.classList.contains('search_select_filter') ||
|
38
|
+
searchSelectFilter.classList.contains('filter_string')) {
|
39
|
+
settings.settings.allowDeselect = false;
|
40
|
+
}
|
41
|
+
|
42
|
+
if (el.options.length > 0) {
|
43
|
+
el.style.width = el.dataset.width || selectStyles.width;
|
44
|
+
if (selectStyles.display === 'inline-block') {
|
45
|
+
el.style.display = 'inline-flex';
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
const emptyOption = el.querySelector('option[value=""]');
|
51
|
+
if (!emptyOption) {
|
52
|
+
el.insertAdjacentHTML('afterbegin', '<option value=""></option>');
|
53
|
+
}
|
54
|
+
el.querySelector('option[value=""]').dataset.placeholder = true;
|
55
|
+
|
56
|
+
Object.keys(selectTypes).forEach((type) => {
|
57
|
+
if (selectTypes[type].classes.some((className) => el.classList.contains(className))) {
|
58
|
+
settings = merge({}, settings, selectTypes[type].settings(el));
|
59
|
+
if (selectTypes[type].init) {
|
60
|
+
selectTypes[type].init(el);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
});
|
64
|
+
|
65
|
+
// eslint-disable-next-line no-new
|
66
|
+
new SlimSelect(settings);
|
67
|
+
}
|
68
|
+
|
69
|
+
function initSelects(node = document) {
|
70
|
+
if (document.querySelector('body').dataset.defaultSelect === 'slim-select') {
|
71
|
+
node.querySelectorAll(SELECT_CLASS).forEach(setupSelect);
|
72
|
+
}
|
73
|
+
|
74
|
+
node.querySelectorAll(SLIM_SELECT_CLASS).forEach(setupSelect);
|
75
|
+
}
|
76
|
+
|
77
|
+
// mutation observer to add slim select to new elements
|
78
|
+
const observer = new MutationObserver((mutations) => {
|
79
|
+
mutations.forEach((mutation) => {
|
80
|
+
if (mutation.type === 'childList') {
|
81
|
+
mutation.addedNodes.forEach((node) => {
|
82
|
+
if (node instanceof Element) {
|
83
|
+
initSelects(node);
|
84
|
+
}
|
85
|
+
});
|
86
|
+
}
|
87
|
+
});
|
88
|
+
});
|
89
|
+
|
90
|
+
window.addEventListener('load', () => {
|
91
|
+
initSelects();
|
92
|
+
observer.observe(document.querySelector('body'), { attributes: false, childList: true, subtree: true });
|
93
|
+
});
|
@@ -1,20 +1,14 @@
|
|
1
|
-
@import 'select2';
|
2
1
|
@import 'imports/jquery-datepicker';
|
3
2
|
@import 'vendor/palette-color-picker';
|
3
|
+
@import 'imports/slimselect';
|
4
|
+
|
5
|
+
$error-color: #932419;
|
4
6
|
|
5
7
|
@import 'inputs/numeric-range-filter';
|
6
8
|
@import 'inputs/date-time-picker-filter';
|
7
9
|
@import 'inputs/color-picker';
|
8
10
|
@import 'inputs/date-time-picker';
|
9
|
-
@import 'inputs/select2';
|
10
11
|
@import 'inputs/selected-list';
|
12
|
+
@import 'inputs/slim-select';
|
11
13
|
@import 'addons/toggle_bool';
|
12
14
|
@import 'addons/interactive_select_tag';
|
13
|
-
|
14
|
-
$error-color: #932419;
|
15
|
-
|
16
|
-
li.error {
|
17
|
-
.select2-selection {
|
18
|
-
border-color: $error-color;
|
19
|
-
}
|
20
|
-
}
|
@@ -0,0 +1 @@
|
|
1
|
+
:root{--ss-primary-color: #5897fb;--ss-bg-color: #ffffff;--ss-font-color: #4d4d4d;--ss-font-placeholder-color: #8d8d8d;--ss-disabled-color: #dcdee2;--ss-border-color: #dcdee2;--ss-highlight-color: #fffb8c;--ss-success-color: #00b755;--ss-error-color: #dc3545;--ss-main-height: 30px;--ss-content-height: 300px;--ss-spacing-l: 7px;--ss-spacing-m: 5px;--ss-spacing-s: 3px;--ss-animation-timing: 0.2s;--ss-border-radius: 4px}@keyframes ss-valueIn{0%{transform:scale(0);opacity:0}100%{transform:scale(1);opacity:1}}@keyframes ss-valueOut{0%{transform:scale(1);opacity:1}100%{transform:scale(0);opacity:0}}.ss-hide{display:none !important}.ss-main{display:flex;flex-direction:row;position:relative;user-select:none;color:var(--ss-font-color);min-height:var(--ss-main-height);width:100%;padding:var(--ss-spacing-s);cursor:pointer;border:1px solid var(--ss-border-color);border-radius:var(--ss-border-radius);background-color:var(--ss-bg-color);outline:0;box-sizing:border-box;transition:background-color var(--ss-animation-timing)}.ss-main:focus{box-shadow:0 0 5px var(--ss-primary-color)}.ss-main.ss-disabled{background-color:var(--ss-disabled-color);cursor:not-allowed}.ss-main.ss-disabled .ss-values .ss-disabled{color:var(--ss-font-color)}.ss-main.ss-disabled .ss-values .ss-value .ss-value-delete{cursor:not-allowed}.ss-main.ss-open-above{border-top-left-radius:0px;border-top-right-radius:0px}.ss-main.ss-open-below{border-bottom-left-radius:0px;border-bottom-right-radius:0px}.ss-main .ss-values{display:inline-flex;flex-wrap:wrap;gap:var(--ss-spacing-m);flex:1 1 100%}.ss-main .ss-values .ss-placeholder{display:flex;padding:var(--ss-spacing-s) var(--ss-spacing-m) var(--ss-spacing-s) var(--ss-spacing-m);margin:auto 0px auto 0px;line-height:1em;align-items:center;width:100%;color:var(--ss-font-placeholder-color);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ss-main .ss-values .ss-max{display:flex;user-select:none;align-items:center;width:fit-content;font-size:12px;color:var(--ss-bg-color);line-height:1;padding:var(--ss-spacing-s) var(--ss-spacing-m);background-color:var(--ss-primary-color);border-radius:var(--ss-border-radius)}.ss-main .ss-values .ss-single{display:flex;margin:auto 0px auto var(--ss-spacing-s)}.ss-main .ss-values .ss-value{display:flex;user-select:none;align-items:center;width:fit-content;background-color:var(--ss-primary-color);border-radius:var(--ss-border-radius);animation-name:ss-valueIn;animation-duration:var(--ss-animation-timing);animation-timing-function:ease-out;animation-fill-mode:both}.ss-main .ss-values .ss-value.ss-value-out{animation-name:ss-valueOut;animation-duration:var(--ss-animation-timing);animation-timing-function:ease-out}.ss-main .ss-values .ss-value .ss-value-text{font-size:12px;color:var(--ss-bg-color);line-height:1;padding:var(--ss-spacing-s) var(--ss-spacing-m)}.ss-main .ss-values .ss-value .ss-value-delete{display:flex;align-items:center;height:var(--ss-spacing-l);width:var(--ss-spacing-l);padding:var(--ss-spacing-s) var(--ss-spacing-m);cursor:pointer;border-left:solid 1px var(--ss-bg-color)}.ss-main .ss-values .ss-value .ss-value-delete svg{height:var(--ss-spacing-l);width:var(--ss-spacing-l)}.ss-main .ss-values .ss-value .ss-value-delete svg path{fill:none;stroke:var(--ss-bg-color);stroke-width:18;stroke-linecap:round;stroke-linejoin:round}.ss-main .ss-deselect{display:flex;align-self:center;justify-content:flex-end;flex:0 1 auto;width:8px;height:8px;margin:0 var(--ss-spacing-m) 0 var(--ss-spacing-m)}.ss-main .ss-deselect svg{width:8px;height:8px}.ss-main .ss-deselect svg path{fill:none;stroke:var(--ss-font-color);stroke-width:20;stroke-linecap:round;stroke-linejoin:round}.ss-main .ss-arrow{display:flex;align-items:center;justify-content:flex-end;flex:0 1 auto;width:12px;height:12px;margin:auto var(--ss-spacing-m) auto var(--ss-spacing-m)}.ss-main .ss-arrow path{fill:none;stroke:var(--ss-font-color);stroke-width:18;stroke-linecap:round;stroke-linejoin:round;transition-timing-function:ease-out;transition:var(--ss-animation-timing)}.ss-content{position:absolute;display:flex;height:auto;flex-direction:column;width:auto;max-height:var(--ss-content-height);box-sizing:border-box;border:solid 1px var(--ss-border-color);background-color:var(--ss-bg-color);transition:transform var(--ss-animation-timing),opacity var(--ss-animation-timing);opacity:0;transform:scaleY(0);transform-origin:center top;overflow:hidden;z-index:10000}.ss-content.ss-relative{position:relative;height:100%}.ss-content.ss-open-above{flex-direction:column-reverse;opacity:1;transform:scaleY(1);transform-origin:center bottom;border-top-left-radius:var(--ss-border-radius);border-top-right-radius:var(--ss-border-radius)}.ss-content.ss-open-below{opacity:1;transform:scaleY(1);transform-origin:center top;border-bottom-left-radius:var(--ss-border-radius);border-bottom-right-radius:var(--ss-border-radius)}.ss-content .ss-search{flex:0 1 auto;display:flex;flex-direction:row;padding:var(--ss-spacing-l) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l)}.ss-content .ss-search input{display:inline-flex;font-size:inherit;line-height:inherit;flex:1 1 auto;width:100%;min-width:0px;padding:var(--ss-spacing-m) var(--ss-spacing-l);margin:0;border:1px solid var(--ss-border-color);border-radius:var(--ss-border-radius);background-color:var(--ss-bg-color);outline:0;text-align:left;box-sizing:border-box}.ss-content .ss-search input::placeholder{color:var(--ss-font-placeholder-color);vertical-align:middle}.ss-content .ss-search input:focus{box-shadow:0 0 5px var(--ss-primary-color)}.ss-content .ss-search .ss-addable{display:inline-flex;justify-content:center;align-items:center;cursor:pointer;flex:0 0 auto;height:auto;margin:0 0 0 var(--ss-spacing-m);border:1px solid var(--ss-border-color);border-radius:var(--ss-border-radius)}.ss-content .ss-search .ss-addable svg{display:flex;align-items:center;justify-content:flex-end;flex:0 1 auto;width:12px;height:12px;margin:auto var(--ss-spacing-m) auto var(--ss-spacing-m)}.ss-content .ss-search .ss-addable svg path{fill:none;stroke:var(--ss-font-color);stroke-width:18;stroke-linecap:round;stroke-linejoin:round}.ss-content .ss-list{flex:1 1 auto;height:auto;overflow-x:hidden;overflow-y:auto}.ss-content .ss-list .ss-error{color:var(--ss-error-color);padding:var(--ss-spacing-l)}.ss-content .ss-list .ss-searching{color:var(--ss-font-color);padding:var(--ss-spacing-l)}.ss-content .ss-list .ss-optgroup.ss-close .ss-option{display:none !important}.ss-content .ss-list .ss-optgroup .ss-optgroup-label{display:flex;flex-direction:row;align-items:center;justify-content:space-between;padding:var(--ss-spacing-m) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l)}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-label-text{flex:1 1 auto;font-weight:bold;color:var(--ss-font-color)}.ss-content .ss-list .ss-optgroup .ss-optgroup-label:has(.ss-arrow){cursor:pointer}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions{flex:0 1 auto;display:flex;flex-direction:row;align-items:center;justify-content:center;gap:var(--ss-spacing-m)}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall{flex:0 0 auto;display:flex;flex-direction:row;cursor:pointer}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall:hover{opacity:.5}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall.ss-selected svg path{stroke:var(--ss-error-color)}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall span{flex:0 1 auto;display:flex;align-items:center;justify-content:center;font-size:60%;text-align:center;padding:0 var(--ss-spacing-s) 0 0}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall svg{flex:0 1 auto;width:13px;height:13px}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall svg path{fill:none;stroke:var(--ss-success-color);stroke-linecap:round;stroke-linejoin:round}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall svg:first-child{stroke-width:5}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-selectall svg:last-child{stroke-width:11}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-closable{flex:0 1 auto;display:flex;flex-direction:row;cursor:pointer}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-closable .ss-arrow{flex:1 1 auto;width:10px;height:10px}.ss-content .ss-list .ss-optgroup .ss-optgroup-label .ss-optgroup-actions .ss-closable .ss-arrow path{fill:none;stroke:var(--ss-font-color);stroke-width:18;stroke-linecap:round;stroke-linejoin:round;transition-timing-function:ease-out;transition:var(--ss-animation-timing)}.ss-content .ss-list .ss-optgroup .ss-option{padding:var(--ss-spacing-s) var(--ss-spacing-s) var(--ss-spacing-s) calc(var(--ss-spacing-l)*3)}.ss-content .ss-list .ss-option{display:flex;padding:var(--ss-spacing-m) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l);color:var(--ss-font-color);cursor:pointer;user-select:none}.ss-content .ss-list .ss-option:hover{color:var(--ss-bg-color);background-color:var(--ss-primary-color)}.ss-content .ss-list .ss-option.ss-highlighted,.ss-content .ss-list .ss-option:not(.ss-disabled).ss-selected{color:var(--ss-bg-color);background-color:var(--ss-primary-color)}.ss-content .ss-list .ss-option.ss-disabled{cursor:not-allowed;background-color:var(--ss-disabled-color)}.ss-content .ss-list .ss-option.ss-disabled:hover{color:var(--ss-font-color)}.ss-content .ss-list .ss-option .ss-search-highlight{background-color:var(--ss-highlight-color)}
|
@@ -3,22 +3,15 @@ module ActiveAdminAddons
|
|
3
3
|
def render
|
4
4
|
return nil if data.nil?
|
5
5
|
|
6
|
-
if Object.const_defined?('
|
7
|
-
paperclip_data
|
8
|
-
elsif Object.const_defined?('Shrine::UploadedFile') && data.is_a?(Shrine::UploadedFile)
|
6
|
+
if Object.const_defined?('Shrine::UploadedFile') && data.is_a?(Shrine::UploadedFile)
|
9
7
|
shrine_data
|
10
8
|
else
|
11
|
-
raise "you need to pass a
|
9
|
+
raise "you need to pass a shrine image attribute"
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
16
14
|
|
17
|
-
def paperclip_data
|
18
|
-
style = options.fetch(:style, :original)
|
19
|
-
context.image_tag(data.url(style)) if data.file?
|
20
|
-
end
|
21
|
-
|
22
15
|
def shrine_data
|
23
16
|
image_options = options[:image_options].presence || {}
|
24
17
|
if options[:style] && derivatives.include?(options[:style])
|
@@ -11,6 +11,7 @@ module ActiveAdminAddons
|
|
11
11
|
def render
|
12
12
|
raise "you need to install AASM gem first" unless defined? AASM
|
13
13
|
raise "the #{attribute} is not an AASM state" unless state_attribute?
|
14
|
+
|
14
15
|
context.status_tag(model.aasm(machine_name).human_state, class: status_class_for_model)
|
15
16
|
end
|
16
17
|
|
@@ -1,13 +1,8 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
2
|
class TagBuilder < CustomBuilder
|
3
3
|
def render
|
4
|
-
|
5
|
-
:enumerize
|
6
|
-
elsif rails_enum_attr?
|
7
|
-
:enum
|
8
|
-
end
|
4
|
+
raise "you need to pass an enum attribute" unless rails_enum_attr?
|
9
5
|
|
10
|
-
raise "you need to pass an enumerize or enum attribute" unless @enum_attr
|
11
6
|
append_tag
|
12
7
|
end
|
13
8
|
|
@@ -36,11 +31,7 @@ module ActiveAdminAddons
|
|
36
31
|
end
|
37
32
|
|
38
33
|
def display_data
|
39
|
-
|
40
|
-
data.text
|
41
|
-
else
|
42
|
-
EnumUtils.translate_enum_option(model.class, attribute.to_s, data)
|
43
|
-
end
|
34
|
+
EnumUtils.translate_enum_option(model.class, attribute.to_s, data)
|
44
35
|
end
|
45
36
|
|
46
37
|
def interactive_params(klass)
|
@@ -72,17 +63,7 @@ module ActiveAdminAddons
|
|
72
63
|
|
73
64
|
def possible_values
|
74
65
|
klass = model.class
|
75
|
-
|
76
|
-
klass.enumerized_attributes[attribute.to_s].values.map { |value| [value.capitalize, value] }
|
77
|
-
else
|
78
|
-
EnumUtils.options_for_select(klass, attribute.to_s)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def enumerize_attr?
|
83
|
-
data.is_a?("Enumerize::Value".constantize)
|
84
|
-
rescue NameError
|
85
|
-
false
|
66
|
+
EnumUtils.options_for_select(klass, attribute.to_s)
|
86
67
|
end
|
87
68
|
|
88
69
|
def rails_enum_attr?
|
@@ -1,18 +1,13 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
2
|
module Rails
|
3
3
|
class Engine < ::Rails::Engine
|
4
|
-
require 'sassc'
|
5
|
-
require 'sassc-rails'
|
6
4
|
require "xdan-datetimepicker-rails"
|
7
5
|
require "require_all"
|
8
|
-
require "active_material"
|
9
6
|
|
10
|
-
initializer "initialize addons" do |
|
7
|
+
initializer "initialize addons" do |_app|
|
11
8
|
require_rel "support"
|
12
9
|
require_rel "addons"
|
13
10
|
require_rel "active_admin_config"
|
14
|
-
app.config.assets.precompile += %w(select.scss fileicons/*.png switches/switch_*.png
|
15
|
-
material/icons *.svg)
|
16
11
|
end
|
17
12
|
end
|
18
13
|
end
|
@@ -7,47 +7,5 @@ module ActiveAdminAddons
|
|
7
7
|
include InputOptionsHandler
|
8
8
|
include InputMethods
|
9
9
|
include InputHtmlHelpers
|
10
|
-
|
11
|
-
def to_html
|
12
|
-
load_input_class
|
13
|
-
load_control_attributes
|
14
|
-
render_custom_input
|
15
|
-
if parts.any?
|
16
|
-
return input_wrapping { parts_to_html }
|
17
|
-
else
|
18
|
-
super
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def input_html_options
|
23
|
-
# maxwidth and size are added by Formtastic::Inputs::StringInput
|
24
|
-
# but according to the HTML standard these are not valid attributes
|
25
|
-
# on the inputs provided by this module
|
26
|
-
super.except(:maxlength, :size).merge(control_attributes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def parts_to_html
|
30
|
-
parts.flatten.join("\n").html_safe
|
31
|
-
end
|
32
|
-
|
33
|
-
def load_input_class
|
34
|
-
load_class(self.class.to_s.underscore.dasherize)
|
35
|
-
end
|
36
|
-
|
37
|
-
def load_control_attributes
|
38
|
-
# Override on child classes if needed
|
39
|
-
end
|
40
|
-
|
41
|
-
def render_custom_input
|
42
|
-
# Override on child classes if needed
|
43
|
-
end
|
44
|
-
|
45
|
-
def parts
|
46
|
-
@parts ||= []
|
47
|
-
end
|
48
|
-
|
49
|
-
def concat(part)
|
50
|
-
parts << part
|
51
|
-
end
|
52
10
|
end
|
53
11
|
end
|
@@ -40,5 +40,47 @@ module ActiveAdminAddons
|
|
40
40
|
value: value
|
41
41
|
)
|
42
42
|
end
|
43
|
+
|
44
|
+
def to_html
|
45
|
+
load_input_class
|
46
|
+
load_control_attributes
|
47
|
+
render_custom_input
|
48
|
+
if parts.any?
|
49
|
+
input_wrapping { parts_to_html }
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def input_html_options
|
56
|
+
# maxwidth and size are added by Formtastic::Inputs::StringInput
|
57
|
+
# but according to the HTML standard these are not valid attributes
|
58
|
+
# on the inputs provided by this module
|
59
|
+
super.except(:maxlength, :size).merge(control_attributes)
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_input_class
|
63
|
+
load_class(self.class.to_s.underscore.dasherize)
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_control_attributes
|
67
|
+
# Override on child classes if needed
|
68
|
+
end
|
69
|
+
|
70
|
+
def render_custom_input
|
71
|
+
# Override on child classes if needed
|
72
|
+
end
|
73
|
+
|
74
|
+
def parts_to_html
|
75
|
+
parts.flatten.join("\n").html_safe # rubocop:disable Rails/OutputSafety
|
76
|
+
end
|
77
|
+
|
78
|
+
def concat(part)
|
79
|
+
parts << part
|
80
|
+
end
|
81
|
+
|
82
|
+
def parts
|
83
|
+
@parts ||= []
|
84
|
+
end
|
43
85
|
end
|
44
86
|
end
|
@@ -14,7 +14,7 @@ module ActiveAdminAddons
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initial_collection_to_select_options
|
17
|
-
initial_options = [
|
17
|
+
initial_options = [] # add blank option
|
18
18
|
selected = selected_item
|
19
19
|
|
20
20
|
if selected
|
@@ -57,21 +57,19 @@ module ActiveAdminAddons
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def selected_collection
|
60
|
-
@selected_collection ||=
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
60
|
+
@selected_collection ||= if active_record_relation?(collection)
|
61
|
+
collection.model.where(id: input_value)
|
62
|
+
else
|
63
|
+
method_model.where(id: input_value)
|
64
|
+
end
|
67
65
|
end
|
68
66
|
|
69
67
|
def selected_item
|
70
68
|
@selected_item ||= begin
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
input_association_value
|
70
|
+
rescue NoMethodError
|
71
|
+
selected_collection.first
|
72
|
+
end
|
75
73
|
end
|
76
74
|
|
77
75
|
private
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "input_helpers/input_options_handler"
|
2
|
+
require_relative "input_helpers/input_methods"
|
3
|
+
require_relative "input_helpers/input_html_helpers"
|
4
|
+
|
5
|
+
module ActiveAdminAddons
|
6
|
+
class SelectInputBase < Formtastic::Inputs::SelectInput
|
7
|
+
include InputOptionsHandler
|
8
|
+
include InputMethods
|
9
|
+
include InputHtmlHelpers
|
10
|
+
end
|
11
|
+
end
|
data/lib/activeadmin_addons.rb
CHANGED
@@ -4,17 +4,20 @@ module ActiveadminAddons
|
|
4
4
|
attr_writer :default_select, :datetime_picker_default_options, :datetime_picker_input_format
|
5
5
|
|
6
6
|
def default_select
|
7
|
-
return "
|
7
|
+
return "slim-select" unless @default_select
|
8
|
+
|
8
9
|
@default_select
|
9
10
|
end
|
10
11
|
|
11
12
|
def datetime_picker_default_options
|
12
13
|
return {} unless @datetime_picker_default_options
|
14
|
+
|
13
15
|
@datetime_picker_default_options
|
14
16
|
end
|
15
17
|
|
16
18
|
def datetime_picker_input_format
|
17
19
|
return "%Y-%m-%d %H:%M" unless @datetime_picker_input_format
|
20
|
+
|
18
21
|
@datetime_picker_input_format
|
19
22
|
end
|
20
23
|
|
@@ -11,7 +11,8 @@ module ActiveadminAddons
|
|
11
11
|
if use_webpacker?
|
12
12
|
generate "activeadmin_addons:webpacker"
|
13
13
|
else
|
14
|
-
|
14
|
+
puts "ActiveAdmin Addons requires ActiveAdmin installed with webpacker. "\
|
15
|
+
"Please run 'rails generate active_admin:install --webpacker' and then 'rails generate activeadmin_addons:install'"
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
ActiveadminAddons.setup do |config|
|
2
2
|
# Change to "default" if you want to use ActiveAdmin's default select control.
|
3
|
-
# config.default_select = "
|
3
|
+
# config.default_select = "slim-select"
|
4
4
|
|
5
5
|
# Set default options for DateTimePickerInput. The options you can provide are the same as in
|
6
|
-
# xdan's datetimepicker library (https://github.com/xdan/datetimepicker/tree/2.5.4).
|
6
|
+
# xdan's datetimepicker library (https://github.com/xdan/datetimepicker/tree/2.5.4). You need to
|
7
7
|
# pass a ruby hash, avoid camelCase keys. For example: use min_date instead of minDate key.
|
8
8
|
# config.datetime_picker_default_options = {}
|
9
9
|
|
@@ -11,20 +11,17 @@ module ActiveadminAddons
|
|
11
11
|
def add_stylesheets
|
12
12
|
file_path = 'app/javascript/stylesheets/active_admin.scss'
|
13
13
|
|
14
|
-
|
15
|
-
prepend_file(file_path, css_assets)
|
16
|
-
end
|
14
|
+
prepend_file(file_path, css_assets)
|
17
15
|
end
|
18
16
|
|
19
17
|
def install_package
|
20
|
-
run "yarn add activeadmin_addons"
|
18
|
+
run "yarn add activeadmin_addons@beta"
|
21
19
|
end
|
22
20
|
|
23
21
|
private
|
24
22
|
|
25
23
|
def js_assets
|
26
|
-
|
27
|
-
to_add
|
24
|
+
"import \"activeadmin_addons\"\n"
|
28
25
|
end
|
29
26
|
|
30
27
|
def css_assets
|