alchemy-chimera 1.2.2 → 1.2.4

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.4 (2023-04-20)
2
+
3
+ * Add document watcher & toolbar manager support
4
+
5
+ ## 1.2.3 (2023-03-10)
6
+
7
+ * Add support for setting a record preview action per model
8
+ * Fix layout of page actions
9
+
1
10
  ## 1.2.2 (2023-02-26)
2
11
 
3
12
  * Fix default menu items not being rendered properly
@@ -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
 
@@ -209,6 +210,10 @@ body {
209
210
  display: block;
210
211
  font-size: 1.2rem;
211
212
  }
213
+
214
+ > al-widgets-column > [type="header"] h1 {
215
+ padding-top: 0;
216
+ }
212
217
  }
213
218
 
214
219
  al-widgets-navigation {
@@ -564,6 +569,17 @@ al-field[mode="inline"] {
564
569
  background: initial;
565
570
  }
566
571
  }
572
+
573
+ al-editor-toolbar {
574
+ width: 100%;
575
+ align-items: center;
576
+ justify-content: space-between;
577
+
578
+ [data-area="buttons"] {
579
+ display: flex;
580
+ gap: 1rem;
581
+ }
582
+ }
567
583
  }
568
584
 
569
585
  al-field {
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
 
@@ -13,4 +13,35 @@ let ChimeraController = Function.inherits('Alchemy.Controller', 'Alchemy.Control
13
13
  if (alchemy.plugins.chimera.theme) {
14
14
  this.view_render.setTheme(alchemy.plugins.chimera.theme);
15
15
  }
16
+ });
17
+
18
+ /**
19
+ * Do something before the action is executed
20
+ *
21
+ * @author Jelle De Loecker <jelle@elevenways.be>
22
+ * @since 1.2.4
23
+ * @version 1.2.4
24
+ */
25
+ ChimeraController.setMethod(function beforeAction() {
26
+ this.set('toolbar_manager', this.toolbar_manager);
27
+ this.toolbar_manager.queueModelFallback(this.conduit.params.model);
28
+ });
29
+
30
+ /**
31
+ * Get this client's toolbar manager
32
+ *
33
+ * @author Jelle De Loecker <jelle@elevenways.be>
34
+ * @since 1.2.4
35
+ * @version 1.2.4
36
+ *
37
+ * @return {Alchemy.Widget.EditorToolbarManager}
38
+ */
39
+ ChimeraController.enforceProperty(function toolbar_manager(new_value) {
40
+
41
+ if (!new_value && this.conduit) {
42
+ new_value = Classes.Alchemy.Widget.EditorToolbarManager.create(this.conduit);
43
+ new_value.scenario = 'chimera';
44
+ }
45
+
46
+ return new_value;
16
47
  });
@@ -12,7 +12,7 @@ const Editor = Function.inherits('Alchemy.Controller.Chimera', 'Editor');
12
12
  *
13
13
  * @author Jelle De Loecker <jelle@elevenways.be>
14
14
  * @since 1.0.1
15
- * @version 1.0.5
15
+ * @version 1.2.4
16
16
  *
17
17
  * @param {String} title
18
18
  */
@@ -39,6 +39,22 @@ Editor.setMethod(function setTitle(title) {
39
39
 
40
40
  this.set('page_title', page_title);
41
41
  this.set('window_title', window_title || page_title);
42
+ this.toolbar_manager.title = page_title;
43
+ });
44
+
45
+ /**
46
+ * Set the context document
47
+ *
48
+ * @author Jelle De Loecker <jelle@elevenways.be>
49
+ * @since 1.2.4
50
+ * @version 1.2.4
51
+ *
52
+ * @param {Document} doc
53
+ */
54
+ Editor.setMethod(function setContextDocument(doc) {
55
+ let document_watcher = this.toolbar_manager.setDocument(doc);
56
+ this.toolbar_manager.setModel(doc.$model_name);
57
+ document_watcher.addWatcher(this.conduit);
42
58
  });
43
59
 
