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

Lectures: Add PDF preview for instructors #8987

Merged
merged 87 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
76e86e1
Open a PDF Preview page for every attachment file
eceeeren Jul 7, 2024
d96f276
Add breadcrumb & show pdf file preview as images
eceeeren Jul 7, 2024
8077b0d
Render files with PDFJS
eceeeren Jul 13, 2024
5ef93eb
Enlarge PDF page content
eceeeren Jul 15, 2024
e36d0aa
Show page numbers when hovered
eceeeren Jul 15, 2024
d88a85b
Clean up the code & styling
eceeeren Jul 15, 2024
56a3abe
Add PDF Preview to correct routing
eceeeren Jul 15, 2024
f691d00
Close PDF preview when clicked outside
eceeeren Jul 21, 2024
5df2075
Add arrows to change pages
eceeeren Jul 21, 2024
6bb13fb
Add functionality to the arrows
eceeeren Jul 21, 2024
bbdd4c2
Add page indicator
eceeeren Jul 21, 2024
ebe6d04
Add JSDoc comments
eceeeren Jul 23, 2024
2bd8316
Translation & colors
eceeeren Jul 23, 2024
e415509
Git merge 'develop' into 'feature/course/attachment-pdf-preview'
eceeeren Jul 24, 2024
48018aa
Install pdf.js
eceeeren Jul 24, 2024
0de1150
Fix build error
eceeeren Jul 24, 2024
c9d9c29
Change file path
eceeeren Jul 24, 2024
9f612e7
Update getAttachmentFile method
eceeeren Jul 24, 2024
2def08c
Update PDF Preview button & add it to Lecture Units
eceeeren Jul 24, 2024
8ed16f6
Fix linting errors
eceeeren Jul 27, 2024
66e4bc4
Merge 'develop' into 'feature/course/attachment-pdf-preview'
eceeeren Jul 27, 2024
a0871fc
Take back unnecessary changes
eceeeren Jul 27, 2024
6f09ccb
Add mapping comment
eceeeren Jul 27, 2024
966fe50
Fix error handling
eceeeren Jul 29, 2024
7fdf2f4
Client tests are added
eceeeren Jul 29, 2024
bee424e
Fix failing server test
eceeeren Jul 29, 2024
60d8414
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Jul 29, 2024
38ce818
Fix typos
eceeeren Jul 29, 2024
8bd6db7
Fix alertService problem
eceeeren Aug 3, 2024
be23c0d
Fix PDF.js worker initialization
eceeeren Aug 4, 2024
52bf703
Fix responsivity of enlarged view
eceeeren Aug 4, 2024
1b3d900
Git merge 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 5, 2024
9f7efab
Fix enlarged view position
eceeeren Aug 5, 2024
175af72
Small fixes
eceeeren Aug 7, 2024
8b0d54e
Fix failing client tests
eceeeren Aug 7, 2024
e5d4110
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 7, 2024
39e8076
viewButtonAvailable check is updated
eceeeren Aug 7, 2024
b4c36b3
Merge remote-tracking branch 'origin/feature/course/attachment-pdf-pr…
eceeeren Aug 7, 2024
16e0cee
Fix LectureAttachments client tests
eceeeren Aug 7, 2024
7b80bd0
Add client tests for View Button
eceeeren Aug 7, 2024
4d14647
Fix FileSource method names
eceeeren Aug 7, 2024
47990e1
Worker tryout
eceeeren Aug 7, 2024
b16581f
Fix Mime Type error
eceeeren Aug 7, 2024
5fcfbfe
Fix PDF Worker
eceeeren Aug 7, 2024
493dba8
Fix MIME Type Error 2
eceeeren Aug 8, 2024
4800301
Fix MIME Type Error 3
eceeeren Aug 8, 2024
a37c978
Merge remote-tracking branch 'origin/feature/course/attachment-pdf-pr…
eceeeren Aug 8, 2024
b451431
Set fake worker back
eceeeren Aug 8, 2024
4d2d1c9
Fix undefined lecture id after saving the attachment
eceeeren Aug 9, 2024
3c54b06
Change get method permissions
eceeeren Aug 9, 2024
ec127b7
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 9, 2024
9a9dfd5
Resolved changes
eceeeren Aug 11, 2024
f63ac22
Merge remote-tracking branch 'origin/feature/course/attachment-pdf-pr…
eceeeren Aug 11, 2024
a2f8f88
Fix client tests
eceeeren Aug 11, 2024
eb9122f
Merge 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 11, 2024
984bcdf
Resolved changes 2
eceeeren Aug 14, 2024
5f9e0c7
Fix error text
eceeeren Aug 14, 2024
5d3e469
Merge 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 14, 2024
240e768
CodeRabbitAI changes
eceeeren Aug 14, 2024
63764d2
Confirmed changes
eceeeren Aug 18, 2024
1affbf6
Fix compilation errors
eceeeren Aug 18, 2024
60ea19f
Fix error handling & add new test cases
eceeeren Aug 18, 2024
4e24d1c
Mak adjustCanvasSize public
eceeeren Aug 18, 2024
24536b3
Fix client tests
eceeeren Aug 18, 2024
d9b47f1
Fix client tests 2
eceeeren Aug 18, 2024
2d5fa81
Merge 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 18, 2024
547be9a
Increase client test coverage, fix typos
eceeeren Aug 18, 2024
6c608b5
Fix test case typo
eceeeren Aug 18, 2024
4c0b38b
Resolved changes
eceeeren Aug 18, 2024
861a179
Add tests for closeIfOutside
eceeeren Aug 20, 2024
f5b48c8
Remove redundant type
eceeeren Aug 20, 2024
387c19b
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 20, 2024
c6978ac
Divide updateEnlargedCanvas into sub functions & increase client test…
eceeeren Aug 20, 2024
5c70fb9
Merge remote-tracking branch 'origin/feature/course/attachment-pdf-pr…
eceeeren Aug 20, 2024
f3683ad
Fix client test
eceeeren Aug 21, 2024
8889a51
Add client tests to AttachmentService and AttachmentUnitService
eceeeren Aug 22, 2024
2fba2b3
Approved changes
eceeeren Aug 22, 2024
4014e51
Fix client tests
eceeeren Aug 22, 2024
a0babdb
Increase client test coverage
eceeeren Aug 24, 2024
5ed8d67
Add server tests for the endpoints
eceeeren Aug 26, 2024
6177c2f
Merge 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 26, 2024
4e0fba6
Fix client test
eceeeren Aug 26, 2024
f37e105
Add ArtemisSharedModule to PDFPreviewComponent for the translation fe…
eceeeren Aug 28, 2024
111b022
Add TranslationService to the client tests
eceeeren Aug 28, 2024
f19b1b4
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Aug 30, 2024
009c190
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Sep 1, 2024
75c5714
Merge branch 'develop' into feature/course/attachment-pdf-preview
eceeeren Sep 2, 2024
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
453 changes: 432 additions & 21 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"ngx-infinite-scroll": "18.0.0",
"ngx-webstorage": "18.0.0",
"papaparse": "5.4.1",
"pdfjs-dist": "^4.5.136",
"posthog-js": "1.160.0",
"rxjs": "7.8.1",
"showdown": "2.1.0",
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/de/tum/in/www1/artemis/web/rest/FileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import de.tum.in.www1.artemis.security.annotations.EnforceAtLeastInstructor;
import de.tum.in.www1.artemis.security.annotations.EnforceAtLeastStudent;
import de.tum.in.www1.artemis.security.annotations.EnforceAtLeastTutor;
import de.tum.in.www1.artemis.security.annotations.enforceRoleInCourse.EnforceAtLeastEditorInCourse;
import de.tum.in.www1.artemis.service.AuthorizationCheckService;
import de.tum.in.www1.artemis.service.FilePathService;
import de.tum.in.www1.artemis.service.FileService;
Expand Down Expand Up @@ -372,6 +373,24 @@ public ResponseEntity<byte[]> getLectureAttachment(@PathVariable Long lectureId,
return buildFileResponse(getActualPathFromPublicPathString(attachment.getLink()), false);
}

/**
* GET /files/courses/{courseId}/attachments/{attachmentId} : Returns the file associated with the
* given attachment ID as a downloadable resource
*
* @param courseId The ID of the course that the Attachment belongs to
* @param attachmentId the ID of the attachment to retrieve
* @return ResponseEntity containing the file as a resource
*/
@GetMapping("files/courses/{courseId}/attachments/{attachmentId}")
@EnforceAtLeastEditorInCourse
public ResponseEntity<byte[]> getAttachmentFile(@PathVariable Long courseId, @PathVariable Long attachmentId) {
Attachment attachment = attachmentRepository.findByIdElseThrow(attachmentId);
Course course = courseRepository.findByIdElseThrow(courseId);
checkAttachmentExistsInCourseOrThrow(course, attachment);

return buildFileResponse(getActualPathFromPublicPathString(attachment.getLink()), false);
}

/**
* GET /files/attachments/lecture/{lectureId}/merge-pdf : Get the lecture units
* PDF attachments merged
Expand Down Expand Up @@ -428,6 +447,26 @@ public ResponseEntity<byte[]> getAttachmentUnitAttachment(@PathVariable Long att
return buildFileResponse(getActualPathFromPublicPathString(attachment.getLink()), false);
}

/**
* GET files/courses/{courseId}/attachment-units/{attachmenUnitId} : Returns the file associated with the
* given attachmentUnit ID as a downloadable resource
*
* @param courseId The ID of the course that the Attachment belongs to
* @param attachmentUnitId the ID of the attachment to retrieve
* @return ResponseEntity containing the file as a resource
*/
@GetMapping("files/courses/{courseId}/attachment-units/{attachmentUnitId}")
@EnforceAtLeastEditorInCourse
public ResponseEntity<byte[]> getAttachmentUnitFile(@PathVariable Long courseId, @PathVariable Long attachmentUnitId) {
log.debug("REST request to get file for attachment unit : {}", attachmentUnitId);
AttachmentUnit attachmentUnit = attachmentUnitRepository.findByIdElseThrow(attachmentUnitId);
Course course = courseRepository.findByIdElseThrow(courseId);
Attachment attachment = attachmentUnit.getAttachment();
checkAttachmentUnitExistsInCourseOrThrow(course, attachmentUnit);

return buildFileResponse(getActualPathFromPublicPathString(attachment.getLink()), false);
}

/**
* GET files/attachments/slides/attachment-unit/:attachmentUnitId/slide/:slideNumber : Get the lecture unit attachment slide by slide number
*
Expand Down Expand Up @@ -557,6 +596,30 @@ private void checkAttachmentAuthorizationOrThrow(Course course, Attachment attac
}
}

/**
* Checks if the attachment exists in the mentioned course
*
* @param course the course to check if the attachment is part of it
* @param attachment the attachment for which the existence should be checked
*/
private void checkAttachmentExistsInCourseOrThrow(Course course, Attachment attachment) {
if (!attachment.getLecture().getCourse().equals(course)) {
throw new EntityNotFoundException("This attachment does not exist in this course.");
}
}

/**
* Checks if the attachment exists in the mentioned course
*
* @param course the course to check if the attachment is part of it
* @param attachmentUnit the attachment unit for which the existence should be checked
*/
private void checkAttachmentUnitExistsInCourseOrThrow(Course course, AttachmentUnit attachmentUnit) {
if (!attachmentUnit.getLecture().getCourse().equals(course)) {
throw new EntityNotFoundException("This attachment unit does not exist in this course.");
}
}

/**
* Reads the file and turns it into a ResponseEntity
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/app/lecture/attachment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,15 @@ export class AttachmentService {
}
return formData;
}

/**
* Retrieve the file associated with a given attachment ID as a Blob object
*
* @param courseId The ID of the course that the attachment belongs to
* @param attachmentId The ID of the attachment to retrieve
* @returns An Observable that emits the Blob object of the file when the HTTP request completes successfully
*/
getAttachmentFile(courseId: number, attachmentId: number): Observable<Blob> {
return this.http.get(`api/files/courses/${courseId}/attachments/${attachmentId}`, { responseType: 'blob' });
}
}
11 changes: 11 additions & 0 deletions src/main/webapp/app/lecture/lecture-attachments.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ <h4 jhiTranslate="artemisApp.lecture.attachments.attachments"></h4>
</td>
<td class="text-end">
<div class="flex-btn-group-container">
@if (viewButtonAvailable[attachment.id!]) {
<button
type="button"
class="btn btn-primary btn-sm me-1"
[routerLink]="['/course-management', lecture.course?.id, 'lectures', lecture.id, 'attachments', attachment.id]"
[ngbTooltip]="'entity.action.view' | artemisTranslate"
>
<fa-icon [icon]="faEye" />
<span class="d-none d-md-inline" jhiTranslate="entity.action.view"></span>
</button>
}
<button
[disabled]="attachmentToBeCreated?.id === attachment?.id"
type="submit"
Expand Down
15 changes: 14 additions & 1 deletion src/main/webapp/app/lecture/lecture-attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Subject } from 'rxjs';
import { FileService } from 'app/shared/http/file.service';
import { Attachment, AttachmentType } from 'app/entities/attachment.model';
import { AttachmentService } from 'app/lecture/attachment.service';
import { faPaperclip, faPencilAlt, faQuestionCircle, faSpinner, faTimes, faTrash } from '@fortawesome/free-solid-svg-icons';
import { faEye, faPaperclip, faPencilAlt, faQuestionCircle, faSpinner, faTimes, faTrash } from '@fortawesome/free-solid-svg-icons';
import { FILE_EXTENSIONS } from 'app/shared/constants/file-extensions.constants';
import { LectureService } from 'app/lecture/lecture.service';

