<commit_before>/* global moment, TapBase, GOVUKAdmin */

/*eslint-disable no-unused-vars*/
class Calendar extends TapBase {
/*eslint-enable no-unused-vars*/
  start(el) {
    const defaultConfig = {
      allDaySlot: false,
      cookieName: el.attr('id') || 'calendar',
      customButtons: {
        jumpToDate: {
          text: 'Jump to date',
          click: this.jumpToDateClick.bind(this)
        }
      },
      buttonText: {
        agendaDay: 'Day',
        timelineDay: 'Timeline',
        today: 'Jump to today',
        month: 'Month',
        week: 'Week'
      },
      defaultDate: moment(el.data('default-date')),
      firstDay: 1,
      height: 'auto',
      maxTime: '19:00:00',
      minTime: '08:30:00',
      schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
      slotLabelFormat: 'H:mm',
      slotEventOverlap: false,
      timeFormat: 'H:mm',
      weekends: false,
      select: (...args) => this.select(...args),
      viewRender: (...args) => this.viewRender(...args),
      eventRender: (...args) => this.eventRender(...args),
      resourceRender: (...args) => this.resourceRender(...args),
      eventAfterRender: (...args) => this.eventAfterRender(...args),
      eventClick: (...args) => this.eventClick(...args),
      eventDrop: (...args) => this.eventDrop(...args),
      eventResize: (...args) => this.eventResize(...args),
      loading: (...args) => this.loading(...args)
    };

    this.config = $.extend(
      true,
      defaultConfig,
      this.config
    );

    super.start(el);

    this.$el.fullCalendar(this.config);

    this.insertJumpToDate();
    this.addAccessibilityImprovements();
    this.insertLoadingView();
  }

  insertLoadingView() {
    this.calendarLoadingView = $(`
      <div class="calendar-loading hide">
        <div class="calendar-loading-spinner">
          <div class="calendar-loading-spinner__bounce calendar-loading-spinner__bounce--1"></div>
          <div class="calendar-loading-spinner__bounce calendar-loading-spinner__bounce--2"></div>
          <div class="calendar-loading-spinner__bounce"></div>
        </div>
      </div>`);

    this.calendarLoadingView.appendTo($('.fc-view-container'));
  }

  addAccessibilityImprovements() {
    $('.fc-prev-button').append('<span class="sr-only">Previous Date</span>');
    $('.fc-next-button').append('<span class="sr-only">Next Date</span>');
  }

  jumpToDateClick() {
    const dateRangePicker = this.$jumpToDateEl.data('daterangepicker'),
      currentDate = this.getCurrentDate();

    this.$jumpToDateEl.val(currentDate);

    dateRangePicker.setStartDate(currentDate);
    dateRangePicker.setEndDate(currentDate);

    this.$jumpToDateEl.click();
  }

  insertJumpToDate() {
    const $jumpToDateButton = $('.fc-jumpToDate-button');

    if ($jumpToDateButton.length === 0) {
      return;
    }

    this.$jumpToDateEl = $(`
      <input type="text" class="jump-to-date" name="jump-to-date" id="jump-to-date" value="${this.getCurrentDate()}">
    `).daterangepicker({
      singleDatePicker: true,
      showDropdowns: true,
      locale: {
        format: 'YYYY-MM-DD'
      }
    }).on(
      'change',
      this.jumpToDateElChange.bind(this)
    ).insertAfter($jumpToDateButton);

    $('<label for="jump-to-date"><span class="sr-only">Jump to date</span></label>').insertAfter($jumpToDateButton);
  }

  jumpToDateElChange(el) {
    this.$el.fullCalendar('gotoDate', moment($(el.currentTarget).val()));
  }

  viewRender(view) {
    this.setCookieConfig(view);
  }

  setCookieConfig(view) {
    GOVUKAdmin.cookie(
      this.config.cookieName,
      JSON.stringify({
        defaultView: view.name,
        defaultDate: view.calendar.getDate()
      }),
      {
        days: 7
      }
    );
  }

  getCurrentDate(format = 'YYYY-MM-DD') {
    return this.$el.fullCalendar('getDate').format(format);
  }

  loading(isLoading) {
    if (isLoading && this.calendarLoadingView) {
      this.calendarLoadingView.removeClass('hide');
    } else if(this.calendarLoadingView) {
      this.calendarLoadingView.addClass('hide');
    }
  }

  eventDrop() {

  }

  select() {

  }

  eventRender() {

  }

  eventAfterRender() {

  }

  resourceRender() {

  }

  eventClick() {

  }

  eventResize() {

  }
}
<commit_msg>Ensure that ajax loading graphic shows when calendars first load<commit_after>/* global moment, TapBase, GOVUKAdmin */

