Skip to content

Commit 2e141f5

Browse files
author
Allen Short
committed
Documentation links for data sources (re getredash#6)
(incorporates: show data source type when no doc link present (re getredash#46))
1 parent b0c33a0 commit 2e141f5

28 files changed

+182
-8
lines changed

client/app/pages/data-sources/list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="data_sources/new" class="btn btn-default"><i class="fa fa-plus"></i> New Data Source</a>
66
</p>
77
<div class="list-group">
8-
<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>
8+
<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>
99
</div>
1010
</div>
1111
</div>

client/app/pages/queries/query.html

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ <h3>
102102
<i class="fa fa-database"></i> &nbsp;
103103
<select ng-disabled="!isQueryOwner" ng-model="query.data_source_id" ng-change="updateDataSource()"
104104
ng-options="ds.id as ds.name for ds in dataSources"></select>
105+
<a ng-if="dataSource.options.doc_url != ''" ng-href={{dataSource.options.doc_url}}>{{dataSource.type_name}} documentation</a>
106+
<span ng-if="dataSource.options.doc_url == ''">{{dataSource.type_name}}</span>
105107

106108
<div class="pull-right">
107109
<button class="btn btn-s btn-default" ng-click="togglePublished()" ng-if="query.is_draft && query.id != undefined && (isQueryOwner || currentUser.hasPermission('admin'))">

redash/models.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,12 @@ def to_dict(self, all=False, with_permissions_for=None):
522522
'type': self.type,
523523
'syntax': self.query_runner.syntax,
524524
'paused': self.paused,
525-
'pause_reason': self.pause_reason
525+
'pause_reason': self.pause_reason,
526+
'type_name': self.query_runner.name(),
526527
}
527528

529+
schema = get_configuration_schema_for_query_runner_type(self.type)
528530
if all:
529-
schema = get_configuration_schema_for_query_runner_type(self.type)
530531
self.options.set_schema(schema)
531532
d['options'] = self.options.to_dict(mask_secrets=True)
532533
d['queue_name'] = self.queue_name
@@ -538,6 +539,11 @@ def to_dict(self, all=False, with_permissions_for=None):
538539
DataSourceGroup.group == with_permissions_for,
539540
DataSourceGroup.data_source == self).one()[0]
540541

542+
doc_url = self.options.get('doc_url', schema['properties'].get(
543+
'doc_url', {}).get('default'))
544+
if doc_url:
545+
d['options'] = {'doc_url': doc_url}
546+
541547
return d
542548

543549
def __unicode__(self):
@@ -612,6 +618,8 @@ def add_group(self, group, view_only=False):
612618
db.session.add(dsg)
613619
return dsg
614620

621+
setattr(self, 'data_source_groups', dsg)
622+
615623
def remove_group(self, group):
616624
db.session.query(DataSourceGroup).filter(
617625
DataSourceGroup.group == group,

redash/query_runner/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class InterruptException(Exception):
4747

4848
class BaseQueryRunner(object):
4949
noop_query = None
50+
default_doc_url = None
5051

5152
def __init__(self, configuration):
5253
self.syntax = 'sql'

redash/query_runner/big_query.py

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def _get_query_results(jobs, project_id, job_id, start_index):
8080

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

8485
@classmethod
8586
def enabled(cls):
@@ -117,6 +118,11 @@ def configuration_schema(cls):
117118
'maximumBillingTier': {
118119
"type": "number",
119120
"title": "Maximum Billing Tier"
121+
},
122+
"doc_url": {
123+
"type": "string",
124+
"title": "Documentation URL",
125+
"default": cls.default_doc_url
120126
}
121127
},
122128
'required': ['jsonKeyFile', 'projectId'],

redash/query_runner/cass.py

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def default(self, o):
2727

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

3132
@classmethod
3233
def enabled(cls):
@@ -65,6 +66,11 @@ def configuration_schema(cls):
6566
'type': 'number',
6667
'title': 'Timeout',
6768
'default': 10
69+
},
70+
"doc_url": {
71+
"type": "string",
72+
"title": "Documentation URL",
73+
"default": cls.default_doc_url
6874
}
6975
},
7076
'required': ['keyspace', 'host']

