Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Adicionado suporte parcial a UNILAB - CE #34

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Adicionado suporte a local de aula do semestre atual
  • Loading branch information
Diassisfilho committed Jan 21, 2024
commit 53296f5a280a811250481e09906e6385d22fc853
87 changes: 87 additions & 0 deletions src/bonds/sigaa-student-bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface StudentBond {
* @param allPeriods if true, all courses will be returned; otherwise, only current courses.
* @returns Promise with array of courses.
*/
getCoursesLocal(): Promise<Record<string, string>[]>;

getCourses(allPeriods?: boolean): Promise<CourseStudent[]>;

getActivities(): Promise<Activity[]>;
Expand Down Expand Up @@ -69,6 +71,84 @@ export class SigaaStudentBond implements StudentBond {

readonly type = 'student';
private _currentPeriod?: string;

async getCoursesLocal(): Promise<Record<string, string>[]> {
const frontPage = await this.http.get(
'/sigaa/portais/discente/discente.jsf'
);

const coursesLocal = [];

const table = frontPage.$('#turmas-portal table:nth-child(3)');
if (table.length === 0) return [];

const rows = table.find('tbody > tr').toArray();

const tableColumnIndexs: Record<string, null | number> = {
title: null,
classLocal: null,
schedule: null
};

let tableHeaderCellElements = table.find('thead > tr td').toArray();
if (!tableHeaderCellElements.length)
tableHeaderCellElements = table.find('thead > tr th').toArray();

for (let column = 0; column < tableHeaderCellElements.length; column++) {
const cellContent = this.parser.removeTagsHtml(
frontPage.$(tableHeaderCellElements[column]).html()
);
switch (cellContent) {
case 'Componente Curricular':
tableColumnIndexs.title = column;
break;
case 'Local':
tableColumnIndexs.classLocal = column;
break;
case 'Horário':
tableColumnIndexs.schedule = column;
break;
}
}

if (tableColumnIndexs.title == null) {
throw new Error(
'SIGAA: Invalid courses table, could not find the column with class titles.'
);
}
if (tableColumnIndexs.classLocal == null) {
throw new Error(
'SIGAA: Invalid courses table, could not find the column with class local.'
);
}
if (tableColumnIndexs.schedule == null) {
throw new Error(
'SIGAA: Invalid courses table, could not find the column with class schedules.'
);
}

for (const row of rows) {
const cellElements = frontPage.$(row).find('td');
const title = this.parser.removeTagsHtml(
cellElements.eq(tableColumnIndexs.title).html()
);
const classLocal = this.parser.removeTagsHtml(
cellElements.eq(tableColumnIndexs.classLocal).html()
);
const schedule = this.parser.removeTagsHtml(
cellElements.eq(tableColumnIndexs.schedule).html()
);

const courseData = {
title,
classLocal,
schedule
};
coursesLocal.push(courseData);
}
return coursesLocal;
}

/**
* Get courses, in IFSC it is called "Turmas Virtuais".
* @param allPeriods if true, all courses will be returned; otherwise, only latest courses.
Expand Down Expand Up @@ -164,6 +244,8 @@ export class SigaaStudentBond implements StudentBond {
'SIGAA: Invalid courses table, could not find the column with class schedules.'
);
}

let coursesLocal = await this.getCoursesLocal();
let period;

for (const row of rows) {
Expand All @@ -177,6 +259,10 @@ export class SigaaStudentBond implements StudentBond {

const [code, ...titleSlices] = fullname.split(' - ');
const title = titleSlices.join(' - ');
let local;
for (const cl of coursesLocal) {
if (title === cl.title) local = cl.classLocal;
}
const buttonCoursePage = cellElements
.eq(tableColumnIndexs.button)
.find('a[onclick]');
Expand Down Expand Up @@ -208,6 +294,7 @@ export class SigaaStudentBond implements StudentBond {
title,
code,
schedule,
classLocal: local,
numberOfStudents,
period,
id,
Expand Down
16 changes: 15 additions & 1 deletion src/courses/sigaa-course-student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface CourseStudentData {
numberOfStudents: number;
period: string;
schedule: string;
classLocal?: string;
form: SigaaForm;
}

Expand Down Expand Up @@ -84,6 +85,13 @@ export interface CourseStudent {
*/
readonly schedule: string;

/**
* Course class local.
*
* Local das aulas.
*/
readonly classLocal: string | undefined;

/**
* Number of students, is 0 if the course of the period is not the current one.
*/
Expand Down Expand Up @@ -186,6 +194,11 @@ export class SigaaCourseStudent implements CourseStudent {
*/
readonly schedule;

/**
* @inheritdoc
*/
readonly classLocal;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -217,6 +230,7 @@ export class SigaaCourseStudent implements CourseStudent {
this.numberOfStudents = courseData.numberOfStudents;
this.period = courseData.period;
this.schedule = courseData.schedule;
this.classLocal = courseData.classLocal;
this.form = courseData.form;

this.resources = resourcesManagerFactory.createCourseResourcesManager(
Expand Down Expand Up @@ -310,7 +324,7 @@ export class SigaaCourseStudent implements CourseStudent {
let pageCourseCode: string | undefined;

if (buttonLabel === 'Ver Notas') {
if (page.bodyDecoded.includes('Ainda não foram')) {
if (page.bodyDecoded.includes('Ainda não foram lançadas notas.')) {
pageCourseCode = this.parser
.removeTagsHtml(page.$('#linkCodigoTurma').html())
.replace(/ -$/, '');
Expand Down