/*eslint-disable no-unused-vars*/
class Calendar extends TapBase {
/*eslint-enable no-unused-vars*/
  start(el) {
    const defaultConfig = {
      allDaySlot: false,
      cookieName: el.attr('id') || 'calendar',
      customButtons: {
        jumpToDate: {
          text: 'Jump to date',
          click: this.jumpToDateClick.bind(this)
        }
      },
      buttonText: {
        agendaDay: 'Day',
        timelineDay: 'Timeline',
        today: 'Jump to today',
        month: 'Month',
        week: 'Week'
      },
      defaultDate: moment(el.data('default-date')),
      firstDay: 1,
      height: 'auto',
      maxTime: '19:00:00',
      minTime: '08:30:00',
      schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
      slotLabelFormat: 'H:mm',
      slotEventOverlap: false,
      timeFormat: 'H:mm',
      weekends: false,
      select: (...args) => this.select(...args),
      viewRender: (...args) => this.viewRender(...args),
      eventRender: (...args) => this.eventRender(...args),
      resourceRender: (...args) => this.resourceRender(...args),
      eventAfterRender: (...args) => this.eventAfterRender(...args),
      eventClick: (...args) => this.eventClick(...args),
      eventDrop: (...args) => this.eventDrop(...args),
      eventResize: (...args) => this.eventResize(...args),
      loading: (...args) => this.loading(...args)
    };

    this.config = $.extend(
      true,
      defaultConfig,
      this.config
    );

    super.start(el);

    this.$el.fullCalendar(this.config);

    this.insertJumpToDate();
    this.addAccessibilityImprovements();
  }

  insertLoadingView() {
    this.calendarLoadingView = $(`
      <div class="calendar-loading hide">
        <div class="calendar-loading-spinner">
          <div class="calendar-loading-spinner__bounce calendar-loading-spinner__bounce--1"></div>
          <div class="calendar-loading-spinner__bounce calendar-loading-spinner__bounce--2"></div>
          <div class="calendar-loading-spinner__bounce"></div>
        </div>
      </div>`);

    this.calendarLoadingView.appendTo($('.fc-view-container'));
  }

  addAccessibilityImprovements() {
    $('.fc-prev-button').append('<span class="sr-only">Previous Date</span>');
    $('.fc-next-button').append('<span class="sr-only">Next Date</span>');
  }

  jumpToDateClick() {
    const dateRangePicker = this.$jumpToDateEl.data('daterangepicker'),
      currentDate = this.getCurrentDate();

    this.$jumpToDateEl.val(currentDate);

    dateRangePicker.setStartDate(currentDate);
    dateRangePicker.setEndDate(currentDate);

    this.$jumpToDateEl.click();
  }

  insertJumpToDate() {
    const $jumpToDateButton = $('.fc-jumpToDate-button');

    if ($jumpToDateButton.length === 0) {
      return;
    }

    this.$jumpToDateEl = $(`
      <input type="text" class="jump-to-date" name="jump-to-date" id="jump-to-date" value="${this.getCurrentDate()}">
    `).daterangepicker({
      singleDatePicker: true,
      showDropdowns: true,
      locale: {
        format: 'YYYY-MM-DD'
      }
    }).on(
      'change',
      this.jumpToDateElChange.bind(this)
    ).insertAfter($jumpToDateButton);

    $('<label for="jump-to-date"><span class="sr-only">Jump to date</span></label>').insertAfter($jumpToDateButton);
  }

  jumpToDateElChange(el) {
    this.$el.fullCalendar('gotoDate', moment($(el.currentTarget).val()));
  }

  viewRender(view) {
    this.setCookieConfig(view);
  }

  setCookieConfig(view) {
    GOVUKAdmin.cookie(
      this.config.cookieName,
      JSON.stringify({
        defaultView: view.name,
        defaultDate: view.calendar.getDate()
      }),
      {
        days: 7
      }
    );
  }

  getCurrentDate(format = 'YYYY-MM-DD') {
    return this.$el.fullCalendar('getDate').format(format);
  }

  loading(isLoading) {
    if (!this.calendarLoadingView) {
      this.insertLoadingView();
    }

    if (isLoading && this.calendarLoadingView) {
      this.calendarLoadingView.removeClass('hide');
    } else if(this.calendarLoadingView) {
      this.calendarLoadingView.addClass('hide');
    }
  }

  eventDrop() {

  }

  select() {

  }

  eventRender() {

  }

  eventAfterRender() {

  }

  resourceRender() {

  }

  eventClick() {

  }

  eventResize() {

  }
}

{'fraction_non_alphanumeric': 0.17047431288414705, 'fraction_numerical': 0.003942943291197959, 'mean_word_length': 2.736568457538995, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 59, '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': '122173', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2773, 'n_words': 411}