Skip to content

Commit b2e8f46

Browse files
committed
Add full server project and mithril workaround
Docs refresh
1 parent ca4e92d commit b2e8f46

File tree

21 files changed

+626
-4
lines changed

21 files changed

+626
-4
lines changed

Framework/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ npm install --save @aliceo2/web-ui
6161

6262
### Getting started
6363
* [Step-by-step tutorial: Time server using Ajax and WebSockets](./docs/tutorial/time-server.md)
64-
* [Advanced frontend demo](https://aliceo2group.github.io/WebUi/Framework/docs/demo/frontend.html)
64+
* [Advanced frontend demo](./docs/demo/README.md)
6565

6666
### Backend guide
6767
* [REST API](./docs/guide/http-server.md) - Serves custom REST API, supports TLS

Framework/docs/demo/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# WebUi Demos
2+
3+
This folder contains example demos showcasing the WebUi framework.
4+
5+
> Mithril is the JavaScript frontend framework that WebUi builds on. It provides the virtual DOM engine and rendering API `m()` that all WebUi components depend on. The WebUi framework's [renderer.js](../../Frontend/js/src/renderer.js#L26) explicitly imports Mithril via an absolute path. Without Mithril loaded globally, none of the demos can render.
6+
7+
There are two ways to run the demos:
8+
1. [Full server approach](#1-full-server-approach-recommended) _(recommended)_ – run a backend that serves Mithril and all demos with clean routes.
9+
2. [Manual workaround](#2-manual-workaround-quick--dirty) _(quick & dirty)_ – serve Mithril with a static server.
10+
11+
## 1. Full server approach (recommended)
12+
13+
See the [project README](./project/README.md) for setup instructions.
14+
15+
This uses a proper backend that serves Mithril and all demos with clean routes. In the HTTP server's [constructor](./project/index.js#L27) a [`specifyRoutes`](https://github.com/AliceO2Group/WebUi/blob/dev/Framework/Backend/http/server.js#L172) logic is invoked to wire up all required routes.
16+
17+
## 2. Manual workaround (quick & dirty)
18+
19+
Serve docs statically and manually provide Mithril.
20+
21+
Copy Mithril to the expected `mithril/mithril.min.js` path:
22+
23+
```bash
24+
cd WebUi/Framework
25+
npm ci
26+
mkdir -p mithril
27+
cp node_modules/mithril/mithril.min.js mithril/mithril.min.js
28+
```
29+
30+
If you don't want to install everything, you can also create the file manually.
31+
```bash
32+
cd WebUi/Framework
33+
mkdir mithril
34+
touch mithril/mithril.min.js
35+
```
36+
Then copy the contents of the `mithril/mithril.min.js` file in there (available for example in the [unpkg.com](https://unpkg.com/mithril@2.3.7/mithril.min.js)).
37+
38+
This is more error-prone than the local copy from `node_modules`.
39+
40+
### Serve the Framework directory
41+
42+
```bash
43+
python3 -m http.server 8080
44+
```
45+
46+
Navigate through available demos:
47+
- [chart](http://localhost:8080/docs/demo/chart.html)
48+
- [frontend](http://localhost:8080/docs/demo/frontend.html)
49+
- [notification](http://localhost:8080/docs/demo/notification.html)
50+
- [template-1](http://localhost:8080/docs/demo/template-1.html)
51+
- [template-2](http://localhost:8080/docs/demo/template-2.html).

Framework/docs/demo/frontend.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@
136136
// Mount will listen to model changes and draw inside body the view
137137
mount(document.body, view, model, debug);
138138

139-
// Expose model to interract with it the browser's console
139+
// Expose model to interact with it the browser's console
140140
window.model = model;
141141
</script>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Full server approach
2+
3+
For the setup, we're basically going to repeat the steps from the tutorial.
4+
5+
### 1. Fetch project template
6+
7+
```bash
8+
mkdir project
9+
git clone https://github.com/AliceO2Group/WebUi.git
10+
cp -R WebUi/Framework/docs/demo/project/* ./project
11+
cd project
12+
```
13+
14+
### 2. Add the framework to dependency list
15+
16+
```bash
17+
npm init
18+
npm install --save @aliceo2/web-ui
19+
```
20+
21+
### 3. Launch the application
22+
23+
Start the server
24+
```bash
25+
node index.js
26+
```
27+
28+
Then, open your browser and navigate to [http://localhost:8080](http://localhost:8080). This is the main demo page.
29+
30+
Navigate through available demos:
31+
- [chart](http://localhost:8080/chart)
32+
- [frontend](http://localhost:8080/frontend/)
33+
- [notification](http://localhost:8080/notification/)
34+
- [template-1](http://localhost:8080/template-1/)
35+
- [template-2](http://localhost:8080/template-2/).
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
4+
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
5+
* All rights not expressly granted are reserved.
6+
*
7+
* This software is distributed under the terms of the GNU General Public
8+
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
9+
*
10+
* In applying this license CERN does not waive the privileges and immunities
11+
* granted to it by virtue of its status as an Intergovernmental Organization
12+
* or submit itself to any jurisdiction.
13+
*/
14+
15+
/*
16+
* This is quick start configuration
17+
* See the Backend documentation for more details
18+
*
19+
*/
20+
module.exports = {
21+
jwt: {
22+
secret: 'supersecret',
23+
expiration: '10m',
24+
},
25+
http: {
26+
port: 8080,
27+
hostname: 'localhost',
28+
tls: false,
29+
},
30+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
4+
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
5+
* All rights not expressly granted are reserved.
6+
*
7+
* This software is distributed under the terms of the GNU General Public
8+
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
9+
*
10+
* In applying this license CERN does not waive the privileges and immunities
11+
* granted to it by virtue of its status as an Intergovernmental Organization
12+
* or submit itself to any jurisdiction.
13+
*/
14+
15+
// Import the backend classes
16+
const { HttpServer } = require('@aliceo2/web-ui');
17+
18+
// Define configuration for JWT tokens and HTTP server
19+
const config = require('./config.js');
20+
21+
/*
22+
* HTTP server
23+
* -----------
24+
*
25+
* Instantiate the HTTP server
26+
*/
27+
const httpServer = new HttpServer(config.http, config.jwt);
28+
29+
// Server static content in public directory
30+
httpServer.addStaticPath('./public');
31+
httpServer.addStaticPath('./public/chart', '/chart');
32+
httpServer.addStaticPath('./public/frontend', '/frontend');
33+
httpServer.addStaticPath('./public/notification', '/notification');
34+
httpServer.addStaticPath('./public/template-1', '/template-1');
35+
httpServer.addStaticPath('./public/template-2', '/template-2');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<title>Chart Demo</title>
3+
<link rel="stylesheet" href="/css/src/bootstrap.css">
4+
<body class="bg-gray">
5+
<!-- This will be replaced by template engine when loaded completly -->
6+
Loading...
7+
</body>
8+
9+
<!-- Main application -->
10+
<script type="module" src="main.js"></script>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license
3+
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
4+
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
5+
* All rights not expressly granted are reserved.
6+
*
7+
* This software is distributed under the terms of the GNU General Public
8+
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
9+
*
10+
* In applying this license CERN does not waive the privileges and immunities
11+
* granted to it by virtue of its status as an Intergovernmental Organization
12+
* or submit itself to any jurisdiction.
13+
*/
14+
15+
import {mount, h, Observable, chartTimeSeries} from '/js/src/index.js';
16+
17+
// Example of chart integration with template engine
18+
const view = (model) => [
19+
h('div.m4', [
20+
chartTimeSeries({
21+
series: model.series1,
22+
title: 'Sinus',
23+
colorPrimary: 'red',
24+
width: '800',
25+
}),
26+
]),
27+
h('div.m4', [
28+
chartTimeSeries({
29+
series: model.series1,
30+
title: 'Sinus',
31+
colorPrimary: 'red',
32+
width: '800',
33+
timeWindow: 100,
34+
}),
35+
]),
36+
h('div.m4', [
37+
chartTimeSeries({
38+
series: model.series2,
39+
title: 'Random',
40+
colorPrimary: 'blue',
41+
width: '800',
42+
}),
43+
]),
44+
h('div.m4', [
45+
chartTimeSeries({
46+
series: model.series3,
47+
title: 'Sinus rounded',
48+
colorPrimary: 'green',
49+
width: '800',
50+
}),
51+
]),
52+
];
53+
54+
// Create some basic model
55+
const model = new Observable();
56+
model.series1 = [];
57+
model.series2 = [];
58+
model.series3 = [];
59+
model.notify();
60+
61+
// Add points at 30 FPS but keep only first 800 points for memory leak
62+
let i = 0;
63+
setInterval(() => {
64+
i++;
65+
model.series1.push({value: Math.cos(i / 10), timestamp: Date.now()});
66+
model.series2.push({value: Math.random() * 10, timestamp: Date.now()});
67+
model.series3.push({value: Math.round(Math.cos(i / 10)), timestamp: Date.now()});
68+
69+
model.series1.splice(0, model.series1.length - 800);
70+
model.series2.splice(0, model.series2.length - 800);
71+
model.series3.splice(0, model.series3.length - 800);
72+
73+
model.notify();
74+
}, 33);
75+
76+
mount(document.body, view, model, true);
77+
78+
window.model = model;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<title>Advanced Frontend Demo</title>
3+
<link rel="stylesheet" href="/css/src/bootstrap.css">
4+
<body class="bg-gray">
5+
<!-- This will be replaced by template engine when loaded completly -->
6+
Loading...
7+
</body>
8+
9+
<!-- Main application -->
10+
<script type="module" src="main.js"></script>

0 commit comments

Comments
 (0)