Expand All @@ -31,6 +31,7 @@ export class LectureAttachmentsComponent implements OnInit, OnDestroy {
notificationText?: string;
erroredFile?: File;
errorMessage?: string;
viewButtonAvailable: Record<number, boolean> = {};
eceeeren marked this conversation as resolved.
Show resolved Hide resolved

// A human-readable list of allowed file extensions
readonly allowedFileExtensions = FILE_EXTENSIONS.join(', ');
Expand All @@ -47,6 +48,7 @@ export class LectureAttachmentsComponent implements OnInit, OnDestroy {
faPencilAlt = faPencilAlt;
faPaperclip = faPaperclip;
faQuestionCircle = faQuestionCircle;
faEye = faEye;

constructor(
protected activatedRoute: ActivatedRoute,
Expand Down Expand Up @@ -75,13 +77,20 @@ export class LectureAttachmentsComponent implements OnInit, OnDestroy {
loadAttachments(): void {
this.attachmentService.findAllByLectureId(this.lecture.id!).subscribe((attachmentsResponse: HttpResponse<Attachment[]>) => {
this.attachments = attachmentsResponse.body!;
this.attachments.forEach((attachment) => {
this.viewButtonAvailable[attachment.id!] = this.isViewButtonAvailable(attachment.link!);
});
});
}

ngOnDestroy(): void {
this.dialogErrorSource.unsubscribe();
}

isViewButtonAvailable(attachmentLink: string): boolean {
return attachmentLink.endsWith('.pdf') ?? false;
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
}

get isSubmitPossible(): boolean {
return !!(this.attachmentToBeCreated?.name && (this.attachmentFile || this.attachmentToBeCreated?.link));
}
Expand Down Expand Up @@ -130,9 +139,13 @@ export class LectureAttachmentsComponent implements OnInit, OnDestroy {
this.attachmentService.create(this.attachmentToBeCreated!, this.attachmentFile!).subscribe({
next: (attachmentRes: HttpResponse<Attachment>) => {
this.attachments.push(attachmentRes.body!);
this.lectureService.findWithDetails(this.lecture.id!).subscribe((lectureResponse: HttpResponse<Lecture>) => {
this.lecture = lectureResponse.body!;
});
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
this.attachmentFile = undefined;
this.attachmentToBeCreated = undefined;
this.attachmentBackup = undefined;
this.loadAttachments();
},
error: (error: HttpErrorResponse) => this.handleFailedUpload(error),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ export class AttachmentUnitService {
const params = new HttpParams().set('commaSeparatedKeyPhrases', keyPhrases);
return this.httpClient.get<Array<number>>(`${this.resourceURL}/lectures/${lectureId}/attachment-units/slides-to-remove/${filename}`, { params, observe: 'response' });
}

/**
* Retrieve the file associated with a given attachment ID as a Blob object
*
* @param courseId The ID of the course that the Attachment Unit belongs to
* @param attachmentUnitId The ID of the attachment to retrieve
* @returns An Observable that emits the Blob object of the file when the HTTP request completes successfully
*/
getAttachmentFile(courseId: number, attachmentUnitId: number): Observable<Blob> {
return this.httpClient.get(`${this.resourceURL}/files/courses/${courseId}/attachment-units/${attachmentUnitId}`, { responseType: 'blob' });
}
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
@if (lecture.course?.id && showCompetencies) {
<jhi-competencies-popover [courseId]="lecture.course!.id!" [competencies]="lectureUnit.competencies || []" [navigateTo]="'competencyManagement'" />
}
@if (viewButtonAvailable[lectureUnit.id!]) {
<a
type="button"
class="btn btn-primary btn-sm flex-grow-1"
[routerLink]="['/course-management', lecture.course?.id, 'lectures', lecture.id, 'unit-management', 'attachment-units', lectureUnit.id, 'view']"
[ngbTooltip]="'entity.action.view' | artemisTranslate"
>
<fa-icon [icon]="faEye" />
</a>
}
<div class="d-flex gap-1 w-100">
@if (this.emitEditEvents) {
@if (editButtonAvailable(lectureUnit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LectureUnitService } from 'app/lecture/lecture-unit/lecture-unit-manage
import { ActionType } from 'app/shared/delete-dialog/delete-dialog.model';
import { AttachmentUnit } from 'app/entities/lecture-unit/attachmentUnit.model';
import { ExerciseUnit } from 'app/entities/lecture-unit/exerciseUnit.model';
import { faPencilAlt, faTrash } from '@fortawesome/free-solid-svg-icons';
import { faEye, faPencilAlt, faTrash } from '@fortawesome/free-solid-svg-icons';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';

@Component({
Expand All @@ -34,8 +34,11 @@ export class LectureUnitManagementComponent implements OnInit, OnDestroy {
lecture: Lecture;
isLoading = false;
updateOrderSubject: Subject<any>;
viewButtonAvailable: Record<number, boolean> = {};

updateOrderSubjectSubscription: Subscription;
navigationEndSubscription: Subscription;

readonly LectureUnitType = LectureUnitType;
readonly ActionType = ActionType;
private dialogErrorSource = new Subject<string>();
Expand All @@ -51,6 +54,7 @@ export class LectureUnitManagementComponent implements OnInit, OnDestroy {
// Icons
faTrash = faTrash;
faPencilAlt = faPencilAlt;
faEye = faEye;

constructor(
private activatedRoute: ActivatedRoute,
Expand Down Expand Up @@ -104,6 +108,9 @@ export class LectureUnitManagementComponent implements OnInit, OnDestroy {
this.lecture = lecture;
if (lecture?.lectureUnits) {
this.lectureUnits = lecture?.lectureUnits;
this.lectureUnits.forEach((lectureUnit) => {
this.viewButtonAvailable[lectureUnit.id!] = this.isViewButtonAvailable(lectureUnit);
});
} else {
this.lectureUnits = [];
}
Expand Down Expand Up @@ -186,6 +193,17 @@ export class LectureUnitManagementComponent implements OnInit, OnDestroy {
});
}

isViewButtonAvailable(lectureUnit: LectureUnit): boolean {
switch (lectureUnit!.type) {
case LectureUnitType.ATTACHMENT: {
const attachmentUnit = <AttachmentUnit>lectureUnit;
return attachmentUnit.attachment?.link?.endsWith('.pdf') ?? false;
}
default:
return false;
}
}

editButtonAvailable(lectureUnit: LectureUnit) {
switch (lectureUnit?.type) {
case LectureUnitType.ATTACHMENT:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Routes } from '@angular/router';
import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { ActivatedRouteSnapshot, Resolve, Routes } from '@angular/router';
import { Observable, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { Authority } from 'app/shared/constants/authority.constants';
import { UserRouteAccessService } from 'app/core/auth/user-route-access-service';
import { LectureUnitManagementComponent } from 'app/lecture/lecture-unit/lecture-unit-management/lecture-unit-management.component';
Expand All @@ -12,6 +16,27 @@ import { EditVideoUnitComponent } from 'app/lecture/lecture-unit/lecture-unit-ma
import { CreateOnlineUnitComponent } from 'app/lecture/lecture-unit/lecture-unit-management/create-online-unit/create-online-unit.component';
import { EditOnlineUnitComponent } from 'app/lecture/lecture-unit/lecture-unit-management/edit-online-unit/edit-online-unit.component';
import { AttachmentUnitsComponent } from 'app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component';
import { PdfPreviewComponent } from 'app/lecture/pdf-preview/pdf-preview.component';
import { AttachmentUnit } from 'app/entities/lecture-unit/attachmentUnit.model';
import { AttachmentUnitService } from 'app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service';
import { CourseManagementResolve } from 'app/course/manage/course-management-resolve.service';

@Injectable({ providedIn: 'root' })
export class AttachmentUnitResolve implements Resolve<AttachmentUnit> {
constructor(private attachmentUnitService: AttachmentUnitService) {}

resolve(route: ActivatedRouteSnapshot): Observable<AttachmentUnit> {
const lectureId = route.params['lectureId'];
const attachmentUnitId = route.params['attachmentUnitId'];
if (attachmentUnitId) {
return this.attachmentUnitService.findById(attachmentUnitId, lectureId).pipe(
filter((response: HttpResponse<AttachmentUnit>) => response.ok),
map((attachmentUnit: HttpResponse<AttachmentUnit>) => attachmentUnit.body!),
);
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
}
return of(new AttachmentUnit());
}
}

export const lectureUnitRoute: Routes = [
{
Expand Down Expand Up @@ -86,6 +111,14 @@ export const lectureUnitRoute: Routes = [
pageTitle: 'artemisApp.attachmentUnit.editAttachmentUnit.title',
},
},
{
path: 'attachment-units/:attachmentUnitId/view',
component: PdfPreviewComponent,
resolve: {
course: CourseManagementResolve,
attachmentUnit: AttachmentUnitResolve,
},
},
{
path: 'video-units/:videoUnitId/edit',
component: EditVideoUnitComponent,
Expand Down
33 changes: 33 additions & 0 deletions src/main/webapp/app/lecture/lecture.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { Authority } from 'app/shared/constants/authority.constants';
import { lectureUnitRoute } from 'app/lecture/lecture-unit/lecture-unit-management/lecture-unit-management.route';
import { CourseManagementResolve } from 'app/course/manage/course-management-resolve.service';
import { CourseManagementTabBarComponent } from 'app/course/manage/course-management-tab-bar/course-management-tab-bar.component';
import { PdfPreviewComponent } from 'app/lecture/pdf-preview/pdf-preview.component';
import { Attachment } from 'app/entities/attachment.model';
import { AttachmentService } from 'app/lecture/attachment.service';

@Injectable({ providedIn: 'root' })
export class LectureResolve implements Resolve<Lecture> {
Expand All @@ -31,6 +34,22 @@ export class LectureResolve implements Resolve<Lecture> {
}
}

@Injectable({ providedIn: 'root' })
export class AttachmentResolve implements Resolve<Attachment> {
constructor(private attachmentService: AttachmentService) {}

resolve(route: ActivatedRouteSnapshot): Observable<Attachment> {
const attachmentId = route.params['attachmentId'];
if (attachmentId) {
return this.attachmentService.find(attachmentId).pipe(
filter((response: HttpResponse<Attachment>) => response.ok),
map((attachment: HttpResponse<Attachment>) => attachment.body!),
eceeeren marked this conversation as resolved.
Show resolved Hide resolved
);
}
return of(new Attachment());
}
}

export const lectureRoute: Routes = [
{
path: ':courseId/lectures',
Expand Down Expand Up @@ -91,6 +110,20 @@ export const lectureRoute: Routes = [
},
canActivate: [UserRouteAccessService],
},
{
path: 'attachments',
canActivate: [UserRouteAccessService],
children: [
{
path: ':attachmentId',
component: PdfPreviewComponent,
resolve: {
attachment: AttachmentResolve,
course: CourseManagementResolve,
},
},
],
},
{
path: 'edit',
component: LectureUpdateComponent,
Expand Down
Loading
Loading