Skip to content

Commit dc74d6b

Browse files
committed
Updated NPM
1 parent afda31b commit dc74d6b

File tree

20 files changed

+602
-23
lines changed

20 files changed

+602
-23
lines changed

etc/server.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
- build/httpserver.plugin
44
- build/log.plugin
55
- build/sqlite3.plugin
6-
# - build/static.plugin
6+
- build/static.plugin
77

88
# HTTP Server parameters
99
httpserver:
@@ -18,11 +18,11 @@ handlers:
1818
# Requests are logged
1919
middleware:
2020
- log
21-
# static:
22-
# prefix: /api/static
23-
24-
#static:
25-
# "/": npm/sqlite3/dist
21+
static:
22+
prefix: /api/static
23+
24+
static:
25+
"/": npm/sqlite3/dist
2626

2727
sqlite3:
2828
# Databases to load and/or create. Only the 'main' database is required.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.17
55
require (
66
github.com/djthorpe/go-errors v1.0.2
77
github.com/djthorpe/go-marshaler v0.0.15
8-
github.com/djthorpe/go-server v1.0.10
8+
github.com/djthorpe/go-server v1.0.12
99
github.com/hashicorp/go-multierror v1.1.1
1010
github.com/mattn/go-sqlite3 v1.14.8
1111
github.com/rjeczalik/notify v0.9.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ github.com/djthorpe/go-errors v1.0.2/go.mod h1:HtfrZnMd6HsX75Mtbv9Qcnn0BqOrrFArv
88
github.com/djthorpe/go-marshaler v0.0.4/go.mod h1:xCXhTzj52UL3YStRsqUSfrKses7ofmfTXYQfVedn8Lw=
99
github.com/djthorpe/go-marshaler v0.0.15 h1:ZXq5YHCsbREbbYJtc0ie9hz7HJ7vIeeDlMbe7cGh0C0=
1010
github.com/djthorpe/go-marshaler v0.0.15/go.mod h1:xCXhTzj52UL3YStRsqUSfrKses7ofmfTXYQfVedn8Lw=
11-
github.com/djthorpe/go-server v1.0.10 h1:9XSNwkP7Y7GnSWKmJgoKhB+47G+YkYoYAtGJrSgsy6E=
12-
github.com/djthorpe/go-server v1.0.10/go.mod h1:UiBRW6dbmRCVDUfzT5IZ0CCdnGChL3RpTTLjcmPICWI=
11+
github.com/djthorpe/go-server v1.0.12 h1:jhGpyG+qukXndAdgQgpzIdxMXg3gR2pXsPnmXmwbtFk=
12+
github.com/djthorpe/go-server v1.0.12/go.mod h1:UiBRW6dbmRCVDUfzT5IZ0CCdnGChL3RpTTLjcmPICWI=
1313
github.com/djthorpe/go-sqlite v1.0.28/go.mod h1:TiGX+dIFea54xxIBVmFemTI/8KUjVUlEoDN2A5HKaMs=
1414
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
1515
github.com/go-ldap/ldap/v3 v3.4.1/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg=

npm/sqlite3/css/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11

22
@import url('@djthorpe/js-framework/dist/index.css');
3+
4+
/* For any action, use a pointer */
5+
.action,.schema {
6+
cursor: pointer;
7+
}
8+

npm/sqlite3/html/index.html

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,12 @@
1010
<link rel="stylesheet" href="/index.css" media="all">
1111
<script src="/index.js"></script>
1212
</head>
13+
1314
<body>
1415
<!-- NAVIGATION -->
1516
<nav class="navbar sticky-top navbar navbar-dark navbar-expand-md bg-primary border-bottom border-white" id="nav">
1617
<div class="container-fluid">
1718
<a class="navbar-brand" href="/"><strong>sqlite</strong></a>
18-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-items"
19-
aria-expanded="false">
20-
<span class="navbar-toggler-icon"></span>
21-
</button>
22-
<div class="collapse navbar-collapse" id="navbar-items">
23-
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
24-
<li class="nav-item">
25-
<a class="nav-link" href="#">Home</a>
26-
</li>
27-
</ul>
28-
</div>
2919
</div>
3020
</nav>
3121
<!-- TOAST -->
@@ -38,6 +28,66 @@
3828
</div>
3929
<div class="toast-body _reason"></div>
4030
</div>
41-
</div>
31+
</div>
32+
<!-- LEFT/RIGHT NAVIGATION -->
33+
<div class="container-fluid">
34+
<div class="row">
35+
<div class="col-md-10 mt-1" id="schema">
36+
<!-- BODY CONTENT (SchemaView) -->
37+
<div class="_title bg-light rounded p-2 mb-2">
38+
<h1 class="_name">[schema]</h1>
39+
<small class="_filename">[filename]</small>
40+
</div>
41+
<ul class="nav nav-tabs" id="schema-table-list">
42+
<li class="nav-item _template">
43+
<a class="nav-link _name" aria-current="page" href="#">[table]</a>
44+
</li>
45+
</ul>
46+
</div>
47+
<div class="col-md-2 d-md-block d-none bg-light border-start" id="database">
48+
<!-- BODY CONTENT (DatabaseView) -->
49+
<h5 class="_version pt-1"></h5>
50+
<button class="btn btn-primary btn-sm m-1 action action-modules">List Modules</button>
51+
<button class="btn btn-primary btn-sm m-1 action">Import</button>
52+
<table class="table table-hover table-sm">
53+
<thead>
54+
<tr>
55+
<th>Database</th>
56+
</tr>
57+
</thead>
58+
<tbody id="database-schemas">
59+
<tr class="_template">
60+
<td class="schema">[schema]</td>
61+
</tr>
62+
</tbody>
63+
</table>
64+
<!-- MODULE MODAL -->
65+
<div class="modal" id="database-modules" tabindex="-1">
66+
<div class="modal-dialog">
67+
<div class="modal-content">
68+
<div class="modal-header">
69+
<h5 class="modal-title">Modules</h5>
70+
<button type="button" class="btn-close" data-bs-dismiss="modal"
71+
aria-label="Close"></button>
72+
</div>
73+
<div class="modal-body">
74+
<form>
75+
<table class="table table-sm">
76+
<tbody id="database-modules-list">
77+
<tr class="_template"><td class="module">[Module]</td></tr>
78+
</tbody>
79+
</table>
80+
</form>
81+
</div>
82+
<div class="modal-footer">
83+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
</div>
89+
</div>
90+
</div>
4291
</body>
43-
</html>
92+
93+
</html>

npm/sqlite3/js/controller/app.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import {
2+
Controller, Nav, Toast, Provider,
3+
} from '@djthorpe/js-framework';
4+
5+
// Models
6+
import Endpoint from '../model/static/endpoint';
7+
import Database from '../model/sqlite3/database';
8+
import Schema from '../model/sqlite3/schema';
9+
import TableData from '../model/sqlite3/tabledata';
10+
11+
// Views
12+
import DatabaseView from '../view/sqlite3/database';
13+
import SchemaView from '../view/sqlite3/schema';
14+
15+
// Constants
16+
const API_STATIC_PREFIX = '/api/static';
17+
const API_SQLITE_PREFIX = '/api/sqlite';
18+
const API_SQLITE_DELTA = 30 * 1000;
19+
const API_STATIC_DELTA = 30 * 1000;
20+
21+
export default class App extends Controller {
22+
constructor() {
23+
super();
24+
25+
// VIEWS
26+
const navNode = document.querySelector('#nav');
27+
if (navNode) {
28+
super.define('nav', new Nav(navNode));
29+
}
30+
31+
const toastNode = document.querySelector('#toast');
32+
if (toastNode) {
33+
super.define('toast', new Toast(toastNode));
34+
}
35+
36+
const databaseNode = document.querySelector('#database');
37+
super.define('databaseview', new DatabaseView(databaseNode));
38+
this.databaseview.addEventListener(['view:click'], (sender, target) => {
39+
if (target.classList.contains('action-modules')) {
40+
this.databaseview.showModules();
41+
} else if (target.classList.contains('schema')) {
42+
const schemaName = target.innerText;
43+
this.schema.request(`/${schemaName}`, null, API_SQLITE_DELTA);
44+
} else {
45+
console.log('view:click', target);
46+
}
47+
});
48+
49+
const schemaNode = document.querySelector('#schema');
50+
super.define('schemaview', new SchemaView(schemaNode));
51+
this.schemaview.addEventListener(['schema:change'], () => {
52+
// TODO: Set active as the first node
53+
console.log('schema:change');
54+
});
55+
this.schemaview.addEventListener(['schema:click'], (sender, target) => {
56+
// Set active
57+
this.schemaview.active = target;
58+
// Load the table data
59+
console.log(`schema:click ${target}`);
60+
this.tabledata.do(`/${target.schema}/${target.name}`);
61+
});
62+
63+
64+
// PROVIDERS
65+
super.define('static', new Provider(Endpoint, API_STATIC_PREFIX));
66+
if (this.static) {
67+
this.static.addEventListener('provider:error', (sender, error) => {
68+
this.toast.show(error);
69+
});
70+
this.static.addEventListener(['provider:added', 'provider:changed'], (sender, endpoint) => {
71+
console.log(`endpoint added or changed: ${endpoint}`);
72+
});
73+
this.static.addEventListener('provider:deleted', (sender, endpoint) => {
74+
console.log(`endpoint deleted: ${endpoint}`);
75+
});
76+
}
77+
78+
super.define('sqlite', new Provider(Database, API_SQLITE_PREFIX));
79+
if (this.sqlite) {
80+
this.sqlite.addEventListener('provider:error', (sender, error) => {
81+
this.toast.show(error);
82+
});
83+
this.sqlite.addEventListener(['provider:added', 'provider:changed'], (sender, database) => {
84+
console.log(`sqlite added or changed: ${database}`);
85+
this.databaseview.database = database;
86+
});
87+
this.sqlite.addEventListener('provider:deleted', (sender, database) => {
88+
console.log(`sqlite deleted: ${database}`);
89+
});
90+
}
91+
92+
super.define('schema', new Provider(Schema, API_SQLITE_PREFIX));
93+
this.schema.addEventListener('provider:error', (sender, error) => {
94+
this.toast.show(error);
95+
});
96+
this.schema.addEventListener(['provider:added', 'provider:changed'], (sender, schema) => {
97+
console.log(`schema added: ${schema}`);
98+
this.schemaview.schema = schema;
99+
});
100+
this.schema.addEventListener('provider:deleted', (sender, schema) => {
101+
console.log(`schema deleted: ${schema}`);
102+
});
103+
104+
super.define('tabledata', new Provider(TableData, API_SQLITE_PREFIX));
105+
this.tabledata.addEventListener('provider:error', (sender, error) => {
106+
this.toast.show(error);
107+
});
108+
this.tabledata.addEventListener(['provider:added', 'provider:changed'], (sender, data) => {
109+
console.log(`data added: ${data}`);
110+
});
111+
}
112+
113+
main() {
114+
super.main();
115+
// Request the static & database endpoints
116+
this.static.request('/', null, API_STATIC_DELTA);
117+
this.sqlite.request('/', null, API_SQLITE_DELTA);
118+
}
119+
}

npm/sqlite3/js/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// CSS
3+
import '../css/index.css';
4+
5+
// Application Controllers
6+
import App from './controller/app';
7+
8+
// Import js-framework
9+
const jsf = require('@djthorpe/js-framework');
10+
11+
// Run
12+
window.addEventListener('DOMContentLoaded', () => {
13+
const app = jsf.Controller.New(App);
14+
15+
// Run the main function for the app
16+
console.log('Running application', app.constructor.name);
17+
app.main();
18+
});
19+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Model } from '@djthorpe/js-framework';
2+
3+
export default class Column extends Model {
4+
static define() {
5+
super.define(Column, {
6+
name: 'string',
7+
schema: 'string',
8+
table: 'string',
9+
type: 'string',
10+
primary: 'boolean',
11+
nullable: 'boolean',
12+
}, 'Column');
13+
}
14+
}
15+
16+
Column.define();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Model } from '@djthorpe/js-framework';
2+
3+
export default class Database extends Model {
4+
static define() {
5+
super.define(Database, {
6+
version: 'string',
7+
modules: '[]string',
8+
schemas: '[]string',
9+
}, 'Database');
10+
}
11+
}
12+
13+
Database.define();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Model } from '@djthorpe/js-framework';
2+
3+
export default class Row extends Model {
4+
constructor(data) {
5+
super({});
6+
console.log(data);
7+
}
8+
9+
static define() {
10+
super.define(Row, {}, 'Row');
11+
}
12+
}
13+
14+
Row.define();

0 commit comments

Comments
 (0)