@bennerinformatics/ember-fw-table 2.0.19 → 2.0.21
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/addon/classes/Row.js +74 -74
- package/addon/classes/Table.js +147 -147
- package/addon/components/fw-cell-action.js +15 -15
- package/addon/components/fw-cell-boolean.js +12 -12
- package/addon/components/fw-cell-nullable.js +12 -12
- package/addon/components/fw-cell-permission-icon.js +12 -12
- package/addon/components/fw-column-title.js +13 -13
- package/addon/components/fw-delete-modal.js +61 -61
- package/addon/components/fw-pagination-wrapper.js +681 -681
- package/addon/components/fw-row-toggle-index.js +14 -14
- package/addon/components/fw-table-expanded-row.js +24 -24
- package/addon/components/fw-table-resort.js +3 -3
- package/addon/components/fw-table-sortable.js +398 -389
- package/addon/documentation.js +98 -98
- package/addon/templates/components/fw-delete-modal.hbs +2 -7
- package/addon/templates/components/fw-pagination-wrapper.hbs +45 -74
- package/addon/templates/components/fw-table-expanded-row.hbs +23 -23
- package/addon/templates/components/fw-table-expanded-rows.hbs +1 -1
- package/addon/templates/components/fw-table-resort.hbs +4 -4
- package/addon/templates/components/fw-table-sortable.hbs +9 -31
- package/addon/utils/base-cells.js +40 -40
- package/addon/utils/export.js +76 -76
- package/addon/utils/formats.js +46 -46
- package/addon/utils/table.js +35 -35
- package/app/breakpoints.js +1 -1
- package/app/components/fw-cell-permission-icon.js +1 -1
- package/app/initializers/responsive.js +1 -1
- package/bitbucket-helpers-override.js +240 -240
- package/codemods.log +16 -0
- package/index.js +9 -10
- package/package.json +67 -67
- package/yuidoc.json +21 -21
package/addon/utils/export.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import EmberObject from '@ember/object';
|
|
2
|
-
import {isEmpty, isNone} from '@ember/utils';
|
|
3
|
-
import Papa from 'papaparse';
|
|
4
|
-
/**
|
|
5
|
-
* Used internally only. DESCRIPTION NEEDED
|
|
6
|
-
* @class Export
|
|
7
|
-
* @module Utils
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Creates a CSV file from a data array and a title
|
|
11
|
-
* @param {Array} data Array of table cells
|
|
12
|
-
* @param {Title} [name=null] Name to export
|
|
13
|
-
*/
|
|
14
|
-
export function createCSV(data, name = null) {
|
|
15
|
-
// first step, we need to extra the cells into "Cell","Cell 2" format, use JSON.stringify as it makes most escapes
|
|
16
|
-
// regex removes the brackets, as its an array we are calling stringify on
|
|
17
|
-
let rows = Papa.unparse(data);
|
|
18
|
-
|
|
19
|
-
// next, join that using newlines and export as data CSV
|
|
20
|
-
let encodedUri = `data:text/csv;charset=utf-8,${encodeURIComponent(rows)}`;
|
|
21
|
-
|
|
22
|
-
// downloading is a bit weird. We create a link element with the name and URL then click the element
|
|
23
|
-
let link = document.createElement('a');
|
|
24
|
-
link.setAttribute('href', encodedUri);
|
|
25
|
-
link.setAttribute('download', `${name || 'Export'}.csv`);
|
|
26
|
-
document.body.appendChild(link); // Required for FF
|
|
27
|
-
link.click(); // This will download the data file
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Exports an Ember Light Table to CSV
|
|
32
|
-
* @param {Table} table Table class, just needs to include rows and columns
|
|
33
|
-
* @param {String} [title='Export'] Title to use for exporting
|
|
34
|
-
*/
|
|
35
|
-
export default function exportTable(table, title = 'Export') {
|
|
36
|
-
// start by filtering out columns which opted out of exporting. Examples include action buttons and the row toggle
|
|
37
|
-
let columns = table.get('columns').filter(({canExport}) => {
|
|
38
|
-
// if canExport is defined, require it to be true
|
|
39
|
-
return isNone(canExport) || canExport;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// ensure we have columns and data
|
|
43
|
-
if (isEmpty(columns)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// start the data with just the labels from the columns
|
|
48
|
-
let data = [columns.map(({exportLabel, label}) => exportLabel || label)];
|
|
49
|
-
|
|
50
|
-
// next, populate data by iterating through the current rows
|
|
51
|
-
table.get('rows').forEach((row) => {
|
|
52
|
-
// in each row, iterate through the columns
|
|
53
|
-
let rowData = columns.map((column) => {
|
|
54
|
-
let {valuePath, format} = column;
|
|
55
|
-
// flat value pulled from the model
|
|
56
|
-
let rawValue = valuePath ? row.get(valuePath) : '';
|
|
57
|
-
let value = rawValue;
|
|
58
|
-
// if we have a format function and a value, run the function
|
|
59
|
-
if (format && typeof format === 'function') {
|
|
60
|
-
// so, typically there is a cell object which contains data as the functions "this"
|
|
61
|
-
// but we are in a action so simulate it by passing in the data we expect the function to have
|
|
62
|
-
// while we are here, might as well pass in an export parameter so they can modify behavior for export if desired
|
|
63
|
-
value = format.call(EmberObject.create({column, row, table, rawValue, export: true}), rawValue);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// return the value, though convert null/undefined into a string
|
|
67
|
-
return isNone(value) ? '' : value;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// add that data into the main array
|
|
71
|
-
data.pushObject(rowData);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// finally, pass our 2 dimensional array to the function to convert to a file download
|
|
75
|
-
createCSV(data, title);
|
|
76
|
-
}
|
|
1
|
+
import EmberObject from '@ember/object';
|
|
2
|
+
import {isEmpty, isNone} from '@ember/utils';
|
|
3
|
+
import Papa from 'papaparse';
|
|
4
|
+
/**
|
|
5
|
+
* Used internally only. DESCRIPTION NEEDED
|
|
6
|
+
* @class Export
|
|
7
|
+
* @module Utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Creates a CSV file from a data array and a title
|
|
11
|
+
* @param {Array} data Array of table cells
|
|
12
|
+
* @param {Title} [name=null] Name to export
|
|
13
|
+
*/
|
|
14
|
+
export function createCSV(data, name = null) {
|
|
15
|
+
// first step, we need to extra the cells into "Cell","Cell 2" format, use JSON.stringify as it makes most escapes
|
|
16
|
+
// regex removes the brackets, as its an array we are calling stringify on
|
|
17
|
+
let rows = Papa.unparse(data);
|
|
18
|
+
|
|
19
|
+
// next, join that using newlines and export as data CSV
|
|
20
|
+
let encodedUri = `data:text/csv;charset=utf-8,${encodeURIComponent(rows)}`;
|
|
21
|
+
|
|
22
|
+
// downloading is a bit weird. We create a link element with the name and URL then click the element
|
|
23
|
+
let link = document.createElement('a');
|
|
24
|
+
link.setAttribute('href', encodedUri);
|
|
25
|
+
link.setAttribute('download', `${name || 'Export'}.csv`);
|
|
26
|
+
document.body.appendChild(link); // Required for FF
|
|
27
|
+
link.click(); // This will download the data file
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Exports an Ember Light Table to CSV
|
|
32
|
+
* @param {Table} table Table class, just needs to include rows and columns
|
|
33
|
+
* @param {String} [title='Export'] Title to use for exporting
|
|
34
|
+
*/
|
|
35
|
+
export default function exportTable(table, title = 'Export') {
|
|
36
|
+
// start by filtering out columns which opted out of exporting. Examples include action buttons and the row toggle
|
|
37
|
+
let columns = table.get('columns').filter(({canExport}) => {
|
|
38
|
+
// if canExport is defined, require it to be true
|
|
39
|
+
return isNone(canExport) || canExport;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ensure we have columns and data
|
|
43
|
+
if (isEmpty(columns)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// start the data with just the labels from the columns
|
|
48
|
+
let data = [columns.map(({exportLabel, label}) => exportLabel || label)];
|
|
49
|
+
|
|
50
|
+
// next, populate data by iterating through the current rows
|
|
51
|
+
table.get('rows').forEach((row) => {
|
|
52
|
+
// in each row, iterate through the columns
|
|
53
|
+
let rowData = columns.map((column) => {
|
|
54
|
+
let {valuePath, format} = column;
|
|
55
|
+
// flat value pulled from the model
|
|
56
|
+
let rawValue = valuePath ? row.get(valuePath) : '';
|
|
57
|
+
let value = rawValue;
|
|
58
|
+
// if we have a format function and a value, run the function
|
|
59
|
+
if (format && typeof format === 'function') {
|
|
60
|
+
// so, typically there is a cell object which contains data as the functions "this"
|
|
61
|
+
// but we are in a action so simulate it by passing in the data we expect the function to have
|
|
62
|
+
// while we are here, might as well pass in an export parameter so they can modify behavior for export if desired
|
|
63
|
+
value = format.call(EmberObject.create({column, row, table, rawValue, export: true}), rawValue);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// return the value, though convert null/undefined into a string
|
|
67
|
+
return isNone(value) ? '' : value;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// add that data into the main array
|
|
71
|
+
data.pushObject(rowData);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// finally, pass our 2 dimensional array to the function to convert to a file download
|
|
75
|
+
createCSV(data, title);
|
|
76
|
+
}
|
package/addon/utils/formats.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/* global moment */
|
|
2
|
-
import {htmlSafe} from '@ember/string';
|
|
3
|
-
import {isNone} from '@ember/utils';
|
|
4
|
-
/**
|
|
5
|
-
* DESCRIPTION NEEDED
|
|
6
|
-
* @class Format
|
|
7
|
-
* @module Utils
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Format function which replaces the value with a basic Yes/No format for if its true or false
|
|
11
|
-
* @param {Any} value Value to test
|
|
12
|
-
* @return {String} "Yes" if the value is truthy, "No" otherwise
|
|
13
|
-
*/
|
|
14
|
-
export function formatBoolean(value) {
|
|
15
|
-
return value ? 'Yes' : 'No';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Generates a format function which returns the value or an italic default text
|
|
20
|
-
* @param {String} [nullText='None'] Text if the value is null
|
|
21
|
-
* @return {Function} Function to pass into the column format
|
|
22
|
-
*/
|
|
23
|
-
export function formatNullable(nullText = 'None') {
|
|
24
|
-
return function(value) {
|
|
25
|
-
if (isNone(value)) {
|
|
26
|
-
return this.get('export') ? '' : htmlSafe(`<i>${nullText}</i>`);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Generates a function which formats a moment based on the specified format
|
|
34
|
-
* @param {String} format moment format
|
|
35
|
-
* @param {String} exportFormat moment format used on exporting
|
|
36
|
-
* @return {Function} Function to pass into a column which formats by a moment
|
|
37
|
-
*/
|
|
38
|
-
export function formatMoment(format, exportFormat = null) {
|
|
39
|
-
return function(date) {
|
|
40
|
-
if (moment.isMoment(date)) {
|
|
41
|
-
// if we are exporting and have an export format, use that
|
|
42
|
-
let useFormat = exportFormat && this.get('export') ? exportFormat : format;
|
|
43
|
-
return date.format(useFormat);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
1
|
+
/* global moment */
|
|
2
|
+
import {htmlSafe} from '@ember/string';
|
|
3
|
+
import {isNone} from '@ember/utils';
|
|
4
|
+
/**
|
|
5
|
+
* DESCRIPTION NEEDED
|
|
6
|
+
* @class Format
|
|
7
|
+
* @module Utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Format function which replaces the value with a basic Yes/No format for if its true or false
|
|
11
|
+
* @param {Any} value Value to test
|
|
12
|
+
* @return {String} "Yes" if the value is truthy, "No" otherwise
|
|
13
|
+
*/
|
|
14
|
+
export function formatBoolean(value) {
|
|
15
|
+
return value ? 'Yes' : 'No';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates a format function which returns the value or an italic default text
|
|
20
|
+
* @param {String} [nullText='None'] Text if the value is null
|
|
21
|
+
* @return {Function} Function to pass into the column format
|
|
22
|
+
*/
|
|
23
|
+
export function formatNullable(nullText = 'None') {
|
|
24
|
+
return function(value) {
|
|
25
|
+
if (isNone(value)) {
|
|
26
|
+
return this.get('export') ? '' : htmlSafe(`<i>${nullText}</i>`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates a function which formats a moment based on the specified format
|
|
34
|
+
* @param {String} format moment format
|
|
35
|
+
* @param {String} exportFormat moment format used on exporting
|
|
36
|
+
* @return {Function} Function to pass into a column which formats by a moment
|
|
37
|
+
*/
|
|
38
|
+
export function formatMoment(format, exportFormat = null) {
|
|
39
|
+
return function(date) {
|
|
40
|
+
if (moment.isMoment(date)) {
|
|
41
|
+
// if we are exporting and have an export format, use that
|
|
42
|
+
let useFormat = exportFormat && this.get('export') ? exportFormat : format;
|
|
43
|
+
return date.format(useFormat);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
package/addon/utils/table.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {isEmpty} from '@ember/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Used internal only DESCRIPTION NEEDED
|
|
4
|
-
* @class TableUtil
|
|
5
|
-
* @module Utils
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Checks if a row should be show in expanded view given the context
|
|
9
|
-
* @param {Table} table Table class instance
|
|
10
|
-
* @param {Row} row Row class instance
|
|
11
|
-
* @param {Column} column Column class instance
|
|
12
|
-
* @return {boolean} True if it is shown in this context, false otherwise
|
|
13
|
-
*/
|
|
14
|
-
export function showExpanded(table, row, column) {
|
|
15
|
-
// if show expanded is defined, use that
|
|
16
|
-
let showExpanded = column.get('showExpanded');
|
|
17
|
-
let showExpandedType = typeof showExpanded;
|
|
18
|
-
// flat boolean? just return
|
|
19
|
-
if (showExpandedType === 'boolean') {
|
|
20
|
-
return showExpanded;
|
|
21
|
-
}
|
|
22
|
-
// key? fetch from the row
|
|
23
|
-
if (showExpandedType === 'string') {
|
|
24
|
-
return row.get(showExpanded);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// no value path? show it
|
|
28
|
-
let valuePath = column.get('valuePath');
|
|
29
|
-
if (isEmpty(valuePath)) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// hides undefined, null, and empty arrays, but not false and 0
|
|
34
|
-
return !isEmpty(row.get(valuePath));
|
|
35
|
-
}
|
|
1
|
+
import {isEmpty} from '@ember/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Used internal only DESCRIPTION NEEDED
|
|
4
|
+
* @class TableUtil
|
|
5
|
+
* @module Utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a row should be show in expanded view given the context
|
|
9
|
+
* @param {Table} table Table class instance
|
|
10
|
+
* @param {Row} row Row class instance
|
|
11
|
+
* @param {Column} column Column class instance
|
|
12
|
+
* @return {boolean} True if it is shown in this context, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export function showExpanded(table, row, column) {
|
|
15
|
+
// if show expanded is defined, use that
|
|
16
|
+
let showExpanded = column.get('showExpanded');
|
|
17
|
+
let showExpandedType = typeof showExpanded;
|
|
18
|
+
// flat boolean? just return
|
|
19
|
+
if (showExpandedType === 'boolean') {
|
|
20
|
+
return showExpanded;
|
|
21
|
+
}
|
|
22
|
+
// key? fetch from the row
|
|
23
|
+
if (showExpandedType === 'string') {
|
|
24
|
+
return row.get(showExpanded);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// no value path? show it
|
|
28
|
+
let valuePath = column.get('valuePath');
|
|
29
|
+
if (isEmpty(valuePath)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// hides undefined, null, and empty arrays, but not false and 0
|
|
34
|
+
return !isEmpty(row.get(valuePath));
|
|
35
|
+
}
|
package/app/breakpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {default} from '@bennerinformatics/ember-fw-table/breakpoints';
|
|
1
|
+
export {default} from '@bennerinformatics/ember-fw-table/breakpoints';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {default} from '@bennerinformatics/ember-fw-table/components/fw-cell-permission-icon';
|
|
1
|
+
export {default} from '@bennerinformatics/ember-fw-table/components/fw-cell-permission-icon';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {default} from '@bennerinformatics/ember-fw-table/initializers/responsive';
|
|
1
|
+
export {default} from '@bennerinformatics/ember-fw-table/initializers/responsive';
|