redash/query_runner/dynamodb_sql.py

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434

3535
class DynamoDBSQL(BaseSQLQueryRunner):
36+
noop_query = "SELECT 1"
37+
default_doc_url = "https://dql.readthedocs.io/en/latest/"
38+
3639
@classmethod
3740
def configuration_schema(cls):
3841
return {
@@ -47,6 +50,11 @@ def configuration_schema(cls):
4750
},
4851
"secret_key": {
4952
"type": "string",
53+
},
54+
"doc_url": {
55+
"type": "string",
56+
"title": "Documentation URL",
57+
"default": cls.default_doc_url
5058
}
5159
},
5260
"required": ["access_key", "secret_key"],

redash/query_runner/elasticsearch.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444

4545

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

4950
@classmethod
5051
def configuration_schema(cls):
@@ -62,6 +63,11 @@ def configuration_schema(cls):
6263
'basic_auth_password': {
6364
'type': 'string',
6465
'title': 'Basic Auth Password'
66+
},
67+
"doc_url": {
68+
"type": "string",
69+
"title": "Documentation URL",
70+
"default": cls.default_doc_url
6571
}
6672
},
6773
"secret": ["basic_auth_password"],

redash/query_runner/google_spreadsheets.py

+9
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def parse_worksheet(worksheet):
108108
columns.append({
109109
'name': column_name,
110110
'friendly_name': column_name,
111+
111112
'type': TYPE_STRING
112113
})
113114

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

140141

141142
class GoogleSpreadsheet(BaseQueryRunner):
143+
default_doc_url = ("http://redash.readthedocs.io/en/latest/"
144+
"datasources.html#google-spreadsheets")
145+
142146
@classmethod
143147
def annotate_query(cls):
144148
return False
@@ -159,6 +163,11 @@ def configuration_schema(cls):
159163
'jsonKeyFile': {
160164
"type": "string",
161165
'title': 'JSON Key File'
166+
},
167+
"doc_url": {
168+
"type": "string",
169+
"title": "Documentation URL",
170+
"default": cls.default_doc_url
162171
}
163172
},
164173
'required': ['jsonKeyFile'],

redash/query_runner/graphite.py

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def configuration_schema(cls):
4242
'verify': {
4343
'type': 'boolean',
4444
'title': 'Verify SSL certificate'
45+
},
46+
"doc_url": {
47+
"type": "string",
48+
"title": "Documentation URL",
49+
"default": cls.default_doc_url
4550
}
4651
},
4752
'required': ['url'],

redash/query_runner/hive_ds.py

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
class Hive(BaseSQLQueryRunner):
3838
noop_query = "SELECT 1"
39+
default_doc_url = ("https://cwiki.apache.org/confluence/display/Hive/"
40+
"LanguageManual")
3941

4042
@classmethod
4143
def configuration_schema(cls):
@@ -53,6 +55,11 @@ def configuration_schema(cls):
5355
},
5456
"username": {
5557
"type": "string"
58+
},
59+
"doc_url": {
60+
"type": "string",
61+
"title": "Documentation URL",
62+
"default": cls.default_doc_url
5663
}
5764
},
5865
"required": ["host"]

redash/query_runner/impala_ds.py

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

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

4042
@classmethod
4143
def configuration_schema(cls):
@@ -66,6 +68,11 @@ def configuration_schema(cls):
6668
},
6769
"timeout": {
6870
"type": "number"
71+
},
72+
"doc_url": {
73+
"type": "string",
74+
"title": "Documentation URL",
75+
"default": cls.default_doc_url
6976
}
7077
},
7178
"required": ["host"],

redash/query_runner/influx_db.py

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def _transform_result(results):
5050

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

5456
@classmethod
5557
def configuration_schema(cls):
@@ -58,6 +60,11 @@ def configuration_schema(cls):
5860
'properties': {
5961
'url': {
6062
'type': 'string'
63+
},
64+
"doc_url": {
65+
"type": "string",
66+
"title": "Documentation URL",
67+
"default": cls.default_doc_url
6168
}
6269
},
6370
'required': ['url']

