diff --git a/logic/models/data.go b/logic/models/data.go
index 0cf7729..09aa640 100644
--- a/logic/models/data.go
+++ b/logic/models/data.go
@@ -459,6 +459,45 @@ func handleDataUpload(handle *Handle) {
return c.SendJSON(model.Id)
})
+ // Create New class
+ type CreateNewEmptyClass struct {
+ Id string `json:"id" validate:"required"`
+ Name string `json:"name" validate:"required"`
+ }
+ PostAuthJson(handle, "/models/data/class/new", User_Normal, func(c *Context, obj *CreateNewEmptyClass) *Error {
+ model, err := GetBaseModel(c.Db, obj.Id)
+ if err == ModelNotFoundError {
+ return c.JsonBadRequest("Model not found")
+ }
+
+ if model.ModelType != 2 && model.Status != CONFIRM_PRE_TRAINING || model.ModelType == 2 && model.Status != CONFIRM_PRE_TRAINING && model.Status != READY {
+ return c.JsonBadRequest("Model not in the correct status for adding new class")
+ }
+
+ var baseOrder struct {
+ Order int `db:"class_order"`
+ }
+ err = GetDBOnce(c, &baseOrder, "model_classes where model_id=$1 order by class_order desc;", model.Id)
+ if err != nil {
+ return c.E500M("Could not create class", err)
+ }
+
+ id, err := model_classes.CreateClass(c.Db, model.Id, baseOrder.Order+1, obj.Name)
+ if err == model_classes.ClassAlreadyExists {
+ return c.JsonBadRequest("Class Already exists")
+ } else if err != nil {
+ return c.E500M("Could not create class", err)
+ }
+
+ var modelClass model_classes.ModelClass
+ err = GetDBOnce(c, &modelClass, "model_classes where id=$1;", id)
+ if err != nil {
+ return c.E500M("Failed to get class information but class was creted", err)
+ }
+
+ return c.SendJSON(modelClass)
+ })
+
// ------
// ------ CLASS DATA UPLOAD
// ------
diff --git a/webpage/src/lib/KeepPageSize.svelte b/webpage/src/lib/KeepPageSize.svelte
new file mode 100644
index 0000000..9260b21
--- /dev/null
+++ b/webpage/src/lib/KeepPageSize.svelte
@@ -0,0 +1,11 @@
+
+
+
diff --git a/webpage/src/lib/requests.svelte.ts b/webpage/src/lib/requests.svelte.ts
index 2f98462..5545f99 100644
--- a/webpage/src/lib/requests.svelte.ts
+++ b/webpage/src/lib/requests.svelte.ts
@@ -99,3 +99,19 @@ export async function postFormData(url: string, body: FormData) {
return r.json();
}
+
+export async function showMessage(
+ e: any,
+ messages: any,
+ message = 'Could not complete request'
+): Promise {
+ if (e == null) {
+ return false;
+ } else if (e instanceof Response) {
+ messages.display(await e.json());
+ return true;
+ } else {
+ messages.display(message);
+ return true;
+ }
+}
diff --git a/webpage/src/routes/models/edit/+page.svelte b/webpage/src/routes/models/edit/+page.svelte
index 19cf0a0..2e09629 100644
--- a/webpage/src/routes/models/edit/+page.svelte
+++ b/webpage/src/routes/models/edit/+page.svelte
@@ -42,6 +42,7 @@
import ModelDataPage from './ModelDataPage.svelte';
import 'src/styles/forms.css';
+ import KeepPageSize from 'src/lib/KeepPageSize.svelte';
let model: Promise = $state(new Promise(() => {}));
let _model: Model | undefined = $state(undefined);
@@ -87,7 +88,6 @@
});
let resetMessages: MessageSimple;
-
async function resetModel() {
resetMessages.display('');
@@ -125,11 +125,7 @@
{/await}
-
+
diff --git a/webpage/src/routes/models/edit/ModelTable.svelte b/webpage/src/routes/models/edit/ModelTable.svelte
index cf6c316..daa76f7 100644
--- a/webpage/src/routes/models/edit/ModelTable.svelte
+++ b/webpage/src/routes/models/edit/ModelTable.svelte
@@ -10,17 +10,22 @@