forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from alison985/154_add_to_dashboard_from_query
add ability to add query to dashboard from query page
- Loading branch information
Showing
9 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="modal-header"> | ||
<button type="button" class="close" aria-label="Close" ng-click="$ctrl.close()"><span aria-hidden="true">×</span></button> | ||
<h4 class="modal-title">Add to Dashboard</h4> | ||
</div> | ||
<div class="modal-body"> | ||
|
||
<form name="alertForm" class="form"> | ||
<div class="form-group"> | ||
<!-- <label>Limit Dashboard search to dashboards I've created? </label> | ||
<input type="checkbox" ng-model="$ctrl.limitToUsersDashboards" on-change="$ctrl.dashboardList == $select.search" ng-disabled="$ctrl.saveInProgress" /> --> | ||
<label>Choose the dashboard to add this query to:</label> | ||
<ui-select ng-model="$ctrl.dashboardList" reset-search-input="false" on-select="$ctrl.onDashboardSelected($item)" ng-disabled="$ctrl.saveInProgress"> | ||
<ui-select-match placeholder="Search a dashboard by name">{{$select.selected.name}}</ui-select-match> | ||
<ui-select-choices repeat="q in $ctrl.dashboards" | ||
refresh="$ctrl.searchDashboards($select.search, $ctrl.limitToUsersDashboards)" | ||
refresh-delay="0"> | ||
<div ng-bind-html="$ctrl.trustAsHtml(q.name | highlight: $select.search)"></div> | ||
</ui-select-choices> | ||
</ui-select> | ||
</div> | ||
</form> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import template from './add-to-dashboard.html'; | ||
|
||
const AddToDashboardForm = { | ||
controller($sce, Dashboard, currentUser, toastr, Query, Widget) { | ||
'ngInject'; | ||
|
||
this.query = this.resolve.query; | ||
this.vis = this.resolve.vis; | ||
this.saveAddToDashbosard = this.resolve.saveAddToDashboard; | ||
this.saveInProgress = false; | ||
|
||
this.trustAsHtml = html => $sce.trustAsHtml(html); | ||
|
||
this.onDashboardSelected = (dash) => { | ||
// add widget to dashboard | ||
this.saveInProgress = true; | ||
this.widgetSize = 1; | ||
this.selectedVis = null; | ||
this.query = {}; | ||
this.selected_query = this.query.id; | ||
this.type = 'visualization'; | ||
this.isVisualization = () => this.type === 'visualization'; | ||
|
||
const widget = new Widget({ | ||
visualization_id: this.vis && this.vis.id, | ||
dashboard_id: dash.id, | ||
options: {}, | ||
width: this.widgetSize, | ||
type: this.type, | ||
}); | ||
|
||
// (response) | ||
widget.$save().then(() => { | ||
// (dashboard) | ||
this.selectedDashboard = Dashboard.get({ slug: dash.slug }, () => {}); | ||
this.close(); | ||
}).catch(() => { | ||
toastr.error('Widget can not be added'); | ||
}).finally(() => { | ||
this.saveInProgress = false; | ||
}); | ||
}; | ||
|
||
this.selectedDashboard = null; | ||
|
||
this.searchDashboards = (term) => { // , limitToUsersDashboards | ||
if (!term || term.length < 3) { | ||
return; | ||
} | ||
|
||
Dashboard.search({ | ||
q: term, | ||
user_id: currentUser.id, | ||
// limit_to_users_dashboards: limitToUsersDashboards, | ||
include_drafts: true, | ||
}, (results) => { | ||
this.dashboards = results; | ||
}); | ||
}; | ||
}, | ||
bindings: { | ||
resolve: '<', | ||
close: '&', | ||
dismiss: '&', | ||
vis: '<', | ||
}, | ||
template, | ||
}; | ||
|
||
export default function (ngModule) { | ||
ngModule.component('addToDashboardDialog', AddToDashboardForm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters