@questwork/vue-q-widget-vue3 3.1.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/.babelrc.json +16 -0
- package/LICENSE +9 -0
- package/dist/q-widget.min.js +14 -0
- package/dist/q-widget.min.js.LICENSE.txt +1 -0
- package/lib/helpers/controller/index.js +11 -0
- package/lib/helpers/controller/saveState.js +26 -0
- package/lib/helpers/controller/showError.js +27 -0
- package/lib/helpers/index.js +2 -0
- package/lib/helpers/utilities/configHandler/configHandler.js +26 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQForm/buttonsHandler.js +41 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQForm/elementQFormConfigHandler.js +38 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQForm/index.js +1 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQForm/layoutHandler.js +54 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQList/actionsHandler.js +41 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQList/bulkActionHandler.js +53 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQList/elementQListConfigHandler.js +43 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQList/headersHandler.js +48 -0
- package/lib/helpers/utilities/configHandler/handlers/elementQList/index.js +1 -0
- package/lib/helpers/utilities/configHandler/handlers/index.js +15 -0
- package/lib/helpers/utilities/configHandler/index.js +1 -0
- package/lib/helpers/utilities/index.js +2 -0
- package/lib/helpers/utilities/setId/index.js +1 -0
- package/lib/helpers/utilities/setId/setId.js +10 -0
- package/lib/index.js +2 -0
- package/lib/models/configs/config.js +23 -0
- package/lib/models/configs/elementQForm/buttonHandler.js +68 -0
- package/lib/models/configs/elementQForm/elementQForm.js +34 -0
- package/lib/models/configs/elementQForm/index.js +1 -0
- package/lib/models/configs/elementQForm/makeFormHandler.js +27 -0
- package/lib/models/configs/elementQForm/nodeHandler.js +60 -0
- package/lib/models/configs/elementQGrid/elementQGrid.js +50 -0
- package/lib/models/configs/elementQGrid/index.js +1 -0
- package/lib/models/configs/elementQGrid/makeClasses.js +86 -0
- package/lib/models/configs/elementQList/elementQList.js +75 -0
- package/lib/models/configs/elementQList/index.js +1 -0
- package/lib/models/configs/elementQList/makeQWidgetQListBulkButton.js +78 -0
- package/lib/models/configs/elementQList/makeQWidgetQListButton.js +83 -0
- package/lib/models/configs/elementQList/makeQWidgetQListHeader.js +75 -0
- package/lib/models/configs/index.js +3 -0
- package/lib/models/controller/controller.js +67 -0
- package/lib/models/controller/index.js +1 -0
- package/lib/models/controllerHelpers/controllerHelpers.js +46 -0
- package/lib/models/controllerHelpers/index.js +1 -0
- package/lib/models/factories/index.js +1 -0
- package/lib/models/factories/nodeFactory.js +55 -0
- package/lib/models/index.js +5 -0
- package/lib/models/nodes/container.js +37 -0
- package/lib/models/nodes/containers/box.js +16 -0
- package/lib/models/nodes/containers/column.js +16 -0
- package/lib/models/nodes/containers/headerSticky.js +16 -0
- package/lib/models/nodes/containers/index.js +18 -0
- package/lib/models/nodes/containers/row.js +16 -0
- package/lib/models/nodes/element.js +124 -0
- package/lib/models/nodes/elements/index.js +33 -0
- package/lib/models/nodes/elements/qButton.js +15 -0
- package/lib/models/nodes/elements/qForm.js +67 -0
- package/lib/models/nodes/elements/qGrid.js +35 -0
- package/lib/models/nodes/elements/qHtml.js +15 -0
- package/lib/models/nodes/elements/qImport.js +15 -0
- package/lib/models/nodes/elements/qLabel.js +15 -0
- package/lib/models/nodes/elements/qList.js +46 -0
- package/lib/models/nodes/elements/qPaginator.js +20 -0
- package/lib/models/nodes/elements/qTab.js +19 -0
- package/lib/models/nodes/index.js +21 -0
- package/lib/models/nodes/node.js +69 -0
- package/package.json +73 -0
- package/vite.config.js +52 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Config {
|
|
2
|
+
constructor(opt = {}) {
|
|
3
|
+
this.css = opt.css
|
|
4
|
+
this.configType = 'Config'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
get isValid() {
|
|
8
|
+
return !!this
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static init(config) {
|
|
12
|
+
const instance = new this(config)
|
|
13
|
+
return instance.isValid ? instance : null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
Config
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
Config
|
|
23
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
function buttonHandler(obj, helpers) {
|
|
2
|
+
const { button, klass } = obj
|
|
3
|
+
const { element } = helpers
|
|
4
|
+
const state = element.getState() || {}
|
|
5
|
+
const { formData = {} } = state
|
|
6
|
+
class QWidgetQFormButton extends klass {
|
|
7
|
+
constructor(opt) {
|
|
8
|
+
super(opt)
|
|
9
|
+
this.hidden = opt.hidden || false
|
|
10
|
+
this.permissionResult = opt.permissionResult
|
|
11
|
+
this.permissionResultHandler(this.permissionResult)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get isValid() {
|
|
15
|
+
return !this.hidden
|
|
16
|
+
&& super.isValid
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static init(options, _helpers) {
|
|
20
|
+
if (options instanceof QWidgetQFormButton) {
|
|
21
|
+
return options
|
|
22
|
+
}
|
|
23
|
+
const permissionResult = options.permissions ? _helpers.permissionHandler(options.permissions, formData) : {
|
|
24
|
+
isAllowCreate: true,
|
|
25
|
+
isAllowRead: true,
|
|
26
|
+
isAllowUpdate: true,
|
|
27
|
+
isAllowDelete: true,
|
|
28
|
+
}
|
|
29
|
+
const instance = new QWidgetQFormButton({
|
|
30
|
+
...options,
|
|
31
|
+
permissionResult
|
|
32
|
+
})
|
|
33
|
+
return instance.isValid ? instance : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
permissionResultHandler(permissionResult) {
|
|
37
|
+
const {
|
|
38
|
+
event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete
|
|
39
|
+
} = permissionResult
|
|
40
|
+
if (event) {
|
|
41
|
+
if (typeof this[event] === 'function') {
|
|
42
|
+
this[event]({ val: true })
|
|
43
|
+
} else {
|
|
44
|
+
console.log(`do not have the event ${event}`)
|
|
45
|
+
}
|
|
46
|
+
} else if (!(isAllowCreate && isAllowRead && isAllowUpdate && isAllowDelete)) {
|
|
47
|
+
this.setHidden({ val: true })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setDisabled({ val }) {
|
|
52
|
+
this.disabled = val
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setHidden({ val }) {
|
|
56
|
+
this.hidden = val
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return QWidgetQFormButton.init(button, helpers)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default {
|
|
63
|
+
buttonHandler
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
buttonHandler
|
|
68
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Config } from '../config'
|
|
2
|
+
import { makeFormHandler } from './makeFormHandler'
|
|
3
|
+
|
|
4
|
+
class ElementQFormConfig extends Config {
|
|
5
|
+
constructor(opt = {}) {
|
|
6
|
+
super(opt)
|
|
7
|
+
this.configType = 'ElementQFormConfig'
|
|
8
|
+
this.buttons = opt.buttons
|
|
9
|
+
this.css = opt.css || {}
|
|
10
|
+
this.disabledForm = opt.disabledForm || false
|
|
11
|
+
this.eventName = opt.eventName || {}
|
|
12
|
+
this.formHandler = makeFormHandler(opt.helpers)
|
|
13
|
+
this.layout = opt.layout
|
|
14
|
+
this.previewForm = opt.previewForm || false
|
|
15
|
+
this.updateLayoutConfigs = opt.updateLayoutConfigs || []
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get isValid() {
|
|
19
|
+
return !!this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static init(layout) {
|
|
23
|
+
const instance = new this(layout)
|
|
24
|
+
return instance.isValid ? instance : null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
ElementQFormConfig
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
ElementQFormConfig
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ElementQFormConfig } from './elementQForm'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { buttonHandler } from './buttonHandler'
|
|
2
|
+
import { nodeHandler } from './nodeHandler'
|
|
3
|
+
|
|
4
|
+
function makeFormHandler(helpers) {
|
|
5
|
+
return (obj) => {
|
|
6
|
+
const { type } = obj
|
|
7
|
+
switch (type) {
|
|
8
|
+
case ('button'): {
|
|
9
|
+
return buttonHandler(obj, helpers)
|
|
10
|
+
}
|
|
11
|
+
case ('node'): {
|
|
12
|
+
return nodeHandler(obj, helpers)
|
|
13
|
+
}
|
|
14
|
+
default: {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
makeFormHandler
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
makeFormHandler
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function nodeHandler(obj, helpers) {
|
|
2
|
+
const { layout, klass } = obj
|
|
3
|
+
const { element } = helpers
|
|
4
|
+
const state = element.getState() || {}
|
|
5
|
+
const { formData = {} } = state
|
|
6
|
+
class QWidgetQFormNode extends klass {
|
|
7
|
+
constructor(opt) {
|
|
8
|
+
super(opt)
|
|
9
|
+
this.permissionResult = opt.permissions ? helpers.permissionHandler(opt.permissions, formData) : {
|
|
10
|
+
isAllowCreate: true,
|
|
11
|
+
isAllowRead: true,
|
|
12
|
+
isAllowUpdate: true,
|
|
13
|
+
isAllowDelete: true,
|
|
14
|
+
}
|
|
15
|
+
this.permissionResultHandler(this.permissionResult)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
permissionResultHandler(permissionResult) {
|
|
19
|
+
const { event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete } = permissionResult
|
|
20
|
+
if (event) {
|
|
21
|
+
if (typeof this[event] === 'function') {
|
|
22
|
+
this[event]({ val: true })
|
|
23
|
+
} else {
|
|
24
|
+
console.log(`do not have the event ${event}`)
|
|
25
|
+
}
|
|
26
|
+
} else if (!isAllowRead) {
|
|
27
|
+
this.setHidden({ val: true })
|
|
28
|
+
} else if (!isAllowUpdate) {
|
|
29
|
+
this.setPreview({ val: true })
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(this.children)) {
|
|
32
|
+
this.children.forEach((child) => {
|
|
33
|
+
child.permissionResultHandler(permissionResult)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setDecoratorDisabled({ val }) {
|
|
39
|
+
this.setDisabled({ val })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setDecoratorHidden({ val }) {
|
|
43
|
+
this.setHidden({ val })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setDecoratorPreview({ val }) {
|
|
47
|
+
this.setPreview({ val })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const i = QWidgetQFormNode.init(layout)
|
|
51
|
+
return i
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
nodeHandler
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
nodeHandler
|
|
60
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Config } from '../config'
|
|
2
|
+
import { makeClasses } from './makeClasses'
|
|
3
|
+
|
|
4
|
+
class ElementQGridConfig extends Config {
|
|
5
|
+
constructor(opt = {}) {
|
|
6
|
+
super(opt)
|
|
7
|
+
this.configType = 'ElementQGridConfig'
|
|
8
|
+
this.classes = makeClasses({
|
|
9
|
+
helpers: opt.helpers
|
|
10
|
+
})
|
|
11
|
+
this.converter = makeConvert({
|
|
12
|
+
helpers: opt.helpers,
|
|
13
|
+
})
|
|
14
|
+
this.eventName = opt.eventName
|
|
15
|
+
this.layout = opt.layout
|
|
16
|
+
this.fillLastRow = opt.fillLastRow
|
|
17
|
+
this.placeholder = opt.placeholder
|
|
18
|
+
this.urlDelegate = opt.urlDelegate
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get isValid() {
|
|
22
|
+
return !!this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static init(layout) {
|
|
26
|
+
const instance = new this(layout)
|
|
27
|
+
return instance.isValid ? instance : null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function makeConvert({ helpers }) {
|
|
32
|
+
const { element } = helpers
|
|
33
|
+
const { converter } = element.getHandlers()
|
|
34
|
+
if (typeof converter !== 'function') {
|
|
35
|
+
return (item) => (item)
|
|
36
|
+
}
|
|
37
|
+
const { QItem } = helpers.qGrid
|
|
38
|
+
return converter({
|
|
39
|
+
helpers: {
|
|
40
|
+
QItem,
|
|
41
|
+
...helpers,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
ElementQGridConfig,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ElementQGridConfig }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ElementQGridConfig } from './elementQGrid'
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The current (vue-q-grid@0.1.20) return type must be { Cell: CustomCell } or {}
|
|
2
|
+
// where CustomCell extends from Cell.
|
|
3
|
+
function makeClasses({ helpers }) {
|
|
4
|
+
const { element } = helpers
|
|
5
|
+
const { getClasses } = element.getHandlers()
|
|
6
|
+
|
|
7
|
+
const { Cell } = helpers.qGrid
|
|
8
|
+
class QWidgetQGridCell extends Cell {
|
|
9
|
+
constructor(opt) {
|
|
10
|
+
super(opt)
|
|
11
|
+
if (typeof opt.hidden === 'function') {
|
|
12
|
+
this.permissionHidden = opt.hidden(this.item.item, this)
|
|
13
|
+
} else {
|
|
14
|
+
this.permissionHidden = opt.hidden || false
|
|
15
|
+
}
|
|
16
|
+
this.permissionResult = opt.permissionResult
|
|
17
|
+
this.permissionResultHandler(this.permissionResult, opt.customComponentName)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get isValid() {
|
|
21
|
+
return this.permissionHidden === false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static init(options) {
|
|
25
|
+
const { permissions } = options
|
|
26
|
+
const permissionResult = permissions ? helpers.permissionHandler(permissions) : {
|
|
27
|
+
isAllowCreate: true,
|
|
28
|
+
isAllowRead: true,
|
|
29
|
+
isAllowUpdate: true,
|
|
30
|
+
isAllowDelete: true,
|
|
31
|
+
}
|
|
32
|
+
const instance = new this({
|
|
33
|
+
...options,
|
|
34
|
+
permissionResult
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return instance.isValid ? instance : null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
permissionResultHandler(permissionResult, customComponentName) {
|
|
41
|
+
const {
|
|
42
|
+
event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete
|
|
43
|
+
} = permissionResult
|
|
44
|
+
if (event) {
|
|
45
|
+
if (typeof this[event] === 'function') {
|
|
46
|
+
this[event]({ val: true })
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`do not have the event ${event}`)
|
|
49
|
+
}
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isButton = customComponentName === 'q-grid-body-row-cell-button'
|
|
54
|
+
if (
|
|
55
|
+
(!isButton && !isAllowRead)
|
|
56
|
+
|| (!(isAllowCreate && isAllowRead && isAllowUpdate && isAllowDelete))
|
|
57
|
+
) {
|
|
58
|
+
this.setHidden({ val: true })
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setHidden({ val }) {
|
|
63
|
+
this.permissionHidden = val
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof getClasses !== 'function') {
|
|
68
|
+
return {
|
|
69
|
+
Cell: QWidgetQGridCell
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return getClasses({
|
|
73
|
+
helpers: {
|
|
74
|
+
Cell: QWidgetQGridCell,
|
|
75
|
+
...helpers,
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
makeClasses
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
makeClasses
|
|
86
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Config } from '../config'
|
|
2
|
+
import { makeQWidgetQListBulkButton } from './makeQWidgetQListBulkButton'
|
|
3
|
+
import { makeQWidgetQListButton } from './makeQWidgetQListButton'
|
|
4
|
+
import { makeQWidgetQListHeader } from './makeQWidgetQListHeader'
|
|
5
|
+
|
|
6
|
+
class ElementQListConfig extends Config {
|
|
7
|
+
constructor(opt = {}) {
|
|
8
|
+
super(opt)
|
|
9
|
+
this.configType = 'ElementQListConfig'
|
|
10
|
+
this.bulkAction = initBulkAction({
|
|
11
|
+
bulkAction: opt.bulkAction,
|
|
12
|
+
helpers: opt.helpers,
|
|
13
|
+
})
|
|
14
|
+
this.converter = makeConvert({
|
|
15
|
+
actions: opt.actions,
|
|
16
|
+
helpers: opt.helpers,
|
|
17
|
+
})
|
|
18
|
+
this.css = opt.css
|
|
19
|
+
this.eventName = opt.eventName
|
|
20
|
+
this.headers = initHeaders({
|
|
21
|
+
headers: opt.headers,
|
|
22
|
+
helpers: opt.helpers,
|
|
23
|
+
})
|
|
24
|
+
this.listStyle = opt.listStyle || 'q-list-table'
|
|
25
|
+
this.listShowFooter = opt.showFooter || false
|
|
26
|
+
this.listSortBys = opt.sortBys
|
|
27
|
+
this.noDataMessage = opt.noDataMessage
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get isValid() {
|
|
31
|
+
return !!this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static init(layout) {
|
|
35
|
+
const instance = new this(layout)
|
|
36
|
+
return instance.isValid ? instance : null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function initBulkAction({ bulkAction = {}, helpers }) {
|
|
41
|
+
const QWidgetQListBulkButton = makeQWidgetQListBulkButton({ helpers })
|
|
42
|
+
return {
|
|
43
|
+
...bulkAction,
|
|
44
|
+
actions: QWidgetQListBulkButton.initOnlyValidFromArray(bulkAction.actions, helpers),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function initHeaders({ headers, helpers }) {
|
|
49
|
+
const QWidgetQListHeader = makeQWidgetQListHeader({ helpers })
|
|
50
|
+
return QWidgetQListHeader.initOnlyValidFromArray(headers, helpers)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function makeConvert({ actions, helpers }) {
|
|
54
|
+
const { QRow } = helpers.qList
|
|
55
|
+
const QWidgetQListButton = makeQWidgetQListButton({ helpers })
|
|
56
|
+
const _helpers = {
|
|
57
|
+
QListButton: QWidgetQListButton,
|
|
58
|
+
QRow,
|
|
59
|
+
...helpers,
|
|
60
|
+
}
|
|
61
|
+
const { element } = _helpers
|
|
62
|
+
const { converter } = element.getHandlers()
|
|
63
|
+
if (typeof converter !== 'function') {
|
|
64
|
+
return (row) => (row)
|
|
65
|
+
}
|
|
66
|
+
return converter({ actions, helpers: _helpers })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
ElementQListConfig
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
ElementQListConfig
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ElementQListConfig } from './elementQList'
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function makeQWidgetQListBulkButton({ helpers }) {
|
|
2
|
+
const { QListBulkButton } = helpers.qList
|
|
3
|
+
const { getValidation } = helpers.qUtilities
|
|
4
|
+
class QWidgetQListBulkButton extends QListBulkButton {
|
|
5
|
+
constructor(opt) {
|
|
6
|
+
super(opt)
|
|
7
|
+
this.hidden = opt.hidden || false
|
|
8
|
+
this.permissionResult = opt.permissionResult
|
|
9
|
+
this.permissionResultHandler(this.permissionResult)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get isValid() {
|
|
13
|
+
return !this.hidden
|
|
14
|
+
// && super.isValid
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static init(options, _helpers) {
|
|
18
|
+
if (options instanceof QWidgetQListBulkButton) {
|
|
19
|
+
return options
|
|
20
|
+
}
|
|
21
|
+
const { restriction, permissions } = options
|
|
22
|
+
const data = _helpers.controller.getState()
|
|
23
|
+
if (!getValidation({ rule: restriction, data })) {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
const permissionResult = permissions ? _helpers.permissionHandler(permissions) : {
|
|
27
|
+
isAllowCreate: true,
|
|
28
|
+
isAllowRead: true,
|
|
29
|
+
isAllowUpdate: true,
|
|
30
|
+
isAllowDelete: true,
|
|
31
|
+
}
|
|
32
|
+
const instance = new QWidgetQListBulkButton({
|
|
33
|
+
...options,
|
|
34
|
+
permissionResult
|
|
35
|
+
})
|
|
36
|
+
return instance.isValid ? instance : null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static initFromArray(arr, _helpers) {
|
|
40
|
+
if (Array.isArray(arr)) {
|
|
41
|
+
return arr.map((i) => (this.init(i, _helpers)))
|
|
42
|
+
}
|
|
43
|
+
return []
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static initOnlyValidFromArray(arr, _helpers) {
|
|
47
|
+
return this.initFromArray(arr, _helpers).filter((i) => i)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
permissionResultHandler(permissionResult) {
|
|
51
|
+
const {
|
|
52
|
+
event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete
|
|
53
|
+
} = permissionResult
|
|
54
|
+
if (event) {
|
|
55
|
+
if (typeof this[event] === 'function') {
|
|
56
|
+
this[event]({ val: true })
|
|
57
|
+
} else {
|
|
58
|
+
console.log(`do not have the event ${event}`)
|
|
59
|
+
}
|
|
60
|
+
} else if (!(isAllowCreate && isAllowRead && isAllowUpdate && isAllowDelete)) {
|
|
61
|
+
this.setHidden({ val: true })
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setHidden({ val }) {
|
|
66
|
+
this.hidden = val
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return QWidgetQListBulkButton
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default {
|
|
73
|
+
makeQWidgetQListBulkButton
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
makeQWidgetQListBulkButton
|
|
78
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
function makeQWidgetQListButton({ helpers }) {
|
|
2
|
+
const { QListButton } = helpers.qList
|
|
3
|
+
class QWidgetQListButton extends QListButton {
|
|
4
|
+
constructor(opt) {
|
|
5
|
+
super(opt)
|
|
6
|
+
this.endpoint = convertUrlPath(opt.endpoint, opt.qRow)
|
|
7
|
+
this.httpMethod = opt.httpMethod
|
|
8
|
+
this.hidden = opt.hidden || false
|
|
9
|
+
this.permissionResult = opt.permissionResult
|
|
10
|
+
this.permissionResultHandler(this.permissionResult)
|
|
11
|
+
this.url = convertUrlPath(opt.url, opt.qRow)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get isValid() {
|
|
15
|
+
return !this.hidden
|
|
16
|
+
&& super.isValid
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static init(options, _helpers) {
|
|
20
|
+
if (options instanceof QWidgetQListButton) {
|
|
21
|
+
return options
|
|
22
|
+
}
|
|
23
|
+
const permissionResult = options.permissions ? _helpers.permissionHandler(options.permissions, options.qRow.get()) : {
|
|
24
|
+
isAllowCreate: true,
|
|
25
|
+
isAllowRead: true,
|
|
26
|
+
isAllowUpdate: true,
|
|
27
|
+
isAllowDelete: true,
|
|
28
|
+
}
|
|
29
|
+
const instance = new QWidgetQListButton({
|
|
30
|
+
...options,
|
|
31
|
+
permissionResult
|
|
32
|
+
})
|
|
33
|
+
return instance.isValid ? instance : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static initFromArray(arr, _helpers) {
|
|
37
|
+
if (Array.isArray(arr)) {
|
|
38
|
+
return arr.map((i) => (this.init(i, _helpers)))
|
|
39
|
+
}
|
|
40
|
+
return []
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static initOnlyValidFromArray(arr, _helpers) {
|
|
44
|
+
return this.initFromArray(arr, _helpers).filter((i) => i)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
permissionResultHandler(permissionResult) {
|
|
48
|
+
const {
|
|
49
|
+
event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete
|
|
50
|
+
} = permissionResult
|
|
51
|
+
if (event) {
|
|
52
|
+
if (typeof this[event] === 'function') {
|
|
53
|
+
this[event]({ val: true })
|
|
54
|
+
} else {
|
|
55
|
+
console.log(`do not have the event ${event}`)
|
|
56
|
+
}
|
|
57
|
+
} else if (!(isAllowCreate && isAllowRead && isAllowUpdate && isAllowDelete)) {
|
|
58
|
+
this.setHidden({ val: true })
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setHidden({ val }) {
|
|
63
|
+
this.hidden = val
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return QWidgetQListButton
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function convertUrlPath(string, qRow) {
|
|
70
|
+
if (!string) {
|
|
71
|
+
return ''
|
|
72
|
+
}
|
|
73
|
+
const patternMatch = /\$\{(.+?)\}/g
|
|
74
|
+
return string.replace(patternMatch, (match, key) => qRow.get(key.trim()))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default {
|
|
78
|
+
makeQWidgetQListButton
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
makeQWidgetQListButton
|
|
83
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
function makeQWidgetQListHeader() {
|
|
3
|
+
class QWidgetQListHeader {
|
|
4
|
+
constructor(opt) {
|
|
5
|
+
Object.keys(opt).forEach((key) => {
|
|
6
|
+
this[key] = opt[key]
|
|
7
|
+
})
|
|
8
|
+
this.hidden = opt.hidden || false
|
|
9
|
+
this.permissionResult = opt.permissionResult
|
|
10
|
+
this.permissionResultHandler(this.permissionResult)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get isValid() {
|
|
14
|
+
return !this.hidden
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static init(options, _helpers) {
|
|
18
|
+
if (options instanceof QWidgetQListHeader) {
|
|
19
|
+
return options
|
|
20
|
+
}
|
|
21
|
+
const { children, permissions } = options
|
|
22
|
+
const permissionResult = permissions ? _helpers.permissionHandler(permissions) : {
|
|
23
|
+
isAllowCreate: true,
|
|
24
|
+
isAllowRead: true,
|
|
25
|
+
isAllowUpdate: true,
|
|
26
|
+
isAllowDelete: true,
|
|
27
|
+
}
|
|
28
|
+
const instance = new QWidgetQListHeader({
|
|
29
|
+
...options,
|
|
30
|
+
children: Array.isArray(children) ? this.initOnlyValidFromArray(children, _helpers) : null,
|
|
31
|
+
permissionResult
|
|
32
|
+
})
|
|
33
|
+
return instance.isValid ? instance : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static initFromArray(arr, _helpers) {
|
|
37
|
+
if (Array.isArray(arr)) {
|
|
38
|
+
return arr.map((i) => (this.init(i, _helpers)))
|
|
39
|
+
}
|
|
40
|
+
return []
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static initOnlyValidFromArray(arr, _helpers) {
|
|
44
|
+
return this.initFromArray(arr, _helpers).filter((i) => i)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
permissionResultHandler(permissionResult) {
|
|
48
|
+
const {
|
|
49
|
+
event, isAllowCreate, isAllowRead, isAllowUpdate, isAllowDelete
|
|
50
|
+
} = permissionResult
|
|
51
|
+
if (event) {
|
|
52
|
+
if (typeof this[event] === 'function') {
|
|
53
|
+
this[event]({ val: true })
|
|
54
|
+
} else {
|
|
55
|
+
console.log(`do not have the event ${event}`)
|
|
56
|
+
}
|
|
57
|
+
} else if (!isAllowRead) {
|
|
58
|
+
this.setHidden({ val: true })
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setHidden({ val }) {
|
|
63
|
+
this.hidden = val
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return QWidgetQListHeader
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
makeQWidgetQListHeader
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
makeQWidgetQListHeader
|
|
75
|
+
}
|