@questwork/vue-q-list-vue3 3.1.1 → 3.1.2

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.
@@ -103,4 +103,25 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
103
103
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
104
104
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
105
105
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
106
- THE SOFTWARE.
106
+ THE SOFTWARE.
107
+
108
+ ---
109
+
110
+ Name: @questwork/q-utilities
111
+ Version: 0.1.12
112
+ License: MIT
113
+ Private: false
114
+ Description: Questwork QUtilities
115
+ Author: Questwork Consulting Limited <info@questwork.com> (https://questwork.com/)
116
+ License Copyright:
117
+ ===
118
+
119
+ Copyright 2019 Questwork Consulting Limited
120
+
121
+ This project is free software released under the MIT/X11 license:
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
126
+
127
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,88 +1,9 @@
1
1
  const { getValue } = require('./getValue')
2
2
 
3
- function getValidation({ rule, data }) {
4
- if (!rule) {
5
- return true
6
- }
7
- const { key = '', value } = rule
8
- const [valueAttribute] = Object.keys(value || {})
9
-
10
- if (!key) {
11
- switch (valueAttribute) {
12
- case '$and': {
13
- const arr = value['$and']
14
- return arr.reduce((acc, item) => (acc && getValidation({ rule: item, data })), true)
15
- }
16
- case '$or': {
17
- const arr = value['$or']
18
- return arr.reduce((acc, item) => (acc || getValidation({ rule: item, data })), false)
19
- }
20
- default:
21
- return false
22
- }
23
- }
3
+ const { getValidation: _getValidation, KeyValueObject } = require('@questwork/q-utilities')
24
4
 
25
- const rowValue = getValue(key, data)
26
- switch (valueAttribute) {
27
- case '$empty': {
28
- return !rowValue === !!value['$empty']
29
- }
30
- case '$eq': {
31
- return rowValue === value['$eq']
32
- }
33
- case '$gt': {
34
- return rowValue > value['$gt']
35
- }
36
- case '$gte': {
37
- return rowValue >= value['$gte']
38
- }
39
- case '$in': {
40
- if (Array.isArray(rowValue)) {
41
- return !!rowValue.find((e) => (value['$in'].includes(e)))
42
- }
43
- if (typeof rowValue !== 'object') {
44
- return !!value['$in'].includes(rowValue)
45
- }
46
- return false
47
- }
48
- case '$lt': {
49
- return rowValue < value['$lt']
50
- }
51
- case '$lte': {
52
- return rowValue <= value['$lte']
53
- }
54
- case '$ne': {
55
- return rowValue !== value['$ne']
56
- }
57
- case '$notIn': {
58
- if (Array.isArray(rowValue)) {
59
- return !rowValue.find((e) => (value['$notIn'].includes(e)))
60
- }
61
- if (typeof rowValue !== 'object') {
62
- return !value['$notIn'].includes(rowValue)
63
- }
64
- return false
65
- }
66
- case '$intervalTimeGt': {
67
- const now = new Date().getTime()
68
- const timestamp = new Date(rowValue).getTime()
69
- return (now - timestamp) > value['$intervalTimeGt']
70
- }
71
- case '$intervalTimeLt': {
72
- const now = new Date().getTime()
73
- const timestamp = new Date(rowValue).getTime()
74
- return (now - timestamp) < value['$intervalTimeLt']
75
- }
76
- case '$range': {
77
- const [min, max] = value['$range']
78
- if (typeof min === 'number' && typeof max === 'number' && rowValue >= min && rowValue <= max) {
79
- return true
80
- }
81
- return false
82
- }
83
- default:
84
- return false
85
- }
5
+ function getValidation({ rule, data }) {
6
+ return _getValidation(rule, data, getValue, KeyValueObject)
86
7
  }
87
8
 
88
9
  module.exports = {
@@ -1,5 +1,8 @@
1
+ const { getValueByKeys} = require('@questwork/q-utilities')
2
+
1
3
  function getValue(key, value) {
2
- return getValueInObj({ keys: key.split('.'), obj: value })
4
+ return getValueByKeys(key.split('.'), value)
5
+ // return getValueInObj({ keys: key.split('.'), obj: value })
3
6
  }
4
7
 
5
8
  function getValueInObj({ keys, obj }) {
@@ -1,4 +1,5 @@
1
1
  const { dateHelper } = require('@questwork/utilities/lib/dateHelper')
2
+ const { TemplateCompiler } = require('@questwork/q-utilities')
2
3
 
3
4
  class QRow {
4
5
  constructor(options = {}) {
@@ -18,6 +19,7 @@ class QRow {
18
19
  this.shouldBeVisible = setShouldBeVisible(options.shouldBeVisible || null)
19
20
  this.uniqueKey = options.uniqueKey
20
21
  this.unread = options.unread || false
22
+ this._templateCompiler = TemplateCompiler.init(this.row)
21
23
  }
22
24
 
23
25
  // Class methods
@@ -81,6 +83,10 @@ class QRow {
81
83
  // const realKey = arr[1]
82
84
  // return this[realKey]
83
85
  }
86
+ // check if regular expr
87
+ if (_useTemplateCompiler(key)) {
88
+ return this._templateCompiler.pipe(key)
89
+ }
84
90
  if (key.includes('.')) {
85
91
  const arr = key.split('.')
86
92
  return getRecursiveValue(this.row, arr)
@@ -146,6 +152,15 @@ class QRow {
146
152
  return cssArr
147
153
  }
148
154
 
155
+ // pipe(templateCompiler) {
156
+ // if (!this._templateCompiler && typeof templateCompiler.init === 'function') {
157
+ // this._templateCompiler = templateCompiler.init(this.row)
158
+ // }
159
+ // return (expr) => {
160
+ // return this._templateCompiler.pipe(expr)
161
+ // }
162
+ // }
163
+
149
164
  removeCss(className) {
150
165
  this.cssNames = this.cssNames.filter((e) => (e !== className))
151
166
  return this
@@ -212,6 +227,11 @@ function setShouldBeVisible(shouldBeVisible) {
212
227
  }
213
228
  }
214
229
 
230
+ function _useTemplateCompiler(key) {
231
+ key = key.trim()
232
+ return (key.indexOf('{{') === 0) || (key.indexOf('<%') === 0)
233
+ }
234
+
215
235
  module.exports = {
216
236
  QRow,
217
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@questwork/vue-q-list-vue3",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "Questwork vue component for displaying a list",
5
5
  "exports": {
6
6
  ".": {
@@ -15,6 +15,9 @@
15
15
  "url": "http://www.questwork.com/"
16
16
  },
17
17
  "license": "MIT",
18
+ "dependencies": {
19
+ "@questwork/q-utilities": "^0.1.12"
20
+ },
18
21
  "devDependencies": {
19
22
  "@babel/core": "^7.17.8",
20
23
  "@babel/eslint-parser": "^7.17.0",