-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold-index-ts.txt
186 lines (146 loc) · 5.81 KB
/
old-index-ts.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { Express, Request, Response } from "express";
import { Wallet, Signer, providers } from 'ethers';
import { Nautilus } from '@deltadao/nautilus';
import { Certificate } from "crypto";
//import { Chart } from 'chart.js';
//import { ChartItem } from 'chart.js/auto';
//import 'jquery'
//import('chart.js/auto')
const ethers = require("ethers");
const ejs = require('ejs');
const express = require('express');
const Chart = require('chart.js/auto');
//var $ = require("jquery");
var jsdom = require('jsdom');
var $ = require('jquery')(new jsdom.JSDOM().window);
//const ChartItem = require('chart.js/auto')
const port = 8000;
const app: Express = express();
app.set('viewEngine', 'ejs');
app.use('/views', express.static('./views/index.html'))
var path = require('path');
app.engine('html', ejs.renderFile);
//ChartItem: (await import('chart.js')). defaults; //oder Modul spezifizieren statt defaults
interface DataPoints {
id: string;
value: number;
}
async function getDataSet() {
//const provider = new ethers.JsonRpcProvider('https://rpc.dev.pontus-x.eu');
const provider = new providers.JsonRpcProvider('https://rpc.dev.pontus-x.eu');
const signer = new Wallet('21ea41b4daed53bb966f0127d14b5e53e91014410da8fb267b351794a8bbb83c', provider);
console.log("created wallet");
console.log("created provider: "+ (await provider.detectNetwork()).chainId);
var datenpunkte = "";
const customConfig = {
chainId: 32456,
network: 'pontusx',
metadataCacheUri: 'https://aquarius.dev.pontus-x.eu',
nodeUri: 'https://rpc.dev.pontus-x.eu',
providerUri: 'https://provider.dev.pontus-x.eu',
subgraphUri: 'https://subgraph.dev.pontus-x.eu',
oceanTokenAddress: '0xdF171F74a8d3f4e2A789A566Dce9Fa4945196112',
oceanTokenSymbol: 'OCEAN',
fixedRateExchangeAddress: '0x8372715D834d286c9aECE1AcD51Da5755B32D505',
dispenserAddress: '0x5461b629E01f72E0A468931A36e039Eea394f9eA',
nftFactoryAddress: '0xFdC4a5DEaCDfc6D82F66e894539461a269900E13',
providerAddress: '0x68C24FA5b2319C81b34f248d1f928601D2E5246B'
};
const nautilus = await Nautilus.create(signer, customConfig);
console.log("created Nautilus");
const accessUrl = await nautilus.access({ assetDid: 'did:op:0fa5657f7382ef32a82325160a5430b79be701a361dfa0f27e1c3f22a96ddaf3'});
console.log("got URL: " + accessUrl);
const data = await fetch(accessUrl);
console.log("hier.");
data.text().then((text) => {
datenpunkte = text;
console.log("Empfangene Daten: " + datenpunkte);
return datenpunkte;
});
}
function createView(datenpunkte: Promise<void>) {
//var datenpunkte = getDataSet();
datenpunkte.then((text) => {
if (text == undefined || text == null) {
createView(datenpunkte);
} else {
console.log("This is going to the frontend: ");
console.log(text);
return text;
}
});
}
app.listen(port, () => {
console.log(`now listening on port ${port}`);
});
app.post('/', function(req, res) {
console.log("post funktion wurde aufgerufen");
res.redirect("/showData")
//res.sendFile(path.resolve('./views/viewData.html'));
});
app.get("/", (req: Request, res: Response) => {
res.sendFile(path.resolve('./views/index.html'));
});
app.get("/showData", (req: Request, res: Response) => {
var datenpunkte = getDataSet();
const text = createView(datenpunkte);
let dataPoints: DataPoints[] = [];
if(text != undefined) {
datapoints = JSON.parse(text);
}
var labels: string[] = ['a', 'b', 'c'];
var datapoints: number[] = [1, 2, 3];
dataPoints.forEach((pair) => {
labels.push(pair.id);
datapoints.push(pair.value);
});
const dataForChart = {
labels: labels,
datasets: [{
label: 'Fuellstand',
data: datapoints,
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
};
var ctx = $('.canvas');
console.log("found Element: " + ctx.length);
//var ctx = document.getElementById('line-chart');
const config = new Chart(ctx, {
type: 'line',
data: dataForChart,
});
res.render(path.resolve('./views/viewData.html'), {data: 'aabbcc'}); //ersetze aabbcc mit text, das kann jedoch nicht gerendert werden.
});
/////////////////////////////////////old html: ///////////////////////////////////////////////////////////////////
<script>
document.body.innerHTML = "<p>Start der JS-HTML Funktion</p>"
var labels = ['a', 'b', 'c'];
var datapoints = [1, 2, 3];
document.body.innerHTML = "<p>Definition der Daten in der JS-HTML Funktion</p>"
const dataForChart = {
labels: labels,
datasets: [{
label: 'Fuellstand',
data: datapoints,
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
};
document.body.innerHTML = "<p>Definition der Chart in der JS-HTML Funktion</p>"
var ctx = $('#viewData');
document.body.innerHTML = "<p>ctx in der JS-HTML Funktion: " + ctx + ". </p>"
console.log("Im Diagramm. ctx = " + ctx.length);
const myChart = new Chart(ctx, {type: 'line', data: dataForChart});
document.body.innerHTML = "<p>Ende der JS-HTML Funktion</p>"
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
/////////////////////////////////not working: ///////////////////////////////////////////////////////////////////////
<script>
const ctx = document.getElementById('myChart');
chartData = <%- passChartData() %>;
new Chart(ctx, chartData);
document.body.innerHTML = "<p>dataForCharts =" + chartData + " </p>";
</script>