diff --git a/src/app/api/models/groups/group.ts b/src/app/api/models/groups/group.ts index 53c37412f..41b31a5aa 100644 --- a/src/app/api/models/groups/group.ts +++ b/src/app/api/models/groups/group.ts @@ -68,7 +68,7 @@ export class Group extends Entity { return `units/${this.unit.id}/group_sets/${this.groupSet.id}/groups/${this.id}/members/${member ? member.id : ''}`; } - public addMember(member: Project) { + public addMember(member: Project, onSuccess?: () => void) { const alerts: any = AppInjector.get(alertService); if (! member) { alerts.add('danger', "The student you are trying to add to the group could not be found.", 6000) @@ -83,14 +83,17 @@ export class Group extends Entity { if (grp) { // Remove current member from old group grp.projectsCache.delete(member); + grp.studentCount--; member.groupCache.delete(grp); } // Add group to member member.groupCache.add(this); + this.studentCount++; // Has members so add this member this.projectsCache.add(member); alerts.add("success", `${member.student.name} was added to '${this.name}'`, 3000); + if ( onSuccess ) onSuccess(); }, error: (message) => alerts.add("danger", message || "Unknown Error", 6000) }) @@ -109,6 +112,7 @@ export class Group extends Entity { // Get old group.. this.projectsCache.delete(member); member.groupCache.delete(this); + this.studentCount--; alerts.add("success", `${member.student.name} was removed from '${this.name}'`, 3000); }, error: (message) => alerts.add("danger", message || "Unknown Error", 6000) @@ -121,11 +125,12 @@ export class Group extends Entity { return projectService.query({},{ endpointFormat: this.memberUri(), cache: this.unit.studentCache, + sourceCache: this.unit.studentCache, constructorParams: this.unit, onQueryCacheReturn: 'previousQuery' }).pipe( tap( - (projects) => { + (projects: Project[]) => { projects.forEach( p => this.projectsCache.add(p)); } ) diff --git a/src/app/api/models/project.ts b/src/app/api/models/project.ts index 0da5cb62f..fef1eb26e 100644 --- a/src/app/api/models/project.ts +++ b/src/app/api/models/project.ts @@ -285,7 +285,7 @@ export class Project extends Entity { } else { const groupSet = task.definition.groupSet; - this.groups.find( group => group.groupSet.id === task.definition.groupSet.id ) || + return this.groups.find( group => group.groupSet.id === task.definition.groupSet.id ) || groupSet.groups.find(group => group.projects.includes(this)); } } diff --git a/src/app/api/models/task-status.ts b/src/app/api/models/task-status.ts index c55ed0ecc..c8b64e4e7 100644 --- a/src/app/api/models/task-status.ts +++ b/src/app/api/models/task-status.ts @@ -361,6 +361,6 @@ export class TaskStatus { } public static statusClass(status: TaskStatusEnum | undefined): string { - return status?.replace(/_/g, "-"); + return status?.replace(new RegExp("_", "g"), "-"); } } diff --git a/src/app/api/services/project.service.ts b/src/app/api/services/project.service.ts index e02eecb41..92404b272 100644 --- a/src/app/api/services/project.service.ts +++ b/src/app/api/services/project.service.ts @@ -1,5 +1,5 @@ import { CachedEntityService, RequestOptions } from 'ngx-entity-service'; -import { CampusService, Project, Unit, UnitService, UserService, Task, TaskStatus } from 'src/app/api/models/doubtfire-model'; +import { CampusService, Project, Unit, UnitService, UserService } from 'src/app/api/models/doubtfire-model'; import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import API_URL from 'src/app/config/constants/apiURL'; @@ -8,6 +8,7 @@ import { Observable } from 'rxjs'; import { TaskService } from './task.service'; import { MappingProcess } from 'ngx-entity-service/lib/mapping-process'; import { TaskOutcomeAlignmentService } from './task-outcome-alignment.service'; +import { GroupService } from './group.service'; @Injectable() export class ProjectService extends CachedEntityService { @@ -20,7 +21,8 @@ export class ProjectService extends CachedEntityService { private campusService: CampusService, private userService: UserService, private taskService: TaskService, - private taskOutcomeAlignmentService: TaskOutcomeAlignmentService + private taskOutcomeAlignmentService: TaskOutcomeAlignmentService, + private groupService: GroupService ) { super(httpClient, API_URL); @@ -112,7 +114,9 @@ export class ProjectService extends CachedEntityService { toEntityFn: (data: object, key: string, entity: Project, params?: any) => { const unitService: UnitService = AppInjector.get(UnitService); const unitData = data['unit']; - return unitService.cache.getOrCreate(unitData.id, unitService, unitData); + const result = unitService.cache.getOrCreate(unitData.id, unitService, unitData); + result.studentCache.add(entity); + return result; }, toJsonFn: (entity: Project, key: string) => { return entity.unit?.id; @@ -127,6 +131,7 @@ export class ProjectService extends CachedEntityService { process.entity.unit = unitService.cache.getOrCreate(unitId, unitService, { id: unitId }); return unitService.get(unitId).subscribe(unit => { process.entity.unit = unit; + unit.studentCache.add(process.entity); process.continue(); }); } @@ -160,9 +165,13 @@ export class ProjectService extends CachedEntityService { }, { keys: 'groups', - toEntityOp: (data: object, key: string, entity: Project, params?: any) => { - data[key].each + toEntityOp: (data: object, key: string, project: Project, params?: any) => { + data[key].forEach((group) => { + const theGroup = project.unit.groupSetsCache.get(group.group_set_id).groupsCache.getOrCreate(group.id, this.groupService, group, {constructorParams: project.unit}); + project.groupCache.add(theGroup); + theGroup.projectsCache.add(project); + }) }, toJsonFn: (entity: Project, key: string) => { return entity.unit?.id; diff --git a/src/app/api/services/task.service.ts b/src/app/api/services/task.service.ts index 12b56cc30..7db203cce 100644 --- a/src/app/api/services/task.service.ts +++ b/src/app/api/services/task.service.ts @@ -66,7 +66,7 @@ export class TaskService extends CachedEntityService { { keys: 'otherProjects', toEntityOp: (data: object, key: string, entity: Task, params?: any) => { - data['other_projects'].foreEach((details) => { + data['other_projects'].forEach((details) => { const proj = entity.unit.findStudent(details.id) if (proj) { // Update the other project's task status overview @@ -163,7 +163,7 @@ export class TaskService extends CachedEntityService { public readonly rejectFutureStates = TaskStatus.REJECT_FUTURE_STATES; public statusClass(status: TaskStatusEnum): string { - return status.replace("_", "-"); + return TaskStatus.statusClass(status); } public readonly statusColors: Map = TaskStatus.STATUS_COLORS; diff --git a/src/app/common/services/group-service.coffee b/src/app/common/services/group-service.coffee index 426101b49..aeec85ba8 100644 --- a/src/app/common/services/group-service.coffee +++ b/src/app/common/services/group-service.coffee @@ -157,7 +157,7 @@ angular.module("doubtfire.common.services.group-service", [ ]) group.student_count += 1 if member.groups? # Get old group.. - grp = member.groupForGroupSet(group.groupSet()) + grp = member.groupForGroupSet(group.groupSet) if grp? grp.student_count -= 1 # Remove current member from old group diff --git a/src/app/groups/group-member-contribution-assigner/group-member-contribution-assigner.coffee b/src/app/groups/group-member-contribution-assigner/group-member-contribution-assigner.coffee index 16244c050..f9d1ed776 100644 --- a/src/app/groups/group-member-contribution-assigner/group-member-contribution-assigner.coffee +++ b/src/app/groups/group-member-contribution-assigner/group-member-contribution-assigner.coffee @@ -50,11 +50,11 @@ angular.module('doubtfire.groups.group-member-contribution-assigner', []) $scope.team.memberContributions = _.map(members, (member) -> result = { project: member, - rating: initialStars, - confRating: initialStars, + rating: $scope.initialStars, + confRating: $scope.initialStars, percent: 0 } - result.percent = memberPercentage(result, initialStars) + result.percent = memberPercentage(result, $scope.initialStars) result ) # Need the '+' to convert to number diff --git a/src/app/groups/group-member-list/group-member-list.coffee b/src/app/groups/group-member-list/group-member-list.coffee index 320b61817..fe890a0cd 100644 --- a/src/app/groups/group-member-list/group-member-list.coffee +++ b/src/app/groups/group-member-list/group-member-list.coffee @@ -44,7 +44,7 @@ angular.module('doubtfire.groups.group-member-list', []) listeners.push $scope.$watch "selectedGroup.id", (newGroupId) -> return unless newGroupId? startLoading() - $scope.canRemoveMembers = $scope.unitRole || ($scope.selectedGroup.groupSet().allowStudentsToManageGroups && !$scope.selectedGroup.locked) + $scope.canRemoveMembers = $scope.unitRole || ($scope.selectedGroup.groupSet.allowStudentsToManageGroups && !$scope.selectedGroup.locked) $scope.selectedGroup.getMembers().subscribe({ next: (members) -> diff --git a/src/app/groups/group-member-list/group-member-list.tpl.html b/src/app/groups/group-member-list/group-member-list.tpl.html index 8d36be011..f483b4acb 100644 --- a/src/app/groups/group-member-list/group-member-list.tpl.html +++ b/src/app/groups/group-member-list/group-member-list.tpl.html @@ -43,7 +43,7 @@

No members in group