feat: add button to remove image from class
This commit is contained in:
parent
eb20c1b0ac
commit
3f828ab855
@ -376,6 +376,35 @@ func processZipFileExpand(c *Context, model *BaseModel) {
|
|||||||
ModelUpdateStatus(c, model.Id, READY)
|
ModelUpdateStatus(c, model.Id, READY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func handleRemoveDataPoint(c *Context) *Error {
|
||||||
|
var dat JustId
|
||||||
|
if err := c.ToJSON(&dat); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var GetModelId struct {
|
||||||
|
Value string `db:"m.id"`
|
||||||
|
Format string `db:"m.format"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err := GetDBOnce(c, &GetModelId, "model_data_point as mdp inner join model_classes as mc on mdp.class_id=mc.id inner join models as m on m.id=mc.model_id where mdp.id=$1;", dat.Id)
|
||||||
|
if err == NotFoundError {
|
||||||
|
return c.SendJSONStatus(404, "Data point not found")
|
||||||
|
} else if err != nil {
|
||||||
|
return c.E500M("Failed to find data point", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Remove(path.Join("savedData", GetModelId.Value, "data", dat.Id+"."+GetModelId.Format))
|
||||||
|
|
||||||
|
_, err = c.Db.Exec("delete from model_data_point where id=$1;", dat.Id)
|
||||||
|
if err != nil {
|
||||||
|
return c.E500M("Failed to remove datapoint from database", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendJSON("ok")
|
||||||
|
}
|
||||||
|
|
||||||
func handleDataUpload(handle *Handle) {
|
func handleDataUpload(handle *Handle) {
|
||||||
handle.Post("/models/data/upload", func(c *Context) *Error {
|
handle.Post("/models/data/upload", func(c *Context) *Error {
|
||||||
if !c.CheckAuthLevel(1) {
|
if !c.CheckAuthLevel(1) {
|
||||||
@ -501,17 +530,14 @@ func handleDataUpload(handle *Handle) {
|
|||||||
return c.SendJSON(model.Id)
|
return c.SendJSON(model.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
handle.Delete("/models/data/point", handleRemoveDataPoint)
|
||||||
|
|
||||||
handle.Delete("/models/data/delete-zip-file", func(c *Context) *Error {
|
handle.Delete("/models/data/delete-zip-file", func(c *Context) *Error {
|
||||||
if !c.CheckAuthLevel(1) {
|
if !c.CheckAuthLevel(1) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModelData struct {
|
var dat JustId
|
||||||
Id string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var dat ModelData
|
|
||||||
|
|
||||||
if err := c.ToJSON(&dat); err != nil {
|
if err := c.ToJSON(&dat); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,16 @@ func (x *Handle) Delete(path string, fn func(c *Context) *Error) {
|
|||||||
x.deletes = append(x.deletes, HandleFunc{path, fn})
|
x.deletes = append(x.deletes, HandleFunc{path, fn})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Handle) DeleteAuth(path string, authLevel int, fn func(c *Context) *Error) {
|
||||||
|
inner_fn := func(c *Context) *Error {
|
||||||
|
if !c.CheckAuthLevel(authLevel) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fn(c)
|
||||||
|
}
|
||||||
|
x.posts = append(x.posts, HandleFunc{path, inner_fn})
|
||||||
|
}
|
||||||
|
|
||||||
func (x *Handle) handleGets(context *Context) {
|
func (x *Handle) handleGets(context *Context) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -204,7 +204,7 @@ func MyParseForm(r *http.Request) (vs url.Values, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type JustId struct{ Id string }
|
type JustId struct{ Id string `json:"id" validate:"required"` }
|
||||||
|
|
||||||
type Generic struct{ reflect.Type }
|
type Generic struct{ reflect.Type }
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Tabs from 'src/lib/Tabs.svelte';
|
import Tabs from 'src/lib/Tabs.svelte';
|
||||||
import type { Class } from './ModelData.svelte';
|
import type { Class } from './ModelData.svelte';
|
||||||
import { get, postFormData } from 'src/lib/requests.svelte';
|
import { get, postFormData, rdelete } from 'src/lib/requests.svelte';
|
||||||
import type { Model } from './+page.svelte';
|
import type { Model } from './+page.svelte';
|
||||||
import FileUpload from 'src/lib/FileUpload.svelte';
|
import FileUpload from 'src/lib/FileUpload.svelte';
|
||||||
import MessageSimple from 'src/lib/MessageSimple.svelte';
|
import MessageSimple from 'src/lib/MessageSimple.svelte';
|
||||||
@ -88,6 +88,16 @@
|
|||||||
|
|
||||||
uploading = Promise.resolve();
|
uploading = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteDataPoint(id: string) {
|
||||||
|
try {
|
||||||
|
rdelete('models/data/point', { id })
|
||||||
|
getList()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('TODO notify user', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if classes.length == 0}
|
{#if classes.length == 0}
|
||||||
@ -219,6 +229,9 @@
|
|||||||
<th>
|
<th>
|
||||||
<!-- Status -->
|
<!-- Status -->
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
<!-- Remove -->
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -258,6 +271,11 @@
|
|||||||
<span class="bi bi-exclamation-triangle-fill" style="color: red"></span>
|
<span class="bi bi-exclamation-triangle-fill" style="color: red"></span>
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
|
<td style="width: 3ch">
|
||||||
|
<button class="danger" on:click={() => deleteDataPoint(image.id)}>
|
||||||
|
<span class="bi bi-trash"></span>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user