diff --git a/app/Commands/Metric/AddMetricCommand.php b/app/Commands/Metric/AddMetricCommand.php index fc2070eb..ea064f27 100644 --- a/app/Commands/Metric/AddMetricCommand.php +++ b/app/Commands/Metric/AddMetricCommand.php @@ -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; } } diff --git a/app/Commands/Metric/UpdateMetricCommand.php b/app/Commands/Metric/UpdateMetricCommand.php index be4002cc..7d690a7f 100644 --- a/app/Commands/Metric/UpdateMetricCommand.php +++ b/app/Commands/Metric/UpdateMetricCommand.php @@ -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; } } diff --git a/app/Handlers/Commands/Metric/AddMetricCommandHandler.php b/app/Handlers/Commands/Metric/AddMetricCommandHandler.php index a497897b..3c61d139 100644 --- a/app/Handlers/Commands/Metric/AddMetricCommandHandler.php +++ b/app/Handlers/Commands/Metric/AddMetricCommandHandler.php @@ -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)); diff --git a/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php b/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php index c4e94b0b..921bf883 100644 --- a/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php +++ b/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php @@ -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) { diff --git a/app/Http/Controllers/Api/MetricController.php b/app/Http/Controllers/Api/MetricController.php index 96ff0df9..b0342556 100644 --- a/app/Http/Controllers/Api/MetricController.php +++ b/app/Http/Controllers/Api/MetricController.php @@ -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(); diff --git a/app/Http/Controllers/Dashboard/MetricController.php b/app/Http/Controllers/Dashboard/MetricController.php index 6afea8bf..7f912a3c 100644 --- a/app/Http/Controllers/Dashboard/MetricController.php +++ b/app/Http/Controllers/Dashboard/MetricController.php @@ -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]) diff --git a/app/Models/Metric.php b/app/Models/Metric.php index a924d592..dd8dd6d6 100644 --- a/app/Models/Metric.php +++ b/app/Models/Metric.php @@ -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', ]; /** diff --git a/app/Presenters/MetricPresenter.php b/app/Presenters/MetricPresenter.php index 3591c20f..9c95c8ce 100644 --- a/app/Presenters/MetricPresenter.php +++ b/app/Presenters/MetricPresenter.php @@ -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. * diff --git a/database/migrations/2015_12_26_162258_AlterTableMetricsAddDefaultViewColumn.php b/database/migrations/2015_12_26_162258_AlterTableMetricsAddDefaultViewColumn.php new file mode 100644 index 00000000..4eec4873 --- /dev/null +++ b/database/migrations/2015_12_26_162258_AlterTableMetricsAddDefaultViewColumn.php @@ -0,0 +1,41 @@ +tinyInteger('default_view')->unsigned()->default(1)->after('places'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('metrics', function (Blueprint $table) { + // + }); + } +} diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index f3ff857c..e0a411f6 100755 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -84,6 +84,7 @@ return [ 'type_sum' => 'Sum', 'type_avg' => 'Average', 'places' => 'Decimal Places', + 'default_view' => 'Default View', 'points' => [ 'value' => 'Value', diff --git a/resources/views/dashboard/metrics/add.blade.php b/resources/views/dashboard/metrics/add.blade.php index 4cd8fe7a..17e329ef 100644 --- a/resources/views/dashboard/metrics/add.blade.php +++ b/resources/views/dashboard/metrics/add.blade.php @@ -38,6 +38,15 @@ +
+ + +
diff --git a/resources/views/dashboard/metrics/edit.blade.php b/resources/views/dashboard/metrics/edit.blade.php index 05c66745..cc84ffea 100644 --- a/resources/views/dashboard/metrics/edit.blade.php +++ b/resources/views/dashboard/metrics/edit.blade.php @@ -19,43 +19,52 @@
- +
- +
- +
-
+
+ + +
- +
- +
- id}}> + id}}>
diff --git a/resources/views/partials/metrics.blade.php b/resources/views/partials/metrics.blade.php index 8985bffa..f7b021dc 100644 --- a/resources/views/partials/metrics.blade.php +++ b/resources/views/partials/metrics.blade.php @@ -13,7 +13,7 @@