diff --git a/main.go b/main.go index ced938c..18d3d8c 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "embed" "encoding/json" + "errors" "flag" "fmt" "html/template" @@ -690,6 +691,22 @@ func (web *Web) importWatch(c *gin.Context) { c.AbortWithError(http.StatusBadRequest, err) return } + importType := c.PostForm("type") + if !(importType == "clear" || importType == "add") { + c.AbortWithError(http.StatusBadRequest, errors.New("Unknown Import Type")) + return + } + clearFilters := importType == "clear" + + offsetX := 0 + offsetY := 0 + + if !clearFilters { + offsetX, _ = strconv.Atoi(c.PostForm("offset_x")) + offsetY, _ = strconv.Atoi(c.PostForm("offset_y")) + offsetX *= -1 + offsetY *= -1 + } file, err := c.FormFile("json") @@ -714,7 +731,9 @@ func (web *Web) importWatch(c *gin.Context) { // stop/delete cronjobs running for this watch var cronFilters []Filter + if !clearFilters { web.db.Model(&Filter{}).Where("watch_id = ? AND type = 'cron'", watchID).Find(&cronFilters) + } for _, filter := range cronFilters { entryID, exist := web.cronWatch[filter.ID] if exist { @@ -728,9 +747,14 @@ func (web *Web) importWatch(c *gin.Context) { filter := &export.Filters[i] filterMap[filter.ID] = filter filter.ID = 0 + filter.X += offsetX + filter.Y += offsetY filter.WatchID = uint(watchID) } + + if clearFilters { web.db.Delete(&Filter{}, "watch_id = ?", watchID) + } if len(export.Filters) > 0 { tx := web.db.Create(&export.Filters) @@ -740,7 +764,7 @@ func (web *Web) importWatch(c *gin.Context) { } for i := range export.Filters { filter := &export.Filters[i] - if filter.Type == "cron" { + if filter.Type == "cron" && filter.Var2 != nil && *filter.Var2 == "yes" { entryID, err := web.cron.AddFunc(filter.Var1, func() { triggerSchedule(filter.WatchID, web, &filter.ID) }) if err != nil { log.Println("Could not start job for Watch: ", filter.WatchID) @@ -752,7 +776,9 @@ func (web *Web) importWatch(c *gin.Context) { } } + if clearFilters { web.db.Delete(&FilterConnection{}, "watch_id = ?", watchID) + } for i := range export.Connections { connection := &export.Connections[i] connection.ID = 0 diff --git a/static/diagram.js b/static/diagram.js index 4336f04..4a6b0ff 100644 --- a/static/diagram.js +++ b/static/diagram.js @@ -568,6 +568,10 @@ var Diagrams = /** @class */ (function () { if (this.mouseState.panning) { this.mouseState.offset.x += this.mouseState.delta.x; this.mouseState.offset.y += this.mouseState.delta.y; + var importOffsetInputX = document.getElementById("offset_x"); + importOffsetInputX.value = this.mouseState.offset.x.toString(); + var importOffsetInputY = document.getElementById("offset_y"); + importOffsetInputY.value = this.mouseState.offset.y.toString(); } this.mouseState.world.x = this.mouseState.canvas.x - this.mouseState.offset.x; this.mouseState.world.y = this.mouseState.canvas.y - this.mouseState.offset.y; diff --git a/static/diagram.ts b/static/diagram.ts index 4246afb..765d2ae 100644 --- a/static/diagram.ts +++ b/static/diagram.ts @@ -611,6 +611,12 @@ class Diagrams { if (this.mouseState.panning){ this.mouseState.offset.x += this.mouseState.delta.x; this.mouseState.offset.y += this.mouseState.delta.y; + + let importOffsetInputX = document.getElementById("offset_x") as HTMLInputElement; + importOffsetInputX.value = this.mouseState.offset.x.toString(); + + let importOffsetInputY = document.getElementById("offset_y") as HTMLInputElement; + importOffsetInputY.value = this.mouseState.offset.y.toString(); } this.mouseState.world.x = this.mouseState.canvas.x - this.mouseState.offset.x; diff --git a/templates/watch/edit.html b/templates/watch/edit.html index bd9338f..2c46612 100644 --- a/templates/watch/edit.html +++ b/templates/watch/edit.html @@ -169,6 +169,12 @@ GoWatch Edit {{ .Watch.Name }}
+ + +
diff --git a/todo.md b/todo.md index 1220966..024f2fc 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,4 @@ # Todo -- import options add/clear - comments - safe escape {{ }} for pages - 'jitter' for cronjobs after first start ?