@kaspernj/api-maker 1.0.221 → 1.0.222
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 +1 -1
- package/src/base-model.mjs +4 -0
- package/src/super-admin/config-reader.jsx +53 -0
- package/src/super-admin/index-page/index.jsx +3 -17
- package/src/super-admin/index.jsx +1 -1
- package/src/super-admin/layout/index.jsx +2 -2
- package/src/super-admin/layout/menu/menu-content.jsx +1 -9
- package/src/super-admin/layout/no-access.jsx +1 -1
- package/src/super-admin/models.js +11 -0
- package/src/table/select-calculator.mjs +10 -0
package/package.json
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -94,6 +94,10 @@ class BaseModel {
|
|
|
94
94
|
return new ModelName({modelClassData: this.modelClassData()})
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
static primaryKey() {
|
|
98
|
+
return digg(this.modelClassData(), "primaryKey")
|
|
99
|
+
}
|
|
100
|
+
|
|
97
101
|
static ransack (query = {}) {
|
|
98
102
|
return new Collection({modelClass: this}, {ransack: query})
|
|
99
103
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {digg, digs} from "diggerize"
|
|
2
|
+
import inflection from "inflection"
|
|
3
|
+
|
|
4
|
+
export default class ApiMakerSuperAdminConfigReader {
|
|
5
|
+
static forModel(modelClass) {
|
|
6
|
+
const modelNameCamelized = digg(modelClass.modelClassData(), "nameDasherized")
|
|
7
|
+
let modelConfig
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
modelConfig = require(`super-admin/model-configs/${modelNameCamelized}`).default
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.log(`No model-config for ${modelClass.modelClassData().name}`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return new ApiMakerSuperAdminConfigReader(modelClass, modelConfig)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(modelClass, modelConfig) {
|
|
19
|
+
this.modelClass = modelClass
|
|
20
|
+
this.modelConfig = modelConfig
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tableColumns() {
|
|
24
|
+
const {modelConfig} = digs(this, "modelConfig")
|
|
25
|
+
|
|
26
|
+
if (modelConfig?.table?.columns) {
|
|
27
|
+
return modelConfig.table.columns()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return this.defaultTableColumns()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
defaultTableColumns() {
|
|
34
|
+
const {modelClass} = digs(this, "modelClass")
|
|
35
|
+
const attributes = modelClass.attributes()
|
|
36
|
+
const columns = []
|
|
37
|
+
|
|
38
|
+
for (const attribute of attributes) {
|
|
39
|
+
if (!attribute.isSelectedByDefault()) continue
|
|
40
|
+
|
|
41
|
+
const camelizedName = inflection.camelize(attribute.name(), true)
|
|
42
|
+
const column = {
|
|
43
|
+
attribute: camelizedName
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (attribute.isColumn()) column.sortKey = camelizedName
|
|
47
|
+
|
|
48
|
+
columns.push(column)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return columns
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import ConfigReader from "../config-reader"
|
|
1
2
|
import {digg, digs} from "diggerize"
|
|
2
|
-
import inflection from "inflection"
|
|
3
3
|
import Params from "../../params"
|
|
4
4
|
import PropTypes from "prop-types"
|
|
5
5
|
import React from "react"
|
|
@@ -27,23 +27,9 @@ export default class ApiMakerSuperAdminIndexPage extends React.PureComponent {
|
|
|
27
27
|
|
|
28
28
|
columns = () => {
|
|
29
29
|
const {modelClass} = digs(this.props, "modelClass")
|
|
30
|
-
const
|
|
31
|
-
const columns = []
|
|
30
|
+
const configReader = ConfigReader.forModel(modelClass)
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
if (!attribute.isSelectedByDefault()) continue
|
|
35
|
-
|
|
36
|
-
const camelizedName = inflection.camelize(attribute.name(), true)
|
|
37
|
-
const column = {
|
|
38
|
-
attribute: camelizedName
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (attribute.isColumn()) column.sortKey = camelizedName
|
|
42
|
-
|
|
43
|
-
columns.push(column)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return columns
|
|
32
|
+
return configReader.tableColumns()
|
|
47
33
|
}
|
|
48
34
|
|
|
49
35
|
viewModelPath = (args) => {
|
|
@@ -20,7 +20,7 @@ class ApiMakerSuperAdmin extends React.PureComponent {
|
|
|
20
20
|
if (queryParams.model) modelClass = modelsModule[queryParams.model]
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<Layout>
|
|
23
|
+
<Layout headerTitle={modelClass?.modelName()?.human({count: 2})}>
|
|
24
24
|
{pageToShow == "index" &&
|
|
25
25
|
<IndexPage
|
|
26
26
|
currentUser={currentUser}
|
|
@@ -81,14 +81,14 @@ class ApiMakerSuperAdminLayout extends React.PureComponent {
|
|
|
81
81
|
{currentUser &&
|
|
82
82
|
<>
|
|
83
83
|
<div className="mb-4">
|
|
84
|
-
{I18n.t("js.api_maker.super_admin.layout.try_signing_out_and_in_with_a_different_user")}
|
|
84
|
+
{I18n.t("js.api_maker.super_admin.layout.try_signing_out_and_in_with_a_different_user", {defaultValue: "Try signing in with a different user."})}
|
|
85
85
|
</div>
|
|
86
86
|
</>
|
|
87
87
|
}
|
|
88
88
|
{!currentUser &&
|
|
89
89
|
<>
|
|
90
90
|
<div className="mb-4">
|
|
91
|
-
{I18n.t("js.api_maker.super_admin.layout.try_signing_in")}
|
|
91
|
+
{I18n.t("js.api_maker.super_admin.layout.try_signing_in", {defaultValue: "Try signing in."})}
|
|
92
92
|
</div>
|
|
93
93
|
</>
|
|
94
94
|
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import CanCanLoader from "@kaspernj/api-maker/src/can-can-loader"
|
|
2
2
|
import {digg, digs} from "diggerize"
|
|
3
3
|
import MenuItem from "./menu-item"
|
|
4
|
+
import models from "../../models"
|
|
4
5
|
import Params from "../../../params"
|
|
5
6
|
import PropTypes from "prop-types"
|
|
6
7
|
import PropTypesExact from "prop-types-exact"
|
|
7
|
-
import * as modelsModule from "@kaspernj/api-maker/src/models.mjs.erb"
|
|
8
|
-
|
|
9
|
-
const models = []
|
|
10
|
-
|
|
11
|
-
for (const modelKey of Object.keys(modelsModule)) {
|
|
12
|
-
const model = modelsModule[modelKey]
|
|
13
|
-
|
|
14
|
-
models.push(model)
|
|
15
|
-
}
|
|
16
8
|
|
|
17
9
|
const abilities = []
|
|
18
10
|
|
|
@@ -7,7 +7,7 @@ class ComponentsAdminLayoutNoAccess extends React.PureComponent {
|
|
|
7
7
|
className="components--admin--layout-no-access"
|
|
8
8
|
data-user-roles={currentUser?.userRoles()?.loaded()?.map((userRole) => userRole.role()?.identifier()).join(", ")}
|
|
9
9
|
>
|
|
10
|
-
{I18n.t("js.api_maker.super_admin.layout.no_access.you_dont_have_no_access_to_this_page")}
|
|
10
|
+
{I18n.t("js.api_maker.super_admin.layout.no_access.you_dont_have_no_access_to_this_page", {defaultValue: "You don't have access to this page."})}
|
|
11
11
|
</div>
|
|
12
12
|
)
|
|
13
13
|
}
|
|
@@ -12,6 +12,16 @@ class SelectCalculator {
|
|
|
12
12
|
const select = this.table.props.select || {}
|
|
13
13
|
const {preparedColumns} = digs(this.table.shape, "preparedColumns")
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
// Ensure the primary key column is loader for the primary model class
|
|
17
|
+
const className = digg(modelClass.modelClassData(), "className")
|
|
18
|
+
const primaryKeyColumnName = modelClass.primaryKey()
|
|
19
|
+
|
|
20
|
+
if (!(className in select)) select[className] = []
|
|
21
|
+
if (!select[className].includes(primaryKeyColumnName)) select[className].push(primaryKeyColumnName)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// Ensure columns used for columns are loaded
|
|
15
25
|
for (const preparedColumn of preparedColumns) {
|
|
16
26
|
const {column} = digs(preparedColumn, "column")
|
|
17
27
|
|