Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrumentation: add status and events page #363

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace HMS\Repositories\Instrumentation\Doctrine;

use Doctrine\ORM\EntityRepository;
use HMS\Entities\Instrumentation\Event;
use HMS\Entities\Instrumentation\Service;
use HMS\Repositories\Instrumentation\EventRepository;
use LaravelDoctrine\ORM\Pagination\PaginatesFromRequest;

class DoctrineEventRepository extends EntityRepository implements EventRepository
{
use PaginatesFromRequest;

/**
* @param Service $service
* @param int $perPage
* @param string $pageName
*
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
public function paginateByService(Service $service, $perPage = 50, $pageName = 'page')
{
$q = parent::createQueryBuilder('event')
->where('event.value = :service_name')
->orderBy('event.time', 'DESC');

$q = $q->setParameter('service_name', $service->getName())->getQuery();

return $this->paginate($q, $perPage, $pageName);
}

/**
* save Event to the DB.
* @param Event $event
*/
public function save(Event $event)
{
$this->_em->persist($event);
$this->_em->flush();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace HMS\Repositories\Instrumentation\Doctrine;

use Doctrine\ORM\EntityRepository;
use HMS\Entities\Instrumentation\Service;
use HMS\Repositories\Instrumentation\ServiceRepository;

class DoctrineServiceRepository extends EntityRepository implements ServiceRepository
{
/**
* Finds all entities in the repository.
*
* @return array The entities.
*/
public function findAll()
{
return parent::findAll();
}

/**
* save Service to the DB.
* @param Service $service
*/
public function save(Service $service)
{
$this->_em->persist($service);
$this->_em->flush();
}
}
24 changes: 24 additions & 0 deletions app/HMS/Repositories/Instrumentation/EventRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace HMS\Repositories\Instrumentation;

use HMS\Entities\Instrumentation\Event;
use HMS\Entities\Instrumentation\Service;

interface EventRepository
{
/**
* @param Service $service
* @param int $perPage
* @param string $pageName
*
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
public function paginateByService(Service $service, $perPage = 15, $pageName = 'page');

/**
* save Event to the DB.
* @param Event $event
*/
public function save(Event $event);
}
21 changes: 21 additions & 0 deletions app/HMS/Repositories/Instrumentation/ServiceRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace HMS\Repositories\Instrumentation;

use HMS\Entities\Instrumentation\Service;

interface ServiceRepository
{
/**
* Finds all entities in the repository.
*
* @return array The entities.
*/
public function findAll();

/**
* save Service to the DB.
* @param Service $service
*/
public function save(Service $service);
}
57 changes: 57 additions & 0 deletions app/Http/Controllers/Instrumentation/ServiceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Controllers\Instrumentation;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use HMS\Entities\Instrumentation\Service;
use HMS\Repositories\Instrumentation\EventRepository;
use HMS\Repositories\Instrumentation\ServiceRepository;

class ServiceController extends Controller
{
/**
* @var ServiceRepository
*/
protected $serviceRepository;

/**
* @var EventRepository
*/
protected $eventRepository;

/**
* Construct a new Controller.
*
* @param ServiceRepository $serviceRepository
*/
public function __construct(
ServiceRepository $serviceRepository,
EventRepository $eventRepository
) {
$this->serviceRepository = $serviceRepository;
$this->eventRepository = $eventRepository;
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function status()
{
$services = $this->serviceRepository->findAll();

return view('instrumentation.status')
->with('services', $services);
}

public function eventsForService(Service $service, Request $request)
{
$events = $this->eventRepository->paginateByService($service);

return view('instrumentation.eventsForService')
->with('service', $service)
->with('events', $events);
}
}
2 changes: 2 additions & 0 deletions config/repositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
'Snackspace\Transaction',
'Tools\Tool',
'Tools\Booking',
'Instrumentation\Service',
'Instrumentation\Event',
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up(Schema $schema)
$now = Carbon::now();

$this->addSql('INSERT INTO label_templates (template_name, template, created_at, updated_at) VALUES
(\'incorrect_dnh\', \'N\nq792\nA180,5,0,4,3,3,N,"INCORRECT"\nA130,85,0,4,2,2,N,"DO NOT HACK LABEL"\n\nLO50,5,20,80\nLO50,105,20,20\n\nLO735,5,20,80\nLO735,105,20,20\n\nA10,170,0,4,1,1,N,"Correct Do Not Hack labels can be generated by"\nA10,210,0,4,1,1,N,"logging into the Hackspace Managment System(HMS)"\nA10,250,0,4,1,1,N,"https://hms.nottinghack.org.uk"\nA10,290,0,4,1,1,N,"and navigating to the \\\'Projects\\\' section"\n\n;qrcode and project Id\nb10,370,Q,s6,"https://guide.nottinghack.org.uk/do-not-hack.html"\nA220,370,0,4,1,1,N,"For more info about Do Not Hack"\nA220,400,0,4,1,1,N,"labels scan this QR code or visit:"\nA220,440,0,4,1,1,N,"https://guide.nottinghack.org.uk\"\n\nP1\n\', \''.$now.'\', \''.$now.'\')'
(\'incorrect_dnh\', \'N\nq792\nA180,5,0,4,3,3,N,"INCORRECT"\nA130,85,0,4,2,2,N,"DO NOT HACK LABEL"\n\nLO50,5,20,80\nLO50,105,20,20\n\nLO735,5,20,80\nLO735,105,20,20\n\nA10,170,0,4,1,1,N,"Correct Do Not Hack labels can be generated by"\nA10,210,0,4,1,1,N,"logging into the Hackspace Managment System(HMS)"\nA10,250,0,4,1,1,N,"https://hms.nottinghack.org.uk"\nA10,290,0,4,1,1,N,"and navigating to the \\\'Projects\\\' section"\n\n;qrcode and project Id\nb10,370,Q,s6,"https://guide.nottinghack.org.uk/do-not-hack.html"\nA220,370,0,4,1,1,N,"For more info about Do Not Hack"\nA220,400,0,4,1,1,N,"labels scan this QR code or visit:"\nA220,440,0,4,1,1,N,"https://guide.nottinghack.org.uk\"\n\nP1\n\', \'' . $now . '\', \'' . $now . '\')'
);
}

Expand Down
29 changes: 29 additions & 0 deletions resources/views/instrumentation/eventsForService.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@extends('layouts.app')

@section('pageTitle', 'Events for ' . $service->getName())

@section('content')
<div class="container">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Time</th>
<th>Type</th>
</tr>
</thead>
<tbody>
@foreach($events as $event)
<tr>
<td class="text-monospace">{{ $event->getTime()->toDateTimeString() }}</td>
<td>{{ $event->getType() }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="container">
{{ $events->links() }}
</div>
@endsection
33 changes: 33 additions & 0 deletions resources/views/instrumentation/status.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@extends('layouts.app')

@section('pageTitle', 'Instrumentaion Services')

@section('content')
<div class="container">
<div class="table-responsive no-more-tables">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Service</th>
<th>Status</th>
<th>Last response</th>
<th>Last restart</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($services as $service)
<tr class="{{ $service->getStatus() != 1 ? 'bg-danger text-white' : '' }}">
<td data-title="Service">{{ $service->getName() }}</td>
<td data-title="Status">{{ $service->getStatusString() }}</td>
<td data-title="Last response">{{ $service->getReplyTime()->toDateTimeString() }}</td>
<td data-title="Last restart">{{ $service->getRestartTime() ? $service->getRestartTime()->toDateTimeString() : '(unknown)' }}</td>
<td class="actions"><a class="btn btn-primary btn-sm btn-sm-spacing" href="{{ route('instrumentation.service.events', $service->getName() ) }}"><i class="far fa-eye" aria-hidden="true"></i> View Events</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

Route::get('home', 'HomeController@index')->name('home');
Route::get('access-codes', 'HomeController@accessCodes')->name('accessCodes');
Route::get('instrumentation/status', 'Instrumentation\ServiceController@status')
->name('instrumentation.status');
Route::get('instrumentation/{service}/events/', 'Instrumentation\ServiceController@eventsForService')
->name('instrumentation.service.events');

// Routes in the following group can only be access from inside the hackspace (as defined by the ip range in .env)
Route::middleware(['ipcheck'])->group(function () {
Expand Down