Skip to content

Commit

Permalink
Enable documentation links and versions of data sources (re #6).
Browse files Browse the repository at this point in the history
Refs #537, #553.

Co-authored-by: Marina Samuel <msamuel@mozilla.com>
Co-authored-by: Allen Short <ashort@mozilla.com>
  • Loading branch information
2 people authored and jezdez committed Nov 7, 2018
1 parent 2e9e7a8 commit ce970a0
Show file tree
Hide file tree
Showing 29 changed files with 558 additions and 507 deletions.
2 changes: 2 additions & 0 deletions client/app/assets/less/redash/query.less
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ a.label-tag {

.datasource-small {
visibility: hidden;
display: none !important;
}

.query-fullscreen .query-metadata__mobile {
Expand Down Expand Up @@ -576,6 +577,7 @@ nav .rg-bottom {

.datasource-small {
visibility: visible;
display: inline-block !important;
}

.query-fullscreen {
Expand Down
2 changes: 1 addition & 1 deletion client/app/pages/data-sources/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="database-source">
<a class="visual-card" ng-href="data_sources/{{dataSource.id}}" ng-repeat="dataSource in $ctrl.dataSources" title="{{dataSource.name}}">
<img ng-src="/static/images/db-logos/{{dataSource.type}}.png" alt="{{dataSource.name}}">
<h3>{{dataSource.name}}</h3>
<h3>{{dataSource.name}}</h3> - {{dataSource.type_name}}
</a>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ <h3>
{{ds.name}}
</ui-select-choices>
</ui-select>
<datasource-link datasource-id="query.data_source_id"></datasource-link>
<datasource-version datasource-id="query.data_source_id"></datasource-version>
</div>

<div class="editor__left__schema" ng-if="sourceMode">
Expand Down Expand Up @@ -168,6 +170,8 @@ <h3>
<select class="form-control datasource-small flex-fill w-100" ng-disabled="!isQueryOwner || !sourceMode" ng-model="query.data_source_id"
ng-change="updateDataSource()" ng-options="ds.id as ds.name for ds in dataSources"></select>

<datasource-link datasource-id="query.data_source_id"></datasource-link>

<button class="btn btn-default m-l-5" ng-show="canEdit" ng-click="saveQuery()" title="Save" uib-tooltip-html="modKey + ' + S'"
tooltip-append-to-body="true">
<span class="fa fa-floppy-o"></span>
Expand Down
2 changes: 1 addition & 1 deletion redash/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from redash.handlers.base import org_scoped_rule
from redash.handlers.permissions import ObjectPermissionsListResource, CheckPermissionResource
from redash.handlers.alerts import AlertResource, AlertListResource, AlertSubscriptionListResource, AlertSubscriptionResource
from redash.handlers.dashboards import DashboardListResource, DashboardResource, DashboardShareResource, PublicDashboardResource
from redash.handlers.dashboards import DashboardListResource, DashboardResource, DashboardShareResource, PublicDashboardResource
from redash.handlers.data_sources import DataSourceTypeListResource, DataSourceListResource, DataSourceSchemaResource, DataSourceResource, DataSourcePauseResource, DataSourceTestResource
from redash.handlers.events import EventsResource
from redash.handlers.queries import QueryForkResource, QueryRefreshResource, QueryListResource, QueryRecentResource, QuerySearchResource, QueryResource, MyQueriesResource, QueryVersionListResource, ChangeResource
Expand Down
2 changes: 2 additions & 0 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ def add_group(self, group, view_only=False):
db.session.add(dsg)
return dsg

setattr(self, 'data_source_groups', dsg)

def remove_group(self, group):
db.session.query(DataSourceGroup).filter(
DataSourceGroup.group == group,
Expand Down
56 changes: 32 additions & 24 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class NotSupported(Exception):

class BaseQueryRunner(object):
noop_query = None
configuration_properties = None

def __init__(self, configuration):
self.syntax = 'sql'
Expand All @@ -78,6 +79,12 @@ def annotate_query(cls):
def configuration_schema(cls):
return {}

@classmethod
def add_configuration_property(cls, property, value):
if cls.configuration_properties is None:
raise NotImplementedError()
cls.configuration_properties[property] = value

def test_connection(self):
if self.noop_query is None:
raise NotImplementedError()
Expand Down Expand Up @@ -151,35 +158,36 @@ class BaseHTTPQueryRunner(BaseQueryRunner):
url_title = 'URL base path'
username_title = 'HTTP Basic Auth Username'
password_title = 'HTTP Basic Auth Password'
configuration_properties = {
'url': {
'type': 'string',
'title': url_title,
},
'username': {
'type': 'string',
'title': username_title,
},
'password': {
'type': 'string',
'title': password_title,
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": (
"This string will be used to toggle visibility of "
"tables in the schema browser when editing a query "
"in order to remove non-useful tables from sight."
),
},
}

@classmethod
def configuration_schema(cls):
schema = {
'type': 'object',
'properties': {
'url': {
'type': 'string',
'title': cls.url_title,
},
'username': {
'type': 'string',
'title': cls.username_title,
},
'password': {
'type': 'string',
'title': cls.password_title,
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": (
"This string will be used to toggle visibility of "
"tables in the schema browser when editing a query "
"in order to remove non-useful tables from sight."
),
}
},
'properties': cls.configuration_properties,
'required': ['url'],
'secret': ['password']
}
Expand Down
82 changes: 42 additions & 40 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,47 @@ def _get_query_results(jobs, project_id, location, job_id, start_index):

class BigQuery(BaseQueryRunner):
noop_query = "SELECT 1"
configuration_properties = {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
"default": "US",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
},
}

@classmethod
def enabled(cls):
Expand All @@ -92,46 +133,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
'properties': cls.configuration_properties,
'required': ['jsonKeyFile', 'projectId'],
"order": ['projectId', 'jsonKeyFile', 'loadSchema', 'useStandardSql', 'location', 'totalMBytesProcessedLimit', 'maximumBillingTier', 'userDefinedFunctionResourceUri'],
'secret': ['jsonKeyFile']
Expand Down
75 changes: 38 additions & 37 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,43 @@ def default(self, o):

class Cassandra(BaseQueryRunner):
noop_query = "SELECT dateof(now()) FROM system.local"
configuration_properties = {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
},
}

@classmethod
def enabled(cls):
Expand All @@ -36,43 +73,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
'properties': cls.configuration_properties,
'required': ['keyspace', 'host']
}

Expand Down
39 changes: 21 additions & 18 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,31 @@


class DynamoDBSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
configuration_properties = {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
},
}

@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
"properties": cls.configuration_properties,
"required": ["access_key", "secret_key"],
"secret": ["secret_key"]
}
Expand Down
Loading

0 comments on commit ce970a0

Please sign in to comment.