forked from github/dataease
Merge pull request #9484 from dataease/pr@dev@feat_drill_dim_sort
feat(视图): 支持自定义下钻维度的排序 #6357
This commit is contained in:
commit
883a4797c3
@ -179,6 +179,14 @@ public class ChartViewController {
|
||||
return chartViewService.getFieldData(id, requestList, false, fieldId, fieldType);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@ApiOperation("获取下钻字段值")
|
||||
@PostMapping("/getDrillFieldData/{id}/{panelId}/{fieldId}")
|
||||
public List<String> getDrillFieldData(@PathVariable String id, @PathVariable String panelId, @PathVariable String fieldId,
|
||||
@RequestBody ChartExtRequest requestList) throws Exception {
|
||||
return chartViewService.getDrillFieldData(id, requestList, false, fieldId);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@ApiOperation("更新视图属性")
|
||||
@PostMapping("/viewPropsSave/{panelId}")
|
||||
|
@ -443,9 +443,6 @@ public class ChartViewService {
|
||||
}
|
||||
|
||||
List<ChartExtFilterRequest> extFilterList = new ArrayList<>();
|
||||
List<ChartExtFilterRequest> filters = new ArrayList<>();
|
||||
List<ChartExtFilterRequest> drillFilters = new ArrayList<>();
|
||||
boolean isDrill = false;
|
||||
|
||||
// 判断连接方式,直连或者定时抽取 table.mode
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
@ -984,7 +981,6 @@ public class ChartViewService {
|
||||
ChartViewFieldDTO nextDrillField = drill.get(i + 1);
|
||||
if (!checkDrillExist(xAxis, extStack, nextDrillField.getId(), view)) {
|
||||
// get drill list first element's sort,then assign to nextDrillField
|
||||
nextDrillField.setSort(getDrillSort(xAxis, drill.get(0)));
|
||||
nextDrillField.setDrill(true);
|
||||
|
||||
if (isAntVScatterNumberXAxis) {
|
||||
@ -2530,4 +2526,27 @@ public class ChartViewService {
|
||||
result.setDatasourceType(null);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getDrillFieldData(String id, ChartExtRequest requestList, boolean cache, String fieldId) throws Exception {
|
||||
ChartViewDTO view = getOne(id, requestList.getQueryFrom());
|
||||
Type tokenType = new TypeToken<List<ChartViewFieldDTO>>() {
|
||||
}.getType();
|
||||
List<ChartViewFieldDTO> drillField = gson.fromJson(view.getDrillFields(), tokenType);
|
||||
ChartViewFieldDTO targetField = null;
|
||||
for (int i = 0; i < drillField.size(); i++) {
|
||||
ChartViewFieldDTO tmp = drillField.get(i);
|
||||
if (tmp.getId().equalsIgnoreCase(fieldId)) {
|
||||
targetField = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetField == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
view.setXAxis(gson.toJson(Collections.singleton(targetField)));
|
||||
|
||||
List<String[]> sqlData = sqlData(view, requestList, cache, fieldId);
|
||||
List<String[]> result = customSort(Optional.ofNullable(targetField.getCustomSort()).orElse(new ArrayList<>()), sqlData, 0);
|
||||
return result.stream().map(i -> i[0]).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -92,10 +92,17 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id + '/' + this.fieldType, {}).then(response => {
|
||||
this.sortList = response.data
|
||||
this.onUpdate()
|
||||
})
|
||||
if (this.fieldType === 'drillFields') {
|
||||
post('/chart/view/getDrillFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id, {}).then(response => {
|
||||
this.sortList = response.data
|
||||
this.onUpdate()
|
||||
})
|
||||
} else {
|
||||
post('/chart/view/getFieldData/' + this.chart.id + '/' + this.panelInfo.id + '/' + this.field.id + '/' + this.fieldType, {}).then(response => {
|
||||
this.sortList = response.data
|
||||
this.onUpdate()
|
||||
})
|
||||
}
|
||||
},
|
||||
moveToTop(index, item) {
|
||||
let targetIndex = index
|
||||
|
@ -59,6 +59,33 @@
|
||||
/>
|
||||
</el-tag>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item>
|
||||
<el-dropdown
|
||||
placement="right-start"
|
||||
size="mini"
|
||||
style="width: 100%"
|
||||
@command="sort"
|
||||
>
|
||||
<span class="el-dropdown-link inner-dropdown-menu">
|
||||
<span>
|
||||
<i class="el-icon-sort" />
|
||||
<span>{{ $t('chart.sort') }}</span>
|
||||
<span class="summary-span-item">({{ item.sort ? $t('chart.' + item.sort) : $t('chart.none') }})</span>
|
||||
</span>
|
||||
<i class="el-icon-arrow-right el-icon--right" />
|
||||
</span>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="beforeSort('none')">{{ $t('chart.none') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeSort('asc')">{{ $t('chart.asc') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeSort('desc')">{{ $t('chart.desc') }}</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
:command="beforeSort('custom_sort')"
|
||||
>
|
||||
{{ $t('chart.custom_sort') }}...
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-show="item.deType === 1"
|
||||
>
|
||||
@ -161,6 +188,10 @@ export default {
|
||||
quotaData: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
chart: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -168,6 +199,18 @@ export default {
|
||||
tagType: 'success'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
showDateExt() {
|
||||
return (
|
||||
this.chart.datasourceType === 'mysql' ||
|
||||
this.chart.datasourceType === 'ds_doris' ||
|
||||
this.chart.datasourceType === 'StarRocks' ||
|
||||
this.chart.datasourceType === 'ck' ||
|
||||
this.chart.datasourceType === 'oracle' ||
|
||||
this.chart.datasetMode === 1) &&
|
||||
this.chart.type !== 'bar-time-range'
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
dimensionData: function() {
|
||||
this.getItemTagType()
|
||||
@ -228,6 +271,25 @@ export default {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
beforeSort(type) {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
sort(param) {
|
||||
if (param.type === 'custom_sort') {
|
||||
const item = {
|
||||
index: this.index,
|
||||
sort: param.type
|
||||
}
|
||||
this.$emit('onCustomSort', item)
|
||||
} else {
|
||||
this.item.index = this.index
|
||||
this.item.sort = param.type
|
||||
this.item.customSort = []
|
||||
this.$emit('onDimensionItemChange', this.item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1183,8 +1183,10 @@
|
||||
:item="item"
|
||||
:dimension-data="dimension"
|
||||
:quota-data="quota"
|
||||
:chart="chart"
|
||||
@onDimensionItemChange="drillItemChange"
|
||||
@onDimensionItemRemove="drillItemRemove"
|
||||
@onCustomSort="item => onCustomSort(item, 'drillFields')"
|
||||
/>
|
||||
</transition-group>
|
||||
</draggable>
|
||||
@ -2934,7 +2936,7 @@ export default {
|
||||
},
|
||||
customSort(args) {
|
||||
const { item, axis } = JSON.parse(JSON.stringify(args))
|
||||
this.onCustomSort(item, axis);
|
||||
this.onCustomSort(item, axis)
|
||||
},
|
||||
onCustomSort(item, axis) {
|
||||
this.customSortFieldType = axis
|
||||
|
Loading…
Reference in New Issue
Block a user