Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/app/teacher/teacher-authoring.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ComponentInfoService } from '../../assets/wise5/services/componentInfoS
import { TeacherProjectTranslationService } from '../../assets/wise5/services/teacherProjectTranslationService';
import { DeleteTranslationsService } from '../../assets/wise5/services/deleteTranslationsService';
import { CopyTranslationsService } from '../../assets/wise5/services/copyTranslationsService';
import { NotifyAuthorService } from '../../assets/wise5/services/notifyAuthorService';

@NgModule({
imports: [StudentTeacherCommonModule, AuthoringToolModule, RouterModule, AuthoringRoutingModule],
Expand All @@ -56,6 +57,7 @@ import { CopyTranslationsService } from '../../assets/wise5/services/copyTransla
MilestoneReportService,
MoveNodesService,
{ provide: NodeService, useExisting: TeacherNodeService },
NotifyAuthorService,
ProjectAssetService,
SpaceService,
DeleteTranslationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,33 @@ import { TeacherWebSocketService } from '../../../services/teacherWebSocketServi
import { ClassroomStatusService } from '../../../services/classroomStatusService';
import { MatDialogModule } from '@angular/material/dialog';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { NotifyAuthorService } from '../../../services/notifyAuthorService';

describe('TopBarComponent', () => {
let component: TopBarComponent;
let fixture: ComponentFixture<TopBarComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [TopBarComponent],
imports: [MatDialogModule,
declarations: [TopBarComponent],
imports: [
MatDialogModule,
MatIconModule,
MatMenuModule,
MatToolbarModule,
MatTooltipModule,
StudentTeacherCommonServicesModule],
providers: [
StudentTeacherCommonServicesModule
],
providers: [
ClassroomStatusService,
NotifyAuthorService,
TeacherDataService,
TeacherProjectService,
TeacherWebSocketService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
}).compileComponents();
]
}).compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ProjectLocale } from '../../../../../app/domain/projectLocale';
import { Language } from '../../../../../app/domain/language';
import { Subscription } from 'rxjs';
import { TeacherDataService } from '../../../services/teacherDataService';
import { NotifyAuthorService } from '../../../services/notifyAuthorService';

