Commit 5152f1dc authored by Kent Nielsen's avatar Kent Nielsen
Browse files

More fixes for merge

parent 66eef714
......@@ -122,26 +122,40 @@ export default {
}
},
methods: {
// Calculate how many days a movement in the calendar should be
// forward: boolean - whether the move is forward or not, changes
// the calculate on friday and monday
daysToAdd (forward){
if(this.schedule.length == 1){
if((this.today.getDay() == 5 && forward) || (this.today.getDay() == 1 && !forward)){
return 3;
} else {
return 1;
}
// If in week view, move 7 days
if(this.schedule.length != 1){
return 7;
}
// If in day view and at friday or monday
// The calendar should move 3 days
if((this.today.getDay() == 5 && forward) || (this.today.getDay() == 1 && !forward)){
return 3;
}
return 7;
// Neither week view nor friday or monday
return 1;
},
// Move the date 7 days back
prevWeek(){
this.today = new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate() - this.daysToAdd(false));
// Move the date back based on calendar view
prevWeek(){
const currentYear = this.today.getFullYear();
const currentMonth = this.today.getMonth();
const dayToMoveCalendarBackTo = this.today.getDate() - this.daysToAdd(false);
this.today = new Date(currentYear, currentMonth, dayToMoveCalendarBackTo);
this.changeSchedule();
},
// Move the date 7 days forward
// Move the date forward based on calendar view
nextWeek(){
this.today = new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate() + this.daysToAdd(true));
const currentYear = this.today.getFullYear();
const currentMonth = this.today.getMonth();
const dayToMoveCalendarForwardTo = this.today.getDate() + this.daysToAdd(true);
this.today = new Date(currentYear, currentMonth, dayToMoveCalendarForwardTo);
this.changeSchedule();
},
......@@ -163,7 +177,7 @@ export default {
// Check for first index in a loop
firstIndex(index){
return index === 0
return index === 0;
},
// Source: https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
......@@ -190,7 +204,7 @@ export default {
else {
ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay());
}
ISOweekStart.setDate(ISOweekStart.getDate() + offset)
ISOweekStart.setDate(ISOweekStart.getDate() + offset);
return ISOweekStart;
},
......@@ -199,11 +213,14 @@ export default {
return this.monthName[month];
},
// Update the vertical size of events within the calendar
updateHalfHourSize(){
const tbody = document.getElementById("calendar").getElementsByTagName("tbody")[0];
this.halfHourSpace = (parseInt(window.getComputedStyle(tbody).height)/(2*9));
},
// Update the amount of days in the display
// Therefor changes form week to day view
updateDaysInDisplay(){
if(parseInt(document.getElementById("calendar").clientWidth) < this.calendarDayWidth){
if(this.schedule.length == 5){
......@@ -220,16 +237,23 @@ export default {
this.updateHalfHourSize();
},
// Initilized the current day on mount of calendar
initToday(){
const firstDayOfWeek = this.getDateOfISOWeek(this.getWeek(this.today), this.today.getFullYear(),0).getDate();
const lastDayOfWeek = this.getDateOfISOWeek(this.getWeek(this.today), this.today.getFullYear(),4).getDate();
if(this.today.getDate() > lastDayOfWeek || this.today.getDate() < firstDayOfWeek){
const isCurrentDayAfterFriday = this.today.getDate() > lastDayOfWeek;
const isCurrentDayBeforeMonday = this.today.getDate() < firstDayOfWeek;
if(isCurrentDayAfterFriday || isCurrentDayBeforeMonday){
while(this.today.getDate() < lastDayOfWeek){
this.today = new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate()-1);
const currentYear = this.today.getFullYear();
const currentMonth = this.today.getMonth();
const dayToInitCalendarTo = this.today.getDate() - 1;
this.today = new Date(currentYear, currentMonth, dayToInitCalendarTo);
}
}
}
},
mounted(){
this.initToday();
this.updateHalfHourSize();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment