alchemymvc 1.3.16 → 1.3.17
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/lib/app/datasource/mongo_datasource.js +51 -29
- package/lib/app/element/time_ago.js +19 -36
- package/lib/app/helper/alchemy_helper.js +2 -2
- package/lib/app/helper/cron.js +1502 -0
- package/lib/app/helper_model/document.js +1 -0
- package/lib/app/model/alchemy_task_history_model.js +109 -0
- package/lib/app/model/alchemy_task_model.js +141 -18
- package/lib/bootstrap.js +3 -0
- package/lib/class/conduit.js +36 -12
- package/lib/class/model.js +24 -0
- package/lib/class/schema_client.js +8 -11
- package/lib/class/session.js +14 -3
- package/lib/class/task.js +297 -145
- package/lib/class/task_service.js +933 -0
- package/lib/core/base.js +23 -1
- package/lib/core/middleware.js +2 -2
- package/lib/init/alchemy.js +82 -4
- package/package.json +2 -2
|
@@ -182,39 +182,45 @@ Mongo.decorateMethod(Blast.Decorators.memoize({ignore_arguments: true}), functio
|
|
|
182
182
|
* @since 0.2.0
|
|
183
183
|
* @version 1.3.16
|
|
184
184
|
*
|
|
185
|
+
* @param {String} name
|
|
185
186
|
* @param {Function} callback
|
|
187
|
+
*
|
|
188
|
+
* @return {Pledge<Collection>}
|
|
186
189
|
*/
|
|
187
190
|
Mongo.setMethod(function collection(name, callback) {
|
|
188
191
|
|
|
189
|
-
|
|
192
|
+
const pledge = new Pledge();
|
|
190
193
|
|
|
191
|
-
|
|
192
|
-
setImmediate(function cachedCollection() {
|
|
193
|
-
callback(null, that.collections[name]);
|
|
194
|
-
});
|
|
194
|
+
pledge.done(callback);
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
if (this.collections[name]) {
|
|
197
|
+
pledge.resolve(this.collections[name]);
|
|
198
|
+
return pledge;
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
const that = this;
|
|
202
|
+
|
|
199
203
|
this.connect().done(function gotConnection(err, db) {
|
|
200
204
|
|
|
201
205
|
if (err) {
|
|
202
|
-
return
|
|
206
|
+
return pledge.reject(err);
|
|
203
207
|
}
|
|
204
208
|
|
|
205
209
|
Pledge.done(that.connection.collection(name), function createdCollection(err, collection) {
|
|
206
210
|
|
|
207
211
|
if (err) {
|
|
208
|
-
return
|
|
212
|
+
return pledge.reject(err);
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
// Cache the collection
|
|
212
216
|
that.collections[name] = collection;
|
|
213
217
|
|
|
214
218
|
// Return it to the callback
|
|
215
|
-
|
|
219
|
+
pledge.resolve(collection);
|
|
216
220
|
});
|
|
217
221
|
});
|
|
222
|
+
|
|
223
|
+
return pledge;
|
|
218
224
|
});
|
|
219
225
|
|
|
220
226
|
/**
|
|
@@ -560,43 +566,59 @@ Mongo.setMethod(function _remove(model, query, options, callback) {
|
|
|
560
566
|
*
|
|
561
567
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
562
568
|
* @since 0.2.0
|
|
563
|
-
* @version 1.
|
|
569
|
+
* @version 1.3.17
|
|
564
570
|
*/
|
|
565
571
|
Mongo.setMethod(function _ensureIndex(model, index, callback) {
|
|
566
572
|
|
|
567
|
-
this.collection(model.table, function gotCollection(err, collection) {
|
|
568
|
-
|
|
569
|
-
var options,
|
|
570
|
-
obj,
|
|
571
|
-
key;
|
|
573
|
+
this.collection(model.table, async function gotCollection(err, collection) {
|
|
572
574
|
|
|
573
575
|
if (err != null) {
|
|
574
576
|
return callback(err);
|
|
575
577
|
}
|
|
576
578
|
|
|
577
|
-
options = {
|
|
578
|
-
name: index.options.name
|
|
579
|
+
let options = {
|
|
580
|
+
name : index.options.name,
|
|
581
|
+
unique : index.options.unique ? true : false,
|
|
582
|
+
sparse : index.options.sparse ? true : false,
|
|
579
583
|
};
|
|
580
584
|
|
|
581
|
-
|
|
582
|
-
options.unique = true;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (index.options.sparse) {
|
|
586
|
-
options.sparse = true;
|
|
587
|
-
}
|
|
585
|
+
let index_specs;
|
|
588
586
|
|
|
589
587
|
// Hack in the text indexes
|
|
590
588
|
if (options.name == 'text') {
|
|
591
|
-
|
|
589
|
+
let key;
|
|
590
|
+
|
|
591
|
+
index_specs = {};
|
|
592
592
|
|
|
593
593
|
for (key in index.fields) {
|
|
594
|
-
|
|
594
|
+
index_specs[key] = 'text';
|
|
595
595
|
}
|
|
596
|
-
|
|
597
|
-
collection.createIndex(obj, options, callback);
|
|
598
596
|
} else {
|
|
599
|
-
|
|
597
|
+
index_specs = index.fields;
|
|
600
598
|
}
|
|
599
|
+
|
|
600
|
+
try {
|
|
601
|
+
await collection.createIndex(index_specs, options);
|
|
602
|
+
} catch (err) {
|
|
603
|
+
|
|
604
|
+
// Check for IndexOptionsConflict
|
|
605
|
+
if (err.code === 85) {
|
|
606
|
+
|
|
607
|
+
try {
|
|
608
|
+
|
|
609
|
+
// Index already exists, drop it
|
|
610
|
+
await collection.dropIndex(options.name);
|
|
611
|
+
|
|
612
|
+
// Try again
|
|
613
|
+
await collection.createIndex(index_specs, options);
|
|
614
|
+
} catch (second_err) {
|
|
615
|
+
return callback(second_err);
|
|
616
|
+
}
|
|
617
|
+
} else {
|
|
618
|
+
return callback(err);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
callback();
|
|
601
623
|
});
|
|
602
624
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const TIMEOUT_ID = Symbol('timeout_id');
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The custom al-time-ago element
|
|
3
5
|
*
|
|
@@ -27,8 +29,6 @@ TimeAgo.setAttribute(function date(str) {
|
|
|
27
29
|
return this._date;
|
|
28
30
|
}, function setValue(value) {
|
|
29
31
|
|
|
30
|
-
var date;
|
|
31
|
-
|
|
32
32
|
if (value) {
|
|
33
33
|
this._date = Date.create(value);
|
|
34
34
|
} else {
|
|
@@ -73,57 +73,40 @@ TimeAgo.setProperty(function value() {
|
|
|
73
73
|
* @version 0.1.0
|
|
74
74
|
*/
|
|
75
75
|
TimeAgo.setMethod(function connected() {
|
|
76
|
-
this.refresh(
|
|
76
|
+
this.refresh();
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* Refresh the content
|
|
81
81
|
*
|
|
82
|
-
* @author Jelle De Loecker <jelle@
|
|
82
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
83
83
|
* @since 0.1.0
|
|
84
|
-
* @version
|
|
85
|
-
*
|
|
86
|
-
* @param {Boolean} reset_timer
|
|
84
|
+
* @version 1.3.17
|
|
87
85
|
*/
|
|
88
|
-
TimeAgo.setMethod(function refresh(
|
|
86
|
+
TimeAgo.setMethod(function refresh() {
|
|
89
87
|
|
|
90
|
-
let
|
|
91
|
-
counter,
|
|
92
|
-
timer,
|
|
93
|
-
text = this.value,
|
|
94
|
-
diff;
|
|
88
|
+
let text = this.value;
|
|
95
89
|
|
|
96
90
|
if (this.textContent != text) {
|
|
97
91
|
this.textContent = text;
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
if (!
|
|
94
|
+
if (Blast.isNode || !this.isConnected || !this.date) {
|
|
101
95
|
return;
|
|
102
96
|
}
|
|
103
97
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
let diff = Math.abs(Date.now() - this.date),
|
|
99
|
+
timer;
|
|
100
|
+
|
|
101
|
+
if (diff < 1000 * 70) {
|
|
102
|
+
timer = 1000;
|
|
103
|
+
} else {
|
|
104
|
+
timer = 1000 * 29;
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
if (this
|
|
110
|
-
|
|
111
|
-
counter = 0;
|
|
112
|
-
|
|
113
|
-
if (diff < 1000 * 29) {
|
|
114
|
-
timer = 1000;
|
|
115
|
-
} else {
|
|
116
|
-
timer = 1000 * 29;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._timer = setInterval(function doUpdate() {
|
|
120
|
-
counter++;
|
|
121
|
-
|
|
122
|
-
if (counter > 60) {
|
|
123
|
-
that.refresh(true);
|
|
124
|
-
} else {
|
|
125
|
-
that.refresh();
|
|
126
|
-
}
|
|
127
|
-
}, timer);
|
|
107
|
+
if (this[TIMEOUT_ID]) {
|
|
108
|
+
clearTimeout(this[TIMEOUT_ID]);
|
|
128
109
|
}
|
|
110
|
+
|
|
111
|
+
this[TIMEOUT_ID] = setTimeout(() => this.refresh(), timer);
|
|
129
112
|
});
|
|
@@ -292,7 +292,7 @@ Alchemy.setMethod(function group(name, id, callback) {
|
|
|
292
292
|
*
|
|
293
293
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
294
294
|
* @since 0.5.0
|
|
295
|
-
* @version 1.3.
|
|
295
|
+
* @version 1.3.17
|
|
296
296
|
*
|
|
297
297
|
* @param {String|Object} options
|
|
298
298
|
* @param {Object} data
|
|
@@ -325,7 +325,7 @@ Alchemy.setMethod(function segment(options, data) {
|
|
|
325
325
|
conduit = that.view.server_var('conduit');
|
|
326
326
|
|
|
327
327
|
if (!conduit) {
|
|
328
|
-
return next();
|
|
328
|
+
return next(null, '<!-- Failed to render segment ' + options.name + ': no conduit found -->');
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
options.params = data;
|