Skip to content

Commit

Permalink
Add 'Original Version' button for instructors
Browse files Browse the repository at this point in the history
  • Loading branch information
eceeeren committed Dec 19, 2024
1 parent 2f4c5cf commit c18def3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ public static URI publicPathForActualPath(Path path, @Nullable Long entityId) {
}

private static URI publicPathForActualAttachmentUnitFilePath(Path path, String filename, String id) {
if (path.toString().contains("/student")) {
return URI.create(String.format("/api/files/attachments/attachment-unit/%s/student/%s", id, filename));
}
if (!path.toString().contains("/slide")) {
return URI.create("/api/files/attachments/attachment-unit/" + id + "/" + filename);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public ResponseEntity<byte[]> getLecturePdfAttachmentsMerged(@PathVariable Long
* @return The requested file, 403 if the logged-in user is not allowed to access it, or 404 if the file doesn't exist
*/
@GetMapping("files/attachments/attachment-unit/{attachmentUnitId}/*")
@EnforceAtLeastEditorInCourse
@EnforceAtLeastInstructor
public ResponseEntity<byte[]> getAttachmentUnitAttachment(@PathVariable Long attachmentUnitId) {
log.debug("REST request to get the file for attachment unit {} for students", attachmentUnitId);
AttachmentUnit attachmentUnit = attachmentUnitRepository.findByIdElseThrow(attachmentUnitId);
Expand Down Expand Up @@ -580,7 +580,7 @@ public ResponseEntity<byte[]> getAttachmentUnitStudentVersion(@PathVariable Long

// check if hidden link is available in the attachment
String studentVersion = attachment.getStudentVersion();
if (studentVersion == null) {
if (attachment.getStudentVersion() == null) {
return buildFileResponse(getActualPathFromPublicPathString(attachment.getLink()), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ResponseEntity<Attachment> updateAttachment(@PathVariable Long attachment
if (studentVersion != null) {
// Update student version of attachment
Path basePath = FilePathService.getAttachmentUnitFilePath().resolve(originalAttachment.getAttachmentUnit().getId().toString());
Path savePath = fileService.saveFile(studentVersion, basePath, true);
Path savePath = fileService.saveFile(studentVersion, basePath.resolve("student"), true);
attachment.setStudentVersion(FilePathService.publicPathForActualPath(savePath, originalAttachment.getAttachmentUnit().getId()).toString());

// Delete the old student version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
[lectureUnit]="lectureUnit()"
[icon]="getAttachmentIcon()"
[showViewIsolatedButton]="true"
[showOriginalVersionButton]="!!lectureUnit().attachment?.studentVersion"
[viewIsolatedButtonLabel]="'artemisApp.attachmentUnit.download'"
[viewIsolatedButtonIcon]="faDownload"
[isPresentationMode]="isPresentationMode()"
(onCompletion)="toggleCompletion($event)"
(onCollapse)="toggleCollapse($event)"
(onShowIsolated)="handleDownload()"
(onShowIsolated)="handleDownload(false)"
(onShowOriginalVersion)="handleDownload(true)"
>
@if (lectureUnit().attachment?.uploadDate) {
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ export class AttachmentUnitComponent extends LectureUnitDirective<AttachmentUnit
}

/**
* Downloads the file
* Downloads the file as the student version if available, otherwise the instructor version
* If it is not the student view, it always downloads the original version
*/
handleDownload() {
handleDownload(originalVersion: boolean) {
this.logEvent();

const link = this.lectureUnit().attachment?.studentVersion || this.lectureUnit().attachment?.link; // Prefer studentVersion if available
const attachment = this.lectureUnit().attachment!;

// Determine the link based on the originalVersion flag and the availability of a student version
const link = originalVersion ? attachment.link! : attachment.studentVersion || this.fileService.createStudentLink(attachment.link!);

if (link) {
const link = this.lectureUnit().attachment!.link!;
this.fileService.downloadFileByAttachmentName(link, this.lectureUnit().attachment!.name!);
this.fileService.downloadFileByAttachmentName(link, attachment.name!);
this.onCompletion.emit({ lectureUnit: this.lectureUnit(), completed: true });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ <h5 class="m-0">{{ lectureUnit().name ?? '' }}</h5>
}
</div>
<div class="d-flex align-items-center">
@if (showOriginalVersionButton() && !isStudentPath()) {
<button id="view-original-version-button" class="btn btn-sm btn-primary me-2" (click)="handleOriginalVersionView($event)">
<fa-icon [icon]="faDownload" />
<span class="d-none d-md-inline" [jhiTranslate]="'artemisApp.textUnit.originalVersion'"></span>
</button>
}
@if (showViewIsolatedButton()) {
<button id="view-isolated-button" class="btn btn-sm btn-primary" (click)="handleIsolatedView($event)">
<fa-icon [icon]="viewIsolatedButtonIcon()" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Component, computed, input, output, signal } from '@angular/core';
import { IconDefinition, faExternalLinkAlt, faSquare, faSquareCheck } from '@fortawesome/free-solid-svg-icons';
import { IconDefinition, faDownload, faExternalLinkAlt, faSquare, faSquareCheck } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module';
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
import { LectureUnit } from 'app/entities/lecture-unit/lectureUnit.model';
import { Router } from '@angular/router';

@Component({
selector: 'jhi-lecture-unit-card',
Expand All @@ -13,12 +14,18 @@ import { LectureUnit } from 'app/entities/lecture-unit/lectureUnit.model';
styleUrl: './lecture-unit.component.scss',
})
export class LectureUnitComponent {
constructor(private router: Router) {}

protected faDownload = faDownload;
protected faSquareCheck = faSquareCheck;
protected faSquare = faSquare;

readonly lectureUnit = input.required<LectureUnit>();
protected readonly icon = input.required<IconDefinition>();

readonly showOriginalVersionButton = input<boolean>(false);
readonly onShowOriginalVersion = output<void>();

readonly showViewIsolatedButton = input<boolean>(false);
readonly viewIsolatedButtonLabel = input<string>('artemisApp.textUnit.isolated');
readonly viewIsolatedButtonIcon = input<IconDefinition>(faExternalLinkAlt);
Expand All @@ -32,6 +39,7 @@ export class LectureUnitComponent {
readonly onCompletion = output<boolean>();

readonly isVisibleToStudents = computed(() => this.lectureUnit().visibleToStudents);
readonly isStudentPath = computed(() => this.router.url.startsWith('/courses'));

toggleCompletion(event: Event) {
event.stopPropagation();
Expand All @@ -47,4 +55,9 @@ export class LectureUnitComponent {
event.stopPropagation();
this.onShowIsolated.emit();
}

handleOriginalVersionView(event: Event) {
event.stopPropagation();
this.onShowOriginalVersion.emit();
}
}
10 changes: 10 additions & 0 deletions src/main/webapp/app/shared/http/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,14 @@ export class FileService {
replaceAttachmentPrefixAndUnderscores(link: string): string {
return link.replace(/AttachmentUnit_\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}_/, '').replace(/_/g, ' ');
}

/**
* Returns the student version of the given link.
*
* @param link the file link
*/
createStudentLink(link: string): string {
const lastSlashIndex = link.lastIndexOf('/');
return `${link.substring(0, lastSlashIndex)}/student${link.substring(lastSlashIndex)}`;
}
}
1 change: 1 addition & 0 deletions src/main/webapp/i18n/en/lectureUnit.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"updated": "Text unit updated",
"tooltip": "This is a text unit",
"isolated": "View Isolated",
"originalVersion": "Original Version",
"notReleasedTooltip": "Text only visible to teaching assistants and instructors. Release date:",
"markdownHelp": "You can enter Markdown here. More information: ",
"cachedMarkdown": "Artemis found some unsaved markdown in the local storage. Do you want to load it? Save Date:",
Expand Down

0 comments on commit c18def3

Please sign in to comment.