Support add/remove objects from presets and tasks

This commit is contained in:
Zaid Abdulla committed 2016-12-29 13:04:11 -08:00
1 parent 179211ce53
commit 33b01d68ca
3 files changed
+55

No files matched your search

+22
View File
@@ -100,6 +100,12 @@ refresh = (callback) ->
counter = 0
return
db.objectsCollection.find().toArray((err, objects) ->
if err
callback(err) if -- counter >= 0
counter = 0
return
res.sort((a, b) ->
if a.weight == b.weight
return a._id > b._id
@@ -145,6 +151,21 @@ refresh = (callback) ->
_provisions.push(['tag', c.tag, false])
when 'provision'
_provisions.push([c.name].concat(c.args or []))
when 'add_object'
for obj in objects
if obj['_id'] == c.object
alias = ("#{k}:#{JSON.stringify(obj[k])}" for k in obj['_keys']).join(',')
p = "#{c.name}.[#{alias}]"
_provisions.push(['instances', p, 1])
for k of obj
if k[0] != '_' and k not in obj['_keys']
_provisions.push(['value', "#{p}.#{k}", obj[k]])
when 'delete_object'
for obj in objects
if obj['_id'] == c.object
alias = ("#{k}:#{JSON.stringify(obj[k])}" for k in obj['_keys']).join(',')
p = "#{c.name}.[#{alias}]"
_provisions.push(['instances', p, 0])
else
callback(new Error("Unknown configuration type #{c.type}")) if -- counter >= 0
counter = 0
@@ -160,6 +181,7 @@ refresh = (callback) ->
return callback()
)
)
)
db.provisionsCollection.find().toArray((err, res) ->
if err
+7
View File
@@ -401,6 +401,13 @@ nextRpc = (currentRequest) ->
when 'download'
session.addProvisions(currentRequest.sessionData, "task_#{task._id}",
[['download', task.fileType, task.fileName, task.targetFileName]])
when 'addObject'
alias = ("#{p[0]}:#{JSON.stringify(p[1])}" for p in task.parameterValues or []).join(',')
session.addProvisions(currentRequest.sessionData, "task_#{task._id}",
[['instances', "#{task.objectName}.[#{alias}]", "+1"]]);
when 'deleteObject'
session.addProvisions(currentRequest.sessionData, "task_#{task._id}",
[['instances', task.objectName, 0]]);
else
return throwError(new Error('Task name not recognized'), currentRequest.httpResponse) if err
+26
View File
@@ -18,6 +18,7 @@
const config = require("./config");
const common = require("./common");
const device = require("./device");
const MAX_DEPTH = config.get("MAX_DEPTH");
@@ -79,9 +80,34 @@ function download(sessionData, provision, declarations, startRevision, endRevisi
}
function instances(sessionData, provision, declarations, startRevision, endRevision) {
let count = Number(provision[2]);
if (Number.isNaN(count))
return true;
let path = common.parsePath(provision[1]);
if (provision[2][0] === "+" || provision[2][0] === "-") {
declarations.push([path, 1]);
if (endRevision === startRevision)
return false;
let unpacked = device.unpack(sessionData.deviceData, path, startRevision + 1);
count = Math.max(0, unpacked.length + count);
}
declarations.push([path, 1, null, count]);
return true;
}
exports.refresh = refresh;
exports.value = value;
exports.tag = tag;
exports.reboot = reboot;
exports.reset = reset;
exports.download = download;
exports.instances = instances;