@kaspernj/api-maker 1.0.228 → 1.0.229
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
|
@@ -9,7 +9,11 @@ export default class ApiMakerSuperAdminConfigReader {
|
|
|
9
9
|
try {
|
|
10
10
|
modelConfig = require(`super-admin/model-configs/${modelNameCamelized}`).default
|
|
11
11
|
} catch (error) {
|
|
12
|
-
|
|
12
|
+
if (error.message.includes("Cannot find module")) {
|
|
13
|
+
console.log(`No model-config for ${modelClass.modelClassData().name}`)
|
|
14
|
+
} else {
|
|
15
|
+
throw error
|
|
16
|
+
}
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
return new ApiMakerSuperAdminConfigReader(modelClass, modelConfig)
|
|
@@ -2,6 +2,7 @@ import AttributeRows from "../../bootstrap/attribute-rows"
|
|
|
2
2
|
import BelongsToAttributeRow from "./belongs-to-attribute-row"
|
|
3
3
|
import ConfigReader from "../config-reader"
|
|
4
4
|
import {digg, digs} from "diggerize"
|
|
5
|
+
import inflection from "inflection"
|
|
5
6
|
import modelLoadWrapper from "../../model-load-wrapper"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
7
8
|
import React from "react"
|
|
@@ -13,10 +14,16 @@ class ApiMakerSuperAdminShowPage extends React.PureComponent {
|
|
|
13
14
|
queryParams: PropTypes.object.isRequired
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
configReader = ConfigReader.forModel(digg(this, "props", "modelClass"))
|
|
18
|
+
|
|
16
19
|
render() {
|
|
17
20
|
const {modelClass, queryParams} = digs(this.props, "modelClass", "queryParams")
|
|
18
21
|
const attributes = this.attributes()
|
|
19
22
|
const model = this.model()
|
|
23
|
+
const extraContent = this.configReader.modelConfig?.show?.extraContent
|
|
24
|
+
const modelArgs = {}
|
|
25
|
+
|
|
26
|
+
modelArgs[inflection.camelize(modelClass.modelClassData().name, true)] = model
|
|
20
27
|
|
|
21
28
|
return (
|
|
22
29
|
<div className="super-admin--show-page">
|
|
@@ -29,16 +36,12 @@ class ApiMakerSuperAdminShowPage extends React.PureComponent {
|
|
|
29
36
|
{model && modelClass.reflections().filter((reflection) => reflection.macro() == "belongs_to").map((reflection) =>
|
|
30
37
|
<BelongsToAttributeRow key={reflection.name()} model={model} modelClass={modelClass} reflection={reflection} />
|
|
31
38
|
)}
|
|
39
|
+
{model && extraContent && extraContent(modelArgs)}
|
|
32
40
|
</div>
|
|
33
41
|
)
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
attributes()
|
|
37
|
-
const {modelClass} = digs(this.props, "modelClass")
|
|
38
|
-
const configReader = ConfigReader.forModel(modelClass)
|
|
39
|
-
|
|
40
|
-
return configReader.attributesToShow()
|
|
41
|
-
}
|
|
44
|
+
attributes = () => this.configReader.attributesToShow()
|
|
42
45
|
|
|
43
46
|
model() {
|
|
44
47
|
const {modelClass} = digs(this.props, "modelClass")
|
|
@@ -60,7 +63,19 @@ export default modelLoadWrapper(
|
|
|
60
63
|
modelClassResolver,
|
|
61
64
|
({modelClass}) => {
|
|
62
65
|
const preload = []
|
|
63
|
-
const
|
|
66
|
+
const configReader = ConfigReader.forModel(modelClass)
|
|
67
|
+
const select = configReader.modelConfig?.show?.extraSelect || {}
|
|
68
|
+
const modelClassName = modelClass.modelClassData().name
|
|
69
|
+
const modelClassSelect = select[modelClassName] || []
|
|
70
|
+
const primaryKeyName = modelClass.primaryKey()
|
|
71
|
+
|
|
72
|
+
if (!(modelClassName in select)) select[modelClassName] = modelClassSelect
|
|
73
|
+
if (!modelClassSelect.includes(primaryKeyName)) modelClassSelect.push(primaryKeyName)
|
|
74
|
+
|
|
75
|
+
// Select all attributes selected by default because they will be shown by default
|
|
76
|
+
for (const attribute of modelClass.attributes()) {
|
|
77
|
+
if (attribute.isSelectedByDefault() && !modelClassSelect.includes(attribute.name())) modelClassSelect.push(attribute.name())
|
|
78
|
+
}
|
|
64
79
|
|
|
65
80
|
for (const reflection of modelClass.reflections()) {
|
|
66
81
|
if (reflection.macro() != "belongs_to") continue
|
|
@@ -70,11 +85,14 @@ export default modelLoadWrapper(
|
|
|
70
85
|
const reflectionModelClassAttributes = reflectionModelClass.attributes()
|
|
71
86
|
const nameAttribute = reflectionModelClassAttributes.find((attribute) => attribute.name() == "name")
|
|
72
87
|
|
|
73
|
-
preload.push(reflection.name())
|
|
88
|
+
preload.push(inflection.underscore(reflection.name()))
|
|
74
89
|
|
|
75
90
|
if (!(reflectionModelClassName in select)) select[reflectionModelClassName] = []
|
|
76
91
|
if (!select[reflectionModelClassName].includes("id")) select[reflectionModelClassName].push("id")
|
|
77
92
|
if (nameAttribute && !select[reflectionModelClassName].includes("name")) select[reflectionModelClassName].push("name")
|
|
93
|
+
|
|
94
|
+
// The foreign key is needed to look up any belongs-to-relationships
|
|
95
|
+
if (!modelClassSelect.includes(reflection.foreignKey())) modelClassSelect.push(reflection.foreignKey())
|
|
78
96
|
}
|
|
79
97
|
|
|
80
98
|
return {
|