<commit_before>package dk.teachus.frontend.components.calendar;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.joda.time.DateMidnight;
import org.joda.time.DateTimeConstants;
import org.joda.time.format.DateTimeFormatter;

import wicket.behavior.SimpleAttributeModifier;
import wicket.extensions.yui.calendar.DateField;
import wicket.markup.html.WebMarkupContainer;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Button;
import wicket.markup.html.form.Form;
import wicket.markup.html.image.Image;
import wicket.markup.html.link.Link;
import wicket.markup.html.panel.Panel;
import wicket.markup.repeater.RepeatingView;
import wicket.model.Model;
import wicket.model.PropertyModel;
import dk.teachus.domain.DatePeriod;
import dk.teachus.domain.Period;
import dk.teachus.domain.Periods;
import dk.teachus.frontend.TeachUsSession;
import dk.teachus.frontend.utils.Formatters;
import dk.teachus.frontend.utils.Resources;

public abstract class CalendarPanel extends Panel {
	private static final long serialVersionUID = 1L;
	
	public CalendarPanel(String wicketId, DateMidnight pageDate, final Periods periods) {
		super(wicketId);
		
		// Status message
		final boolean showCalendar = periods.getPeriods().isEmpty() == false;
		
		Label statusMessage = new Label("statusMessage", TeachUsSession.get().getString("General.noPeriodsConfigured")) { //$NON-NLS-1$ //$NON-NLS-2$
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isVisible() {
				return showCalendar == false;
			}
		};
		add(statusMessage);
		
		
		// Calendar
		WebMarkupContainer calendar = new WebMarkupContainer("calendar") { //$NON-NLS-1$
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isVisible() {
				return showCalendar;
			}
		};
		add(calendar);
		
		if (showCalendar) {
			// Navigation form
			Form navigationForm = new Form("navigationForm"); //$NON-NLS-1$
			calendar.add(navigationForm);
			
			final NavigationModel navigationModel = new NavigationModel(pageDate.toDate());
			navigationForm.add(new DateField("date", new PropertyModel(navigationModel, "date"))); //$NON-NLS-1$ //$NON-NLS-2$
			navigationForm.add(new Button("goto", new Model(TeachUsSession.get().getString("CalendarPanel.goTo"))) { //$NON-NLS-1$ //$NON-NLS-2$
				private static final long serialVersionUID = 1L;

				@Override
				public void onSubmit() {
					navigationDateSelected(new DateMidnight(navigationModel.getDate()));
				}
			});
			
			
			// Calendar
			DateMidnight weekDate = pageDate.withDayOfWeek(DateTimeConstants.MONDAY);
			final DateMidnight firstWeekDate = weekDate;
			List<DatePeriod> dates = periods.generateDates(weekDate, 7);
			
			// Get the biggest date of the generates dates
			for (DatePeriod period : dates) {
				DateMidnight periodDate = new DateMidnight(period.getDate());
				if (weekDate.isBefore(periodDate)) {
					weekDate = periodDate;
				}
			}
			if (weekDate.getWeekOfWeekyear() == pageDate.getWeekOfWeekyear()) {
				weekDate = weekDate.plusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY);
			}
						
			fireIntervalDetermined(dates);
			
			// Weeks
			RepeatingView weeks = new RepeatingView("weeks"); //$NON-NLS-1$
			calendar.add(weeks);
			
			int w = -1;
			RepeatingView days = null;
			DateTimeFormatter formatWeekOfYear = Formatters.getFormatWeekOfYear();
			Label weekHeader = null;
			int daysInWeek = 0;
			int localWeekNumber = 0;
			
			// Calculate the number of weeks<commit_msg>Navigate correctly forward, so it doesn't start from the last week from previous page.<commit_after>package dk.teachus.frontend.components.calendar;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.joda.time.DateMidnight;
import org.joda.time.DateTimeConstants;
import org.joda.time.format.DateTimeFormatter;

import wicket.behavior.SimpleAttributeModifier;
import wicket.extensions.yui.calendar.DateField;
import wicket.markup.html.WebMarkupContainer;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Button;
import wicket.markup.html.form.Form;
import wicket.markup.html.image.Image;
import wicket.markup.html.link.Link;
import wicket.markup.html.panel.Panel;
import wicket.markup.repeater.RepeatingView;
import wicket.model.Model;
import wicket.model.PropertyModel;
import dk.teachus.domain.DatePeriod;
import dk.teachus.domain.Period;
import dk.teachus.domain.Periods;
import dk.teachus.frontend.TeachUsSession;
import dk.teachus.frontend.utils.Formatters;
import dk.teachus.frontend.utils.Resources;

public abstract class CalendarPanel extends Panel {
	private static final long serialVersionUID = 1L;
	
	public CalendarPanel(String wicketId, DateMidnight pageDate, final Periods periods) {
		super(wicketId);
		
		// Status message
		final boolean showCalendar = periods.getPeriods().isEmpty() == false;
		
		Label statusMessage = new Label("statusMessage", TeachUsSession.get().getString("General.noPeriodsConfigured")) { //$NON-NLS-1$ //$NON-NLS-2$
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isVisible() {
				return showCalendar == false;
			}
		};
		add(statusMessage);
		
		
		// Calendar
		WebMarkupContainer calendar = new WebMarkupContainer("calendar") { //$NON-NLS-1$
			private static final long serialVersionUID = 1L;

			@Override
			public boolean isVisible() {
				return showCalendar;
			}
		};
		add(calendar);
		
		if (showCalendar) {
			// Navigation form
			Form navigationForm = new Form("navigationForm"); //$NON-NLS-1$
			calendar.add(navigationForm);
			
			final NavigationModel navigationModel = new NavigationModel(pageDate.toDate());
			navigationForm.add(new DateField("date", new PropertyModel(navigationModel, "date"))); //$NON-NLS-1$ //$NON-NLS-2$
			navigationForm.add(new Button("goto", new Model(TeachUsSession.get().getString("CalendarPanel.goTo"))) { //$NON-NLS-1$ //$NON-NLS-2$
				private static final long serialVersionUID = 1L;

				@Override
				public void onSubmit() {
					navigationDateSelected(new DateMidnight(navigationModel.getDate()));
				}
			});
			
			
			// Calendar
			DateMidnight weekDate = pageDate.withDayOfWeek(DateTimeConstants.MONDAY);
			final DateMidnight firstWeekDate = weekDate;
			List<DatePeriod> dates = periods.generateDates(weekDate, 7);
			
			// Get the biggest date of the generates dates
			for (DatePeriod period : dates) {
				DateMidnight periodDate = new DateMidnight(period.getDate());
				if (weekDate.isBefore(periodDate)) {
					weekDate = periodDate;
				}
			}
			weekDate = weekDate.plusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY);
						
			fireIntervalDetermined(dates);
			
			// Weeks
			RepeatingView weeks = new RepeatingView("weeks"); //$NON-NLS-1$
			calendar.add(weeks);
			
			int w = -1;
			RepeatingView days = null;
			DateTimeFormatter formatWeekOfYear = Formatters.getFormatWeekOfYear();
			Label weekHeader = null;
			int daysInWeek = 0;
			int localWeekNumber = 0;
			
			// Calculate the number of weeks
{'fraction_non_alphanumeric': 0.11364926220204313, 'fraction_numerical': 0.00510783200908059, 'mean_word_length': 4.236998514115899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5219138', 'n_tokens_mistral': 2550, 'n_tokens_neox': 2161, 'n_words': 461}