add possibility to add attributes to an object

feat/vaults
Tomáš Mládek 2021-02-21 17:48:15 +01:00
parent 367698bfbe
commit 9261aac086
1 changed files with 42 additions and 3 deletions

View File

@ -14,7 +14,7 @@
</tr> </tr>
<tr v-for="[id, entry] in attributes"> <tr v-for="[id, entry] in attributes">
<td> <td>
<sl-icon-button name="x-circle" @click="removeAttribute(id)"/> <sl-icon-button name="x-circle" @click="removeEntry(id)"/>
</td> </td>
<td>{{ entry.key }}</td> <td>{{ entry.key }}</td>
<td> <td>
@ -24,6 +24,17 @@
</template> </template>
</td> </td>
</tr> </tr>
<tr>
<td>
<sl-icon-button name="plus-circle" @click="addEntry()"/>
</td>
<td>
<sl-input v-sl-model:newEntryKey/>
</td>
<td>
<sl-input v-sl-model:newEntryValue/>
</td>
</tr>
</table> </table>
</template> </template>
<template v-if="backlinks.length"> <template v-if="backlinks.length">
@ -63,7 +74,16 @@ export default defineComponent({
Address, Address,
}, },
props: { props: {
"address": String "address": {
type: String,
required: true
}
},
data: () => {
return {
newEntryKey: "",
newEntryValue: ""
};
}, },
computed: { computed: {
objectEntries(): [string, IEntry][] { objectEntries(): [string, IEntry][] {
@ -85,11 +105,30 @@ export default defineComponent({
} }
}, },
methods: { methods: {
async removeAttribute(id: string) { async removeEntry(id: string) {
if (confirm("Are you sure you want to remove the attribute?")) { if (confirm("Are you sure you want to remove the attribute?")) {
await fetch(`/api/obj/${id}`, {method: "DELETE"}); await fetch(`/api/obj/${id}`, {method: "DELETE"});
await this.mutate(); await this.mutate();
} }
},
async addEntry() {
await fetch(`/api/obj`, {
method: "PUT",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({
target: this.address,
key: this.newEntryKey,
value: {
t: "Value",
c: this.newEntryValue
}
})
});
await this.mutate();
this.newEntryKey = "";
this.newEntryValue = "";
} }
}, },
setup(props) { setup(props) {