add type, validation & toast
This commit is contained in:
@@ -1,22 +1,57 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { BField, BInput, BButton } from "buefy";
|
import { BField, BInput, BButton, useToast } from "buefy";
|
||||||
import { apiClient } from "@/services/api";
|
import { apiClient } from "@/services/api";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
let knowledgeText = ""
|
import type { Knowledge } from "@/types/types";
|
||||||
function postKnowledge(){
|
|
||||||
let knowlegde = {
|
const knowledgeModel = ref<string>("")
|
||||||
content: knowledgeText,
|
const uriModel = ref<string>("")
|
||||||
uri: "wiki"
|
|
||||||
|
const Toast = useToast()
|
||||||
|
|
||||||
|
async function postKnowledge(){
|
||||||
|
const knowledge: Knowledge = {
|
||||||
|
id: null,
|
||||||
|
content: knowledgeModel.value,
|
||||||
|
uri: uriModel.value
|
||||||
}
|
}
|
||||||
apiClient.post("api/v1/knowledges/", knowlegde)
|
if(validation(knowledge)){
|
||||||
|
try {
|
||||||
|
await apiClient.post("api/v1/knowledges/", knowledge)
|
||||||
|
Toast.open({message: "Knowledge collected", type: "is-success"})
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
Toast.open({message: "Data entry error", type: "is-danger"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validation(knowledge: Knowledge){
|
||||||
|
return knowledge.content && knowledge.uri
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Collect Knowledge</h2>
|
<h2>Collect Knowledge</h2>
|
||||||
<b-field label="Knowledge">
|
<b-field label="Knowledge">
|
||||||
<b-input maxlength="1200" type="textarea" v-model="knowledgeText"></b-input>
|
<!-- @vue-ignore -->
|
||||||
|
<b-input
|
||||||
|
v-model="knowledgeModel"
|
||||||
|
maxlength="1200"
|
||||||
|
type="textarea"
|
||||||
|
required
|
||||||
|
></b-input>
|
||||||
|
</b-field>
|
||||||
|
<b-field label="URI">
|
||||||
|
<!-- @vue-ignore -->
|
||||||
|
<b-input
|
||||||
|
v-model="uriModel"
|
||||||
|
maxlength="100"
|
||||||
|
required
|
||||||
|
></b-input>
|
||||||
</b-field>
|
</b-field>
|
||||||
<b-button type="is-primary" @click="postKnowledge" >Submit</b-button>
|
<b-button type="is-primary" @click="postKnowledge" >Submit</b-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
20
user-interface/src/types/types.ts
Normal file
20
user-interface/src/types/types.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
interface Knowledge {
|
||||||
|
id: number | null,
|
||||||
|
content: string,
|
||||||
|
uri: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Question {
|
||||||
|
id: number | null,
|
||||||
|
question: string,
|
||||||
|
knowledgId: number,
|
||||||
|
metric: Metric | null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Metric {
|
||||||
|
id: number | null,
|
||||||
|
questionId: number,
|
||||||
|
needIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type {Knowledge, Question, Metric}
|
||||||
Reference in New Issue
Block a user