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

Poc structur #304

Open
wants to merge 2 commits into
base: upl-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions domain/curriculum.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,83 @@ function curriculumInfo({ programmeTermYear = {}, curriculum }) {
}
}

function curriculumInfoFromLadok({ programmeTermYear = {}, curriculum }) {
let code = ''
let specializationName = null
let isCommon = true

const participations = {}
const isFirstSpec = false

const { programmeSpecialization, studyYears } = curriculum
const { studyYear } = programmeTermYear

if (programmeSpecialization) {
code = programmeSpecialization.programmeSpecializationCode
specializationName = programmeSpecialization.title
isCommon = false
}

const [curriculumStudyYear] = studyYears.filter(s => Math.abs(s.yearNumber) === Math.abs(studyYear))

if (curriculumStudyYear) {
for (const course of curriculumStudyYear.courses) {
if (!participations[course.Valvillkor]) participations[course.Valvillkor] = []

const termCode = course.startperiod.code.startsWith('HT') ? '1' : '2'
const year = course.startperiod.code.replace(/[^0-9]/g, '')
const term = `${year}${termCode}`

const creditsPerPeriod = [0, 0, 0, 0, 0, 0]

course.Tillfallesperioder.forEach(period => {
if (period.Lasperiodsfordelning) {
period.Lasperiodsfordelning.forEach(lasperiod => {
const periodIndex =
{
P1: 1,
P2: 2,
P3: 3,
P4: 4,
}[lasperiod.Lasperiodskod] || 0

creditsPerPeriod[periodIndex] += lasperiod.Omfattningsvarde
})
} else {
creditsPerPeriod[1] += period.Omfattningsvarde // Default to first period
}
})

participations[course.Valvillkor].push({
course: {
courseCode: course.kod,
title: course.benamning,
credits: course.omfattning.number,
formattedCredits: course.omfattning.formattedWithUnit,
educationalLevel: course.utbildningstyp?.level?.name,
electiveCondition: course.Valvillkor,
},
applicationCodes: [course.tillfalleskod],
term,
creditsPerPeriod,
})

participations[course.Valvillkor].sort((a, b) => a.term.localeCompare(b.term))
}
}

const hasInfo = Object.keys(participations).length !== 0

return {
code,
specializationName,
isCommon,
participations,
isFirstSpec,
hasInfo,
}
}

