-import { getJSON, postJSON } from '../helpers/request';
+import { getJSON, post } from '../helpers/request';
export function setLogLevel (level) {
let url = window.baseUrl + '/api/system/change_log_level';
let data = { level };
- return postJSON(url, data);
+ return post(url, data);
}
export function getSystemInfo () {
const LOG_LEVELS = ['INFO', 'DEBUG', 'TRACE'];
export default React.createClass({
+ getInitialState () {
+ return { level: this.props.value };
+ },
+
onChange() {
let newValue = React.findDOMNode(this.refs.select).value;
- setLogLevel(newValue);
+ setLogLevel(newValue).then(() => {
+ this.setState({ level: newValue });
+ });
},
render() {
let options = LOG_LEVELS.map(level => {
return <option key={level} value={level}>{level}</option>;
});
- return <select ref="select"
- onChange={this.onChange}
- defaultValue={this.props.value}>{options}</select>;
+ let warning = this.state.level !== 'INFO' ? (
+ <div className="alert alert-danger spacer-top" style={{ wordBreak: 'normal' }}>
+ {window.t('system.log_level.warning')}
+ </div>
+ ) : null;
+ return <div>
+ <select ref="select"
+ onChange={this.onChange}
+ value={this.state.level}>{options}</select>
+ {warning}
+ </div>
}
});
.then(checkStatus)
.then(parseJSON);
}
+
+
+/**
+ * Shortcut to do a POST request and return response json
+ * @param url
+ * @param data
+ */
+export function post (url, data) {
+ return request(url)
+ .setMethod('POST')
+ .setData(data)
+ .submit()
+ .then(checkStatus);
+}
</a>
<ul className="dropdown-menu">
{this.renderLink('/updatecenter', window.t('update_center.page'))}
- {this.renderLink('/system/index', window.t('system_info.page'))}
- {this.renderNewLink('/system/new', window.t('system_info.page'))}
+ {this.renderLink('/system', window.t('system_info.page'))}
</ul>
</li>
</ul>
end
- def new
-
- end
-
end
+++ /dev/null
-<% content_for :extra_script do %>
- <script src="<%= ApplicationController.root_context -%>/js/bundles/system.js?v=<%= sonar_version -%>"></script>
-<% end %>
-
expect(select.value).to.equal('DEBUG');
});
+ it('should render warning', () => {
+ let result = TestUtils.renderIntoDocument(<ItemValue value="DEBUG" name="Logs Level"/>);
+ TestUtils.findRenderedDOMComponentWithClass(result, 'alert');
+ });
+
+ it('should not render warning', () => {
+ let result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
+ expect(TestUtils.scryRenderedDOMComponentsWithClass(result, 'alert')).to.be.empty;
+ });
+
it('should change value', () => {
let result = TestUtils.renderIntoDocument(<ItemValue value="INFO" name="Logs Level"/>);
let select = React.findDOMNode(TestUtils.findRenderedDOMComponentWithTag(result, 'select'));