mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Moved time column and grains to models.py (#1255)
This commit is contained in:
parent
a8a16900e7
commit
659bf6d7e8
@ -29,7 +29,7 @@ export const CHANGE_FILTER_OP = 'CHANGE_FILTER_OP';
|
|||||||
export const CHANGE_FILTER_VALUE = 'CHANGE_FILTER_VALUE';
|
export const CHANGE_FILTER_VALUE = 'CHANGE_FILTER_VALUE';
|
||||||
export const RESET_FORM_DATA = 'RESET_FORM_DATA';
|
export const RESET_FORM_DATA = 'RESET_FORM_DATA';
|
||||||
export const CLEAR_ALL_OPTS = 'CLEAR_ALL_OPTS';
|
export const CLEAR_ALL_OPTS = 'CLEAR_ALL_OPTS';
|
||||||
export const SET_DATASOURCE_CLASS = 'SET_DATASOURCE_CLASS';
|
export const SET_DATASOURCE_TYPE = 'SET_DATASOURCE_TYPE';
|
||||||
|
|
||||||
export function setTimeColumnOpts(timeColumnOpts) {
|
export function setTimeColumnOpts(timeColumnOpts) {
|
||||||
return { type: SET_TIME_COLUMN_OPTS, timeColumnOpts };
|
return { type: SET_TIME_COLUMN_OPTS, timeColumnOpts };
|
||||||
@ -60,8 +60,8 @@ export function clearAllOpts() {
|
|||||||
return { type: CLEAR_ALL_OPTS };
|
return { type: CLEAR_ALL_OPTS };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setDatasourceClass(datasourceClass) {
|
export function setDatasourceType(datasourceType) {
|
||||||
return { type: SET_DATASOURCE_CLASS, datasourceClass };
|
return { type: SET_DATASOURCE_TYPE, datasourceType };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setFormOpts(datasourceId, datasourceType) {
|
export function setFormOpts(datasourceId, datasourceType) {
|
||||||
@ -94,7 +94,6 @@ export function setFormOpts(datasourceId, datasourceType) {
|
|||||||
if (d) timeGrainOpts.push({ value: d, label: d });
|
if (d) timeGrainOpts.push({ value: d, label: d });
|
||||||
});
|
});
|
||||||
// Repopulate options for controls
|
// Repopulate options for controls
|
||||||
dispatch(setDatasourceClass(data.datasource_class));
|
|
||||||
dispatch(setTimeColumnOpts(timeColumnOpts));
|
dispatch(setTimeColumnOpts(timeColumnOpts));
|
||||||
dispatch(setTimeGrainOpts(timeGrainOpts));
|
dispatch(setTimeGrainOpts(timeGrainOpts));
|
||||||
dispatch(setGroupByColumnOpts(groupByColumnOpts));
|
dispatch(setGroupByColumnOpts(groupByColumnOpts));
|
||||||
|
@ -17,7 +17,6 @@ const bootstrappedState = Object.assign(initialState, {
|
|||||||
datasources: bootstrapData.datasources,
|
datasources: bootstrapData.datasources,
|
||||||
datasourceId: parseInt(bootstrapData.datasource_id, 10),
|
datasourceId: parseInt(bootstrapData.datasource_id, 10),
|
||||||
datasourceType: bootstrapData.datasource_type,
|
datasourceType: bootstrapData.datasource_type,
|
||||||
datasourceClass: bootstrapData.datasource_class,
|
|
||||||
sliceName: bootstrapData.viz.form_data.slice_name,
|
sliceName: bootstrapData.viz.form_data.slice_name,
|
||||||
sliceId: bootstrapData.viz.form_data.slice_id,
|
sliceId: bootstrapData.viz.form_data.slice_id,
|
||||||
vizType: bootstrapData.viz.form_data.viz_type,
|
vizType: bootstrapData.viz.form_data.viz_type,
|
||||||
|
@ -103,8 +103,8 @@ export const exploreReducer = function (state, action) {
|
|||||||
[actions.CLEAR_ALL_OPTS]() {
|
[actions.CLEAR_ALL_OPTS]() {
|
||||||
return Object.assign({}, state, defaultOpts);
|
return Object.assign({}, state, defaultOpts);
|
||||||
},
|
},
|
||||||
[actions.SET_DATASOURCE_CLASS]() {
|
[actions.SET_DATASOURCE_TYPE]() {
|
||||||
return Object.assign({}, state, { datasourceClass: action.datasourceClass });
|
return Object.assign({}, state, { datasourceType: action.datasourceType });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (action.type in actionHandlers) {
|
if (action.type in actionHandlers) {
|
||||||
|
@ -2,7 +2,6 @@ export const initialState = {
|
|||||||
datasources: null,
|
datasources: null,
|
||||||
datasourceId: null,
|
datasourceId: null,
|
||||||
datasourceType: null,
|
datasourceType: null,
|
||||||
datasourceClass: null,
|
|
||||||
vizType: null,
|
vizType: null,
|
||||||
timeColumnOpts: [],
|
timeColumnOpts: [],
|
||||||
timeColumn: null,
|
timeColumn: null,
|
||||||
|
@ -760,6 +760,13 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
|||||||
def sql_url(self):
|
def sql_url(self):
|
||||||
return self.database.sql_url + "?table_name=" + str(self.table_name)
|
return self.database.sql_url + "?table_name=" + str(self.table_name)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def time_column_grains(self):
|
||||||
|
return {
|
||||||
|
"time_columns": self.dttm_cols,
|
||||||
|
"time_grains": [grain.name for grain in self.database.grains()]
|
||||||
|
}
|
||||||
|
|
||||||
def get_col(self, col_name):
|
def get_col(self, col_name):
|
||||||
columns = self.table_columns
|
columns = self.table_columns
|
||||||
for col in columns:
|
for col in columns:
|
||||||
@ -1278,6 +1285,16 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
|
|||||||
"[{obj.cluster_name}]."
|
"[{obj.cluster_name}]."
|
||||||
"[{obj.datasource_name}]").format(obj=self)
|
"[{obj.datasource_name}]").format(obj=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def time_column_grains(self):
|
||||||
|
return {
|
||||||
|
"time_columns": [
|
||||||
|
'all', '5 seconds', '30 seconds', '1 minute',
|
||||||
|
'5 minutes', '1 hour', '6 hour', '1 day', '7 days'
|
||||||
|
],
|
||||||
|
"time_grains": ['now']
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.datasource_name
|
return self.datasource_name
|
||||||
|
|
||||||
|
@ -42,10 +42,6 @@ config = app.config
|
|||||||
log_this = models.Log.log_this
|
log_this = models.Log.log_this
|
||||||
can_access = utils.can_access
|
can_access = utils.can_access
|
||||||
QueryStatus = models.QueryStatus
|
QueryStatus = models.QueryStatus
|
||||||
DRUID_TIME_GRAINS = [
|
|
||||||
'all', '5 seconds', '30 seconds', '1 minute',
|
|
||||||
'5 minutes', '1 hour', '6 hour', '1 day', '7 days'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class BaseCaravelView(BaseView):
|
class BaseCaravelView(BaseView):
|
||||||
@ -1301,7 +1297,6 @@ class Caravel(BaseCaravelView):
|
|||||||
"datasources": [(d.id, d.full_name) for d in datasources],
|
"datasources": [(d.id, d.full_name) for d in datasources],
|
||||||
"datasource_id": datasource_id,
|
"datasource_id": datasource_id,
|
||||||
"datasource_type": datasource_type,
|
"datasource_type": datasource_type,
|
||||||
"datasource_class": datasource_class.__name__,
|
|
||||||
"user_id": g.user.get_id() if g.user else None,
|
"user_id": g.user.get_id() if g.user else None,
|
||||||
"viz": json.loads(viz_obj.get_json())
|
"viz": json.loads(viz_obj.get_json())
|
||||||
}
|
}
|
||||||
@ -1963,25 +1958,14 @@ class Caravel(BaseCaravelView):
|
|||||||
if not self.datasource_access(datasource):
|
if not self.datasource_access(datasource):
|
||||||
return json_error_response(DATASOURCE_ACCESS_ERR)
|
return json_error_response(DATASOURCE_ACCESS_ERR)
|
||||||
|
|
||||||
time_columns = []
|
column_opts = {
|
||||||
grains_choices = []
|
|
||||||
datasource_class_name = datasource_class.__name__
|
|
||||||
if datasource_class_name == 'SqlaTable':
|
|
||||||
time_columns = datasource.dttm_cols
|
|
||||||
grains = datasource.database.grains()
|
|
||||||
grains_choices = [grain.name for grain in grains]
|
|
||||||
elif datasource_class_name == 'DruidDatasource':
|
|
||||||
time_columns = DRUID_TIME_GRAINS
|
|
||||||
grains_choices = ['now']
|
|
||||||
|
|
||||||
form_data = {
|
|
||||||
"datasource_class": datasource_class_name,
|
|
||||||
"time_columns": time_columns,
|
|
||||||
"time_grains": grains_choices,
|
|
||||||
"groupby_cols": datasource.groupby_column_names,
|
"groupby_cols": datasource.groupby_column_names,
|
||||||
"metrics": datasource.metrics_combo,
|
"metrics": datasource.metrics_combo,
|
||||||
"filter_cols": datasource.filterable_column_names,
|
"filter_cols": datasource.filterable_column_names
|
||||||
}
|
}
|
||||||
|
form_data = dict(
|
||||||
|
column_opts.items() + datasource.time_column_grains.items()
|
||||||
|
)
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
json.dumps(form_data), mimetype="application/json")
|
json.dumps(form_data), mimetype="application/json")
|
||||||
|
Loading…
Reference in New Issue
Block a user