From cfd3df4266c247c3a6ef2a1aa731f111462e52dc Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Wed, 21 Jan 2015 02:32:18 -0600 Subject: [PATCH] Added a very basic metric API. Closes #4 --- .../2015_01_05_202826_CreateMetricsTable.php | 1 + app/lang/de/dashboard.php | 5 + app/lang/de/forms.php | 14 ++ app/lang/en/cachet.php | 9 + app/lang/en/dashboard.php | 11 +- app/lang/en/forms.php | 15 ++ app/lang/es/forms.php | 14 ++ app/lang/fr/dashboard.php | 5 + app/lang/fr/forms.php | 14 ++ app/routes/dashboard.php | 11 +- app/views/dashboard/incidents/add.blade.php | 2 +- app/views/dashboard/incidents/edit.blade.php | 2 +- app/views/dashboard/incidents/index.blade.php | 2 +- app/views/dashboard/metrics/add.blade.php | 54 +++++ app/views/dashboard/metrics/edit.blade.php | 57 +++++ app/views/dashboard/metrics/index.blade.php | 35 ++- .../dashboard/settings/app-setup.blade.php | 9 + app/views/index.blade.php | 8 +- .../partials/dashboard/sidebar.blade.php | 7 +- app/views/partials/graphs.blade.php | 69 ++++++ bower.json | 3 +- gulpfile.js | 1 + public/build/dist/js/all-35b543c2.js | 11 - public/build/dist/js/all-3f815dae.js | 13 ++ public/build/rev-manifest.json | 2 +- src/Http/Controllers/DashMetricController.php | 203 ++++++++++++++++++ src/Http/Controllers/DashboardController.php | 12 -- src/Http/Controllers/HomeController.php | 9 + src/Models/Metric.php | 28 +++ src/Models/MetricPoint.php | 19 ++ src/Providers/RepositoryServiceProvider.php | 4 + src/Providers/RoutingServiceProvider.php | 2 + 32 files changed, 606 insertions(+), 45 deletions(-) create mode 100644 app/views/dashboard/metrics/add.blade.php create mode 100644 app/views/dashboard/metrics/edit.blade.php delete mode 100644 public/build/dist/js/all-35b543c2.js create mode 100644 public/build/dist/js/all-3f815dae.js create mode 100644 src/Http/Controllers/DashMetricController.php diff --git a/app/database/migrations/2015_01_05_202826_CreateMetricsTable.php b/app/database/migrations/2015_01_05_202826_CreateMetricsTable.php index 00af3e19..28e07834 100644 --- a/app/database/migrations/2015_01_05_202826_CreateMetricsTable.php +++ b/app/database/migrations/2015_01_05_202826_CreateMetricsTable.php @@ -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(); diff --git a/app/lang/de/dashboard.php b/app/lang/de/dashboard.php index 11d0dac7..aa8b3559 100644 --- a/app/lang/de/dashboard.php +++ b/app/lang/de/dashboard.php @@ -65,6 +65,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 diff --git a/app/lang/de/forms.php b/app/lang/de/forms.php index ab2579ee..11f33b3f 100644 --- a/app/lang/de/forms.php +++ b/app/lang/de/forms.php @@ -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', diff --git a/app/lang/en/cachet.php b/app/lang/en/cachet.php index fbaa6c47..60e02500 100644 --- a/app/lang/en/cachet.php +++ b/app/lang/en/cachet.php @@ -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 Cachet.', 'about_this_site' => 'About this site', diff --git a/app/lang/en/dashboard.php b/app/lang/en/dashboard.php index b40247a6..2e7bbbbf 100644 --- a/app/lang/en/dashboard.php +++ b/app/lang/en/dashboard.php @@ -68,9 +68,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.', ], ], diff --git a/app/lang/en/forms.php b/app/lang/en/forms.php index 12221c43..4ed6449d 100644 --- a/app/lang/en/forms.php +++ b/app/lang/en/forms.php @@ -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', diff --git a/app/lang/es/forms.php b/app/lang/es/forms.php index 634f6379..679d4acc 100644 --- a/app/lang/es/forms.php +++ b/app/lang/es/forms.php @@ -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', diff --git a/app/lang/fr/dashboard.php b/app/lang/fr/dashboard.php index e7778c79..c641988a 100644 --- a/app/lang/fr/dashboard.php +++ b/app/lang/fr/dashboard.php @@ -71,6 +71,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 diff --git a/app/lang/fr/forms.php b/app/lang/fr/forms.php index b0579456..ff9f2be9 100644 --- a/app/lang/fr/forms.php +++ b/app/lang/fr/forms.php @@ -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', diff --git a/app/routes/dashboard.php b/app/routes/dashboard.php index 71d59ccb..dcb36fa9 100644 --- a/app/routes/dashboard.php +++ b/app/routes/dashboard.php @@ -71,8 +71,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 diff --git a/app/views/dashboard/incidents/add.blade.php b/app/views/dashboard/incidents/add.blade.php index 20531466..03ca1e38 100644 --- a/app/views/dashboard/incidents/add.blade.php +++ b/app/views/dashboard/incidents/add.blade.php @@ -6,7 +6,7 @@ - {{ trans('dashboard.incidents.incidents') }} + {{ trans('dashboard.incidents.incidents') }} > {{ trans('dashboard.incidents.add.title') }} diff --git a/app/views/dashboard/incidents/edit.blade.php b/app/views/dashboard/incidents/edit.blade.php index 197bc67d..977b6767 100644 --- a/app/views/dashboard/incidents/edit.blade.php +++ b/app/views/dashboard/incidents/edit.blade.php @@ -6,7 +6,7 @@ - {{ trans('dashboard.incidents.incidents') }} + {{ trans('dashboard.incidents.incidents') }} > {{ trans('dashboard.incidents.edit.title') }} diff --git a/app/views/dashboard/incidents/index.blade.php b/app/views/dashboard/incidents/index.blade.php index b1c7c63d..5ce27c24 100644 --- a/app/views/dashboard/incidents/index.blade.php +++ b/app/views/dashboard/incidents/index.blade.php @@ -6,7 +6,7 @@ - {{ trans('dashboard.incidents.incidents') }} + {{ trans('dashboard.incidents.incidents') }} {{ trans('dashboard.incidents.add.title') }} diff --git a/app/views/dashboard/metrics/add.blade.php b/app/views/dashboard/metrics/add.blade.php new file mode 100644 index 00000000..1c7722aa --- /dev/null +++ b/app/views/dashboard/metrics/add.blade.php @@ -0,0 +1,54 @@ +@extends('layout.dashboard') + +@section('content') +
+ + + {{ trans('dashboard.metrics.metrics') }} + + > {{ trans('dashboard.metrics.add.title') }} +
+
+ +
+@stop diff --git a/app/views/dashboard/metrics/edit.blade.php b/app/views/dashboard/metrics/edit.blade.php new file mode 100644 index 00000000..b47acb1d --- /dev/null +++ b/app/views/dashboard/metrics/edit.blade.php @@ -0,0 +1,57 @@ +@extends('layout.dashboard') + +@section('content') +
+ + + {{ trans('dashboard.metrics.metrics') }} + + > {{ trans('dashboard.metrics.edit.title') }} +
+
+
+
+ @include('partials.dashboard.errors') +
+ {{ Form::token() }} +
+
+ + name }}> +
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+ + + display_chart ? 'checked' : null }}> +
+
+ + id}}> + +
+
+ + {{ trans('forms.cancel') }} +
+
+
+
+
+
+@stop diff --git a/app/views/dashboard/metrics/index.blade.php b/app/views/dashboard/metrics/index.blade.php index 96f1db49..0648121c 100644 --- a/app/views/dashboard/metrics/index.blade.php +++ b/app/views/dashboard/metrics/index.blade.php @@ -1,16 +1,39 @@ @extends('layout.dashboard') @section('content') -
+
- {{ trans('dashboard.metrics.metrics') }} + + {{ trans('dashboard.metrics.metrics') }} + + + {{ trans('dashboard.metrics.add.title') }} + +
-
-
-

