@kaspernj/api-maker 1.0.217 → 1.0.218

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
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.217",
19
+ "version": "1.0.218",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -1,4 +1,5 @@
1
1
  import Config from "./config.mjs"
2
+ import inflection from "inflection"
2
3
 
3
4
  export default class ModelName {
4
5
  constructor(data) {
@@ -23,8 +24,11 @@ export default class ModelName {
23
24
  }
24
25
 
25
26
  const key = `activerecord.models.${this.data.modelClassData.i18nKey}.${countKey}`
27
+ let defaultModelName = this.data.modelClassData.name
26
28
 
27
- return Config.getI18n().t(key)
29
+ if (args?.count > 1) defaultModelName = inflection.pluralize(defaultModelName)
30
+
31
+ return Config.getI18n().t(key, {defaultValue: defaultModelName})
28
32
  }
29
33
 
30
34
  paramKey() {
package/src/params.mjs CHANGED
@@ -15,6 +15,13 @@ export default class Params {
15
15
  return incorporator.merge()
16
16
  }
17
17
 
18
+ static withParams (params, opts = {}) {
19
+ const newParams = qs.stringify(params)
20
+ const newPath = `${location.pathname}?${newParams}`
21
+
22
+ return newPath
23
+ }
24
+
18
25
  static changeParams (given, opts = {}) {
19
26
  const params = Params.change(given)
20
27
  const newParams = qs.stringify(params)
@@ -0,0 +1,44 @@
1
+ import {digg, digs} from "diggerize"
2
+ import Params from "../../params"
3
+ import Table from "../../table/table"
4
+
5
+ export default class ApiMakerSuperAdminIndexPage extends React.PureComponent {
6
+ static propTypes = {
7
+ currentUser: PropTypes.object,
8
+ modelClass: PropTypes.func.isRequired,
9
+ queryParams: PropTypes.object.isRequired
10
+ }
11
+
12
+ render() {
13
+ const {currentUser, modelClass} = digs(this.props, "currentUser", "modelClass")
14
+
15
+ return (
16
+ <div>
17
+ <Table
18
+ columns={digg(this, "columns")}
19
+ currentUser={currentUser}
20
+ modelClass={modelClass}
21
+ viewModelPath={digg(this, "viewModelPath")}
22
+ />
23
+ </div>
24
+ )
25
+ }
26
+
27
+ columns = () => {
28
+ return [
29
+
30
+ ]
31
+ }
32
+
33
+ viewModelPath = (args) => {
34
+ const argName = digg(this.props.modelClass.modelClassData(), "camelizedLower")
35
+ const model = digg(args, argName)
36
+
37
+ console.log({args, model})
38
+
39
+ return Params.withParams({
40
+ model: this.props.modelClass.modelClassData().name,
41
+ model_id: model.primaryKey()
42
+ })
43
+ }
44
+ }
@@ -1,11 +1,46 @@
1
+ import {digs} from "diggerize"
2
+ import IndexPage from "./index-page"
1
3
  import Layout from "./layout"
4
+ import * as modelsModule from "@kaspernj/api-maker/src/models.mjs.erb"
5
+ import ShowPage from "./show-page"
6
+ import withQueryParams from "on-location-changed/src/with-query-params"
7
+
8
+ class ApiMakerSuperAdmin extends React.PureComponent {
9
+ static propTypes = {
10
+ currentUser: PropTypes.object
11
+ }
2
12
 
3
- export default class ApiMakerSuperAdmin extends React.PureComponent {
4
13
  render() {
14
+ const {currentUser} = this.props
15
+ const {queryParams} = digs(this.props, "queryParams")
16
+ const pageToShow = this.pageToShow()
17
+ let modelClass
18
+
19
+ if (queryParams.model) modelClass = modelsModule[queryParams.model]
20
+
5
21
  return (
6
22
  <Layout>
7
- stub
23
+ {pageToShow == "index" &&
24
+ <IndexPage currentUser={currentUser} modelClass={modelClass} queryParams={queryParams} />
25
+ }
26
+ {pageToShow == "show" &&
27
+ <ShowPage modelClass={modelClass} modelId={queryParams.modelId} />
28
+ }
8
29
  </Layout>
9
30
  )
10
31
  }
32
+
33
+ pageToShow() {
34
+ const {queryParams} = digs(this.props, "queryParams")
35
+
36
+ if (queryParams.model && queryParams.model_id) {
37
+ return "show"
38
+ } else if (queryParams.model) {
39
+ return "index"
40
+ }
41
+
42
+ return "welcome"
43
+ }
11
44
  }
45
+
46
+ export default withQueryParams(ApiMakerSuperAdmin)
@@ -1,16 +1,23 @@
1
1
  import CanCanLoader from "@kaspernj/api-maker/src/can-can-loader"
2
2
  import MenuItem from "components/admin/layout/menu/menu-item"
3
+ import Params from "../../../params"
4
+ import * as modelsModule from "@kaspernj/api-maker/src/models.mjs.erb"
3
5
 
4
- const abilities = [
5
- [CheckIn, ["index"]],
6
- [ClassStep, ["index"]],
7
- [ScoreFactor, ["index"]],
8
- [ScoreFactorGroup, ["index"]],
9
- [School, ["index"]],
10
- [SchoolClass, ["index"]],
11
- [Survey, ["index"]],
12
- [User, ["index"]]
13
- ]
6
+ const models = []
7
+
8
+ for (const modelKey of Object.keys(modelsModule)) {
9
+ const model = modelsModule[modelKey]
10
+
11
+ models.push(model)
12
+ }
13
+
14
+ const abilities = []
15
+
16
+ for (const model of models) {
17
+ abilities.push(
18
+ [model, ["index"]]
19
+ )
20
+ }
14
21
 
15
22
  export default class ComponentsAdminLayoutMenuContent extends BaseComponent {
16
23
  static propTypes = PropTypesExact({
@@ -28,79 +35,21 @@ export default class ComponentsAdminLayoutMenuContent extends BaseComponent {
28
35
  return (
29
36
  <>
30
37
  <CanCanLoader abilities={abilities} component={this} />
31
- {canCan?.can("index", CheckIn) &&
38
+ {this.sortedModels().map((model) => canCan?.can("index", model) &&
32
39
  <MenuItem
33
40
  active={active}
34
41
  icon="sitemap"
35
42
  identifier="check-ins"
36
- label={CheckIn.modelName().human({count: 2})}
37
- to={Routes.adminCheckInsPath()}
38
- />
39
- }
40
- {canCan?.can("index", ClassStep) &&
41
- <MenuItem
42
- active={active}
43
- icon="sitemap"
44
- identifier="class-steps"
45
- label={ClassStep.modelName().human({count: 2})}
46
- to={Routes.adminClassStepsPath()}
47
- />
48
- }
49
- {canCan?.can("index", School) &&
50
- <MenuItem
51
- active={active}
52
- icon="sitemap"
53
- identifier="schools"
54
- label={School.modelName().human({count: 2})}
55
- to={Routes.adminSchoolsPath()}
56
- />
57
- }
58
- {canCan?.can("index", SchoolClass) &&
59
- <MenuItem
60
- active={active}
61
- icon="sitemap"
62
- identifier="school-classes"
63
- label={SchoolClass.modelName().human({count: 2})}
64
- to={Routes.adminSchoolClassesPath()}
65
- />
66
- }
67
- {canCan?.can("index", ScoreFactor) &&
68
- <MenuItem
69
- active={active}
70
- icon="list-ol"
71
- identifier="score-factors"
72
- label={ScoreFactor.modelName().human({count: 2})}
73
- to={Routes.adminScoreFactorsPath()}
74
- />
75
- }
76
- {canCan?.can("index", ScoreFactorGroup) &&
77
- <MenuItem
78
- active={active}
79
- icon="list-ol"
80
- identifier="score-factor-groups"
81
- label={ScoreFactorGroup.modelName().human({count: 2})}
82
- to={Routes.adminScoreFactorGroupsPath()}
43
+ label={model.modelName().human({count: 2})}
44
+ key={model.modelClassData().name}
45
+ to={Params.withParams({model: model.modelClassData().name})}
83
46
  />
84
- }
85
- {canCan?.can("index", Survey) &&
86
- <MenuItem
87
- active={active}
88
- icon="list-ol"
89
- identifier="surveys"
90
- label={Survey.modelName().human({count: 2})}
91
- to={Routes.adminSurveysPath()}
92
- />
93
- }
94
- {canCan?.can("index", User) &&
95
- <MenuItem
96
- active={active}
97
- icon="users"
98
- identifier="users"
99
- label={User.modelName().human({count: 2})}
100
- to={Routes.adminUsersPath()}
101
- />
102
- }
47
+ )}
103
48
  </>
104
49
  )
105
50
  }
51
+
52
+ sortedModels() {
53
+ return models.sort((a, b) => a.modelName().human({count: 2}).toLowerCase().localeCompare(b.modelName().human({count: 2}).toLowerCase()))
54
+ }
106
55
  }
@@ -0,0 +1,16 @@
1
+ class ComponentsAdminLayoutNoAccess extends BaseComponent {
2
+ render() {
3
+ const {currentUser} = digs(this.props, "currentUser")
4
+
5
+ return (
6
+ <div
7
+ className="components--admin--layout-no-access"
8
+ data-user-roles={currentUser?.userRoles()?.loaded()?.map((userRole) => userRole.role()?.identifier()).join(", ")}
9
+ >
10
+ {I18n.t("js.components.app_layout.no_access.you_dont_have_no_access_to_this_page")}
11
+ </div>
12
+ )
13
+ }
14
+ }
15
+
16
+ export default withCurrentUser(ComponentsAdminLayoutNoAccess)
@@ -0,0 +1,9 @@
1
+ export default class ApiMakerSuperAdminShowPage extends React.PureComponent {
2
+ render() {
3
+ return (
4
+ <div>
5
+ show page
6
+ </div>
7
+ )
8
+ }
9
+ }