mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
Merge branch 'trunk' of github.com:UniversityOfHelsinkiCS/oodikone into trunk
This commit is contained in:
@@ -108,11 +108,6 @@ const formatStudentForPopulationStatistics = ({
|
||||
const dateMonthsFromNow = (date, months) => moment(date).add(months, 'months').format('YYYY-MM-DD')
|
||||
|
||||
const getStudentsIncludeCoursesBetween = async (studentnumbers, startDate, endDate, studyright, tag) => {
|
||||
const tagQuery = tag ? {
|
||||
tag_id: {
|
||||
[Op.eq]: tag
|
||||
}
|
||||
} : null
|
||||
|
||||
const creditsOfStudentOther = {
|
||||
student_studentnumber: {
|
||||
@@ -222,7 +217,6 @@ const getStudentsIncludeCoursesBetween = async (studentnumbers, startDate, endDa
|
||||
{
|
||||
model: TagStudent,
|
||||
attributes: ['id'],
|
||||
where: tagQuery,
|
||||
include: [
|
||||
{
|
||||
model: Tag,
|
||||
@@ -236,8 +230,20 @@ const getStudentsIncludeCoursesBetween = async (studentnumbers, startDate, endDa
|
||||
studentnumber: {
|
||||
[Op.in]: studentnumbers
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
if (tag) {
|
||||
const studentsWithSearchedTag = {}
|
||||
students.forEach(student => {
|
||||
if (student.tag_students.some(t => t.tag.tag_id === tag)) {
|
||||
studentsWithSearchedTag[student.studentnumber] = true
|
||||
}
|
||||
})
|
||||
|
||||
return students.filter(student => studentsWithSearchedTag[student.studentnumber])
|
||||
}
|
||||
return students
|
||||
}
|
||||
|
||||
@@ -308,6 +314,7 @@ const studentnumbersWithAllStudyrightElements = async (studyRights, startDate, e
|
||||
}
|
||||
|
||||
const parseQueryParams = query => {
|
||||
// tagYear not a good variable name, need to change it
|
||||
const { semesters, studentStatuses, studyRights, months, year, tagYear } = query
|
||||
const startDate = semesters.includes('FALL') ?
|
||||
`${tagYear}-${semesterStart[semesters.find(s => s === 'FALL')]}` :
|
||||
|
||||
@@ -162,7 +162,6 @@ class PopulationSearchForm extends Component {
|
||||
handleYearSelection = (momentYear) => {
|
||||
const { query } = this.state
|
||||
const { studyProgrammes } = this.props
|
||||
|
||||
if (!moment.isMoment(momentYear)) {
|
||||
this.setState({
|
||||
momentYear: null,
|
||||
@@ -221,16 +220,21 @@ class PopulationSearchForm extends Component {
|
||||
}
|
||||
|
||||
handleTagSearch = (event, { value }) => {
|
||||
this.setState({
|
||||
selectedTag: value
|
||||
})
|
||||
}
|
||||
|
||||
handleTagYearSelect = (momentYear) => {
|
||||
const { query } = this.state
|
||||
const months = this.getMonths('2015', new Date(), 'FALL')
|
||||
const months = this.getMonths(reformatDate(momentYear, YEAR_DATE_FORMAT), new Date(), 'FALL')
|
||||
this.setState({
|
||||
query: {
|
||||
...query,
|
||||
year: '2018',
|
||||
tagYear: '2015',
|
||||
tagYear: reformatDate(momentYear, YEAR_DATE_FORMAT),
|
||||
year: reformatDate(new Date(), YEAR_DATE_FORMAT),
|
||||
months
|
||||
},
|
||||
selectedTag: value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -562,7 +566,7 @@ class PopulationSearchForm extends Component {
|
||||
|
||||
const { translate, tags } = this.props
|
||||
const { query } = this.state
|
||||
const { semesters, studentStatuses } = query
|
||||
const { semesters, studentStatuses, tagYear } = query
|
||||
const options = this.state.isAdmin ? tags.map(tag => ({ key: tag.tag_id, text: tag.tagname, value: tag.tag_id })) : null
|
||||
|
||||
return (
|
||||
@@ -629,6 +633,17 @@ class PopulationSearchForm extends Component {
|
||||
options={options}
|
||||
onChange={this.handleTagSearch}
|
||||
/>
|
||||
<Datetime
|
||||
className="yearSelectInput"
|
||||
control={Datetime}
|
||||
dateFormat={YEAR_DATE_FORMAT}
|
||||
timeFormat={false}
|
||||
renderYear={(props, selectableYear) => <td {...props}>{`${selectableYear}-${selectableYear + 1}`}</td>}
|
||||
closeOnSelect
|
||||
value={`${tagYear}-${moment().year(tagYear).add(1, 'years').format('YYYY')}`}
|
||||
isValidDate={this.validYearCheck}
|
||||
onChange={this.handleTagYearSelect}
|
||||
/>
|
||||
<Button onClick={() => this.fetchPopulation(this.state.query, this.state.selectedTag)}> Search by tag</Button>
|
||||
</div>) : null}
|
||||
</Form.Field>
|
||||
|
||||
Reference in New Issue
Block a user