Skip to content

Commit c2e84a8

Browse files
authored
Merge pull request #22 from billmurrin/Issue9-qvp-default-global-configuration
Initial global defaults configuration
2 parents 0c2d5fd + 3fe67c0 commit c2e84a8

File tree

6 files changed

+237
-8
lines changed

6 files changed

+237
-8
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
<version>${graylog.version}</version>
8686
<scope>provided</scope>
8787
</dependency>
88+
<dependency>
89+
<groupId>com.google.auto.value</groupId>
90+
<artifactId>auto-value</artifactId>
91+
<version>1.4.1</version>
92+
<scope>provided</scope>
93+
</dependency>
8894
</dependencies>
8995

9096
<build>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.graylog.plugins.quickvaluesplus;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
import com.fasterxml.jackson.annotation.JsonCreator;
5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.google.auto.value.AutoValue;
8+
9+
@JsonAutoDetect
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
@AutoValue
12+
public abstract class QuickValuesPlusPluginConfiguration {
13+
14+
@JsonProperty("table_size")
15+
public abstract Number tableSize();
16+
17+
@JsonProperty("top_values")
18+
public abstract Number topValues();
19+
20+
@JsonProperty("sort_order")
21+
public abstract String sortOrder();
22+
23+
@JsonCreator
24+
public static QuickValuesPlusPluginConfiguration create(@JsonProperty("table_size") Number tableSize,
25+
@JsonProperty("top_values") Number topValues,
26+
@JsonProperty("sort_order") String sortOrder) {
27+
return builder()
28+
.tableSize(tableSize)
29+
.topValues(topValues)
30+
.sortOrder(sortOrder)
31+
.build();
32+
}
33+
34+
public static Builder builder() {
35+
return new AutoValue_QuickValuesPlusPluginConfiguration.Builder();
36+
}
37+
38+
@AutoValue.Builder
39+
public static abstract class Builder {
40+
public abstract Builder tableSize(Number tableSize);
41+
42+
public abstract Builder topValues(Number topValues);
43+
44+
public abstract Builder sortOrder(String sortOrder);
45+
46+
public abstract QuickValuesPlusPluginConfiguration build();
47+
}
48+
49+
}

src/main/java/org/graylog/plugins/quickvaluesplus/QuickValuesPlusWidgetModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
package org.graylog.plugins.quickvaluesplus;
22

33
import org.graylog2.plugin.PluginModule;
4+
import org.graylog2.plugin.PluginConfigBean;
45
import org.graylog.plugins.quickvaluesplus.widget.strategy.QuickValuesPlusWidgetStrategy;
56

