Commit 3f317597 by Marcus Efraimsson

dashboards: fix batch dashboard/folder delete response

Use message returned from backend and use that as alert success response to user
parent 01351786
......@@ -167,8 +167,10 @@ func DeleteDashboard(c *middleware.Context) Response {
return ApiError(500, "Failed to delete dashboard", err)
}
var resp = map[string]interface{}{"title": dash.Title}
return Json(200, resp)
return Json(200, util.DynMap{
"title": dash.Title,
"message": fmt.Sprintf("Dashboard %s deleted", dash.Title),
})
}
func DeleteDashboardByUid(c *middleware.Context) Response {
......@@ -187,8 +189,10 @@ func DeleteDashboardByUid(c *middleware.Context) Response {
return ApiError(500, "Failed to delete dashboard", err)
}
var resp = map[string]interface{}{"title": dash.Title}
return Json(200, resp)
return Json(200, util.DynMap{
"title": dash.Title,
"message": fmt.Sprintf("Dashboard %s deleted", dash.Title),
})
}
func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
......
package api
import (
"fmt"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
......@@ -82,8 +84,10 @@ func DeleteFolder(c *middleware.Context) Response {
return toFolderError(err)
}
var resp = map[string]interface{}{"title": f.Title}
return Json(200, resp)
return Json(200, util.DynMap{
"title": f.Title,
"message": fmt.Sprintf("Folder %s deleted", f.Title),
})
}
func toFolderDto(g guardian.DashboardGuardian, folder *m.Folder) dtos.Folder {
......
......@@ -179,41 +179,7 @@ export class ManageDashboardsCtrl {
}
private deleteFoldersAndDashboards(folderUids, dashboardUids) {
this.backendSrv.deleteFoldersAndDashboards(folderUids, dashboardUids).then(result => {
const folders = _.filter(result, dash => !dash.dashboard);
const folderCount = folders.length;
const dashboards = _.filter(result, dash => dash.dashboard);
const dashCount = dashboards.length;
if (result.length > 0) {
let header;
let msg;
if (folderCount > 0 && dashCount > 0) {
header = `Folder${folderCount === 1 ? '' : 's'} And Dashboard${dashCount === 1 ? '' : 's'} Deleted`;
msg = `${folderCount} folder${folderCount === 1 ? '' : 's'} `;
msg += `and ${dashCount} dashboard${dashCount === 1 ? '' : 's'} has been deleted`;
} else if (folderCount > 0) {
header = `Folder${folderCount === 1 ? '' : 's'} Deleted`;
if (folderCount === 1) {
msg = `${folders[0].title} has been deleted`;
} else {
msg = `${folderCount} folder${folderCount === 1 ? '' : 's'} has been deleted`;
}
} else if (dashCount > 0) {
header = `Dashboard${dashCount === 1 ? '' : 's'} Deleted`;
if (dashCount === 1) {
msg = `${dashboards[0].dashboard.title} has been deleted`;
} else {
msg = `${dashCount} dashboard${dashCount === 1 ? '' : 's'} has been deleted`;
}
}
appEvents.emit('alert-success', [header, msg]);
}
this.backendSrv.deleteFoldersAndDashboards(folderUids, dashboardUids).then(() => {
this.refreshList();
});
}
......
......@@ -258,47 +258,27 @@ export class BackendSrv {
});
}
deleteFolder(uid: string) {
let deferred = this.$q.defer();
this.getFolderByUid(uid).then(folder => {
this.delete(`/api/folders/${uid}`)
.then(() => {
deferred.resolve(folder);
})
.catch(err => {
deferred.reject(err);
});
});
return deferred.promise;
deleteFolder(uid: string, showSuccessAlert) {
return this.request({ method: 'DELETE', url: `/api/folders/${uid}`, showSuccessAlert: showSuccessAlert === true });
}
deleteDashboard(uid) {
let deferred = this.$q.defer();
this.getDashboardByUid(uid).then(fullDash => {
this.delete(`/api/dashboards/uid/${uid}`)
.then(() => {
deferred.resolve(fullDash);
})
.catch(err => {
deferred.reject(err);
});
deleteDashboard(uid, showSuccessAlert) {
return this.request({
method: 'DELETE',
url: `/api/dashboards/uid/${uid}`,
showSuccessAlert: showSuccessAlert === true,
});
return deferred.promise;
}
deleteFoldersAndDashboards(folderUids, dashboardUids) {
const tasks = [];
for (let folderUid of folderUids) {
tasks.push(this.createTask(this.deleteFolder.bind(this), true, folderUid));
tasks.push(this.createTask(this.deleteFolder.bind(this), true, folderUid, true));
}
for (let dashboardUid of dashboardUids) {
tasks.push(this.createTask(this.deleteDashboard.bind(this), true, dashboardUid));
tasks.push(this.createTask(this.deleteDashboard.bind(this), true, dashboardUid, true));
}
return this.executeInOrder(tasks, []);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment