mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
WIP: refactor folder-picker for dashlist
This commit is contained in:
parent
c602afb9c6
commit
533f2d3d72
@ -42,7 +42,7 @@ export class SearchCtrl {
|
|||||||
this.giveSearchFocus = 0;
|
this.giveSearchFocus = 0;
|
||||||
this.selectedIndex = -1;
|
this.selectedIndex = -1;
|
||||||
this.results = [];
|
this.results = [];
|
||||||
this.query = { query: '', tag: [], starred: false };
|
this.query = { query: '', tag: [], starred: false, mode: 'tree' };
|
||||||
this.currentSearchId = 0;
|
this.currentSearchId = 0;
|
||||||
this.ignoreClose = true;
|
this.ignoreClose = true;
|
||||||
|
|
||||||
|
@ -135,6 +135,10 @@ export class DashNavCtrl {
|
|||||||
var uri = "data:application/json;charset=utf-8," + encodeURIComponent(html);
|
var uri = "data:application/json;charset=utf-8," + encodeURIComponent(html);
|
||||||
var newWindow = window.open(uri);
|
var newWindow = window.open(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFolderChange(parentId) {
|
||||||
|
this.dashboard.parentId = parentId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dashNavDirective() {
|
export function dashNavDirective() {
|
||||||
|
@ -5,32 +5,34 @@ import appEvents from 'app/core/app_events';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export class FolderPickerCtrl {
|
export class FolderPickerCtrl {
|
||||||
dashboard: any;
|
|
||||||
folders: Folder[];
|
folders: Folder[];
|
||||||
selectedFolder: number;
|
selectedFolder: number;
|
||||||
selectedFolderSegment: any;
|
selectedFolderSegment: any;
|
||||||
|
onChange: any;
|
||||||
|
rootFolderName: string;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private backendSrv, private $scope, private $sce, private uiSegmentSrv) {
|
constructor(private backendSrv, private $scope, private $sce, private uiSegmentSrv) {
|
||||||
this.selectedFolderSegment = this.uiSegmentSrv.newSegment({value: 'Root', selectMode: true});
|
this.selectedFolderSegment = this.uiSegmentSrv.newSegment({value: this.rootFolderName || 'Root', selectMode: true});
|
||||||
|
this.get();
|
||||||
this.selectedFolder = this.dashboard.meta.parentId;
|
|
||||||
this.get(this.dashboard.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get(dashboardId: number) {
|
get() {
|
||||||
var params = {
|
var params = {
|
||||||
type: 'dash-folder',
|
type: 'dash-folder',
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.backendSrv.search(params).then(result => {
|
return this.backendSrv.search(params).then(result => {
|
||||||
this.folders = [{id: 0, title: 'Root', type: 'dash-folder'}];
|
this.folders = [{id: 0, title: this.rootFolderName || 'Root', type: 'dash-folder'}];
|
||||||
this.folders.push(...result);
|
this.folders.push(...result);
|
||||||
const selected = _.find(this.folders, {id: this.selectedFolder});
|
|
||||||
|
|
||||||
this.selectedFolderSegment.value = selected.title;
|
if (this.selectedFolder) {
|
||||||
this.selectedFolderSegment.text = selected.title;
|
const selected = _.find(this.folders, {id: this.selectedFolder});
|
||||||
this.selectedFolderSegment.html = this.$sce.trustAsHtml(selected.title);
|
|
||||||
|
this.selectedFolderSegment.value = selected.title;
|
||||||
|
this.selectedFolderSegment.text = selected.title;
|
||||||
|
this.selectedFolderSegment.html = this.$sce.trustAsHtml(selected.title);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ export class FolderPickerCtrl {
|
|||||||
folderChanged() {
|
folderChanged() {
|
||||||
const selected = _.find(this.folders, {title: this.selectedFolderSegment.value});
|
const selected = _.find(this.folders, {title: this.selectedFolderSegment.value});
|
||||||
if (selected) {
|
if (selected) {
|
||||||
this.dashboard.parentId = selected.id;
|
this.onChange(selected.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +68,11 @@ export function folderPicker() {
|
|||||||
controller: FolderPickerCtrl,
|
controller: FolderPickerCtrl,
|
||||||
bindToController: true,
|
bindToController: true,
|
||||||
controllerAs: 'ctrl',
|
controllerAs: 'ctrl',
|
||||||
scope: { dashboard: "=" }
|
scope: {
|
||||||
|
selectedFolder: "<",
|
||||||
|
onChange: "<",
|
||||||
|
rootFolderName: "@"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<folder-picker ng-if="!dashboardMeta.isFolder" dashboard="dashboard"></folder-picker>
|
<folder-picker ng-if="!dashboardMeta.isFolder" selected-folder="dashboard.meta.parentId" on-change="onFolderChange"></folder-picker>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
|
@ -66,6 +66,10 @@ export class SaveDashboardAsModalCtrl {
|
|||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFolderChange(parentId) {
|
||||||
|
this.clone.parentId = parentId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveDashboardAsDirective() {
|
export function saveDashboardAsDirective() {
|
||||||
|
@ -22,6 +22,11 @@
|
|||||||
<input type="text" class="gf-form-input" placeholder="title query" ng-model="ctrl.panel.query" ng-change="ctrl.refresh()" ng-model-onblur>
|
<input type="text" class="gf-form-input" placeholder="title query" ng-model="ctrl.panel.query" ng-change="ctrl.refresh()" ng-model-onblur>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="gf-form">
|
||||||
|
<span class="gf-form-label width-6">Folder</span>
|
||||||
|
<folder-picker on-change="ctrl.onFolderChange" root-folder-name="All"></folder-picker>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-6">Tags</span>
|
<span class="gf-form-label width-6">Tags</span>
|
||||||
<bootstrap-tagsinput ng-model="ctrl.panel.tags" tagclass="label label-tag" placeholder="add tags" on-tags-updated="ctrl.refresh()">
|
<bootstrap-tagsinput ng-model="ctrl.panel.tags" tagclass="label label-tag" placeholder="add tags" on-tags-updated="ctrl.refresh()">
|
||||||
|
@ -12,6 +12,7 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
modes: any[];
|
modes: any[];
|
||||||
|
|
||||||
panelDefaults = {
|
panelDefaults = {
|
||||||
|
folder: '',
|
||||||
query: '',
|
query: '',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
tags: [],
|
tags: [],
|
||||||
@ -19,6 +20,7 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
search: false,
|
search: false,
|
||||||
starred: true,
|
starred: true,
|
||||||
headings: true,
|
headings: true,
|
||||||
|
folderId: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
@ -87,6 +89,7 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
limit: this.panel.limit,
|
limit: this.panel.limit,
|
||||||
query: this.panel.query,
|
query: this.panel.query,
|
||||||
tag: this.panel.tags,
|
tag: this.panel.tags,
|
||||||
|
folderId: this.panel.folderId
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.backendSrv.search(params).then(result => {
|
return this.backendSrv.search(params).then(result => {
|
||||||
@ -123,6 +126,11 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFolderChange(parentId) {
|
||||||
|
this.$scope.$parent.ctrl.panel.folderId = parentId;
|
||||||
|
this.$scope.$parent.ctrl.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {DashListCtrl, DashListCtrl as PanelCtrl};
|
export {DashListCtrl, DashListCtrl as PanelCtrl};
|
||||||
|
Loading…
Reference in New Issue
Block a user