From bcb44b7b31f747fc936dee819c467000954d94d6 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Tue, 19 Jan 2016 05:02:22 -0800 Subject: [PATCH] UI and backend connectivity implemented --- pkg/api/api.go | 1 + pkg/api/index.go | 2 +- pkg/services/sqlstore/dashboard_snapshot.go | 2 +- public/app/features/all.js | 1 + public/app/features/snapshot/all.js | 4 ++ .../features/snapshot/partials/snapshots.html | 39 +++++++++++++++++ public/app/features/snapshot/snapshot_ctrl.js | 43 +++++++++++++++++++ .../app/features/snapshot/snapshot_routes.js | 18 ++++++++ 8 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 public/app/features/snapshot/all.js create mode 100644 public/app/features/snapshot/partials/snapshots.html create mode 100644 public/app/features/snapshot/snapshot_ctrl.js create mode 100644 public/app/features/snapshot/snapshot_routes.js diff --git a/pkg/api/api.go b/pkg/api/api.go index c42bb376df2..034d9adc180 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -69,6 +69,7 @@ func Register(r *macaron.Macaron) { // dashboard snapshots r.Get("/dashboard/snapshot/*", Index) + r.Get("/dashboard/snapshots/", reqSignedIn, Index) // api for dashboard snapshots r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot) diff --git a/pkg/api/index.go b/pkg/api/index.go index 3423651922a..ca2f9320215 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -63,7 +63,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{ Text: "Snapshots", Icon: "fa fa-fw fa-camera-retro", - Url: "/snapshots", + Url: "/dashboard/snapshots", }) if c.OrgRole == m.ROLE_ADMIN { diff --git a/pkg/services/sqlstore/dashboard_snapshot.go b/pkg/services/sqlstore/dashboard_snapshot.go index eef2898a7c0..64e7e31898c 100644 --- a/pkg/services/sqlstore/dashboard_snapshot.go +++ b/pkg/services/sqlstore/dashboard_snapshot.go @@ -68,7 +68,7 @@ func GetDashboardSnapshot(query *m.GetDashboardSnapshotQuery) error { func SearchDashboardSnapshots(query *m.GetDashboardSnapshotsQuery) error { var snapshots = make(m.DashboardSnapshots, 0) - sess := x.Cols("name,key,delete_key").Limit(query.Limit) + sess := x.Limit(query.Limit) if query.Name != "" { sess.Where("name LIKE ?", query.Name) diff --git a/public/app/features/all.js b/public/app/features/all.js index d4436c9deaa..4ec4719ebdd 100644 --- a/public/app/features/all.js +++ b/public/app/features/all.js @@ -5,6 +5,7 @@ define([ './templating/templateSrv', './dashboard/all', './playlist/all', + './snapshot/all', './panel/all', './profile/profileCtrl', './profile/changePasswordCtrl', diff --git a/public/app/features/snapshot/all.js b/public/app/features/snapshot/all.js new file mode 100644 index 00000000000..45cb9eb594f --- /dev/null +++ b/public/app/features/snapshot/all.js @@ -0,0 +1,4 @@ +define([ + './snapshot_ctrl', + './snapshot_routes' +], function () {}); diff --git a/public/app/features/snapshot/partials/snapshots.html b/public/app/features/snapshot/partials/snapshots.html new file mode 100644 index 00000000000..58b6c872617 --- /dev/null +++ b/public/app/features/snapshot/partials/snapshots.html @@ -0,0 +1,39 @@ + + +
+
+ +

Available snapshots

+ + + + + + + + + + + + + + + + +
NameSnapshot url
+ {{snapshot.Name}} + + dashboard/snapshot/{{snapshot.Key}} + + + + View + + + + + +
+ +
+
diff --git a/public/app/features/snapshot/snapshot_ctrl.js b/public/app/features/snapshot/snapshot_ctrl.js new file mode 100644 index 00000000000..345638f4770 --- /dev/null +++ b/public/app/features/snapshot/snapshot_ctrl.js @@ -0,0 +1,43 @@ +define([ + 'angular', + 'lodash' +], +function (angular, _) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('SnapshotsCtrl', function($scope, $location, backendSrv) { + backendSrv.get('/api/dashboard/snapshots') + .then(function(result) { + $scope.snapshots = result; + }); + + $scope.removeSnapshotConfirmed = function(snapshot) { + _.remove($scope.snapshots, {Key: snapshot.Key}); + + backendSrv.get('/api/snapshots-delete/' + snapshot.DeleteKey) + .then(function() { + $scope.appEvent('alert-success', ['Snapshot deleted', '']); + }, function() { + $scope.appEvent('alert-error', ['Unable to delete snapshot', '']); + $scope.snapshots.push(snapshot); + }); + }; + + $scope.removeSnapshot = function(snapshot) { + + $scope.appEvent('confirm-modal', { + title: 'Confirm delete snapshot', + text: 'Are you sure you want to delete snapshot ' + snapshot.Name + '?', + yesText: "Delete", + icon: "fa-warning", + onConfirm: function() { + $scope.removeSnapshotConfirmed(snapshot); + } + }); + + }; + + }); +}); diff --git a/public/app/features/snapshot/snapshot_routes.js b/public/app/features/snapshot/snapshot_routes.js new file mode 100644 index 00000000000..74de0634282 --- /dev/null +++ b/public/app/features/snapshot/snapshot_routes.js @@ -0,0 +1,18 @@ +define([ + 'angular', + 'app/core/config', + 'lodash' +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.routes'); + + module.config(function($routeProvider) { + $routeProvider + .when('/dashboard/snapshots', { + templateUrl: 'app/features/snapshot/partials/snapshots.html', + controller : 'SnapshotsCtrl' + }); + }); +});