Skip to content

Commit

Permalink
fix: reinstate group submission functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Sep 2, 2022
1 parent 800f4f5 commit 63702a6
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/app/api/models/groups/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
Expand All @@ -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)
Expand All @@ -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));
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/models/task-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,6 @@ export class TaskStatus {
}

public static statusClass(status: TaskStatusEnum | undefined): string {
return status?.replace(/_/g, "-");
return status?.replace(new RegExp("_", "g"), "-");
}
}
19 changes: 14 additions & 5 deletions src/app/api/services/project.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Project> {
Expand All @@ -20,7 +21,8 @@ export class ProjectService extends CachedEntityService<Project> {
private campusService: CampusService,
private userService: UserService,
private taskService: TaskService,
private taskOutcomeAlignmentService: TaskOutcomeAlignmentService
private taskOutcomeAlignmentService: TaskOutcomeAlignmentService,
private groupService: GroupService
) {
super(httpClient, API_URL);

Expand Down Expand Up @@ -112,7 +114,9 @@ export class ProjectService extends CachedEntityService<Project> {
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;
Expand All @@ -127,6 +131,7 @@ export class ProjectService extends CachedEntityService<Project> {
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();
});
}
Expand Down Expand Up @@ -160,9 +165,13 @@ export class ProjectService extends CachedEntityService<Project> {
},
{
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;
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/services/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TaskService extends CachedEntityService<Task> {
{
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
Expand Down Expand Up @@ -163,7 +163,7 @@ export class TaskService extends CachedEntityService<Task> {
public readonly rejectFutureStates = TaskStatus.REJECT_FUTURE_STATES;

public statusClass(status: TaskStatusEnum): string {
return status.replace("_", "-");
return TaskStatus.statusClass(status);
}

public readonly statusColors: Map<string, string> = TaskStatus.STATUS_COLORS;
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/services/group-service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/groups/group-member-list/group-member-list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h4>No members in group</h4>
<td class="actions" ng-if="canRemoveMembers">
<button ng-click="removeMember(member)" class="btn btn-sm btn-danger" ng-hide="project">
<i class="fa fa-minus"></i>
<span ng-hide="member.id == project.id">Kick</span>
<span ng-hide="member.id == project.id">Remove</span>
</button>
<button ng-click="removeMember(member)" class="btn btn-sm btn-danger" ng-show="member.id == project.id">
<i class="fa fa-minus"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/app/groups/group-selector/group-selector.tpl.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="panel-heading">
<h4 class="panel-title">
Groups in
Groups for
<strong ng-hide="showGroupSetSelector"> {{selectedGroupSet.name}} </strong>
<group-set-selector
ng-show="showGroupSetSelector"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<select
class="form-control"
ng-change="selectGroupSet()"
ng-options="gs as gs.name for gs in unit.groupSets track by gs.id"
ng-options="gs as gs.name for gs in unit.groupSets"
ng-model="selectedGroupSet">
</select>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ angular.module('doubtfire.tasks.modals.upload-submission-modal', [])
UploadSubmissionModal.show = (task, reuploadEvidence, isTestSubmission = false) ->
# Refuse to open modal if group task and not in a group
if !isTestSubmission && task.isGroupTask() && !task.group
alertService.add('danger', "This is a group assignment. Join a #{task.definition.groupSet.name} group set to submit this task.", 8000)
alertService.add('danger', "This is a group task. Join a #{task.definition.groupSet.name} group to submit this task.", 8000)
return null

if isTestSubmission
Expand Down

0 comments on commit 63702a6

Please sign in to comment.