44
60
  /**
@@ -117,7 +133,7 @@ Editor.setAction(async function add(conduit, model_name) {
117
133
  this.set('widget_config', widget_config);
118
134
  this.setTitle(model.constructor.title + ' Add');
119
135
 
120
- this.render('chimera/widgets');
136
+ this.render('chimera/editor/add');
121
137
  });
122
138
 
123
139
  /**
@@ -125,7 +141,7 @@ Editor.setAction(async function add(conduit, model_name) {
125
141
  *
126
142
  * @author Jelle De Loecker <jelle@elevenways.be>
127
143
  * @since 0.1.0
128
- * @version 1.2.2
144
+ * @version 1.2.4
129
145
  *
130
146
  * @param {Conduit} conduit
131
147
  * @param {String} model_name
@@ -181,10 +197,57 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
181
197
 
182
198
  widget_config.class_names.push('chimera-editor-widgets');
183
199
 
200
+ if (model.chimera.record_preview) {
201
+ this.set('add_preview_button', true);
202
+ }
203
+
204
+ this.setContextDocument(record);
205
+
206
+ this.set('record_pk', record.$pk);
207
+ this.set('model_name', model.model_name.toLowerCase());
184
208
  this.set('widget_config', widget_config);
185
209
  this.setTitle(model.constructor.title + ' Edit');
186
210
 
187
- this.render('chimera/widgets');
211
+ this.render('chimera/editor/edit');
212
+ });
213
+
214
+ /**
215
+ * The preview action
216
+ *
217
+ * @author Jelle De Loecker <jelle@elevenways.be>
218
+ * @since 1.2.3
219
+ * @version 1.2.3
220
+ *
221
+ * @param {Conduit} conduit
222
+ * @param {String} model_name
223
+ * @param {String} pk_val
224
+ */
225
+ Editor.setAction(async function preview(conduit, model_name, pk_val) {
226
+
227
+ let model = this.getModel(model_name);
228
+ const action_name = model?.chimera?.record_preview_action;
229
+
230
+ if (!action_name) {
231
+ return conduit.notFound();
232
+ }
233
+
234
+ let record = await model.findByPk(pk_val);
235
+
236
+ if (!record) {
237
+ return conduit.notFound();
238
+ }
239
+
240
+ const controller = Controller.get(model.chimera.record_preview_controller, conduit);
241
+
242
+ console.log(conduit.view_render.variables);
243
+
244
+ if (!controller) {
245
+ return conduit.notFound();
246
+ }
247
+
248
+ console.log('URLPARAMS:', controller.view_render?.variables?.__urlparams)
249
+
250
+ controller.doAction(action_name, [conduit, record]);
188
251
  });
189
252
 
190
253
  /**
@@ -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.2",
4
+ "version": "1.2.4",
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 %}
@@ -0,0 +1,8 @@
1
+ <a
2
+ !Route="Chimera.Editor#add"
3
+ #model={% model_name %}
4
+ class="btn"
5
+ >
6
+ <al-icon icon-name="plus"></al-icon>
7
+ {%t "new" model=model_name %}
8
+ </a>
@@ -0,0 +1,10 @@
1
+ <a
2
+ !Route="Chimera.Editor#edit"
3
+ +model={% model_name %}
4
+ +pk={% record_pk %}
5
+ class="btn"
6
+ target="_blank"
7
+ >
8
+ <al-icon icon-name="pencil"></al-icon>
9
+ {%t "edit" model=model_name in="backend" %}
10
+ </a>
@@ -0,0 +1,10 @@
1
+ <a
2
+ !Route="Chimera.Editor#preview"
3
+ +model={% model_name %}
4
+ +pk={% record_pk %}
5
+ class="btn"
6
+ target="_blank"
7
+ >
8
+ <al-icon icon-name="eye"></al-icon>
9
+ {%t "preview" model=model_name %}
10
+ </a>
@@ -12,9 +12,39 @@
12
12
  </div>
13
13
  <div class="chimera-content">
14
14
  <div class="chimera-page-header">
15
- <div class="page-title" data-he-name="page-title"></div>
16
- <div class="page-notification" data-he-name="page-notification"></div>
17
- <div class="page-actions" data-he-name="page-actions"></div>
15
+ <div hidden>
16
+ <div class="page-title" data-he-name="page-title"></div>
17
+ <div class="page-notification" data-he-name="page-notification"></div>
18
+ <div class="page-actions" data-he-name="page-actions"></div>
19
+ </div>
20
+
21
+ <al-editor-toolbar
22
+ #toolbar_manager={% toolbar_manager %}
23
+ >
24
+ <div slot="left">
25
+ <div class="page-title">
26
+ <span data-toolbar="title"></span>
27
+ </div>
28
+ </div>
29
+
30
+ <div slot="center">
31
+ <al-user-avatar-group
32
+ class="watchers"
33
+ ></al-user-avatar-group>
34
+ </div>
35
+
36
+ <div slot="right">
37
+ <div data-area="buttons">
38
+
39
+ </div>
40
+ </div>
41
+ </al-editor-toolbar>
42
+
43
+ {#
44
+ <al-user-avatar
45
+ #user={% Acl.data %}
46
+ ></al-user-avatar>
47
+ #}
18
48
  </div>
19
49
  <div data-he-name="main" class="chimera-main">
20
50