From d504cb6f8bab5d1f7bfec21edc28f1b32a66d976 Mon Sep 17 00:00:00 2001 From: skadefro Date: Sat, 12 Aug 2023 23:40:50 +0200 Subject: [PATCH] add schedule name dobule check --- OpenFlow/src/public/Controllers.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/OpenFlow/src/public/Controllers.ts b/OpenFlow/src/public/Controllers.ts index 9d742463..5ac4d833 100644 --- a/OpenFlow/src/public/Controllers.ts +++ b/OpenFlow/src/public/Controllers.ts @@ -8218,13 +8218,20 @@ export class AgentCtrl extends entityCtrl { if(this.newpackage._id == "") return; var cron = this.newcron; if(this.newpackage.daemon == true) cron = ""; - this.model.schedules.push({ + var nameexists = this.model.schedules.find(x => x.name == this.newpackage.name) + const schedule = { name: this.newpackage.name, packageid: this.newpackage._id, enabled: true, cron, "env": {} - }) + } + if(nameexists != null) { + schedule.name = this.newpackage.name + "_" + Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + return; + } + this.model.schedules.push(schedule) + this.newcron = "* * * * *" } removepackage(schedule) { var index = this.model.schedules.indexOf(schedule); @@ -8273,6 +8280,15 @@ export class AgentCtrl extends entityCtrl { if (image != null && image != "") { this.model.docker = true; } + if(this.model.schedules == null) this.model.schedules = []; + var schedulenames = this.model.schedules.map(x => x.name); + // does schedulenames has doubles? + var doubles = schedulenames.filter((item, index) => schedulenames.indexOf(item) != index) + if(doubles.length > 0) { + this.errormessage = "Schedule names must be unique" + return; + } + if (this.model._id) { await NoderedUtil.UpdateOne({ collectionname: this.collection, item: this.model }); if(this.instances.length == 0 && this.model.image != null && this.model.image != "") { @@ -8658,6 +8674,9 @@ export class RunPackageCtrl extends entityCtrl { async addprocess(streamid:string, schedulename:string = undefined): Promise { var _a = this.agents.find(x => x._id == this.id); if (_a == null) return; + var pretest = document.getElementById(streamid); + if(pretest != null) return; + var payload ={ "command": "setstreamid", "id": streamid,