@kaspernj/api-maker 1.0.222 → 1.0.223
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
|
@@ -71,10 +71,9 @@ export default class ApiMakerBootstrapAttributeRow extends React.PureComponent {
|
|
|
71
71
|
if (value instanceof Date) {
|
|
72
72
|
return strftime("%Y-%m-%d %H:%M", value)
|
|
73
73
|
} else if (typeof value === "boolean") {
|
|
74
|
-
if (value)
|
|
75
|
-
return I18n.t("js.shared.yes")
|
|
74
|
+
if (value) return I18n.t("js.shared.yes", {defaultValue: "Yes"})
|
|
76
75
|
|
|
77
|
-
return I18n.t("js.shared.no")
|
|
76
|
+
return I18n.t("js.shared.no", {defaultValue: "No"})
|
|
78
77
|
} else if (MoneyFormatter.isMoney(value)) {
|
|
79
78
|
return MoneyFormatter.format(value)
|
|
80
79
|
} else {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import {digg, digs} from "diggerize"
|
|
1
2
|
import EventUpdated from "./event-updated"
|
|
2
3
|
import Params from "./params.mjs"
|
|
3
4
|
import PropTypes from "prop-types"
|
|
4
5
|
import React from "react"
|
|
5
6
|
import withQueryParams from "on-location-changed/src/with-query-params"
|
|
6
7
|
|
|
7
|
-
export default (WrappedComponent,
|
|
8
|
+
export default (WrappedComponent, mdelClassArg, args = {}) => {
|
|
8
9
|
class ModelLoadWrapper extends React.PureComponent {
|
|
9
10
|
static propTypes = {
|
|
10
11
|
queryParams: PropTypes.object
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
modelClass = this.resolveModelClass(mdelClassArg)
|
|
15
|
+
camelizedLower = this.modelClass.modelName().camelizedLower()
|
|
16
|
+
paramsVariableName = `${this.modelClass.modelName().paramKey()}_id`
|
|
15
17
|
|
|
16
18
|
state = {
|
|
17
19
|
model: undefined,
|
|
@@ -19,6 +21,14 @@ export default (WrappedComponent, ModelClass, args = {}) => {
|
|
|
19
21
|
notFound: undefined
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
resolveModelClass(modelClassArg) {
|
|
25
|
+
const {queryParams} = digs(this.props, "queryParams")
|
|
26
|
+
|
|
27
|
+
if (typeof modelClassArg == "function") return modelClassArg({queryParams})
|
|
28
|
+
|
|
29
|
+
return modelClassArg
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
componentDidMount() {
|
|
23
33
|
this.loadModel()
|
|
24
34
|
}
|
|
@@ -50,6 +60,7 @@ export default (WrappedComponent, ModelClass, args = {}) => {
|
|
|
50
60
|
|
|
51
61
|
loadExistingModel = async () => {
|
|
52
62
|
const modelId = this.getModelId()
|
|
63
|
+
const ModelClass = digg(this, "modelClass")
|
|
53
64
|
const query = await ModelClass.ransack({id_eq: modelId})
|
|
54
65
|
|
|
55
66
|
if (args.abilities) query.abilities(args.abilities)
|
|
@@ -20,6 +20,26 @@ export default class ApiMakerSuperAdminConfigReader {
|
|
|
20
20
|
this.modelConfig = modelConfig
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
attributesToShow() {
|
|
24
|
+
const {modelConfig} = digs(this, "modelConfig")
|
|
25
|
+
|
|
26
|
+
if (modelConfig?.show?.attributesToShow) {
|
|
27
|
+
return modelConfig.show.attributesToShow()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return this.defaultAttributesToShow()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
defaultAttributesToShow() {
|
|
34
|
+
const attributesToShow = []
|
|
35
|
+
|
|
36
|
+
for (const column of this.defaultTableColumns()) {
|
|
37
|
+
attributesToShow.push(digg(column, "attribute"))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return attributesToShow
|
|
41
|
+
}
|
|
42
|
+
|
|
23
43
|
tableColumns() {
|
|
24
44
|
const {modelConfig} = digs(this, "modelConfig")
|
|
25
45
|
|
|
@@ -1,11 +1,49 @@
|
|
|
1
|
+
import AttributeRows from "../bootstrap/attribute-rows"
|
|
2
|
+
import ConfigReader from "./config-reader"
|
|
3
|
+
import {digg, digs} from "diggerize"
|
|
4
|
+
import modelLoadWrapper from "../model-load-wrapper"
|
|
1
5
|
import React from "react"
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
class ApiMakerSuperAdminShowPage extends React.PureComponent {
|
|
4
8
|
render() {
|
|
9
|
+
const attributes = this.attributes()
|
|
10
|
+
const model = this.model()
|
|
11
|
+
|
|
5
12
|
return (
|
|
6
13
|
<div className="super-admin--show-page">
|
|
7
|
-
|
|
14
|
+
{attributes && model &&
|
|
15
|
+
<AttributeRows attributes={attributes} model={model} />
|
|
16
|
+
}
|
|
8
17
|
</div>
|
|
9
18
|
)
|
|
10
19
|
}
|
|
20
|
+
|
|
21
|
+
attributes() {
|
|
22
|
+
const {modelClass} = digs(this.props, "modelClass")
|
|
23
|
+
const configReader = ConfigReader.forModel(modelClass)
|
|
24
|
+
|
|
25
|
+
return configReader.attributesToShow()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
model() {
|
|
29
|
+
const {modelClass} = digs(this.props, "modelClass")
|
|
30
|
+
const camelizedLower = digg(modelClass.modelClassData(), "camelizedLower")
|
|
31
|
+
|
|
32
|
+
return digg(this, "props", camelizedLower)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const modelClassResolver = ({queryParams}) => {
|
|
37
|
+
const modelClassName = digg(queryParams, "model")
|
|
38
|
+
const modelClass = digg(require("../models.mjs.erb"), modelClassName)
|
|
39
|
+
|
|
40
|
+
return modelClass
|
|
11
41
|
}
|
|
42
|
+
|
|
43
|
+
export default modelLoadWrapper(
|
|
44
|
+
ApiMakerSuperAdminShowPage,
|
|
45
|
+
modelClassResolver,
|
|
46
|
+
{
|
|
47
|
+
loadByQueryParam: ({props}) => props.queryParams.model_id
|
|
48
|
+
}
|
|
49
|
+
)
|