Commit 96af051c by Hugo Häggmark Committed by Hugo Häggmark

chore: Cleaning up implicit anys in manage_dashboard.ts and manage_dashboard.test.ts

progress: #14714
parent aa4b593d
// @ts-ignore
import _ from 'lodash'; import _ from 'lodash';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { SearchSrv } from 'app/core/services/search_srv'; import { SearchSrv } from 'app/core/services/search_srv';
import { BackendSrv } from 'app/core/services/backend_srv';
import { NavModelSrv } from 'app/core/nav_model_srv';
import { ContextSrv } from 'app/core/services/context_srv';
export interface Section {
id: number;
uid: string;
title: string;
expanded: false;
items: any[];
url: string;
icon: string;
score: number;
checked: boolean;
hideHeader: boolean;
toggle: Function;
}
export interface FoldersAndDashboardUids {
folderUids: string[];
dashboardUids: string[];
}
class Query { class Query {
query: string; query: string;
...@@ -14,7 +37,7 @@ class Query { ...@@ -14,7 +37,7 @@ class Query {
} }
export class ManageDashboardsCtrl { export class ManageDashboardsCtrl {
sections: any[]; sections: Section[];
query: Query; query: Query;
navModel: any; navModel: any;
...@@ -45,7 +68,12 @@ export class ManageDashboardsCtrl { ...@@ -45,7 +68,12 @@ export class ManageDashboardsCtrl {
hasEditPermissionInFolders: boolean; hasEditPermissionInFolders: boolean;
/** @ngInject */ /** @ngInject */
constructor(private backendSrv, navModelSrv, private searchSrv: SearchSrv, private contextSrv) { constructor(
private backendSrv: BackendSrv,
navModelSrv: NavModelSrv,
private searchSrv: SearchSrv,
private contextSrv: ContextSrv
) {
this.isEditor = this.contextSrv.isEditor; this.isEditor = this.contextSrv.isEditor;
this.hasEditPermissionInFolders = this.contextSrv.hasEditPermissionInFolders; this.hasEditPermissionInFolders = this.contextSrv.hasEditPermissionInFolders;
...@@ -73,7 +101,7 @@ export class ManageDashboardsCtrl { ...@@ -73,7 +101,7 @@ export class ManageDashboardsCtrl {
refreshList() { refreshList() {
return this.searchSrv return this.searchSrv
.search(this.query) .search(this.query)
.then(result => { .then((result: Section[]) => {
return this.initDashboardList(result); return this.initDashboardList(result);
}) })
.then(() => { .then(() => {
...@@ -81,7 +109,7 @@ export class ManageDashboardsCtrl { ...@@ -81,7 +109,7 @@ export class ManageDashboardsCtrl {
return; return;
} }
return this.backendSrv.getFolderByUid(this.folderUid).then(folder => { return this.backendSrv.getFolderByUid(this.folderUid).then((folder: any) => {
this.canSave = folder.canSave; this.canSave = folder.canSave;
if (!this.canSave) { if (!this.canSave) {
this.hasEditPermissionInFolders = false; this.hasEditPermissionInFolders = false;
...@@ -90,7 +118,7 @@ export class ManageDashboardsCtrl { ...@@ -90,7 +118,7 @@ export class ManageDashboardsCtrl {
}); });
} }
initDashboardList(result: any) { initDashboardList(result: Section[]) {
this.canMove = false; this.canMove = false;
this.canDelete = false; this.canDelete = false;
this.selectAllChecked = false; this.selectAllChecked = false;
...@@ -128,25 +156,25 @@ export class ManageDashboardsCtrl { ...@@ -128,25 +156,25 @@ export class ManageDashboardsCtrl {
this.canDelete = selectedDashboards > 0 || selectedFolders > 0; this.canDelete = selectedDashboards > 0 || selectedFolders > 0;
} }
getFoldersAndDashboardsToDelete() { getFoldersAndDashboardsToDelete(): FoldersAndDashboardUids {
const selectedDashboards = { const selectedDashboards: FoldersAndDashboardUids = {
folders: [], folderUids: [],
dashboards: [], dashboardUids: [],
}; };
for (const section of this.sections) { for (const section of this.sections) {
if (section.checked && section.id !== 0) { if (section.checked && section.id !== 0) {
selectedDashboards.folders.push(section.uid); selectedDashboards.folderUids.push(section.uid);
} else { } else {
const selected = _.filter(section.items, { checked: true }); const selected = _.filter(section.items, { checked: true });
selectedDashboards.dashboards.push(..._.map(selected, 'uid')); selectedDashboards.dashboardUids.push(..._.map(selected, 'uid'));
} }
} }
return selectedDashboards; return selectedDashboards;
} }
getFolderIds(sections) { getFolderIds(sections: Section[]) {
const ids = []; const ids = [];
for (const s of sections) { for (const s of sections) {
if (s.checked) { if (s.checked) {
...@@ -158,8 +186,8 @@ export class ManageDashboardsCtrl { ...@@ -158,8 +186,8 @@ export class ManageDashboardsCtrl {
delete() { delete() {
const data = this.getFoldersAndDashboardsToDelete(); const data = this.getFoldersAndDashboardsToDelete();
const folderCount = data.folders.length; const folderCount = data.folderUids.length;
const dashCount = data.dashboards.length; const dashCount = data.dashboardUids.length;
let text = 'Do you want to delete the '; let text = 'Do you want to delete the ';
let text2; let text2;
...@@ -179,12 +207,12 @@ export class ManageDashboardsCtrl { ...@@ -179,12 +207,12 @@ export class ManageDashboardsCtrl {
icon: 'fa-trash', icon: 'fa-trash',
yesText: 'Delete', yesText: 'Delete',
onConfirm: () => { onConfirm: () => {
this.deleteFoldersAndDashboards(data.folders, data.dashboards); this.deleteFoldersAndDashboards(data.folderUids, data.dashboardUids);
}, },
}); });
} }
private deleteFoldersAndDashboards(folderUids, dashboardUids) { private deleteFoldersAndDashboards(folderUids: string[], dashboardUids: string[]) {
this.backendSrv.deleteFoldersAndDashboards(folderUids, dashboardUids).then(() => { this.backendSrv.deleteFoldersAndDashboards(folderUids, dashboardUids).then(() => {
this.refreshList(); this.refreshList();
}); });
...@@ -219,13 +247,13 @@ export class ManageDashboardsCtrl { ...@@ -219,13 +247,13 @@ export class ManageDashboardsCtrl {
} }
initTagFilter() { initTagFilter() {
return this.searchSrv.getDashboardTags().then(results => { return this.searchSrv.getDashboardTags().then((results: any) => {
this.tagFilterOptions = [{ term: 'Filter By Tag', disabled: true }].concat(results); this.tagFilterOptions = [{ term: 'Filter By Tag', disabled: true }].concat(results);
this.selectedTagFilter = this.tagFilterOptions[0]; this.selectedTagFilter = this.tagFilterOptions[0];
}); });
} }
filterByTag(tag) { filterByTag(tag: any) {
if (_.indexOf(this.query.tag, tag) === -1) { if (_.indexOf(this.query.tag, tag) === -1) {
this.query.tag.push(tag); this.query.tag.push(tag);
} }
...@@ -243,7 +271,7 @@ export class ManageDashboardsCtrl { ...@@ -243,7 +271,7 @@ export class ManageDashboardsCtrl {
return res; return res;
} }
removeTag(tag, evt) { removeTag(tag: any, evt: Event) {
this.query.tag = _.without(this.query.tag, tag); this.query.tag = _.without(this.query.tag, tag);
this.refreshList(); this.refreshList();
if (evt) { if (evt) {
...@@ -269,7 +297,7 @@ export class ManageDashboardsCtrl { ...@@ -269,7 +297,7 @@ export class ManageDashboardsCtrl {
section.checked = this.selectAllChecked; section.checked = this.selectAllChecked;
} }
section.items = _.map(section.items, item => { section.items = _.map(section.items, (item: any) => {
item.checked = this.selectAllChecked; item.checked = this.selectAllChecked;
return item; return item;
}); });
......
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