@raketa-cloud/admin 0.0.12 → 0.0.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-cloud/admin",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "main": "src/index.js",
5
5
  "scripts": {
6
6
  "dev": "npx tailwindcss -i ./src/styles/application.css -o ../../apps/admin/static/application.css --watch",
package/src/Adapter.js CHANGED
@@ -125,6 +125,7 @@ export default class Adapter {
125
125
 
126
126
  async renderLayout(assigns, body) {
127
127
  const layoutTemplate = `${currentPath}/views/layouts/application.ejs`;
128
+
128
129
  return await ejs.renderFile(layoutTemplate, {
129
130
  ...assigns,
130
131
  body,
@@ -84,113 +84,117 @@ export default class HonoAdapter extends Adapter {
84
84
  ]) {
85
85
  const method = this.getMethod(verb);
86
86
 
87
- [...Object.keys(this.globalConfig.i18n.locales), ""].forEach(
88
- (currentLocale) => {
89
- const completedPath = `/${currentLocale}${path}`;
90
-
91
- method(completedPath, async (routerCtx, next) => {
92
- const ctx = await this.createContext(
93
- routerCtx,
94
- next,
95
- verb,
96
- resource,
97
- action
98
- );
99
-
100
- ctx.locales = this.globalConfig.i18n.locales;
101
- ctx.defaultLocale = this.globalConfig.i18n.defaultLocale;
102
- ctx.locale = currentLocale;
103
-
104
- const _context = {
105
- locales: ctx.locales,
106
- locale: ctx.locale,
107
- defaultLocale: ctx.defaultLocale,
108
- path: ctx.req.path,
109
- query: ctx.query || {},
110
- };
111
-
112
- console.info(
113
- `\x1b[35m[${ctx.method}] ${ctx.rawPath}\x1b[0m -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`
114
- );
115
-
116
- const assigns = {
117
- beforeFilterAssigns: {},
118
- actionAssigns: {},
119
- afterFilterAssigns: {},
120
- };
121
-
122
- // Initialize global context
123
- ctx.initGlobalContext();
124
-
125
- // Process before filters
126
- if (before_filter) {
127
- const {
128
- redirect,
129
- json,
130
- assigns: beforeFilterAssigns = {},
131
- } = before_filter(ctx) || {};
132
-
133
- if (redirect) return routerCtx.redirect(redirect);
134
-
135
- if (json) {
136
- return routerCtx.json(json);
137
- }
138
-
139
- assigns.beforeFilterAssigns = beforeFilterAssigns;
140
- }
141
-
142
- // Process action
87
+ Object.keys(this.globalConfig.i18n.locales).forEach((currentLocale) => {
88
+ const completePath = `/${currentLocale}${path}`;
89
+
90
+ // A terrible, terrible hack...
91
+ // So how do we override for the entire handler.. do we need to completely override it, or just partially? Fun stuff?
92
+ this.router.router.routes = this.router.router.routes.filter((route) => {
93
+ return route[0] !== verb || route[1] !== completePath;
94
+ });
95
+
96
+ method(completePath, async (routerCtx, next) => {
97
+ const ctx = await this.createContext(
98
+ routerCtx,
99
+ next,
100
+ verb,
101
+ resource,
102
+ action
103
+ );
104
+
105
+ ctx.locales = this.globalConfig.i18n.locales;
106
+ ctx.defaultLocale = this.globalConfig.i18n.defaultLocale;
107
+ ctx.locale = currentLocale;
108
+
109
+ const _context = {
110
+ locales: ctx.locales,
111
+ locale: ctx.locale,
112
+ defaultLocale: ctx.defaultLocale,
113
+ path: ctx.req.path,
114
+ query: ctx.query || {},
115
+ };
116
+
117
+ console.info(
118
+ `\x1b[35m[${ctx.method}] ${ctx.rawPath}\x1b[0m -> ${resource}/${action} | ${JSON.stringify(ctx.params)}`
119
+ );
120
+
121
+ const assigns = {
122
+ beforeFilterAssigns: {},
123
+ actionAssigns: {},
124
+ afterFilterAssigns: {},
125
+ };
126
+
127
+ // Initialize global context
128
+ ctx.initGlobalContext();
129
+
130
+ // Process before filters
131
+ if (before_filter) {
143
132
  const {
144
- headers,
145
133
  redirect,
146
134
  json,
147
- assigns: actionAssigns = {},
148
- } = (await handler(ctx)) || {};
149
- assigns.actionAssigns = actionAssigns;
150
-
151
- this.applyHeaders(headers, routerCtx);
135
+ assigns: beforeFilterAssigns = {},
136
+ } = before_filter(ctx) || {};
152
137
 
153
138
  if (redirect) return routerCtx.redirect(redirect);
154
139
 
155
- // Process after filters
156
- if (after_filter) {
157
- const {
158
- redirect,
159
- json,
160
- assigns: afterFilterAssigns = {},
161
- } = after_filter(ctx) || {};
140
+ if (json) {
141
+ return routerCtx.json(json);
142
+ }
162
143
 
163
- if (redirect) return routerCtx.redirect(redirect);
144
+ assigns.beforeFilterAssigns = beforeFilterAssigns;
145
+ }
164
146
 
165
- if (json) {
166
- return routerCtx.json(json);
167
- }
147
+ // Process action
148
+ const {
149
+ headers,
150
+ redirect,
151
+ json,
152
+ assigns: actionAssigns = {},
153
+ } = (await handler(ctx)) || {};
154
+ assigns.actionAssigns = actionAssigns;
168
155
 
169
- assigns.afterFilterAssigns = afterFilterAssigns;
170
- }
156
+ this.applyHeaders(headers, routerCtx);
157
+
158
+ if (redirect) return routerCtx.redirect(redirect);
159
+
160
+ // Process after filters
161
+ if (after_filter) {
162
+ const {
163
+ redirect,
164
+ json,
165
+ assigns: afterFilterAssigns = {},
166
+ } = after_filter(ctx) || {};
171
167
 
172
- const fullAssigns = {
173
- ...ctx.assigns,
174
- ...assigns.beforeFilterAssigns,
175
- ...assigns.actionAssigns,
176
- ...assigns.afterFilterAssigns,
177
- _context: _context,
178
- };
168
+ if (redirect) return routerCtx.redirect(redirect);
179
169
 
180
170
  if (json) {
181
171
  return routerCtx.json(json);
182
172
  }
183
173
 
184
- const rendered = this.renderAction({
185
- views,
186
- action,
187
- assigns: fullAssigns,
188
- });
189
-
190
- return routerCtx.html(rendered);
174
+ assigns.afterFilterAssigns = afterFilterAssigns;
175
+ }
176
+
177
+ const fullAssigns = {
178
+ ...ctx.assigns,
179
+ ...assigns.beforeFilterAssigns,
180
+ ...assigns.actionAssigns,
181
+ ...assigns.afterFilterAssigns,
182
+ _context: _context,
183
+ };
184
+
185
+ if (json) {
186
+ return routerCtx.json(json);
187
+ }
188
+
189
+ const rendered = this.renderAction({
190
+ views,
191
+ action,
192
+ assigns: fullAssigns,
191
193
  });
192
- }
193
- );
194
+
195
+ return routerCtx.html(rendered);
196
+ });
197
+ });
194
198
  }
195
199
 
196
200
  routeCollection(mapping) {
@@ -37,4 +37,4 @@
37
37
  </div>
38
38
  </div>
39
39
  </div>
40
- </div>
40
+ </div>
@@ -39,4 +39,4 @@
39
39
  </div>
40
40
  </div>
41
41
  </div>
42
- </div>
42
+ </div>