diff --git a/src/app/teacher/create-run-dialog/create-run-dialog.component.html b/src/app/teacher/create-run-dialog/create-run-dialog.component.html index 7a4fb172b0c..46792bc3869 100644 --- a/src/app/teacher/create-run-dialog/create-run-dialog.component.html +++ b/src/app/teacher/create-run-dialog/create-run-dialog.component.html @@ -1,30 +1,30 @@ -

Use with Class

-
- -

- {{ project.metadata.title }} (Unit ID: {{ project.id }}) -

-

1. Choose Periods

-

- - - {{ control.controls.name.value }} + +

Use with Class

+ + +

+ {{ project.metadata.title }} (Unit ID: {{ project.id }}) +

+

1. Choose Periods

+

+ + + {{ control.controls.name.value }} + + +

+ + Add your own periods + + For "Period 9", just enter the number 9. Separate periods with commas (e.g. "Section 1, Section + 2"). Manually named periods should be no more than 16 characters long. + + +

+

+ + Randomly assign students to periods - -

- - Add your own periods - - For "Period 9", just enter the number 9. Separate periods with commas (e.g. "Section 1, - Section 2"). Manually named periods should be no more than 16 characters long. - - -

-

- - Randomly assign students to periods -

2. Choose Students Per Team

@@ -36,40 +36,20 @@

2. Choose Students Per Team

3. Set Schedule

- + Start date - + Start date is required
- + End date - + @@ -101,6 +81,7 @@

3. Set Schedule

+

Run Created.

Success! This unit has been added to your Class Schedule.

@@ -115,18 +96,40 @@

3. Set Schedule

You can always find the Access Code for each classroom unit in your Class Schedule.

+
+ + + + Link to a CK Board Project + Connected to CK Board Project + + + Click to connect to a CK Board Project + Code: {{linkedCkProjectControl.value}} + + +
+ + SCORE-CK Connect Code + + + + + +

Note: You can always manage CK Board Project linkining in Run Settings.

+
+
- -
+ \ No newline at end of file diff --git a/src/app/teacher/create-run-dialog/create-run-dialog.component.ts b/src/app/teacher/create-run-dialog/create-run-dialog.component.ts index 7f1e42167c3..3e2584444c3 100644 --- a/src/app/teacher/create-run-dialog/create-run-dialog.component.ts +++ b/src/app/teacher/create-run-dialog/create-run-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject } from '@angular/core'; +import { Component, ElementRef, Inject, ViewChild } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog'; import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { finalize } from 'rxjs/operators'; @@ -9,6 +9,8 @@ import { ConfigService } from '../../services/config.service'; import { ListClassroomCoursesDialogComponent } from '../list-classroom-courses-dialog/list-classroom-courses-dialog.component'; import { TeacherRun } from '../teacher-run'; import { Router } from '@angular/router'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { MatExpansionPanel } from '@angular/material/expansion'; @Component({ selector: 'create-run-dialog', @@ -28,6 +30,10 @@ export class CreateRunDialogComponent { isCreating: boolean = false; isCreated: boolean = false; run: TeacherRun = null; + linkedCkProjectControl: FormControl; + @ViewChild('CkCodeInput') ckInput: ElementRef; + @ViewChild('linkRunPanel') linkPanel: MatExpansionPanel; + showProcessingLink: boolean = false; constructor( private configService: ConfigService, @@ -37,7 +43,8 @@ export class CreateRunDialogComponent { private fb: FormBuilder, private router: Router, private teacherService: TeacherService, - private userService: UserService + private userService: UserService, + private snackBar: MatSnackBar ) { this.project = data.project; this.maxStudentsPerTeam = 3; @@ -66,6 +73,7 @@ export class CreateRunDialogComponent { this.endDateControl.valueChanges.subscribe((v) => { this.updateLockedAfterEndDateCheckbox(); }); + this.linkedCkProjectControl = new FormControl(''); this.form = this.fb.group({ selectedPeriods: this.periodsGroup, customPeriods: this.customPeriods, @@ -102,6 +110,51 @@ export class CreateRunDialogComponent { return selectedPeriods.length ? selectedPeriods : []; } + openLinkRunToCkProjectPanel() { + if (!this.linkedCkProjectControl.disabled) { + setTimeout(() => this.ckInput.nativeElement.focus(), 200); + } + } + + linkRunToCkProject() { + this.showProcessingLink = true; + this.linkedCkProjectControl.disable(); + this.teacherService + .linkRunToCkProject(this.run.id, this.linkedCkProjectControl.value) + .pipe( + finalize(() => { + this.showProcessingLink = false; + }) + ) + .subscribe(({ code, message }) => { + if (!!code) { + setTimeout(() => this.linkPanel.close(), 200); + } else { + this.linkedCkProjectControl.enable(); + this.ckInput.nativeElement.focus(); + } + this.snackBar.open($localize`${message}`); + }); + } + + unlinkRunFromCkProject() { + this.showProcessingLink = true; + this.teacherService + .unlinkRunFromCkProject(this.run.id, this.linkedCkProjectControl.value) + .pipe( + finalize(() => { + this.showProcessingLink = false; + }) + ) + .subscribe(({ code, message }) => { + if (!!code) { + this.linkedCkProjectControl.enable(); + this.ckInput.nativeElement.focus(); + } + this.snackBar.open($localize`${message}`); + }); + } + create() { this.isCreating = true; const combinedPeriods = this.getPeriodsString(); diff --git a/src/app/teacher/run-settings-dialog/run-settings-dialog.component.html b/src/app/teacher/run-settings-dialog/run-settings-dialog.component.html index 9fe6a290979..a3e2e748310 100644 --- a/src/app/teacher/run-settings-dialog/run-settings-dialog.component.html +++ b/src/app/teacher/run-settings-dialog/run-settings-dialog.component.html @@ -121,6 +121,23 @@

