alchemymvc 1.2.7 → 1.3.0

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.
Files changed (35) hide show
  1. package/lib/app/behaviour/sluggable_behaviour.js +4 -2
  2. package/lib/app/conduit/loopback_conduit.js +2 -2
  3. package/lib/app/controller/alchemy_info_controller.js +5 -5
  4. package/lib/app/helper/router_helper.js +82 -17
  5. package/lib/app/helper_controller/controller.js +45 -30
  6. package/lib/app/helper_datasource/00-nosql_datasource.js +44 -10
  7. package/lib/app/helper_field/enum_field.js +4 -4
  8. package/lib/app/helper_field/schema_field.js +6 -6
  9. package/lib/app/helper_model/document.js +41 -10
  10. package/lib/app/helper_model/field_set.js +11 -0
  11. package/lib/app/helper_model/model.js +35 -10
  12. package/lib/app/view/alchemy/{info.ejs → info.hwk} +43 -38
  13. package/lib/bootstrap.js +1 -0
  14. package/lib/class/conduit.js +231 -244
  15. package/lib/class/datasource.js +6 -2
  16. package/lib/class/document.js +3 -3
  17. package/lib/class/field.js +13 -0
  18. package/lib/class/inode.js +27 -0
  19. package/lib/class/inode_file.js +204 -4
  20. package/lib/class/model.js +4 -4
  21. package/lib/class/path_definition.js +76 -120
  22. package/lib/class/path_param_definition.js +202 -0
  23. package/lib/class/route.js +176 -32
  24. package/lib/class/router.js +17 -3
  25. package/lib/class/schema.js +11 -11
  26. package/lib/class/schema_client.js +52 -19
  27. package/lib/class/sitemap.js +341 -0
  28. package/lib/core/base.js +6 -2
  29. package/lib/core/client_alchemy.js +76 -7
  30. package/lib/core/client_base.js +16 -10
  31. package/lib/core/middleware.js +56 -45
  32. package/lib/init/alchemy.js +12 -9
  33. package/lib/init/constants.js +11 -0
  34. package/lib/init/functions.js +134 -83
  35. package/package.json +5 -5
@@ -142,6 +142,19 @@ Model.setProperty(function datasource() {
142
142
  return fallback_datasource;
143
143
  });
144
144
 
145
+ /**
146
+ * Does this model have translatable fields?
147
+ *
148
+ * @author Jelle De Loecker <jelle@elevenways.be>
149
+ * @since 1.3.0
150
+ * @version 1.3.0
151
+ *
152
+ * @type {Boolean}
153
+ */
154
+ Model.setProperty(function has_translatable_fields() {
155
+ return this.schema.has_translatable_fields;
156
+ });
157
+
145
158
  /**
146
159
  * The conduit
147
160
  *
@@ -349,7 +362,7 @@ Model.setProperty(function name() {
349
362
  *
350
363
  * @author Jelle De Loecker <jelle@develry.be>
351
364
  * @since 1.1.0
352
- * @version 1.1.0
365
+ * @version 1.3.0
353
366
  *
354
367
  * @param {Object} options
355
368
  */
@@ -371,7 +384,7 @@ Model.setMethod(function init(options) {
371
384
  }
372
385
 
373
386
  // Initialize behaviours
374
- if (this.schema && this.schema.hasBehaviours && this.initBehaviours) {
387
+ if (this.schema && this.schema.has_behaviours && this.initBehaviours) {
375
388
  this.initBehaviours();
376
389
  }
377
390
  });
