Commit 533f2d3d by Daniel Lee

WIP: refactor folder-picker for dashlist

parent c602afb9
...@@ -42,7 +42,7 @@ export class SearchCtrl { ...@@ -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 { ...@@ -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'; ...@@ -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 { ...@@ -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() { ...@@ -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 @@ ...@@ -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 { ...@@ -66,6 +66,10 @@ export class SaveDashboardAsModalCtrl {
this.save(); this.save();
} }
} }
onFolderChange(parentId) {
this.clone.parentId = parentId;
}
} }
export function saveDashboardAsDirective() { export function saveDashboardAsDirective() {
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
</div> </div>
<div class="gf-form"> <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">
<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()">
</bootstrap-tagsinput> </bootstrap-tagsinput>
......
...@@ -12,6 +12,7 @@ class DashListCtrl extends PanelCtrl { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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};
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