@qtoggle/qui 0.0.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/.eslintignore +2 -0
- package/.eslintrc.json +492 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- package/.github/ISSUE_TEMPLATE/improvement_proposal.md +20 -0
- package/.github/workflows/main.yml +74 -0
- package/.pre-commit-config.yaml +8 -0
- package/LICENSE.txt +177 -0
- package/README.md +4 -0
- package/font/dejavusans-bold.woff +0 -0
- package/font/dejavusans-bolditalic.woff +0 -0
- package/font/dejavusans-italic.woff +0 -0
- package/font/dejavusans-regular.woff +0 -0
- package/img/qui-icons.svg +1937 -0
- package/js/base/base.js +47 -0
- package/js/base/condition-variable.js +92 -0
- package/js/base/errors.js +36 -0
- package/js/base/i18n.js +20 -0
- package/js/base/mixwith.js +135 -0
- package/js/base/require-js-compat.js +78 -0
- package/js/base/signal.js +91 -0
- package/js/base/singleton.js +66 -0
- package/js/base/timer.js +126 -0
- package/js/config.js +184 -0
- package/js/forms/common-fields/check-field.js +42 -0
- package/js/forms/common-fields/choice-buttons-field.js +30 -0
- package/js/forms/common-fields/color-combo-field.js +37 -0
- package/js/forms/common-fields/combo-field.js +108 -0
- package/js/forms/common-fields/common-fields.js +23 -0
- package/js/forms/common-fields/composite-field.js +132 -0
- package/js/forms/common-fields/custom-html-field.js +51 -0
- package/js/forms/common-fields/email-field.js +30 -0
- package/js/forms/common-fields/file-picker-field.js +46 -0
- package/js/forms/common-fields/jquery-ui-field.js +111 -0
- package/js/forms/common-fields/labels-field.js +69 -0
- package/js/forms/common-fields/numeric-field.js +39 -0
- package/js/forms/common-fields/password-field.js +28 -0
- package/js/forms/common-fields/phone-field.js +26 -0
- package/js/forms/common-fields/progress-disk-field.js +69 -0
- package/js/forms/common-fields/push-button-field.js +138 -0
- package/js/forms/common-fields/slider-field.js +51 -0
- package/js/forms/common-fields/text-area-field.js +34 -0
- package/js/forms/common-fields/text-field.js +89 -0
- package/js/forms/common-fields/up-down-field.js +85 -0
- package/js/forms/common-forms/common-forms.js +16 -0
- package/js/forms/common-forms/options-form.js +77 -0
- package/js/forms/common-forms/page-form.js +115 -0
- package/js/forms/form-button.js +202 -0
- package/js/forms/form-field.js +1183 -0
- package/js/forms/form.js +1181 -0
- package/js/forms/forms.js +68 -0
- package/js/global-glass.js +100 -0
- package/js/icons/default-stock.js +173 -0
- package/js/icons/icon.js +64 -0
- package/js/icons/icons.js +16 -0
- package/js/icons/multi-state-sprites-icon.js +362 -0
- package/js/icons/stock-icon.js +219 -0
- package/js/icons/stock.js +98 -0
- package/js/icons/stocks.js +57 -0
- package/js/index.js +232 -0
- package/js/lib/jquery.longpress.js +79 -0
- package/js/lib/jquery.module.js +4 -0
- package/js/lib/logger.module.js +4 -0
- package/js/lib/pep.module.js +4 -0
- package/js/lists/common-items/common-items.js +5 -0
- package/js/lists/common-items/icon-label-list-item.js +86 -0
- package/js/lists/common-lists/common-lists.js +5 -0
- package/js/lists/common-lists/page-list.js +53 -0
- package/js/lists/list-item.js +147 -0
- package/js/lists/list.js +636 -0
- package/js/lists/lists.js +26 -0
- package/js/main-ui/main-ui.js +64 -0
- package/js/main-ui/menu-bar.js +144 -0
- package/js/main-ui/options-bar.js +181 -0
- package/js/main-ui/status.js +185 -0
- package/js/main-ui/top-bar.js +59 -0
- package/js/messages/common-message-forms/common-message-forms.js +7 -0
- package/js/messages/common-message-forms/confirm-message-form.js +81 -0
- package/js/messages/common-message-forms/simple-message-form.js +67 -0
- package/js/messages/common-message-forms/sticky-simple-message-form.js +27 -0
- package/js/messages/message-form.js +107 -0
- package/js/messages/messages.js +21 -0
- package/js/messages/sticky-modal-page.js +98 -0
- package/js/messages/sticky-modal-progress-message.js +27 -0
- package/js/messages/toast.js +164 -0
- package/js/navigation.js +654 -0
- package/js/pages/breadcrumbs.js +124 -0
- package/js/pages/common-pages/common-pages.js +6 -0
- package/js/pages/common-pages/modal-progress-page.js +83 -0
- package/js/pages/common-pages/structured-page.js +46 -0
- package/js/pages/page.js +1018 -0
- package/js/pages/pages-context.js +154 -0
- package/js/pages/pages.js +252 -0
- package/js/pwa.js +337 -0
- package/js/sections/section.js +612 -0
- package/js/sections/sections.js +300 -0
- package/js/tables/common-cells/common-cells.js +7 -0
- package/js/tables/common-cells/icon-label-table-cell.js +68 -0
- package/js/tables/common-cells/push-button-table-cell.js +133 -0
- package/js/tables/common-cells/simple-table-cell.js +37 -0
- package/js/tables/common-tables/common-tables.js +5 -0
- package/js/tables/common-tables/page-table.js +55 -0
- package/js/tables/table-cell.js +198 -0
- package/js/tables/table-row.js +126 -0
- package/js/tables/table.js +492 -0
- package/js/tables/tables.js +36 -0
- package/js/theme.js +304 -0
- package/js/utils/ajax.js +126 -0
- package/js/utils/array.js +194 -0
- package/js/utils/colors.js +445 -0
- package/js/utils/cookies.js +65 -0
- package/js/utils/crypto.js +439 -0
- package/js/utils/css.js +234 -0
- package/js/utils/date.js +300 -0
- package/js/utils/files.js +27 -0
- package/js/utils/gestures.js +165 -0
- package/js/utils/html.js +76 -0
- package/js/utils/misc.js +81 -0
- package/js/utils/object.js +324 -0
- package/js/utils/promise.js +49 -0
- package/js/utils/string.js +192 -0
- package/js/utils/url.js +187 -0
- package/js/utils/utils.js +3 -0
- package/js/utils/visibility-manager.js +211 -0
- package/js/views/common-views/common-views.js +7 -0
- package/js/views/common-views/icon-label-view.js +210 -0
- package/js/views/common-views/progress-view.js +89 -0
- package/js/views/common-views/structured-view.js +368 -0
- package/js/views/view.js +467 -0
- package/js/views/views.js +3 -0
- package/js/widgets/base-widget.js +23 -0
- package/js/widgets/common-widgets/check-button.js +109 -0
- package/js/widgets/common-widgets/choice-buttons.js +322 -0
- package/js/widgets/common-widgets/color-combo.js +104 -0
- package/js/widgets/common-widgets/combo.js +645 -0
- package/js/widgets/common-widgets/common-widgets.js +17 -0
- package/js/widgets/common-widgets/email-input.js +7 -0
- package/js/widgets/common-widgets/file-picker.js +133 -0
- package/js/widgets/common-widgets/labels.js +132 -0
- package/js/widgets/common-widgets/numeric-input.js +49 -0
- package/js/widgets/common-widgets/password-input.js +91 -0
- package/js/widgets/common-widgets/phone-input.js +7 -0
- package/js/widgets/common-widgets/progress-disk.js +174 -0
- package/js/widgets/common-widgets/push-button.js +155 -0
- package/js/widgets/common-widgets/slider.js +455 -0
- package/js/widgets/common-widgets/text-area.js +52 -0
- package/js/widgets/common-widgets/text-input.js +174 -0
- package/js/widgets/common-widgets/up-down.js +351 -0
- package/js/widgets/widgets.js +57 -0
- package/js/window.js +557 -0
- package/jsdoc.conf.json +20 -0
- package/less/base.less +123 -0
- package/less/forms/common-fields.less +101 -0
- package/less/forms/common-forms.less +5 -0
- package/less/forms/form-button.less +21 -0
- package/less/forms/form-field.less +266 -0
- package/less/forms/form.less +131 -0
- package/less/global-glass.less +64 -0
- package/less/icon-label-view.less +82 -0
- package/less/icons.less +144 -0
- package/less/lists.less +105 -0
- package/less/main-ui.less +328 -0
- package/less/messages.less +189 -0
- package/less/no-effects.less +24 -0
- package/less/pages/breadcrumbs.less +98 -0
- package/less/pages/common-pages.less +36 -0
- package/less/pages/page.less +70 -0
- package/less/progress-view.less +51 -0
- package/less/stock-icons.less +43 -0
- package/less/structured-view.less +245 -0
- package/less/tables.less +84 -0
- package/less/theme-dark.less +133 -0
- package/less/theme-light.less +132 -0
- package/less/theme.less +419 -0
- package/less/visibility-manager.less +11 -0
- package/less/widgets/check-button.less +96 -0
- package/less/widgets/choice-buttons.less +160 -0
- package/less/widgets/color-combo.less +33 -0
- package/less/widgets/combo.less +230 -0
- package/less/widgets/common-buttons.less +120 -0
- package/less/widgets/common.less +24 -0
- package/less/widgets/input.less +258 -0
- package/less/widgets/labels.less +81 -0
- package/less/widgets/progress-disk.less +70 -0
- package/less/widgets/slider.less +199 -0
- package/less/widgets/updown.less +115 -0
- package/less/widgets/various.less +36 -0
- package/package.json +47 -0
- package/pyproject.toml +45 -0
- package/qui/__init__.py +110 -0
- package/qui/constants.py +1 -0
- package/qui/exceptions.py +2 -0
- package/qui/j2template.py +71 -0
- package/qui/settings.py +60 -0
- package/qui/templates/manifest.json +25 -0
- package/qui/templates/qui.html +126 -0
- package/qui/templates/service-worker.js +188 -0
- package/qui/web/__init__.py +0 -0
- package/qui/web/tornado.py +220 -0
- package/scripts/postinstall.sh +10 -0
- package/webpack/webpack-adjust-css-urls-loader.js +36 -0
- package/webpack/webpack-common.js +384 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
|
|
2
|
+
import {AssertionError} from '$qui/base/errors.js'
|
|
3
|
+
import List from '$qui/lists/list.js'
|
|
4
|
+
import * as ObjectUtils from '$qui/utils/object.js'
|
|
5
|
+
|
|
6
|
+
import SimpleTableCell from './common-cells/simple-table-cell.js'
|
|
7
|
+
import TableRow from './table-row.js'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A table view.
|
|
12
|
+
* @alias qui.tables.Table
|
|
13
|
+
* @extends qui.lists.List
|
|
14
|
+
*/
|
|
15
|
+
class Table extends List {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @constructs
|
|
19
|
+
* @param {Array} [header] optional table header
|
|
20
|
+
* @param {qui.tables.TableRow} [headerRow] optional table header row
|
|
21
|
+
* ({@link qui.tables.commoncells.SimpleTableCell} cells will be used by default)
|
|
22
|
+
* @param {String[]} [widths] table column widths, in percents or absolute values with units
|
|
23
|
+
* @param {Boolean[]} [visibilities] table column visibilities
|
|
24
|
+
* @param {String[]} [horizontalAlign] default horizontal cell alignment for each column; a list containing one of:
|
|
25
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_LEFT}
|
|
26
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_CENTER} (default)
|
|
27
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_RIGHT}
|
|
28
|
+
* @param {String[]} [verticalAlign] default vertical cell alignment for each column; a list containing one of:
|
|
29
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_TOP}
|
|
30
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_CENTER} (default)
|
|
31
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_BOTTOM}
|
|
32
|
+
* @param {qui.tables.TableCell[]|Object[]} [rowTemplate] an optional row template to use when adding new rows with
|
|
33
|
+
* {@link qui.tables.Table#addRowValues}; if a list of objects is supplied, each object must contain a `class`
|
|
34
|
+
* property indicating the table cell class, while the rest of properties are used as constructor parameters
|
|
35
|
+
* @param {qui.tables.TableRow[]} [initialRows] initial table rows
|
|
36
|
+
* @param {Array[]} [initialValues] initial table values
|
|
37
|
+
* @param {...*} args parent class parameters
|
|
38
|
+
*/
|
|
39
|
+
constructor({
|
|
40
|
+
header = null,
|
|
41
|
+
headerRow = null,
|
|
42
|
+
widths = null,
|
|
43
|
+
visibilities = null,
|
|
44
|
+
horizontalAlign = null,
|
|
45
|
+
verticalAlign = null,
|
|
46
|
+
rowTemplate = null,
|
|
47
|
+
initialRows = null,
|
|
48
|
+
initialValues = null,
|
|
49
|
+
...args
|
|
50
|
+
} = {}) {
|
|
51
|
+
|
|
52
|
+
/* Ensure no items are passed via constructor; we have initialRows for that */
|
|
53
|
+
delete args.items
|
|
54
|
+
|
|
55
|
+
super(args)
|
|
56
|
+
|
|
57
|
+
this._header = header
|
|
58
|
+
this._headerRow = headerRow
|
|
59
|
+
this._widths = widths
|
|
60
|
+
this._visibilities = visibilities
|
|
61
|
+
this._horizontalAlign = horizontalAlign
|
|
62
|
+
this._verticalAlign = verticalAlign
|
|
63
|
+
this._rowTemplate = rowTemplate
|
|
64
|
+
this._initialRows = initialRows
|
|
65
|
+
this._initialValues = initialValues
|
|
66
|
+
|
|
67
|
+
this._numColumns = null
|
|
68
|
+
this._computedWidths = null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
initHTML(html) {
|
|
72
|
+
super.initHTML(html)
|
|
73
|
+
|
|
74
|
+
html.addClass('qui-table')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
init() {
|
|
78
|
+
super.init()
|
|
79
|
+
|
|
80
|
+
if (this._initialRows) {
|
|
81
|
+
this.setItems(this._initialRows)
|
|
82
|
+
delete this._initialRows /* Don't waste memory */
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this._header) {
|
|
86
|
+
this.prepareHeader()
|
|
87
|
+
this._addHeaderRow()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this._initialValues) {
|
|
91
|
+
this.setValues(this._initialValues)
|
|
92
|
+
delete this._initialValues /* Don't waste memory */
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/* Alignment */
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Return the default horizontal alignment for each column.
|
|
101
|
+
* @returns {String[]} a list containing one of:
|
|
102
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_LEFT}
|
|
103
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_CENTER}
|
|
104
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_RIGHT}
|
|
105
|
+
*/
|
|
106
|
+
getHorizontalAlign() {
|
|
107
|
+
return this._horizontalAlign
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Return the default vertical alignment for each column.
|
|
112
|
+
* @returns {String[]} a list containing one of:
|
|
113
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_TOP}
|
|
114
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_CENTER}
|
|
115
|
+
* * {@link qui.tables.TABLE_CELL_ALIGN_BOTTOM}
|
|
116
|
+
*/
|
|
117
|
+
getVerticalAlign() {
|
|
118
|
+
return this._verticalAlign
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/* Header */
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Return the table header row.
|
|
126
|
+
* @returns {?qui.tables.TableRow}
|
|
127
|
+
*/
|
|
128
|
+
getHeaderRow() {
|
|
129
|
+
return this._headerRow
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Set table header row. If `null` is passed, {@link qui.tables.commoncells.SimpleTableCell} are used to build a
|
|
134
|
+
* table row.
|
|
135
|
+
* @param {?qui.tables.TableRow} headerRow table header row
|
|
136
|
+
*/
|
|
137
|
+
setHeaderRow(headerRow) {
|
|
138
|
+
if (this._headerRow) {
|
|
139
|
+
this._removeHeaderRow()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this._headerRow = headerRow
|
|
143
|
+
if (this._header) {
|
|
144
|
+
this.prepareHeader()
|
|
145
|
+
this._addHeaderRow()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Return the table header.
|
|
151
|
+
* @returns {?Array}
|
|
152
|
+
*/
|
|
153
|
+
getHeader() {
|
|
154
|
+
return this._header
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Set or clear the table header.
|
|
159
|
+
* @param {?Array} header
|
|
160
|
+
*/
|
|
161
|
+
setHeader(header) {
|
|
162
|
+
if (this._headerRow) {
|
|
163
|
+
this._removeHeaderRow()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this._header = header
|
|
167
|
+
if (this._header) {
|
|
168
|
+
this.prepareHeader()
|
|
169
|
+
this._addHeaderRow()
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_addHeaderRow() {
|
|
174
|
+
if (this._searchElem) {
|
|
175
|
+
this._searchElem.after(this._headerRow.getHTML())
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.getBody().prepend(this._headerRow.getHTML())
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
_removeHeaderRow() {
|
|
183
|
+
this._headerRow.getHTML().remove()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
/* Rows */
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Update the row template to use when adding new rows with {@link qui.tables.Table#addRowValues}; if a list of
|
|
191
|
+
* objects is supplied, each object must contain a `class`.
|
|
192
|
+
*
|
|
193
|
+
* A call to this method won't affect the currently added rows.
|
|
194
|
+
*
|
|
195
|
+
* @param {qui.tables.TableCell[]|Object[]} rowTemplate
|
|
196
|
+
*/
|
|
197
|
+
setRowTemplate(rowTemplate) {
|
|
198
|
+
this._rowTemplate = rowTemplate
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Return all rows.
|
|
203
|
+
* @returns {qui.tables.TableRow[]}
|
|
204
|
+
*/
|
|
205
|
+
getRows() {
|
|
206
|
+
return /** @type {qui.tables.TableRow[]} */ this.getItems().filter(i => i instanceof TableRow)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Set the rows of the list.
|
|
211
|
+
* @param {qui.tables.TableRow[]} rows table rows
|
|
212
|
+
*/
|
|
213
|
+
setRows(rows) {
|
|
214
|
+
this.invalidateColumns()
|
|
215
|
+
this.setItems(rows)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Update one row.
|
|
220
|
+
* @param {Number} index the index where to perform the update
|
|
221
|
+
* @param {qui.tables.TableRow} row the row to update
|
|
222
|
+
*/
|
|
223
|
+
setRow(index, row) {
|
|
224
|
+
this.invalidateColumns()
|
|
225
|
+
this.setItem(index, row)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Add one row to the list.
|
|
230
|
+
* @param {Number} index the index where the row should be added; `-1` will add the row at the end
|
|
231
|
+
* @param {qui.tables.TableRow} row the row
|
|
232
|
+
*/
|
|
233
|
+
addRow(index, row) {
|
|
234
|
+
this.invalidateColumns()
|
|
235
|
+
this.addItem(index, row)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Add one row to the list using row template. Table must have a row template.
|
|
240
|
+
* @param {Number} index the index where the row should be added; `-1` will add the row at the end
|
|
241
|
+
* @param {Array} values values to set to new row
|
|
242
|
+
* @param {*} [data] optional data to pass to row
|
|
243
|
+
* @returns {qui.tables.TableRow} the added row
|
|
244
|
+
*/
|
|
245
|
+
addRowValues(index, values, data = null) {
|
|
246
|
+
if (!this._rowTemplate) {
|
|
247
|
+
throw new AssertionError('addRowValues() called on table without row template')
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let cells = this._rowTemplate.map(function (c) {
|
|
251
|
+
let CellClass
|
|
252
|
+
let params = {}
|
|
253
|
+
if (c.class) {
|
|
254
|
+
CellClass = ObjectUtils.pop(c, 'class')
|
|
255
|
+
Object.assign(params, c)
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
CellClass = c
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return new CellClass(params)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
let row = new TableRow({cells, initialValues: values, data})
|
|
265
|
+
|
|
266
|
+
this.addRow(index, row)
|
|
267
|
+
|
|
268
|
+
return row
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Remove the row at a given index.
|
|
273
|
+
* @param {Number} index the index of the row to remove
|
|
274
|
+
* @returns {?qui.tables.TableRow} the removed row
|
|
275
|
+
*/
|
|
276
|
+
removeRowAt(index) {
|
|
277
|
+
this.invalidateColumns()
|
|
278
|
+
return /** @type ?qui.tables.TableRow */ this.removeItemAt(index)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Remove a specific row.
|
|
283
|
+
* @param {qui.tables.TableRow} row the row to remove
|
|
284
|
+
* @returns {Boolean} `true` if row found and removed, `false` otherwise
|
|
285
|
+
*/
|
|
286
|
+
removeRow(row) {
|
|
287
|
+
this.invalidateColumns()
|
|
288
|
+
return this.removeItem(row)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Remove all rows that match a condition.
|
|
293
|
+
* @param {qui.tables.TableRowMatchFunc} matchFunc
|
|
294
|
+
* @returns {qui.tables.TableRow[]} the removed rows
|
|
295
|
+
*/
|
|
296
|
+
removeRows(matchFunc) {
|
|
297
|
+
this.invalidateColumns()
|
|
298
|
+
return /** @type qui.tables.TableRow[] */ this.removeItems(/** @type qui.lists.ListItemMatchFunc */ matchFunc)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
prepareItem(item) {
|
|
302
|
+
super.prepareItem(item)
|
|
303
|
+
|
|
304
|
+
/* Set column widths */
|
|
305
|
+
item.getHTML().css('grid-template-columns', this.getComputedWidths(item).join(' '))
|
|
306
|
+
|
|
307
|
+
if (this._visibilities) {
|
|
308
|
+
item.getCells().forEach(function (cell, i) {
|
|
309
|
+
if (!this._visibilities[i]) {
|
|
310
|
+
cell.hide()
|
|
311
|
+
}
|
|
312
|
+
}.bind(this))
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
prepareHeader() {
|
|
317
|
+
if (!this._headerRow) {
|
|
318
|
+
this._headerRow = new TableRow({cells: this._header.map(_ => new SimpleTableCell())})
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
this._headerRow.setList(this)
|
|
322
|
+
this._headerRow.getHTML().addClass('qui-table-header')
|
|
323
|
+
this._headerRow.setValues(this._header)
|
|
324
|
+
this._headerRow.getHTML().css('grid-template-columns', this.getComputedWidths(this._headerRow).join(' '))
|
|
325
|
+
|
|
326
|
+
if (this._visibilities) {
|
|
327
|
+
this._headerRow.getCells().forEach(function (cell, i) {
|
|
328
|
+
if (!this._visibilities[i]) {
|
|
329
|
+
cell.hide()
|
|
330
|
+
}
|
|
331
|
+
}.bind(this))
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
/* Selection */
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Return the currently selected rows.
|
|
340
|
+
* @returns {qui.tables.TableRow[]}
|
|
341
|
+
*/
|
|
342
|
+
getSelectedRows() {
|
|
343
|
+
return this.getRows().filter(r => r.isSelected())
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Update current selection.
|
|
348
|
+
* @param {qui.tables.TableRow[]} rows the list of new rows to select; empty list clears selection
|
|
349
|
+
*/
|
|
350
|
+
setSelectedRows(rows) {
|
|
351
|
+
this.setSelectedItems(rows)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
/* Columns */
|
|
356
|
+
|
|
357
|
+
invalidateColumns() {
|
|
358
|
+
this._numColumns = null
|
|
359
|
+
this._computedWidths = null
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Return the number of table columns.
|
|
364
|
+
* @param {qui.tables.TableRow} [row] an optional row about to be added
|
|
365
|
+
* @returns {Number}
|
|
366
|
+
*/
|
|
367
|
+
getNumColumns(row = null) {
|
|
368
|
+
if (this._numColumns == null) {
|
|
369
|
+
let rows = this.getRows()
|
|
370
|
+
if (row) {
|
|
371
|
+
rows.push(row)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
this._numColumns = Math.max(...rows.map(r => r.getCells().length))
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return this._numColumns
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Set column widths.
|
|
382
|
+
* @param {String[]} widths table column widths, in percents or absolute values with units
|
|
383
|
+
*/
|
|
384
|
+
setWidths(widths) {
|
|
385
|
+
this._widths = widths
|
|
386
|
+
this._computedWidths = null
|
|
387
|
+
|
|
388
|
+
this.getRows().forEach(r => r.getHTML().css('grid-template-columns', this.getComputedWidths().join(' ')))
|
|
389
|
+
if (this._headerRow) {
|
|
390
|
+
this._headerRow.getHTML().css('grid-template-columns', this.getComputedWidths().join(' '))
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Return column widths.
|
|
396
|
+
* @returns {String[]}
|
|
397
|
+
*/
|
|
398
|
+
getWidths() {
|
|
399
|
+
return this._widths
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Return computed column widths.
|
|
404
|
+
* @param {qui.tables.TableRow} [row] an optional row about to be added
|
|
405
|
+
* @returns {String[]}
|
|
406
|
+
*/
|
|
407
|
+
getComputedWidths(row = null) {
|
|
408
|
+
if (this._computedWidths == null) {
|
|
409
|
+
this._computedWidths = this._widths
|
|
410
|
+
let numColumns = this.getNumColumns(row)
|
|
411
|
+
|
|
412
|
+
if (this._computedWidths == null) {
|
|
413
|
+
this._computedWidths = []
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
while (this._computedWidths.length < numColumns) {
|
|
417
|
+
this._computedWidths.push('1fr')
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
this._computedWidths = this._computedWidths.map(function (width, i) {
|
|
421
|
+
if (this._visibilities && !this._visibilities[i]) {
|
|
422
|
+
return '0'
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
return width
|
|
426
|
+
}
|
|
427
|
+
}.bind(this))
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return this._computedWidths
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Set column visibilities.
|
|
435
|
+
* @param {?Boolean[]} visibilities table column visibilities
|
|
436
|
+
*/
|
|
437
|
+
setVisibilities(visibilities) {
|
|
438
|
+
this._visibilities = visibilities
|
|
439
|
+
|
|
440
|
+
/* Recalculate widths as they depend on visibilities */
|
|
441
|
+
this.setWidths(this._widths)
|
|
442
|
+
|
|
443
|
+
let rows = this.getRows()
|
|
444
|
+
if (this._headerRow) {
|
|
445
|
+
rows.push(this._headerRow)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
rows.forEach(function (row) {
|
|
449
|
+
row.getCells().forEach(function (cell, i) {
|
|
450
|
+
if (!this._visibilities || this._visibilities[i]) {
|
|
451
|
+
cell.show()
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
cell.hide()
|
|
455
|
+
}
|
|
456
|
+
}.bind(this))
|
|
457
|
+
}.bind(this))
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Return column visibilities.
|
|
462
|
+
* @returns {Boolean[]}
|
|
463
|
+
*/
|
|
464
|
+
getVisibilities() {
|
|
465
|
+
return this._visibilities
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/* Values */
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Return the current values of the table.
|
|
472
|
+
* @returns {Array[]}
|
|
473
|
+
*/
|
|
474
|
+
getValues() {
|
|
475
|
+
return this.getRows().map(r => r.getValues())
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Set table values. If more values than needed are supplied, extra values are ignored. If less values are supplied,
|
|
480
|
+
* extra rows are left unchanged.
|
|
481
|
+
* @param {Array[]} values
|
|
482
|
+
* @param {Number} [index] optional start index (defaults to `0`)
|
|
483
|
+
*/
|
|
484
|
+
setValues(values, index = 0) {
|
|
485
|
+
let rows = this.getRows().slice(index, index + values.length)
|
|
486
|
+
rows.forEach((r, i) => r.setValues(values[i]))
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
export default Table
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @namespace qui.tables
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @alias qui.tables.TABLE_CELL_ALIGN_LEFT
|
|
7
|
+
*/
|
|
8
|
+
export const TABLE_CELL_ALIGN_LEFT = 'left'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @alias qui.tables.TABLE_CELL_ALIGN_CENTER
|
|
12
|
+
*/
|
|
13
|
+
export const TABLE_CELL_ALIGN_CENTER = 'center'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @alias qui.tables.TABLE_CELL_ALIGN_RIGHT
|
|
17
|
+
*/
|
|
18
|
+
export const TABLE_CELL_ALIGN_RIGHT = 'right'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @alias qui.tables.TABLE_CELL_ALIGN_TOP
|
|
22
|
+
*/
|
|
23
|
+
export const TABLE_CELL_ALIGN_TOP = 'top'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @alias qui.tables.TABLE_CELL_ALIGN_BOTTOM
|
|
27
|
+
*/
|
|
28
|
+
export const TABLE_CELL_ALIGN_BOTTOM = 'bottom'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Table row match function.
|
|
33
|
+
* @callback qui.tables.TableRowMatchFunc
|
|
34
|
+
* @param {qui.tables.TableRow} row the row to be tested
|
|
35
|
+
* @returns {Boolean} `true` if the row matches the condition, `false` otherwise
|
|
36
|
+
*/
|