|
|
@@ -22,24 +22,21 @@ function getTrueFilters(item, filters) {
|
|
|
)) {
|
|
|
if(f.operator === 'betweent' ? ( !!f.value1 && (f.value1.length ? f.value1.length > 0 : true) && !!f.value2 && (f.value2.length ? f.value2.length > 0 : true)) : (!!f.value1 && (f.value1.length ? f.value1.length > 0 : true))) {
|
|
|
if(f.combined) {
|
|
|
- let column = f.dataSource.columns.find(c => c.name === f.name);
|
|
|
- column.relations.forEach(re => {
|
|
|
- if(re.dataSource.code === item.dataSourceCode) {
|
|
|
- trueFilters.push({
|
|
|
- dataSourceCode: re.dataSource.code,
|
|
|
- name: re.column.name,
|
|
|
- operator: f.operator,
|
|
|
- type: f.type,
|
|
|
- value1: f.value1,
|
|
|
- value2: f.value2,
|
|
|
- using: f.using
|
|
|
- });
|
|
|
- }
|
|
|
+ f.dataSource.forEach(d => {
|
|
|
+ trueFilters.push({
|
|
|
+ dataSourceCode: d.dataSource.code,
|
|
|
+ name: d.column.name,
|
|
|
+ operator: f.operator,
|
|
|
+ type: f.type,
|
|
|
+ value1: f.value1,
|
|
|
+ value2: f.value2,
|
|
|
+ using: f.using
|
|
|
+ });
|
|
|
});
|
|
|
}else {
|
|
|
- if(f.dataSource.name === item.dataSourceCode) {
|
|
|
+ if(f.dataSource.code === item.dataSourceCode) {
|
|
|
trueFilters.push({
|
|
|
- dataSourceCode: f.dataSource.name,
|
|
|
+ dataSourceCode: f.dataSource.code,
|
|
|
name: f.name,
|
|
|
operator: f.operator,
|
|
|
type: f.type,
|
|
|
@@ -277,7 +274,6 @@ export default {
|
|
|
const { relationColumns } = state;
|
|
|
let index = relationColumns.findIndex(r => r.code === code);
|
|
|
relationColumns.splice(index, 1);
|
|
|
- console.log(relationColumns);
|
|
|
return { ...state, relationColumns, dirty: true };
|
|
|
},
|
|
|
setRelationColumn(state, action) {
|
|
|
@@ -406,11 +402,10 @@ export default {
|
|
|
filters = filters.map(f => {
|
|
|
if(f.key === filter.key) {
|
|
|
if(f.combined) {
|
|
|
- let column = f.dataSource.columns.find(c => c.name === f.name);
|
|
|
- targetDataSourceCodes = targetDataSourceCodes.concat(column.relations.map(r => r.dataSource.code));
|
|
|
+ targetDataSourceCodes = targetDataSourceCodes.concat(f.dataSource.map(d => d.dataSource.code));
|
|
|
}else {
|
|
|
- if(targetDataSourceCodes.indexOf(f.dataSource.name) === -1) {
|
|
|
- targetDataSourceCodes.push(f.dataSource.name);
|
|
|
+ if(targetDataSourceCodes.indexOf(f.dataSource.code) === -1) {
|
|
|
+ targetDataSourceCodes.push(f.dataSource.code);
|
|
|
}
|
|
|
}
|
|
|
return Object.assign({}, f, filter);
|
|
|
@@ -518,7 +513,61 @@ export default {
|
|
|
}else {
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ *setRelationColumns(action, { put, call, select }) {
|
|
|
+ const { relationColumns } = action;
|
|
|
+ let targetDataSourceCodes = []; // 记录有改动的数据源code
|
|
|
+ const dashboardDesigner = yield select(state => state.present.dashboardDesigner);
|
|
|
+ let { filters, items } = dashboardDesigner;
|
|
|
+ for(let i = filters.length - 1; i >= 0; i--) {
|
|
|
+ let f = filters[i];
|
|
|
+ let idx = relationColumns.findIndex(rc => rc.code === f.name);
|
|
|
+ if(idx > -1) {
|
|
|
+ // 如果改变的自定义条件已经添加到了筛选条件区域
|
|
|
+ let nrc = relationColumns[idx];
|
|
|
+ let willRemove = false;
|
|
|
+ if(f.type !== nrc.relations[0].column.type) { // 如果改变了所选的列
|
|
|
+ willRemove = true;
|
|
|
+ }
|
|
|
+ let oldDataSourceCodes = f.dataSource.map(d => d.dataSource.code);
|
|
|
+ let oldColumns = f.dataSource.map(d => d.column.name);
|
|
|
+ let newDataSourceCodes = nrc.relations.map(r => r.dataSource.code);
|
|
|
+ let newColumns = nrc.relations.map(r => r.column.name);
|
|
|
+
|
|
|
+ if(!oldDataSourceCodes.equals(newDataSourceCodes) || !oldColumns.equals(newColumns)) { // 如果改变了数据源或者数据列
|
|
|
+ willRemove = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(willRemove) {
|
|
|
+ f.dataSource.forEach(d => {
|
|
|
+ targetDataSourceCodes.push(d.dataSource.code);
|
|
|
+ });
|
|
|
+ filters.splice(i, 1); // 将该过滤字段移除
|
|
|
+ }else { // 只剩下label会改变了
|
|
|
+ filters[i] = { ...filters[i], label: nrc.name }
|
|
|
+ }
|
|
|
+ }else if(f.combined) { // 自定义字段已被删除
|
|
|
+ f.dataSource.forEach(d => {
|
|
|
+ targetDataSourceCodes.push(d.dataSource.code);
|
|
|
+ });
|
|
|
+
|
|
|
+ filters.splice(i, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yield put({ type: 'setFields', fields: [
|
|
|
+ { name: 'relationColumns', value: relationColumns },
|
|
|
+ { name: 'filters', value: filters },
|
|
|
+ { name: 'dirty', value: true },
|
|
|
+ ] });
|
|
|
+ // 找到filters有影响的item
|
|
|
+ let targetItems = items.filter(item => targetDataSourceCodes.indexOf(item.dataSourceCode) !== -1);
|
|
|
+
|
|
|
+ yield put({ type: 'silentSetField', name: 'filters', value: filters });
|
|
|
+
|
|
|
+ for(let i = 0; i < targetItems.length; i++) {
|
|
|
+ yield put({ type:'fetchChartData', item: targetItems[i], mandatory: true });
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
subscriptions: {
|
|
|
setup({ dispatch, history}) {
|