ALL: '__ALL__',
ONLY_CURRENTS: 'CURRENTS'
};
+
+
+export const DATE = {
+ ANY: 'ANY',
+ TODAY: 'TODAY',
+ CUSTOM: 'CUSTOM'
+};
+
+
+export const DATE_FORMAT = 'YYYY-MM-DD';
import _ from 'underscore';
import React from 'react';
import {getQueue, getActivity, cancelTask, cancelAllTasks} from '../../api/ce';
-import {STATUSES, CURRENTS} from './constants';
+import {STATUSES, CURRENTS, DATE} from './constants';
import Header from './header';
import Stats from './stats';
import Search from './search';
activityTotal: 0,
activityPage: 1,
statusFilter: STATUSES.ALL,
- currentsFilter: CURRENTS.ALL
+ currentsFilter: CURRENTS.ALL,
+ dateFilter: DATE.ANY
};
},
filterQueueForComponent(queue) {
if (this.props.options.componentId) {
return queue.filter(task => {
- return task.componentId === this.props.options.componentId
+ return task.componentId === this.props.options.componentId;
});
} else {
return queue;
}
},
+ getDateFilter() {
+ const DATE_FORMAT = 'YYYY-MM-DD';
+ let filter = {};
+ switch (this.state.dateFilter) {
+ case DATE.TODAY:
+ filter.minSubmittedAt = moment().startOf('day').format(DATE_FORMAT);
+ break;
+ case DATE.CUSTOM:
+ if (this.state.minDate) {
+ filter.minSubmittedAt = moment(this.state.minDate).format(DATE_FORMAT);
+ }
+ if (this.state.maxDate) {
+ filter.maxFinishedAt = moment(this.state.maxDate).format(DATE_FORMAT);
+ }
+ break;
+ default:
+ // do nothing
+ }
+ return filter;
+ },
+
getCurrentFilters() {
let filters = {};
if (this.state.statusFilter !== STATUSES.ALL) {
if (this.state.currentsFilter !== STATUSES.ALL) {
filters.onlyCurrents = true;
}
+ if (this.state.dateFilter !== DATE.ANY) {
+ _.extend(filters, this.getDateFilter());
+ }
return filters;
},
this.setState({ currentsFilter: newCurrents, activityPage: 1 }, this.requestData);
},
+ onDateChange(newDate, minDate, maxDate) {
+ this.setState({
+ dateFilter: newDate,
+ minDate: minDate,
+ maxDate: maxDate,
+ activityPage: 1
+ }, this.requestData);
+ },
+
loadMore() {
this.setState({ activityPage: this.state.activityPage + 1 }, this.requestActivity);
},
<div className="page">
<Header/>
<Stats {...this.state} cancelPending={this.cancelPending} showFailures={this.showFailures}/>
- <Search {...this.state} onStatusChange={this.onStatusChange} onCurrentsChange={this.onCurrentsChange}/>
+ <Search {...this.state} onStatusChange={this.onStatusChange} onCurrentsChange={this.onCurrentsChange} onDateChange={this.onDateChange}/>
<Tasks tasks={[].concat(this.state.queue, this.state.activity)} onTaskCanceled={this.onTaskCanceled}/>
<ListFooter count={this.state.queue.length + this.state.activity.length}
total={this.state.queue.length + this.state.activityTotal}
+import _ from 'underscore';
import React from 'react';
import RadioToggle from '../../components/shared/radio-toggle';
-import {STATUSES, CURRENTS} from './constants';
+import {STATUSES, CURRENTS, DATE, DATE_FORMAT} from './constants';
export default React.createClass({
getCurrentsOptions() {
];
},
+ getDateOptions() {
+ return [
+ { value: DATE.ANY, label: 'Any Date' },
+ { value: DATE.TODAY, label: 'Today' },
+ { value: DATE.CUSTOM, label: 'Custom' }
+ ];
+ },
+
+ onDateChange(newDate) {
+ if (newDate === DATE.CUSTOM) {
+ let minDateRaw = React.findDOMNode(this.refs.minDate).value,
+ maxDateRaw = React.findDOMNode(this.refs.maxDate).value,
+ minDate = moment(minDateRaw, DATE_FORMAT, true),
+ maxDate = moment(maxDateRaw, DATE_FORMAT, true);
+ this.props.onDateChange(newDate,
+ minDate.isValid() ? minDate : null,
+ maxDate.isValid() ? maxDate : null);
+ } else {
+ this.props.onDateChange(newDate);
+ }
+ },
+
+ onDateInputChange(e) {
+ let value = e.target.value;
+ if (moment(value, DATE_FORMAT, true).isValid() || !value) {
+ this.onDateChange(DATE.CUSTOM);
+ }
+ },
+
+ renderCustomDateInput() {
+ let shouldBeVisible = this.props.dateFilter === DATE.CUSTOM,
+ className = shouldBeVisible ? 'spacer-top' : 'spacer-top hidden';
+ return (
+ <div className={className}>
+ from
+ <input onChange={this.onDateInputChange} ref="minDate" type="date" placeholder={DATE_FORMAT}
+ placeholder={DATE_FORMAT}/>
+ to
+ <input onChange={this.onDateInputChange} ref="maxDate" type="date" placeholder={DATE_FORMAT}
+ placeholder={DATE_FORMAT}/>
+ </div>
+ );
+ },
+
render() {
return (
<section className="big-spacer-top big-spacer-bottom">
<RadioToggle options={this.getCurrentsOptions()} value={this.props.currentsFilter}
name="background-task-currents" onCheck={this.props.onCurrentsChange}/>
</li>
+ <li>
+ <RadioToggle options={this.getDateOptions()} value={this.props.dateFilter}
+ name="background-task-date" onCheck={this.onDateChange}/>
+ {this.renderCustomDateInput()}
+ </li>
</ul>
</section>
);
input[type=password],
input[type=email],
input[type=search],
+input[type=date],
textarea {
border: 1px solid @darkGrey;
.box-sizing(border-box);
input[type=text],
input[type=password],
input[type=email],
-input[type=search] {
+input[type=search],
+input[type=date] {
height: @formControlHeight;
padding: 0 6px;
}
.radio-toggle {
display: inline-block;
+ vertical-align: middle;
font-size: 0;
& > li {