Skip to content

Commit

Permalink
migrate programming-exercise-group-cell.component
Browse files Browse the repository at this point in the history
  • Loading branch information
coolchock committed Nov 27, 2024
1 parent 361b4cc commit 159069d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,38 +297,38 @@ <h5 class="group-title font-weight-bold mb-0">{{ exerciseGroup.title }}</h5>
@if (exerciseGroup.id && exerciseGroupToExerciseTypesDict.get(exerciseGroup.id)?.includes(exerciseType.PROGRAMMING)) {
<td class="align-middle">
@if (exercise.type === exerciseType.PROGRAMMING) {
<jhi-programming-exercise-group-cell [exercise]="exercise" [displayShortName]="true" />
<jhi-programming-exercise-group-cell [programmingExercise]="exercise" [displayShortName]="true" />
}
</td>
<td class="align-middle">
@if (exercise.type === exerciseType.PROGRAMMING) {
<jhi-programming-exercise-group-cell [exercise]="exercise" [displayRepositoryUri]="true" />
<jhi-programming-exercise-group-cell [programmingExercise]="exercise" [displayRepositoryUri]="true" />
}
</td>
<td class="align-middle">
@if (exercise.type === exerciseType.PROGRAMMING) {
<jhi-programming-exercise-group-cell [exercise]="exercise" [displayTemplateUrls]="true" />
<jhi-programming-exercise-group-cell [programmingExercise]="exercise" [displayTemplateUrls]="true" />
}
</td>
<td class="align-middle">
@if (exercise.type === exerciseType.PROGRAMMING) {
<jhi-programming-exercise-group-cell [exercise]="exercise" [displayEditorModus]="true" />
<jhi-programming-exercise-group-cell [programmingExercise]="exercise" [displayEditorModus]="true" />
}
</td>
}
@if (exerciseGroup.id && exerciseGroupToExerciseTypesDict.get(exerciseGroup.id!)?.includes(exerciseType.QUIZ)) {
<td class="align-middle">
<jhi-quiz-exercise-group-cell [exercise]="exercise" />
<jhi-quiz-exercise-group-cell [quizExercise]="exercise" />
</td>
}
@if (exerciseGroup.id && exerciseGroupToExerciseTypesDict.get(exerciseGroup.id!)?.includes(exerciseType.MODELING)) {
<td class="align-middle">
<jhi-modeling-exercise-group-cell [exercise]="exercise" />
<jhi-modeling-exercise-group-cell [modelingExercise]="exercise" />
</td>
}
@if (exerciseGroup.id && exerciseGroupToExerciseTypesDict.get(exerciseGroup.id!)?.includes(exerciseType.FILE_UPLOAD)) {
<td class="align-middle">
<jhi-file-upload-exercise-group-cell [exercise]="exercise" />
<jhi-file-upload-exercise-group-cell [fileUploadExercise]="exercise" />
</td>
}
@if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
@if (programmingExercise) {
@if (displayShortName) {
@if (programmingExercise()) {
@if (displayShortName()) {
<div>
{{ programmingExercise.shortName || '' }}
{{ programmingExercise().shortName || '' }}
</div>
}
@if (displayRepositoryUri) {
@if (displayRepositoryUri()) {
<div>
<div>
@if (programmingExercise.templateParticipation?.repositoryUri) {
@if (programmingExercise().templateParticipation?.repositoryUri) {
<!--Checks if the programming exercise has a setup with VCS and CI, if this not the case
the links/clone-buttons are disabled--->
@if (!localVCEnabled) {
<span>
<a href="{{ programmingExercise.templateParticipation?.repositoryUri || '' }}" target="_blank">Template</a>
<a href="{{ programmingExercise().templateParticipation?.repositoryUri || '' }}" target="_blank">Template</a>
</span>
} @else {
<a [routerLink]="" (click)="downloadRepository('TEMPLATE')"> <fa-icon [icon]="faDownload" /> Template </a>
}
}
@if (programmingExercise.templateParticipation?.results?.length) {
@if (programmingExercise().templateParticipation?.results?.length) {
<jhi-programming-exercise-instructor-status
[participationType]="participationType.TEMPLATE"
[participation]="programmingExercise.templateParticipation!"
[exercise]="programmingExercise"
[participation]="programmingExercise().templateParticipation!"
[exercise]="programmingExercise()"
/>
}
</div>
<div>
@if (programmingExercise.solutionParticipation?.repositoryUri) {
@if (programmingExercise().solutionParticipation?.repositoryUri) {
@if (!localVCEnabled) {
<span>
<a href="{{ programmingExercise.solutionParticipation?.repositoryUri || '' }}" target="_blank">Solution</a>
<a href="{{ programmingExercise().solutionParticipation?.repositoryUri || '' }}" target="_blank">Solution</a>
</span>
} @else {
<a [routerLink]="" (click)="downloadRepository('SOLUTION')"> <fa-icon [icon]="faDownload" /> Solution </a>
}
}
@if (programmingExercise.solutionParticipation?.results?.length) {
@if (programmingExercise().solutionParticipation?.results?.length) {
<jhi-programming-exercise-instructor-status
[participationType]="participationType.SOLUTION"
[participation]="programmingExercise.solutionParticipation!"
[exercise]="programmingExercise"
[participation]="programmingExercise().solutionParticipation!"
[exercise]="programmingExercise()"
/>
}
</div>
<div>
@if (programmingExercise.testRepositoryUri) {
@if (programmingExercise().testRepositoryUri) {
@if (!localVCEnabled) {
<span>
<a href="{{ programmingExercise.testRepositoryUri }}" target="_blank">Test</a>
<a href="{{ programmingExercise().testRepositoryUri }}" target="_blank">Test</a>
</span>
} @else {
<a [routerLink]="" (click)="downloadRepository('TESTS')"> <fa-icon [icon]="faDownload" /> Test </a>
Expand All @@ -57,44 +57,44 @@
</div>
</div>
}
@if (displayTemplateUrls) {
@if (displayTemplateUrls()) {
<div>
@if (programmingExercise.templateParticipation?.buildPlanId) {
@if (programmingExercise().templateParticipation?.buildPlanId) {
<span>
@if (!localVCEnabled) {
<a target="_blank" rel="noreferrer" href="{{ programmingExercise.templateParticipation!.buildPlanUrl }}">Template</a>
<a target="_blank" rel="noreferrer" href="{{ programmingExercise().templateParticipation!.buildPlanUrl }}">Template</a>
} @else {
{{ programmingExercise.templateParticipation!.buildPlanId }}
{{ programmingExercise().templateParticipation!.buildPlanId }}
}
</span>
}
<br />
@if (programmingExercise.solutionParticipation?.buildPlanId) {
@if (programmingExercise().solutionParticipation?.buildPlanId) {
<span>
@if (!localVCEnabled) {
<a target="_blank" rel="noreferrer" href="{{ programmingExercise.solutionParticipation!.buildPlanUrl }}">Solution</a>
<a target="_blank" rel="noreferrer" href="{{ programmingExercise().solutionParticipation!.buildPlanUrl }}">Solution</a>
} @else {
{{ programmingExercise.solutionParticipation!.buildPlanId }}
{{ programmingExercise().solutionParticipation!.buildPlanId }}
}
</span>
}
<br />
</div>
}
@if (displayEditorModus) {
@if (displayEditorModus()) {
<div>
<div class="d-flex justify-content-between">
<span class="colon-suffix" [jhiTranslate]="'artemisApp.programmingExercise.offlineIde'"></span>
<span [jhiTranslate]="programmingExercise.allowOfflineIde ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
<span [jhiTranslate]="programmingExercise().allowOfflineIde ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
</div>
<div class="d-flex justify-content-between">
<span class="colon-suffix" [jhiTranslate]="'artemisApp.programmingExercise.onlineEditor'"></span>
<span [jhiTranslate]="programmingExercise.allowOnlineEditor ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
<span [jhiTranslate]="programmingExercise().allowOnlineEditor ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
</div>
@if (onlineIdeEnabled) {
<div class="d-flex justify-content-between">
<span class="colon-suffix" [jhiTranslate]="'artemisApp.programmingExercise.onlineIde'"></span>
<span [jhiTranslate]="programmingExercise.allowOnlineIde ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
<span [jhiTranslate]="programmingExercise().allowOnlineIde ? 'artemisApp.exercise.yes' : 'artemisApp.exercise.no'"></span>
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, OnInit, inject, input } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { ProgrammingExercise } from 'app/entities/programming/programming-exercise.model';
import { ProgrammingExerciseParticipationType } from 'app/entities/programming/programming-exercise-participation.model';
import { Exercise } from 'app/entities/exercise.model';
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { createBuildPlanUrl } from 'app/exercises/programming/shared/utils/programming-exercise.utils';
import { ProgrammingExerciseInstructorRepositoryType, ProgrammingExerciseService } from 'app/exercises/programming/manage/services/programming-exercise.service';
Expand All @@ -17,53 +16,38 @@ import { PROFILE_LOCALVC, PROFILE_THEIA } from 'app/app.constants';
styles: [':host{display: contents}'],
})
export class ProgrammingExerciseGroupCellComponent implements OnInit {
participationType = ProgrammingExerciseParticipationType;
private profileService = inject(ProfileService);
private programmingExerciseService = inject(ProgrammingExerciseService);
private alertService = inject(AlertService);

programmingExercise: ProgrammingExercise;
participationType = ProgrammingExerciseParticipationType;

localVCEnabled = false;
onlineIdeEnabled = false;

@Input()
displayShortName = false;
@Input()
displayRepositoryUri = false;
@Input()
displayTemplateUrls = false;
@Input()
displayEditorModus = false;

@Input()
set exercise(exercise: Exercise) {
this.programmingExercise = exercise as ProgrammingExercise;
}
displayShortName = input(false);
displayRepositoryUri = input(false);
displayTemplateUrls = input(false);
displayEditorModus = input(false);
programmingExercise = input.required<ProgrammingExercise>();

faDownload = faDownload;

constructor(
private profileService: ProfileService,
private programmingExerciseService: ProgrammingExerciseService,
private alertService: AlertService,
) {}

ngOnInit(): void {
this.profileService.getProfileInfo().subscribe((profileInfo) => {
this.localVCEnabled = profileInfo.activeProfiles.includes(PROFILE_LOCALVC);
this.onlineIdeEnabled = profileInfo.activeProfiles.includes(PROFILE_THEIA);
if (this.programmingExercise.projectKey) {
if (this.programmingExercise.solutionParticipation?.buildPlanId) {
this.programmingExercise.solutionParticipation!.buildPlanUrl = createBuildPlanUrl(
profileInfo.buildPlanURLTemplate,
this.programmingExercise.projectKey,
this.programmingExercise.solutionParticipation.buildPlanId,
);

const projectKey = this.programmingExercise()?.projectKey;
if (projectKey) {
const solutionParticipation = this.programmingExercise()?.solutionParticipation;
if (solutionParticipation?.buildPlanId) {
solutionParticipation.buildPlanUrl = createBuildPlanUrl(profileInfo.buildPlanURLTemplate, projectKey, solutionParticipation.buildPlanId);
}
if (this.programmingExercise.templateParticipation?.buildPlanId) {
this.programmingExercise.templateParticipation!.buildPlanUrl = createBuildPlanUrl(
profileInfo.buildPlanURLTemplate,
this.programmingExercise.projectKey,
this.programmingExercise.templateParticipation.buildPlanId,
);

const templateParticipation = this.programmingExercise()?.templateParticipation;
if (templateParticipation?.buildPlanId) {
templateParticipation.buildPlanUrl = createBuildPlanUrl(profileInfo.buildPlanURLTemplate, projectKey, templateParticipation.buildPlanId);
}
}
});
Expand All @@ -76,10 +60,11 @@ export class ProgrammingExerciseGroupCellComponent implements OnInit {
*
* @param repositoryType
*/
downloadRepository(repositoryType: ProgrammingExerciseInstructorRepositoryType) {
if (this.programmingExercise.id) {
downloadRepository(repositoryType: ProgrammingExerciseInstructorRepositoryType): void {
const programmingExerciseId = this.programmingExercise()?.id;
if (programmingExerciseId) {
// Repository type cannot be 'AUXILIARY' as auxiliary repositories are currently not supported for the local VCS.
this.programmingExerciseService.exportInstructorRepository(this.programmingExercise.id, repositoryType, undefined).subscribe((response: HttpResponse<Blob>) => {
this.programmingExerciseService.exportInstructorRepository(programmingExerciseId, repositoryType, undefined).subscribe((response: HttpResponse<Blob>) => {
downloadZipFileFromResponse(response);
this.alertService.success('artemisApp.programmingExercise.export.successMessageRepos');
});
Expand Down

0 comments on commit 159069d

Please sign in to comment.