Moved server, added backend structs and added ui elements.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {defineStore} from "pinia";
|
||||
import type {Entity} from "~/types/entity";
|
||||
import type {Article} from "~/types/article";
|
||||
import {NotificationMessage} from "~/types/notificationMessage";
|
||||
import type {RuntimeConfig} from "nuxt/schema";
|
||||
|
||||
@@ -10,8 +10,8 @@ interface State {
|
||||
notifications: NotificationMessage[],
|
||||
notificationQueue: NotificationMessage[],
|
||||
|
||||
// Entity
|
||||
entity: Entity | null,
|
||||
// Article
|
||||
article: Article | null,
|
||||
}
|
||||
|
||||
export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
@@ -22,8 +22,8 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
notifications: [],
|
||||
notificationQueue: [],
|
||||
|
||||
// Entity
|
||||
entity: null,
|
||||
// Article
|
||||
article: null,
|
||||
}),
|
||||
actions: {
|
||||
// Notification
|
||||
@@ -88,33 +88,45 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
},
|
||||
|
||||
|
||||
// Entity
|
||||
async loadEntity(entityID: number) {
|
||||
// Article
|
||||
async loadArticle(articleID: number) {
|
||||
try {
|
||||
const entity: Entity = await $fetch<Entity>(this.config.public.url + '/entity/' + entityID, {
|
||||
const entity: Article = await $fetch<Article>(this.config.public.url + '/article/' + articleID, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
this.entity = entity;
|
||||
this.addNotification(false, 'Artikel geladen: ' + this.entity.name);
|
||||
this.article = entity;
|
||||
this.addNotification(false, 'Artikel geladen: ' + this.article.name);
|
||||
} catch {
|
||||
this.entity = null;
|
||||
this.addNotification(true, 'Fehler beim laden des Artikel. ID:' + entityID);
|
||||
this.article = null;
|
||||
this.addNotification(true, 'Fehler beim laden des Artikel. ID:' + articleID);
|
||||
}
|
||||
},
|
||||
|
||||
async updateEntity(entity: Entity) {
|
||||
if (this.entity != null) {
|
||||
async createArticle(article: Article) {
|
||||
try {
|
||||
this.article = await $fetch<Article>(this.config.public.url + '/article', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(article),
|
||||
});
|
||||
|
||||
this.addNotification(false, 'Artikel "' + article.name + '" erstellt');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim erstellen des Artikel: ' + article.name);
|
||||
}
|
||||
},
|
||||
|
||||
async updateArticle(article: Article) {
|
||||
if (this.article != null) {
|
||||
try {
|
||||
const entity: Entity = await $fetch<Entity>(this.config.public.url + '/entity/update', {
|
||||
this.article = await $fetch<Article>(this.config.public.url + '/article/update', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(this.entity),
|
||||
body: JSON.stringify(this.article),
|
||||
});
|
||||
|
||||
this.entity = entity;
|
||||
this.addNotification(false, 'Artikel "' + this.entity.name + '" aktualisiert');
|
||||
this.addNotification(false, 'Artikel "' + this.article.name + '" aktualisiert');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Artikel: ' + this.entity.name);
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Artikel: ' + this.article.name);
|
||||
}
|
||||
} else {
|
||||
this.addNotification(true, 'Es ist kein Artikel ausgewählt');
|
||||
@@ -122,7 +134,7 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
},
|
||||
|
||||
clearEntity() {
|
||||
this.entity = null;
|
||||
this.article = null;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user