alchemymvc 1.2.5 → 1.2.7

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 (86) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/app/assets/scripts/.gitkeep +0 -0
  4. package/lib/app/assets/stylesheets/alchemy-info.less +0 -0
  5. package/lib/app/behaviour/publishable_behaviour.js +0 -0
  6. package/lib/app/behaviour/revision_behaviour.js +0 -0
  7. package/lib/app/behaviour/sluggable_behaviour.js +0 -0
  8. package/lib/app/component/.gitkeep +0 -0
  9. package/lib/app/conduit/electron_conduit.js +0 -0
  10. package/lib/app/conduit/http_conduit.js +173 -173
  11. package/lib/app/conduit/loopback_conduit.js +2 -3
  12. package/lib/app/conduit/socket_conduit.js +620 -620
  13. package/lib/app/controller/alchemy_info_controller.js +0 -0
  14. package/lib/app/datasource/mongo_datasource.js +0 -0
  15. package/lib/app/element/time_ago.js +2 -4
  16. package/lib/app/helper/alchemy_helper.js +22 -11
  17. package/lib/app/helper/client_collection.js +0 -0
  18. package/lib/app/helper/pagination_helper.js +0 -0
  19. package/lib/app/helper/router_helper.js +20 -7
  20. package/lib/app/helper/socket_helper.js +613 -613
  21. package/lib/app/helper_component/paginate_component.js +0 -0
  22. package/lib/app/helper_controller/component.js +0 -0
  23. package/lib/app/helper_controller/conduit.js +0 -0
  24. package/lib/app/helper_controller/controller.js +0 -0
  25. package/lib/app/helper_datasource/00-nosql_datasource.js +0 -0
  26. package/lib/app/helper_datasource/05-fallback_datasource.js +0 -0
  27. package/lib/app/helper_datasource/idb_datasource.js +0 -0
  28. package/lib/app/helper_datasource/indexed_db.js +0 -0
  29. package/lib/app/helper_field/00-objectid_field.js +0 -0
  30. package/lib/app/helper_field/06-text_field.js +0 -0
  31. package/lib/app/helper_field/10-number_field.js +0 -0
  32. package/lib/app/helper_field/boolean_field.js +0 -0
  33. package/lib/app/helper_field/date_field.js +0 -0
  34. package/lib/app/helper_field/datetime_field.js +0 -0
  35. package/lib/app/helper_field/enum_field.js +0 -0
  36. package/lib/app/helper_field/geopoint_field.js +0 -0
  37. package/lib/app/helper_field/habtm_field.js +0 -0
  38. package/lib/app/helper_field/hasoneparent_field.js +0 -0
  39. package/lib/app/helper_field/html_field.js +0 -0
  40. package/lib/app/helper_field/integer_field.js +0 -0
  41. package/lib/app/helper_field/object_field.js +0 -0
  42. package/lib/app/helper_field/regexp_field.js +0 -0
  43. package/lib/app/helper_field/schema_field.js +23 -2
  44. package/lib/app/helper_field/time_field.js +0 -0
  45. package/lib/app/helper_field/url_field.js +0 -0
  46. package/lib/app/helper_model/criteria.js +21 -3
  47. package/lib/app/helper_model/db_query.js +0 -0
  48. package/lib/app/helper_model/document_list.js +0 -0
  49. package/lib/app/helper_model/field_config.js +2 -2
  50. package/lib/app/helper_model/model.js +72 -5
  51. package/lib/app/model/alchemy_task_model.js +0 -0
  52. package/lib/app/routes.js +0 -0
  53. package/lib/app/view/alchemy/info.ejs +0 -0
  54. package/lib/app/view/error/unknown.ejs +0 -0
  55. package/lib/app/view/paginate/navlist.ejs +0 -0
  56. package/lib/bootstrap.js +0 -0
  57. package/lib/class/behaviour.js +0 -0
  58. package/lib/class/component.js +0 -0
  59. package/lib/class/conduit.js +2572 -2552
  60. package/lib/class/controller.js +4 -1
  61. package/lib/class/document.js +18 -4
  62. package/lib/class/document_list.js +0 -0
  63. package/lib/class/helper.js +0 -0
  64. package/lib/class/inode.js +0 -0
  65. package/lib/class/inode_dir.js +0 -0
  66. package/lib/class/inode_file.js +136 -112
  67. package/lib/class/inode_list.js +0 -0
  68. package/lib/class/model.js +1740 -1769
  69. package/lib/class/path_definition.js +0 -0
  70. package/lib/class/route.js +0 -0
  71. package/lib/class/router.js +6 -3
  72. package/lib/class/session.js +0 -0
  73. package/lib/class/task.js +0 -0
  74. package/lib/core/base.js +41 -18
  75. package/lib/core/client_alchemy.js +48 -2
  76. package/lib/core/discovery.js +0 -0
  77. package/lib/core/middleware.js +6 -4
  78. package/lib/core/routing.js +0 -0
  79. package/lib/core/socket.js +159 -159
  80. package/lib/init/alchemy.js +1848 -1823
  81. package/lib/init/constants.js +0 -0
  82. package/lib/init/functions.js +8 -4
  83. package/lib/init/load_functions.js +0 -0
  84. package/lib/init/requirements.js +101 -101
  85. package/lib/stages.js +10 -2
  86. package/package.json +74 -74
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -364,7 +364,7 @@ SchemaField.setMethod(function _toApp(query, options, value, callback) {
364
364
  *
365
365
  * @author Jelle De Loecker <jelle@elevenways.be>
366
366
  * @since 1.1.4
367
- * @version 1.1.4
367
+ * @version 1.2.6
368
368
  */
369
369
  SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
370
370
 
@@ -373,11 +373,18 @@ SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
373
373
  translateRecord.super.call(this, prefixes, record, allow_empty);
374
374
  }
375
375
 
376
+ if (!record.$translated_fields) {
377
+ record.$translated_fields = {};
378
+ }
379
+
376
380
  // Turn it into an array, some already are (is_array fields)
377
381
  let subject = Array.cast(record[this.name]),
378
- schema_record;
382
+ schema_record,
383
+ count = -1;
379
384
 
380
385
  for (schema_record of subject) {
386
+ count++;
387
+
381
388
  if (this.field_schema.hasTranslations && schema_record) {
382
389
 
383
390
  let field_name,
@@ -386,6 +393,20 @@ SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
386
393
  for (field_name in this.field_schema.translatableFields) {
387
394
  field = this.field_schema.translatableFields[field_name];
388
395
  field.translateRecord(prefixes, schema_record, allow_empty);
396
+
397
+ if (schema_record.$translated_fields) {
398
+ for (let key in schema_record.$translated_fields) {
399
+ let path = this.name;
400
+
401
+ if (this.is_array) {
402
+ path += '.' + count;
403
+ }
404
+
405
+ path += '.' + key;
406
+
407
+ record.$translated_fields[path] = schema_record.$translated_fields[key];
408
+ }
409
+ }
389
410
  }
390
411
  }
391
412
  }
File without changes
File without changes
@@ -659,13 +659,18 @@ Criteria.setMethod(function augment(type) {
659
659
  *
660
660
  * @author Jelle De Loecker <jelle@develry.be>
661
661
  * @since 1.1.0
662
- * @version 1.1.0
662
+ * @version 1.2.7
663
663
  *
664
664
  * @param {Number} amount
665
665
  *
666
666
  * @return {Criteria}
667
667
  */
668
668
  Criteria.setMethod(function limit(amount) {
669
+
670
+ if (typeof amount != 'number') {
671
+ amount = parseInt(amount);
672
+ }
673
+
669
674
  this.options.limit = amount;
670
675
  return this;
671
676
  });
@@ -675,13 +680,18 @@ Criteria.setMethod(function limit(amount) {
675
680
  *
676
681
  * @author Jelle De Loecker <jelle@develry.be>
677
682
  * @since 1.1.0
678
- * @version 1.1.0
683
+ * @version 1.2.7
679
684
  *
680
685
  * @param {Number} amount
681
686
  *
682
687
  * @return {Criteria}
683
688
  */
684
689
  Criteria.setMethod(function skip(amount) {
690
+
691
+ if (typeof amount != 'number') {
692
+ amount = parseInt(amount);
693
+ }
694
+
685
695
  this.options.skip = amount;
686
696
  return this;
687
697
  });
@@ -691,7 +701,7 @@ Criteria.setMethod(function skip(amount) {
691
701
  *
692
702
  * @author Jelle De Loecker <jelle@develry.be>
693
703
  * @since 1.1.3
694
- * @version 1.1.3
704
+ * @version 1.2.7
695
705
  *
696
706
  * @param {Number} page A 1-indexed page number
697
707
  * @param {Number} page_size
@@ -700,6 +710,14 @@ Criteria.setMethod(function skip(amount) {
700
710
  */
701
711
  Criteria.setMethod(function page(page, page_size) {
702
712
 
713
+ if (typeof page != 'number') {
714
+ page = parseInt(page);
715
+ }
716
+
717
+ if (page_size && typeof page_size != 'number') {
718
+ page_size = parseInt(page_size);
719
+ }
720
+
703
721
  if (!page) {
704
722
  throw new Error('A page number is required');
705
723
  }
File without changes
File without changes
@@ -161,7 +161,7 @@ FieldConfig.setMethod(function getModel() {
161
161
  *
162
162
  * @author Jelle De Loecker <jelle@elevenways.be>
163
163
  * @since 1.2.2
164
- * @version 1.2.5
164
+ * @version 1.2.7
165
165
  *
166
166
  * @return {Field}
167
167
  */
@@ -178,7 +178,7 @@ FieldConfig.setMethod(function getFieldDefinition() {
178
178
  let constructor = Classes.Alchemy.Field.Field.getMember(this.options.type);
179
179
 
180
180
  if (constructor) {
181
- result = new constructor(null, this.name);
181
+ result = new constructor(null, this.name, this.options);
182
182
  }
183
183
  }
184
184
 
@@ -188,7 +188,7 @@ Model.prepareStaticProperty('Document', function getDocumentClass() {
188
188
  *
189
189
  * @author Jelle De Loecker <jelle@develry.be>
190
190
  * @since 1.0.0
191
- * @version 1.1.3
191
+ * @version 1.2.7
192
192
  *
193
193
  * @param {String} model_name
194
194
  * @param {Boolean} allow_create
@@ -237,8 +237,9 @@ Model.setStatic(function getClass(model_name, allow_create ) {
237
237
 
238
238
  if (config && config.super) {
239
239
  config = {
240
- parent : config.super.name,
241
- primary_key : config.prototype.primary_key
240
+ parent : config.super.name,
241
+ primary_key : config.prototype.primary_key,
242
+ display_field : config.prototype.display_field,
242
243
  };
243
244
  }
244
245
  }
@@ -252,8 +253,14 @@ Model.setStatic(function getClass(model_name, allow_create ) {
252
253
 
253
254
  ModelClass.setProperty('$model_name', model_name);
254
255
 
255
- if (config && config.primary_key) {
256
- ModelClass.setProperty('primary_key', config.primary_key);
256
+ if (config) {
257
+ if (config.primary_key) {
258
+ ModelClass.setProperty('primary_key', config.primary_key);
259
+ }
260
+
261
+ if (config.display_field) {
262
+ ModelClass.setProperty('display_field', config.display_field);
263
+ }
257
264
  }
258
265
 
259
266
  if (Blast.isBrowser) {
@@ -414,6 +421,66 @@ Model.setMethod(function getFindOptions(options) {
414
421
  return Object.assign({}, def_options, options);
415
422
  });
416
423
 
424
+
425
+ /**
426
+ * Get the title to display for this record
427
+ *
428
+ * @author Jelle De Loecker <jelle@elevenways.be>
429
+ * @since 0.0.1
430
+ * @version 1.2.7
431
+ *
432
+ * @param {Object} item The record item of this model
433
+ * @param {String|Array} fallbacks Extra fallbacks to use
434
+ *
435
+ * @return {String} The display title to use
436
+ */
437
+ Model.setMethod(function getDisplayTitle(item, fallbacks) {
438
+
439
+ if (!item) {
440
+ return 'Undefined item';
441
+ }
442
+
443
+ let main;
444
+
445
+ if (item[this.modelName]) {
446
+ main = item[this.modelName];
447
+ } else {
448
+ main = item;
449
+ }
450
+
451
+ if (!main) {
452
+ return 'Undefined item';
453
+ }
454
+
455
+ let field,
456
+ val,
457
+ i;
458
+
459
+ let fields = Array.cast(this.display_field);
460
+
461
+ if (fallbacks) {
462
+ fields = fields.concat(fallbacks);
463
+ }
464
+
465
+ for (i = 0; i < fields.length; i++) {
466
+ val = main[fields[i]];
467
+
468
+ if (Object.isObject(val)) {
469
+ field = this.getField(fields[i]);
470
+
471
+ if (field && field.isTranslatable) {
472
+ val = alchemy.pickTranslation(this.conduit, val).result;
473
+ }
474
+ }
475
+
476
+ if (val && typeof val == 'string') {
477
+ return val;
478
+ }
479
+ }
480
+
481
+ return main[this.primary_key] || '';
482
+ });
483
+
417
484
  /**
418
485
  * Return association configuration
419
486
  *
File without changes
package/lib/app/routes.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/lib/bootstrap.js CHANGED
File without changes
File without changes
File without changes