Browse Source

refactored code to avoid relative paths

added Component and Page base classes
added Clock widget (wip)
master
Youen Toupin 3 years ago
parent
commit
f8c2a28c47
  1. 1
      WebApp/package.json
  2. 4
      WebApp/src/app.ts
  3. 19
      WebApp/src/components/component.ts
  4. 5
      WebApp/src/components/page.ts
  5. 8
      WebApp/src/components/widgets/clock.tsx
  6. 11
      WebApp/src/pages/dashboard/dashboard-page.tsx
  7. 0
      WebApp/src/pages/raw-data/raw-data-page.css
  8. 5
      WebApp/src/pages/raw-data/raw-data-page.tsx
  9. 7
      WebApp/tsconfig.json
  10. 2
      WebApp/webpack.config.js

1
WebApp/package.json

@ -19,6 +19,7 @@
"purgecss-webpack-plugin": "^4.1.3",
"style-loader": "^3.3.1",
"ts-loader": "^9.2.8",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "^4.6.2",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2"

4
WebApp/src/app.ts

@ -1,8 +1,8 @@
import m from 'mithril';
import Layout from './layout';
import RawDataPage from './raw-data-page';
import DashboardPage from './dashboard-page';
import { RawDataPage } from 'pages/raw-data/raw-data-page';
import { DashboardPage } from 'pages/dashboard/dashboard-page';
require('../node_modules/bulma/css/bulma.css');

19
WebApp/src/components/component.ts

@ -0,0 +1,19 @@
import m from 'mithril';
export abstract class Component {
abstract view(vnode: m.Vnode): m.Children;
oninit(vnode: m.Vnode) {}
oncreate(vnode: m.Vnode) {}
onbeforeupdate(newVnode: m.Vnode, oldVnode: m.Vnode) {
return true;
}
onupdate(vnode: m.Vnode) {}
onbeforeremove(vnode: m.Vnode): Promise<void> | void {}
onremove(vnode: m.Vnode) {}
}

5
WebApp/src/components/page.ts

@ -0,0 +1,5 @@
import { Component } from 'components/component';
export abstract class Page extends Component {
}

8
WebApp/src/components/widgets/clock.tsx

@ -0,0 +1,8 @@
import m from 'mithril';
import { Component } from 'components/component'
export default class Clock extends Component {
view(vnode: m.Vnode<{}, {}>): m.Children {
return <p>clock</p>;
}
}

11
WebApp/src/dashboard-page.tsx → WebApp/src/pages/dashboard/dashboard-page.tsx

@ -1,7 +1,9 @@
import m from 'mithril';
import { MonitorApi, Status } from './monitor-api';
import { Page } from 'components/page';
import { MonitorApi, Status } from 'monitor-api';
import Clock from 'components/widgets/clock';
export default class DashboardPage {
export class DashboardPage extends Page {
status: Status = null;
autoRefresh = true;
@ -10,8 +12,8 @@ export default class DashboardPage {
this.refresh();
}
onbeforeremove() {
this.autoRefresh = false;
onbeforeremove(vnode: m.Vnode<{}, {}>) {
this.autoRefresh = false;
}
async refresh() {
@ -23,6 +25,7 @@ export default class DashboardPage {
view() {
return this.status
? <div class="dashboard-page">
<Clock/>
</div>
: <p>Chargement...</p>;
}

0
WebApp/src/raw-data-page.css → WebApp/src/pages/raw-data/raw-data-page.css

5
WebApp/src/raw-data-page.tsx → WebApp/src/pages/raw-data/raw-data-page.tsx

@ -1,9 +1,10 @@
import m from 'mithril';
import { MonitorApi, Status } from './monitor-api';
import { Page } from 'components/page';
import { MonitorApi, Status } from 'monitor-api';
require("./raw-data-page.css");
export default class RawDataPage {
export class RawDataPage extends Page {
status: Status = null;
autoRefresh = true;

7
WebApp/tsconfig.json

@ -1,12 +1,15 @@
{
"compilerOptions": {
"noImplicitAny": true,
"module": "CommonJS",
"module": "ES6",
"esModuleInterop": true,
"target": "es5",
"jsx": "react",
"jsxFactory": "m",
"allowJs": true,
"moduleResolution": "node"
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
}
}
}

2
WebApp/webpack.config.js

@ -5,6 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PurgecssPlugin = require('purgecss-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
entry: './src/app.ts',
@ -23,6 +24,7 @@ module.exports = {
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [new TsconfigPathsPlugin({})]
},
output: {
filename: '[name].js',

Loading…
Cancel
Save