alchemy-chimera 1.2.1 → 1.2.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.2.3 (2023-03-10)
2
+
3
+ * Add support for setting a record preview action per model
4
+ * Fix layout of page actions
5
+
6
+ ## 1.2.2 (2023-02-26)
7
+
8
+ * Fix default menu items not being rendered properly
9
+
1
10
  ## 1.2.1 (2022-12-23)
2
11
 
3
12
  * Show field descriptions under the field title
@@ -172,7 +172,8 @@ body {
172
172
  }
173
173
 
174
174
  .page-actions {
175
-
175
+ display: flex;
176
+ gap: 1rem;
176
177
  }
177
178
  }
178
179
 
@@ -304,7 +305,6 @@ al-field-translatable {
304
305
 
305
306
  height: 3rem;
306
307
  display: flex;
307
- flex-flow: column;
308
308
  justify-content: center;
309
309
  align-items: center;
310
310
 
package/config/routes.js CHANGED
@@ -58,6 +58,26 @@ chimera_section.add({
58
58
  paths : '/api/content/sidebar',
59
59
  });
60
60
 
61
+ alchemy.sputnik.after('base_app', () => {
62
+
63
+ let prefixes = Prefix.all();
64
+ let preview_paths = {
65
+ '': '/editor/{model}/preview/{pk}',
66
+ };
67
+
68
+ for (let prefix in prefixes) {
69
+ preview_paths[prefix] = '/editor/{model}/preview/{pk}';
70
+ }
71
+
72
+ // Preview action
73
+ chimera_section.add({
74
+ name : 'Chimera.Editor#preview',
75
+ methods : ['get', 'post'],
76
+ paths : preview_paths,
77
+ breadcrumb : 'chimera.editor.{model}.preview.{pk}'
78
+ });
79
+ });
80
+
61
81
  return
62
82
  var chimera_menu;
63
83
 
@@ -117,7 +117,7 @@ Editor.setAction(async function add(conduit, model_name) {
117
117
  this.set('widget_config', widget_config);
118
118
  this.setTitle(model.constructor.title + ' Add');
119
119
 
120
- this.render('chimera/widgets');
120
+ this.render('chimera/editor/add');
121
121
  });
122
122
 
123
123
  /**
@@ -125,7 +125,7 @@ Editor.setAction(async function add(conduit, model_name) {
125
125
  *
126
126
  * @author Jelle De Loecker <jelle@elevenways.be>
127
127
  * @since 0.1.0
128
- * @version 1.0.5
128
+ * @version 1.2.3
129
129
  *
130
130
  * @param {Conduit} conduit
131
131
  * @param {String} model_name
@@ -138,6 +138,11 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
138
138
  model.translateItems = false;
139
139
 
140
140
  let record = await model.findByPk(pk_val);
141
+
142
+ if (!record) {
143
+ return conduit.notFound('Unable to find record with primary key "' + pk_val + '"');
144
+ }
145
+
141
146
  let message_type = conduit.param('message');
142
147
 
143
148
  record.keepPrivateFields();
@@ -176,10 +181,55 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
176
181
 
177
182
  widget_config.class_names.push('chimera-editor-widgets');
178
183
 
184
+ if (model.chimera.record_preview) {
185
+ this.set('add_preview_button', true);
186
+ }
187
+
188
+ this.set('record_pk', record.$pk);
189
+ this.set('model_name', model.model_name.toLowerCase());
179
190
  this.set('widget_config', widget_config);
180
191
  this.setTitle(model.constructor.title + ' Edit');
181
192
 
182
- this.render('chimera/widgets');
193
+ this.render('chimera/editor/edit');
194
+ });
195
+
196
+ /**
197
+ * The preview action
198
+ *
199
+ * @author Jelle De Loecker <jelle@elevenways.be>
200
+ * @since 1.2.3
201
+ * @version 1.2.3
202
+ *
203
+ * @param {Conduit} conduit
204
+ * @param {String} model_name
205
+ * @param {String} pk_val
206
+ */
207
+ Editor.setAction(async function preview(conduit, model_name, pk_val) {
208
+
209
+ let model = this.getModel(model_name);
210
+ const action_name = model?.chimera?.record_preview_action;
211
+
212
+ if (!action_name) {
213
+ return conduit.notFound();
214
+ }
215
+
216
+ let record = await model.findByPk(pk_val);
217
+
218
+ if (!record) {
219
+ return conduit.notFound();
220
+ }
221
+
222
+ const controller = Controller.get(model.chimera.record_preview_controller, conduit);
223
+
224
+ console.log(conduit.view_render.variables);
225
+
226
+ if (!controller) {
227
+ return conduit.notFound();
228
+ }
229
+
230
+ console.log('URLPARAMS:', controller.view_render?.variables?.__urlparams)
231
+
232
+ controller.doAction(action_name, [conduit, record]);
183
233
  });
184
234
 
185
235
  /**
@@ -26,7 +26,7 @@ ChimeraStatic.setAction(function dashboard(conduit) {
26
26
  *
27
27
  * @author Jelle De Loecker <jelle@elevenways.be>
28
28
  * @since 1.0.0
29
- * @version 1.2.1
29
+ * @version 1.2.2
30
30
  *
31
31
  * @param {Conduit} conduit
32
32
  */
@@ -95,16 +95,23 @@ ChimeraStatic.setAction(function sidebar(conduit) {
95
95
  models.sortByPath(1, 'model_name');
96
96
 
97
97
  for (let model of models) {
98
- widgets.push({
98
+ let entry = {
99
99
  type : 'link',
100
100
  config : {
101
- route : 'Chimera.Editor#index',
102
- parameters: [
103
- {name: 'model', value: model.type_name},
104
- ],
105
- content: model.title
101
+ link_type: 'route',
102
+ link_settings: {
103
+ route : 'Chimera.Editor#index',
104
+ parameters: [
105
+ {name: 'model', value: model.type_name},
106
+ ],
107
+ },
108
+ text: model.title
106
109
  }
107
- });
110
+ };
111
+
112
+ console.log(entry)
113
+
114
+ widgets.push(entry);
108
115
  }
109
116
  }
110
117
 
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @author Jelle De Loecker <jelle@elevenways.be>
9
9
  * @since 0.2.0
10
- * @version 1.0.0
10
+ * @version 1.2.3
11
11
  *
12
12
  * @param {Model} ModelClass
13
13
  */
@@ -18,6 +18,37 @@ const Config = Function.inherits('Alchemy.Base', 'Alchemy.Chimera', function Con
18
18
 
19
19
  // The different default field sets
20
20
  this.field_sets = {};
21
+
22
+ // The record preview action
23
+ this.record_preview = null;
24
+ this.record_preview_controller = null;
25
+ this.record_preview_action = null;
26
+ });
27
+
28
+ /**
29
+ * Set a record preview
30
+ *
31
+ * @deprecated
32
+ *
33
+ * @author Jelle De Loecker <jelle@elevenways.be>
34
+ * @since 1.2.3
35
+ * @version 1.2.3
36
+ *
37
+ * @param {String} target The controller#method to use
38
+ */
39
+ Config.setMethod(function setRecordPreview(target) {
40
+ this.record_preview = target;
41
+ this.record_preview_controller = null;
42
+ this.record_preview_action = null;
43
+
44
+ if (target && typeof target == 'string') {
45
+ let parts = target.split('#');
46
+
47
+ if (parts.length == 2) {
48
+ this.record_preview_controller = parts[0];
49
+ this.record_preview_action = parts[1];
50
+ }
51
+ }
21
52
  });
22
53
 
23
54
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "alchemy-chimera",
3
3
  "description": "Chimera plugin for Alchemy MVC",
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -0,0 +1,12 @@
1
+ {% include "layouts/chimera_basics" %}
2
+
3
+ {% block "page-actions" %}
4
+
5
+ {% /block %}
6
+
7
+ {% block "main" %}
8
+ <al-widgets
9
+ #context_variables={% context_variables %}
10
+ #value={% widget_config %}
11
+ ></al-widgets>
12
+ {% /block %}
@@ -0,0 +1,33 @@
1
+ {% include "layouts/chimera_basics" %}
2
+
3
+ {% block "page-actions" %}
4
+
5
+ {% if add_preview_button %}
6
+ <a
7
+ !Route="Chimera.Editor#preview"
8
+ +model={% model_name %}
9
+ +pk={% record_pk %}
10
+ class="btn"
11
+ target="_blank"
12
+ >
13
+ <al-icon icon-name="eye"></al-icon>
14
+ {%t "preview" model=model_name %}
15
+ </a>
16
+ {% /if %}
17
+
18
+ <a
19
+ !Route="Chimera.Editor#add"
20
+ #model={% model_name %}
21
+ class="btn"
22
+ >
23
+ <al-icon icon-name="plus"></al-icon>
24
+ {%t "new" model=model_name %}
25
+ </a>
26
+ {% /block %}
27
+
28
+ {% block "main" %}
29
+ <al-widgets
30
+ #context_variables={% context_variables %}
31
+ #value={% widget_config %}
32
+ ></al-widgets>
33
+ {% /block %}