Moving some UI files and create no UI elements. Also updates to sqlite plugin.
This commit is contained in:
parent
54f16d0ac2
commit
a88d85d3bc
80
.gitignore
vendored
80
.gitignore
vendored
@ -1,40 +1,40 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
.npm
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# IDEs
|
||||
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# build directory
|
||||
dist/
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
.npm
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# IDEs
|
||||
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# build directory
|
||||
dist/
|
||||
|
||||
10
.parcelrc
10
.parcelrc
@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": "@parcel/config-default",
|
||||
"transformers": {
|
||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
||||
}
|
||||
{
|
||||
"extends": "@parcel/config-default",
|
||||
"transformers": {
|
||||
"*.riot": ["@riotjs/parcel-transformer-riot"]
|
||||
}
|
||||
}
|
||||
40
index.html
40
index.html
@ -1,21 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
|
||||
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
|
||||
<title>Time Chain</title>
|
||||
<link rel="stylesheet" href="src/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="loading" >
|
||||
<h1>Time Chain!</h1>
|
||||
<p>Time traveling your data! Comming soon...</p>
|
||||
<p id="timestamp"></p>
|
||||
<img src="src/img/chain2.svg" class="rotate">
|
||||
</div>
|
||||
|
||||
<script type="module" src="src/dist/start.js"></script>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
|
||||
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
|
||||
<title>Time Chain</title>
|
||||
<link rel="stylesheet" href="src/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="loading" >
|
||||
<h1>Time Chain!</h1>
|
||||
<p>Time traveling your data! Comming soon...</p>
|
||||
<p id="timestamp"></p>
|
||||
<img src="src/img/chain2.svg" class="rotate">
|
||||
</div>
|
||||
|
||||
<script type="module" src="src/dist/start.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,31 +1,31 @@
|
||||
body {
|
||||
background-color: #333;
|
||||
color: whitesmoke;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 5em;
|
||||
}
|
||||
|
||||
.loading img {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.loading p {
|
||||
font-weight: 700;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.rotate {
|
||||
animation: rotation 2s infinite linear;
|
||||
}
|
||||
|
||||
@keyframes rotation {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
body {
|
||||
background-color: #333;
|
||||
color: whitesmoke;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 5em;
|
||||
}
|
||||
|
||||
.loading img {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.loading p {
|
||||
font-weight: 700;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.rotate {
|
||||
animation: rotation 2s infinite linear;
|
||||
}
|
||||
|
||||
@keyframes rotation {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@ -1,35 +1,35 @@
|
||||
const InterfaceRecord = {
|
||||
find(search,limit,offset){},
|
||||
get(uuid){},
|
||||
add(uuid,timestamp,content,mime,hash){},
|
||||
update(uuid,timestamp,content,mime,hash){},
|
||||
delete(uuid){},
|
||||
}
|
||||
|
||||
const InterfaceFile = {
|
||||
add(uuid_record,uuid,timestamp,content,mime,hash){},
|
||||
getByRecord(uuid_record){},
|
||||
get(uuid){},
|
||||
delete(uuid){},
|
||||
deleteRecord(uuid_record){},
|
||||
update(uuid,timestamp,content,mime,hash){}
|
||||
}
|
||||
|
||||
const InterfaceTag = {
|
||||
add(uuid,word){},
|
||||
delete(uuid){}
|
||||
}
|
||||
|
||||
const InterfaceTagLink = {
|
||||
add(uuid_record,uuid_tag){},
|
||||
delete(uuid_record,uuid_tag){},
|
||||
deleteTag(uuid){},
|
||||
deleteRecord(uuid){}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
InterfaceTagLink,
|
||||
InterfaceTag,
|
||||
InterfaceFile,
|
||||
InterfaceRecord
|
||||
const InterfaceRecord = {
|
||||
find(search,limit,offset){},
|
||||
get(uuid){},
|
||||
add(uuid,timestamp,content,mime,hash){},
|
||||
update(uuid,timestamp,content,mime,hash){},
|
||||
delete(uuid){},
|
||||
}
|
||||
|
||||
const InterfaceFile = {
|
||||
add(uuid_record,uuid,timestamp,content,mime,hash){},
|
||||
getByRecord(uuid_record){},
|
||||
get(uuid){},
|
||||
delete(uuid){},
|
||||
deleteRecord(uuid_record){},
|
||||
update(uuid,timestamp,content,mime,hash){}
|
||||
}
|
||||
|
||||
const InterfaceTag = {
|
||||
add(uuid,word){},
|
||||
delete(uuid){}
|
||||
}
|
||||
|
||||
const InterfaceTagLink = {
|
||||
add(uuid_record,uuid_tag){},
|
||||
delete(uuid_record,uuid_tag){},
|
||||
deleteTag(uuid){},
|
||||
deleteRecord(uuid){}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
InterfaceTagLink,
|
||||
InterfaceTag,
|
||||
InterfaceFile,
|
||||
InterfaceRecord
|
||||
}
|
||||
@ -1,76 +1,76 @@
|
||||
const { ipcMain } = require('electron');
|
||||
|
||||
const {app} = require('electron');
|
||||
const config = app.getPath('userData');
|
||||
|
||||
const Conf = require('conf');
|
||||
const config = new Conf();
|
||||
|
||||
|
||||
// ** Extra Data
|
||||
ipcMain.on('timechain-config-dir', (event,arg) => {
|
||||
const configDir = app.getPath('userData');
|
||||
event.reply('timechain-config-dir-reply', configDir);
|
||||
});
|
||||
|
||||
// ** RECORD **
|
||||
|
||||
ipcMain.on('timechain-record-add', (event, arg) => {
|
||||
event.reply('timechain-record-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-delete', (event, arg) => {
|
||||
event.reply('timechain-record-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-update', (event, arg) => {
|
||||
event.reply('timechain-record-update-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-find', (event, arg) => {
|
||||
event.reply('timechain-record-find-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** FILE **
|
||||
|
||||
ipcMain.on('timechain-file-find', (event, arg) => {
|
||||
event.reply('timechain-file-find-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-add', (event, arg) => {
|
||||
event.reply('timechain-file-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-update', (event, arg) => {
|
||||
event.reply('timechain-file-update-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-delete', (event, arg) => {
|
||||
event.reply('timechain-file-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** TAG **
|
||||
ipcMain.on('timechain-tag-add', (event, arg) => {
|
||||
event.reply('timechain-tag-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-tag-delete', (event, arg) => {
|
||||
event.reply('timechain-tag-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** TAG LINK **
|
||||
ipcMain.on('timechain-taglink-add', (event, arg) => {
|
||||
event.reply('timechain-taglink-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-delete', (event, arg) => {
|
||||
event.reply('timechain-taglink-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-deleteTag', (event, arg) => {
|
||||
event.reply('timechain-taglink-deleteTag-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-deleteRecord', (event, arg) => {
|
||||
event.reply('timechain-taglink-deleteRecord-reply', 'pong')
|
||||
const { ipcMain } = require('electron');
|
||||
|
||||
const {app} = require('electron');
|
||||
const config = app.getPath('userData');
|
||||
|
||||
const Conf = require('conf');
|
||||
const config = new Conf();
|
||||
|
||||
|
||||
// ** Extra Data
|
||||
ipcMain.on('timechain-config-dir', (event,arg) => {
|
||||
const configDir = app.getPath('userData');
|
||||
event.reply('timechain-config-dir-reply', configDir);
|
||||
});
|
||||
|
||||
// ** RECORD **
|
||||
|
||||
ipcMain.on('timechain-record-add', (event, arg) => {
|
||||
event.reply('timechain-record-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-delete', (event, arg) => {
|
||||
event.reply('timechain-record-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-update', (event, arg) => {
|
||||
event.reply('timechain-record-update-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-record-find', (event, arg) => {
|
||||
event.reply('timechain-record-find-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** FILE **
|
||||
|
||||
ipcMain.on('timechain-file-find', (event, arg) => {
|
||||
event.reply('timechain-file-find-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-add', (event, arg) => {
|
||||
event.reply('timechain-file-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-update', (event, arg) => {
|
||||
event.reply('timechain-file-update-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-file-delete', (event, arg) => {
|
||||
event.reply('timechain-file-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** TAG **
|
||||
ipcMain.on('timechain-tag-add', (event, arg) => {
|
||||
event.reply('timechain-tag-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-tag-delete', (event, arg) => {
|
||||
event.reply('timechain-tag-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
// ** TAG LINK **
|
||||
ipcMain.on('timechain-taglink-add', (event, arg) => {
|
||||
event.reply('timechain-taglink-add-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-delete', (event, arg) => {
|
||||
event.reply('timechain-taglink-delete-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-deleteTag', (event, arg) => {
|
||||
event.reply('timechain-taglink-deleteTag-reply', 'pong')
|
||||
});
|
||||
|
||||
ipcMain.on('timechain-taglink-deleteRecord', (event, arg) => {
|
||||
event.reply('timechain-taglink-deleteRecord-reply', 'pong')
|
||||
});
|
||||
@ -1,264 +1,264 @@
|
||||
const Interface = require("es6-interface");
|
||||
const {InterfaceRecord,InterfaceFile,InterfaceTag,InterfaceTagLink} = require("./interfaces");
|
||||
|
||||
let db = null;
|
||||
|
||||
const connectToDatabase = (path)=>{
|
||||
db = require('better-sqlite3')(path, {});
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteTag extends Interface(InterfaceTag) {
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
add(uuid,word){
|
||||
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteTagLink extends Interface(InterfaceTagLink) {
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteFile extends Interface(InterfaceFile) {
|
||||
|
||||
constructor(){
|
||||
const table = `CREATE TABLE IF NOT EXISTS "files" (
|
||||
"uuid" TEXT UNIQUE,
|
||||
"uuid_record" TEXT NOT NULL,
|
||||
"timestamp" INTEGER NOT NULL,
|
||||
"content" BLOB NOT NULL,
|
||||
"mime" TEXT NOT NULL,
|
||||
"hash" TEXT,
|
||||
"created_at" INTEGER NOT NULL,
|
||||
"updated_at" INTEGER NOT NULL,
|
||||
PRIMARY KEY("uuid")
|
||||
);`;
|
||||
const table_idx = `
|
||||
CREATE INDEX IF NOT EXISTS "files_idx_record" ON "files" (
|
||||
"uuid_record"
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "files_idx_time" ON "files" (
|
||||
"timestamp" DESC
|
||||
);`;
|
||||
|
||||
if(!db){
|
||||
throw new Error("Database is not connected");
|
||||
}
|
||||
|
||||
db.exec(table + "\n" + table_idx);
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
get table_insert() {
|
||||
if(!this._table_insert){
|
||||
this._table_insert = db.prepare(`INSERT INTO files (uuid,uuid_record,timestamp,content,mime,hash,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?)`);
|
||||
}
|
||||
return this._table_insert;
|
||||
}
|
||||
|
||||
get table_update() {
|
||||
if(!this._table_update){
|
||||
this._table_update = db.prepare(`UPDATE files SET timestamp = ?, content = ?, mime = ? hash = ?, updated_at = ? WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_update;
|
||||
}
|
||||
|
||||
get table_delete() {
|
||||
if(!this._table_delete){
|
||||
this._table_delete = db.prepare(`DELETE FROM files WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_delete;
|
||||
}
|
||||
|
||||
get table_delete_record() {
|
||||
|
||||
if(!this._table_delete_record){
|
||||
this._table_delete_record = db.prepare(`DELETE FROM files WHERE uuid_record = ?`);
|
||||
}
|
||||
|
||||
return this._table_delete_record;
|
||||
}
|
||||
|
||||
get table_find_one() {
|
||||
if(!this._table_find_one){
|
||||
this._table_find_one = db.prepare(`SELECT * FROM files WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_find_one;
|
||||
}
|
||||
|
||||
get table_find_record(){
|
||||
if(!this._table_find_record){
|
||||
this._table_find_record = db.prepare(`SELECT * FROM files WHERE uuid_record = ?`);
|
||||
}
|
||||
return this._table_find_record;
|
||||
}
|
||||
|
||||
add(uuid_record,uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_insert.exec(uuid,uuid_record,timestamp,content,mime,hash,dt,dt);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
getByRecord(uuid_record){
|
||||
return new Promise(resolve => {
|
||||
const res = this.table_find_record.get(uuid_record);
|
||||
return resolve(res);
|
||||
});
|
||||
}
|
||||
|
||||
get(uuid){
|
||||
return new Promise(resolve => {
|
||||
const res = this.table_fine_one.get(uuid);
|
||||
return resolve(res);
|
||||
});
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete.exec(uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
deleteRecord(){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete_record.exec(uuid_record);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
update(uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_update.exec(timestamp,content,mime,hash,uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteRecord extends Interface(InterfaceRecord) {
|
||||
|
||||
constructor(){
|
||||
//TODO: Create Tables Here if not exist
|
||||
const table = `CREATE TABLE IF NOT EXISTS "records" (
|
||||
"uuid" TEXT NOT NULL UNIQUE,
|
||||
"timestamp" INTEGER NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"mime" TEXT NOT NULL,
|
||||
"hash" TEXT,
|
||||
"created_at" INTEGER NOT NULL,
|
||||
"updated_at" INTEGER NOT NULL,
|
||||
PRIMARY KEY("uuid")
|
||||
);`;
|
||||
const table_idx = `CREATE INDEX IF NOT EXISTS "records_idx_timestamp" ON "records" (
|
||||
"timestamp" DESC
|
||||
);`
|
||||
|
||||
if(!db){
|
||||
throw new Error("Database is not connected");
|
||||
}
|
||||
|
||||
db.exec(table + "\n" + table_idx);
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
get table_insert() {
|
||||
if(!this._table_insert){
|
||||
this._table_insert = db.prepare(`INSERT INTO records (uuid,timestamp,content,mime,hash,created_at,updated_at) VALUES (?,?,?,?,?,?,?)`);
|
||||
}
|
||||
return this._table_insert;
|
||||
}
|
||||
|
||||
get table_update(){
|
||||
if(!this._table_update){
|
||||
this._table_update = db.prepare(`UPDATE records SET timestamp = ?, content = ?, mime = ?, hash = ? updated_at = ? WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_update;
|
||||
}
|
||||
|
||||
get table_delete(){
|
||||
if(!this._table_delete){
|
||||
this._table_delete = db.prepare(`DELETE FROM records WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_delete;
|
||||
}
|
||||
|
||||
get table_fine_one(){
|
||||
if(!this._table_fine_one){
|
||||
this._table_fine_one = db.prepare(`SELECT * FROM records WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_fine_one;
|
||||
}
|
||||
|
||||
add(uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_insert.run(uuid,timestamp,content,mime,hash,dt,dt);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
get(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const rec = this.table_fine_one.get(uuid);
|
||||
return resolve(rec);
|
||||
});
|
||||
}
|
||||
|
||||
find(search,sort=null,limit=undefined,offset=0){
|
||||
//TODO: add logic for seach and sort (Currently does nothing)
|
||||
return new Promise(resolve=>{
|
||||
const rescount = this.db.prepare("SELECT count(*) as cnt FROM records").get();
|
||||
|
||||
if(limit){
|
||||
const res = this.db.prepare("SELECT * FROM records ORDER BY timestamp DESC LIMIT ? OFFSET ?").all(limit,offset);
|
||||
}else{
|
||||
const res = this.db.prepare("SELECT * FROM records ORDER BY timestamp DESC").all();
|
||||
}
|
||||
|
||||
return resolve({
|
||||
data: res,
|
||||
count: rescount?.cnt,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
});
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete.exec(uuid);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
update(uuid,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_update.exec(content,mime,hash,dt,uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqlite {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
const Interface = require("es6-interface");
|
||||
const {InterfaceRecord,InterfaceFile,InterfaceTag,InterfaceTagLink} = require("./interfaces");
|
||||
|
||||
let db = null;
|
||||
|
||||
const connectToDatabase = (path)=>{
|
||||
db = require('better-sqlite3')(path, {});
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteTag extends Interface(InterfaceTag) {
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
add(uuid,word){
|
||||
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteTagLink extends Interface(InterfaceTagLink) {
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteFile extends Interface(InterfaceFile) {
|
||||
|
||||
constructor(){
|
||||
const table = `CREATE TABLE IF NOT EXISTS "files" (
|
||||
"uuid" TEXT UNIQUE,
|
||||
"uuid_record" TEXT NOT NULL,
|
||||
"timestamp" INTEGER NOT NULL,
|
||||
"content" BLOB NOT NULL,
|
||||
"mime" TEXT NOT NULL,
|
||||
"hash" TEXT,
|
||||
"created_at" INTEGER NOT NULL,
|
||||
"updated_at" INTEGER NOT NULL,
|
||||
PRIMARY KEY("uuid")
|
||||
);`;
|
||||
const table_idx = `
|
||||
CREATE INDEX IF NOT EXISTS "files_idx_record" ON "files" (
|
||||
"uuid_record"
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "files_idx_time" ON "files" (
|
||||
"timestamp" DESC
|
||||
);`;
|
||||
|
||||
if(!db){
|
||||
throw new Error("Database is not connected");
|
||||
}
|
||||
|
||||
db.exec(table + "\n" + table_idx);
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
get table_insert() {
|
||||
if(!this._table_insert){
|
||||
this._table_insert = db.prepare(`INSERT INTO files (uuid,uuid_record,timestamp,content,mime,hash,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?)`);
|
||||
}
|
||||
return this._table_insert;
|
||||
}
|
||||
|
||||
get table_update() {
|
||||
if(!this._table_update){
|
||||
this._table_update = db.prepare(`UPDATE files SET timestamp = ?, content = ?, mime = ? hash = ?, updated_at = ? WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_update;
|
||||
}
|
||||
|
||||
get table_delete() {
|
||||
if(!this._table_delete){
|
||||
this._table_delete = db.prepare(`DELETE FROM files WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_delete;
|
||||
}
|
||||
|
||||
get table_delete_record() {
|
||||
|
||||
if(!this._table_delete_record){
|
||||
this._table_delete_record = db.prepare(`DELETE FROM files WHERE uuid_record = ?`);
|
||||
}
|
||||
|
||||
return this._table_delete_record;
|
||||
}
|
||||
|
||||
get table_find_one() {
|
||||
if(!this._table_find_one){
|
||||
this._table_find_one = db.prepare(`SELECT * FROM files WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_find_one;
|
||||
}
|
||||
|
||||
get table_find_record(){
|
||||
if(!this._table_find_record){
|
||||
this._table_find_record = db.prepare(`SELECT * FROM files WHERE uuid_record = ?`);
|
||||
}
|
||||
return this._table_find_record;
|
||||
}
|
||||
|
||||
add(uuid_record,uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_insert.exec(uuid,uuid_record,timestamp,content,mime,hash,dt,dt);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
getByRecord(uuid_record){
|
||||
return new Promise(resolve => {
|
||||
const res = this.table_find_record.get(uuid_record);
|
||||
return resolve(res);
|
||||
});
|
||||
}
|
||||
|
||||
get(uuid){
|
||||
return new Promise(resolve => {
|
||||
const res = this.table_fine_one.get(uuid);
|
||||
return resolve(res);
|
||||
});
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete.exec(uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
deleteRecord(){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete_record.exec(uuid_record);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
update(uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_update.exec(timestamp,content,mime,hash,uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class TimeChainDataSqliteRecord extends Interface(InterfaceRecord) {
|
||||
|
||||
constructor(){
|
||||
//TODO: Create Tables Here if not exist
|
||||
const table = `CREATE TABLE IF NOT EXISTS "records" (
|
||||
"uuid" TEXT NOT NULL UNIQUE,
|
||||
"timestamp" INTEGER NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"mime" TEXT NOT NULL,
|
||||
"hash" TEXT,
|
||||
"created_at" INTEGER NOT NULL,
|
||||
"updated_at" INTEGER NOT NULL,
|
||||
PRIMARY KEY("uuid")
|
||||
);`;
|
||||
const table_idx = `CREATE INDEX IF NOT EXISTS "records_idx_timestamp" ON "records" (
|
||||
"timestamp" DESC
|
||||
);`
|
||||
|
||||
if(!db){
|
||||
throw new Error("Database is not connected");
|
||||
}
|
||||
|
||||
db.exec(table + "\n" + table_idx);
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
get table_insert() {
|
||||
if(!this._table_insert){
|
||||
this._table_insert = db.prepare(`INSERT INTO records (uuid,timestamp,content,mime,hash,created_at,updated_at) VALUES (?,?,?,?,?,?,?)`);
|
||||
}
|
||||
return this._table_insert;
|
||||
}
|
||||
|
||||
get table_update(){
|
||||
if(!this._table_update){
|
||||
this._table_update = db.prepare(`UPDATE records SET timestamp = ?, content = ?, mime = ?, hash = ? updated_at = ? WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_update;
|
||||
}
|
||||
|
||||
get table_delete(){
|
||||
if(!this._table_delete){
|
||||
this._table_delete = db.prepare(`DELETE FROM records WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_delete;
|
||||
}
|
||||
|
||||
get table_fine_one(){
|
||||
if(!this._table_fine_one){
|
||||
this._table_fine_one = db.prepare(`SELECT * FROM records WHERE uuid = ?`);
|
||||
}
|
||||
return this._table_fine_one;
|
||||
}
|
||||
|
||||
add(uuid,timestamp,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_insert.run(uuid,timestamp,content,mime,hash,dt,dt);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
get(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const rec = this.table_fine_one.get(uuid);
|
||||
return resolve(rec);
|
||||
});
|
||||
}
|
||||
|
||||
find(search,sort=null,limit=undefined,offset=0){
|
||||
//TODO: add logic for seach and sort (Currently does nothing)
|
||||
return new Promise(resolve=>{
|
||||
const rescount = this.db.prepare("SELECT count(*) as cnt FROM records").get();
|
||||
|
||||
if(limit){
|
||||
const res = this.db.prepare("SELECT * FROM records ORDER BY timestamp DESC LIMIT ? OFFSET ?").all(limit,offset);
|
||||
}else{
|
||||
const res = this.db.prepare("SELECT * FROM records ORDER BY timestamp DESC").all();
|
||||
}
|
||||
|
||||
return resolve({
|
||||
data: res,
|
||||
count: rescount?.cnt,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
});
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
delete(uuid){
|
||||
return new Promise(resolve=>{
|
||||
const res = this.table_delete.exec(uuid);
|
||||
return resolve(res?.changes);
|
||||
});
|
||||
}
|
||||
|
||||
update(uuid,content,mime,hash){
|
||||
return new Promise(resolve=>{
|
||||
const dt = Math.floor(Date.now());
|
||||
const res = this.table_update.exec(content,mime,hash,dt,uuid);
|
||||
return resolve(res?.changes);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeChainDataSqlite {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
5
src/ui/app.riot
Normal file
5
src/ui/app.riot
Normal file
@ -0,0 +1,5 @@
|
||||
<app>
|
||||
|
||||
|
||||
|
||||
</app>
|
||||
0
src/ui/timechain-input.riot
Normal file
0
src/ui/timechain-input.riot
Normal file
0
src/ui/timer-ctrl.riot
Normal file
0
src/ui/timer-ctrl.riot
Normal file
@ -1,34 +1,34 @@
|
||||
<timestamp>
|
||||
|
||||
<div class="timestamp">
|
||||
<div class="timestamp-icon">
|
||||
<div class="timestamp-text">{ state.time_text }</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
const pubsub = require('pubsub-js');
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
export default {
|
||||
state: {
|
||||
time_text: "",
|
||||
format: "long"
|
||||
},
|
||||
onMounted(){
|
||||
this.start();
|
||||
},
|
||||
start(){
|
||||
setTimeout(()=>{
|
||||
this.makeString();
|
||||
this.start();
|
||||
},200);
|
||||
},
|
||||
makeString(){
|
||||
if(this.state.format=="long"){
|
||||
this.update({time_text:dayjs().format("MMMM D, YYYY h:mm:ss A")});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<timestamp>
|
||||
|
||||
<div class="timestamp">
|
||||
<div class="timestamp-icon">
|
||||
<div class="timestamp-text">{ state.time_text }</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
const pubsub = require('pubsub-js');
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
export default {
|
||||
state: {
|
||||
time_text: "",
|
||||
format: "long"
|
||||
},
|
||||
onMounted(){
|
||||
this.start();
|
||||
},
|
||||
start(){
|
||||
setTimeout(()=>{
|
||||
this.makeString();
|
||||
this.start();
|
||||
},200);
|
||||
},
|
||||
makeString(){
|
||||
if(this.state.format=="long"){
|
||||
this.update({time_text:dayjs().format("MMMM D, YYYY h:mm:ss A")});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</timestamp>
|
||||
12
start.js
12
start.js
@ -1,7 +1,7 @@
|
||||
import Timestamp from './timestamp.riot'
|
||||
import { component } from 'riot'
|
||||
|
||||
|
||||
component(Timestamp)(document.getElementById('timestamp'))
|
||||
|
||||
import Timestamp from './src/ui/timestamp.riot'
|
||||
import { component } from 'riot'
|
||||
|
||||
|
||||
component(Timestamp)(document.getElementById('timestamp'))
|
||||
|
||||
console.log("yes!");
|
||||
Loading…
x
Reference in New Issue
Block a user