diff --git a/db.go b/db.go deleted file mode 100644 index 94fb070..0000000 --- a/db.go +++ /dev/null @@ -1,6 +0,0 @@ -package main - -import ( -) - - diff --git a/logic/tasks/list.go b/logic/tasks/list.go index 4f79f21..0343ae4 100644 --- a/logic/tasks/list.go +++ b/logic/tasks/list.go @@ -8,12 +8,32 @@ import ( ) func handleList(handler *Handle) { + + handler.PostAuth("/tasks/task", 1, func(c *Context) *Error { + var getId JustId + if _err := c.ToJSON(&getId); _err != nil { + return _err + } + + var task Task + + err := GetDBOnce(c, &task, "tasks where id=$1;", getId.Id) + if err == NotFoundError { + return c.JsonBadRequest("Did not found task id") + } else if err != nil { + return c.E500M("Faied to get task", err) + } + + c.ShowMessage = false + return c.SendJSON(task) + }) + handler.PostAuth("/tasks/list", 1, func(c *Context) *Error { - var err error = nil + var err error = nil var requestData struct { ModelId string `json:"model_id"` - Page int `json:"page"` + Page int `json:"page"` } if _err := c.ToJSON(&requestData); _err != nil { @@ -33,29 +53,29 @@ func handleList(handler *Handle) { } } - var rows []*Task = nil + var rows []*Task = nil if requestData.ModelId != "" { - rows, err = GetDbMultitple[Task](c, "tasks where model_id=$1 order by created_on desc limit 11 offset $2", requestData.ModelId, requestData.Page * 10) + rows, err = GetDbMultitple[Task](c, "tasks where model_id=$1 order by created_on desc limit 11 offset $2", requestData.ModelId, requestData.Page*10) if err != nil { return c.Error500(err) } } else { - rows, err = GetDbMultitple[Task](c, "tasks order by created_on desc limit 11 offset $1", requestData.Page * 10) + rows, err = GetDbMultitple[Task](c, "tasks order by created_on desc limit 11 offset $1", requestData.Page*10) if err != nil { return c.Error500(err) } } max_len := min(11, len(rows)) - - c.ShowMessage = false + + c.ShowMessage = false return c.SendJSON(struct { - TaskList []*Task `json:"task_list"` - ShowNext bool `json:"show_next"` - } { - rows[0:max_len], - len(rows) > 10, - }) + TaskList []*Task `json:"task_list"` + ShowNext bool `json:"show_next"` + }{ + rows[0:max_len], + len(rows) > 10, + }) }) } diff --git a/main.go b/main.go index b31e8bf..b2a908d 100644 --- a/main.go +++ b/main.go @@ -8,10 +8,10 @@ import ( _ "github.com/lib/pq" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/models" - . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks" models_utils "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils" - . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" + . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/runner" + . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" ) const ( @@ -35,10 +35,10 @@ func main() { defer db.Close() log.Info("Starting server on :5002!") - config := LoadConfig() - log.Info("Config loaded!", "config", config) + config := LoadConfig() + log.Info("Config loaded!", "config", config) - StartRunners(db, config) + StartRunners(db, config) //TODO check if file structure exists to save data handle := NewHandler(db, config) @@ -59,7 +59,7 @@ func main() { usersEndpints(db, handle) HandleModels(handle) - HandleTasks(handle) + HandleTasks(handle) handle.Startup() } diff --git a/webpage/src/lib/Spinner.svelte b/webpage/src/lib/Spinner.svelte new file mode 100644 index 0000000..b9cba68 --- /dev/null +++ b/webpage/src/lib/Spinner.svelte @@ -0,0 +1,34 @@ + diff --git a/webpage/src/routes/models/edit/RunModel.svelte b/webpage/src/routes/models/edit/RunModel.svelte index 4575759..36400d2 100644 --- a/webpage/src/routes/models/edit/RunModel.svelte +++ b/webpage/src/routes/models/edit/RunModel.svelte @@ -1,95 +1,111 @@ -
+ diff --git a/webpage/src/routes/models/edit/TasksDataPage.svelte b/webpage/src/routes/models/edit/TasksDataPage.svelte index e0c263b..4d44dd9 100644 --- a/webpage/src/routes/models/edit/TasksDataPage.svelte +++ b/webpage/src/routes/models/edit/TasksDataPage.svelte @@ -1,16 +1,15 @@ -- {#if task.type == 1} - Image Run - {:else} - {task.type} - {/if} + {#if task.type == 1} + Image Run + {:else} + {task.type} + {/if} | {#if task.type == 1} @@ -83,42 +101,42 @@ {/if} | - {#if task.type == 1} - {#if task.status == 4} - {#if task.user_confirmed == 0} - User has not agreed to the result of this task - {:else if task.user_confirmed == -1} - User has disagred with the result of this task - {:else if task.user_confirmed == 1} - User has aggred with the result of this task - {:else} - TODO {task.user_confirmed} - {/if} - {:else} - - - {/if} - {:else} - TODO Handle {task.type} - {/if} + {#if task.type == 1} + {#if task.status == 4} + {#if task.user_confirmed == 0} + User has not agreed to the result of this task + {:else if task.user_confirmed == -1} + User has disagred with the result of this task + {:else if task.user_confirmed == 1} + User has aggred with the result of this task + {:else} + TODO {task.user_confirmed} + {/if} + {:else} + - + {/if} + {:else} + TODO Handle {task.type} + {/if} | -- {#if task.status == 4} - {#if task.type == 1} - {@const temp = JSON.parse(task.result)} - {temp.class}({temp.confidence * 100}%) - {:else} - {task.result} - {/if} - {/if} + | + {#if task.status == 4} + {#if task.type == 1} + {@const temp = JSON.parse(task.result)} + {temp.class}({temp.confidence * 100}%) + {:else} + {task.result} + {/if} + {/if} | -- {task.status} + | + {TaskTypeStrings[task.status]} | -- {task.status_message} + | + {task.status_message} | -- {(new Date(task.created)).toLocaleString()} + | + {new Date(task.created).toLocaleString()} |