@@ -568,7 +581,7 @@ Model.setMethod(function getAliasModel(alias) {
568
581
  *
569
582
  * @author Jelle De Loecker <jelle@develry.be>
570
583
  * @since 0.0.1
571
- * @version 1.2.5
584
+ * @version 1.3.0
572
585
  *
573
586
  * @param {String} type The type of find (first, all)
574
587
  * @param {Criteria} criteria The criteria object
@@ -626,10 +639,17 @@ Model.setMethod(function find(type, criteria, callback) {
626
639
  return pledge;
627
640
  }
628
641
 
642
+ if (this.conduit) {
643
+ criteria.conduit = this.conduit;
644
+ }
645
+
646
+ if (!criteria.options.locale && this.conduit) {
647
+ criteria.setOption('locale', this.conduit.prefix);
648
+ }
649
+
629
650
  let that = this,
630
651
  available,
631
652
  records,
632
- query,
633
653
  Type;
634
654
 
635
655
  // The criteria instance has to know about the model
@@ -1310,8 +1330,7 @@ Model.setMethod(function save(data, _options, _callback) {
1310
1330
  return iter.hasNext();
1311
1331
  }, function saveData(next) {
1312
1332
 
1313
- var document = iter.next().value,
1314
- temp;
1333
+ var document = iter.next().value;
1315
1334
 
1316
1335
  // Skip invalid items
1317
1336
  if (!document) {
@@ -1360,9 +1379,9 @@ Model.setMethod(function save(data, _options, _callback) {
1360
1379
  * Create a new document.
1361
1380
  * If data is given, the document is populated
1362
1381
  *
1363
- * @author Jelle De Loecker <jelle@develry.be>
1382
+ * @author Jelle De Loecker <jelle@elevenways.be>
1364
1383
  * @since 0.2.0
1365
- * @version 1.1.0
1384
+ * @version 1.3.0
1366
1385
  *
1367
1386
  * @param {Object} data Optional data
1368
1387
  * @param {Object} options
@@ -1371,13 +1390,15 @@ Model.setMethod(function save(data, _options, _callback) {
1371
1390
  */
1372
1391
  Model.setMethod(function createDocument(data, options) {
1373
1392
 
1374
- var doc;
1393
+ let original_record;
1375
1394
 
1376
1395
  if (!options) {
1377
1396
  options = {};
1378
1397
  }
1379
1398
 
1380
1399
  if (data && this.constructor.Document.isDocument(data)) {
1400
+ original_record = data.$attributes.original_record;
1401
+
1381
1402
  data = {
1382
1403
  [data.$model_alias] : data.$main,
1383
1404
  };
@@ -1385,7 +1406,11 @@ Model.setMethod(function createDocument(data, options) {
1385
1406
 
1386
1407
  options.model = this;
1387
1408
 
1388
- doc = new this.constructor.Document(data, options);
1409
+ let doc = new this.constructor.Document(data, options);
1410
+
1411
+ if (original_record) {
1412
+ doc.$attributes.original_record = original_record;
1413
+ }
1389
1414
 
1390
1415
  return doc;
1391
1416
  });
@@ -11,7 +11,7 @@
11
11
  <header>
12
12
  <div class="header-image">
13
13
  <img class="alchemy-logo" src="/alchemy-logo.png">
14
- <h1 class="alchemy-name">Alchemy<br>v<%= versions.alchemy %></h1>
14
+ <h1 class="alchemy-name">Alchemy<br>v{{ versions.alchemy }}</h1>
15
15
  </div>
16
16
  <div class="content">
17
17
 
@@ -20,22 +20,22 @@
20
20
  <div class="row">
21
21
  <article class="engine col">
22
22
  <span>You are running</span>
23
- <span class="engine-name"><%= engine %></span>
23
+ <span class="engine-name">{{ engine }}</span>
24
24
  <span>version</span>
25
- <span class="engine-version"><%= versions.node %></span>
25
+ <span class="engine-version">{{ versions.node }}</span>
26
26
  </article>
27
27
 
28
28
  <article class="modules col">
29
29
  <h1>Modules</h1>
30
30
  <div class="table-wrap">
31
31
  <table>
32
- <% modules.forEach(function eachModule(module) { %>
32
+ {% each modules as module %}
33
33
  <tr class=<% module.failed ? 'failed' : '' %>>
34
- <td class="package-name"><%= module.name %></td>
35
- <td class="package-version"><%= module.package ? module.package.version : '' %></td>
36
- <td class="package-description"><%= module.package ? module.package.description : '' %></td>
34
+ <td class="package-name">{{ module.name }}</td>
35
+ <td class="package-version">{{ module.package.version }}</td>
36
+ <td class="package-description">{{ module.package.description }}</td>
37
37
  </tr>
38
- <% }) %>
38
+ {% /each %}
39
39
  </table>
40
40
  </div>
41
41
  </article>
@@ -43,15 +43,20 @@
43
43
  <article class="datasources col">
44
44
  <h1>Datasources</h1>
45
45
  <ul class="checklist">
46
- <% Object.each(data_sources, function eachDatasource(datasource, key) { %>
47
- <% if (datasource.error) { %>
48
- <li class="failed">Could not connect to
49
- <% } else { %>
50
- <li class="success">Connected to
51
- <% } %>
52
- <%= datasource.type %> <strong><%= key %></strong
53
- </li>
54
- <% }) %>
46
+ {% each data_sources as key, datasource %}
47
+ <li>
48
+ {% if datasource.error %}
49
+ {% $0.classList.add('failed') %}
50
+ Could not connect to
51
+ {% else %}
52
+ {% $0.classList.add('success') %}
53
+ Connected to
54
+ {% /if %}
55
+
56
+ {{ datasource.type }}
57
+ <strong>{{ key }}</strong>
58
+ </li>
59
+ {% /each %}
55
60
  </ul>
56
61
  </article>
57
62
  </div>
@@ -60,9 +65,9 @@
60
65
  <article class="plugins col">
61
66
  <h1>Plugins</h1>
62
67
  <ul>
63
- <% plugins.forEach(function eachPlugin(plugin) { %>
64
- <li><%= plugin %></li>
65
- <% }) %>
68
+ {% each plugins as plugin %}
69
+ <li>{{ plugin }}</li>
70
+ {% /each %}
66
71
  </ul>
67
72
  </article>
68
73
 
@@ -79,79 +84,79 @@
79
84
 
80
85
  <tr>
81
86
  <td>cache</td>
82
- <td><%= settings.cache %></td>
87
+ <td>{{ settings.cache }}</td>
83
88
  <td>Cache has been <%= ['disabled', 'enabled'][Number(!!settings.cache)] %></td>
84
89
  </tr>
85
90
 
86
91
  <tr>
87
92
  <td>compression</td>
88
- <td><%= settings.compression %></td>
93
+ <td>{{ settings.compression }}</td>
89
94
  <td>Compression has been <%= ['disabled', 'enabled'][Number(!!settings.compression)] %></td>
90
95
  </tr>
91
96
 
92
97
  <tr>
93
98
  <td>cookies</td>
94
- <td><%= settings.cookies %></td>
99
+ <td>{{ settings.cookies }}</td>
95
100
  <td>Cookies have been <%= ['disabled', 'enabled'][Number(!!settings.cookies)] %></td>
96
101
  </tr>
97
102
 
98
103
  <tr>
99
104
  <td>debug</td>
100
- <td><%= settings.debug %></td>
105
+ <td>{{ settings.debug }}</td>
101
106
  <td>Debugging has been <%= ['disabled', 'enabled'][Number(!!settings.debug)] %></td>
102
107
  </tr>
103
108
 
104
109
  <tr>
105
110
  <td>minify_js</td>
106
- <td><%= settings.minify_js %></td>
111
+ <td>{{ settings.minify_js }}</td>
107
112
  <td>JavaScript minification has been <%= ['disabled', 'enabled'][Number(!!settings.minify_js)] %></td>
108
113
  </tr>
109
114
 
110
115
  <tr>
111
116
  <td>model_query_cache_duration</td>
112
- <td><%= settings.model_query_cache_duration %></td>
117
+ <td>{{ settings.model_query_cache_duration }}</td>
113
118
  <td>
114
- <% if (settings.model_query_cache_duration) { %>
115
- Database query results are cached for <%= settings.model_query_cache_duration %>
116
- <% } else { %>
119
+ {% if settings.model_query_cache_duration %}
120
+ Database query results are cached for {{ settings.model_query_cache_duration }}
121
+ {% else %}
117
122
  Database query results are not cached
118
- <% } %>
123
+ {% /else %}
119
124
  </td>
120
125
  </tr>
121
126
 
122
127
  <tr>
123
128
  <td>port</td>
124
- <td><%= settings.port %></td>
125
- <td>The server runs on port <%= settings.port %></td>
129
+ <td>{{ settings.port }}</td>
130
+ <td>The server runs on port {{ settings.port }}</td>
126
131
  </tr>
127
132
 
128
133
  <tr>
129
134
  <td>kill_on_file_change</td>
130
- <td><%= settings.kill_on_file_change %></td>
135
+ <td>{{ settings.kill_on_file_change }}</td>
131
136
  <td>The process <%= ['will', 'won\'t'][Number(!settings.kill_on_file_change)] %> be killed when a node.js file changes</td>
132
137
  </tr>
133
138
 
134
139
  <tr>
135
140
  <td>kill_extensions</td>
136
- <td><%= settings.kill_extensions %></td>
141
+ <td>{{ settings.kill_extensions }}</td>
137
142
  <td></td>
138
143
  </tr>
139
144
 
140
145
  <tr>
141
146
  <td>sessions</td>
142
- <td><%= settings.session_key %></td>
147
+ <td>{{ settings.session_key }}</td>
143
148
  <td>Session cookie name</td>
144
149
  </tr>
145
150
 
146
151
  <tr>
147
152
  <td>session_length</td>
148
- <td><%= settings.session_length %></td>
149
- <td>A session lasts for <%= settings.session_length %></td>
153
+ <td>{{ settings.session_length }}</td>
154
+ <td>A session lasts for {{ settings.session_length }}</td>
150
155
  </tr>
151
156
 
152
157
  <tr>
153
158
  <td>websockets</td>
154
- <td><%= settings.websockets %></td>
159
+ <td>{{ settings.websockets }}</td>
155
160
  <td>Websockets have been <%= ['disabled', 'enabled'][Number(!!settings.websockets)] %></td>
156
161
  </tr>
157
162
  </table>
package/lib/bootstrap.js CHANGED
@@ -160,6 +160,7 @@ hawkejs_options.server = false;
160
160
  * @version 1.1.0
161
161
  */
162
162
  alchemy.hawkejs.load(libpath.resolve(PATH_CORE, 'class', 'path_definition.js'), hawkejs_options);
163
+ alchemy.hawkejs.load(libpath.resolve(PATH_CORE, 'class', 'path_param_definition.js'), hawkejs_options);
163
164
 
164
165
  /**
165
166
  * Require the element class on the client side too