@kaspernj/api-maker 1.0.219 → 1.0.220
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/package.json
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -13,8 +13,44 @@ import Services from "./services.mjs"
|
|
|
13
13
|
import ValidationError from "./validation-error.mjs"
|
|
14
14
|
import {ValidationErrors} from "./validation-errors.mjs"
|
|
15
15
|
|
|
16
|
+
class ApiMakerAttribute {
|
|
17
|
+
constructor(attributeData) {
|
|
18
|
+
this.attributeData = attributeData
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
isColumn() {
|
|
22
|
+
return Boolean(digg(this, "attributeData", "column"))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isSelectedByDefault() {
|
|
26
|
+
const isSelectedByDefault = digg(this, "attributeData", "selected_by_default")
|
|
27
|
+
|
|
28
|
+
if (isSelectedByDefault || isSelectedByDefault === null) return true
|
|
29
|
+
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
name() {
|
|
34
|
+
return digg(this, "attributeData", "name")
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
16
38
|
class BaseModel {
|
|
17
|
-
static
|
|
39
|
+
static attributes() {
|
|
40
|
+
const attributes = digg(this.modelClassData(), "attributes")
|
|
41
|
+
const result = []
|
|
42
|
+
|
|
43
|
+
for (const attributeKey in attributes) {
|
|
44
|
+
const attributeData = attributes[attributeKey]
|
|
45
|
+
const attribute = new ApiMakerAttribute(attributeData)
|
|
46
|
+
|
|
47
|
+
result.push(attribute)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static modelClassData() {
|
|
18
54
|
throw new Error("modelClassData should be overriden by child")
|
|
19
55
|
}
|
|
20
56
|
|
|
@@ -25,9 +25,24 @@ export default class ApiMakerSuperAdminIndexPage extends React.PureComponent {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
columns = () => {
|
|
28
|
-
|
|
28
|
+
const {modelClass} = digs(this.props, "modelClass")
|
|
29
|
+
const attributes = modelClass.attributes()
|
|
30
|
+
const columns = []
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
for (const attribute of attributes) {
|
|
33
|
+
if (!attribute.isSelectedByDefault()) continue
|
|
34
|
+
|
|
35
|
+
const camelizedName = inflection.camelize(attribute.name(), true)
|
|
36
|
+
const column = {
|
|
37
|
+
attribute: camelizedName
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (attribute.isColumn()) column.sortKey = camelizedName
|
|
41
|
+
|
|
42
|
+
columns.push(column)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return columns
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
viewModelPath = (args) => {
|