function setFirstSpec(cis) {
for (let i = 0; i < cis.length; i++) {
const ci = cis[i]
Expand All @@ -164,6 +241,7 @@ const ELECTIVE_CONDITIONS = ['ALL', 'O', 'VV', 'R', 'V']

module.exports = {
curriculumInfo,
curriculumInfoFromLadok,
setFirstSpec,
filterCourseRoundsForNthYear,
ELECTIVE_CONDITIONS,
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions public/js/app/pages/Appendix1.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { courseLink } from '../util/links'
function CourseListTableRow({ course }) {
const { language } = useStore()
const t = translate(language)
const { code, name, comment, credits, creditAbbr, level } = course
const { code, name, comment, credits, creditAbbr, formattedCredits, formattedLevel, level } = course

const courselink = courseLink(code, language)
return (
Expand All @@ -33,8 +33,10 @@ function CourseListTableRow({ course }) {
<a href={courselink}>{name}</a>
{comment && <b className="course-comment">{comment}</b>}
</td>
<td className="credits">{`${formatCredits(language, credits)} ${creditAbbr}`}</td>
<td className="level">{`${t('programme_edulevel')[level]}`}</td>
<td className="credits">
{formattedCredits ? formattedCredits : `${formatCredits(language, credits)} ${creditAbbr}`}
</td>
<td className="level">{formattedLevel ? formattedLevel : `${t('programme_edulevel')[level]}`}</td>
</tr>
)
}
Expand All @@ -44,8 +46,10 @@ const courseType = PropTypes.shape({
name: PropTypes.string.isRequired,
comment: PropTypes.oneOfType([PropTypes.string, undefined]).isRequired,
credits: PropTypes.number.isRequired,
creditAbbr: PropTypes.string.isRequired,
level: PropTypes.string.isRequired,
creditAbbr: PropTypes.string,
formattedCredits: PropTypes.string,
level: PropTypes.string,
formattedLevel: PropTypes.string,
})

CourseListTableRow.propTypes = {
Expand Down
14 changes: 10 additions & 4 deletions public/js/app/pages/Curriculum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ function CourseTableRow({
creditsPerPeriod,
}) {
const { language } = useStore()
console.log('here', credits)
return (
<tr>
<td>{courseNameCellData}</td>
<td className="text-center">{applicationCodeCellData}</td>
<td className="text-right credits">{`${formatCredits(language, credits)} ${creditUnitAbbr}`}</td>
<td className="text-right credits">
{creditUnitAbbr ? `${formatCredits(language, credits)} ${creditUnitAbbr}` : credits}
</td>
<CourseTablePeriodCols language={language} creditsPerPeriod={creditsPerPeriod} courseCode={courseCode} />
</tr>
)
Expand All @@ -59,8 +62,11 @@ function CourseTableRows({ participations }) {
return participations.map(participation => {
const { course, applicationCodes, term, creditsPerPeriod } = participation

const { courseCode, title, credits, creditUnitAbbr, comment } = course
const translatedCreditUnitAbbr = translateCreditUnitAbbr(language, creditUnitAbbr)
console.log(course)

const { courseCode, title, credits, formattedCredits, creditUnitAbbr, comment } = course
let translatedCreditUnitAbbr
if (!formattedCredits) translatedCreditUnitAbbr = translateCreditUnitAbbr(language, creditUnitAbbr)
const currentTerm = getCurrentTerm()
const courseNameCellData = (
<>
Expand All @@ -75,7 +81,7 @@ function CourseTableRows({ participations }) {
courseCode={courseCode}
courseNameCellData={courseNameCellData}
applicationCodeCellData={applicationCodeCellData}
credits={credits}
credits={formattedCredits ? formattedCredits : credits}
creditUnitAbbr={translatedCreditUnitAbbr}
creditsPerPeriod={creditsPerPeriod}
/>
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/appendix1Ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ async function getIndex(req, res, next) {
const options = { applicationStore, lang, programmeCode, term }
log.info(`Starting to fill in application store ${storeId} on server side `, { programmeCode })

const { programmeName } = await fetchAndFillProgrammeDetails(options, storeId)
const { programmeName, tillfalleUid } = await fetchAndFillProgrammeDetails(options, storeId)

fillStoreWithQueryParams(options)
await fetchAndFillCurriculumList(options)
await fetchAndFillCurriculumList(options, tillfalleUid)
const compressedStoreCode = getCompressedStoreCode(applicationStore)
log.info(`${storeId} store was filled in and compressed on server side`, { programmeCode })

Expand Down
4 changes: 2 additions & 2 deletions server/controllers/appendix2Ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ async function getIndex(req, res, next) {
const options = { applicationStore, lang, programmeCode, term }

log.info(`Starting to fill application store, for ${storeId}`)
const { programmeName } = await fetchAndFillProgrammeDetails(options, storeId)
const { programmeName, tillfalleUid } = await fetchAndFillProgrammeDetails(options, storeId)
fillStoreWithQueryParams(options)
await fetchAndFillSpecializations(options)
await fetchAndFillSpecializations(options, tillfalleUid)
const compressedStoreCode = getCompressedStoreCode(applicationStore)
log.info(`${storeId} store was filled in and compressed on server side`)

Expand Down
38 changes: 26 additions & 12 deletions server/controllers/curriculumCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const { server: serverConfig } = require('../configuration')
const i18n = require('../../i18n')

const koppsApi = require('../kopps/koppsApi')
const { curriculumInfo, setFirstSpec } = require('../../domain/curriculum')
const { curriculumInfo, curriculumInfoFromLadok, setFirstSpec } = require('../../domain/curriculum')
const { calculateStartTerm } = require('../../domain/academicYear')

const { createProgrammeBreadcrumbs } = require('../utils/breadcrumbUtil')
const { getServerSideFunctions } = require('../utils/serverSideRendering')
const { programmeFullName } = require('../utils/programmeFullName')

const { getProgramStructure, getActiveProgramTillfalle } = require('../ladok/ladokApi')

const {
fillStoreWithQueryParams,
fetchAndFillProgrammeDetails,
Expand Down Expand Up @@ -79,21 +81,32 @@ function _compareCurriculum(a, b) {
* @param {string} options.term
* @param {string} storeId
*/
async function _fetchAndFillCurriculumByStudyYear(options, storeId) {
async function _fetchAndFillCurriculumByStudyYear(options, storeId, tillfalleUid) {
const { applicationStore, lang, programmeCode, studyYear, term } = options
const { studyProgrammeId, statusCode } = await fetchAndFillStudyProgrammeVersion({ ...options, storeId })
if (!studyProgrammeId) {
_setErrorMissingAdmission(applicationStore, statusCode)
return
} // react NotFound
const { curriculums, statusCode: secondStatusCode } = await koppsApi.listCurriculums(studyProgrammeId, lang)
applicationStore.setStatusCode(secondStatusCode)
if (secondStatusCode !== 200) return // react NotFound

const curriculumsWithCourseRounds = await _addCourseRounds(curriculums, programmeCode, term, studyYear, lang)
applicationStore.setCurriculums(curriculumsWithCourseRounds)
const curriculumInfos = curriculumsWithCourseRounds
.map(curriculum => curriculumInfo({ programmeTermYear: { programStartTerm: term, studyYear }, curriculum }))

let curriculumData

if (tillfalleUid) {
curriculumData = await getProgramStructure(tillfalleUid, lang)
} else {
const { curriculums, statusCode: secondStatusCode } = await koppsApi.listCurriculums(studyProgrammeId, lang)
applicationStore.setStatusCode(secondStatusCode)
if (secondStatusCode !== 200) return // react NotFound
curriculumData = await _addCourseRounds(curriculums, programmeCode, term, studyYear, lang)
}

applicationStore.setCurriculums(curriculumData)
const curriculumInfos = curriculumData
.map(curriculum => {
if (tillfalleUid)
return curriculumInfoFromLadok({ programmeTermYear: { programStartTerm: term, studyYear }, curriculum })
else return curriculumInfo({ programmeTermYear: { programStartTerm: term, studyYear }, curriculum })
})
.filter(ci => ci.hasInfo)
curriculumInfos.sort(_compareCurriculum)
setFirstSpec(curriculumInfos)
Expand Down Expand Up @@ -134,10 +147,11 @@ async function getIndex(req, res, next) {
const options = { applicationStore, lang, programmeCode, term, studyYear }

log.info(`Starting to fill in application store ${storeId} on server side `, { programmeCode })
const { programmeName } = await fetchAndFillProgrammeDetails(options, storeId)

const { programmeName, tillfalleUid } = await fetchAndFillProgrammeDetails(options, storeId)

fillStoreWithQueryParams(options)
await _fetchAndFillCurriculumByStudyYear(options, storeId)
await _fetchAndFillCurriculumByStudyYear(options, storeId, tillfalleUid)

const compressedStoreCode = getCompressedStoreCode(applicationStore)
log.info(`${storeId} store was filled in and compressed`, { programmeCode })
Expand Down
14 changes: 14 additions & 0 deletions server/ladok/ladokApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ async function searchCourses(pattern, lang) {
return courses
}

async function getActiveProgramTillfalle(programCode, startPeriod, lang) {
const client = createApiClient(serverConfig.ladokMellanlagerApi)
const courses = await client.getActiveProgramTillfalle(programCode, startPeriod, lang)
return courses
}

async function getProgramStructure(programCode, lang) {
const client = createApiClient(serverConfig.ladokMellanlagerApi)
const courses = await client.getUtbildningstilfalleStructure(programCode, lang)
return courses
}

module.exports = {
searchCourses,
getProgramStructure,
getActiveProgramTillfalle,
}
Loading