mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-04-21 16:02:11 +02:00
commit
b0efc012c2
@ -18,6 +18,7 @@ class CreateMetricsTable extends Migration
|
||||
$table->string('name');
|
||||
$table->string('suffix');
|
||||
$table->text('description');
|
||||
$table->integer('default_value');
|
||||
$table->boolean('display_chart')->default(1);
|
||||
$table->timestamps();
|
||||
|
||||
|
@ -70,6 +70,11 @@ return [
|
||||
'success' => 'Metrik-Punkt angelegt.',
|
||||
'failure' => 'Es ist ein Fehler bei der Erstellung eines Metrik-Punktes aufgetreten.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Edit a metric',
|
||||
'success' => 'Metric updated.',
|
||||
'failure' => 'Something went wrong with the metric.',
|
||||
],
|
||||
],
|
||||
|
||||
// Team
|
||||
|
@ -51,6 +51,19 @@ return [
|
||||
],
|
||||
],
|
||||
|
||||
// Metric form fields
|
||||
'metrics' => [
|
||||
'name' => 'Name',
|
||||
'suffix' => 'Suffix',
|
||||
'description' => 'Description',
|
||||
'description-help' => 'You may also use Markdown.',
|
||||
'display-chart' => 'Display chart on status page?',
|
||||
|
||||
'points' => [
|
||||
'value' => 'Value',
|
||||
],
|
||||
],
|
||||
|
||||
// Settings
|
||||
'settings' => [
|
||||
/// Application setup
|
||||
@ -60,6 +73,7 @@ return [
|
||||
'site-timezone' => 'Wählen Sie Ihre Zeitzone',
|
||||
'site-locale' => 'Wählen Sie Ihre Sprache',
|
||||
'date-format' => 'Datumsformat',
|
||||
'display-graphs' => 'Display graphs on status page?',
|
||||
'about-this-page' => 'Über diese Seite',
|
||||
'days-of-incidents' => 'Wie viele (vergangene) Tage sollen angezeigt werden?',
|
||||
'banner' => 'Banner-Bild',
|
||||
|
@ -37,6 +37,15 @@ return [
|
||||
'revoke' => 'Revoke API Key',
|
||||
],
|
||||
|
||||
// Metrics
|
||||
'metrics' => [
|
||||
'filter' => [
|
||||
'hourly' => 'Hourly',
|
||||
'daily' => 'Daily',
|
||||
'monthly' => 'Monthly',
|
||||
],
|
||||
],
|
||||
|
||||
// Other
|
||||
'powered_by' => ':app Status Page is powered by <a href="https://cachethq.io">Cachet</a>.',
|
||||
'about_this_site' => 'About this site',
|
||||
|
@ -73,9 +73,14 @@ return [
|
||||
'metrics' => [
|
||||
'metrics' => 'Metrics',
|
||||
'add' => [
|
||||
'title' => 'Create a metric point',
|
||||
'success' => 'Metric point created.',
|
||||
'failure' => 'Something went wrong with the metric point.',
|
||||
'title' => 'Create a metric',
|
||||
'success' => 'Metric created.',
|
||||
'failure' => 'Something went wrong with the metric.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Edit a metric',
|
||||
'success' => 'Metric updated.',
|
||||
'failure' => 'Something went wrong with the metric.',
|
||||
],
|
||||
],
|
||||
|
||||
|
@ -52,6 +52,20 @@ return [
|
||||
],
|
||||
],
|
||||
|
||||
// Metric form fields
|
||||
'metrics' => [
|
||||
'name' => 'Name',
|
||||
'suffix' => 'Suffix',
|
||||
'description' => 'Description',
|
||||
'description-help' => 'You may also use Markdown.',
|
||||
'display-chart' => 'Display chart on status page?',
|
||||
'default-value' => 'Default value',
|
||||
|
||||
'points' => [
|
||||
'value' => 'Value',
|
||||
],
|
||||
],
|
||||
|
||||
// Settings
|
||||
'settings' => [
|
||||
/// Application setup
|
||||
@ -61,6 +75,7 @@ return [
|
||||
'site-timezone' => 'Site Timezone',
|
||||
'site-locale' => 'Site Language',
|
||||
'date-format' => 'Date Format',
|
||||
'display-graphs' => 'Display graphs on status page?',
|
||||
'about-this-page' => 'About this page',
|
||||
'days-of-incidents' => 'How many days of incidents to show?',
|
||||
'banner' => 'Banner Image',
|
||||
|
@ -52,6 +52,19 @@ return [
|
||||
],
|
||||
],
|
||||
|
||||
// Metric form fields
|
||||
'metrics' => [
|
||||
'name' => 'Nombre',
|
||||
'suffix' => 'Sufijo',
|
||||
'description' => 'Descripción',
|
||||
'description-help' => 'Puedes usar también Markdown.',
|
||||
'display-chart' => '¿Vizualizar gráfica en la página de estado?',
|
||||
|
||||
'points' => [
|
||||
'value' => 'Valor',
|
||||
],
|
||||
],
|
||||
|
||||
// Settings
|
||||
'settings' => [
|
||||
/// Application setup
|
||||
@ -61,6 +74,7 @@ return [
|
||||
'site-timezone' => 'Zona horaria del sitio',
|
||||
'site-locale' => 'Idioma del sitio',
|
||||
'date-format' => 'Formato de la fecha',
|
||||
'display-graphs' => '¿Visualizar gráficas en la página de estado?',
|
||||
'about-this-page' => 'Sobre esta página',
|
||||
'days-of-incidents' => '¿Cuántos días de incidentes mostrar?',
|
||||
'banner' => 'Imagen de inicio',
|
||||
|
@ -76,6 +76,11 @@ return [
|
||||
'success' => 'Point de mesure créé.',
|
||||
'failure' => 'Il s\'est passé quelque chose avec ce point de mesure.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Edit a metric',
|
||||
'success' => 'Metric updated.',
|
||||
'failure' => 'Something went wrong with the metric.',
|
||||
],
|
||||
],
|
||||
|
||||
// Team
|
||||
|
@ -51,6 +51,19 @@ return [
|
||||
],
|
||||
],
|
||||
|
||||
// Metric form fields
|
||||
'metrics' => [
|
||||
'name' => 'Name',
|
||||
'suffix' => 'Suffix',
|
||||
'description' => 'Description',
|
||||
'description-help' => 'You may also use Markdown.',
|
||||
'display-chart' => 'Display chart on status page?',
|
||||
|
||||
'points' => [
|
||||
'value' => 'Value',
|
||||
],
|
||||
],
|
||||
|
||||
// Settings
|
||||
'settings' => [
|
||||
/// Application setup
|
||||
@ -60,6 +73,7 @@ return [
|
||||
'site-timezone' => 'Fuseau horaire du site',
|
||||
'site-locale' => 'Langue du site',
|
||||
'date-format' => 'Format de date',
|
||||
'display-graphs' => 'Display graphs on status page?',
|
||||
'about-this-page' => 'À propos de cette page',
|
||||
'days-of-incidents' => 'Nombre de jours à afficher ?',
|
||||
'banner' => 'Bannière',
|
||||
|
@ -77,8 +77,17 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache
|
||||
Route::group(['prefix' => 'metrics'], function () {
|
||||
Route::get('/', [
|
||||
'as' => 'dashboard.metrics',
|
||||
'uses' => 'DashboardController@showMetrics',
|
||||
'uses' => 'DashMetricController@showMetrics',
|
||||
]);
|
||||
|
||||
Route::get('add', [
|
||||
'as' => 'dashboard.metrics.add',
|
||||
'uses' => 'DashMetricController@showAddMetric',
|
||||
]);
|
||||
Route::post('add', 'DashMetricController@createMetricAction');
|
||||
Route::delete('{metric}/delete', 'DashMetricController@deleteMetricAction');
|
||||
Route::get('{metric}/edit', 'DashMetricController@showEditMetricAction');
|
||||
Route::post('{metric}/edit', 'DashMetricController@editMetricAction');
|
||||
});
|
||||
|
||||
// Notifications
|
||||
|
@ -6,7 +6,7 @@
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
<i class="icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.incidents.add.title') }}</small>
|
||||
</div>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
<i class="icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.incidents.edit.title') }}</small>
|
||||
</div>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
<i class="icon ion-android-alert"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
</span>
|
||||
<a class="btn btn-sm btn-success pull-right" href="{{ route('dashboard.incidents.add') }}">
|
||||
{{ trans('dashboard.incidents.add.title') }}
|
||||
|
54
app/views/dashboard/metrics/add.blade.php
Normal file
54
app/views/dashboard/metrics/add.blade.php
Normal file
@ -0,0 +1,54 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-stats-bars"></i> {{ trans('dashboard.metrics.metrics') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.metrics.add.title') }}</small>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@include('partials.dashboard.errors')
|
||||
<form class='form-vertical' name='MetricsForm' role='form' method='POST'>
|
||||
{{ Form::token() }}
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="metric-name">{{ trans('forms.metrics.name') }}</label>
|
||||
<input type="text" class="form-control" name="metric[name]" id="metric-name" required value="{{ Input::old('metric.name') }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="metric-suffix">{{ trans('forms.metrics.suffix') }}</label>
|
||||
<input type="text" class="form-control" name="metric[suffix]" id="metric-suffix" required value="{{ Input::old('metric.suffix') }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.description') }}</label>
|
||||
<div class='markdown-control'>
|
||||
<textarea name="metric[description]" class="form-control" rows="5" required>{{ Input::old('metric.description') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="metric-default_value">{{ trans('forms.metrics.default-value') }}</label>
|
||||
<input type="number" class="form-control" name="metric[default_value]" id="metric-default_value" value="{{ Input::old('metric.default_value') }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.display-chart') }}</label>
|
||||
<input type="hidden" value="0" name="metric[display_chart]">
|
||||
<input type="checkbox" value="1" name="metric[display_chart]" class="form-control" {{ Input::old('display_chart') ? 'checked' : null }}>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class='form-group'>
|
||||
<div class='btn-group'>
|
||||
<button type="submit" class="btn btn-success">{{ trans('forms.add') }}</button>
|
||||
<a class="btn btn-default" href="{{ route('dashboard.metrics') }}">{{ trans('forms.cancel') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
57
app/views/dashboard/metrics/edit.blade.php
Normal file
57
app/views/dashboard/metrics/edit.blade.php
Normal file
@ -0,0 +1,57 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon icon ion-android-alert"></i> {{ trans('dashboard.metrics.metrics') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.metrics.edit.title') }}</small>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@include('partials.dashboard.errors')
|
||||
<form class='form-vertical' name='MetricsForm' role='form' method='POST'>
|
||||
{{ Form::token() }}
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="metric-name">{{ trans('forms.metrics.name') }}</label>
|
||||
<input type="text" class="form-control" name="metric[name]" id="metric-name" required value={{ $metric->name }}>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="metric-suffix">{{ trans('forms.metrics.suffix') }}</label>
|
||||
<input type="text" class="form-control" name="metric[suffix]" id="metric-suffix" required value="{{ $metric->suffix }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.description') }}</label>
|
||||
<div class='markdown-control'>
|
||||
<textarea name="metric[description]" class="form-control" rows="5" required>{{ $metric->description }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="metric-default_value">{{ trans('forms.metrics.default-value') }}</label>
|
||||
<input type="number" class="form-control" name="metric[default_value]" id="metric-default_value" value="{{ $metric->default_value }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.display-chart') }}</label>
|
||||
<input type="hidden" value="0" name="metric[display_chart]">
|
||||
<input type="checkbox" value="1" name="metric[display_chart]" class="form-control" {{ $metric->display_chart ? 'checked' : null }}>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<input type="hidden" name="metric[id]" value={{$metric->id}}>
|
||||
|
||||
<div class='form-group'>
|
||||
<div class='btn-group'>
|
||||
<button type="submit" class="btn btn-success">{{ trans('forms.update') }}</button>
|
||||
<a class="btn btn-default" href="{{ route('dashboard.metrics') }}">{{ trans('forms.cancel') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
@ -1,16 +1,39 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="header fixed">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<i class="ion ion-stats-bars"></i> {{ trans('dashboard.metrics.metrics') }}
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-stats-bars"></i> {{ trans('dashboard.metrics.metrics') }}
|
||||
</span>
|
||||
<a class="btn btn-sm btn-success pull-right" href="{{ route('dashboard.metrics.add') }}">
|
||||
{{ trans('dashboard.metrics.add.title') }}
|
||||
</a>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h3>{{ trans('dashboard.metrics.metrics') }}</h3>
|
||||
<p class="lead">Eventually this page will show all of the graphs that make up your metrics.</p>
|
||||
<div class="content-wrapper header-fixed">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
@include('partials.dashboard.errors')
|
||||
<div class="striped-list">
|
||||
@foreach($metrics as $metric)
|
||||
<div class="row striped-list-item">
|
||||
<div class="col-md-6">
|
||||
<i class="{{ $metric->icon }}"></i> <strong>{{ $metric->name }}</strong>
|
||||
@if($metric->description)
|
||||
<p><small>{{ Str::words($metric->description, 5) }}</small></p>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-md-6 text-right">
|
||||
<a href="/dashboard/metrics/{{ $metric->id }}/edit" class="btn btn-default">{{ trans('forms.edit') }}</a>
|
||||
<a href="/dashboard/metrics/{{ $metric->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
|
@ -104,6 +104,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.settings.app-setup.display-graphs') }}</label>
|
||||
<input type="hidden" value="0" name="display_graphs">
|
||||
<input type="checkbox" value="1" name="display_graphs" class="form-control" {{ Setting::get('display_graphs') ? 'checked' : null }}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="form-group">
|
||||
|
@ -21,13 +21,13 @@
|
||||
|
||||
@include('partials.components')
|
||||
|
||||
{{-- @if(Setting::get('display_graphs'))
|
||||
@include('partials.graphs')
|
||||
@endif --}}
|
||||
@if($displayMetrics && Setting::get('display_graphs'))
|
||||
@include('partials.graphs')
|
||||
@endif
|
||||
|
||||
<h1>{{ trans('cachet.incidents.past') }}</h1>
|
||||
@foreach($allIncidents as $incidents)
|
||||
@include('partials.incidents', $incidents)
|
||||
@include('partials.incidents', $incidents)
|
||||
@endforeach
|
||||
<hr>
|
||||
|
||||
|
@ -55,12 +55,13 @@
|
||||
<span>{{ trans('dashboard.team.team') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{{-- <li {{ set_active('dashboard/metrics') }}>
|
||||
<li {{ set_active('dashboard/metrics*') }}>
|
||||
<a href="{{ route('dashboard.metrics') }}">
|
||||
<i class="ion ion-stats-bats"></i> {{ trans('cachet.dashboard.metrics') }}
|
||||
<i class="icon ion-stats-bars"></i>
|
||||
<span>{{ trans('dashboard.metrics.metrics') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
<li {{ set_active('dashboard/notifications') }}>
|
||||
{{-- <li {{ set_active('dashboard/notifications') }}>
|
||||
<a href="{{ route('dashboard.notifications') }}">
|
||||
<i class="ion ion-email"></i> {{ trans('cachet.dashboard.notifications') }}
|
||||
</a>
|
||||
|
@ -0,0 +1,69 @@
|
||||
@if($metrics->count() > 0)
|
||||
<ul class="list-group metrics">
|
||||
@foreach($metrics as $metric)
|
||||
<?php
|
||||
$points = range(0, 10);
|
||||
foreach($points as $hour) {
|
||||
$points[$hour] = $metric->getValues($hour);
|
||||
}
|
||||
$points = array_reverse($points);
|
||||
?>
|
||||
<li class="list-group-item metric">
|
||||
<div class="row">
|
||||
<div class="col-xs-10">
|
||||
<h4>
|
||||
{{ $metric->name }}
|
||||
@if($metric->description)
|
||||
<i class="ion ion-ios-help-outline" data-toggle="tooltip" data-title="{{ $metric->description }}"></i>
|
||||
@endif
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col-xs-2 text-right">
|
||||
<small>{{ trans('cachet.metrics.filter.hourly') }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div>
|
||||
<canvas id="metric-{{ $metric->id }}" height="150" width="600"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var hourList = [];
|
||||
var date = new Date();
|
||||
|
||||
for (var i = 10; i >= 1; i--) {
|
||||
hourList.push(moment(date).subtract(i, 'hours').seconds(0).format('HH:ss'));
|
||||
}
|
||||
|
||||
hourList.push(moment(date).seconds(0).format('HH:ss'));
|
||||
|
||||
var data = {
|
||||
showTooltips: false,
|
||||
labels: hourList,
|
||||
datasets: [{
|
||||
fillColor: "rgba(220,220,220,0.2)",
|
||||
strokeColor: "rgba(220,220,220,1)",
|
||||
pointColor: "rgba(220,220,220,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data: [{{ implode(',', $points) }}]
|
||||
}]
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
var ctx = document.getElementById("metric-{{ $metric->id }}").getContext("2d");
|
||||
window.myLine = new Chart(ctx).Line(data, {
|
||||
scaleShowVerticalLines: true,
|
||||
pointDot: false,
|
||||
responsive: true
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
@ -12,7 +12,8 @@
|
||||
"Sortable": "~1.0.0",
|
||||
"animate-sass": "~0.6.2",
|
||||
"moment": "~2.9",
|
||||
"livestampjs": "~1.1.2"
|
||||
"livestampjs": "~1.1.2",
|
||||
"chartjs": "~1.0.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"jquery": "~2.1.1"
|
||||
|
@ -20,6 +20,7 @@ elixir(function (mix) {
|
||||
'bower_components/livestampjs/livestamp.js',
|
||||
'bower_components/jquery-minicolors/jquery.minicolors.js',
|
||||
'bower_components/jquery-serialize-object/jquery.serialize-object.js',
|
||||
'bower_components/chartjs/Chart.js',
|
||||
'js/app.js',
|
||||
'js/**/*.js'
|
||||
], 'public/dist/js/all.js', './app/assets/')
|
||||
|
11
public/build/dist/js/all-35b543c2.js
vendored
11
public/build/dist/js/all-35b543c2.js
vendored
File diff suppressed because one or more lines are too long
13
public/build/dist/js/all-3f815dae.js
vendored
Normal file
13
public/build/dist/js/all-3f815dae.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
{
|
||||
"dist/css/all.css": "dist/css/all-3929b4f6.css",
|
||||
"dist/js/all.js": "dist/js/all-35b543c2.js"
|
||||
"dist/js/all.js": "dist/js/all-3f815dae.js"
|
||||
}
|
203
src/Http/Controllers/DashMetricController.php
Normal file
203
src/Http/Controllers/DashMetricController.php
Normal file
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashMetricController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
$metrics = Metric::orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
|
||||
'metrics' => $metrics,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetric()
|
||||
{
|
||||
return View::make('dashboard.metrics.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metric points.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetricPoints()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricAction()
|
||||
{
|
||||
$metricData = Binput::get('metric');
|
||||
$metric = Metric::create($metricData);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.metrics.add.failure')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric point view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetricPoint()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric point.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricPointAction()
|
||||
{
|
||||
$_point = Binput::get('point');
|
||||
$point = MetricPoint::create($_point);
|
||||
|
||||
if (! $point->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.failure')
|
||||
))
|
||||
->with('errors', $point->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteMetricAction(Metric $metric)
|
||||
{
|
||||
$metric->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit metric view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditMetricAction(Metric $metric)
|
||||
{
|
||||
return View::make('dashboard.metrics.edit')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'metric' => $metric,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editMetricAction(Metric $metric)
|
||||
{
|
||||
$_metric = Binput::get('metric');
|
||||
$metric->update($_metric);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong>',
|
||||
trans('dashboard.notifications.awesome')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/metrics')->with('success', $successMsg);
|
||||
}
|
||||
}
|
@ -22,18 +22,6 @@ class DashboardController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notifications view.
|
||||
*
|
||||
|
@ -5,6 +5,7 @@ namespace CachetHQ\Cachet\Http\Controllers;
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
@ -66,6 +67,12 @@ class HomeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$metrics = null;
|
||||
|
||||
if ($displayMetrics = Setting::get('display_graphs')) {
|
||||
$metrics = Metric::where('display_chart', 1)->get();
|
||||
}
|
||||
|
||||
foreach (range(0, $incidentDays) as $i) {
|
||||
$date = $startDate->copy()->subDays($i);
|
||||
|
||||
@ -82,6 +89,8 @@ class HomeController extends Controller
|
||||
|
||||
return View::make('index', [
|
||||
'components' => $components,
|
||||
'displayMetrics' => $displayMetrics,
|
||||
'metrics' => $metrics,
|
||||
'allIncidents' => $allIncidents,
|
||||
'pageTitle' => Setting::get('app_name'),
|
||||
'aboutApp' => Markdown::render(Setting::get('app_about')),
|
||||
|
@ -5,6 +5,7 @@ namespace CachetHQ\Cachet\Models;
|
||||
use CachetHQ\Cachet\Transformers\MetricTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
@ -20,6 +21,15 @@ class Metric extends Model implements TransformableInterface
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'default_value' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@ -48,6 +58,24 @@ class Metric extends Model implements TransformableInterface
|
||||
return $this->hasMany('CachetHQ\Cachet\Models\MetricPoint', 'metric_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of all values a metric has.
|
||||
*
|
||||
* @param int $hour
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getValues($hour)
|
||||
{
|
||||
$value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%c%e%H") = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL '.$hour.' HOUR), "%Y%c%e%H")')->whereRaw('HOUR(created_at) = HOUR(DATE_SUB(NOW(), INTERVAL '.$hour.' HOUR))')->groupBy(DB::raw('HOUR(created_at)'))->sum('value');
|
||||
|
||||
if ($value === 0 && $this->default_value != $value) {
|
||||
return $this->default_value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a chart should be shown.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -13,6 +14,24 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class MetricPoint extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['metric_id', 'value'];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'value' => 'integer|required',
|
||||
];
|
||||
|
||||
/**
|
||||
* A metric point belongs to a metric unit.
|
||||
*
|
||||
|
@ -35,5 +35,9 @@ class RepositoryServiceProvider extends ServiceProvider
|
||||
'CachetHQ\Cachet\Repositories\Metric\MetricRepository',
|
||||
'CachetHQ\Cachet\Repositories\Metric\EloquentMetricRepository'
|
||||
);
|
||||
$this->app->bind(
|
||||
'CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository',
|
||||
'CachetHQ\Cachet\Repositories\MetricPoint\EloquentMetricPointRepository'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ class RoutingServiceProvider extends ServiceProvider
|
||||
$this->app->router->model('component_group', 'CachetHQ\Cachet\Models\ComponentGroup');
|
||||
$this->app->router->model('incident', 'CachetHQ\Cachet\Models\Incident');
|
||||
$this->app->router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate');
|
||||
$this->app->router->model('metric', 'CachetHQ\Cachet\Models\Metric');
|
||||
$this->app->router->model('metric_point', 'CachetHQ\Cachet\Models\MetricPoint');
|
||||
$this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting');
|
||||
$this->app->router->model('user', 'CachetHQ\Cachet\Models\User');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user