Skip to content

Commit

Permalink
[#510] Support multiple years in holiday calendar
Browse files Browse the repository at this point in the history
Merge pull request #532 from Igalia/increase-available-months
  • Loading branch information
jaragunde authored Nov 19, 2021
2 parents 329124e + 85a7ccc commit 3725d71
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions model/facade/UsersFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ static function GetPendingHolidayHours(DateTime $init, DateTime $end, UserVO $us
return $action->execute();
}

static function GetHolidayHoursSummary(DateTime $init, DateTime $end, UserVO $user = NULL) {
$action = new GetHolidayHoursSummaryAction($init, $end, $user);
static function GetHolidayHoursSummary(DateTime $init, DateTime $end, UserVO $user = NULL, Datetime $referenceDate = NULL) {
$action = new GetHolidayHoursSummaryAction($init, $end, $user, $referenceDate);
return $action->execute();
}

Expand Down
6 changes: 3 additions & 3 deletions model/facade/action/GetHolidayHoursBaseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(DateTime $init, DateTime $end, ?UserVO $user = NULL)
$this->user = $user;
}

protected function getHoursSummary(DateTime $today = NULL): array
protected function getHoursSummary(DateTime $referenceDate = NULL): array
{
$taskDao = DAOFactory::getTaskDAO();
$journeyHistoryDao = DAOFactory::getJourneyHistoryDAO();
Expand Down Expand Up @@ -130,8 +130,8 @@ protected function getHoursSummary(DateTime $today = NULL): array
$holidayHours = ($workHours / (365 * 8)) * ConfigurationParametersManager::getParameter('YEARLY_HOLIDAY_HOURS');
$userAvailableHours[$userVO->getLogin()] = $holidayHours;

$today = $today ?? new DateTime();
$userEnjoyedHours[$userVO->getLogin()] = $taskDao->getVacations($userVO, $reportInit, $today)["add_hours"] ?? 0;
$referenceDate = $referenceDate ?? new DateTime();
$userEnjoyedHours[$userVO->getLogin()] = $taskDao->getVacations($userVO, $reportInit, $referenceDate)["add_hours"] ?? 0;
$userScheduledHours[$userVO->getLogin()] = $vacations - $userEnjoyedHours[$userVO->getLogin()];

// The difference is the number of pending holiday hours
Expand Down
6 changes: 3 additions & 3 deletions model/facade/action/GetHolidayHoursSummaryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

class GetHolidayHoursSummaryAction extends GetHolidayHoursBaseAction
{
public function __construct(DateTime $init, DateTime $end, UserVO $user = NULL, Datetime $today = NULL)
public function __construct(DateTime $init, DateTime $end, UserVO $user = NULL, Datetime $referenceDate = NULL)
{
parent::__construct($init, $end, $user);
$this->preActionParameter = "GET_HOLIDAY_HOURS_SUMMARY_PREACTION";
$this->postActionParameter = "GET_HOLIDAY_HOURS_SUMMARY_POSTACTION";
$this->today = $today ?? new DateTime();
$this->referenceDate = $referenceDate ?? new DateTime();
}

protected function doExecute()
{
return $this->getHoursSummary();
return $this->getHoursSummary($referenceDate = $this->referenceDate);
}
}
6 changes: 3 additions & 3 deletions web/holidayManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div class="holidayContainer">
<div class="sidebar">
<div class="holidaysList">
<h2 class="sidebarTitle"><?php echo date("Y"); ?> Holidays</h2>
<h2 class="sidebarTitle">Holidays Summary for {{ currentYear }}</h2>
<div v-if="!isEditing" class="autocompleteContainer">
<input
class="autocompleteSearchInput"
Expand Down Expand Up @@ -102,10 +102,10 @@ class="autocompleteSearchInput"
</div>
<div class="calendar">
<div v-if="isEditing">
<v-date-picker is-range v-model="range" :attributes="ranges" :first-day-of-week="2" :rows="3" :columns="$screens({ default: 2, lg: 4 })" show-iso-weeknumbers :select-attribute="selectAttribute" @dayclick="onDayClick" :min-date="init" :max-date="end" />
<v-date-picker ref="calendar" :from-page="fromPage" is-range v-model="range" :attributes="ranges" :first-day-of-week="2" :rows="3" :columns="$screens({ default: 2, lg: 4 })" show-iso-weeknumbers :select-attribute="selectAttribute" @dayclick="onDayClick" @update:from-page="updateCurrentYear" :min-date="init" :max-date="end" />
</div>
<div v-show="!isEditing">
<v-calendar is-range v-model="teamRange" :attributes="teamAttributes" :first-day-of-week="2" :rows="3" :columns="$screens({ default: 2, lg: 4 })" show-iso-weeknumbers :min-date="init" :max-date="end" />
<v-calendar is-range :from-page="fromPage" v-model="teamRange" :attributes="teamAttributes" :first-day-of-week="2" :rows="3" :columns="$screens({ default: 2, lg: 4 })" show-iso-weeknumbers @update:from-page="updateCurrentYear" :min-date="init" :max-date="end" />
</div>
</div>
<div class="snackbarWrapper">
Expand Down
40 changes: 34 additions & 6 deletions web/js/holidayManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ var app = new Vue({
range: {},
teamRange: {},
teamAttributes: {},
teamDaysByWeek: {},
teamDaysByWeek: [],
teamDays: [],
ranges: [],
isEditing: true,
userSummary: {},
personalSummary: {},
daysByWeek: null,
daysByWeek: [],
latestDelete: null,
isEndOfRange: false,
init: new Date(new Date().getFullYear(), 0, 1),
end: new Date(new Date().getFullYear(), 11, 31),
init: new Date(new Date().getFullYear() - 1, 0, 1),
end: new Date(new Date().getFullYear() + 1, 11, 31),
personalFromPage: { month: 1, year: new Date().getFullYear() },
teamFromPage: { month: 1, year: new Date().getFullYear() },
currentYear: new Date().getFullYear(),
serverMessages: [],
// Clean selected range styles to avoid confusion when
// removing dates
Expand Down Expand Up @@ -122,10 +125,14 @@ var app = new Vue({
return this.ranges;
},
weeksList() {
return this.isEditing ? this.daysByWeek : this.teamDaysByWeek;
const weeks = this.isEditing ? this.daysByWeek : this.teamDaysByWeek;
return weeks?.filter(week => week.weekNumber.startsWith(this.currentYear));
},
summary() {
return this.isEditing ? this.personalSummary : this.userSummary;
},
fromPage() {
return this.isEditing ? this.personalFromPage : this.teamFromPage;
}
},
methods: {
Expand Down Expand Up @@ -157,7 +164,13 @@ var app = new Vue({
}
},
async fetchSummary(user = null) {
let url = `services/getPersonalSummaryByDateService.php?date=${formatDate(this.end)}`;
let referenceDate = new Date();
if (this.currentYear < referenceDate.getFullYear()) {
referenceDate = new Date(this.currentYear, 11, 31);
} else if (this.currentYear > referenceDate.getFullYear()) {
referenceDate = new Date(this.currentYear, 0, 1);
}
let url = `services/getPersonalSummaryByDateService.php?date=${formatDate(referenceDate)}`;
if (user) {
url += `&userLogin=${user}`
}
Expand Down Expand Up @@ -256,6 +269,13 @@ var app = new Vue({
onDayClick(day) {
let endDay = day.date;

// Make sure the montha that are being displayed are not changed
// after clicking on a day
this.personalFromPage = {
month: this.$refs.calendar.$refs.calendar.pages[0].month,
year: this.$refs.calendar.$refs.calendar.pages[0].year
};

// Check if the selected day is already in the list, if it is, it means the user
// is edditing or removing some range, so delete respective range and dates
if (this.days.findIndex(d => d === day.id) >= 0) {
Expand Down Expand Up @@ -312,6 +332,14 @@ var app = new Vue({
// Next click will be the opposite of the current state
this.isEndOfRange = !this.isEndOfRange;
},
updateCurrentYear(fromPage) {
this.currentYear = fromPage.year;
if (this.isEditing) {
this.fetchSummary();
} else {
this.fetchSummary(this.searchUser);
}
},
onSaveClick: async function () {
const url = `services/updateHolidays.php?init=${formatDate(this.init)}&end=${formatDate(this.end)}`;
const res = await fetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion web/services/getPersonalSummaryByDateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

// Report holidays from the entire year, including those later than $date
$endYearDate = new DateTime($date->format('Y') . '-12-31');
$holidays = UsersFacade::GetHolidayHoursSummary($initYearDate, $endYearDate, $userVO);
$holidays = UsersFacade::GetHolidayHoursSummary($initYearDate, $endYearDate, $userVO, $date);
$pendingHolidays = $holidays["pendingHours"][$userVO->getLogin()];
$pendingHolidays = HolidayService::formatHours($pendingHolidays, $currentJourney, 5);

Expand Down

0 comments on commit 3725d71

Please sign in to comment.