diff --git a/groupTasks/groups/janex-acryl/index.json b/groupTasks/groups/janex-acryl/index.json index 09c8325..dd0868f 100644 --- a/groupTasks/groups/janex-acryl/index.json +++ b/groupTasks/groups/janex-acryl/index.json @@ -1,16 +1,46 @@ { - "category": "Janex", - "name": "Janex Device Acryl schneiden", - "globalInputs": [ - { - "parameterName": "irgendwas", - "type": "text", - "displayName": "Irgendwas tolles" - }, - { - "parameterName": "kiste", - "type": "number", - "displayName": "Nummer der Kiste" - } - ] -} \ No newline at end of file + "category": "Janex", + "name": "Janex Device Acryl schneiden", + "globalInputs": [ + { + "parameterName": "irgendwas", + "type": "text", + "displayName": "Irgendwas tolles" + }, + { + "parameterName": "kiste", + "type": "number", + "displayName": "Nummer der Kiste" + }, + { + "parameterName": "3d_printer_machine_selection3", + "type": "select_machine", + "displayName": "3D Drucker3", + "options": { + "location": 5, + "whitelistParts": [1, 2], + "blacklistParts": [0, 5] + } + }, + { + "parameterName": "3d_printer_machine_selection2", + "type": "select_machine", + "displayName": "3D Drucker2", + "options": { + "location": 5, + "whitelistParts": [1, 2], + "blacklistParts": [0, 5] + } + } + ], + "tasks": [ + { + "name": "Label drucken", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": false, + "scriptPath": "test2.py", + "parameters": [] + } + ] +} diff --git a/groupTasks/groups/production1/index.json b/groupTasks/groups/production1/index.json index f682da9..a56d961 100644 --- a/groupTasks/groups/production1/index.json +++ b/groupTasks/groups/production1/index.json @@ -20,11 +20,11 @@ { "parameterName": "3d_printer_machine_selection", "type": "select_machine", - "displayName": "3D Drucker auswählen", + "displayName": "3D Drucker", "options": { - "location": 1, - "whitelist": [1, 2], - "blacklist": [0, 5] + "location": 5, + "whitelistParts": [], + "blacklistParts": [] } } ], @@ -53,6 +53,16 @@ "type": "textarea", "displayName": "Nummer der zweiten Kiste lul", "global": true + }, + { + "parameterName": "print_machine_selection", + "type": "select_machine", + "displayName": "Drucker", + "options": { + "location": 5, + "whitelistParts": [], + "blacklistParts": [] + } } ] }, diff --git a/groupTasks/groups/production1/test1.py b/groupTasks/groups/production1/test1.py index 9395d1d..b3621ae 100644 --- a/groupTasks/groups/production1/test1.py +++ b/groupTasks/groups/production1/test1.py @@ -4,12 +4,17 @@ import time import sys import numpy as np from stl import mesh +import json time.sleep(3) -labelformat = sys.argv[1] -kiste = sys.argv[2] +# arg format is like this: args ['test1.py', '{"kiste":{"value":"321"},"labelformat":{"value":"123123"},"print_machine_selection":{"data":{"displayName":"Brother Workplace","ip":"127.0.0.1"},"value":"Brother Workplace"}}', '--undo'] undo is optional +json_object = json.loads(sys.argv[1]) +labelformat = json_object["labelformat"] +kiste = json_object["kiste"] + +print("args", sys.argv) if len(sys.argv) >= 5: undo = sys.argv[4] diff --git a/modules/grouptasks/grouptasks.go b/modules/grouptasks/grouptasks.go index 6afb1f4..6be981b 100644 --- a/modules/grouptasks/grouptasks.go +++ b/modules/grouptasks/grouptasks.go @@ -503,15 +503,7 @@ func RunGroupTask(args RunGroupTaskArgs) { }) return } else if len(args.TaskInputs) > 0 { - var taskParameterInputs []InputParameters - - if err := json.Unmarshal([]byte(args.TaskInputs), &taskParameterInputs); err != nil { - log.Error().Msgf("err unmarshalling task parameter inputs %s", err.Error()) - } - - for _, taskParameterInput := range taskParameterInputs { - commandArgs = append(commandArgs, taskParameterInput.Value) - } + commandArgs = append(commandArgs, args.TaskInputs) // append undo as last arg to script if args.StartType == RunGroupTaskStartTypeUndo { diff --git a/modules/structs/machines.go b/modules/structs/machines.go index fe5463d..b2c258e 100644 --- a/modules/structs/machines.go +++ b/modules/structs/machines.go @@ -1,9 +1,9 @@ package structs type MachinesBody struct { - Location int - Whitelist []int - Blacklist []int + Location int + WhitelistParts []int + BlacklistParts []int } /* diff --git a/routers/router/api/v1/machines/machines.go b/routers/router/api/v1/machines/machines.go index 4478c63..afa766c 100644 --- a/routers/router/api/v1/machines/machines.go +++ b/routers/router/api/v1/machines/machines.go @@ -5,25 +5,17 @@ import ( "jannex/admin-dashboard-backend/modules/requestclient" "jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/utils" + "strconv" "github.com/gofiber/fiber/v2" "github.com/rs/zerolog/log" ) -// POST /v1/machines/ - -/* -{ - location: 2, - whitelist: [], - blacklist: [] -} -*/ - type InvexApiStockListResponse struct { Results []struct { Notes string Status int + Part int PartDetail struct { Name string Thumbnail string @@ -40,7 +32,7 @@ func GetMachines(c *fiber.Ctx) error { log.Info().Msgf("body %v", body) - statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=25&location=5&part_detail=true") + statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0") log.Info().Msgf("statuscode %v", statusCode) @@ -57,11 +49,29 @@ func GetMachines(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusInternalServerError) } - for locationItem, i := range data.Results { - log.Info().Msgf("lI %v %v", locationItem, i) + var finalData InvexApiStockListResponse + + for _, item := range data.Results { + if !contains(body.BlacklistParts, item.Part) { + if len(body.WhitelistParts) == 0 || contains(body.WhitelistParts, item.Part) { + finalData.Results = append(finalData.Results, item) + } + } } - //log.Info().Msgf("body %s", data) + // send empty array if no results + if len(finalData.Results) == 0 { + return c.JSON([]string{}) + } - return c.JSON(data.Results) + return c.JSON(finalData.Results) +} + +func contains(slice []int, item int) bool { + for _, s := range slice { + if s == item { + return true + } + } + return false } diff --git a/socketserver/hub.go b/socketserver/hub.go index 6c96165..d7b94c8 100644 --- a/socketserver/hub.go +++ b/socketserver/hub.go @@ -90,6 +90,8 @@ func RunHub() { globalInputsJsonString := utils.MarshalJson(receivedMessage.Body["globalInputs"]) + log.Debug().Msgf("globalInputsJsonString %v", globalInputsJsonString) + grouptasks.StartGroupTask(data.Conn.Locals("userId").(string), structs.GroupTasks{ Category: category,