Skip to content

Commit

Permalink
chore: implement i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed Jun 28, 2019
1 parent c1ad44d commit 78b470d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 19 deletions.
19 changes: 19 additions & 0 deletions config/dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"type": "addons"
},
{
"type": "alarms",
"options": {
"extend": true,
"max": 5
}
},
{
"type": "chart",
"options": {
"extend": true,
"mic": "?"
}
}
]
13 changes: 13 additions & 0 deletions i18n/english.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format": "en-GB",
"keys": {
"activity_overview": "Activity Overview",
"search": "Search",
"menu": {
"dashboard": "Dashboard",
"alarmconsole": "Alarms Console",
"alerting": "Alertings Views",
"metrics": "Metrics"
}
}
}
18 changes: 18 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare namespace IHM {
interface i18n {
format: string;
keys: {
activity_overview: string;
search: string;
menu: {
dashboard: string;
alarmconsole: string;
alerting: string;
metrics: string;
}
}
}
}

export = IHM;
export as namespace IHM;
30 changes: 29 additions & 1 deletion src/httpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const send = require("@polka/send-type");
const sirv = require("sirv");
const zup = require("zup");

// Require Internal Dependencies
/** @type {IHM.i18n} */
const i18n = require("../i18n/english.json");

// CONSTANTS
const PUBLIC_DIR = join(__dirname, "..", "public");
const VIEWS_DIR = join(__dirname, "..", "views");
Expand Down Expand Up @@ -40,16 +44,40 @@ async function getActivityOverview(ihm) {
*/
function exportServer(ihm) {
const httpServer = polka();

// Serve static assets!
httpServer.use(sirv(PUBLIC_DIR, { dev: true }));

httpServer.get("/", async(req, res) => {
try {
console.time("get_home");
const [views, data] = await Promise.all([
readFile(join(VIEWS_DIR, "index.html"), "utf-8"),
getActivityOverview(ihm)
]);

send(res, 200, zup(views)(data), { "Content-Type": "text/html" });
const menu = {
dashboard: {
title: i18n.keys.menu.dashboard,
icon: "icon-home"
},
alarmconsole: {
title: i18n.keys.menu.alarmconsole,
icon: "icon-bell-alt"
},
alerting: {
title: i18n.keys.menu.alerting,
icon: "icon-eye"
},
metrics: {
title: i18n.keys.menu.metrics,
icon: "icon-chart-line"
}
};

const renderedHTML = zup(views)(Object.assign(data, { menu, i18n }));
send(res, 200, renderedHTML, { "Content-Type": "text/html" });
console.timeEnd("get_home");
}
catch (err) {
send(res, 500, err.message);
Expand Down
26 changes: 8 additions & 18 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>[[=z.serverName]]</h2>
</header>

<!-- Activity Overview (stats on alarms, mic & entities) -->
<p class="overview_title">Activity Overview</p>
<p class="overview_title">[[=z.i18n.keys.activity_overview]]</p>
<div class="overview">
<div>
<div class="bull"><i class="icon-bell"></i></div>
Expand All @@ -53,22 +53,12 @@ <h2>[[=z.serverName]]</h2>
<!-- Navigation (to update #view) -->
<nav>
<ul>
<li data-menu="dashboard">
<i class="icon-home"></i>
<p>Dashboard</p>
</li>
<li data-menu="alarmconsole">
<i class="icon-bell-alt"></i>
<p>Alarms Console</p>
</li>
<li data-menu="alerting" class="disabled">
<i class="icon-eye"></i>
<p>Alerting Views</p>
</li>
<li data-menu="metrics">
<i class="icon-chart-line"></i>
<p>Metrics</p>
</li>
[[ for (const [menu, prop] of Object.entries(z.menu)) { ]]
<li data-menu="[[=menu]]">
<i class="[[=prop.icon]]"></i>
<p>[[=prop.title]]</p>
</li>
[[ } ]]
</ul>
</nav>

Expand All @@ -94,7 +84,7 @@ <h2>[[=z.serverName]]</h2>
<link rel="stylesheet" href="css/searchbar.css">

<i class="icon-search"></i>
<input type="text" placeholder="Search">
<input type="text" placeholder="[[=z.i18n.keys.search]]">
<div class="help-btn">
<i class="icon-help"></i>
</div>
Expand Down

0 comments on commit 78b470d

Please sign in to comment.