Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

course statistics url #979

Merged
merged 10 commits into from
Jun 4, 2019
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"cypress:open": "CYPRESS_baseUrl=http://localhost:8081 cypress open",
"cypress:run": "CYPRESS_baseUrl=http://localhost:8081 cypress run --config video=false -P ./",
"cypress:record": "cypress run --config videoUploadOnPasses=false --record -P ./",
"cypress:record": "cypress run --config videoUploadOnPasses=false -P ./",
"concurrently": "concurrently",
"test": "./run_all_tests.sh",
"test_services": "./run_service_tests.sh"
Expand Down
13 changes: 4 additions & 9 deletions services/backend/oodikone2-backend/src/database/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ const conf = require('../conf-backend')
const sequelize = new Sequelize(conf.DB_URL, {
schema: conf.DB_SCHEMA,
logging: false,
operatorsAliases: false,
dialectOptions: {
prependSearchPath: true
}
operatorsAliases: false
})
sequelize.query(`SET SESSION search_path to ${conf.DB_SCHEMA}`)

const sequelizeKone = new Sequelize(conf.DB_URL, {
schema: conf.DB_SCHEMA_KONE,
logging: false,
operatorsAliases: false,
searchPath: conf.DB_SCHEMA_KONE,
dialectOptions: {
prependSearchPath: true
}
operatorsAliases: false
})
sequelizeKone.query(`SET SESSION search_path to ${conf.DB_SCHEMA_KONE}`) // See https://github.com/sequelize/sequelize/issues/10875

const runMigrations = async () => {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { Component } from 'react'
import { Segment, Header, Form } from 'semantic-ui-react'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import qs from 'query-string'
import { func, arrayOf, shape, bool } from 'prop-types'
import { getSemesters } from '../../../redux/semesters'
import { clearCourses, findCoursesV2 } from '../../../redux/coursesearch'
import { getCourseStats } from '../../../redux/coursestats'
import { getCourseStats, clearCourseStats } from '../../../redux/coursestats'
import AutoSubmitSearchInput from '../../AutoSubmitSearchInput'
import CourseTable from '../CourseTable'
import { getCourseSearchResults } from '../../../selectors/courses'
Expand All @@ -30,8 +32,23 @@ class SearchForm extends Component {
}

componentDidMount() {
this.props.getSemesters()
this.props.clearCourses()
const { location } = this.props
if (location.search) {
console.log(location.search)
this.fetchStatisticsFromUrlParams()
} else {
this.props.getSemesters()
this.props.clearCourses()
}
}

componentDidUpdate(prevProps) {
const { location } = this.props
const queryParamsChanged = prevProps.location.search !== this.props.location.search
if (location.search && queryParamsChanged) {
console.log('shiiiii')
this.fetchStatisticsFromUrlParams()
}
}

onSelectCourse = (course) => {
Expand Down Expand Up @@ -69,7 +86,36 @@ class SearchForm extends Component {
separate
}

await this.props.getCourseStats(params)
// await this.props.getCourseStats(params)
this.pushQueryToUrl(params)
}

fetchStatisticsFromUrlParams() {
const query = this.parseQueryFromUrl()
this.setState({ query })
this.props.getCourseStats(query)
}

pushQueryToUrl = (query) => {
const { history } = this.props
const { courseCodes, ...rest } = query
const queryObject = { ...rest, courseCodes: JSON.stringify(courseCodes) }
const searchString = qs.stringify(queryObject)
history.push({ search: searchString })
}

parseQueryFromUrl = () => {
const { location } = this.props
const { courseCodes, fromYear, toYear, separate, ...rest } = qs.parse(location.search)
const query = {
...this.state.INITIAL,
...rest,
courseCodes: JSON.parse(courseCodes),
fromYear: JSON.parse(fromYear),
toYear: JSON.parse(toYear),
separate: JSON.parse(separate)
}
return query
}

fetchCourses = () => {
Expand Down Expand Up @@ -103,7 +149,7 @@ class SearchForm extends Component {
coursename,
coursecode
} = this.state

console.log(this.state)
const courses = matchingCourses.filter(c => !selectedcourses[c.code])

const disabled = (!fromYear || Object.keys(selectedcourses).length === 0) || isLoading
Expand Down Expand Up @@ -187,7 +233,9 @@ SearchForm.propTypes = {
matchingCourses: arrayOf(shape({})).isRequired,
years: arrayOf(shape({})).isRequired,
isLoading: bool.isRequired,
coursesLoading: bool.isRequired
coursesLoading: bool.isRequired,
history: shape({}).isRequired,
location: shape({}).isRequired
}

const mapStateToProps = (state) => {
Expand All @@ -205,9 +253,10 @@ const mapStateToProps = (state) => {
}
}

export default connect(mapStateToProps, {
export default withRouter(connect(mapStateToProps, {
getSemesters,
getCourseStats,
clearCourses,
findCoursesV2
})(SearchForm)
findCoursesV2,
clearCourseStats
})(SearchForm))
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ class PopulationStudents extends Component {

const priorityText = (studyRights) => {
const codes = this.studyrightCodes(studyRights, 'prioritycode')
return codes.map(code => PRIORITYCODE_TEXTS[code] ? PRIORITYCODE_TEXTS[code] : code).join(', ') // eslint-disable-line
return codes.map(code => (PRIORITYCODE_TEXTS[code] ? PRIORITYCODE_TEXTS[code] : code)).join(', ')
}

const extentCodes = (studyRights) => {
const codes = this.studyrightCodes(studyRights, 'extentcode')
return codes.join(', ') // eslint-disable-line
return codes.join(', ')
}

const studytrack = studyrights => (
Expand Down Expand Up @@ -290,22 +290,29 @@ class PopulationStudents extends Component {
['asc', 'asc']
)

const labelColumns = []
if (mandatoryCourseLabels.reduce((acc, e) => acc + e.length, 0) > 0) {
labelColumns.push(
{
key: 'general',
title: <b>Labels:</b>,
parent: true,
headerProps: { colSpan: nameColumns.length, style: { textAlign: 'right' } }
},
...mandatoryCourseLabels.map(e => ({
key: e,
title: (
<div style={{ overflowX: 'hidden' }}><div style={{ width: 0 }}>{e}</div></div>
),
parent: true,
headerProps: { colSpan: labelToMandatoryCourses[e].length, width: labelToMandatoryCourses[e].length, title: e }
}))
)
}

const mandatoryCourseColumns = [
...nameColumns,
...(mandatoryCourseLabels.reduce((acc, e) => acc + e.length, 0) > 0) ? [{
key: 'general',
title: <b>Labels:</b>,
parent: true,
headerProps: { colSpan: nameColumns.length, style: { textAlign: 'right' } }
}] : [],
...mandatoryCourseLabels.map(e => ({
key: e,
title: (
<div style={{ overflowX: 'hidden' }}><div style={{ width: 0 }}>{e}</div></div>
),
parent: true,
headerProps: { colSpan: labelToMandatoryCourses[e].length, width: labelToMandatoryCourses[e].length, title: e }
})),
...labelColumns,
..._.flatten(mandatoryCourseLabels.map(e => _.sortBy(
labelToMandatoryCourses[e],
[(m) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class StudyProgrammeSelector extends Component {
getRowKey={programme => programme.code}
getRowProps={programme => ({ onClick: () => this.props.handleSelect(programme.code), style: { cursor: 'pointer' } })}
data={studyprogrammes}
defaultdescending
/>
)
}
Expand Down