{{ trans('dashboard.metrics.metrics') }}

-

Eventually this page will show all of the graphs that make up your metrics.

+
+
+
+ @include('partials.dashboard.errors') +
+ @foreach($metrics as $metric) +
+
+ {{ $metric->name }} + @if($metric->description) +

{{ Str::words($metric->description, 5) }}

+ @endif +
+ +
+ @endforeach +
+
@stop diff --git a/app/views/dashboard/settings/app-setup.blade.php b/app/views/dashboard/settings/app-setup.blade.php index 40b0f0a2..f1e754c1 100644 --- a/app/views/dashboard/settings/app-setup.blade.php +++ b/app/views/dashboard/settings/app-setup.blade.php @@ -104,6 +104,15 @@
+
+
+
+ + + +
+
+
diff --git a/app/views/index.blade.php b/app/views/index.blade.php index b9dbb4aa..46c0f773 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -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

{{ trans('cachet.incidents.past') }}

@foreach($allIncidents as $incidents) - @include('partials.incidents', $incidents) + @include('partials.incidents', $incidents) @endforeach
diff --git a/app/views/partials/dashboard/sidebar.blade.php b/app/views/partials/dashboard/sidebar.blade.php index 52a8710e..dc222a2b 100644 --- a/app/views/partials/dashboard/sidebar.blade.php +++ b/app/views/partials/dashboard/sidebar.blade.php @@ -55,12 +55,13 @@ {{ trans('dashboard.team.team') }} - {{--
  • +
  • - {{ trans('cachet.dashboard.metrics') }} + + {{ trans('dashboard.metrics.metrics') }}
  • -
  • + {{--
  • {{ trans('cachet.dashboard.notifications') }} diff --git a/app/views/partials/graphs.blade.php b/app/views/partials/graphs.blade.php index e69de29b..c9d27a29 100644 --- a/app/views/partials/graphs.blade.php +++ b/app/views/partials/graphs.blade.php @@ -0,0 +1,69 @@ +@if($metrics->count() > 0) +
      + @foreach($metrics as $metric) + getValues($hour); + } + $points = array_reverse($points); + ?> +
    • +
      +
      +

      + {{ $metric->name }} + @if($metric->description) + + @endif +

      +
      +
      + {{ trans('cachet.metrics.filter.hourly') }} +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
    • + @endforeach +
    +@endif diff --git a/bower.json b/bower.json index c37a868f..77dc0bad 100644 --- a/bower.json +++ b/bower.json @@ -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" diff --git a/gulpfile.js b/gulpfile.js index e3364432..550c3140 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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/') diff --git a/public/build/dist/js/all-35b543c2.js b/public/build/dist/js/all-35b543c2.js deleted file mode 100644 index 694abd69..00000000 --- a/public/build/dist/js/all-35b543c2.js +++ /dev/null @@ -1,11 +0,0 @@ -if(function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){function n(e){var t=e.length,n=Z.type(e);return"function"===n||Z.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e}function r(e,t,n){if(Z.isFunction(t))return Z.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return Z.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(ot.test(t))return Z.filter(t,e,n);t=Z.filter(t,e)}return Z.grep(e,function(e){return B.call(t,e)>=0!==n})}function i(e,t){for(;(e=e[t])&&1!==e.nodeType;);return e}function a(e){var t=_t[e]={};return Z.each(e.match(ht)||[],function(e,n){t[n]=!0}),t}function s(){Q.removeEventListener("DOMContentLoaded",s,!1),e.removeEventListener("load",s,!1),Z.ready()}function o(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=Z.expando+o.uid++}function u(e,t,n){var r;if(void 0===n&&1===e.nodeType)if(r="data-"+t.replace(Mt,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:vt.test(n)?Z.parseJSON(n):n}catch(i){}yt.set(e,t,n)}else n=void 0;return n}function l(){return!0}function d(){return!1}function c(){try{return Q.activeElement}catch(e){}}function f(e,t){return Z.nodeName(e,"table")&&Z.nodeName(11!==t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function h(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function _(e){var t=Ot.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function p(e,t){for(var n=0,r=e.length;r>n;n++)gt.set(e[n],"globalEval",!t||gt.get(t[n],"globalEval"))}function m(e,t){var n,r,i,a,s,o,u,l;if(1===t.nodeType){if(gt.hasData(e)&&(a=gt.access(e),s=gt.set(t,a),l=a.events)){delete s.handle,s.events={};for(i in l)for(n=0,r=l[i].length;r>n;n++)Z.event.add(t,i,l[i][n])}yt.hasData(e)&&(o=yt.access(e),u=Z.extend({},o),yt.set(t,u))}}function g(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return void 0===t||t&&Z.nodeName(e,t)?Z.merge([e],n):n}function y(e,t){var n=t.nodeName.toLowerCase();"input"===n&&bt.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}function v(t,n){var r,i=Z(n.createElement(t)).appendTo(n.body),a=e.getDefaultComputedStyle&&(r=e.getDefaultComputedStyle(i[0]))?r.display:Z.css(i[0],"display");return i.detach(),a}function M(e){var t=Q,n=Ft[e];return n||(n=v(e,t),"none"!==n&&n||(Pt=(Pt||Z("