add ability to agree with results closes #96
This commit is contained in:
parent
f165e9e744
commit
00ddb91a22
29
logic/tasks/agreement.go
Normal file
29
logic/tasks/agreement.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
||||||
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
|
||||||
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handleRequests(x *Handle) {
|
||||||
|
type AgreementRequest struct {
|
||||||
|
Id string `json:"id" validate:"required"`
|
||||||
|
Agreement int `json:"agreement" validate:"required"`
|
||||||
|
}
|
||||||
|
PostAuthJson(x, "/task/agreement", User_Normal, func(c *Context, dat *AgreementRequest) *Error {
|
||||||
|
var task Task
|
||||||
|
err := GetDBOnce(c, &task, "tasks where id=$1", dat.Id)
|
||||||
|
if err == ModelNotFoundError {
|
||||||
|
return c.JsonBadRequest("Model not found")
|
||||||
|
} else if err != nil {
|
||||||
|
return c.E500M("Failed to get task data", err)
|
||||||
|
}
|
||||||
|
err = task.SetAgreement(c, TaskAgreement(dat.Agreement))
|
||||||
|
if err != nil {
|
||||||
|
return c.E500M("Failed to update task data", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendJSON(JustId{Id: dat.Id})
|
||||||
|
})
|
||||||
|
}
|
@ -7,5 +7,5 @@ import (
|
|||||||
func HandleTasks(handle *Handle) {
|
func HandleTasks(handle *Handle) {
|
||||||
handleUpload(handle)
|
handleUpload(handle)
|
||||||
handleList(handle)
|
handleList(handle)
|
||||||
|
handleRequests(handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,23 @@ const (
|
|||||||
TASK_TYPE_RETRAINING
|
TASK_TYPE_RETRAINING
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TaskAgreement int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TASK_AGREE_DISAGRE TaskAgreement = -1 + iota
|
||||||
|
TASK_AGREE_NONE
|
||||||
|
TASK_AGREE_AGREE
|
||||||
|
)
|
||||||
|
|
||||||
func (t Task) UpdateStatus(base BasePack, status TaskStatus, message string) (err error) {
|
func (t Task) UpdateStatus(base BasePack, status TaskStatus, message string) (err error) {
|
||||||
return UpdateTaskStatus(base, t.Id, status, message)
|
return UpdateTaskStatus(base, t.Id, status, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t Task) SetAgreement(base BasePack, agreement TaskAgreement) (err error) {
|
||||||
|
_, err = base.GetDb().Exec("update tasks set user_confirmed=$1 where id=$2", agreement, t.Id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the UpdateStatus function and logs on the case of failure!
|
* Call the UpdateStatus function and logs on the case of failure!
|
||||||
* This varient does not return any error message
|
* This varient does not return any error message
|
||||||
|
@ -32,10 +32,11 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { post } from 'src/lib/requests.svelte';
|
import { post, showMessage } from 'src/lib/requests.svelte';
|
||||||
import type { Model } from './+page.svelte';
|
import type { Model } from './+page.svelte';
|
||||||
|
import MessageSimple from 'src/lib/MessageSimple.svelte';
|
||||||
|
|
||||||
let { model } = $props<{ model: Model; uploadCounter?: number }>();
|
let { model }: { model: Model } = $props();
|
||||||
|
|
||||||
let page = $state(0);
|
let page = $state(0);
|
||||||
let showNext = $state(false);
|
let showNext = $state(false);
|
||||||
@ -59,10 +60,27 @@
|
|||||||
getList();
|
getList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let userPreceptionMessages: MessageSimple;
|
||||||
|
// This returns a function that performs the call and does not do the call it self
|
||||||
|
function userPreception(task: string, agree: number) {
|
||||||
|
return async function () {
|
||||||
|
try {
|
||||||
|
await post('task/agreement', {
|
||||||
|
id: task,
|
||||||
|
agreement: agree
|
||||||
|
});
|
||||||
|
getList();
|
||||||
|
} catch (e) {
|
||||||
|
showMessage(e, userPreception);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>Tasks</h2>
|
<h2>Tasks</h2>
|
||||||
|
<MessageSimple bind:this={userPreceptionMessages} />
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -116,6 +134,16 @@
|
|||||||
{:else}
|
{:else}
|
||||||
TODO {task.user_confirmed}
|
TODO {task.user_confirmed}
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if task.user_confirmed == -1}
|
||||||
|
<button type="button" on:click={userPreception(task.id, 1)}>
|
||||||
|
<span class="bi bi-check"></span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
{#if task.user_confirmed == 1}
|
||||||
|
<button class="danger" type="button" on:click={userPreception(task.id, -1)}>
|
||||||
|
<span class="bi bi-x-lg"></span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
-
|
-
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
Reference in New Issue
Block a user