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

refactor(DiscussionShowWorkComponent): Extract common function to show/hide posts #1485

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[response]="componentState"
[numReplies]="componentState.replies.length"
[mode]="'grading'"
(deleteButtonClicked)="deleteButtonClicked($event)"
(undoDeleteButtonClicked)="undoDeleteButtonClicked($event)"
(deleteButtonClicked)="hidePost($event)"
(undoDeleteButtonClicked)="showPost($event)"
[isDisabled]="true"
class="post"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,8 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
* the class from seeing the post.
* @param componentState the student component state the teacher wants to delete.
*/
deleteButtonClicked(componentState: any): void {
const toWorkgroupId = componentState.workgroupId;
const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId);
const periodId = userInfo.periodId;
const teacherUserInfo = this.ConfigService.getMyUserInfo();
const fromWorkgroupId = teacherUserInfo.workgroupId;
const runId = this.ConfigService.getRunId();
const nodeId = this.nodeId;
const componentId = this.componentId;
const studentWorkId = componentState.id;
const data = {
action: 'Delete'
};
const annotation = this.AnnotationService.createInappropriateFlagAnnotation(
runId,
periodId,
nodeId,
componentId,
fromWorkgroupId,
toWorkgroupId,
studentWorkId,
data
);
this.AnnotationService.saveAnnotation(annotation).then(() => {
const componentStates = this.TeacherDiscussionService.getPostsAssociatedWithComponentIdsAndWorkgroupId(
this.getGradingComponentIds(),
this.workgroupId
);
const annotations = this.getInappropriateFlagAnnotationsByComponentStates(componentStates);
this.setClassResponses(componentStates, annotations);
});
protected hidePost(componentState: any): void {
this.flagPost(componentState, 'Delete');
}

/**
Expand All @@ -146,7 +117,11 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
* This will make the post visible to the students.
* @param componentState the student component state the teacher wants to show again.
*/
undoDeleteButtonClicked(componentState: any): any {
protected showPost(componentState: any): void {
this.flagPost(componentState, 'Undo Delete');
}

private flagPost(componentState: any, action: 'Delete' | 'Undo Delete'): void {
const toWorkgroupId = componentState.workgroupId;
const userInfo = this.ConfigService.getUserInfoByWorkgroupId(toWorkgroupId);
const periodId = userInfo.periodId;
Expand All @@ -157,7 +132,7 @@ export class DiscussionShowWorkComponent extends ComponentShowWorkDirective {
const componentId = this.componentId;
const studentWorkId = componentState.id;
const data = {
action: 'Undo Delete'
action: action
};
const annotation = this.AnnotationService.createInappropriateFlagAnnotation(
runId,
Expand Down
Loading