Support add/remove objects from presets and tasks
This commit is contained in:
1 parent
179211ce53
commit
33b01d68ca
3 files changed
+55
No files matched your search
@@ -100,6 +100,12 @@ refresh = (callback) ->
|
|||||||
counter = 0
|
counter = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
|
db.objectsCollection.find().toArray((err, objects) ->
|
||||||
|
if err
|
||||||
|
callback(err) if -- counter >= 0
|
||||||
|
counter = 0
|
||||||
|
return
|
||||||
|
|
||||||
res.sort((a, b) ->
|
res.sort((a, b) ->
|
||||||
if a.weight == b.weight
|
if a.weight == b.weight
|
||||||
return a._id > b._id
|
return a._id > b._id
|
||||||
@@ -145,6 +151,21 @@ refresh = (callback) ->
|
|||||||
_provisions.push(['tag', c.tag, false])
|
_provisions.push(['tag', c.tag, false])
|
||||||
when 'provision'
|
when 'provision'
|
||||||
_provisions.push([c.name].concat(c.args or []))
|
_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
|
else
|
||||||
callback(new Error("Unknown configuration type #{c.type}")) if -- counter >= 0
|
callback(new Error("Unknown configuration type #{c.type}")) if -- counter >= 0
|
||||||
counter = 0
|
counter = 0
|
||||||
@@ -160,6 +181,7 @@ refresh = (callback) ->
|
|||||||
return callback()
|
return callback()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
db.provisionsCollection.find().toArray((err, res) ->
|
db.provisionsCollection.find().toArray((err, res) ->
|
||||||
if err
|
if err
|
||||||
|
|||||||
@@ -401,6 +401,13 @@ nextRpc = (currentRequest) ->
|
|||||||
when 'download'
|
when 'download'
|
||||||
session.addProvisions(currentRequest.sessionData, "task_#{task._id}",
|
session.addProvisions(currentRequest.sessionData, "task_#{task._id}",
|
||||||
[['download', task.fileType, task.fileName, task.targetFileName]])
|
[['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
|
else
|
||||||
return throwError(new Error('Task name not recognized'), currentRequest.httpResponse) if err
|
return throwError(new Error('Task name not recognized'), currentRequest.httpResponse) if err
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const common = require("./common");
|
const common = require("./common");
|
||||||
|
const device = require("./device");
|
||||||
|
|
||||||
const MAX_DEPTH = config.get("MAX_DEPTH");
|
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.refresh = refresh;
|
||||||
exports.value = value;
|
exports.value = value;
|
||||||
exports.tag = tag;
|
exports.tag = tag;
|
||||||
exports.reboot = reboot;
|
exports.reboot = reboot;
|
||||||
exports.reset = reset;
|
exports.reset = reset;
|
||||||
exports.download = download;
|
exports.download = download;
|
||||||
|
exports.instances = instances;
|
||||||
Reference in new issue
Block a user