@Component({
selector: 'at-top-bar',
Expand All @@ -34,6 +35,7 @@ export class TopBarComponent implements OnInit {
constructor(
private configService: ConfigService,
private dataService: TeacherDataService,
private notifyAuthorService: NotifyAuthorService,
private projectService: TeacherProjectService,
private router: Router,
private sessionService: SessionService
Expand Down Expand Up @@ -108,7 +110,7 @@ export class TopBarComponent implements OnInit {
}

protected goHome(): void {
this.projectService.notifyAuthorProjectEnd().then(() => {
this.notifyAuthorService.editEnd(this.projectId).then(() => {
this.sessionService.goHome();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { of } from 'rxjs';
import { SessionService } from '../../services/sessionService';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { NotifyAuthorService } from '../../services/notifyAuthorService';

class MockConfigService {
getMyUsername(): string {
Expand All @@ -24,16 +25,17 @@ let fixture: ComponentFixture<ConcurrentAuthorsMessageComponent>;
describe('ConcurrentAuthorsMessageComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ConcurrentAuthorsMessageComponent],
imports: [],
providers: [
declarations: [ConcurrentAuthorsMessageComponent],
imports: [],
providers: [
{ provide: ConfigService, useClass: MockConfigService },
NotifyAuthorService,
SessionService,
{ provide: TeacherProjectService, useClass: MockTeacherProjectService },
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
});
]
});
fixture = TestBed.createComponent(ConcurrentAuthorsMessageComponent);
component = fixture.componentInstance;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RxStomp } from '@stomp/rx-stomp';
import { Message } from '@stomp/stompjs';
import { TeacherProjectService } from '../../services/teacherProjectService';
import { SessionService } from '../../services/sessionService';
import { NotifyAuthorService } from '../../services/notifyAuthorService';

@Component({
selector: 'concurrent-authors-message',
Expand All @@ -17,6 +18,7 @@ export class ConcurrentAuthorsMessageComponent {

constructor(
private configService: ConfigService,
private notifyAuthorService: NotifyAuthorService,
private projectService: TeacherProjectService,
private sessionService: SessionService
) {
Expand All @@ -29,7 +31,7 @@ export class ConcurrentAuthorsMessageComponent {
ngOnInit() {
this.rxStomp.activate();
this.rxStomp.connected$.subscribe(() => {
this.projectService.notifyAuthorProjectBegin(this.projectId);
this.notifyAuthorService.editBegin(this.projectId);
});
this.subscribeToCurrentAuthors();
this.subscribeToSessionExit();
Expand All @@ -49,7 +51,7 @@ export class ConcurrentAuthorsMessageComponent {

private subscribeToSessionExit(): void {
this.sessionService.exit$.subscribe(() => {
this.projectService.notifyAuthorProjectEnd();
this.notifyAuthorService.editEnd(this.projectId);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input } from '@angular/core';
import { TeacherProjectService } from '../../services/teacherProjectService';
import { NotifyAuthorService } from '../../services/notifyAuthorService';

@Component({
templateUrl: './project-authoring-parent.component.html',
Expand All @@ -8,17 +8,17 @@ import { TeacherProjectService } from '../../services/teacherProjectService';
export class ProjectAuthoringParentComponent {
@Input('unitId') protected projectId?: number;

constructor(private projectService: TeacherProjectService) {}
constructor(private notifyAuthorService: NotifyAuthorService) {}

ngOnInit(): void {
this.projectId = Number(this.projectId);
this.projectService.notifyAuthorProjectBegin(this.projectId);
this.notifyAuthorService.editBegin(this.projectId);
window.onbeforeunload = (event) => {
this.projectService.notifyAuthorProjectEnd(this.projectId);
this.notifyAuthorService.editEnd(this.projectId);
};
}

ngOnDestroy(): void {
this.projectService.notifyAuthorProjectEnd(this.projectId);
this.notifyAuthorService.editEnd(this.projectId);
}
}
22 changes: 22 additions & 0 deletions src/assets/wise5/services/notifyAuthorService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class NotifyAuthorService {
constructor(private http: HttpClient) {}

editBegin(projectId: number): void {
this.http.post(`/api/author/project/notify/${projectId}/true`, null).subscribe();
}

editEnd(projectId: number): Promise<void> {
return new Promise((resolve, reject) => {
if (projectId == null) {
resolve();
}
this.http.post(`/api/author/project/notify/${projectId}/false`, null).subscribe(() => {
resolve();
});
});
}
}
26 changes: 2 additions & 24 deletions src/assets/wise5/services/teacherProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class TeacherProjectService extends ProjectService {
public errorSavingProject$: Observable<void> = this.errorSavingProjectSource.asObservable();
private nodeTypeSelected: WritableSignal<NodeTypeSelected> = signal(null);
private notAllowedToEditThisProjectSource: Subject<void> = new Subject<void>();
public notAllowedToEditThisProject$: Observable<void> = this.notAllowedToEditThisProjectSource.asObservable();
public notAllowedToEditThisProject$: Observable<void> =
this.notAllowedToEditThisProjectSource.asObservable();
private projectSavedSource: Subject<void> = new Subject<void>();
public projectSaved$: Observable<void> = this.projectSavedSource.asObservable();
private savingProjectSource: Subject<void> = new Subject<void>();
Expand Down Expand Up @@ -183,29 +184,6 @@ export class TeacherProjectService extends ProjectService {
};
}

notifyAuthorProjectBeginEnd(projectId, isBegin) {
return this.http.post(`/api/author/project/notify/${projectId}/${isBegin}`, null).toPromise();
}

notifyAuthorProjectBegin(projectId) {
return this.notifyAuthorProjectBeginEnd(projectId, true);
}

notifyAuthorProjectEnd(projectId = null) {
return new Promise((resolve, reject) => {
if (projectId == null) {
if (this.project != null) {
projectId = this.configService.getProjectId();
} else {
resolve({});
}
}
this.notifyAuthorProjectBeginEnd(projectId, false).then(() => {
resolve({});
});
});
}

/**
* Retrieve the project JSON
* @param projectId retrieve the project JSON with this id
Expand Down
Loading