Colors and styles; Live up and down with appwrite
This commit is contained in:
parent
5aa0458097
commit
2b89338e85
@ -6,6 +6,7 @@ const sdk = require('node-appwrite')
|
|||||||
const client = new sdk.Client()
|
const client = new sdk.Client()
|
||||||
const databases = new sdk.Databases(client)
|
const databases = new sdk.Databases(client)
|
||||||
const strftime = require('strftime')
|
const strftime = require('strftime')
|
||||||
|
const { entries } = require('./import.js')
|
||||||
client
|
client
|
||||||
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
||||||
.setProject('lifetracker') // Your project ID
|
.setProject('lifetracker') // Your project ID
|
||||||
|
|||||||
@ -22,10 +22,10 @@ var data = fs.readFileSync('data.csv')
|
|||||||
var comments = entry.slice(27).filter(x => x != "").join().replace(/^"/,"").replace(/"$/,'')
|
var comments = entry.slice(27).filter(x => x != "").join().replace(/^"/,"").replace(/"$/,'')
|
||||||
|
|
||||||
var dbEntry = {
|
var dbEntry = {
|
||||||
Date: date,
|
date: date,
|
||||||
Hours: hours,
|
hours: hours,
|
||||||
Mood: mood,
|
mood: mood,
|
||||||
Comments: comments
|
comments: comments
|
||||||
};
|
};
|
||||||
client
|
client
|
||||||
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
||||||
|
|||||||
1
lifetracker-vue/package-lock.json
generated
1
lifetracker-vue/package-lock.json
generated
@ -12,6 +12,7 @@
|
|||||||
"appwrite": "^11.0.0",
|
"appwrite": "^11.0.0",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"handsontable": "^12.3.3",
|
"handsontable": "^12.3.3",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"node": "^20.0.0",
|
"node": "^20.0.0",
|
||||||
"pinia": "^2.0.35",
|
"pinia": "^2.0.35",
|
||||||
"vue": "^3.2.47",
|
"vue": "^3.2.47",
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
"appwrite": "^11.0.0",
|
"appwrite": "^11.0.0",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"handsontable": "^12.3.3",
|
"handsontable": "^12.3.3",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"node": "^20.0.0",
|
"node": "^20.0.0",
|
||||||
"pinia": "^2.0.35",
|
"pinia": "^2.0.35",
|
||||||
"vue": "^3.2.47",
|
"vue": "^3.2.47",
|
||||||
|
|||||||
69
lifetracker-vue/src/assets/colors.css
Normal file
69
lifetracker-vue/src/assets/colors.css
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
:root{
|
||||||
|
--white: white;
|
||||||
|
--black: #273036;
|
||||||
|
--red: #c71634;
|
||||||
|
--cyan: #005744;
|
||||||
|
--pink: #ff65ae;
|
||||||
|
--blue: #00a9b3;
|
||||||
|
--green: #189749;
|
||||||
|
--yellow: #fff336;
|
||||||
|
--orange: #ff6d01;
|
||||||
|
--purple: #5b3ab1;
|
||||||
|
--darkred: #ff2816;
|
||||||
|
--lime: #bfff55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.handsontable * {
|
||||||
|
border: 0px !important;
|
||||||
|
text-align: center !important;
|
||||||
|
vertical-align: middle !important;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.handsontable td, .handsontable th{
|
||||||
|
font-family: monospace;
|
||||||
|
color: var(--white);
|
||||||
|
background: var(--black);
|
||||||
|
}
|
||||||
|
|
||||||
|
th{
|
||||||
|
color: gray !important;
|
||||||
|
}
|
||||||
|
td.color-black{
|
||||||
|
background: var(--black);
|
||||||
|
}
|
||||||
|
td.color-red{
|
||||||
|
background: var(--red);
|
||||||
|
}
|
||||||
|
td.color-blue{
|
||||||
|
background: var(--blue);
|
||||||
|
}
|
||||||
|
td.color-green{
|
||||||
|
background: var(--green);
|
||||||
|
}
|
||||||
|
td.color-purple{
|
||||||
|
background: var(--purple);
|
||||||
|
}
|
||||||
|
td.color-lime{
|
||||||
|
background: var(--lime);
|
||||||
|
color: var(--black);
|
||||||
|
}
|
||||||
|
td.color-cyan{
|
||||||
|
background: var(--cyan);
|
||||||
|
}
|
||||||
|
td.color-darkred{
|
||||||
|
background: var(--darkred);
|
||||||
|
}
|
||||||
|
td.color-pink{
|
||||||
|
background: var(--pink);
|
||||||
|
}
|
||||||
|
td.color-orange{
|
||||||
|
background: var(--orange);
|
||||||
|
}
|
||||||
|
td.color-yellow{
|
||||||
|
background: var(--yellow);
|
||||||
|
color: var(--black);
|
||||||
|
}
|
||||||
|
h2{
|
||||||
|
color:green;
|
||||||
|
}
|
||||||
@ -8,7 +8,9 @@ storeSession.connect();
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="!storeSession.isConnected">
|
<div v-if="!storeSession.isConnected">
|
||||||
Not connected.
|
<button @click="storeSession.loginAsRyan()">
|
||||||
|
Connect
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="storeSession.isConnected">
|
<div v-if="storeSession.isConnected">
|
||||||
Connected as {{ storeSession.session.userId }}.
|
Connected as {{ storeSession.session.userId }}.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Client, Databases, Account } from "appwrite";
|
import { Client, Databases, Account, Query } from "appwrite";
|
||||||
|
|
||||||
class AppwriteService {
|
class AppwriteService {
|
||||||
databaseId = 'lifetracker-db';
|
databaseId = 'lifetracker-db';
|
||||||
@ -41,7 +41,11 @@ class AppwriteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getEntries = async () => {
|
getEntries = async () => {
|
||||||
return (await this.database.listDocuments(this.databaseId, this.collectionId)).documents;
|
return (await this.database.listDocuments(
|
||||||
|
this.databaseId, this.collectionId,
|
||||||
|
[Query.orderAsc("date")]
|
||||||
|
)
|
||||||
|
).documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
logout = () => {
|
logout = () => {
|
||||||
|
|||||||
@ -18,18 +18,23 @@ export const useSessionStore = defineStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
logout() {
|
logout() {
|
||||||
const promise = account.deleteSession(this.session.id);
|
const promise = account.deleteSession(this.session['id']);
|
||||||
var self = this;
|
var self = this;
|
||||||
promise.then(function (response) {
|
promise.then(
|
||||||
self.session = {
|
function (response) {
|
||||||
|
self.session = [
|
||||||
|
{
|
||||||
email: '',
|
email: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
id: '',
|
id: '',
|
||||||
};
|
},
|
||||||
|
];
|
||||||
console.log(response); // Success
|
console.log(response); // Success
|
||||||
}, function (error) {
|
},
|
||||||
|
function (error) {
|
||||||
console.log(error); // Failure
|
console.log(error); // Failure
|
||||||
});
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
connect() {
|
connect() {
|
||||||
const promise = account.getSession('current');
|
const promise = account.getSession('current');
|
||||||
@ -56,7 +61,10 @@ export const useSessionStore = defineStore({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
login(email : string, password : string) {
|
loginAsRyan() {
|
||||||
|
this.login('ryan@ryanpandya.com', 'A(84)o9@38appwrite');
|
||||||
|
},
|
||||||
|
login(email: string, password: string) {
|
||||||
console.log(this.session);
|
console.log(this.session);
|
||||||
const promise = account.createEmailSession(email, password);
|
const promise = account.createEmailSession(email, password);
|
||||||
var session: ISession = {
|
var session: ISession = {
|
||||||
@ -65,15 +73,18 @@ export const useSessionStore = defineStore({
|
|||||||
id: '',
|
id: '',
|
||||||
};
|
};
|
||||||
var self = this;
|
var self = this;
|
||||||
promise.then(function (response) {
|
promise.then(
|
||||||
|
function (response) {
|
||||||
session.email = response.providerUid;
|
session.email = response.providerUid;
|
||||||
session.userId = response.userId;
|
session.userId = response.userId;
|
||||||
session.id = response.$id;
|
session.id = response.$id;
|
||||||
console.log('Logged in');
|
console.log('Logged in');
|
||||||
self.session = session;
|
self.session = session;
|
||||||
}, function (error) {
|
},
|
||||||
|
function (error) {
|
||||||
console.log('Error');
|
console.log('Error');
|
||||||
});
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
import { useDatabaseStore } from "@/stores/database"
|
import { useDatabaseStore } from "@/stores/database"
|
||||||
import Api from "@/services/Api"
|
import Api from "@/services/Api"
|
||||||
import appwrite from '@/services/appwrite';
|
import appwrite from '@/services/appwrite';
|
||||||
|
import moment from 'moment';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -10,10 +10,45 @@ import { defineComponent } from 'vue';
|
|||||||
import { HotTable } from '@handsontable/vue3';
|
import { HotTable } from '@handsontable/vue3';
|
||||||
import { registerAllModules } from 'handsontable/registry';
|
import { registerAllModules } from 'handsontable/registry';
|
||||||
import 'handsontable/dist/handsontable.full.css';
|
import 'handsontable/dist/handsontable.full.css';
|
||||||
|
import '../assets/colors.css';
|
||||||
import Handsontable from 'handsontable/base';
|
import Handsontable from 'handsontable/base';
|
||||||
// register Handsontable's modules
|
// register Handsontable's modules
|
||||||
registerAllModules();
|
registerAllModules();
|
||||||
|
|
||||||
|
function getHourClass(i) {
|
||||||
|
const colorMapping = {
|
||||||
|
0: "black",
|
||||||
|
1: "red",
|
||||||
|
2: "cyan",
|
||||||
|
3: "pink",
|
||||||
|
4: "blue",
|
||||||
|
5: "green",
|
||||||
|
6: "yellow",
|
||||||
|
7: "orange",
|
||||||
|
8: "purple",
|
||||||
|
9: "darkred",
|
||||||
|
10: "lime"
|
||||||
|
}
|
||||||
|
if (i == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "color-" + colorMapping[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hourCol(t) {
|
||||||
|
return {
|
||||||
|
data: "hours." + t,
|
||||||
|
type: 'numeric',
|
||||||
|
renderer(instance, td, row, col, prop, value) {
|
||||||
|
td.className = getHourClass(value);
|
||||||
|
td.innerText = value == null ? value : parseFloat(value);
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const colHeaders = ["DATE", "DAY", "12 AM"]
|
const colHeaders = ["DATE", "DAY", "12 AM"]
|
||||||
.concat(Array.from(new Array(11), (x, y) => y+1 + " AM") )
|
.concat(Array.from(new Array(11), (x, y) => y+1 + " AM") )
|
||||||
.concat(Array.from(new Array(12), (x, y) => y+1 + " PM") )
|
.concat(Array.from(new Array(12), (x, y) => y+1 + " PM") )
|
||||||
@ -26,21 +61,37 @@ const ExampleComponent = defineComponent({
|
|||||||
hotSettings: {
|
hotSettings: {
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
readOnly: true,
|
||||||
data: "date"
|
data: "date",
|
||||||
|
renderer(instance, td, row, col, prop, value) {
|
||||||
|
var date = new moment(value).utc().format("MM/DD");
|
||||||
|
td.className = "color-black";
|
||||||
|
td.innerText = date;
|
||||||
|
return td;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ renderer: 'text'},
|
{
|
||||||
Array.from(new Array(24), (a, b) => { renderer: 'hour'}),
|
readOnly: true,
|
||||||
{ renderer: 'text'},
|
data: "date",
|
||||||
{ renderer: 'text'}
|
renderer(instance, td, row, col, prop, value) {
|
||||||
|
var date = new moment(value).utc().format("ddd")
|
||||||
|
td.innerText = date;
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Array.from(new Array(24), (_, t) => hourCol(t)),
|
||||||
|
{ data: "mood", type: "numeric" },
|
||||||
|
{ data: "comments", style: "text-align:left;" }
|
||||||
].flat(),
|
].flat(),
|
||||||
colHeaders: colHeaders,
|
colHeaders: colHeaders,
|
||||||
rowHeaders: false,
|
rowHeaders: false,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
afterChange: () => {
|
afterChange: (changes) => {
|
||||||
if (this.hotRef) {
|
if (changes != null) {
|
||||||
console.log(this.hotRef.getSourceData());
|
var entry = this.entries[changes[0][0]];
|
||||||
|
entry.date = entry.date.replace(/T.*/, "");
|
||||||
|
appwrite.updateEntry(entry);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
licenseKey: 'non-commercial-and-evaluation'
|
licenseKey: 'non-commercial-and-evaluation'
|
||||||
@ -58,6 +109,7 @@ const ExampleComponent = defineComponent({
|
|||||||
subscribe(){
|
subscribe(){
|
||||||
console.log("subscribing");
|
console.log("subscribing");
|
||||||
appwrite.subscribe((payload) => {
|
appwrite.subscribe((payload) => {
|
||||||
|
console.log("Caught " + payload);
|
||||||
var event = payload.events.filter((e) =>
|
var event = payload.events.filter((e) =>
|
||||||
e.match(/databases\.\*\.collections\.\*\.documents\.\*\.\w+/)
|
e.match(/databases\.\*\.collections\.\*\.documents\.\*\.\w+/)
|
||||||
)[0].replace(/.+\./,"");
|
)[0].replace(/.+\./,"");
|
||||||
@ -96,12 +148,12 @@ export default ExampleComponent;
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button @click="updateTable">Fetch</button>
|
<!-- <button @click="updateTable">Fetch</button>
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="e in entries" :key="e">
|
<li v-for="e in entries" :key="e">
|
||||||
{{ e }}
|
{{ e }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul> -->
|
||||||
<hot-table ref="wrapper" :settings="hotSettings" :data="entries"></hot-table>
|
<hot-table ref="wrapper" :settings="hotSettings" :data="entries"></hot-table>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user