From 7adb54781685f2e3831905074d38df0f92e3f791 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=A1clav=20Barto=C5=A1?= <bartos@cesnet.cz>
Date: Mon, 4 May 2020 15:49:46 +0200
Subject: [PATCH] TheHiveButton: Options editing (URL, API key) now works

---
 thehive_button/public/case_form.html        | 11 -----
 thehive_button/public/main.js               | 51 ++++++++++++++++-----
 thehive_button/public/options_template.html | 11 +++--
 3 files changed, 45 insertions(+), 28 deletions(-)
 delete mode 100644 thehive_button/public/case_form.html

diff --git a/thehive_button/public/case_form.html b/thehive_button/public/case_form.html
deleted file mode 100644
index fe45cbc..0000000
--- a/thehive_button/public/case_form.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<form>
-<label for="case-title">Title:</label><br>
-<input type="text" name="case-title" style="width: 100%" value="" required="true"><br>
-<br>
-<label for="case-title">Description:</label><br>
-<textarea name="case-descr" rows="10" style="width: 100%">
-
---
-Created from Kibana
-</textarea>
-</form>
\ No newline at end of file
diff --git a/thehive_button/public/main.js b/thehive_button/public/main.js
index 1361795..747846c 100644
--- a/thehive_button/public/main.js
+++ b/thehive_button/public/main.js
@@ -1,5 +1,4 @@
 //import './vis.less';
-//import optionsTemplate from './options_template.html';
 import { THEHIVE_API_KEY, THEHIVE_URL, THEHIVE_OWNER } from './env';
 //import { VisController } from './vis_controller';
 import { TheHiveButtonVisComponent } from './vis_controller';
@@ -7,7 +6,40 @@ import { TheHiveButtonVisComponent } from './vis_controller';
 import { VisFactoryProvider } from 'ui/vis/vis_factory';
 import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
 import { Schemas } from 'ui/vis/editors/default/schemas';
-import { Status } from 'ui/vis/update_status';
+//import { Status } from 'ui/vis/update_status';
+import { DefaultEditorSize } from 'ui/vis/editor_size';
+
+import optionsTemplate from './options_template.html';
+
+/*
+TODO: It would be better to compose options tab of EUI React elements,
+but this probably needs at least kibana 7.4.
+See this for example of a custom editor:
+  https://github.com/elastic/kibana/tree/master/src/plugins/vis_type_markdown/public 
+
+import React from 'react';
+import {
+  EuiForm,
+  EuiFormRow,
+  EuiFieldText,
+} from '@elastic/eui';
+
+import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
+
+const optionsTemplate = (
+  <EuiForm>
+    <EuiFormRow label="Base URL of The Hive">
+      <EuiFieldText value={editorState.params.url} />
+    </EuiFormRow>
+    <EuiFormRow label="API key">
+      <EuiFieldText value={editorState.params.apikey} />
+    </EuiFormRow>
+    <EuiFormRow label="Username" helpText="Used as the owner of cases created from here">
+      <EuiFieldText value={editorState.params.owner} />
+    </EuiFormRow>
+  </EuiForm>
+);
+*/
 
 function TheHiveButtonVisProvider(Private) {
   const VisFactory = Private(VisFactoryProvider);
@@ -33,14 +65,9 @@ function TheHiveButtonVisProvider(Private) {
     editor: 'default',
 //    editor: MyEditorController,
     editorConfig: {
-      /*collections: { 
-        colorSchemas: [
-          {id: "test1", label: "Test 1"},
-          {id: "test2", label: "Test 2"},
-        ],
-      },*/
-      optionsTemplate: '<div>TEST</div>',
-//      optionsTemplate: '<thehivebutton-vis-params></thehivebutton-vis-params>',
+      optionsTemplate: optionsTemplate,
+      defaultSize: DefaultEditorSize.MEDIUM,
+      //enableAutoApply: true,
       schemas: new Schemas([
         // TODO all this (metric and bucket "terms") could be pre-defind
         // (just a selection of fields to read Observables from would be nice)
@@ -58,7 +85,7 @@ function TheHiveButtonVisProvider(Private) {
         {
           group: 'metrics',
           name: 'metric',
-          title: "Metric (not used)",
+          title: "Metric (not used, ignore this)",
           min: 1,
           max: 1,
           aggFilter: 'count',
@@ -75,7 +102,7 @@ function TheHiveButtonVisProvider(Private) {
           title: 'Observables',
           min: 1,
           max: 1,
-          aggFilter: 'terms',//['!geohash_grid', '!geotile_grid', '!filter'],
+          aggFilter: ['terms'],
 //           defaults: [
 //             {
 //               type: 'terms',
diff --git a/thehive_button/public/options_template.html b/thehive_button/public/options_template.html
index 5ec603b..ef99657 100644
--- a/thehive_button/public/options_template.html
+++ b/thehive_button/public/options_template.html
@@ -1,7 +1,8 @@
 <div class="form-group">
-  <p style="margin-bottom: 1em">The plugin is currently not configurable from here. Below are the predefined configuration values. They can be edited in "<tt>&lt;KIBANA_PATH&gt;/plugins/thehive_button/public/env.js</tt>" on the backend.</p>
-  <label>The Hive API URL</label>
-  <input ng-model=vis.params.url class=form-control disabled=disabled />
-  <label>The Hive API key</label>
-  <input ng-model=vis.params.apikey class=form-control disabled=disabled />
+  <p><label>Base URL of The Hive</label>
+  <input ng-model="editorState.params.url" class=form-control /></p>
+  <p><label>API key</label>
+  <input ng-model="editorState.params.apikey" class=form-control /></p>
+  <p><label>User name to use as the owner of cases created from here</label>
+  <input ng-model="editorState.params.owner" class=form-control /></p>
 </div>
-- 
GitLab