alchemy-chimera 1.0.0 → 1.0.1

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,10 @@
1
+ ## 1.0.1 (2022-01-28)
2
+
3
+ * Allow setting a simple menu sidebar in the config
4
+ * Add simple notification after adding/saving
5
+ * Add page & window titles
6
+ * Improve edit buttons
7
+
1
8
  ## 1.0.0 (2021-09-12)
2
9
 
3
10
  * Use widgets to create the interface
@@ -0,0 +1,19 @@
1
+ hawkejs.scene.after({
2
+ type : 'set',
3
+ name : 'page-notification',
4
+ }, function onNotification(element, variables, block) {
5
+
6
+ let notification = element.querySelector('.notification');
7
+
8
+ if (!notification) {
9
+ return;
10
+ }
11
+
12
+ setTimeout(() => {
13
+ notification.classList.add('removing');
14
+
15
+ setTimeout(() => {
16
+ notification.remove();
17
+ }, 2500);
18
+ }, 4 * 1000);
19
+ });
@@ -14,6 +14,10 @@ body {
14
14
  --button-bg-hover-color: #e7e9f2;
15
15
  --button-text-color: #3699FF;
16
16
 
17
+ --notification-bg-color: #4a4e58;
18
+ --notification-text-color: #f4f5f9;
19
+ --notification-border-color: #dadee0;
20
+
17
21
  --color-title: #475466;
18
22
  --color-box-border: #DADEE0;
19
23
  --color-active: #3699FF;
@@ -35,6 +39,8 @@ body {
35
39
  text-align: center;
36
40
  border-radius: 2px;
37
41
  font-weight: 500;
42
+ cursor: pointer;
43
+ border: 1px solid;
38
44
 
39
45
  &:hover {
40
46
  background-color: var(--button-bg-hover-color);
@@ -156,6 +162,21 @@ alchemy-widgets-navigation {
156
162
  height: 2rem;
157
163
  }
158
164
 
165
+ .page-notification {
166
+ .notification {
167
+ border: 1px solid var(--notification-border-color);
168
+ background: var(--notification-bg-color);
169
+ color: var(--notification-text-color);
170
+ border-radius: 5px;
171
+ padding: 0.5rem 0.8rem;
172
+ }
173
+ }
174
+
175
+ .removing {
176
+ transition: opacity 2s;
177
+ opacity: 0;
178
+ }
179
+
159
180
  alchemy-table .aft-column-filters input {
160
181
  @extend .chimera-input-field;
161
182
  width: 100%;
@@ -234,4 +255,19 @@ alchemy-field {
234
255
  border: none;
235
256
  padding: 0;
236
257
  }
258
+ }
259
+
260
+ .aft-actions {
261
+ a {
262
+ color: var(--button-text-color);
263
+ background-color: var(--button-bg-color);
264
+ padding: 0.5rem;
265
+ border-radius: 6px;
266
+ margin: 0.2rem;
267
+ display: inline-block;
268
+
269
+ &:hover {
270
+ background-color: var(--button-bg-hover-color);
271
+ }
272
+ }
237
273
  }
@@ -7,12 +7,44 @@
7
7
  */
8
8
  const Editor = Function.inherits('Alchemy.Controller.Chimera', 'Editor');
9
9
 
10
+ /**
11
+ * Set the title
12
+ *
13
+ * @author Jelle De Loecker <jelle@elevenways.be>
14
+ * @since 1.0.1
15
+ * @version 1.0.1
16
+ *
17
+ * @param {String} title
18
+ */
19
+ Editor.setMethod(function setTitle(title) {
20
+
21
+ let window_title,
22
+ page_title;
23
+
24
+ if (alchemy.plugins.chimera.title) {
25
+ window_title = alchemy.plugins.chimera.title || '';
26
+
27
+ if (title && window_title) {
28
+ window_title += ' | ';
29
+ }
30
+ }
31
+
32
+ if (title) {
33
+ window_title += title;
34
+ }
35
+
36
+ page_title = title;
37
+
38
+ this.set('page_title', page_title);
39
+ this.set('window_title', window_title || page_title);
40
+ });
41
+
10
42
  /**
11
43
  * The index action
12
44
  *
13
45
  * @author Jelle De Loecker <jelle@elevenways.be>
14
46
  * @since 0.1.0
15
- * @version 1.0.0
47
+ * @version 1.0.1
16
48
  *
17
49
  * @param {Conduit} conduit
18
50
  * @param {String} model_name
@@ -23,7 +55,8 @@ Editor.setAction(function index(conduit, model_name) {
23
55
 
24
56
  let widget_config = model.chimera.getWidgetConfig('index', conduit);
25
57
 
26
- this.set('page_title', model_name.titleize());
58
+ this.setTitle(model_name.titleize());
59
+
27
60
  this.set('model_name', model_name);
28
61
 
29
62
  this.set('widget_config', widget_config);
@@ -36,7 +69,7 @@ Editor.setAction(function index(conduit, model_name) {
36
69
  *
37
70
  * @author Jelle De Loecker <jelle@elevenways.be>
38
71
  * @since 0.1.0
39
- * @version 1.0.0
72
+ * @version 1.0.1
40
73
  *
41
74
  * @param {Conduit} conduit
42
75
  * @param {String} model_name
@@ -56,7 +89,11 @@ Editor.setAction(async function add(conduit, model_name) {
56
89
  try {
57
90
  await record.save();
58
91
 
59
- let url = alchemy.routeUrl('Chimera.Editor#edit', {model: model_name, pk: record.$pk});
92
+ let url = alchemy.routeUrl('Chimera.Editor#edit', {
93
+ model: model_name,
94
+ pk: record.$pk,
95
+ message: 'added'
96
+ });
60
97
 
61
98
  return conduit.redirect(url);
62
99
  } catch (err) {
@@ -78,6 +115,7 @@ Editor.setAction(async function add(conduit, model_name) {
78
115
  widget_config.class_names.push('chimera-editor-widgets');
79
116
 
80
117
  this.set('widget_config', widget_config);
118
+ this.setTitle(model.constructor.title + ' Add');
81
119
 
82
120
  this.render('chimera/widgets');
83
121
  });
@@ -87,7 +125,7 @@ Editor.setAction(async function add(conduit, model_name) {
87
125
  *
88
126
  * @author Jelle De Loecker <jelle@elevenways.be>
89
127
  * @since 0.1.0
90
- * @version 1.0.0
128
+ * @version 1.0.1
91
129
  *
92
130
  * @param {Conduit} conduit
93
131
  * @param {String} model_name
@@ -100,6 +138,7 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
100
138
  model.translateItems = false;
101
139
 
102
140
  let record = await model.findByPk(pk_val);
141
+ let message_type = conduit.param('message');
103
142
 
104
143
  this.set('context_variables', {
105
144
  record : record
@@ -109,10 +148,9 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
109
148
 
110
149
  Object.assign(record, conduit.body[model_name]);
111
150
 
112
- console.log('Set data record of', record, conduit.body);
113
-
114
151
  try {
115
152
  await record.save();
153
+ message_type = 'saved';
116
154
  } catch (err) {
117
155
  // @TODO: set this in the context somehow?
118
156
  this.set('record_violations', err);
@@ -125,9 +163,18 @@ Editor.setAction(async function edit(conduit, model_name, pk_val) {
125
163
  widget_config.class_names = [];
126
164
  }
127
165
 
166
+ if (message_type) {
167
+ if (message_type == 'added') {
168
+ this.set('message', 'Record has been added');
169
+ } else if (message_type == 'saved') {
170
+ this.set('message', 'Record has been saved');
171
+ }
172
+ }
173
+
128
174
  widget_config.class_names.push('chimera-editor-widgets');
129
175
 
130
176
  this.set('widget_config', widget_config);
177
+ this.setTitle(model.constructor.title + ' Edit');
131
178
 
132
179
  this.render('chimera/widgets');
133
180
  });
@@ -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.0.0
29
+ * @version 1.0.1
30
30
  *
31
31
  * @param {Conduit} conduit
32
32
  */
@@ -35,20 +35,71 @@ ChimeraStatic.setAction(function sidebar(conduit) {
35
35
  let widgets = [],
36
36
  config;
37
37
 
38
- let models = Model.getAllChildren();
39
- models.sortByPath(1, 'model_name');
40
-
41
- for (let model of models) {
42
- widgets.push({
43
- type : 'link',
44
- config : {
45
- route : 'Chimera.Editor#index',
46
- parameters: [
47
- {name: 'model', value: model.type_name},
48
- ],
49
- content: model.title
38
+ if (Array.isArray(alchemy.plugins.chimera.sidebar_menu)) {
39
+
40
+ for (let entry of alchemy.plugins.chimera.sidebar_menu) {
41
+
42
+ if (!entry.model && !entry.href) {
43
+ continue;
44
+ }
45
+
46
+ let model,
47
+ title = entry.title;
48
+
49
+ if (entry.model) {
50
+ model = Model.get(entry.model);
51
+ }
52
+
53
+ if (!title) {
54
+ if (model) {
55
+ title = model.constructor.title;
56
+ }
57
+
58
+ if (!title && entry.href) {
59
+ title = entry.href;
60
+ }
50
61
  }
51
- });
62
+
63
+ if (entry.href) {
64
+ widgets.push({
65
+ type : 'link',
66
+ config : {
67
+ href : entry.href,
68
+ content: title
69
+ }
70
+ });
71
+ } else {
72
+
73
+ widgets.push({
74
+ type : 'link',
75
+ config : {
76
+ route : 'Chimera.Editor#index',
77
+ parameters: [
78
+ {name: 'model', value: model.constructor.type_name},
79
+ ],
80
+ content: title
81
+ }
82
+ });
83
+ }
84
+ }
85
+
86
+ } else {
87
+
88
+ let models = Model.getAllChildren();
89
+ models.sortByPath(1, 'model_name');
90
+
91
+ for (let model of models) {
92
+ widgets.push({
93
+ type : 'link',
94
+ config : {
95
+ route : 'Chimera.Editor#index',
96
+ parameters: [
97
+ {name: 'model', value: model.type_name},
98
+ ],
99
+ content: model.title
100
+ }
101
+ });
102
+ }
52
103
  }
53
104
 
54
105
  config = [
@@ -89,10 +89,13 @@ Config.setMethod(function getWidgetConfig(action, conduit) {
89
89
  let field;
90
90
 
91
91
  for (field of fieldset) {
92
+
92
93
  field_widgets.push({
93
94
  type : 'alchemy_field',
94
95
  config : {
95
- field : field.name,
96
+ field : field.name,
97
+ view : field.options.view,
98
+ widget_settings : field.options.widget_settings || {},
96
99
  }
97
100
  });
98
101
  }
@@ -100,7 +103,7 @@ Config.setMethod(function getWidgetConfig(action, conduit) {
100
103
  field_widgets.push({
101
104
  type : 'html',
102
105
  config : {
103
- html : '<button type="submit">Submit</button>'
106
+ html : '<button class="btn btn-submit" type="submit">Save</button>'
104
107
  }
105
108
  });
106
109
 
@@ -159,7 +162,5 @@ Config.setMethod(function getWidgetConfig(action, conduit) {
159
162
 
160
163
  result.widgets = widgets;
161
164
 
162
- console.log('Widget config', result, 'for', this);
163
-
164
165
  return result;
165
166
  });
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.0.0",
4
+ "version": "1.0.1",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -11,13 +11,13 @@
11
11
  ],
12
12
  "repository": "11ways/alchemy-chimera",
13
13
  "peerDependencies": {
14
- "alchemy-acl" : "~0.6.0",
14
+ "alchemy-acl" : "~0.7.0",
15
15
  "alchemy-menu" : "~0.6.0",
16
16
  "alchemymvc" : "~1.1.0",
17
17
  "alchemy-widget": "~0.1.0"
18
18
  },
19
19
  "license": "MIT",
20
20
  "engines": {
21
- "node" : ">=10.21.0"
21
+ "node" : ">=12.0.0"
22
22
  }
23
23
  }
@@ -1,4 +1,4 @@
1
- {% extend "layouts/chimera_body" %}
1
+ {% include "layouts/chimera_basics" %}
2
2
 
3
3
  {% block "main" %}
4
4
  <alchemy-widgets
@@ -3,6 +3,7 @@
3
3
  <head>
4
4
  <!-- This puts in all the required styles, scripts, ... -->
5
5
  <% this.foundation({protoblast: true}) %>
6
+ <% script('chimera/chimera') %>
6
7
  </head>
7
8
  <body>
8
9
  <!-- This is a block you can assign content to -->
@@ -1,4 +1,15 @@
1
1
  {% extend "layouts/chimera_body" %}
2
2
 
3
- <% console.log('Pagetitle:', page_title) %>
4
- {% block "page-title" %}{{ page_title }}{% /block %}
3
+ {% if page_title %}
4
+ {% block "page-title" %}{{ page_title }}{% /block %}
5
+ {% /if %}
6
+
7
+ {% if window_title %}
8
+ <% set_title(window_title) %>
9
+ {% elseif page_title %}
10
+ <% set_title(page_title) %>
11
+ {% /if %}
12
+
13
+ {% if message %}
14
+ {% block "page-notification" %}<span class="notification">{{ message }}</span>{% /block %}
15
+ {% /if %}
@@ -6,13 +6,14 @@
6
6
  <div class="chimera-wrapper">
7
7
  <div class="chimera-sidebar">
8
8
  <div class="chimera-page-header">
9
- Test
9
+
10
10
  </div>
11
11
  <%= Alchemy.segment('Chimera.Static#sidebar') %>
12
12
  </div>
13
13
  <div class="chimera-content">
14
14
  <div class="chimera-page-header">
15
15
  <div class="page-title" data-he-name="page-title"></div>
16
+ <div class="page-notification" data-he-name="page-notification"></div>
16
17
  <div class="page-actions" data-he-name="page-actions"></div>
17
18
  </div>
18
19
  <div data-he-name="main" class="chimera-main">