From e26cd21048b631235c98e141184b9986d0fc2458 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Tue, 19 Jan 2016 21:04:53 -0800 Subject: [PATCH] Converted ctrl to typescript --- public/app/core/routes/all.js | 3 +- public/app/features/snapshot/all.js | 3 -- public/app/features/snapshot/all.ts | 1 + .../features/snapshot/partials/snapshots.html | 6 +-- public/app/features/snapshot/snapshot_ctrl.js | 43 ------------------- public/app/features/snapshot/snapshot_ctrl.ts | 20 +++++++++ 6 files changed, 26 insertions(+), 50 deletions(-) delete mode 100644 public/app/features/snapshot/all.js create mode 100644 public/app/features/snapshot/all.ts delete mode 100644 public/app/features/snapshot/snapshot_ctrl.js create mode 100644 public/app/features/snapshot/snapshot_ctrl.ts diff --git a/public/app/core/routes/all.js b/public/app/core/routes/all.js index ba993134455..521e8008f98 100644 --- a/public/app/core/routes/all.js +++ b/public/app/core/routes/all.js @@ -134,7 +134,8 @@ define([ }) .when('/dashboard/snapshots', { templateUrl: 'app/features/snapshot/partials/snapshots.html', - controller : 'SnapshotsCtrl' + controller : 'SnapshotsCtrl', + controllerAs: 'ctrl', }) .when('/apps', { templateUrl: 'app/features/apps/partials/list.html', diff --git a/public/app/features/snapshot/all.js b/public/app/features/snapshot/all.js deleted file mode 100644 index b0f66edc414..00000000000 --- a/public/app/features/snapshot/all.js +++ /dev/null @@ -1,3 +0,0 @@ -define([ - './snapshot_ctrl', -], function () {}); diff --git a/public/app/features/snapshot/all.ts b/public/app/features/snapshot/all.ts new file mode 100644 index 00000000000..521c7a4c111 --- /dev/null +++ b/public/app/features/snapshot/all.ts @@ -0,0 +1 @@ +import './snapshot_ctrl'; diff --git a/public/app/features/snapshot/partials/snapshots.html b/public/app/features/snapshot/partials/snapshots.html index 58b6c872617..9d1b688fd35 100644 --- a/public/app/features/snapshot/partials/snapshots.html +++ b/public/app/features/snapshot/partials/snapshots.html @@ -1,7 +1,7 @@
-
+

Available snapshots

@@ -14,7 +14,7 @@ - + {{snapshot.Name}} @@ -28,7 +28,7 @@ - + diff --git a/public/app/features/snapshot/snapshot_ctrl.js b/public/app/features/snapshot/snapshot_ctrl.js deleted file mode 100644 index 345638f4770..00000000000 --- a/public/app/features/snapshot/snapshot_ctrl.js +++ /dev/null @@ -1,43 +0,0 @@ -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_ctrl.ts b/public/app/features/snapshot/snapshot_ctrl.ts new file mode 100644 index 00000000000..b194fbf9119 --- /dev/null +++ b/public/app/features/snapshot/snapshot_ctrl.ts @@ -0,0 +1,20 @@ +/// + +import angular from 'angular'; +import _ from 'lodash'; + +export class SnapshotsCtrl { + snapshots: any[]; + + /** @ngInject */ + constructor(private backendSrv: any) {} + + init() { + this.backendSrv.get('/api/dashboard/snapshots').then(snapshots => { + this.snapshots = snapshots; + }); + console.log(this.snapshots); + } +} + +angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);