Skip to content

Commit

Permalink
Implemented multilingual support
Browse files Browse the repository at this point in the history
  • Loading branch information
GijsGoudzwaard committed Oct 26, 2019
1 parent db7df1e commit 21fd6e0
Show file tree
Hide file tree
Showing 13 changed files with 34,997 additions and 32 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"require-dev": {
}
}
15 changes: 14 additions & 1 deletion dist/css/card.css
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
.resources-card{height:auto;padding-bottom:1px}.resources-card h3:first-letter{text-transform:capitalize}.resources{width:100%!important;height:200px!important}
.resources-card {
height: auto;
padding-bottom: 1px;
}

.resources-card h3::first-letter {
text-transform: capitalize;
}

.resources {
width: 100% !important;
height: 200px !important;
}

34,943 changes: 34,942 additions & 1 deletion dist/js/card.js

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions resources/js/chart.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import 'chartjs-plugin-streaming';
import axios from 'axios';
import * as moment from 'moment';

export default function lineChart(usage, resource, element) {
export default function lineChart(ctx, element) {
let chart = element.getContext("2d");
let resources = buildData(ctx.card.usage);

let resources = buildData(usage);
moment.locale(ctx.card.locale);

chart = new Chart(chart, {
type: 'line',
data: {
datasets: [{
label: 'Usage',
label: ctx.$root.__('usage'),
data: resources,
borderColor: '#4099de',
backgroundColor: '#fff',
Expand Down Expand Up @@ -48,10 +50,10 @@ export default function lineChart(usage, resource, element) {
delay: 10000,
refresh: 5000,
onRefresh: function (chart) {
axios.get('/nova-vendor/systemResources/' + resource).then(function (result) {
axios.get('/nova-vendor/systemResources/' + ctx.resource).then(function (result) {
chart.data.datasets.forEach(function (dataset) {
dataset.data.push({
x: Date.now(),
x: moment(),
y: Math.round(result.data)
});
});
Expand All @@ -64,20 +66,20 @@ export default function lineChart(usage, resource, element) {
}
});

axios.get('/nova-vendor/systemResources/' + resource).then(function (result) {
axios.get('/nova-vendor/systemResources/' + ctx.resource).then(function (result) {
chart.data.datasets.forEach(function (dataset) {
if (usage === null) {
if (ctx.card.usage === null) {
dataset.data.push({
x: Date.now() - (10000),
x: moment().subtract(10, 'seconds'),
y: Math.round(result.data)
});
dataset.data.push({
x: Date.now() - (5000),
x: moment().subtract(5, 'seconds'),
y: Math.round(result.data)
});
}
dataset.data.push({
x: Date.now(),
x: moment(),
y: Math.round(result.data)
});
});
Expand All @@ -91,7 +93,7 @@ function buildData(usage) {

for (let i in usage) {
resources.push({
x: Date.now() - ((usage.length * 5000) - (i * 5000)),
x: moment().subtract((usage.length * 5) - (i * 5), 'seconds'),
y: usage[i]
});
}
Expand Down
10 changes: 2 additions & 8 deletions resources/js/components/Card.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<template>
<card class="px-6 py-4 resources-card">
<h3 class="mr-3 text-base text-80 font-bold">
<span class="uppercase">{{ resource }}</span> usage
</h3>
<h3 class="mr-3 text-base text-80 font-bold">{{ __(`${resource}_usage`) }}</h3>

<div class="flex mb-4 resources">
<canvas v-bind:id="resource" height="150"></canvas>
Expand All @@ -17,11 +15,7 @@
props: ["card"],
mounted() {
lineChart(
this.card.usage,
this.resource,
document.getElementById(this.resource)
);
lineChart(this, document.getElementById(this.resource));
},
data() {
Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cpu_usage": "CPU usage",
"ram_usage": "RAM usage",
"usage": "Usage"
}
5 changes: 5 additions & 0 deletions resources/lang/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cpu_usage": "CPU verbruik",
"ram_usage": "RAM verbruik",
"usage": "Verbruik"
}
2 changes: 0 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -17,4 +16,3 @@
Route::get('ram', 'GijsG\SystemResources\SystemResources@ram');

Route::get('cpu', 'GijsG\SystemResources\SystemResources@cpu');

6 changes: 3 additions & 3 deletions src/Adapters/LinuxSystemResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LinuxSystemResources implements SystemResourcesInterface
public function __construct()
{
$free = shell_exec('free');
$free = (string)trim($free);
$free = (string) trim($free);

$free_arr = explode("\n", $free);

Expand All @@ -46,7 +46,7 @@ public function cpuResources()
*/
public function ramResources()
{
return (int)$this->ram_resources[2];
return (int) $this->ram_resources[2];
}

/**
Expand All @@ -56,7 +56,7 @@ public function ramResources()
*/
public function ramTotalResources()
{
return (int)$this->ram_resources[1];
return (int) $this->ram_resources[1];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Adapters/WindowsSystemResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function ramResources()
{
$ram = shell_exec("wmic OS get FreePhysicalMemory /Value");
$ram = (int) str_replace('FreePhysicalMemory=', '', $ram);

return (int) ($ram / 1024);
}

Expand All @@ -37,6 +38,7 @@ public function ramTotalResources()
{
$ram = shell_exec("wmic OS get TotalVisibleMemorySize /Value");
$ram = (int) str_replace('TotalVisibleMemorySize=', '', $ram);

return (int) ($ram / 1024);
}

Expand Down
10 changes: 6 additions & 4 deletions src/CardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public function boot()
$this->routes();
});

Nova::translations(__DIR__ . '/../resources/lang/' . app()->getLocale() . '.json');

Nova::serving(function (ServingNova $event) {
Nova::script('systemResources', __DIR__.'/../dist/js/card.js');
Nova::style('systemResources', __DIR__.'/../dist/css/card.css');
Nova::script('systemResources', __DIR__ . '/../dist/js/card.js');
Nova::style('systemResources', __DIR__ . '/../dist/css/card.css');
});
}

Expand All @@ -38,8 +40,8 @@ protected function routes()
}

Route::middleware(['nova'])
->prefix('nova-vendor/systemResources')
->group(__DIR__.'/../routes/api.php');
->prefix('nova-vendor/systemResources')
->group(__DIR__ . '/../routes/api.php');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/SystemResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function component()
return $this->withMeta([
'usage' => $this->usage,
'resource' => $this->resource,
'locale' => app()->getLocale(),
'component' => 'systemAnalytics'
]);
}
Expand Down
2 changes: 1 addition & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let mix = require('laravel-mix')

mix.js('resources/js/card.js', 'dist/js')
.sass('resources/sass/card.scss', 'dist/css')
.sass('resources/sass/card.scss', 'dist/css')

0 comments on commit 21fd6e0

Please sign in to comment.