Skip to content

Commit

Permalink
Adding switcher to define matching type for stream. Updating results.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Aug 14, 2015
1 parent 0a14dda commit 38e41c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/api/StreamsApiController.java
Expand Up @@ -6,6 +6,7 @@
import controllers.AuthenticatedController; import controllers.AuthenticatedController;
import lib.json.Json; import lib.json.Json;
import models.descriptions.StreamDescription; import models.descriptions.StreamDescription;
import org.graylog2.rest.models.streams.requests.UpdateStreamRequest;
import org.graylog2.restclient.lib.APIException; import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.models.Stream; import org.graylog2.restclient.models.Stream;
import org.graylog2.restclient.models.StreamService; import org.graylog2.restclient.models.StreamService;
Expand Down Expand Up @@ -60,7 +61,7 @@ public Result resume(String streamId) throws APIException, IOException {


public Result update(String streamId) throws APIException, IOException { public Result update(String streamId) throws APIException, IOException {
final JsonNode json = request().body().asJson(); final JsonNode json = request().body().asJson();
final CreateStreamRequest request = Json.fromJson(json, CreateStreamRequest.class); final UpdateStreamRequest request = Json.fromJson(json, UpdateStreamRequest.class);


this.streamService.update(streamId, request); this.streamService.update(streamId, request);
return ok(); return ok();
Expand Down
6 changes: 4 additions & 2 deletions javascript/src/components/streamrules/StreamRulesEditor.jsx
Expand Up @@ -10,6 +10,7 @@ var StreamRulesStore = require('../../stores/streams/StreamRulesStore');
var Alert = require('react-bootstrap').Alert; var Alert = require('react-bootstrap').Alert;
var StreamRuleForm = require('./StreamRuleForm'); var StreamRuleForm = require('./StreamRuleForm');
var Spinner = require('../common/Spinner'); var Spinner = require('../common/Spinner');
var MatchingTypeSwitcher = require('../streams/MatchingTypeSwitcher');


var StreamRulesEditor = React.createClass({ var StreamRulesEditor = React.createClass({
getInitialState() { getInitialState() {
Expand Down Expand Up @@ -54,12 +55,12 @@ var StreamRulesEditor = React.createClass({
if (this.state.matchData.matches) { if (this.state.matchData.matches) {
return ( return (
<span> <span>
<i className="fa fa-check" style={{"color":"green"}}/> This message matches all rules and would be routed to this stream. <i className="fa fa-check" style={{"color":"green"}}/> This message would be routed to this stream.
</span>); </span>);
} else { } else {
return ( return (
<span> <span>
<i className="fa fa-remove" style={{"color":"red"}}/> This message does not match one or more of the rules and would not be routed to this stream. <i className="fa fa-remove" style={{"color":"red"}}/> This message would not be routed to this stream.
</span>); </span>);
} }
} else { } else {
Expand Down Expand Up @@ -105,6 +106,7 @@ var StreamRulesEditor = React.createClass({


{this._explainMatchResult()} {this._explainMatchResult()}


<MatchingTypeSwitcher stream={this.state.stream} onChange={this.loadData}/>
<Alert ref='well' bsStyle={styles}> <Alert ref='well' bsStyle={styles}>
<StreamRuleList stream={this.state.stream} streamRuleTypes={this.state.streamRuleTypes} <StreamRuleList stream={this.state.stream} streamRuleTypes={this.state.streamRuleTypes}
permissions={this.props.permissions} matchData={this.state.matchData}/> permissions={this.props.permissions} matchData={this.state.matchData}/>
Expand Down
35 changes: 35 additions & 0 deletions javascript/src/components/streams/MatchingTypeSwitcher.jsx
@@ -0,0 +1,35 @@
import React from 'react';
import { PropTypes, Component } from 'react';
import { Input } from 'react-bootstrap';
import StreamsStore from '../../stores/streams/StreamsStore';

class MatchingTypeSwitcher extends Component {
static propTypes = {
stream: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
}
render() {
const valueLink = {
value: this.props.stream.matching_type,
requestChange: this.handleTypeChange,
streamId: this.props.stream.id,
onChange: this.props.onChange,
};
return (
<div className="form-inline">
A message needs to match{' '}
<Input type="select" className="form-inline input-sm" valueLink={valueLink}>
<option value="AND">all rules</option>
<option value="OR">at least one rule</option>
</Input>
{' '}to be routed into this stream.{' '}
</div>
);
}

handleTypeChange(newValue) {
StreamsStore.update(this.streamId, { 'matching_type': newValue }, this.onChange);
}
}

export default MatchingTypeSwitcher;

0 comments on commit 38e41c5

Please sign in to comment.