@questwork/vue-q-list-vue3 3.1.8 → 3.1.9

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.
@@ -0,0 +1,27 @@
1
+ const { ExpansionManagerQList, ExpansionManagerTemplate } = require('../expansionManager')
2
+
3
+
4
+ class ExpansionFactory {
5
+ static getExpansionManager(config) {
6
+ const { type } = config
7
+ switch (type) {
8
+ case 'template': {
9
+ return ExpansionManagerTemplate.init(config)
10
+ }
11
+ case 'q-list': {
12
+ return ExpansionManagerQList.init(config)
13
+ }
14
+ default: {
15
+ return ExpansionManagerQList.init(config)
16
+ }
17
+
18
+ }
19
+ }
20
+
21
+ }
22
+
23
+
24
+
25
+ module.exports = {
26
+ ExpansionFactory,
27
+ }
@@ -0,0 +1,5 @@
1
+ const { ExpansionFactory } = require('./expansionFactory')
2
+
3
+ module.exports = {
4
+ ExpansionFactory,
5
+ }
@@ -0,0 +1,30 @@
1
+ const { getValidation } = require('../../helpers')
2
+
3
+ class ExpansionManager {
4
+ constructor(options = {}) {
5
+ options = options || {}
6
+ this.noDataMessage = options.noDataMessage || 'No Data'
7
+ this.qRow = options.qRow
8
+ this.restriction = options.restriction
9
+ this.type = options.type
10
+ }
11
+ static init(options) {
12
+ if (options instanceof ExpansionManager) {
13
+ return options
14
+ }
15
+ const instance = new this(options)
16
+ return instance.isValid ? instance : null
17
+ }
18
+
19
+ get isValid() {
20
+ return this
21
+ }
22
+
23
+ get expansibility() {
24
+ return this.restriction ? getValidation({ rule: this.restriction, data: this.qRow}) : true
25
+ }
26
+ }
27
+
28
+ module.exports = {
29
+ ExpansionManager
30
+ }
@@ -0,0 +1,60 @@
1
+ const { ExpansionManager } = require('./expansionManager')
2
+ const { getValue } = require('../../helpers')
3
+
4
+ class ExpansionManagerQList extends ExpansionManager {
5
+ constructor(options = {}) {
6
+ options = options || {}
7
+ super(options)
8
+ this._QRow = options._QRow
9
+ this.bulkAction = options.bulkAction
10
+ this.listData = options.listData
11
+ this.headers = options.headers || []
12
+ this.rowUniqueKey = options.rowUniqueKey
13
+ this.setQRows()
14
+ }
15
+
16
+ get selectedQRows() {
17
+ return this._qRows.filter((r) => r.getIsChecked())
18
+ }
19
+
20
+ get selectedRows() {
21
+ return this.selectedQRows.map((r) => (r.get()))
22
+ }
23
+
24
+ onExpansionSelectedRowsChange() {
25
+ const isChecked = !(this._qRows).find((r) => !r.getIsChecked())
26
+ this.qRow.setChecked(isChecked, false)
27
+ }
28
+
29
+ setCheckedAll(val) {
30
+ this._qRows.forEach((r) => r.setChecked(val))
31
+ }
32
+
33
+ setCheckedRows(rows) {
34
+ this._qRows.forEach((r) => {
35
+ r.updateIsChecked(rows)
36
+ })
37
+ this.onExpansionSelectedRowsChange()
38
+ }
39
+
40
+ setQRows() {
41
+ const rows = getValue(this.listData, this.qRow) || []
42
+ if (!Array.isArray(rows)) {
43
+ this._qRows = []
44
+ } else {
45
+ this._qRows = rows.map((row) => {
46
+ if (row instanceof this._QRow) {
47
+ return row
48
+ }
49
+ return this._QRow.init({
50
+ row,
51
+ uniqueKey: this.rowUniqueKey
52
+ })
53
+ })
54
+ }
55
+ }
56
+ }
57
+
58
+ module.exports = {
59
+ ExpansionManagerQList
60
+ }
@@ -0,0 +1,13 @@
1
+ const { ExpansionManager } = require('./expansionManager')
2
+
3
+ class ExpansionManagerTemplate extends ExpansionManager {
4
+ constructor(options = {}) {
5
+ options = options || {}
6
+ super(options)
7
+ this.templateValue = options.templateValue || []
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ ExpansionManagerTemplate
13
+ }
@@ -0,0 +1,9 @@
1
+ const { ExpansionManager } = require('./expansionManager')
2
+ const { ExpansionManagerQList } = require('./expansionManagerQList')
3
+ const { ExpansionManagerTemplate } = require('./expansionManagerTemplate')
4
+
5
+ module.exports = {
6
+ ExpansionManager,
7
+ ExpansionManagerQList,
8
+ ExpansionManagerTemplate
9
+ }
@@ -1,10 +1,11 @@
1
+ const { ExpansionFactory } = require('../expansionFactory')
1
2
  const { dateHelper } = require('@questwork/utilities/lib/dateHelper')
2
3
  const { TemplateCompiler } = require('@questwork/q-utilities')
3
4
 
4
5
  class QRow {
5
6
  constructor(options = {}) {
6
7
  options = options || {}
7
- this.isChecked = options.isChecked || false
8
+ this.isChecked = options.isChecked
8
9
  this.cssMaker = options.cssMaker
9
10
  this.cssNames = options.cssNames || []
10
11
  this.editable = (typeof options.editable === 'boolean') ? options.editable : true
@@ -15,6 +16,7 @@ class QRow {
15
16
  this.shouldBeVisible = setShouldBeVisible(options.shouldBeVisible || null)
16
17
  this.uniqueKey = options.uniqueKey
17
18
  this._templateCompiler = TemplateCompiler.init(this.row)
19
+ this._expansionManager = {}
18
20
  }
19
21
 
20
22
  // Class methods
@@ -57,6 +59,11 @@ class QRow {
57
59
  get isValid() {
58
60
  return !!this.row
59
61
  }
62
+
63
+ get isAllowCheck() {
64
+ return true
65
+ }
66
+
60
67
  get read() {
61
68
  return !this.unread
62
69
  }
@@ -138,17 +145,34 @@ class QRow {
138
145
  this.editable = val
139
146
  }
140
147
 
148
+ setChecked(val, force = true) {
149
+ if (this.isAllowCheck) {
150
+ this.isChecked = val
151
+ if (force && this._expansionManager && typeof this._expansionManager.setCheckedAll === 'function') {
152
+ this._expansionManager.setCheckedAll(val)
153
+ }
154
+ }
155
+ }
156
+
141
157
  setExpansion(val) {
142
158
  this.expansion = val
143
159
  return this
144
160
  }
145
161
 
162
+ setExpansionManager(config) {
163
+ this._expansionManager = ExpansionFactory.getExpansionManager({
164
+ _QRow: QRow,
165
+ ...config,
166
+ qRow: this,
167
+ })
168
+ }
169
+
146
170
  toggleExpansion() {
147
171
  this.expansion = !this.expansion
148
172
  }
149
173
 
150
174
  updateIsChecked(selectedRows = []) {
151
- this.isChecked = selectedRows.filter((selectedRow) => {
175
+ this.isChecked = typeof this.isChecked === 'boolean' ? this.isChecked : selectedRows.filter((selectedRow) => {
152
176
  return typeof selectedRow.getUniqueKey === 'function' && selectedRow.getUniqueKey() === this.getUniqueKey()
153
177
  }).length > 0
154
178
  return this
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@questwork/vue-q-list-vue3",
3
- "version": "3.1.8",
3
+ "version": "3.1.9",
4
4
  "description": "Questwork vue component for displaying a list",
5
5
  "exports": {
6
6
  ".": {