From 6a7d2291b4ca914e577a2e27729d28eacdae1263 Mon Sep 17 00:00:00 2001
From: Levko Kravets
Date: Sun, 29 Oct 2017 12:03:59 +0200
Subject: [PATCH] getredash/redash#335 Better dashboard editor
---
client/app/assets/css/superflat_redash.css | 42 +++++++-
.../dashboards/add-widget-dialog.html | 6 +-
.../dashboards/add-widget-dialog.js | 53 +++++-----
.../dashboards/edit-dashboard-dialog.html | 8 --
.../dashboards/edit-dashboard-dialog.js | 32 +-----
client/app/components/dashboards/widget.html | 4 +-
client/app/components/dashboards/widget.js | 10 +-
client/app/config/index.js | 34 +++++++
client/app/directives/index.js | 42 ++++++++
client/app/pages/dashboards/dashboard.html | 18 +++-
client/app/pages/dashboards/dashboard.js | 98 ++++++++++++++-----
.../dashboards/public-dashboard-page.html | 8 +-
.../pages/dashboards/public-dashboard-page.js | 7 +-
client/app/services/dashboard.js | 31 +++++-
client/app/services/widget.js | 63 +++++++++++-
package.json | 1 +
redash/handlers/widgets.py | 1 +
webpack.config.js | 2 +-
18 files changed, 342 insertions(+), 118 deletions(-)
diff --git a/client/app/assets/css/superflat_redash.css b/client/app/assets/css/superflat_redash.css
index bbccd3a05c..ea1ae7fe09 100644
--- a/client/app/assets/css/superflat_redash.css
+++ b/client/app/assets/css/superflat_redash.css
@@ -6209,7 +6209,7 @@ button.close {
/* --------------------------------------------------------
Container
-----------------------------------------------------------*/
-/* --------------------------------------------------------
+/* --------------------------------------------------------
Template Variables
-----------------------------------------------------------*/
/* --------------------------------------------------------
@@ -6259,7 +6259,7 @@ button.close {
Carousel
-----------------------------------------------------------*/
/* --------------------------------------------------------
- Modal
+ Modal
-----------------------------------------------------------*/
/* --------------------------------------------------------
Tooltips
@@ -7913,6 +7913,44 @@ fieldset[disabled] .btn-inverse.active {
position: relative;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.07);
}
+
+.dashboard-wrapper {
+ margin: -7px;
+}
+.dashboard-wrapper .tile {
+ position: absolute;
+ left: 7px;
+ top: 7px;
+ right: 7px;
+ bottom: 7px;
+ overflow: auto;
+ margin: 0;
+ padding: 0 0 40px 0;
+}
+.dashboard-wrapper.gridster-mobile {
+ margin: 0;
+}
+.dashboard-wrapper.gridster-mobile .gridster-item {
+ margin-left: 0 !important;
+ margin-right: 0 !important;
+}
+.dashboard-wrapper.gridster-mobile .tile {
+ display: block;
+ position: static;
+ height: auto;
+ margin-bottom: 15px;
+}
+
+.dashboard-widget-bottom-panel {
+ line-height: 28px;
+}
+.dashboard-wrapper .dashboard-widget-bottom-panel {
+ position: absolute;
+ left: 0;
+ right: 0;
+ bottom: 0;
+}
+
.tile[class*="bg-"] {
color: #fff;
}
diff --git a/client/app/components/dashboards/add-widget-dialog.html b/client/app/components/dashboards/add-widget-dialog.html
index 62c43efeb1..0a96b7d495 100644
--- a/client/app/components/dashboards/add-widget-dialog.html
+++ b/client/app/components/dashboards/add-widget-dialog.html
@@ -38,10 +38,8 @@ Add Widget
-
diff --git a/client/app/components/dashboards/add-widget-dialog.js b/client/app/components/dashboards/add-widget-dialog.js
index a9b10e0ef7..d0c5262d88 100644
--- a/client/app/components/dashboards/add-widget-dialog.js
+++ b/client/app/components/dashboards/add-widget-dialog.js
@@ -1,3 +1,4 @@
+import * as _ from 'underscore';
import template from './add-widget-dialog.html';
const AddWidgetDialog = {
@@ -12,21 +13,13 @@ const AddWidgetDialog = {
this.dashboard = this.resolve.dashboard;
this.saveInProgress = false;
- this.widgetSize = 1;
this.selectedVis = null;
this.query = {};
this.selected_query = undefined;
this.text = '';
this.existing_text = '';
this.new_text = '';
- this.widgetSizes = [{
- name: 'Regular',
- value: 1,
- }, {
- name: 'Double',
- value: 2,
- }];
-
+ this.isHidden = false;
this.type = 'visualization';
this.trustAsHtml = html => $sce.trustAsHtml(html);
@@ -35,11 +28,6 @@ const AddWidgetDialog = {
this.setType = (type) => {
this.type = type;
- if (type === 'textbox') {
- this.widgetSizes.push({ name: 'Hidden', value: 0 });
- } else if (this.widgetSizes.length > 2) {
- this.widgetSizes.pop();
- }
};
this.onQuerySelect = () => {
@@ -72,21 +60,40 @@ const AddWidgetDialog = {
const widget = new Widget({
visualization_id: this.selectedVis && this.selectedVis.id,
dashboard_id: this.dashboard.id,
- options: {},
- width: this.widgetSize,
+ options: {
+ isHidden: this.isTextBox() && this.isHidden,
+ position: {
+ // Place new widget below all others
+ col: 0,
+ row: _.chain(this.dashboard.widgets)
+ .map((w) => {
+ let temp = _.extend({}, w.options);
+ temp = _.extend({}, temp.position);
+ const row = parseInt(temp.row, 10);
+ const height = parseInt(temp.sizeY, 10);
+
+ let result = 0;
+ if (isFinite(row)) {
+ result += row;
+ }
+ if (isFinite(height)) {
+ result += height;
+ }
+ return result;
+ })
+ .max()
+ .value(),
+ // Auto-height by default
+ sizeY: -1,
+ },
+ },
text: this.text,
});
widget.$save().then((response) => {
// update dashboard layout
- this.dashboard.layout = response.layout;
this.dashboard.version = response.version;
- const newWidget = new Widget(response.widget);
- if (response.new_row) {
- this.dashboard.widgets.push([newWidget]);
- } else {
- this.dashboard.widgets[this.dashboard.widgets.length - 1].push(newWidget);
- }
+ this.dashboard.widgets.push(new Widget(response.widget));
this.close();
}).catch(() => {
toastr.error('Widget can not be added');
diff --git a/client/app/components/dashboards/edit-dashboard-dialog.html b/client/app/components/dashboards/edit-dashboard-dialog.html
index edac266bfc..867bc31661 100644
--- a/client/app/components/dashboards/edit-dashboard-dialog.html
+++ b/client/app/components/dashboards/edit-dashboard-dialog.html
@@ -13,14 +13,6 @@ Edit: {{$ctrl.dashboard.name}}
Use Dashboard Level Filters
-
-