Skip to content

Commit

Permalink
Merge pull request getredash#194 from EverythingMe/feature_markdown_w…
Browse files Browse the repository at this point in the history
…idget

Several small fixes (getredash#186, getredash#120, getredash#174)
  • Loading branch information
arikfr committed Apr 29, 2014
2 parents 191ad19 + 6efd830 commit cdf6a19
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
26 changes: 15 additions & 11 deletions rd_ui/app/scripts/controllers/query_source.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';

function QuerySourceCtrl(Events, $controller, $scope, $location, Query, Visualization, KeyboardShortcuts) {
function QuerySourceCtrl(Events, growl, $controller, $scope, $location, Query, Visualization, KeyboardShortcuts) {
// extends QueryViewCtrl
$controller('QueryViewCtrl', {$scope: $scope});
// TODO:
Expand Down Expand Up @@ -67,15 +67,19 @@
if (confirm('Are you sure you want to delete ' + vis.name + ' ?')) {
Events.record(currentUser, 'delete', 'visualization', vis.id);

Visualization.delete(vis);
if ($scope.selectedTab == vis.id) {
$scope.selectedTab = DEFAULT_TAB;
$location.hash($scope.selectedTab);
}
$scope.query.visualizations =
$scope.query.visualizations.filter(function(v) {
return vis.id !== v.id;
});
Visualization.delete(vis, function() {
if ($scope.selectedTab == vis.id) {
$scope.selectedTab = DEFAULT_TAB;
$location.hash($scope.selectedTab);
}
$scope.query.visualizations =
$scope.query.visualizations.filter(function (v) {
return vis.id !== v.id;
});
}, function () {
growl.addErrorMessage("Error deleting visualization. Maybe it's used in a dashboard?");
});

}
};

Expand All @@ -99,7 +103,7 @@
}

angular.module('redash.controllers').controller('QuerySourceCtrl', [
'Events', '$controller', '$scope', '$location', 'Query',
'Events', 'growl', '$controller', '$scope', '$location', 'Query',
'Visualization', 'KeyboardShortcuts', QuerySourceCtrl
]);
})();
2 changes: 2 additions & 0 deletions rd_ui/app/scripts/visualizations/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
}
});

scope.xAxisType = (scope.visualization.options.xAxis && scope.visualization.options.xAxis.type) || scope.xAxisType;

xAxisUnwatch = scope.$watch("xAxisType", function (xAxisType) {
scope.visualization.options.xAxis = scope.visualization.options.xAxis || {};
scope.visualization.options.xAxis.type = xAxisType;
Expand Down
2 changes: 1 addition & 1 deletion redash/data/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _fork_and_process(self, job_id):
self.name, job_id)
job.done(None, "Interrupted/Cancelled while running.")

job.expire(24 * 3600)
job.expire(settings.JOB_EXPIRY_TIME)

logging.info("[%s] Finished Processing %s (pid: %d status: %d)",
self.name, job_id, self.child_pid, status)
Expand Down
27 changes: 24 additions & 3 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ def to_dict(self):
def get_latest(cls, data_source, query, ttl=0):
query_hash = utils.gen_query_hash(query)

query = cls.select().where(cls.query_hash == query_hash, cls.data_source == data_source,
peewee.SQL("retrieved_at + interval '%s second' >= now() at time zone 'utc'", ttl)).order_by(cls.retrieved_at.desc())
if ttl == -1:
query = cls.select().where(cls.query_hash == query_hash,
cls.data_source == data_source).order_by(cls.retrieved_at.desc())
else:
query = cls.select().where(cls.query_hash == query_hash, cls.data_source == data_source,
peewee.SQL("retrieved_at + interval '%s second' >= now() at time zone 'utc'",
ttl)).order_by(cls.retrieved_at.desc())

return query.first()

Expand Down Expand Up @@ -261,7 +266,23 @@ def to_dict(self, with_widgets=False):
.switch(Query)\
.join(QueryResult, join_type=peewee.JOIN_LEFT_OUTER)
widgets = {w.id: w.to_dict() for w in widgets}
widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout)

# The following is a workaround for cases when the widget object gets deleted without the dashboard layout
# updated. This happens for users with old databases that didn't have a foreign key relationship between
# visualizations and widgets.
# It's temporary until better solution is implemented (we probably should move the position information
# to the widget).
widgets_layout = []
for row in layout:
new_row = []
for widget_id in row:
widget = widgets.get(widget_id, None)
if widget:
new_row.append(widget)

widgets_layout.append(new_row)

# widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout)
else:
widgets_layout = None

Expand Down
1 change: 1 addition & 0 deletions redash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def parse_boolean(str):
ALLOWED_EXTERNAL_USERS = array_from_string(os.environ.get("REDASH_ALLOWED_EXTERNAL_USERS", ''))
STATIC_ASSETS_PATH = fix_assets_path(os.environ.get("REDASH_STATIC_ASSETS_PATH", "../rd_ui/app/"))
WORKERS_COUNT = int(os.environ.get("REDASH_WORKERS_COUNT", "2"))
JOB_EXPIRY_TIME = int(os.environ.get("REDASH_JOB_EXPIRY_TIME", 3600*24))
COOKIE_SECRET = os.environ.get("REDASH_COOKIE_SECRET", "c292a0a3aa32397cdb050e233733900f")
LOG_LEVEL = os.environ.get("REDASH_LOG_LEVEL", "INFO")
EVENTS_LOG_PATH = os.environ.get("REDASH_EVENTS_LOG_PATH", "")
Expand Down
10 changes: 10 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ def test_get_latest_returns_the_most_recent_result(self):

found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, 60)

self.assertEqual(found_query_result.id, qr.id)

def test_get_latest_returns_the_last_cached_result_for_negative_ttl(self):
yesterday = datetime.datetime.now() + datetime.timedelta(days=-100)
very_old = query_result_factory.create(retrieved_at=yesterday)

yesterday = datetime.datetime.now() + datetime.timedelta(days=-1)
qr = query_result_factory.create(retrieved_at=yesterday)
found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, -1)

self.assertEqual(found_query_result.id, qr.id)

0 comments on commit cdf6a19

Please sign in to comment.