Skip to content

Commit

Permalink
Documentation links for data sources (re #6)
Browse files Browse the repository at this point in the history
(incorporates: show data source type when no doc link present (re #46))
  • Loading branch information
Allen Short committed Dec 12, 2017
1 parent b0c33a0 commit 2e141f5
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 8 deletions.
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 @@ -5,7 +5,7 @@
<a href="data_sources/new" class="btn btn-default"><i class="fa fa-plus"></i> New Data Source</a>
</p>
<div class="list-group">
<a ng-href="data_sources/{{dataSource.id}}" class="list-group-item" ng-repeat="dataSource in dataSources"><i class="fa fa-database"></i> {{dataSource.name}}</a>
<a ng-href="data_sources/{{dataSource.id}}" class="list-group-item" ng-repeat="dataSource in dataSources"><i class="fa fa-database"></i> <b>{{dataSource.name}}</b> - {{dataSource.type_name}}</a>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ <h3>
<i class="fa fa-database"></i> &nbsp;
<select ng-disabled="!isQueryOwner" ng-model="query.data_source_id" ng-change="updateDataSource()"
ng-options="ds.id as ds.name for ds in dataSources"></select>
<a ng-if="dataSource.options.doc_url != ''" ng-href={{dataSource.options.doc_url}}>{{dataSource.type_name}} documentation</a>
<span ng-if="dataSource.options.doc_url == ''">{{dataSource.type_name}}</span>

<div class="pull-right">
<button class="btn btn-s btn-default" ng-click="togglePublished()" ng-if="query.is_draft && query.id != undefined && (isQueryOwner || currentUser.hasPermission('admin'))">
Expand Down
12 changes: 10 additions & 2 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,12 @@ def to_dict(self, all=False, with_permissions_for=None):
'type': self.type,
'syntax': self.query_runner.syntax,
'paused': self.paused,
'pause_reason': self.pause_reason
'pause_reason': self.pause_reason,
'type_name': self.query_runner.name(),
}

schema = get_configuration_schema_for_query_runner_type(self.type)
if all:
schema = get_configuration_schema_for_query_runner_type(self.type)
self.options.set_schema(schema)
d['options'] = self.options.to_dict(mask_secrets=True)
d['queue_name'] = self.queue_name
Expand All @@ -538,6 +539,11 @@ def to_dict(self, all=False, with_permissions_for=None):
DataSourceGroup.group == with_permissions_for,
DataSourceGroup.data_source == self).one()[0]

doc_url = self.options.get('doc_url', schema['properties'].get(
'doc_url', {}).get('default'))
if doc_url:
d['options'] = {'doc_url': doc_url}

return d

def __unicode__(self):
Expand Down Expand Up @@ -612,6 +618,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
1 change: 1 addition & 0 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class InterruptException(Exception):

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

def __init__(self, configuration):
self.syntax = 'sql'
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _get_query_results(jobs, project_id, job_id, start_index):

class BigQuery(BaseQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://cloud.google.com/bigquery/docs/reference/legacy-sql"

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -117,6 +118,11 @@ def configuration_schema(cls):
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['jsonKeyFile', 'projectId'],
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def default(self, o):

class Cassandra(BaseQueryRunner):
noop_query = "SELECT dateof(now()) FROM system.local"
default_doc_url = "http://cassandra.apache.org/doc/latest/cql/index.html"

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -65,6 +66,11 @@ def configuration_schema(cls):
'type': 'number',
'title': 'Timeout',
'default': 10
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['keyspace', 'host']
Expand Down
8 changes: 8 additions & 0 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@


class DynamoDBSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://dql.readthedocs.io/en/latest/"

@classmethod
def configuration_schema(cls):
return {
Expand All @@ -47,6 +50,11 @@ def configuration_schema(cls):
},
"secret_key": {
"type": "string",
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["access_key", "secret_key"],
Expand Down
8 changes: 7 additions & 1 deletion redash/query_runner/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@


class BaseElasticSearch(BaseQueryRunner):
DEBUG_ENABLED = False
DEBUG_ENABLED = True
default_doc_url = "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html"

@classmethod
def configuration_schema(cls):
Expand All @@ -62,6 +63,11 @@ def configuration_schema(cls):
'basic_auth_password': {
'type': 'string',
'title': 'Basic Auth Password'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"secret": ["basic_auth_password"],
Expand Down
9 changes: 9 additions & 0 deletions redash/query_runner/google_spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def parse_worksheet(worksheet):
columns.append({
'name': column_name,
'friendly_name': column_name,

'type': TYPE_STRING
})

Expand Down Expand Up @@ -139,6 +140,9 @@ def request(self, *args, **kwargs):


class GoogleSpreadsheet(BaseQueryRunner):
default_doc_url = ("http://redash.readthedocs.io/en/latest/"
"datasources.html#google-spreadsheets")

@classmethod
def annotate_query(cls):
return False
Expand All @@ -159,6 +163,11 @@ def configuration_schema(cls):
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['jsonKeyFile'],
Expand Down
5 changes: 5 additions & 0 deletions redash/query_runner/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def configuration_schema(cls):
'verify': {
'type': 'boolean',
'title': 'Verify SSL certificate'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url'],
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/hive_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class Hive(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = ("https://cwiki.apache.org/confluence/display/Hive/"
"LanguageManual")

@classmethod
def configuration_schema(cls):
Expand All @@ -53,6 +55,11 @@ def configuration_schema(cls):
},
"username": {
"type": "string"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["host"]
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/impala_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class Impala(BaseSQLQueryRunner):
noop_query = "show schemas"
default_doc_url = ("http://www.cloudera.com/documentation/enterprise/"
"latest/topics/impala_langref.html")

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -66,6 +68,11 @@ def configuration_schema(cls):
},
"timeout": {
"type": "number"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["host"],
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/influx_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _transform_result(results):

class InfluxDB(BaseQueryRunner):
noop_query = "show measurements limit 1"
default_doc_url = ("https://docs.influxdata.com/influxdb/v1.0/"
"query_language/spec/")

@classmethod
def configuration_schema(cls):
Expand All @@ -58,6 +60,11 @@ def configuration_schema(cls):
'properties': {
'url': {
'type': 'string'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url']
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/jql.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def get_dict_output_field_name(cls,field_name, member_name):

class JiraJQL(BaseQueryRunner):
noop_query = '{"queryType": "count"}'
default_doc_url = ("https://confluence.atlassian.com/jirasoftwarecloud/"
"advanced-searching-764478330.html")

@classmethod
def configuration_schema(cls):
Expand All @@ -154,6 +156,11 @@ def configuration_schema(cls):
},
'password': {
'type': 'string'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url', 'username', 'password'],
Expand Down
8 changes: 8 additions & 0 deletions redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def parse_query_json(query):


class MongoDB(BaseQueryRunner):
default_doc_url = ("https://docs.mongodb.com/manual/reference/operator/"
"query/")

@classmethod
def configuration_schema(cls):
return {
Expand All @@ -92,6 +95,11 @@ def configuration_schema(cls):
'type': 'string',
'title': 'Replica Set Name'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['connectionString', 'dbName']
}
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def default(self, o):

class SqlServer(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://msdn.microsoft.com/en-us/library/bb510741.aspx"

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -68,6 +69,11 @@ def configuration_schema(cls):
"db": {
"type": "string",
"title": "Database Name"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["db"],
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

class Mysql(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = 'https://dev.mysql.com/doc/refman/5.7/en/'

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -79,6 +80,11 @@ def configuration_schema(cls):
'ssl_key': {
'type': 'string',
'title': 'Path to private key file (SSL)'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
})

Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

logger = logging.getLogger(__name__)


class Oracle(BaseSQLQueryRunner):
noop_query = "SELECT 1 FROM dual"
default_doc_url = "http://docs.oracle.com/database/121/SQLRF/toc.htm"

@classmethod
def get_col_type(cls, col_type, scale):
Expand Down Expand Up @@ -65,6 +67,11 @@ def configuration_schema(cls):
"servicename": {
"type": "string",
"title": "DSN Service Name"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["servicename", "user", "password", "host", "port"],
Expand Down
14 changes: 14 additions & 0 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _wait(conn, timeout=None):

class PostgreSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://www.postgresql.org/docs/current/"

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -75,6 +76,11 @@ def configuration_schema(cls):
"type": "string",
"title": "SSL Mode",
"default": "prefer"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"order": ['host', 'port', 'user', 'password'],
Expand Down Expand Up @@ -179,6 +185,9 @@ def run_query(self, query, user):


class Redshift(PostgreSQL):
default_doc_url = ("http://docs.aws.amazon.com/redshift/latest/"
"dg/cm_chap_SQLCommandRef.html")

@classmethod
def type(cls):
return "redshift"
Expand Down Expand Up @@ -218,6 +227,11 @@ def configuration_schema(cls):
"dbname": {
"type": "string",
"title": "Database Name"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"order": ['host', 'port', 'user', 'password'],
Expand Down
Loading

0 comments on commit 2e141f5

Please sign in to comment.