Skip to content

Commit 7699819

Browse files
Show error to view
1 parent 514530a commit 7699819

File tree

7 files changed

+52
-32
lines changed

7 files changed

+52
-32
lines changed

Public/css/common.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ body {
6161
color: #0d6efd;
6262
border-color: #0d6efd;
6363
}
64+
65+
.alert {
66+
font-family: Menlo, Consolas, "DejaVu Sans Mono", "Ubuntu Mono", monospace;
67+
font-size: 11pt;
68+
}

Public/index.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,7 @@
108108
</div>
109109
<div id="statistics-tab-pane" class="tab-pane" role="tabpanel" aria-labelledby="statistics-tab"
110110
tabindex="0">
111-
<div id="statistics-container" class="" role="document">
112-
<table class="table table-borderless table-striped table-hover table-sm">
113-
<thead>
114-
<tr>
115-
<th scope="col" style="width: 60%;">Syntax</th>
116-
<th scope="col">Count</th>
117-
</tr>
118-
</thead>
119-
<tbody>
120-
</tbody>
121-
</table>
122-
</div>
111+
<div id="statistics-container" class="" role="document"></div>
123112
</div>
124113
</div>
125114
</div>

Public/js/app.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import "ace-builds/src-min-noconflict/theme-xcode";
1616
const Range = ace.require("ace/range").Range;
1717

1818
export class App {
19-
get contentMaxHeight() {
19+
get contentViewHeight() {
2020
const headerHeight = document.querySelector("header").clientHeight;
2121
const footerHeight = document.querySelector("footer").clientHeight;
2222
return `calc(100vh - ${headerHeight}px - ${footerHeight}px)`;
@@ -133,6 +133,13 @@ export class App {
133133
false
134134
);
135135

136+
const onresize = debounce(() => {
137+
this.onresize();
138+
}, 200);
139+
new ResizeObserver(() => {
140+
onresize();
141+
}).observe(document.body);
142+
136143
this.update();
137144
}
138145

@@ -179,19 +186,12 @@ export class App {
179186
}, []);
180187
this.updateStatistics(statistics);
181188

182-
document.getElementById("structure").style.maxHeight =
183-
this.contentMaxHeight;
184-
document.getElementById("syntax-container").style.maxHeight =
185-
this.contentMaxHeight;
186-
document.getElementById("statistics-container").style.maxHeight =
187-
this.contentMaxHeight;
189+
this.onresize();
188190
})
189191
.catch((error) => {
190-
if (error.status == 413) {
191-
alert("Payload Too Large");
192-
} else {
193-
alert("Something went wrong");
194-
}
192+
this.structureView.error = error;
193+
this.syntaxView.error = error;
194+
this.statisticsView.error = error;
195195
})
196196
.finally(() => {
197197
hideLoading();
@@ -241,6 +241,14 @@ export class App {
241241
}
242242
};
243243
}
244+
245+
onresize() {
246+
document.getElementById("structure").style.height = this.contentViewHeight;
247+
document.getElementById("syntax-container").style.height =
248+
this.contentViewHeight;
249+
document.getElementById("statistics-container").style.height =
250+
this.contentViewHeight;
251+
}
244252
}
245253

246254
function configurations() {

Public/js/statistics_view.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,35 @@ import "datatables.net-bs5/css/dataTables.bootstrap5.min.css";
66
import "../css/table.css";
77

88
export class StatisticsView {
9+
set error(error) {
10+
this.container.innerHTML = `<div class="alert alert-danger m-3" role="alert">${error}</div>`;
11+
}
12+
913
constructor(container) {
1014
this.container = container;
1115

1216
this.onmouseover = () => {};
1317
this.onmouseout = () => {};
14-
15-
this.init();
16-
}
17-
18-
init() {
19-
this.body = this.container.querySelector(":scope > table > tbody");
2018
}
2119

2220
update(statistics) {
23-
this.body.innerHTML = "";
21+
this.container.innerHTML = `<table class="table table-borderless table-striped table-hover table-sm">
22+
<thead>
23+
<tr>
24+
<th scope="col" style="width: 60%;">Syntax</th>
25+
<th scope="col">Count</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
</tbody>
30+
</table>
31+
`;
2432

33+
const body = this.container.querySelector(":scope > table > tbody");
2534
for (const row of statistics) {
2635
const tr = document.createElement("tr");
2736
tr.innerHTML = `<td style="font-family: Menlo, Consolas, 'DejaVu Sans Mono', 'Ubuntu Mono', monospace;">${row.text}</td><td><div>${row.ranges.length}</div></td>`;
28-
this.body.appendChild(tr);
37+
body.appendChild(tr);
2938

3039
tr.addEventListener("mouseover", (event) => {
3140
event.preventDefault();

Public/js/structure_view.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { TreeView } from "./tree_view.js";
44
import { Popover } from "./popover.js";
55

66
export class StructureView {
7+
set error(error) {
8+
this.container.innerHTML = `<div class="alert alert-danger m-3" role="alert">${error}</div>`;
9+
}
10+
711
constructor(container) {
812
this.container = container;
913
this.popover = new Popover();

Public/js/syntax_view.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { Popover } from "./popover.js";
44
import "../css/syntax.css";
55

66
export class SyntaxView {
7+
set error(error) {
8+
this.container.innerHTML = `<div class="alert alert-danger m-3" role="alert">${error}</div>`;
9+
}
10+
711
constructor(container) {
812
this.container = container;
913
this.popover = new Popover();

Public/scss/default.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@import "bootstrap/scss/dropdown";
1616
@import "bootstrap/scss/nav";
1717
@import "bootstrap/scss/badge";
18+
@import "bootstrap/scss/alert";
1819
@import "bootstrap/scss/close";
1920
@import "bootstrap/scss/modal";
2021
@import "bootstrap/scss/tooltip";

0 commit comments

Comments
 (0)