@massimo-cassandro/minimo 1.7.1 → 1.8.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.
- package/design-tokens/tokens/size.minimo.tokens.jsonc +16 -16
- package/index.js +4 -2
- package/package.json +1 -1
- package/src/components/TODO form-multiselect/form-multiselect.css +40 -0
- package/src/components/TODO form-multiselect/form-multiselect.js +83 -0
- package/src/components/TODO vanilla-cookie-consent/cookie-consent.css +20 -0
- package/src/components/TODO vanilla-cookie-consent/cookie-consent.js +76 -0
- package/src/components/TODO vanilla-cookie-consent/render-cookie-list.js +32 -0
- package/src/components/TODO vanilla-cookie-consent/src/cookie-list.js +85 -0
- package/src/components/TODO vanilla-cookie-consent/src/it-translation.js +38 -0
- package/src/components/TODO vanilla-cookie-consent/src/run-analytics.js +54 -0
- package/src/components/TODO vanilla-cookie-consent/src/run-recaptcha.js +71 -0
- package/src/components/modal-alert/TODO modal-alert-demo/demo.css +63 -0
- package/src/components/modal-alert/TODO modal-alert-demo/demo.js +155 -0
- package/src/components/modal-popup/modal-popup.js +2 -1
- package/src/components/slide-up-down-toggle/slide-up-down-toggle.js +246 -0
- package/src/components/slide-up-down-toggle/slide-up-down-toggle.module.css +97 -0
- package/src/components/snackbar/snackbar.js +2 -1
- package/src/components/spinner/spinner.js +2 -1
- package/src/components/unsplash-page/TODO unsplash-page-demo/README.md +194 -0
- package/src/components/unsplash-page/TODO unsplash-page-demo/changelog.md +5 -0
- package/src/components/unsplash-page/TODO unsplash-page-demo/unsplash-page/demo.js +15 -0
- package/src/components/unsplash-page/TODO unsplash-page-demo/unsplash-page/rollup.config.mjs +26 -0
- package/src/components/unsplash-page/TODO unsplash-page-demo/unsplash-page/unsplash-page-demo.min.js +3 -0
- package/src/utilities/generate-pwd.js +22 -0
- package/src/web-components/TODO json-table/README.md +67 -0
- package/src/web-components/TODO json-table/TODO.md +12 -0
- package/src/web-components/TODO json-table/_work/OLD/docs/custom-props-list.md +69 -0
- package/src/web-components/TODO json-table/_work/OLD/script/create-css-custom-props-doc.mjs +113 -0
- package/src/web-components/TODO json-table/_work/OLD/script/src/custom-props-end.md +4 -0
- package/src/web-components/TODO json-table/_work/OLD/script/src/custom-props-start.md +30 -0
- package/src/web-components/TODO json-table/_work/OLD/src/css/icons.module.css +22 -0
- package/src/web-components/TODO json-table/_work/OLD/src/css/info.module.css +42 -0
- package/src/web-components/TODO json-table/_work/OLD/src/css/main-wrapper.module.css +4 -0
- package/src/web-components/TODO json-table/_work/OLD/src/css/table.module.css +154 -0
- package/src/web-components/TODO json-table/_work/OLD/src/css/utility.module.css +9 -0
- package/src/web-components/TODO json-table/_work/OLD/src/icons/false.svg +1 -0
- package/src/web-components/TODO json-table/_work/OLD/src/icons/search-arrows.svg +1 -0
- package/src/web-components/TODO json-table/_work/OLD/src/icons/true.svg +1 -0
- package/src/web-components/TODO json-table/_work/OLD/src/index.js +56 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/default-columns-data-types.js +172 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/defaults.js +156 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/info-section.js +31 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/listeners.js +17 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/main-builder.js +26 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/parse-params.js +121 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/set-column-classname.js +22 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/table-builder.js +64 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/table-foot.js +8 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/table-head.js +47 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/table-row.js +83 -0
- package/src/web-components/TODO json-table/_work/OLD/src/js/utilities.js +5 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/index.js +4 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/build-page-array.js +73 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/columns-data-types.js +73 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/defaults.js +50 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/download-excel.js +156 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/set-className.js +19 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/set-download-filename.js +17 -0
- package/src/web-components/TODO json-table/_work/__json-table-react/src/table-to-csv.js +48 -0
- package/src/web-components/TODO json-table/_work/archived/table-to-csv.js +48 -0
- package/src/web-components/TODO json-table/_work/arrow.svg +3 -0
- package/src/web-components/TODO json-table/_work/da decidere/get-cell-data.js +18 -0
- package/src/web-components/TODO json-table/_work/download-button.js +29 -0
- package/src/web-components/TODO json-table/_work/download-excel.js +155 -0
- package/src/web-components/TODO json-table/_work/pagination-array-builder.js +73 -0
- package/src/web-components/TODO json-table/_work/pagination.js +37 -0
- package/src/web-components/TODO json-table/_work/set-download-filename.js +19 -0
- package/src/web-components/TODO json-table/_work/table-info.js +24 -0
- package/src/web-components/TODO json-table/demo/README.md +66 -0
- package/src/web-components/TODO json-table/demo/assets/link-simple.svg +1 -0
- package/src/web-components/TODO json-table/demo/demo-data/json-static-table-demo-data.js +512 -0
- package/src/web-components/TODO json-table/demo/demo.css +32 -0
- package/src/web-components/TODO json-table/demo/demo.js +24 -0
- package/src/web-components/TODO json-table/demo/js/demo-ajax-table.js +165 -0
- package/src/web-components/TODO json-table/demo/js/demo-static-table.js +180 -0
- package/src/web-components/TODO json-table/demo/webpack-modules/css-rules.mjs +122 -0
- package/src/web-components/TODO json-table/demo/webpack-modules/get-jsConfig-aliases.mjs +33 -0
- package/src/web-components/TODO json-table/demo/webpack-modules/svg-rules.mjs +108 -0
- package/src/web-components/TODO json-table/demo/webpack-modules/svgo.config.mjs +26 -0
- package/src/web-components/TODO json-table/demo/webpack.config.mjs +333 -0
- package/src/web-components/TODO json-table/docs/custom-props-list.md +74 -0
- package/src/web-components/TODO json-table/docs-builder/create-css-custom-props-doc.mjs +157 -0
- package/src/web-components/TODO json-table/docs-builder/src/custom-props-end.md +6 -0
- package/src/web-components/TODO json-table/docs-builder/src/custom-props-start.md +29 -0
- package/src/web-components/TODO json-table/src/TODO.md +1 -0
- package/src/web-components/TODO json-table/src/__json-table-react/build-page-array.js +73 -0
- package/src/web-components/TODO json-table/src/__json-table-react/columns-data-types.js +73 -0
- package/src/web-components/TODO json-table/src/__json-table-react/defaults.js +50 -0
- package/src/web-components/TODO json-table/src/__json-table-react/download-excel.js +156 -0
- package/src/web-components/TODO json-table/src/__json-table-react/set-className.js +19 -0
- package/src/web-components/TODO json-table/src/__json-table-react/set-download-filename.js +17 -0
- package/src/web-components/TODO json-table/src/__json-table-react/table-to-csv.js +48 -0
- package/src/web-components/TODO json-table/src/css/custom-media.css +16 -0
- package/src/web-components/TODO json-table/src/css/icons.module.css +22 -0
- package/src/web-components/TODO json-table/src/css/info-section.module.css +78 -0
- package/src/web-components/TODO json-table/src/css/main-builder.module.css +6 -0
- package/src/web-components/TODO json-table/src/css/table.module.css +172 -0
- package/src/web-components/TODO json-table/src/css/utility.module.css +9 -0
- package/src/web-components/TODO json-table/src/icons/arrow-down-bold.svg +1 -0
- package/src/web-components/TODO json-table/src/icons/false.svg +1 -0
- package/src/web-components/TODO json-table/src/icons/true.svg +1 -0
- package/src/web-components/TODO json-table/src/index.js +125 -0
- package/src/web-components/TODO json-table/src/js/default-columns-data-types.js +172 -0
- package/src/web-components/TODO json-table/src/js/defaults.js +510 -0
- package/src/web-components/TODO json-table/src/js/get-ajax-data.js +72 -0
- package/src/web-components/TODO json-table/src/js/info-section.js +39 -0
- package/src/web-components/TODO json-table/src/js/init-ajax-table.js +30 -0
- package/src/web-components/TODO json-table/src/js/init-static-table.js +18 -0
- package/src/web-components/TODO json-table/src/js/main-builder.js +87 -0
- package/src/web-components/TODO json-table/src/js/parse-data-row.js +123 -0
- package/src/web-components/TODO json-table/src/js/parse-params.js +118 -0
- package/src/web-components/TODO json-table/src/js/set-search-listener.js +62 -0
- package/src/web-components/TODO json-table/src/js/set-sort-listeners.js +115 -0
- package/src/web-components/TODO json-table/src/js/static-data-sorting.js +23 -0
- package/src/web-components/TODO json-table/src/js/table-builder.js +45 -0
- package/src/web-components/TODO json-table/src/js/table-row.js +43 -0
- package/src/web-components/TODO json-table/src/js/table-tfoot.js +9 -0
- package/src/web-components/TODO json-table/src/js/table-thead.js +91 -0
- package/src/web-components/TODO json-table/src/js/update-info.js +42 -0
- package/src/web-components/TODO json-table/src/js/utilities.js +5 -0
- package/src/web-components/s-datatable-component/s-datatable-component.js +2 -1
- package/src/web-components/s-datatable-component/src/parse-cols.js +2 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
|
|
2
|
+
import { defaults_params, columns_default } from './defaults';
|
|
3
|
+
import { defaultDataTypes } from './default-columns-data-types';
|
|
4
|
+
|
|
5
|
+
export function parseParams({custom_params = {}, custom_data_types = {}}) {
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const params = {
|
|
11
|
+
...defaults_params,
|
|
12
|
+
...(JSON.parse(custom_params?.container?.dataset?.params?? null)?? {}), // params from `data-params` attribute
|
|
13
|
+
...custom_params
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if(!params.container) {
|
|
17
|
+
throw '`container` parameter not present';
|
|
18
|
+
}
|
|
19
|
+
if(typeof params.container === 'string') {
|
|
20
|
+
throw '`container` parameter must be a dom element';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ENHANCEMENT jqDatatableCompliant
|
|
24
|
+
// temporarily force `jqDatatableCompliant` to true
|
|
25
|
+
params.jqDatatableCompliant = true;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// ENHANCEMENT download btn
|
|
30
|
+
// if(params.ajax === true) {
|
|
31
|
+
// params.showDownloadBtn = false;
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// =>> DATA TYPES
|
|
36
|
+
// parse default datatypes
|
|
37
|
+
params.dataTypes = defaultDataTypes(params);
|
|
38
|
+
|
|
39
|
+
// if custom_data_types are provided, they are merged with the one defined in the `inheritsFrom` key
|
|
40
|
+
if(Object.keys(custom_data_types).length) {
|
|
41
|
+
|
|
42
|
+
for(const key in custom_data_types) {
|
|
43
|
+
if(custom_data_types[key].inheritsFrom) {
|
|
44
|
+
custom_data_types[key] = {
|
|
45
|
+
...params.dataTypes[custom_data_types[key].inheritsFrom],
|
|
46
|
+
...custom_data_types[key]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// merge custom data types with the default ones
|
|
51
|
+
params.dataTypes = {...params.dataTypes, ...custom_data_types};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// check if the dataTypes are valid
|
|
56
|
+
const dataTypesList = Object.keys(params.dataTypes);
|
|
57
|
+
params.columns.forEach(col => {
|
|
58
|
+
if(col.dataType && !dataTypesList.includes(col.dataType)) {
|
|
59
|
+
throw `JsonTable: Invalid data type for column with key '${col.key}' (${col.dataType})`;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// =>> COLUMNS
|
|
65
|
+
|
|
66
|
+
// build columns definition array
|
|
67
|
+
params.columns = params.columns.map(col => {
|
|
68
|
+
|
|
69
|
+
const inheritedDatatype = params.dataTypes[col.dataType]?.inheritsFrom?? null;
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
// default values
|
|
73
|
+
...columns_default,
|
|
74
|
+
|
|
75
|
+
// override values for columns with specific dataTypes (from the `colDefaultsOverrides` object in dataTypes)`)
|
|
76
|
+
...(params.dataTypes[col.dataType]?.colDefaultsOverrides?? {}),
|
|
77
|
+
|
|
78
|
+
// same, from the inherited dataType, if exists
|
|
79
|
+
...(inheritedDatatype? params.dataTypes[inheritedDatatype].colDefaultsOverrides?? {} : {}),
|
|
80
|
+
|
|
81
|
+
// user settings
|
|
82
|
+
...col
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// columns key list and check for missing ones
|
|
88
|
+
params.fieldKeysList = params.columns.reduce((acc, col, idx) => {
|
|
89
|
+
if(!col.key) {
|
|
90
|
+
throw `JsonTable: Missing key for column #${idx}`;
|
|
91
|
+
}
|
|
92
|
+
acc.push(col.key);
|
|
93
|
+
return acc;
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
// default sorting check
|
|
97
|
+
params.defaultSorting??= {}; // force null to empty object
|
|
98
|
+
|
|
99
|
+
Object.keys(params.defaultSorting).forEach(sort_key => {
|
|
100
|
+
|
|
101
|
+
if(!params.fieldKeysList.includes(sort_key)) {
|
|
102
|
+
throw `JsonTable: Invalid sort key '${sort_key}'`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// force sorting direction to lowercase
|
|
106
|
+
params.defaultSorting[sort_key] = params.defaultSorting[sort_key].toLowerCase();
|
|
107
|
+
if(['asc', 'desc'].indexOf(params.defaultSorting[sort_key]) === -1) {
|
|
108
|
+
throw `JsonTable: Invalid sorting direction for column with key '${sort_key}' `+
|
|
109
|
+
`(${params.defaultSorting[sort_key]} instead of 'sort' or 'desc')`;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return params;
|
|
114
|
+
|
|
115
|
+
} catch(e) {
|
|
116
|
+
return {err: e};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// returns the string of classes for the given column
|
|
2
|
+
// according to the column definition and to the data_types object
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function setColumClassname(col, addClassAttrName = true) {
|
|
6
|
+
let classname ='';
|
|
7
|
+
|
|
8
|
+
if(col.className) {
|
|
9
|
+
classname = col.className;
|
|
10
|
+
|
|
11
|
+
} else if(col.dataType) {
|
|
12
|
+
classname = this.params.dataTypes[col.dataType]?.className?? '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
classname = classname.trim();
|
|
16
|
+
|
|
17
|
+
if(addClassAttrName) {
|
|
18
|
+
return classname? ` class="${classname}"` : '';
|
|
19
|
+
} else {
|
|
20
|
+
return classname? classname : null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import { isFunction } from './utilities';
|
|
3
|
+
|
|
4
|
+
import * as styles from '../css/table.module.css';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function tableBuilder() {
|
|
8
|
+
|
|
9
|
+
this.params.tableId ??= nanoid();
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
|
|
13
|
+
const table = document.createElement('table');
|
|
14
|
+
table.className = this.params.tableAltClassName??
|
|
15
|
+
styles.table + (this.params.tableExtraClassName? ` ${this.params.tableExtraClassName}` : '');
|
|
16
|
+
table.id = this.params.tableId;
|
|
17
|
+
|
|
18
|
+
if(this.params.caption) {
|
|
19
|
+
table.insertAdjacentHTML('beforeend', `<caption>${this.params.caption}</caption>`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// headings
|
|
23
|
+
table.insertAdjacentElement('beforeend', this.tableHead());
|
|
24
|
+
|
|
25
|
+
// rows
|
|
26
|
+
const data = this.params.data; // TODO dati da ajax
|
|
27
|
+
|
|
28
|
+
const tbody = document.createElement('tbody');
|
|
29
|
+
table.appendChild(tbody);
|
|
30
|
+
|
|
31
|
+
data.forEach((row_data, idx) => {
|
|
32
|
+
tbody.insertAdjacentElement('beforeend', this.tableRow(row_data, idx));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// TODO tfoot ajax ???
|
|
36
|
+
// tfoot
|
|
37
|
+
if(this.params.footerData) {
|
|
38
|
+
table.insertAdjacentElement('beforeend', this.tableFoot());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// TODO table sort (vedi custom sort function in defaults.js)
|
|
43
|
+
|
|
44
|
+
// tr callback
|
|
45
|
+
if(isFunction(this.params.trCallback) ) {
|
|
46
|
+
table.querySelectorAll('tbody tr').forEach((row, idx) => this.params.trCallback(row, data[idx], this.params));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// responsive wrapper
|
|
50
|
+
if(this.params.addTableWrapper) {
|
|
51
|
+
const wrapper = document.createElement('div');
|
|
52
|
+
wrapper.className = this.params.tableWrapperClassName?? styles.tableWrapper;
|
|
53
|
+
wrapper.appendChild(table);
|
|
54
|
+
return wrapper;
|
|
55
|
+
|
|
56
|
+
} else {
|
|
57
|
+
table.classList.add(styles.stickyHeaders);
|
|
58
|
+
return table;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} catch(e) { //throw error
|
|
62
|
+
console.error( e ); // eslint-disable-line
|
|
63
|
+
} // finally {}
|
|
64
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { titleCase } from './utilities';
|
|
2
|
+
import searchArrow from '../icons/search-arrows.svg?inline';
|
|
3
|
+
import * as styles from '../css/table.module.css';
|
|
4
|
+
|
|
5
|
+
export function tableHead() {
|
|
6
|
+
|
|
7
|
+
const thead = document.createElement('thead'),
|
|
8
|
+
tr = document.createElement('tr');
|
|
9
|
+
|
|
10
|
+
this.params.columns.forEach(col => {
|
|
11
|
+
|
|
12
|
+
const th = document.createElement('th'),
|
|
13
|
+
sorting_available = this.params.sort && col.sortable,
|
|
14
|
+
sorting_activated = sorting_available && this.params.defaultSorting[col.key],
|
|
15
|
+
sorting_direction = sorting_activated && (this.params.defaultSorting[col.key]?? null),
|
|
16
|
+
|
|
17
|
+
className = [
|
|
18
|
+
this.setColumClassname(col, false),
|
|
19
|
+
...(sorting_available? [styles.sort] : []),
|
|
20
|
+
...(sorting_activated? [styles.sortingOn] : []),
|
|
21
|
+
...(sorting_direction? [ styles[`sorting${titleCase(sorting_direction)}`] ] : []),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
th.setAttribute('scope', 'col');
|
|
26
|
+
th.className = className.join(' ');
|
|
27
|
+
|
|
28
|
+
// TODO defaul desc sorting non si vede (freccia non colorata)
|
|
29
|
+
th.innerHTML = sorting_available?
|
|
30
|
+
'<div>' +
|
|
31
|
+
`<span>${col.title}</span>` +
|
|
32
|
+
`<span class="${styles.sortArrows}">` +
|
|
33
|
+
`<span class="${styles.sortArrowUp}">${searchArrow}</span>` +
|
|
34
|
+
`<span class="${styles.sortArrowDn}">${searchArrow}</span>` +
|
|
35
|
+
'</span>' +
|
|
36
|
+
'</div>'
|
|
37
|
+
: col.title;
|
|
38
|
+
|
|
39
|
+
tr.appendChild(th);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// TODO sort listener
|
|
44
|
+
|
|
45
|
+
thead.appendChild(tr);
|
|
46
|
+
return thead;
|
|
47
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { isFunction } from './utilities';
|
|
2
|
+
import * as iconStyles from '../css/icons.module.css';
|
|
3
|
+
|
|
4
|
+
export function tableRow(row, idx, target = 'null') {
|
|
5
|
+
|
|
6
|
+
const tr = document.createElement('tr');
|
|
7
|
+
if (this.params.addRowIndex && idx) {
|
|
8
|
+
tr.dataset.id = idx;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
this.params.columns.forEach((col, i) => {
|
|
12
|
+
let raw_content, content;
|
|
13
|
+
|
|
14
|
+
const datatypeObj = this.params.dataTypes[col.dataType]?? {};
|
|
15
|
+
|
|
16
|
+
if(col.parse && isFunction(col.parse)) {
|
|
17
|
+
raw_content = col.parse(row);
|
|
18
|
+
} else {
|
|
19
|
+
raw_content = row[col.key];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// if target is 'tfoot', columns with `tfoot: false` in their column definitions are not rendered
|
|
23
|
+
if(target === 'tfoot' && !col.tfoot) {
|
|
24
|
+
content = '';
|
|
25
|
+
|
|
26
|
+
} else if(raw_content === 0 && this.params.useZeroAltChar) {
|
|
27
|
+
content = this.params.zeroAltChar;
|
|
28
|
+
|
|
29
|
+
// All `render` functions are invoked with the `raw_content` value and the global params object as arguments
|
|
30
|
+
} else if(col.render && isFunction(col.render)) {
|
|
31
|
+
content = col.render(raw_content, this.params);
|
|
32
|
+
|
|
33
|
+
} else if(col.dataType && isFunction(datatypeObj?.render)) {
|
|
34
|
+
content = datatypeObj.render(raw_content, this.params);
|
|
35
|
+
|
|
36
|
+
} else if(raw_content == null) {
|
|
37
|
+
content = '';
|
|
38
|
+
|
|
39
|
+
} else {
|
|
40
|
+
content = raw_content;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isTh = col.rowHeading && i === 0,
|
|
44
|
+
CellTag = isTh? 'th' : 'td'
|
|
45
|
+
;
|
|
46
|
+
let classnames = this.setColumClassname(col, false);
|
|
47
|
+
classnames = classnames? [classnames] : [];
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// adding different classes for true and false boolean icons
|
|
51
|
+
// NB: main icon class is added in setColumClassname() and is defined in the `default-columns-data-types.js` script
|
|
52
|
+
if(col.dataType === 'bool') {
|
|
53
|
+
|
|
54
|
+
if(this.params.boolValuesClassName !== null) { // custom class for icons
|
|
55
|
+
classnames = [
|
|
56
|
+
...classnames,
|
|
57
|
+
...(this.params.boolTrueClassName && raw_content === true? [this.params.boolTrueClassName] : []),
|
|
58
|
+
...(this.params.boolFalseClassName && raw_content === false? [this.params.boolFalseClassName] : []),
|
|
59
|
+
];
|
|
60
|
+
} else {
|
|
61
|
+
classnames.push(raw_content === true? iconStyles.true : (raw_content === false? iconStyles.false : ''));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
tr.insertAdjacentHTML('beforeend',
|
|
66
|
+
`<${CellTag}` +
|
|
67
|
+
(isTh? ' scope="row"' : '') +
|
|
68
|
+
(classnames.length? ` class="${classnames.join(' ')}"` : '') +
|
|
69
|
+
|
|
70
|
+
// dataset values: // TODO necessari? possibile accedere ai dati in altro modo?
|
|
71
|
+
// TODO sort e search solo se abilitati
|
|
72
|
+
// TODO custom sort e search data su col, deve prevalere sulle funzioni di default
|
|
73
|
+
` data-key="${col.key}"` +
|
|
74
|
+
` data-search="${datatypeObj.searchValue? datatypeObj.searchValue(raw_content, this.params) : raw_content}"` +
|
|
75
|
+
` data-sort="${datatypeObj.sortValue? datatypeObj.sortValue(raw_content, this.params) : raw_content}"` +
|
|
76
|
+
` data-type="${col.dataType}"` +
|
|
77
|
+
`>${content}</${CellTag}>`
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return tr;
|
|
82
|
+
|
|
83
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function calcTotPages(records, pageRows) {
|
|
2
|
+
return Math.ceil(records / pageRows);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export default function (currentPage, pageRows, records, showed_pages = 11) {
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const pages = calcTotPages(records, pageRows);
|
|
9
|
+
|
|
10
|
+
let pages_array = [];
|
|
11
|
+
|
|
12
|
+
if (pages <= showed_pages) {
|
|
13
|
+
pages_array = [...Array(pages).fill().map((_, idx) => idx + 1)];
|
|
14
|
+
|
|
15
|
+
} else {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
let side_pages = 2, // pagine a dx/sx della pagina corrente
|
|
19
|
+
|
|
20
|
+
step_min = Math.max(1, currentPage - side_pages),
|
|
21
|
+
step_max = Math.min(pages, currentPage + side_pages),
|
|
22
|
+
|
|
23
|
+
// spazi aggiuntibi a dx/sx da lasciare liberi per '1', '...', <pages>
|
|
24
|
+
slots_left = step_min > 2? 2 : step_min - 1,
|
|
25
|
+
slots_right = step_max < pages - 1? 2 : pages - step_max;
|
|
26
|
+
|
|
27
|
+
// console.log(step_min, step_max, slots_left, slots_right);
|
|
28
|
+
// console.log(step_max - step_min + 1 + slots_left + slots_right);
|
|
29
|
+
|
|
30
|
+
// fix per avere sempre il numero prefissato di pagine
|
|
31
|
+
while (step_max - step_min + 1 + slots_left + slots_right < showed_pages) {
|
|
32
|
+
step_min = Math.max(1, step_min - 1);
|
|
33
|
+
step_max = Math.min(pages, step_max + 1);
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// console.log(step_max - step_min + 1 + slots_left + slots_right);
|
|
38
|
+
|
|
39
|
+
// if(step_max - step_min + 1 + slots_left + slots_right > showed_pages) {
|
|
40
|
+
// step_min++;
|
|
41
|
+
// }
|
|
42
|
+
|
|
43
|
+
pages_array = [
|
|
44
|
+
...Array(step_max - step_min + 1)
|
|
45
|
+
.fill()
|
|
46
|
+
.map((_, idx) => step_min + idx)
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
// console.log(pages_array.slice(0));
|
|
50
|
+
|
|
51
|
+
if(pages_array[0] === 2) {
|
|
52
|
+
pages_array.unshift(1);
|
|
53
|
+
|
|
54
|
+
} else if (pages_array[0] === 3) {
|
|
55
|
+
pages_array.unshift(1, 2);
|
|
56
|
+
|
|
57
|
+
} else if (pages_array[0] > 3) {
|
|
58
|
+
pages_array.unshift(1, null);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if(pages_array.at(-1) === pages - 1) {
|
|
62
|
+
pages_array.push(pages);
|
|
63
|
+
|
|
64
|
+
} else if(pages_array.at(-1) === pages - 2) {
|
|
65
|
+
pages_array.push(pages -1, pages);
|
|
66
|
+
|
|
67
|
+
} else if(pages_array.at(-1) < pages - 2) {
|
|
68
|
+
pages_array.push(null, pages);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return pages_array;
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// formattazioni std per i vari tipi di dati
|
|
2
|
+
// la classe std viene sovrascritta se presente come parametro nella colonna
|
|
3
|
+
import {defaults} from './defaults';
|
|
4
|
+
|
|
5
|
+
export const data_types = {
|
|
6
|
+
// string: {} // default type
|
|
7
|
+
date: {
|
|
8
|
+
className: defaults.rightAlignClassName,
|
|
9
|
+
render: d => (new Date(d)).toLocaleString('it-IT', {
|
|
10
|
+
year : 'numeric', // '2-digit'
|
|
11
|
+
month : '2-digit', // 'short'
|
|
12
|
+
day : '2-digit' // 'numeric
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
// symfony date field
|
|
16
|
+
sfDate: {
|
|
17
|
+
className: defaults.rightAlignClassName,
|
|
18
|
+
render: d => (new Date(d.date)).toLocaleString('it-IT', {
|
|
19
|
+
year : 'numeric', // '2-digit'
|
|
20
|
+
month : '2-digit', // 'short'
|
|
21
|
+
day : '2-digit' // 'numeric
|
|
22
|
+
})
|
|
23
|
+
},
|
|
24
|
+
datetime: {
|
|
25
|
+
className: defaults.rightAlignClassName,
|
|
26
|
+
render: d => {
|
|
27
|
+
const date = new Date(d);
|
|
28
|
+
return date.toLocaleString('it-IT', {
|
|
29
|
+
year : 'numeric', // '2-digit'
|
|
30
|
+
month : '2-digit', // 'short'
|
|
31
|
+
day : '2-digit', // 'numeric
|
|
32
|
+
}) +
|
|
33
|
+
'\u00A0' +
|
|
34
|
+
'<small>' +
|
|
35
|
+
date.toLocaleString('it-IT', {
|
|
36
|
+
hour12: false,
|
|
37
|
+
hour:'2-digit',
|
|
38
|
+
minute:'2-digit'
|
|
39
|
+
}) +
|
|
40
|
+
'</small>';
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
num: {
|
|
44
|
+
className: defaults.rightAlignClassName,
|
|
45
|
+
render: d => (d? +d : 0).toLocaleString('it-IT', {
|
|
46
|
+
maximumFractionDigits : 2
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
perc: {
|
|
50
|
+
className: defaults.rightAlignClassName,
|
|
51
|
+
formatClassName : defaults.percClassName,
|
|
52
|
+
render: d => (d? +d : 0).toLocaleString('it-IT', {
|
|
53
|
+
maximumFractionDigits : 2,
|
|
54
|
+
minimumFractionDigits : 2,
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
percDecimal: {
|
|
58
|
+
className: defaults.rightAlignClassName,
|
|
59
|
+
formatClassName : defaults.percClassName,
|
|
60
|
+
render: d => ((d? +d : 0) * 100).toLocaleString('it-IT', {
|
|
61
|
+
maximumFractionDigits : 2,
|
|
62
|
+
minimumFractionDigits : 2,
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
euro: {
|
|
66
|
+
className: defaults.rightAlignClassName,
|
|
67
|
+
formatClassName : defaults.euroClassName,
|
|
68
|
+
render: d => (d? +d : 0).toLocaleString('it-IT', {
|
|
69
|
+
minimumFractionDigits : 2,
|
|
70
|
+
maximumFractionDigits : 2
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parametri di configurazione
|
|
3
|
+
* @property {array} columns - colonne della tabella
|
|
4
|
+
* @property {array} data - array dei dati
|
|
5
|
+
* @property {array} footerData - array dei dati da renderizzare nell'elemento <tfoot>
|
|
6
|
+
* @author Massimo Cassandro
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export const defaults = {
|
|
11
|
+
columns : [], // definizione delle colonne
|
|
12
|
+
ajax : true, // se true usa `ajaxUrl` e ignora `data`
|
|
13
|
+
ajaxUrl : null, // url ajax
|
|
14
|
+
data : [], // dati (per versione statica)
|
|
15
|
+
footerData : [],
|
|
16
|
+
caption : null,
|
|
17
|
+
addRowIndex : false, // se true aggiunge un attributo data al tr con l'indice del record json
|
|
18
|
+
|
|
19
|
+
tableClassName : 'table',
|
|
20
|
+
wrapperClassName : 'table-responsive',
|
|
21
|
+
centerAlignClassName : 'text-center',
|
|
22
|
+
rightAlignClassName : 'text-right',
|
|
23
|
+
percClassName : 'perc',
|
|
24
|
+
euroClassName : 'euro',
|
|
25
|
+
showZero : false,
|
|
26
|
+
zeroValuesChar : '\u2014',
|
|
27
|
+
showDownloadBtn : false,
|
|
28
|
+
downloadBtnLabel : 'Download',
|
|
29
|
+
downloadBtnClassName : 'btn btn-outline-secondary btn-sm',
|
|
30
|
+
separateDownloadBtn : false, // se true viene restituito un array con tabella e pulsante download separati
|
|
31
|
+
downloadFilename : 'download',
|
|
32
|
+
downloadFormat : 'excel', // 'excel' o 'csv'
|
|
33
|
+
trCallback : null,
|
|
34
|
+
|
|
35
|
+
// array di eventuali fogli da aggiungere all'excel nel download
|
|
36
|
+
// ogni elemento dell'array è un oggetto con
|
|
37
|
+
// name - nome dela foglio
|
|
38
|
+
// data - array già formattato da trasformare in excel
|
|
39
|
+
extraDownloadSheets : null
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const columns_default = {
|
|
43
|
+
title : null, // titolo colonna (testo th)
|
|
44
|
+
key : null, // chiave oggetto del json
|
|
45
|
+
dataType : null, // tipo dati
|
|
46
|
+
className : null, // classe
|
|
47
|
+
render : null, // funzione ad hoc per il rendering
|
|
48
|
+
parse : null, // funzione ad hoc per elaborare il valore
|
|
49
|
+
rowHeading : false // se true, viene creato un elemento th[scope=row] invece di un td
|
|
50
|
+
};
|