Laravel details view. Adjusted navbar and routes

This commit is contained in:
2017-09-24 01:31:39 +02:00
parent 736cbd3ac7
commit 60b0cabed3
5 changed files with 142 additions and 25 deletions

View File

@@ -11,26 +11,30 @@ use App\Http\Requests;
class PagesController extends Controller class PagesController extends Controller
{ {
// //
public function dashboard() { public function details() {
$pagetitle = 'Dashboard'; $pagetitle = 'Details';
$activeNav = 'dashboard'; $activeNav = 'details';
$temperature = Stats::select('temperature') $temperature = Stats::select('temperature')
->where('node_id', 1)
->limit('144') ->limit('144')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->pluck('temperature'); ->pluck('temperature');
$humidity = Stats::select('humidity') $humidity = Stats::select('humidity')
->where('node_id', 1)
->limit('144') ->limit('144')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->pluck('humidity'); ->pluck('humidity');
$gm3 = Stats::select('gm3') $gm3 = Stats::select('gm3')
->where('node_id', 1)
->limit('144') ->limit('144')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->pluck('gm3'); ->pluck('gm3');
$created_at = Stats::select('created_at') $created_at = Stats::select('created_at')
->where('node_id', 1)
->limit('144') ->limit('144')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->pluck('created_at'); ->pluck('created_at');
@@ -56,10 +60,7 @@ public function dashboard() {
$latestHumidity = '' . $latestHumidity[0]; $latestHumidity = '' . $latestHumidity[0];
$latestGM3 = '' . $latestGM3[0]; $latestGM3 = '' . $latestGM3[0];
$chart[0] = Charts::multi('line', 'material')
$latestShit = 'Temp: ' . $latestTemp . ' Hum: ' . $latestHumidity . ' g/m³: ' . $latestGM3;
$chart = Charts::multi('line', 'material')
->title("Temperatur, Luftfeuchtigkeit, g/m³") ->title("Temperatur, Luftfeuchtigkeit, g/m³")
->dimensions(0, 400) // Width x Height ->dimensions(0, 400) // Width x Height
// This defines a preset of colors already done:) // This defines a preset of colors already done:)
@@ -73,21 +74,36 @@ public function dashboard() {
// Setup what the values mean // Setup what the values mean
->labels($created_at); ->labels($created_at);
return view('dashboard')->with([ $chart[1] = Charts::multi('line', 'material')
->title("Temperatur")
->dimensions(0, 400) // Width x Height
// This defines a preset of colors already done:)
->template("material")
// You could always set them manually
// ->colors(['#2196F3', '#F44336', '#FFC107'])
// Setup the diferent datasets (this is a multi chart)
->dataset('°C', $temperature)
//->dataset('%', $humidity)
//->dataset('g/m³', $gm3)
// Setup what the values mean
->labels($created_at);
return view('details')->with([
'pagetitle' => $pagetitle, 'pagetitle' => $pagetitle,
'activeNav' => $activeNav, 'activeNav' => $activeNav,
'chart' => $chart, 'chart' => $chart,
'latestTemp' => $latestTemp, 'latestTemp' => $latestTemp,
'latestHumidity' => $latestHumidity, 'latestHumidity' => $latestHumidity,
'latestGM3' => $latestGM3, 'latestGM3' => $latestGM3,
'latestShit' => $latestShit,
]); ]);
} }
public function welcome() { public function dashboard() {
$pagetitle = 'Willkommen'; $pagetitle = 'Dashboard';
$activeNav = 'welcome'; $activeNav = 'dashboard';
//Db queries
$latestTemp = Stats::select('temperature') $latestTemp = Stats::select('temperature')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
@@ -103,12 +119,29 @@ public function dashboard() {
->limit('1') ->limit('1')
->pluck('gm3'); ->pluck('gm3');
return view('welcome')->with([ //Pick values from array
$latestTemp = $latestTemp[0];
$latestHumidity = $latestHumidity[0];
$latestGM3 = $latestGM3[0];
//prepare suggestion
$compareIDs = '1-2';
$ids = explode('-', $compareIDs);
$latestTest = 11.0; //Outside
$lowerHumidityMode = true; //true --> suggestion lowers inside humidity; false --> suggestion heighten inside humidity
if ($lowerHumidityMode) {
($latestGM3 > $latestTest) ? $air = true : $air = false;
} else {
($latestGM3 < $latestTest) ? $air = true : $air = false;
}
return view('dashboard')->with([
'pagetitle' => $pagetitle, 'pagetitle' => $pagetitle,
'activeNav' => $activeNav, 'activeNav' => $activeNav,
'latestTemp' => $latestTemp, 'latestTemp' => $latestTemp,
'latestHumidity' => $latestHumidity, 'latestHumidity' => $latestHumidity,
'latestGM3' => $latestGM3, 'latestGM3' => $latestGM3,
'air' => $air,
]); ]);
} }

View File

@@ -3,9 +3,7 @@
@section('title', $pagetitle) @section('title', $pagetitle)
@section('content') @section('content')
{!! Charts::styles() !!}
<h1>Dashboard <small>Infos auf einen Blick</small></h1> <h1>Dashboard <small>Infos auf einen Blick</small></h1>
<table style="width:100%"> <table style="width:100%">
<tr> <tr>
<td> <td>
@@ -45,12 +43,37 @@
</tr> </tr>
</table> </table>
@if($latestHumidity > 80)
<div class="resizechart resizechart2"> <div class="panel panel-danger">
{!! $chart->html() !!} @else
<div class="panel panel-success">
@endif
<div class="panel-heading">
<h3 class="panel-title">Schimmelbildung</h3>
</div>
<div class="panel-body">
@if($latestHumidity >= 75)
Die Luftfeuchtigkeit liegt bei {!! $latestHumidity !!} %. Es besteht Schimmelgefahr!
@else
Es besteht keine Schimmelgefahr! Luftfeuchtigkeit: {!! $latestHumidity !!} %.
@endif
</div>
</div> </div>
@if($air)
{!! Charts::scripts() !!} <div class="panel panel-success">
{!! $chart->script() !!} @else
<div class="panel panel-danger">
@endif
<div class="panel-heading">
<h3 class="panel-title">Lüftungsempfehlung</h3>
</div>
<div class="panel-body">
@if($air)
Es kann gelüftet werden, um die Luftfeuchtigkeit zu verringern.
@else
Es sollte nicht gelüftet werde. Die Luftfeuchtigkeit würde sich erhöhen.
@endif
</div>
</div>
@endsection @endsection

View File

@@ -0,0 +1,61 @@
@extends('layouts.master')
@section('title', $pagetitle)
@section('content')
{!! Charts::styles() !!}
<h1>Details <small>Genauere Infos</small></h1>
<table style="width:100%">
<tr>
<td>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Temperatur</h3>
</div>
<div class="panel-body">
<p>{!! $latestTemp !!} °C</p>
</div>
</div>
</td>
<td>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Luftfeuchtigkeit</h3>
</div>
<div class="panel-body">
<p>{!! $latestHumidity !!} %</p>
</div>
</div>
</td>
<td>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Absoluter Feuchtegehalt </h3>
</div>
<div class="panel-body">
<p>{!! $latestGM3 !!} g/</p>
</div>
</div>
</td>
</tr>
</table>
<div class="resizechart resizechart2">
@foreach($chart as $ch)
{!! $ch->html() !!}
</br>
@endforeach
</div>
{!! Charts::scripts() !!}
@foreach($chart as $ch)
{!! $ch->script() !!}
@endforeach
@endsection

View File

@@ -55,12 +55,12 @@
{{-- Left Side Of Navbar --}} {{-- Left Side Of Navbar --}}
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
{{-- Navlink Startseite --}} {{-- Navlink Startseite --}}
@if(isset($activeNav) && $activeNav == 'dashboard') @if(isset($activeNav) && $activeNav == 'details')
<li class="active"> <li class="active">
@else @else
<li> <li>
@endif @endif
<a href="{{ url('/dashboard') }}">Dashboard</a> <a href="{{ url('/details') }}">Details</a>
</li> </li>

View File

@@ -12,6 +12,6 @@
*/ */
Route::get('/', 'PagesController@welcome'); Route::get('/', 'PagesController@dashboard');
Route::get('/dashboard', 'PagesController@dashboard'); Route::get('/details', 'PagesController@details');