From e1ad5515a11cabbf067aa5eea5dae77044944790 Mon Sep 17 00:00:00 2001 From: silenceqi Date: Wed, 20 Jan 2021 23:36:00 +0800 Subject: [PATCH] modify index management --- api/index_management/indices.go | 29 +++ api/init.go | 1 + web/src/pages/DataManagement/Document.js | 3 + web/src/pages/DataManagement/Index.js | 253 +++++++------------ web/src/pages/DataManagement/models/index.js | 14 +- web/src/services/indices.js | 9 + 6 files changed, 148 insertions(+), 161 deletions(-) diff --git a/api/index_management/indices.go b/api/index_management/indices.go index 73e9d604..50970447 100644 --- a/api/index_management/indices.go +++ b/api/index_management/indices.go @@ -1,6 +1,7 @@ package index_management import ( + "fmt" "net/http" "strings" @@ -107,4 +108,32 @@ func (handler APIHandler) HandleDeleteIndexAction(w http.ResponseWriter, req *ht } resBody["payload"] = true handler.WriteJSON(w, resBody, http.StatusOK) +} + +func (handler APIHandler) HandleCreateIndexAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { + defer func() { + if err := recover(); err != nil { + fmt.Println(err) + } + }() + client := elastic.GetClient(handler.Config.Elasticsearch) + indexName := ps.ByName("index") + resBody := newResponseBody() + config := map[string]interface{}{} + err := handler.DecodeJSON(req, &config) + if err != nil { + resBody["status"] = false + resBody["error"] = err + handler.WriteJSON(w, resBody, http.StatusOK) + return + } + err = client.CreateIndex(indexName, config) + if err != nil { + resBody["status"] = false + resBody["error"] = err + handler.WriteJSON(w, resBody, http.StatusOK) + return + } + resBody["payload"] = true + handler.WriteJSON(w, resBody, http.StatusOK) } \ No newline at end of file diff --git a/api/init.go b/api/init.go index 9a15b7f0..7e489256 100644 --- a/api/init.go +++ b/api/init.go @@ -34,6 +34,7 @@ func Init(cfg *config.AppConfig) { ui.HandleUIMethod(api.GET, pathPrefix+"index/:index/_settings", handler.HandleGetSettingsAction) ui.HandleUIMethod(api.PUT, pathPrefix+"index/:index/_settings", handler.HandleUpdateSettingsAction) ui.HandleUIMethod(api.DELETE, pathPrefix+"index/:index", handler.HandleDeleteIndexAction) + ui.HandleUIMethod(api.POST, pathPrefix+"index/:index", handler.HandleCreateIndexAction) task.RegisterScheduleTask(task.ScheduleTask{ Description: "sync reindex task result to index infinireindex", diff --git a/web/src/pages/DataManagement/Document.js b/web/src/pages/DataManagement/Document.js index 8ed73cad..6a9f4e6a 100644 --- a/web/src/pages/DataManagement/Document.js +++ b/web/src/pages/DataManagement/Document.js @@ -426,6 +426,9 @@ class Doucment extends React.Component { return; } let {indices, mappings} = document; + if(!indices){ + return + } let _index = indices[0]; if(indices && indices.length > 1){ //console.log(this.indexSelEl); diff --git a/web/src/pages/DataManagement/Index.js b/web/src/pages/DataManagement/Index.js index 761b674c..1a5ee556 100644 --- a/web/src/pages/DataManagement/Index.js +++ b/web/src/pages/DataManagement/Index.js @@ -55,82 +55,56 @@ class JSONWrapper extends PureComponent { ) } } - -const CreateForm = Form.create()(props => { - const { modalVisible, form, handleAdd, handleModalVisible } = props; - const okHandle = () => { +@Form.create() +class CreateForm extends React.Component { + okHandle = () => { + const {handleAdd, form} = this.props; form.validateFields((err, fieldsValue) => { if (err) return; form.resetFields(); + fieldsValue['config'] = this.editorValueGetter(); handleAdd(fieldsValue); }); }; - return ( - handleModalVisible()} - > - - {form.getFieldDecorator('index', { - rules: [{ required: true, message: '请输入至少五个字符的名称!', min: 5 }], - })()} - - - {form.getFieldDecorator('settings', { - rules: [{ required: true }], - })(