<commit_before>'use strict';

import * as _ from 'lodash'
import * as React from 'react'

import Course from './course.es6'
import Semester from './semester.es6'

import findFirstAvailableSemester from '../helpers/findFirstAvailableSemester.es6'
import calculateNextScheduleId from '../helpers/calculateNextScheduleId.es6'

var isCurrentYearSchedule = _.curry((year, schedule) => {
	return (schedule.year === year)
})

var Year = React.createClass({
	displayName: 'Year',
	canAddSemester() {
		return findFirstAvailableSemester(this.props.schedules.data, this.props.year) <= 5
	},

	addSemester() {
		var nextAvailableSemester = findFirstAvailableSemester(this.props.schedules.data, this.props.year)

		this.props.schedules.create({
			year: this.props.year, semester: nextAvailableSemester,
			sequence: 1, active: true,
		})
	},

	removeYear() {
		var currentYearSchedules = _.filter(this.props.schedules.data, isCurrentYearSchedule(this.props.year))
		var scheduleIds = _.pluck(currentYearSchedules, 'id')

		this.props.schedules.destroyMultiple(scheduleIds)
	},

	render() {
		var thisYearSchedules = this.props.schedules.byYear[this.props.year]
		let schedules = _.chain(thisYearSchedules).filter('active').groupBy('semester').value()

		var terms = _.map(schedules, function(schedule, semester) {
			semester = parseInt(semester, 10)
			return React.createElement(Semester, {
				key: semester,
				ref: semester,
				semester: semester,
				year: this.props.year,
				schedules: this.props.schedules,
			})
		}, this)

		return React.createElement('div', {className: 'year'},
			React.createElement('header', {className: 'year-title'},
				React.createElement('h1', null, this.props.year + ' + ' + (this.props.year + 1)),
				React.createElement('button', {
					className: 'remove-year',
					title: 'Remove the year ' + this.props.year,
					onClick: this.removeYear,
				})
			),
			React.createElement('div', {className: 'semester-list'}, terms),
			React.createElement('button', {
				className: 'add-semester',
				title: 'Add Semester',
				disabled: !this.canAddSemester(),
				onClick: this.addSemester,
			})
		)
	}
})

export default Year<commit_msg>Use expandYear in Year<commit_after>'use strict';

import * as _ from 'lodash'
import * as React from 'react'

import Course from './course.es6'
import Semester from './semester.es6'

import {expandYear} from '../helpers/semesterName.es6'
import findFirstAvailableSemester from '../helpers/findFirstAvailableSemester.es6'
import calculateNextScheduleId from '../helpers/calculateNextScheduleId.es6'

var isCurrentYearSchedule = _.curry((year, schedule) => {
	return (schedule.year === year)
})

var Year = React.createClass({
	displayName: 'Year',
	canAddSemester() {
		return findFirstAvailableSemester(this.props.schedules.data, this.props.year) <= 5
	},

	addSemester() {
		var nextAvailableSemester = findFirstAvailableSemester(this.props.schedules.data, this.props.year)

		this.props.schedules.create({
			year: this.props.year, semester: nextAvailableSemester,
			sequence: 1, active: true,
		})
	},

	removeYear() {
		var currentYearSchedules = _.filter(this.props.schedules.data, isCurrentYearSchedule(this.props.year))
		var scheduleIds = _.pluck(currentYearSchedules, 'id')

		this.props.schedules.destroyMultiple(scheduleIds)
	},

	render() {
		var thisYearSchedules = this.props.schedules.byYear[this.props.year]
		let schedules = _.chain(thisYearSchedules).filter('active').groupBy('semester').value()

		var terms = _.map(schedules, function(schedule, semester) {
			semester = parseInt(semester, 10)
			return React.createElement(Semester, {
				key: semester,
				ref: semester,
				semester: semester,
				year: this.props.year,
				schedules: this.props.schedules,
			})
		}, this)

		return React.createElement('div', {className: 'year'},
			React.createElement('header', {className: 'year-title'},
				React.createElement('h1', null, expandYear(this.props.year)),
				React.createElement('button', {
					className: 'remove-year',
					title: 'Remove the year ' + this.props.year,
					onClick: this.removeYear,
				})
			),
			React.createElement('div', {className: 'semester-list'}, terms),
			React.createElement('button', {
				className: 'add-semester',
				title: 'Add Semester',
				disabled: !this.canAddSemester(),
				onClick: this.addSemester,
			})
		)
	}
})

export default Year
{'fraction_non_alphanumeric': 0.14223744292237442, 'fraction_numerical': 0.0045662100456621, 'mean_word_length': 4.4694132334581775, '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': '3178902', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1374, 'n_words': 274}