>

+ +

+ CK Board Project Linking +

+
+ + SCORE-CK Connect Code + + + + + +
diff --git a/src/app/teacher/run-settings-dialog/run-settings-dialog.component.ts b/src/app/teacher/run-settings-dialog/run-settings-dialog.component.ts index b91ea8b6525..334c25c8250 100644 --- a/src/app/teacher/run-settings-dialog/run-settings-dialog.component.ts +++ b/src/app/teacher/run-settings-dialog/run-settings-dialog.component.ts @@ -5,6 +5,8 @@ import { LibraryProjectDetailsComponent } from '../../modules/library/library-pr import { TeacherService } from '../teacher.service'; import { formatDate } from '@angular/common'; import { TeacherRun } from '../teacher-run'; +import { FormControl } from '@angular/forms'; +import { finalize } from 'rxjs/operators'; @Component({ selector: 'app-run-settings-dialog', @@ -32,6 +34,8 @@ export class RunSettingsDialogComponent implements OnInit { minEndDate: Date; targetEndDate: Date; messageCodeToMessage: any; + linkedCkProjectControl: FormControl; + showProcessingLink: boolean = false; constructor( public dialog: MatDialog, @@ -71,7 +75,13 @@ export class RunSettingsDialogComponent implements OnInit { }; } - ngOnInit() {} + ngOnInit() { + this.linkedCkProjectControl = new FormControl(''); + if (!!this.run.connectCode) { + this.linkedCkProjectControl.setValue(this.run.connectCode); + this.linkedCkProjectControl.disable(); + } + } newPeriodNameKeyUp(event) { if (this.isEnterKeyWithNewPeriodName(event)) { @@ -286,6 +296,53 @@ export class RunSettingsDialogComponent implements OnInit { }); } + linkRunToCkProject() { + this.showProcessingLink = true; + this.linkedCkProjectControl.disable(); + this.teacherService + .linkRunToCkProject(this.run.id, this.linkedCkProjectControl.value) + .pipe( + finalize(() => { + this.showProcessingLink = false; + }) + ) + .subscribe(({ code, message }) => { + if (!!code) { + this.run.connectCode = code; + this.teacherService.broadcastRunChanges(new TeacherRun(this.run)); + } else { + this.linkedCkProjectControl.enable(); + } + this.snackBar.open($localize`${message}`); + }); + } + + unlinkRunFromCkProject() { + if ( + confirm( + `Are you sure you want to unlink CK Board project: ${this.linkedCkProjectControl.value}` + ) + ) { + this.showProcessingLink = true; + this.teacherService + .unlinkRunFromCkProject(this.run.id, this.linkedCkProjectControl.value) + .pipe( + finalize(() => { + this.showProcessingLink = false; + }) + ) + .subscribe(({ code, message }) => { + if (!!code) { + this.linkedCkProjectControl.setValue(''); + this.linkedCkProjectControl.enable(); + this.run.connectCode = ''; + this.teacherService.broadcastRunChanges(new TeacherRun(this.run)); + } + this.snackBar.open($localize`${message}`); + }); + } + } + private rollbackRandomPeriodAssignment() { this.isRandomPeriodAssignment = this.run.isRandomPeriodAssignment; } diff --git a/src/app/teacher/teacher-run.ts b/src/app/teacher/teacher-run.ts index 6eb4480b1a5..3d31b8fa1ec 100644 --- a/src/app/teacher/teacher-run.ts +++ b/src/app/teacher/teacher-run.ts @@ -3,6 +3,7 @@ import { Run } from '../domain/run'; export class TeacherRun extends Run { isHighlighted: boolean; shared: boolean; + connectCode: string; constructor(jsonObject: any = {}) { super(jsonObject); diff --git a/src/app/teacher/teacher.service.ts b/src/app/teacher/teacher.service.ts index 7b845c40361..c35dc363765 100644 --- a/src/app/teacher/teacher.service.ts +++ b/src/app/teacher/teacher.service.ts @@ -1,14 +1,14 @@ -import { Injectable } from '@angular/core'; -import { Observable, Subject } from 'rxjs'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; +import { Observable, Subject } from 'rxjs'; +import { Course } from '../domain/course'; +import { Period } from '../domain/period'; import { Project } from '../domain/project'; -import { Teacher } from '../domain/teacher'; import { Run } from '../domain/run'; -import { Course } from '../domain/course'; +import { Teacher } from '../domain/teacher'; import { CopyProjectDialogComponent } from '../modules/library/copy-project-dialog/copy-project-dialog.component'; import { TeacherRun } from './teacher-run'; -import { Period } from '../domain/period'; @Injectable() export class TeacherService { @@ -344,4 +344,14 @@ export class TeacherService { params = params.set('teacherPassword', teacherPassword); return this.http.post(`/api/teacher/run/${runId}/student/${studentId}/change-password`, params); } + + linkRunToCkProject(id: number, code: string): Observable { + const params = new HttpParams().set('runId', id).set('code', code); + return this.http.post('/api/teacher/run/score/link', params); + } + + unlinkRunFromCkProject(id: number, code: string): Observable { + const params = new HttpParams().set('runId', id).set('code', code); + return this.http.post('/api/teacher/run/score/unlink', params); + } }