Adds the ability to set the default view in which to display metrics

This commit is contained in:
James Brooks
2015-12-26 16:43:22 +00:00
parent 0d406b8360
commit 1c27cf7360
16 changed files with 152 additions and 28 deletions
+11 -1
View File
@@ -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;
}
}
+12 -2
View File
@@ -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])
+5 -1
View File
@@ -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',
];
/**
+28
View File
@@ -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.
*