7+
import java.util.Collections;
8+
import java.util.Set;
9+
610
/**
711
* Extend the PluginModule abstract class here to add you plugin to the system.
812
*/
913
public class QuickValuesPlusWidgetModule extends PluginModule {
14+
15+
@Override
16+
public Set<? extends PluginConfigBean> getConfigBeans() {
17+
return Collections.emptySet();
18+
}
19+
1020
@Override
1121
protected void configure() {
1222
addWidgetStrategy(QuickValuesPlusWidgetStrategy.class, QuickValuesPlusWidgetStrategy.Factory.class);

src/web/components/FieldQuickValuesPlus.jsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import StringUtils from 'util/StringUtils';
1010
import UIUtils from 'util/UIUtils';
1111
import StoreProvider from 'injection/StoreProvider';
1212
import { QuickValuesPlusActions, QuickValuesPlusStore } from 'stores/QuickValuesPlusStore';
13+
const ConfigurationsStore = StoreProvider.getStore('Configurations');
14+
import ActionsProvider from 'injection/ActionsProvider';
15+
const ConfigurationActions = ActionsProvider.getActions('Configuration');
1316

1417
import style from '!style/useable!css!./FieldQuickValuesPlus.css';
1518

@@ -22,14 +25,15 @@ const FieldQuickValuesPlus = React.createClass({
2225
},
2326
mixins: [
2427
Reflux.connect(QuickValuesPlusStore),
25-
Reflux.listenTo(RefreshStore, '_setupTimer', '_setupTimer')
28+
Reflux.listenTo(RefreshStore, '_setupTimer', '_setupTimer'),
29+
Reflux.connect(ConfigurationsStore)
2630
],
2731
getInitialState() {
2832
return {
2933
field: undefined,
3034
dropdownIsOpen: false,
3135
data: [],
32-
quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 50, show_pie_chart: true, show_data_table: true}
36+
quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}
3337
};
3438
},
3539
style: style,
@@ -38,9 +42,10 @@ const FieldQuickValuesPlus = React.createClass({
3842
},
3943
componentWillMount() {
4044
this.setState({ dropdownIsOpen: false });
41-
this.setState({quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 50, show_pie_chart: true, show_data_table: true}});
45+
this.setState({quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}});
4246
},
4347
componentDidMount() {
48+
ConfigurationActions.list("org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration");
4449
this.style.use();
4550
this._loadQuickValuesData();
4651
},
@@ -84,10 +89,14 @@ const FieldQuickValuesPlus = React.createClass({
8489
this.setState({field: field}, () => this._loadQuickValuesData(false));
8590
},
8691
_loadQuickValuesData() {
87-
if (this.state.field !== undefined) {
88-
this.setState({loadPending: true});
89-
const promise = QuickValuesPlusActions.getQuickValues(this.state.field, 50, "descending");
90-
promise.then((data) => this.setState({data: data, loadPending: false}));
92+
if (this.state.configuration !== undefined) {
93+
this.setState({quickValuesOptions: {top_values: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].top_values, sort_order: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order, table_size: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size, show_pie_chart: true, show_data_table: true}});
94+
95+
if (this.state.field !== undefined) {
96+
this.setState({loadPending: true});
97+
const promise = QuickValuesPlusActions.getQuickValues(this.state.field, this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size, this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order);
98+
promise.then((data) => this.setState({data: data, loadPending: false}));
99+
}
91100
}
92101
},
93102
_resetStatus() {
@@ -126,7 +135,6 @@ const FieldQuickValuesPlus = React.createClass({
126135
render() {
127136
let content;
128137
let inner;
129-
let myvalue;
130138

131139
const submenus = [
132140
<li key="sort_order-submenu" className="dropdown-submenu left-submenu">
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import React from 'react';
2+
import { Input } from 'components/bootstrap';
3+
import { Button } from 'react-bootstrap';
4+
import BootstrapModalForm from 'components/bootstrap/BootstrapModalForm';
5+
import { IfPermitted, Select } from 'components/common';
6+
import ObjectUtils from 'util/ObjectUtils';
7+
8+
const QuickValuesPlusDefaultConfig = React.createClass({
9+
propTypes: {
10+
config: React.PropTypes.object,
11+
updateConfig: React.PropTypes.func.isRequired,
12+
},
13+
14+
getDefaultProps() {
15+
return {
16+
config: {
17+
sort_order: "descending",
18+
table_size: 50,
19+
top_values: 5,
20+
},
21+
};
22+
},
23+
24+
getInitialState() {
25+
return {
26+
config: ObjectUtils.clone(this.props.config),
27+
};
28+
},
29+
30+
componentWillReceiveProps(newProps) {
31+
this.setState({config: ObjectUtils.clone(newProps.config)});
32+
},
33+
34+
_updateConfigField(field, value) {
35+
const update = ObjectUtils.clone(this.state.config);
36+
update[field] = value;
37+
this.setState({config: update});
38+
},
39+
40+
_onCheckboxClick(field, ref) {
41+
return () => {
42+
this._updateConfigField(field, this.refs[ref].getChecked());
43+
};
44+
},
45+
46+
_onSelect(field) {
47+
return (selection) => {
48+
this._updateConfigField(field, selection);
49+
};
50+
},
51+
52+
_onUpdate(field) {
53+
return (e) => {
54+
this._updateConfigField(field, e.target.value);
55+
};
56+
},
57+
58+
_openModal() {
59+
this.refs.quickvaluesplusConfigModal.open();
60+
},
61+
62+
_closeModal() {
63+
this.refs.quickvaluesplusConfigModal.close();
64+
},
65+
66+
_resetConfig() {
67+
// Reset to initial state when the modal is closed without saving.
68+
this.setState(this.getInitialState());
69+
},
70+
71+
_saveConfig() {
72+
this.props.updateConfig(this.state.config).then(() => {
73+
this._closeModal();
74+
});
75+
},
76+
77+
render() {
78+
return (
79+
<div>
80+
<h3>Quick Values Plus Configuration</h3>
81+
82+
<p>
83+
Defaults Configuration for the Quick Values Plus Field Analyzer and Widget
84+
</p>
85+
86+
<dl className="deflist">
87+
<dt>Default Table Size</dt>
88+
<dd>{this.state.config.table_size}</dd>
89+
90+
<dt>Default Top Values</dt>
91+
<dd>{this.state.config.top_values}</dd>
92+
93+
<dt>Default Sort Order</dt>
94+
<dd>{this.state.config.sort_order === "descending" ? 'Descending' : 'Ascending'}</dd>
95+
</dl>
96+
97+
<IfPermitted permissions="clusterconfigentry:edit">
98+
<Button bsStyle="info" bsSize="xs" onClick={this._openModal}>Configure</Button>
99+
</IfPermitted>
100+
101+
<BootstrapModalForm ref="quickvaluesplusConfigModal"
102+
title="Update Quick Values Plus plugin Configuration"
103+
onSubmitForm={this._saveConfig}
104+
onModalClose={this._resetConfig}
105+
submitButtonText="Save">
106+
<fieldset>
107+
<Input key="dataTopValues"
108+
type="text"
109+
id="quickvaluesplus-top-values"
110+
name="top_values"
111+
label="Number of Top Values"
112+
value={this.state.config.top_values}
113+
onChange={this._onUpdate('top_values')}
114+
help="Modify the number of results that are considered Top Values in the table."/>
115+
116+
<Input key="dataTableSize"
117+
type="text"
118+
id="quickvaluesplus-tables-size"
119+
name="table_size"
120+
label="Size of Table"
121+
value={this.state.config.table_size}
122+
onChange={this._onUpdate('table_size')}
123+
help="Modify the number of results in the table."/>
124+
125+
<label for="quickvaluesplus-sort-order-descending" class="control-label"><span>Sort Order</span></label>
126+
<div className="radio">
127+
<label>
128+
<input key="dataSortOrderDesc" id="quickvaluesplus-sort-order-descending" type="radio" name="sort_order" value="descending"
129+
onChange={this._onUpdate('sort_order')}
130+
checked={this.state.config.sort_order === "descending"} />
131+
Descending
132+
</label>
133+
</div>
134+
<div className="radio">
135+
<label>
136+
<input key="dataSortOrderAsc" id="quickvaluesplus-sort-order-ascending" type="radio" name="sort_order" value="ascending"
137+
onChange={this._onUpdate('sort_order')}
138+
checked={this.state.config.sort_order === "ascending"} />
139+
Ascending
140+
</label>
141+
</div>
142+
</fieldset>
143+
</BootstrapModalForm>
144+
</div>
145+
);
146+
},
147+
});
148+
149+
export default QuickValuesPlusDefaultConfig;

src/web/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import QuickValuesPlusVisualization from 'components/QuickValuesPlusVisualizatio
77
import FieldQuickValuesPlus from 'components/FieldQuickValuesPlus';
88
import QuickValuesPlusWidgetCreateConfiguration from 'components/QuickValuesPlusWidgetCreateConfiguration';
99
import QuickValuesPlusWidgetEditConfiguration from 'components/QuickValuesPlusWidgetEditConfiguration'
10+
import QuickValuesPlusDefaultConfig from 'components/QuickValuesPlusDefaultConfig';
1011

1112
PluginStore.register(new PluginManifest(packageJson, {
1213
widgets: [
@@ -28,4 +29,10 @@ PluginStore.register(new PluginManifest(packageJson, {
2829
displayPriority: 10,
2930
},
3031
],
32+
systemConfigurations: [
33+
{
34+
component: QuickValuesPlusDefaultConfig,
35+
configType: 'org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration',
36+
},
37+
],
3138
}));

0 commit comments

Comments
 (0)