Adds the ability to set the default view in which to display metrics
This commit is contained in:
@@ -62,6 +62,13 @@ final class AddMetricCommand
|
||||
*/
|
||||
public $places;
|
||||
|
||||
/**
|
||||
* The view to show the metric points in.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $default_view;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@@ -76,6 +83,7 @@ final class AddMetricCommand
|
||||
'calc_type' => 'int',
|
||||
'display_chart' => 'int',
|
||||
'places' => 'int|between:0,4',
|
||||
'default_view' => 'int|between:0,3',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -88,10 +96,11 @@ final class AddMetricCommand
|
||||
* @param int $calc_type
|
||||
* @param int $display_chart
|
||||
* @param int $places
|
||||
* @param int $default_view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, $suffix, $description, $default_value, $calc_type, $display_chart, $places)
|
||||
public function __construct($name, $suffix, $description, $default_value, $calc_type, $display_chart, $places, $default_view)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->suffix = $suffix;
|
||||
@@ -100,5 +109,6 @@ final class AddMetricCommand
|
||||
$this->calc_type = $calc_type;
|
||||
$this->display_chart = $display_chart;
|
||||
$this->places = $places;
|
||||
$this->default_view = $default_view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,13 @@ final class UpdateMetricCommand
|
||||
*/
|
||||
public $places;
|
||||
|
||||
/**
|
||||
* The view to show the metric points in.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $default_view;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@@ -84,7 +91,8 @@ final class UpdateMetricCommand
|
||||
'default_value' => 'numeric',
|
||||
'calc_type' => 'int|in:0,1',
|
||||
'display_chart' => 'int',
|
||||
'places' => 'numeric|min:0|max:4',
|
||||
'places' => 'numeric|between:0,4',
|
||||
'default_view' => 'numeric|between:0,4',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -98,10 +106,11 @@ final class UpdateMetricCommand
|
||||
* @param int $calc_type
|
||||
* @param int $display_chart
|
||||
* @param int $places
|
||||
* @param int $default_view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Metric $metric, $name, $suffix, $description, $default_value, $calc_type, $display_chart, $places)
|
||||
public function __construct(Metric $metric, $name, $suffix, $description, $default_value, $calc_type, $display_chart, $places, $default_view)
|
||||
{
|
||||
$this->metric = $metric;
|
||||
$this->name = $name;
|
||||
@@ -111,5 +120,6 @@ final class UpdateMetricCommand
|
||||
$this->calc_type = $calc_type;
|
||||
$this->display_chart = $display_chart;
|
||||
$this->places = $places;
|
||||
$this->default_view = $default_view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ class AddMetricCommandHandler
|
||||
'calc_type' => $command->calc_type,
|
||||
'display_chart' => $command->display_chart,
|
||||
'places' => $command->places,
|
||||
'default_view' => $command->default_view,
|
||||
]);
|
||||
|
||||
event(new MetricWasAddedEvent($metric));
|
||||
|
||||
@@ -52,6 +52,7 @@ class UpdateMetricCommandHandler
|
||||
'calc_type' => $command->calc_type,
|
||||
'display_chart' => $command->display_chart,
|
||||
'places' => $command->places,
|
||||
'default_view' => $command->default_view,
|
||||
];
|
||||
|
||||
return array_filter($params, function ($val) {
|
||||
|
||||
@@ -73,7 +73,8 @@ class MetricController extends AbstractApiController
|
||||
Binput::get('default_value'),
|
||||
Binput::get('calc_type', 0),
|
||||
Binput::get('display_chart'),
|
||||
Binput::get('places', 2)
|
||||
Binput::get('places', 2),
|
||||
Binput::get('view', 1)
|
||||
));
|
||||
} catch (QueryException $e) {
|
||||
throw new BadRequestHttpException();
|
||||
@@ -100,7 +101,8 @@ class MetricController extends AbstractApiController
|
||||
Binput::get('default_value'),
|
||||
Binput::get('calc_type', 0),
|
||||
Binput::get('display_chart'),
|
||||
Binput::get('places', 2)
|
||||
Binput::get('places', 2),
|
||||
Binput::get('view', 1)
|
||||
));
|
||||
} catch (QueryException $e) {
|
||||
throw new BadRequestHttpException();
|
||||
|
||||
@@ -78,7 +78,8 @@ class MetricController extends Controller
|
||||
$metricData['default_value'],
|
||||
$metricData['calc_type'],
|
||||
$metricData['display_chart'],
|
||||
$metricData['places']
|
||||
$metricData['places'],
|
||||
$metricData['view']
|
||||
));
|
||||
} catch (ValidationException $e) {
|
||||
return Redirect::route('dashboard.metrics.add')
|
||||
@@ -143,13 +144,14 @@ class MetricController extends Controller
|
||||
try {
|
||||
dispatch(new UpdateMetricCommand(
|
||||
$metric,
|
||||
Binput::get('metric.name', null, false),
|
||||
Binput::get('metric.suffix', null, false),
|
||||
Binput::get('metric.description', null, false),
|
||||
Binput::get('metric.default_value', null, false),
|
||||
Binput::get('metric.calc_type', null, false),
|
||||
Binput::get('metric.display_chart', null, false),
|
||||
Binput::get('metric.places', null, false)
|
||||
Binput::get('name', null, false),
|
||||
Binput::get('suffix', null, false),
|
||||
Binput::get('description', null, false),
|
||||
Binput::get('default_value', null, false),
|
||||
Binput::get('calc_type', null, false),
|
||||
Binput::get('display_chart', null, false),
|
||||
Binput::get('places', null, false),
|
||||
Binput::get('default_view', null, false)
|
||||
));
|
||||
} catch (ValidationException $e) {
|
||||
return Redirect::route('dashboard.metrics.edit', ['id' => $metric->id])
|
||||
|
||||
@@ -45,6 +45,7 @@ class Metric extends Model implements HasPresenter
|
||||
'default_value' => 0,
|
||||
'calc_type' => 0,
|
||||
'places' => 2,
|
||||
'default_view' => 1,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -59,6 +60,7 @@ class Metric extends Model implements HasPresenter
|
||||
'default_value' => 'int',
|
||||
'calc_type' => 'int',
|
||||
'places' => 'int',
|
||||
'default_view' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -74,6 +76,7 @@ class Metric extends Model implements HasPresenter
|
||||
'default_value',
|
||||
'calc_type',
|
||||
'places',
|
||||
'default_view',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -86,7 +89,8 @@ class Metric extends Model implements HasPresenter
|
||||
'suffix' => 'required',
|
||||
'display_chart' => 'bool',
|
||||
'default_value' => 'numeric',
|
||||
'places' => 'numeric|min:0|max:4',
|
||||
'places' => 'numeric|between:0,4',
|
||||
'default_view' => 'numeric|between:0,3',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,34 @@ class MetricPresenter extends AbstractPresenter
|
||||
{
|
||||
use TimestampsTrait;
|
||||
|
||||
/**
|
||||
* Determines the metric view filter name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function view_name() {
|
||||
switch ($this->wrappedObject->default_view) {
|
||||
case 0: return 'last_hour';
|
||||
case 1: return 'today';
|
||||
case 2: return 'week';
|
||||
case 3: return 'month';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the metric translation view filter name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function trans_string_name() {
|
||||
switch ($this->wrappedObject->default_view) {
|
||||
case 0: return 'last_hour';
|
||||
case 1: return 'hourly';
|
||||
case 2: return 'weekly';
|
||||
case 3: return 'monthly';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the presenter instance to an array.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class AlterTableMetricsAddDefaultViewColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('metrics', function (Blueprint $table) {
|
||||
$table->tinyInteger('default_view')->unsigned()->default(1)->after('places');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('metrics', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ return [
|
||||
'type_sum' => 'Sum',
|
||||
'type_avg' => 'Average',
|
||||
'places' => 'Decimal Places',
|
||||
'default_view' => 'Default View',
|
||||
|
||||
'points' => [
|
||||
'value' => 'Value',
|
||||
|
||||
@@ -38,6 +38,15 @@
|
||||
<option value="1">{{ trans('forms.metrics.type_avg') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.default_view') }}</label>
|
||||
<select name="metric[default_view]" class="form-control" required>
|
||||
<option value="0">{{ trans('cachet.metrics.filter.last_hour') }}</option>
|
||||
<option value="1" selected>{{ trans('cachet.metrics.filter.hourly') }}</option>
|
||||
<option value="2">{{ trans('cachet.metrics.filter.weekly') }}</option>
|
||||
<option value="3">{{ trans('cachet.metrics.filter.monthly') }}</option>
|
||||
</select>
|
||||
</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="{{ Binput::old('metric.default_value') }}">
|
||||
|
||||
@@ -19,43 +19,52 @@
|
||||
<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 }}">
|
||||
<input type="text" class="form-control" name="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 }}">
|
||||
<input type="text" class="form-control" name="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">{{ $metric->description }}</textarea>
|
||||
<textarea name="description" class="form-control" rows="5">{{ $metric->description }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.calc_type') }}</label>
|
||||
<select name="metric[calc_type]" class="form-control" required>
|
||||
<select name="calc_type" class="form-control" required>
|
||||
<option value="0" {{ $metric->calc_type === 0 ? "selected" : null }}>{{ trans('forms.metrics.type_sum') }}</option>
|
||||
<option value="1" {{ $metric->calc_type === 1 ? "selected" : null }}>{{ trans('forms.metrics.type_avg') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.metrics.default_view') }}</label>
|
||||
<select name="default_view" class="form-control" required>
|
||||
<option value="0" {{ $metric->default_view === 0 ? "selected" : null }}>{{ trans('cachet.metrics.filter.last_hour') }}</option>
|
||||
<option value="1" {{ $metric->default_view === 1 ? "selected" : null }}>{{ trans('cachet.metrics.filter.hourly') }}</option>
|
||||
<option value="2" {{ $metric->default_view === 2 ? "selected" : null }}>{{ trans('cachet.metrics.filter.weekly') }}</option>
|
||||
<option value="3" {{ $metric->default_view === 3 ? "selected" : null }}>{{ trans('cachet.metrics.filter.monthly') }}</option>
|
||||
</select>
|
||||
</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 }}">
|
||||
<input type="number" class="form-control" name="default_value" id="metric-default_value" value="{{ $metric->default_value }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="metric-places">{{ trans('forms.metrics.places') }}</label>
|
||||
<input type="number" min="0" max="4" class="form-control" name="metric[places]" id="metric-places" required value="{{ $metric->places }}">
|
||||
<input type="number" min="0" max="4" class="form-control" name="places" id="metric-places" required value="{{ $metric->places }}">
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="hidden" value="0" name="metric[display_chart]">
|
||||
<input type="checkbox" value="1" name="metric[display_chart]" {{ $metric->display_chart ? 'checked' : null }}>
|
||||
<input type="hidden" value="0" name="display_chart">
|
||||
<input type="checkbox" value="1" name="display_chart" {{ $metric->display_chart ? 'checked' : null }}>
|
||||
{{ trans('forms.metrics.display-chart') }}
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<input type="hidden" name="metric[id]" value={{$metric->id}}>
|
||||
<input type="hidden" name="id" value={{$metric->id}}>
|
||||
|
||||
<div class='form-group'>
|
||||
<div class='btn-group'>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<div class="dropdown pull-right">
|
||||
<a href="javascript: void(0);" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class='filter'>{{ trans('cachet.metrics.filter.hourly') }}</span> <span class="caret"></span></a>
|
||||
<a href="javascript: void(0);" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class='filter'>{{ trans('cachet.metrics.filter.'.$metric->trans_string_name) }}</span> <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right">
|
||||
<li><a href="#" data-filter-type="last_hour">{{ trans('cachet.metrics.filter.last_hour') }}</a></li>
|
||||
<li><a href="#" data-filter-type="today">{{ trans('cachet.metrics.filter.hourly') }}</a></li>
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div>
|
||||
<canvas id="metric-{{ $metric->id }}" data-metric-name="{{ $metric->name }}" data-metric-suffix="{{ $metric->suffix }}" data-metric-id="{{ $metric->id }}" data-metric-group="today" height="160" width="600"></canvas>
|
||||
<canvas id="metric-{{ $metric->id }}" data-metric-name="{{ $metric->name }}" data-metric-suffix="{{ $metric->suffix }}" data-metric-id="{{ $metric->id }}" data-metric-group="{{ $metric->view_name }}" height="160" width="600"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -61,6 +61,7 @@ class MetricTest extends AbstractApiTestCase
|
||||
'default_value' => 1,
|
||||
'display_chart' => 1,
|
||||
'places' => 0,
|
||||
'view' => 0,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo']);
|
||||
$this->assertResponseOk();
|
||||
@@ -82,8 +83,9 @@ class MetricTest extends AbstractApiTestCase
|
||||
|
||||
$this->put('/api/v1/metrics/1', [
|
||||
'name' => 'Foo',
|
||||
'view' => 2,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo']);
|
||||
$this->seeJson(['name' => 'Foo', 'default_view' => 2]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class AddMetricCommandTest extends AbstractTestCase
|
||||
'calc_type' => 0,
|
||||
'display_chart' => 1,
|
||||
'places' => 0,
|
||||
'default_view' => 0,
|
||||
];
|
||||
|
||||
$object = new AddMetricCommand(
|
||||
@@ -45,7 +46,8 @@ class AddMetricCommandTest extends AbstractTestCase
|
||||
$params['default_value'],
|
||||
$params['calc_type'],
|
||||
$params['display_chart'],
|
||||
$params['places']
|
||||
$params['places'],
|
||||
$params['default_view']
|
||||
);
|
||||
|
||||
return compact('params', 'object');
|
||||
|
||||
@@ -38,6 +38,7 @@ class UpdateMetricCommandTest extends AbstractTestCase
|
||||
'calc_type' => 0,
|
||||
'display_chart' => 1,
|
||||
'places' => 0,
|
||||
'default_view' => 0,
|
||||
];
|
||||
|
||||
$object = new UpdateMetricCommand(
|
||||
@@ -48,7 +49,8 @@ class UpdateMetricCommandTest extends AbstractTestCase
|
||||
$params['default_value'],
|
||||
$params['calc_type'],
|
||||
$params['display_chart'],
|
||||
$params['places']
|
||||
$params['places'],
|
||||
$params['default_view']
|
||||
);
|
||||
|
||||
return compact('params', 'object');
|
||||
|
||||
Reference in New Issue
Block a user