From: Stas Vilchik Date: Mon, 28 Sep 2015 13:01:42 +0000 (+0200) Subject: SONAR-6834 add date filter X-Git-Tag: 5.2-RC1~237 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0fdb1764e2be1efc00f84f2ce966d1a8ad78eb3e;p=sonarqube.git SONAR-6834 add date filter --- diff --git a/server/sonar-web/src/main/js/apps/background-tasks/constants.js b/server/sonar-web/src/main/js/apps/background-tasks/constants.js index c3d6e728374..68c14edb5b0 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/constants.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/constants.js @@ -12,3 +12,13 @@ export const CURRENTS = { ALL: '__ALL__', ONLY_CURRENTS: 'CURRENTS' }; + + +export const DATE = { + ANY: 'ANY', + TODAY: 'TODAY', + CUSTOM: 'CUSTOM' +}; + + +export const DATE_FORMAT = 'YYYY-MM-DD'; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/main.js b/server/sonar-web/src/main/js/apps/background-tasks/main.js index 0ea7eb73487..cdc56585af1 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/main.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/main.js @@ -1,7 +1,7 @@ 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'; @@ -18,14 +18,15 @@ export default React.createClass({ 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; @@ -44,6 +45,27 @@ export default React.createClass({ } }, + 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) { @@ -52,6 +74,9 @@ export default React.createClass({ if (this.state.currentsFilter !== STATUSES.ALL) { filters.onlyCurrents = true; } + if (this.state.dateFilter !== DATE.ANY) { + _.extend(filters, this.getDateFilter()); + } return filters; }, @@ -124,6 +149,15 @@ export default React.createClass({ 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); }, @@ -153,7 +187,7 @@ export default React.createClass({
- + + from  + +  to  + +
+ ); + }, + render() { return (
@@ -31,6 +76,11 @@ export default React.createClass({ +
  • + + {this.renderCustomDateInput()} +
  • ); diff --git a/server/sonar-web/src/main/less/init/forms.less b/server/sonar-web/src/main/less/init/forms.less index de66272f948..ceaf5db6dfe 100644 --- a/server/sonar-web/src/main/less/init/forms.less +++ b/server/sonar-web/src/main/less/init/forms.less @@ -10,6 +10,7 @@ input[type=text], input[type=password], input[type=email], input[type=search], +input[type=date], textarea { border: 1px solid @darkGrey; .box-sizing(border-box); @@ -31,7 +32,8 @@ textarea { input[type=text], input[type=password], input[type=email], -input[type=search] { +input[type=search], +input[type=date] { height: @formControlHeight; padding: 0 6px; } @@ -204,6 +206,7 @@ label[for] { .radio-toggle { display: inline-block; + vertical-align: middle; font-size: 0; & > li {