redash/query_runner/jql.py

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def get_dict_output_field_name(cls,field_name, member_name):
139139

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

143145
@classmethod
144146
def configuration_schema(cls):
@@ -154,6 +156,11 @@ def configuration_schema(cls):
154156
},
155157
'password': {
156158
'type': 'string'
159+
},
160+
"doc_url": {
161+
"type": "string",
162+
"title": "Documentation URL",
163+
"default": cls.default_doc_url
157164
}
158165
},
159166
'required': ['url', 'username', 'password'],

redash/query_runner/mongodb.py

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def parse_query_json(query):
7575

7676

7777
class MongoDB(BaseQueryRunner):
78+
default_doc_url = ("https://docs.mongodb.com/manual/reference/operator/"
79+
"query/")
80+
7881
@classmethod
7982
def configuration_schema(cls):
8083
return {
@@ -92,6 +95,11 @@ def configuration_schema(cls):
9295
'type': 'string',
9396
'title': 'Replica Set Name'
9497
},
98+
"doc_url": {
99+
"type": "string",
100+
"title": "Documentation URL",
101+
"default": cls.default_doc_url
102+
}
95103
},
96104
'required': ['connectionString', 'dbName']
97105
}

redash/query_runner/mssql.py

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def default(self, o):
3535

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

3940
@classmethod
4041
def configuration_schema(cls):
@@ -68,6 +69,11 @@ def configuration_schema(cls):
6869
"db": {
6970
"type": "string",
7071
"title": "Database Name"
72+
},
73+
"doc_url": {
74+
"type": "string",
75+
"title": "Documentation URL",
76+
"default": cls.default_doc_url
7177
}
7278
},
7379
"required": ["db"],

redash/query_runner/mysql.py

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

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

3334
@classmethod
3435
def configuration_schema(cls):
@@ -79,6 +80,11 @@ def configuration_schema(cls):
7980
'ssl_key': {
8081
'type': 'string',
8182
'title': 'Path to private key file (SSL)'
83+
},
84+
"doc_url": {
85+
"type": "string",
86+
"title": "Documentation URL",
87+
"default": cls.default_doc_url
8288
}
8389
})
8490

redash/query_runner/oracle.py

+7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
logger = logging.getLogger(__name__)
3333

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

3739
@classmethod
3840
def get_col_type(cls, col_type, scale):
@@ -65,6 +67,11 @@ def configuration_schema(cls):
6567
"servicename": {
6668
"type": "string",
6769
"title": "DSN Service Name"
70+
},
71+
"doc_url": {
72+
"type": "string",
73+
"title": "Documentation URL",
74+
"default": cls.default_doc_url
6875
}
6976
},
7077
"required": ["servicename", "user", "password", "host", "port"],

redash/query_runner/pg.py

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _wait(conn, timeout=None):
4747

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

5152
@classmethod
5253
def configuration_schema(cls):
@@ -75,6 +76,11 @@ def configuration_schema(cls):
7576
"type": "string",
7677
"title": "SSL Mode",
7778
"default": "prefer"
79+
},
80+
"doc_url": {
81+
"type": "string",
82+
"title": "Documentation URL",
83+
"default": cls.default_doc_url
7884
}
7985
},
8086
"order": ['host', 'port', 'user', 'password'],
@@ -179,6 +185,9 @@ def run_query(self, query, user):
179185

180186

181187
class Redshift(PostgreSQL):
188+
default_doc_url = ("http://docs.aws.amazon.com/redshift/latest/"
189+
"dg/cm_chap_SQLCommandRef.html")
190+
182191
@classmethod
183192
def type(cls):
184193
return "redshift"
@@ -218,6 +227,11 @@ def configuration_schema(cls):
218227
"dbname": {
219228
"type": "string",
220229
"title": "Database Name"
230+
},
231+
"doc_url": {
232+
"type": "string",
233+
"title": "Documentation URL",
234+
"default": cls.default_doc_url
221235
}
222236
},
223237
"order": ['host', 'port', 'user', 'password'],

0 commit comments

Comments
 (0)