add field sort
This commit is contained in:
parent
75b4584e4f
commit
baf78677c5
|
@ -12,14 +12,16 @@ import (
|
|||
)
|
||||
|
||||
type docReqBody struct {
|
||||
Index string `json:"index"`
|
||||
Action string `json:"action"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Filter string `json:"filter"`
|
||||
Cluster string `json:"cluster"`
|
||||
Keyword string `json:"keyword"`
|
||||
Index string `json:"index"`
|
||||
Action string `json:"action"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Filter string `json:"filter"`
|
||||
Cluster string `json:"cluster"`
|
||||
Keyword string `json:"keyword"`
|
||||
Sort string `json:"sort"`
|
||||
SortDirection string `json:"sort_direction"`
|
||||
}
|
||||
|
||||
func (handler APIHandler) HandleDocumentAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
|
@ -94,6 +96,7 @@ func (handler APIHandler) HandleDocumentAction(w http.ResponseWriter, req *http.
|
|||
var (
|
||||
pageSize = 10
|
||||
pageIndex = 1
|
||||
sort = ""
|
||||
)
|
||||
if reqBody.PageSize > 0 {
|
||||
pageSize = reqBody.PageSize
|
||||
|
@ -109,7 +112,14 @@ func (handler APIHandler) HandleDocumentAction(w http.ResponseWriter, req *http.
|
|||
if reqBody.Filter != "" {
|
||||
filter = reqBody.Filter
|
||||
}
|
||||
query := fmt.Sprintf(`{"from":%d, "size": %d, "query": %s}`, from, pageSize, filter)
|
||||
if sortField := strings.Trim(reqBody.Sort, " "); sortField != "" {
|
||||
sortDirection := reqBody.SortDirection
|
||||
if sortDirection != "desc" {
|
||||
sortDirection = "asc"
|
||||
}
|
||||
sort = fmt.Sprintf(`"%s":{"order":"%s"}`, sortField, sortDirection)
|
||||
}
|
||||
query := fmt.Sprintf(`{"from":%d, "size": %d, "query": %s, "sort": [{%s}]}`, from, pageSize, filter, sort)
|
||||
fmt.Println(indexName, query)
|
||||
var reqBytes = []byte(query)
|
||||
resp, err := client.SearchWithRawQueryDSL(indexName, reqBytes)
|
||||
|
|
|
@ -60,6 +60,15 @@ export default {
|
|||
'form.publicUsers.option.A': 'Colleague A',
|
||||
'form.publicUsers.option.B': 'Colleague B',
|
||||
'form.publicUsers.option.C': 'Colleague C',
|
||||
'form.button.search': 'Search',
|
||||
'form.button.new': 'New',
|
||||
'form.button.edit': 'Edit',
|
||||
'form.button.delete': 'Delete',
|
||||
'form.button.cancel': 'Cancel',
|
||||
'form.button.collapse': 'Collapse',
|
||||
'form.button.advanced': 'Advanced',
|
||||
'table.field.operation': 'Operation',
|
||||
|
||||
'component.globalHeader.search': 'Search',
|
||||
'component.globalHeader.search.example1': 'Search example 1',
|
||||
'component.globalHeader.search.example2': 'Search example 2',
|
||||
|
@ -89,6 +98,7 @@ export default {
|
|||
'menu.data.snapshot': 'SNAPSHOT',
|
||||
'menu.data.rebuild': 'REBUILD',
|
||||
'menu.data.export': 'IMPORT&EXPORT',
|
||||
'menu.data.query': 'DOCUMENT',
|
||||
|
||||
'menu.search': 'SEARCH',
|
||||
'menu.search.template': 'TEMPLATE',
|
||||
|
|
|
@ -66,6 +66,15 @@ export default {
|
|||
'form.logstash.jdbcconf.placeholder':"请输入JDBC配置",
|
||||
'form.logstash.kafkaconf.label':"Logstash Kafka 配置",
|
||||
'form.logstash.kafkaconf.placeholder':"请输入Kafka配置",
|
||||
'form.button.search': '搜索',
|
||||
'form.button.new': '新建',
|
||||
'form.button.edit': '编辑',
|
||||
'form.button.delete': '删除',
|
||||
'form.button.cancel': '取消',
|
||||
'form.button.collapse': '收起',
|
||||
'form.button.advanced': '高级',
|
||||
'table.field.operation': '操作',
|
||||
|
||||
'component.globalHeader.search': '站内搜索',
|
||||
'component.globalHeader.search.example1': '搜索提示一',
|
||||
'component.globalHeader.search.example2': '搜索提示二',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import React, { Component, createRef } from 'react';
|
||||
import React from 'react';
|
||||
import { formatMessage, FormattedMessage } from 'umi/locale';
|
||||
import router from 'umi/router';
|
||||
import { connect } from 'dva';
|
||||
import { Col, Form, Row,Select, Input, Card,Icon, Table, InputNumber, Popconfirm,
|
||||
|
@ -120,7 +121,7 @@ class EditableCell extends React.Component {
|
|||
let initialValue = '';
|
||||
if(editing){
|
||||
if(type=='date'){
|
||||
initialValue = moment(record[dataIndex]);
|
||||
initialValue = record[dataIndex] && moment(record[dataIndex]);
|
||||
}else{
|
||||
initialValue = record[dataIndex];
|
||||
}
|
||||
|
@ -169,21 +170,21 @@ class EditableCell extends React.Component {
|
|||
onClick={() => this.save(form, record.id)}
|
||||
style={{ marginRight: 8 }}
|
||||
>
|
||||
Save
|
||||
{formatMessage({id:'form.save'})}
|
||||
</a>
|
||||
)}
|
||||
</EditableContext.Consumer>
|
||||
<Popconfirm title="Sure to cancel?" onConfirm={() => this.cancel(record.id)}>
|
||||
<a>Cancel</a>
|
||||
<a>{formatMessage({id:'form.button.cancel'})}</a>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
) : (<div>
|
||||
<a disabled={editingKey !== ''} onClick={() => this.edit(record)}>
|
||||
Edit
|
||||
{formatMessage({id:'form.button.edit'})}
|
||||
</a>
|
||||
<Divider type="vertical"/>
|
||||
<Popconfirm title="Sure to delete?" onConfirm={() => this.delete(record)}>
|
||||
<a>Delete</a>
|
||||
<a>{formatMessage({id:'form.button.delete'})}</a>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
);
|
||||
|
@ -268,58 +269,67 @@ class EditableCell extends React.Component {
|
|||
}
|
||||
});
|
||||
}
|
||||
handlePageChange = (pageIndex)=>{
|
||||
|
||||
handleTableChange = (pagination, filters, sorter) =>{
|
||||
//console.log(pagination, filters, sorter);
|
||||
|
||||
const {fetchData, doclist} = this.props;
|
||||
fetchData({
|
||||
pageIndex: pageIndex,
|
||||
pageSize: doclist.pageSize,
|
||||
pageIndex: pagination.current,
|
||||
pageSize: pagination.pageSize,
|
||||
index: doclist.index,
|
||||
cluster: doclist.cluster,
|
||||
filter: doclist.filter,
|
||||
sort: (sorter.order && sorter.field) || '',
|
||||
sort_direction: sorter.order == 'ascend' ? 'asc' : 'desc'
|
||||
})
|
||||
}
|
||||
|
||||
isSortable = (type) => {
|
||||
return ['keyword', 'date', 'long', 'integer', 'short', 'byte', 'double', 'float', 'scaled_float'].includes(type)
|
||||
}
|
||||
|
||||
onShowSizeChange = (current, pageSize)=> {
|
||||
const {fetchData, doclist} = this.props;
|
||||
fetchData({
|
||||
pageIndex: current,
|
||||
pageSize: pageSize,
|
||||
index: doclist.index,
|
||||
cluster: doclist.cluster,
|
||||
filter: doclist.filter,
|
||||
})
|
||||
//console.log(current, pageSize);
|
||||
}
|
||||
|
||||
render() {
|
||||
let {doclist} = this.props;
|
||||
let columns = [];
|
||||
if(doclist.data && doclist.data.length > 0 ){
|
||||
for(let key in doclist.data[0]){
|
||||
if(["_index"].includes(key)){
|
||||
continue;
|
||||
}
|
||||
let col = {
|
||||
title: key,
|
||||
dataIndex: key,
|
||||
ellipsis: true,
|
||||
render: (text)=>(<Tooltip placement="top" title={text}>{text}</Tooltip>),
|
||||
onCell: record => ({
|
||||
record,
|
||||
dataIndex: key,
|
||||
title: key,
|
||||
editing: this.isEditing(record),
|
||||
type: this.getFieldType(record, key),
|
||||
// onMouseEnter: event => {console.log(event)},
|
||||
// onMouseLeave: event => {},
|
||||
}),
|
||||
}
|
||||
if(["id"].includes(key)){
|
||||
col.onCell = "";
|
||||
}
|
||||
columns.push(col)
|
||||
let keys = [];
|
||||
let sortObj = {};
|
||||
if(doclist.mappings){
|
||||
for(let mkey in doclist.mappings){
|
||||
Object.keys(doclist.mappings[mkey].mappings.properties).forEach(key=>{
|
||||
if(!keys.includes(key)){
|
||||
keys.push(key);
|
||||
sortObj[key] = this.isSortable(doclist.mappings[mkey].mappings.properties[key].type);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
for(let key of keys){
|
||||
if(["_index"].includes(key)){
|
||||
continue;
|
||||
}
|
||||
let col = {
|
||||
title: key,
|
||||
dataIndex: key,
|
||||
ellipsis: true,
|
||||
sorter: sortObj[key],
|
||||
render: (text)=>(<Tooltip placement="top" title={text}>{text}</Tooltip>),
|
||||
onCell: record => ({
|
||||
record,
|
||||
dataIndex: key,
|
||||
title: key,
|
||||
editing: this.isEditing(record),
|
||||
type: this.getFieldType(record, key),
|
||||
// onMouseEnter: event => {console.log(event)},
|
||||
// onMouseLeave: event => {},
|
||||
}),
|
||||
}
|
||||
if(["id"].includes(key)){
|
||||
col.onCell = "";
|
||||
}
|
||||
columns.push(col)
|
||||
}
|
||||
|
||||
columns.push(this.operField);
|
||||
//console.log(columns);
|
||||
|
||||
|
@ -334,19 +344,17 @@ class EditableCell extends React.Component {
|
|||
components={components}
|
||||
bordered
|
||||
rowKey="id"
|
||||
onChange={this.handleTableChange}
|
||||
size="small"
|
||||
loading={doclist.isLoading}
|
||||
dataSource={doclist.data}
|
||||
columns={columns}
|
||||
rowClassName="editable-row"
|
||||
pagination={{
|
||||
onChange: this.cancel,
|
||||
showSizeChanger: true,
|
||||
onShowSizeChange: this.onShowSizeChange,
|
||||
total: doclist.total? doclist.total.value: 0,
|
||||
pageSize: doclist.pageSize,
|
||||
current: doclist.pageIndex,
|
||||
onChange: this.handlePageChange,
|
||||
showTotal: (total, range) => `Total ${total} items`,
|
||||
size: 'small',
|
||||
}}
|
||||
|
@ -470,10 +478,15 @@ class Doucment extends React.Component {
|
|||
_index = vals[0];
|
||||
}
|
||||
}
|
||||
let keys = Object.keys(mappings[_index].mappings.properties)
|
||||
let properties = mappings[_index].mappings.properties;
|
||||
let keys = Object.keys(properties)
|
||||
let newDoc = {id:"", _index};
|
||||
for(let key of keys){
|
||||
newDoc[key] = ""
|
||||
if(properties[key].type == 'date'){
|
||||
newDoc[key] = null
|
||||
}else{
|
||||
newDoc[key] = ""
|
||||
}
|
||||
}
|
||||
dispatch({
|
||||
type: 'document/_addNew',
|
||||
|
@ -528,7 +541,7 @@ class Doucment extends React.Component {
|
|||
return (<Select.Option key={item} label={item}>{item}</Select.Option>)
|
||||
})}
|
||||
</Select>) : ''}
|
||||
<Button type="primary" icon="plus" onClick={this.handleNewClick}>新建</Button>
|
||||
<Button type="primary" icon="plus" onClick={this.handleNewClick}>{formatMessage({ id: 'form.button.new' })}</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -566,7 +579,7 @@ class Doucment extends React.Component {
|
|||
placeholder="input search keyword"
|
||||
disabled = {this.state.bodyDisplay != 'none'}
|
||||
/>
|
||||
<Button type="primary" onClick={this.handleSearchClick}>execute</Button>
|
||||
<Button type="primary" onClick={this.handleSearchClick}>{formatMessage({ id: 'form.button.search' })}</Button>
|
||||
</Input.Group>
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
|
@ -582,7 +595,7 @@ class Doucment extends React.Component {
|
|||
};
|
||||
}
|
||||
});
|
||||
}}>{this.state.bodyDisplay == 'none' ? '高级':'收起'}<Icon type="down" /></a>
|
||||
}}>{this.state.bodyDisplay == 'none' ? formatMessage({id:'form.button.advanced'}): formatMessage({id:'form.button.collapse'})}<Icon type="down" /></a>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{display: this.state.bodyDisplay}} gutter={[16, { xs: 8, sm: 16, md: 24, lg: 32 }]}>
|
||||
|
@ -606,15 +619,16 @@ class Doucment extends React.Component {
|
|||
<Col span={8}>
|
||||
<div style={{fontSize: 12, paddingLeft: 20}}>
|
||||
<div style={{fontSize: 16, paddingBottom: 10, color: '#1890FF'}}>query example:</div>
|
||||
<code dangerouslySetInnerHTML={{ __html: `{<br/> "bool":{<br/>
|
||||
"must": {<br/>
|
||||
"match":{ <br/>
|
||||
"FIELD": "VALUE"<br/>
|
||||
}<br/>
|
||||
}<br/>
|
||||
}<br/>}` }}>
|
||||
|
||||
</code>
|
||||
<div style={{background:'rgb(245, 247, 250)', padding: 10}}>
|
||||
<code dangerouslySetInnerHTML={{ __html: `{<br/> "bool":{<br/>
|
||||
"must": {<br/>
|
||||
"match":{ <br/>
|
||||
"FIELD": "VALUE"<br/>
|
||||
}<br/>
|
||||
}<br/>
|
||||
}<br/>}` }}>
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
|
|
|
@ -46,6 +46,12 @@ export default {
|
|||
let res = yield call(getDocList, payload);
|
||||
if(res.errno != "0"){
|
||||
message.warn("加载数据失败")
|
||||
yield put({
|
||||
type: 'saveData',
|
||||
payload:{
|
||||
isLoading: false,
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
let indices = Object.keys(res.payload.mappings); //indices state can remove
|
||||
|
|
|
@ -94,10 +94,10 @@ class Pro extends React.Component {
|
|||
form.validateFields((err, fieldsValue) => {
|
||||
if (err) return;
|
||||
me.fetchData({
|
||||
form: 0,
|
||||
from: 0,
|
||||
size: me.props.dict.search.size,
|
||||
name: fieldsValue.name,
|
||||
tags: fieldsValue.tags.join(',')
|
||||
tags: fieldsValue.tags && fieldsValue.tags.join(',')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue