1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Calendar month view should notify user if all or part of the month was not included in the query search

Summary: Closes T8104, Calendar month view should notify user if all or part of the month was not included in the query search

Test Plan: In Calendar month view, search May 1-13, get "part of month is out of range", search May 1-31, 12am - 11:59:59, get no errors.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8104

Differential Revision: https://secure.phabricator.com/D12787
This commit is contained in:
lkassianik 2015-05-09 19:11:30 -07:00
parent b67ad3c4e0
commit f7662d61ac
3 changed files with 82 additions and 24 deletions

View file

@ -323,11 +323,15 @@ final class PhabricatorCalendarEventSearchEngine
if ($start_month == $now_month && $start_year == $now_year) {
$month_view = new PHUICalendarMonthView(
$this->getDateFrom($query),
$this->getDateTo($query),
$start_month,
$start_year,
$now_day);
} else {
$month_view = new PHUICalendarMonthView(
$this->getDateFrom($query),
$this->getDateTo($query),
$start_month,
$start_year);
}

View file

@ -170,33 +170,13 @@ final class PHUICalendarDayView extends AphrontView {
$header = $this->renderDayViewHeader();
$sidebar = $this->renderSidebar();
$errors = array();
$range_start_epoch = $this->rangeStart->getEpoch();
$range_end_epoch = $this->rangeEnd->getEpoch();
if (($range_start_epoch != null &&
$range_start_epoch < $day_end &&
$range_start_epoch > $day_start) ||
($range_end_epoch != null &&
$range_end_epoch < $day_end &&
$range_end_epoch > $day_start)) {
$errors[] = pht('Part of the day is out of range');
}
if (($this->rangeEnd->getEpoch() != null &&
$this->rangeEnd->getEpoch() < $day_start) ||
($this->rangeStart->getEpoch() != null &&
$this->rangeStart->getEpoch() > $day_end)) {
$errors[] = pht('Day is out of query range');
}
$warnings = $this->getQueryRangeWarning();
$table_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($all_day_event_box)
->appendChild($table)
->setFormErrors($errors)
->setFormErrors($warnings)
->setFlush(true);
$layout = id(new AphrontMultiColumnView())
@ -226,6 +206,35 @@ final class PHUICalendarDayView extends AphrontView {
return $all_day_events;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = $this->rangeStart->getEpoch();
$range_end_epoch = $this->rangeEnd->getEpoch();
$day_start = $this->getDateTime();
$day_end = id(clone $day_start)->modify('+1 day');
$day_start = $day_start->format('U');
$day_end = $day_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $day_end &&
$range_start_epoch > $day_start) ||
($range_end_epoch != null &&
$range_end_epoch < $day_end &&
$range_end_epoch > $day_start)) {
$errors[] = pht('Part of the day is out of range');
}
if (($this->rangeEnd->getEpoch() != null &&
$this->rangeEnd->getEpoch() < $day_start) ||
($this->rangeStart->getEpoch() != null &&
$this->rangeStart->getEpoch() > $day_end)) {
$errors[] = pht('Day is out of query range');
}
}
private function renderSidebar() {
$this->events = msort($this->events, 'getEpochStart');
$week_of_boxes = $this->getWeekOfBoxes();

View file

@ -1,6 +1,8 @@
<?php
final class PHUICalendarMonthView extends AphrontView {
private $rangeStart;
private $rangeEnd;
private $day;
private $month;
@ -40,7 +42,16 @@ final class PHUICalendarMonthView extends AphrontView {
return $this;
}
public function __construct($month, $year, $day = null) {
public function __construct(
$range_start,
$range_end,
$month,
$year,
$day = null) {
$this->rangeStart = $range_start;
$this->rangeEnd = $range_end;
$this->day = $day;
$this->month = $month;
$this->year = $year;
@ -188,9 +199,12 @@ final class PHUICalendarMonthView extends AphrontView {
phutil_implode_html("\n", $table),
));
$warnings = $this->getQueryRangeWarning();
$box = id(new PHUIObjectBoxView())
->setHeader($this->renderCalendarHeader($first))
->appendChild($table);
->appendChild($table)
->setFormErrors($warnings);
if ($this->error) {
$box->setInfoView($this->error);
@ -250,6 +264,37 @@ final class PHUICalendarMonthView extends AphrontView {
return $header;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = $this->rangeStart->getEpoch();
$range_end_epoch = $this->rangeEnd->getEpoch();
$month_start = $this->getDateTime();
$month_end = id(clone $month_start)->modify('+1 month');
$month_start = $month_start->format('U');
$month_end = $month_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $month_end &&
$range_start_epoch > $month_start) ||
($range_end_epoch != null &&
$range_end_epoch < $month_end &&
$range_end_epoch > $month_start)) {
$errors[] = pht('Part of the month is out of range');
}
if (($this->rangeEnd->getEpoch() != null &&
$this->rangeEnd->getEpoch() < $month_start) ||
($this->rangeStart->getEpoch() != null &&
$this->rangeStart->getEpoch() > $month_end)) {
$errors[] = pht('Month is out of query range');
}
return $errors;
}
private function getNextYearAndMonth() {
$next = $this->getDateTime();
$next->modify('+1 month');