mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #3792 from utkarshcmu/snapshot-view
UI Review: Snapshot view
This commit is contained in:
commit
fcc960e9a2
@ -69,9 +69,11 @@ func Register(r *macaron.Macaron) {
|
||||
r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), wrap(ResetPassword))
|
||||
|
||||
// dashboard snapshots
|
||||
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
||||
r.Get("/dashboard/snapshot/*", Index)
|
||||
r.Get("/dashboard/snapshots/", reqSignedIn, Index)
|
||||
|
||||
// api for dashboard snapshots
|
||||
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
||||
r.Get("/api/snapshot/shared-options/", GetSharingOptions)
|
||||
r.Get("/api/snapshots/:key", GetDashboardSnapshot)
|
||||
r.Get("/api/snapshots-delete/:key", DeleteDashboardSnapshot)
|
||||
@ -183,6 +185,11 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/tags", GetDashboardTags)
|
||||
})
|
||||
|
||||
// Dashboard snapshots
|
||||
r.Group("/dashboard/snapshots", func() {
|
||||
r.Get("/", wrap(SearchDashboardSnapshots))
|
||||
})
|
||||
|
||||
// Playlist
|
||||
r.Group("/playlists", func() {
|
||||
r.Get("/", wrap(SearchPlaylists))
|
||||
|
@ -36,7 +36,6 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
|
||||
cmd.DeleteKey = util.GetRandomString(32)
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.UserId = c.UserId
|
||||
cmd.Name = c.Name
|
||||
metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
|
||||
}
|
||||
|
||||
@ -99,3 +98,43 @@ func DeleteDashboardSnapshot(c *middleware.Context) {
|
||||
|
||||
c.JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it's cleared from a CDN cache."})
|
||||
}
|
||||
|
||||
func SearchDashboardSnapshots(c *middleware.Context) Response {
|
||||
query := c.Query("query")
|
||||
limit := c.QueryInt("limit")
|
||||
|
||||
if limit == 0 {
|
||||
limit = 1000
|
||||
}
|
||||
|
||||
searchQuery := m.GetDashboardSnapshotsQuery{
|
||||
Name: query,
|
||||
Limit: limit,
|
||||
OrgId: c.OrgId,
|
||||
}
|
||||
|
||||
err := bus.Dispatch(&searchQuery)
|
||||
if err != nil {
|
||||
return ApiError(500, "Search failed", err)
|
||||
}
|
||||
|
||||
dtos := make([]*m.DashboardSnapshotDTO, len(searchQuery.Result))
|
||||
for i, snapshot := range searchQuery.Result {
|
||||
dtos[i] = &m.DashboardSnapshotDTO{
|
||||
Id: snapshot.Id,
|
||||
Name: snapshot.Name,
|
||||
Key: snapshot.Key,
|
||||
DeleteKey: snapshot.DeleteKey,
|
||||
OrgId: snapshot.OrgId,
|
||||
UserId: snapshot.UserId,
|
||||
External: snapshot.External,
|
||||
ExternalUrl: snapshot.ExternalUrl,
|
||||
Expires: snapshot.Expires,
|
||||
Created: snapshot.Created,
|
||||
Updated: snapshot.Updated,
|
||||
}
|
||||
}
|
||||
|
||||
return Json(200, dtos)
|
||||
//return Json(200, searchQuery.Result)
|
||||
}
|
||||
|
@ -60,6 +60,12 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
||||
Url: "/playlists",
|
||||
})
|
||||
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
||||
Text: "Snapshots",
|
||||
Icon: "fa fa-fw fa-camera-retro",
|
||||
Url: "/dashboard/snapshots",
|
||||
})
|
||||
|
||||
if c.OrgRole == m.ROLE_ADMIN {
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
||||
Text: "Data Sources",
|
||||
|
@ -20,6 +20,22 @@ type DashboardSnapshot struct {
|
||||
Dashboard map[string]interface{}
|
||||
}
|
||||
|
||||
// DashboardSnapshotDTO without dashboard map
|
||||
type DashboardSnapshotDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Key string `json:"key"`
|
||||
DeleteKey string `json:"deleteKey"`
|
||||
OrgId int64 `json:"orgId"`
|
||||
UserId int64 `json:"userId"`
|
||||
External bool `json:"external"`
|
||||
ExternalUrl string `json:"externalUrl"`
|
||||
|
||||
Expires time.Time `json:"expires"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
// -----------------
|
||||
// COMMANDS
|
||||
|
||||
@ -48,3 +64,13 @@ type GetDashboardSnapshotQuery struct {
|
||||
|
||||
Result *DashboardSnapshot
|
||||
}
|
||||
|
||||
type DashboardSnapshots []*DashboardSnapshot
|
||||
|
||||
type GetDashboardSnapshotsQuery struct {
|
||||
Name string
|
||||
Limit int
|
||||
OrgId int64
|
||||
|
||||
Result DashboardSnapshots
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ func init() {
|
||||
bus.AddHandler("sql", CreateDashboardSnapshot)
|
||||
bus.AddHandler("sql", GetDashboardSnapshot)
|
||||
bus.AddHandler("sql", DeleteDashboardSnapshot)
|
||||
bus.AddHandler("sql", SearchDashboardSnapshots)
|
||||
}
|
||||
|
||||
func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
|
||||
@ -64,3 +65,18 @@ func GetDashboardSnapshot(query *m.GetDashboardSnapshotQuery) error {
|
||||
query.Result = &snapshot
|
||||
return nil
|
||||
}
|
||||
|
||||
func SearchDashboardSnapshots(query *m.GetDashboardSnapshotsQuery) error {
|
||||
var snapshots = make(m.DashboardSnapshots, 0)
|
||||
|
||||
sess := x.Limit(query.Limit)
|
||||
|
||||
if query.Name != "" {
|
||||
sess.Where("name LIKE ?", query.Name)
|
||||
}
|
||||
|
||||
sess.Where("org_id = ?", query.OrgId)
|
||||
err := sess.Find(&snapshots)
|
||||
query.Result = snapshots
|
||||
return err
|
||||
}
|
||||
|
@ -137,6 +137,11 @@ define([
|
||||
templateUrl: 'public/app/partials/reset_password.html',
|
||||
controller : 'ResetPasswordCtrl',
|
||||
})
|
||||
.when('/dashboard/snapshots', {
|
||||
templateUrl: 'app/features/snapshot/partials/snapshots.html',
|
||||
controller : 'SnapshotsCtrl',
|
||||
controllerAs: 'ctrl',
|
||||
})
|
||||
.when('/apps', {
|
||||
templateUrl: 'public/app/features/apps/partials/list.html',
|
||||
controller: 'AppListCtrl',
|
||||
|
@ -5,6 +5,7 @@ define([
|
||||
'./templating/templateSrv',
|
||||
'./dashboard/all',
|
||||
'./playlist/all',
|
||||
'./snapshot/all',
|
||||
'./panel/all',
|
||||
'./profile/profileCtrl',
|
||||
'./profile/changePasswordCtrl',
|
||||
|
1
public/app/features/snapshot/all.ts
Normal file
1
public/app/features/snapshot/all.ts
Normal file
@ -0,0 +1 @@
|
||||
import './snapshot_ctrl';
|
39
public/app/features/snapshot/partials/snapshots.html
Normal file
39
public/app/features/snapshot/partials/snapshots.html
Normal file
@ -0,0 +1,39 @@
|
||||
<navbar icon="fa fa-fw fa-camera-retro" title="Dashboard snapshots"></navbar>
|
||||
|
||||
<div class="page-container">
|
||||
<div class="page-wide">
|
||||
|
||||
<h2>Available snapshots</h2>
|
||||
|
||||
<table class="filter-table" style="margin-top: 20px">
|
||||
<thead>
|
||||
<th><strong>Name</strong></th>
|
||||
<th><strong>Snapshot url</strong></th>
|
||||
<th style="width: 70px"></th>
|
||||
<th style="width: 25px"></th>
|
||||
|
||||
</thead>
|
||||
|
||||
<tr ng-repeat="snapshot in ctrl.snapshots">
|
||||
<td>
|
||||
<a href="dashboard/snapshot/{{snapshot.key}}">{{snapshot.name}}</a>
|
||||
</td>
|
||||
<td >
|
||||
<a href="dashboard/snapshot/{{snapshot.key}}">dashboard/snapshot/{{snapshot.key}}</a>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="dashboard/snapshot/{{snapshot.key}}" class="btn btn-inverse btn-mini">
|
||||
<i class="fa fa-eye"></i>
|
||||
View
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a ng-click="ctrl.removeSnapshot(snapshot)" class="btn btn-danger btn-mini">
|
||||
<i class="fa fa-remove"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
42
public/app/features/snapshot/snapshot_ctrl.ts
Normal file
42
public/app/features/snapshot/snapshot_ctrl.ts
Normal file
@ -0,0 +1,42 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
|
||||
export class SnapshotsCtrl {
|
||||
|
||||
snapshots: any;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private $rootScope, private backendSrv) {
|
||||
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
|
||||
this.snapshots = result;
|
||||
});
|
||||
}
|
||||
|
||||
removeSnapshotConfirmed(snapshot) {
|
||||
_.remove(this.snapshots, {key: snapshot.key});
|
||||
this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
|
||||
.then(() => {
|
||||
this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
|
||||
}, () => {
|
||||
this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
|
||||
this.snapshots.push(snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
removeSnapshot(snapshot) {
|
||||
this.$rootScope.appEvent('confirm-modal', {
|
||||
title: 'Confirm delete snapshot',
|
||||
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
|
||||
yesText: "Delete",
|
||||
icon: "fa-warning",
|
||||
onConfirm: () => {
|
||||
this.removeSnapshotConfirmed(snapshot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);
|
Loading…
Reference in New Issue
Block a user