<commit_before>import moment from 'moment';
import calendar from 'calendar';

import View from '../base/view';
import Toggle from '../components/toggle';
import Slider from '../components/slider';

import {toggleClass, range} from '../utils';

import template from '../../templates/calendar.ejs';


export default class Calendar extends View {
  constructor({app, location, date}) {
    super({app});

    this.location = location;
    this.date = date;
  }

  getHTML() {
    const today = moment.tz(this.location.timezone).startOf('day');
    const current = {location: this.location, date: this.date};
    const quickDates = range(15).map(n => today.clone().add(n, 'days'));
    const firstDayOfWeek = moment.localeData().firstDayOfWeek();
    const daysOfWeek = this.getDaysOfWeekInOrder(firstDayOfWeek)
    const dateToString = this.dateToString;

    const cal = new calendar.Calendar(firstDayOfWeek);
    const months = range(3).map(n => {
      const date = today.clone().startOf('month').add(n, 'months');
      return {
        name: date.format('MMMM'),
        number: date.month(),
        weekDates: cal.monthDates(date.year(), date.month(), moment),
      }
    });

    return this.app.renderTemplate(template, {
      today, current, quickDates, daysOfWeek, months, dateToString});
  }

  mount(element, sync=false) {
    this.element = element;

    new Toggle(element.querySelector('.custom-date-button'), element);
    new Slider(element.querySelector('.calendar'), false);

    if (sync) {
      this.updateLinks();
      this.updateActiveDate();
    }
  }

  updateLinks() {
    const links = this.element.querySelectorAll('a.calendar-day');
    const location = this.location.slug;
    Array.from(links).forEach(element => {
      const date = element.getAttribute('data-date');
      const args = date ? {location, date} : {location};
      const url = this.app.resolver.reverse('event-list', args);
      element.setAttribute('href', url);
    });
  }

  updateActiveDate() {
    Array
      .from(this.element.querySelectorAll('a.calendar-day.active'))<commit_msg>Hide calendar after choosing the date<commit_after>import moment from 'moment';
import calendar from 'calendar';

import View from '../base/view';
import Toggle from '../components/toggle';
import Slider from '../components/slider';

import {toggleClass, hide, range} from '../utils';

import template from '../../templates/calendar.ejs';


export default class Calendar extends View {
  constructor({app, location, date}) {
    super({app});

    this.location = location;
    this.date = date;
  }

  getHTML() {
    const today = moment.tz(this.location.timezone).startOf('day');
    const current = {location: this.location, date: this.date};
    const quickDates = range(15).map(n => today.clone().add(n, 'days'));
    const firstDayOfWeek = moment.localeData().firstDayOfWeek();
    const daysOfWeek = this.getDaysOfWeekInOrder(firstDayOfWeek)
    const dateToString = this.dateToString;

    const cal = new calendar.Calendar(firstDayOfWeek);
    const months = range(3).map(n => {
      const date = today.clone().startOf('month').add(n, 'months');
      return {
        name: date.format('MMMM'),
        number: date.month(),
        weekDates: cal.monthDates(date.year(), date.month(), moment),
      }
    });

    return this.app.renderTemplate(template, {
      today, current, quickDates, daysOfWeek, months, dateToString});
  }

  mount(element, sync=false) {
    this.element = element;

    new Toggle(element.querySelector('.custom-date-button'), element);
    new Slider(element.querySelector('.calendar'), false);

    element
      .querySelector('.calendar .months-container')
      .addEventListener('click', event => this.hideCalendar());

    if (sync) {
      this.hideCalendar();
      this.updateLinks();
      this.updateActiveDate();
    }
  }

  hideCalendar() {
    const doHide = () => hide(this.element.querySelector('.calendar-box'));
    window.setTimeout(doHide, 5);
  }

  updateLinks() {
    const links = this.element.querySelectorAll('a.calendar-day');
    const location = this.location.slug;
    Array.from(links).forEach(element => {
      const date = element.getAttribute('data-date');
      const args = date ? {location, date} : {location};
      const url = this.app.resolver.reverse('event-list', args);
      element.setAttribute('href', url);
    });
  }

  updateActiveDate() {
    Array
      .from(this.element.querySelectorAll('a.calendar-day.active'))
{'fraction_non_alphanumeric': 0.15422222222222223, 'fraction_numerical': 0.0015555555555555555, 'mean_word_length': 3.447628458498024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7225112', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1303, 'n_words': 288}