Skip to content

Commit

Permalink
Removed unneeded prompts
Browse files Browse the repository at this point in the history
Enable eventFormRedirect to work more than 2 times.
Fix issue with grades starting with numbers
  • Loading branch information
chrisekelley committed Oct 31, 2023
1 parent 3382e22 commit 360a5e9
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 105 deletions.
80 changes: 46 additions & 34 deletions client/src/app/class/_services/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,9 @@ export class DashboardService {
// str = str.replace(/\s+/g, '-').
let searchTerm
if (curriculumLabel) {
searchTerm = reportDate ? type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, '-')) + '-' + reportDate : type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, '-'))
searchTerm = reportDate ? type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, '')) + '-' + reportDate : type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, ''))
} else {
searchTerm = reportDate ? type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId + '-' + reportDate : type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId
searchTerm = reportDate ? type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId + '-' + reportDate : type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId
}
const result = await this.db.allDocs({
startkey: searchTerm,
Expand All @@ -777,9 +777,9 @@ export class DashboardService {
const reportTime = DateTime.local().toISOTime()
const grade = this.getValue('grade', currentClass)
if (!curriculumLabel) {
id = type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId + '-' + reportDate + '-' + sanitize(username) + '-' + reportTime
id = type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId + '-' + reportDate + '-' + sanitize(username) + '-' + reportTime
} else {
id = type + '-' + sanitize(grade.replace(/\s+/g, '-')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, '-')) + '-' + reportDate + '-' + sanitize(username) + '-' + reportTime
id = type + '-' + sanitize(grade.replace(/\s+/g, '')) + '-' + randomId + '-' + sanitize(curriculumLabel.replace(/\s+/g, '')) + '-' + reportDate + '-' + sanitize(username) + '-' + reportTime
}
return {reportDate, grade, reportTime, id};
}
Expand All @@ -798,7 +798,7 @@ export class DashboardService {
* @param ignoreCurriculumsForTracking - for classes that teach the same students multiple subjects.
* @private
*/
async processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, students: any[], scoreUnits, currentBehaviorReport, ignoreCurriculumsForTracking: boolean = false) {
async processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, students: any[], scoreUnits, currentBehaviorReport, ignoreCurriculumsForTracking: boolean = false, curriculum) {
// return async (attendanceReport) => {
// const attendanceList = attendanceReport.doc.attendanceList
for (let i = 0; i < attendanceList.length; i++) {
Expand All @@ -823,36 +823,14 @@ export class DashboardService {
currentStudent.presentPercentage = Math.round((currentStudent.presentCount / currentStudent.reportCount) * 100)
}

// currentStudent.moodValues = currentStudent.moodValues ? currentStudent.moodValues : []
// const mood = student.mood
// if (mood) {
// switch (mood) {
// case 'happy':
// currentStudent.moodValues.push(100)
// currentStudent.moodPercentage = Math.round(currentStudent.moodValues.reduce((a, b) => a + b, 0) / currentStudent.moodValues.length)
// break
// case 'neutral':
// currentStudent.moodValues.push(66.6)
// currentStudent.moodPercentage = Math.round(currentStudent.moodValues.reduce((a, b) => a + b, 0) / currentStudent.moodValues.length)
// break
// case 'sad':
// currentStudent.moodValues.push(33.3)
// currentStudent.moodPercentage = Math.round(currentStudent.moodValues.reduce((a, b) => a + b, 0) / currentStudent.moodValues.length)
// break
// }
// }

// currentStudent['behavior'] = {}
// await this.addBehaviorRecords(currentStudent, student.id)

if (!currentStudent.score) {
if (ignoreCurriculumsForTracking) {
for (let j = 0; j < scoreReport.length; j++) {
const report = scoreReport[j].doc
this.processScoreReport(report, student, scoreUnits, ignoreCurriculumsForTracking, currentStudent);
this.processScoreReport(report, student, scoreUnits, ignoreCurriculumsForTracking, currentStudent, curriculum);
}
} else {
this.processScoreReport(scoreReport, student, scoreUnits, ignoreCurriculumsForTracking, currentStudent);
this.processScoreReport(scoreReport, student, scoreUnits, ignoreCurriculumsForTracking, currentStudent, curriculum);
}
}

Expand All @@ -874,7 +852,7 @@ export class DashboardService {
// }
}

private processScoreReport(scoreReport, student, scoreUnits, ignoreCurriculumsForTracking: boolean, currentStudent) {
private processScoreReport(scoreReport, student, scoreUnits, ignoreCurriculumsForTracking: boolean, currentStudent, curriculum) {
const currentStudentScore = scoreReport?.scoreList.find((thisStudent) => {
return thisStudent.id === student.id
})
Expand All @@ -895,24 +873,25 @@ export class DashboardService {
if (!currentStudent.scores) {
currentStudent.scores = {}
}
const curriculumId = scoreReport._id.split("-")[4]
currentStudent.scores[curriculumId] = averageScore
const curriculumLabel = sanitize(curriculum.label.replace(/\s+/g, ''))
// using bracket notation in case the curriculumId is a number.
currentStudent.scores[curriculumLabel] = averageScore
} else {
currentStudent.score = averageScore
}
}
}
}

async getRecentVisitsReport(recentVisitReports, scoreReport, allStudentScores, scoreUnits) {
async getRecentVisitsReport(recentVisitReports, scoreReport, allStudentScores, scoreUnits, curriculum) {
// do a deep clone
const recentVisitDoc = recentVisitReports[recentVisitReports.length - 1]?.doc
const currentAttendanceReport = JSON.parse(JSON.stringify(recentVisitDoc))
const currentBehaviorReport = null
for (let i = 0; i < recentVisitReports.length; i++) {
const attendanceReport = recentVisitReports[i];
const attendanceList = attendanceReport.doc.attendanceList
await this.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, null, scoreUnits, currentBehaviorReport, null)
await this.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, null, scoreUnits, currentBehaviorReport, null, curriculum)

}
// this.recentVisitsReport = currentAttendanceReport
Expand Down Expand Up @@ -1408,6 +1387,39 @@ export class DashboardService {
this.selectedClass$.next(currentClass)
return currentClass;
}

buildAttendanceReport(id: string, timestamp: number, currentClassId, grade, schoolName, schoolYear, reportDate: string, type: string, attendanceList) {
return {
_id: id,
timestamp: timestamp,
classId: currentClassId,
grade: grade,
schoolName: schoolName,
schoolYear: schoolYear,
reportDate: reportDate,
attendanceList: attendanceList,
collection: 'TangyFormResponse',
type: type,
form: {
id: type,
},
items: [{
id: 'class-registration',
title: 'Class Registration',
inputs: [{}]
},
{
id: 'item_1',
title: 'Item 1',
inputs: [{
name: 'timestamp',
label: 'timestamp'
}]
}],
complete: false
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,61 +113,26 @@ export class AttendanceCheckComponent implements OnInit {

this.attendanceList = await this.dashboardService.getAttendanceList(students, savedAttendanceList)
if (!currentAttendanceReport) {
this.attendanceRegister = {
_id: id,
timestamp: timestamp,
classId: currentClassId,
grade: grade,
schoolName: schoolName,
schoolYear: schoolYear,
reportDate: reportDate,
attendanceList: this.attendanceList,
collection: 'TangyFormResponse',
type: type,
form: {
id: type,
},
items: [{
id: 'class-registration',
title: 'Class Registration',
inputs: [{}]
},
{
id: 'item_1',
title: 'Item 1',
inputs: [{
name: 'timestamp',
label: 'timestamp'
}]
}],
complete: false
}
const startRegister = confirm(_TRANSLATE('Begin ' + registerNameForDialog + ' record for today?'))
if (startRegister) {
// const curriculum = {
// 'name': type,
// 'value': 'on',
// 'label': _TRANSLATE(registerNameForDialog)
// }
// this.currArray.push(curriculum)
// this.selectedCurriculum = this.currArray.find(x => x.name === type)
// await this.saveStudentAttendance(null)
} else {
// this.showAttendanceList = false
// if (!this.currentItemId || this.currentItemId === '') {
// const initialForm = this.curriculumFormsList[0]
// this.currentItemId = initialForm.id
// }
// await this.selectSubTask(this.currentItemId, this.currentClassId, this.curriculumId)
this.router.navigate(['/attendance-dashboard/']);
}
this.attendanceRegister = this.dashboardService.buildAttendanceReport(id, timestamp, currentClassId, grade, schoolName, schoolYear, reportDate, type, this.attendanceList);
// const startRegister = confirm(_TRANSLATE('Begin ' + registerNameForDialog + ' record for today?'))
// if (startRegister) {
// } else {
// this.router.navigate(['/attendance-dashboard/']);
// }
} else {
currentAttendanceReport.attendanceList = this.attendanceList
this.attendanceRegister = currentAttendanceReport
}
await this.saveStudentAttendance(null)
if (students.length > 0) {
await this.saveStudentAttendance(null)
} else {
const startRegister = confirm(_TRANSLATE('There are no students. Begin ' + registerNameForDialog + ' record for today anyways?'))
if (startRegister) {
await this.saveStudentAttendance(null)
}
}
}

async toggleAttendance(student) {
student.absent = !student.absent
if (student.absent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export class AttendanceDashboardComponent implements OnInit {
private async populateSummary(currentClass, curriculum) {
const classId = currentClass._id
const students = await this.dashboardService.getMyStudents(classId);
if (students.length === 0) {
alert(_TRANSLATE('You must register students before you can view the attendance dashboard.'))
this.router.navigate(['class-form'], { queryParams: {curriculum:'student-registration',classId:currentClass?._id} });
return
}
// if (students.length === 0) {
// alert(_TRANSLATE('You must register students before you can view the attendance dashboard.'))
// this.router.navigate(['class-form'], { queryParams: {curriculum:'student-registration',classId:currentClass?._id} });
// return
// }

const ignoreCurriculumsForTracking = this.dashboardService.getValue('ignoreCurriculumsForTracking', currentClass)
let curriculumLabel = curriculum?.label
Expand All @@ -97,12 +97,12 @@ export class AttendanceDashboardComponent implements OnInit {

const attendanceReports = await this.dashboardService.searchDocs('attendance', currentClass, null, curriculumLabel, randomId)
const currentAttendance = attendanceReports[attendanceReports.length - 1]
const currentAttendanceReport = currentAttendance?.doc
if (!currentAttendanceReport) {
alert(_TRANSLATE('You must take attendance before you can view the attendance dashboard.'))
this.router.navigate(['attendance-check'])
return
}
let currentAttendanceReport = currentAttendance?.doc
if (!currentAttendanceReport && students.length > 0) {
// create a new attendance report stub
const attendanceList = await this.dashboardService.getAttendanceList(students, null)
currentAttendanceReport = this.dashboardService.buildAttendanceReport(null, null, classId, null, null, null, null, 'attendance', attendanceList);
}

const studentsWithoutAttendance:any[] = students.filter((thisStudent) => {
return !currentAttendanceReport?.attendanceList.find((student) => {
Expand Down Expand Up @@ -150,7 +150,7 @@ export class AttendanceDashboardComponent implements OnInit {
for (let i = 0; i < attendanceReports.length; i++) {
const attendanceReport = attendanceReports[i];
const attendanceList = attendanceReport.doc.attendanceList
await this.dashboardService.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, students, this.units, currentBehaviorReport, ignoreCurriculumsForTracking)
await this.dashboardService.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, allStudentScores, students, this.units, currentBehaviorReport, ignoreCurriculumsForTracking, curriculum)
}
this.attendanceReport = currentAttendanceReport

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<mat-form-field>
<mat-label>{{'Change Subject'|translate}}</mat-label>
<mat-select [(value)]="curriculumId" placeholder="Select SubTask">
<mat-option>{{'None'|translate}}</mat-option>
<mat-option>{{'----'|translate}}</mat-option>
<mat-option *ngFor="let item of currArray;" value="{{item.id}}"
(click)="changeCurriculum(item.name)">{{item.label}}</mat-option>
</mat-select>
Expand Down
23 changes: 18 additions & 5 deletions client/src/app/class/class-form/class-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {ClassUtils} from "../class-utils";
import {TangyFormResponseModel} from "tangy-form/tangy-form-response-model";
Expand Down Expand Up @@ -55,8 +55,11 @@ export class ClassFormComponent implements OnInit {
private classFormService: ClassFormService,
private tangyFormService: TangyFormService,
private variableService: VariableService,
private appConfigService: AppConfigService
) { }
private appConfigService: AppConfigService,
private ref: ChangeDetectorRef
) {
ref.detach()
}

async ngOnInit(): Promise<void> {
await this.classFormService.initialize();
Expand Down Expand Up @@ -123,7 +126,7 @@ export class ClassFormComponent implements OnInit {
// For new student-registration etc.
this.formPlayer.formHtml = formHtml
}
await this.formPlayer.render()
this.ref.detectChanges()

// this.formPlayer.formEl.addEventListener('TANGY_FORM_UPDATE', async (event) => {
this.formPlayer.$afterSubmit.subscribe(async (state:any) => {
Expand Down Expand Up @@ -202,12 +205,22 @@ export class ClassFormComponent implements OnInit {

if (window['eventFormRedirect']) {
// await this.router.navigate(['case', 'event', this.caseService.case._id, this.caseEvent.id])
await this.router.navigate(['class-form'], { queryParams:
{ curriculum: this.curriculum, classId: this.classId, newForm: this.newForm, queryParamsHandling: 'preserve',
preserveFragment: true }
});
// /class-form?curriculum=student-registration&classId=' + classId + '&newForm=true';
// '/class-form?curriculum=student-registration&classId=d4605997-8a4f-4027-a52b-185e84e2454f&newForm=true'
this.router.navigateByUrl(window['eventFormRedirect'])
window['eventFormRedirect'] = ''
// Fix for double-submit of this form clearing eventFormRedirect.
if (!this.newForm) {
window['eventFormRedirect'] = ''
}
} else {
this.router.navigate([url]);
}
})
await this.formPlayer.render()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export class AttendanceComponent implements OnInit {
for (let i = 0; i < this.attendanceReports.length; i++) {
const attendanceReport = this.attendanceReports[i];
const attendanceList = attendanceReport.doc.attendanceList
await this.dashboardService.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, this.allStudentScores, null, this.units, currentBehaviorReport, this.ignoreCurriculumsForTracking)
await this.dashboardService.processAttendanceReport(attendanceList, currentAttendanceReport, scoreReport, this.allStudentScores, null, this.units, currentBehaviorReport, this.ignoreCurriculumsForTracking, this.curriculum)
}

this.attendanceReport = currentAttendanceReport
const mostRecentAttendanceReport = this.attendanceReports.slice(0 - parseInt(this.numVisits, 10))
this.recentVisitsReport = await this.dashboardService.getRecentVisitsReport(mostRecentAttendanceReport, this.scoreReport, this.allStudentScores, this.units)
this.recentVisitsReport = await this.dashboardService.getRecentVisitsReport(mostRecentAttendanceReport, this.scoreReport, this.allStudentScores, this.units, this.curriculum)
}

async getUserDB() {
Expand All @@ -147,7 +147,7 @@ export class AttendanceComponent implements OnInit {
console.log('numVisits: ', this.numVisits)
if (this.numVisits) {
const mostRecentAttendanceReport = this.attendanceReports.slice(0 - parseInt(this.numVisits, 10))
this.recentVisitsReport = await this.dashboardService.getRecentVisitsReport(mostRecentAttendanceReport, this.scoreReport, this.allStudentScores, this.units)
this.recentVisitsReport = await this.dashboardService.getRecentVisitsReport(mostRecentAttendanceReport, this.scoreReport, this.allStudentScores, this.units, this.curriculum)
}
}

Expand Down

0 comments on commit 360a5e9

Please sign in to comment.