Fixing bug
This commit is contained in:
@@ -43,7 +43,10 @@ class AppwriteService {
|
||||
getEntries = async () => {
|
||||
return (await this.database.listDocuments(
|
||||
this.databaseId, this.collectionId,
|
||||
[Query.orderAsc("date")]
|
||||
[
|
||||
Query.orderAsc("date"),
|
||||
//Query.limit(365)
|
||||
]
|
||||
)
|
||||
).documents;
|
||||
}
|
||||
|
||||
@@ -1,114 +1,42 @@
|
||||
<script setup>
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import Api from "@/services/Api";
|
||||
|
||||
import appwrite from '@/services/appwrite';
|
||||
|
||||
const storeSession = useSessionStore();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var email; var userId; var password; var session;
|
||||
export default {
|
||||
async mounted(){
|
||||
this.user = await appwrite.getUser();
|
||||
this.entries = await appwrite.getEntries();
|
||||
this.subscribe();
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
user: null,
|
||||
entries: [],
|
||||
testEntry: {
|
||||
date: "2023-12-18",
|
||||
hours: [1, 2, 3],
|
||||
mood: 5,
|
||||
comments: "Moot"
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getEntries() {
|
||||
this.entries = appwrite.getEntries();
|
||||
},
|
||||
subscribe(){
|
||||
console.log("subscribing");
|
||||
appwrite.subscribe((payload) => {
|
||||
var event = payload.events.filter((e) =>
|
||||
e.match(/databases\.\*\.collections\.\*\.documents\.\*\.\w+/)
|
||||
)[0].replace(/.+\./,"");
|
||||
switch (event) {
|
||||
case 'create':
|
||||
this.entries.push(payload.payload)
|
||||
this.entries = this.entries
|
||||
break
|
||||
case 'update':
|
||||
this.entries = this.entries.map((day) => {
|
||||
if (day.$id === payload.payload.$id) {
|
||||
return payload.payload
|
||||
} else {
|
||||
return day
|
||||
}
|
||||
})
|
||||
break
|
||||
case 'delete':
|
||||
this.entries = this.entries.filter((day) => day.$id !== payload.payload.$id)
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
import { defineComponent } from 'vue';
|
||||
import { HotTable } from '@handsontable/vue3';
|
||||
import { registerAllModules } from 'handsontable/registry';
|
||||
import 'handsontable/dist/handsontable.full.css';
|
||||
|
||||
// register Handsontable's modules
|
||||
registerAllModules();
|
||||
|
||||
const ExampleComponent = defineComponent({
|
||||
data() {
|
||||
return {
|
||||
hotSettings: {
|
||||
data: [
|
||||
['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
|
||||
['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
|
||||
['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
|
||||
['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
|
||||
['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
|
||||
['A6', 'B6', 'C6', 'D6', 'E6', 'F6', 'G6', 'H6', 'I6', 'J6'],
|
||||
],
|
||||
colHeaders: true,
|
||||
height: 'auto',
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
}
|
||||
};
|
||||
},
|
||||
components: {
|
||||
HotTable,
|
||||
}
|
||||
});
|
||||
|
||||
export default ExampleComponent;
|
||||
</script>
|
||||
<template>
|
||||
<div v-if="storeSession.isConnected == null">
|
||||
Loading...
|
||||
</div>
|
||||
<div v-if="storeSession.isConnected == ''" id="form">
|
||||
<h2>Not connected yet.</h2>
|
||||
<div id="login">
|
||||
<input name="email" type="text" v-model="email" placeholder="email" />
|
||||
<input name="password" type="password" v-model="password" placeholder="password"/>
|
||||
<button @click="storeSession.login(email, password)">Connect to database</button>
|
||||
<h3 class="error" v-if="error">{{ error }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="storeSession.isConnected">
|
||||
<h2>Welcome back, {{ storeSession.session.userId }}!</h2>
|
||||
|
||||
<div>
|
||||
{{ entries }}
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<li><input v-model='testEntry.date'/></li>
|
||||
<li><input v-model='testEntry.hours'/></li>
|
||||
<li><input v-model='testEntry.mood'/></li>
|
||||
<li><input v-model='testEntry.comments'/></li>
|
||||
</ul>
|
||||
<button @click="appwrite.addEntry(testEntry)">Add Entry</button>
|
||||
<button @click="appwrite.updateEntry(testEntry)">Update Entry</button>
|
||||
<button @click="appwrite.deleteEntry(testEntry.date)">Delete Entry</button>
|
||||
|
||||
<div class="flex">
|
||||
<button @click="storeSession.logout()">Log Out</button>
|
||||
</div>
|
||||
<div id="example1">
|
||||
<hot-table :settings="hotSettings"></hot-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
div#form{
|
||||
display:flex;
|
||||
flex-direction: column;
|
||||
gap: 1em;
|
||||
width: 200px;
|
||||
|
||||
}
|
||||
h3.error{
|
||||
color: var(--darkred);
|
||||
}
|
||||
div#login{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user