Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from RedRoundRobin/feature/backendMod
Browse files Browse the repository at this point in the history
Feature/backend mod
  • Loading branch information
Maxelweb committed Apr 9, 2020
2 parents d216203 + 99c8f49 commit 6d4ff85
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 175 deletions.
5 changes: 1 addition & 4 deletions __tests__/ChartManagement.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import SingleChart from "../resources/js/components/SingleChart";

window.axios = require("axios");

import { mount } from "@vue/test-utils";
import DoubleChart from "../resources/js/components/DoubleChart.vue";
import SingleChart from "../resources/js/components/SingleChart";

describe("DoubleChart", () => {
test("is a Vue instance", () => {
Expand All @@ -18,8 +17,6 @@ describe("DoubleChart", () => {
});
});

import SingleChartChart from "../resources/js/components/SingleChart";

describe("SingleChart", () => {
test("is a Vue instance", () => {
const sensor =
Expand Down
62 changes: 62 additions & 0 deletions app/Http/Controllers/GraphsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Http\Controllers;

use App\Providers\ViewGraphServiceProvider;
use App\Providers\ViewServiceProvider;

class GraphsController extends Controller
{
private $viewGraphProvider;
private $viewProvider;


/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->viewGraphProvider = new ViewGraphServiceProvider();
$this->viewProvider = new ViewServiceProvider();
}
public function store($viewId)
{
if ($this->viewProvider->find($viewId)) {
$data = request()->validate([
'correlation' => 'required|string|in:0,1,2,3',
'sensor1' => 'required|string',
'sensor2' => 'required|string'
]);
$data['view'] = $viewId;
$data = array_map(function ($value) {
return (int)$value;
}, $data);
$this->viewGraphProvider->store(json_encode($data));
return redirect(route('views.show', ['viewId' => $viewId]));
}
}
public function destroy($viewGraphId)
{
$this->viewGraphProvider->destroy($viewGraphId);
return redirect(route('views.index'));
}

/* public function update($viewId){
if($this->viewProvider->find($viewId)){
$data = request()->validate([
'correlation' => 'required|string|in:0,1,2,3',
'sensor1' => 'required|string',
'sensor2' => 'required|string'
]);
$data['view'] = $viewId;
$data = array_map(function ($value) {
return (int)$value;
}, $data);
$this->viewGraphProvider->update($viewId, json_encode($data));
return redirect(route('views.show', ['viewId' => $viewId]));
}
}*/
}
53 changes: 42 additions & 11 deletions app/Http/Controllers/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Sensor;
use App\Models\View;
use App\Models\ViewGraph;
use App\Providers\DeviceServiceProvider;
use App\Providers\SensorServiceProvider;
use App\Providers\ViewGraphServiceProvider;
use App\Providers\ViewServiceProvider;
Expand All @@ -14,6 +15,7 @@ class ViewController extends Controller
private $viewProvider;
private $viewGraphProvider;
private $sensorProvider;
private $deviceProvider;

/**
* Create a new controller instance.
Expand All @@ -26,6 +28,7 @@ public function __construct()
$this->viewProvider = new ViewServiceProvider();
$this->viewGraphProvider = new ViewGraphServiceProvider();
$this->sensorProvider = new SensorServiceProvider();
$this->deviceProvider = new DeviceServiceProvider();
}

public function index()
Expand All @@ -36,21 +39,49 @@ public function index()

public function show($viewId)
{
$graphs = $this->viewGraphProvider->findAllFromView($viewId);
$view = $this->viewProvider->find($viewId);
$sensors = $this->sensorProvider->findAll();
$sensor1 = null;
$sensor2 = null;
foreach ($graphs as $graph) {
foreach ($sensors as $sensor) {
if ($sensor->realSensorId == $graph->sensor1) {
$sensor1 = $sensor;
$graphs = $this->viewGraphProvider->findAllFromView($viewId);
$devices = $this->deviceProvider->findAll();
foreach ($devices as $d) {
$sensors[$d->deviceId] = $this->sensorProvider->findAllFromDevice($d->deviceId);
}
$sensorsOnGraphs = [];
foreach ($graphs as $g) {
$found = [0 => false,1 => false];
foreach ($devices as $d) {
foreach ($sensors[$d->deviceId] as $s) {
if ($g->sensor1 == $s->sensorId) {
$sensorsOnGraphs[$g->viewGraphId][0] = $s;
$found[0] = true;
}
if ($g->sensor2 == $s->sensorId) {
$sensorsOnGraphs[$g->viewGraphId][1] = $s;
$found[1] = true;
}
if ($found[0] && $found[1]) {
break;
}
}
if ($sensor->realSensorId == $graph->sensor2) {
$sensor2 = $sensor;
if ($found[0] && $found[1]) {
break;
}
}
}
return view('views.show', compact(['graphs','view', 'sensor1', 'sensor2']));
return view('views.show', compact(['graphs','view','sensorsOnGraphs', 'sensors', 'devices']));
}

public function destroy($userId)
{
$this->viewProvider->destroy($userId);
return redirect(route('views.index'));
}

public function store()
{
$data = request()->validate([
'viewName' => 'required|string',
]);
$this->viewProvider->store(json_encode(['name' => $data['viewName']]));
return redirect(route('views.index'));
}
}
43 changes: 37 additions & 6 deletions app/Providers/ViewGraphServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()
{
parent::__construct(app());
$this->request = new Client([
'base_uri' => config('app.api') . '/viewGraphs/',
'base_uri' => config('app.api') . '/viewGraphs',
'headers' => [
'Content-Type' => 'application/json',
]
Expand All @@ -31,12 +31,12 @@ public function __construct()
public function find($identifier)
{
try {
$response = json_decode($this->request->get($identifier, $this->setHeaders())->getBody());
$response = json_decode($this->request->get('/viewGraphs/' . $identifier, $this->setHeaders())->getBody());
$graph = new ViewGraph();
$graph->fill((array)$response);
return $graph;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
Expand All @@ -56,15 +56,15 @@ public function findAll()
}
return $graphs;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
public function findAllFromView($viewId)
{
try {
$response = json_decode($this->request->get('', array_merge($this->setHeaders(), [
'query' => 'viewId=' . $viewId
'query' => 'view=' . $viewId
]))->getBody());
$graphs = [];
foreach ($response as $g) {
Expand All @@ -74,8 +74,39 @@ public function findAllFromView($viewId)
}
return $graphs;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
public function store(string $body)
{
try {
$this->request->post('', array_merge($this->setHeaders(), [
'body' => $body
]));
} catch (RequestException $e) {
$this->isExpired($e);
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
}
}
public function destroy(string $who)
{
try {
$this->request->delete('/viewGraphs/' . $who, $this->setHeaders());
} catch (RequestException $e) {
$this->isExpired($e);
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
}
}
/* public function update(string $who, string $body)
{
try {
$this->request->put('/viewGraphs/' . $who, array_merge($this->setHeaders(), [
'body' => $body
]));
} catch (RequestException $e) {
$this->isExpired($e);
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
}
}*/
}
37 changes: 32 additions & 5 deletions app/Providers/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()
{
parent::__construct(app());
$this->request = new Client([
'base_uri' => config('app.api') . '/views/',
'base_uri' => config('app.api') . '/views',
'headers' => [
'Content-Type' => 'application/json',
]
Expand All @@ -31,12 +31,12 @@ public function __construct()
public function find($identifier)
{
try {
$response = json_decode($this->request->get($identifier, $this->setHeaders())->getBody());
$response = json_decode($this->request->get('/views/' . $identifier, $this->setHeaders())->getBody());
$view = new View();
$view->fill((array)$response);
return $view;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
Expand All @@ -56,7 +56,7 @@ public function findAll()
}
return $views;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
Expand All @@ -75,8 +75,35 @@ public function findAllFromUser($user)
}
return $views;
} catch (RequestException $e) {
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
$this->isExpired($e);
return null;
}
}
/**
* @param string $who
*/
public function destroy(string $who)
{
try {
$this->request->delete('/views/' . $who, $this->setHeaders());
} catch (RequestException $e) {
$this->isExpired($e);
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
}
}

/**
* @param string $body
*/
public function store(string $body)
{
try {
$this->request->post('', array_merge($this->setHeaders(), [
'body' => $body
]));
} catch (RequestException $e) {
$this->isExpired($e);
abort($e->getCode(), $e->getResponse()->getReasonPhrase());
}
}
}
12 changes: 3 additions & 9 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ window.Vue = require("vue");
// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Vue.component(
"double-chart",
require("./components/DoubleChart.vue").default
);
Vue.component(
"single-chart",
require("./components/SingleChart.vue").default
);
Vue.component("double-chart", require("./components/DoubleChart.vue").default);
Vue.component("single-chart", require("./components/SingleChart.vue").default);

import VueApexCharts from "vue-apexcharts";
Vue.use(VueApexCharts);
Expand All @@ -44,6 +38,6 @@ Vue.component("apexchart", VueApexCharts);
* or customize the JavaScript scaffolding to fit your unique needs.
*/

var app = new Vue({
const app = new Vue({
el: "#app",
});
Loading

0 comments on commit 6d4ff85

Please sign in to comment.