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

Development: Migrate text module to use inject #9772

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { Component, Input } from '@angular/core';
import { Component, Input, inject } from '@angular/core';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { filter } from 'rxjs/operators';
import { FileUploadExercise } from 'app/entities/file-upload-exercise.model';
import { FileUploadExerciseService } from './file-upload-exercise.service';
import { ExerciseComponent } from 'app/exercises/shared/exercise/exercise.component';
import { onError } from 'app/shared/util/global.utils';
import { AccountService } from 'app/core/auth/account.service';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { SortService } from 'app/shared/service/sort.service';
import { ExerciseService } from 'app/exercises/shared/exercise/exercise.service';
import { AlertService } from 'app/core/util/alert.service';
import { EventManager } from 'app/core/util/event-manager.service';
import { faBook, faPlus, faSort, faTable, faTrash, faUsers, faWrench } from '@fortawesome/free-solid-svg-icons';
import { faListAlt } from '@fortawesome/free-regular-svg-icons';
import { CourseExerciseService } from 'app/exercises/shared/course-exercises/course-exercise.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
selector: 'jhi-file-upload-exercise',
templateUrl: './file-upload-exercise.component.html',
})
export class FileUploadExerciseComponent extends ExerciseComponent {
protected exerciseService = inject(ExerciseService);
protected fileUploadExerciseService = inject(FileUploadExerciseService);
private courseExerciseService = inject(CourseExerciseService);
private alertService = inject(AlertService);
private accountService = inject(AccountService);
private sortService = inject(SortService);

@Input() fileUploadExercises: FileUploadExercise[] = [];
filteredFileUploadExercises: FileUploadExercise[] = [];

Expand All @@ -40,23 +42,6 @@ export class FileUploadExerciseComponent extends ExerciseComponent {
return this.fileUploadExercises;
}

constructor(
public exerciseService: ExerciseService,
public fileUploadExerciseService: FileUploadExerciseService,
private courseExerciseService: CourseExerciseService,
private alertService: AlertService,
private accountService: AccountService,
private modalService: NgbModal,
private router: Router,
private sortService: SortService,
courseService: CourseManagementService,
translateService: TranslateService,
eventManager: EventManager,
route: ActivatedRoute,
) {
super(courseService, translateService, route, eventManager);
}

protected loadExercises(): void {
this.courseExerciseService
.findAllFileUploadExercisesForCourse(this.courseId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { Component, Input } from '@angular/core';
import { Component, Input, inject } from '@angular/core';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { ModelingExercise } from 'app/entities/modeling-exercise.model';
import { ModelingExerciseService } from './modeling-exercise.service';
import { AccountService } from 'app/core/auth/account.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ActivatedRoute, Router } from '@angular/router';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { ExerciseComponent } from 'app/exercises/shared/exercise/exercise.component';
import { TranslateService } from '@ngx-translate/core';
import { onError } from 'app/shared/util/global.utils';
import { SortService } from 'app/shared/service/sort.service';
import { ExerciseService } from 'app/exercises/shared/exercise/exercise.service';
import { AlertService } from 'app/core/util/alert.service';
import { EventManager } from 'app/core/util/event-manager.service';
import { faBook, faPlus, faSort, faTable, faTimes, faTrash, faUsers, faWrench } from '@fortawesome/free-solid-svg-icons';
import { faListAlt } from '@fortawesome/free-regular-svg-icons';
import { CourseExerciseService } from 'app/exercises/shared/course-exercises/course-exercise.service';
Expand All @@ -22,7 +17,14 @@ import { CourseExerciseService } from 'app/exercises/shared/course-exercises/cou
templateUrl: './modeling-exercise.component.html',
})
export class ModelingExerciseComponent extends ExerciseComponent {
@Input() modelingExercises: ModelingExercise[];
protected exerciseService = inject(ExerciseService);
protected modelingExerciseService = inject(ModelingExerciseService);
private courseExerciseService = inject(CourseExerciseService);
private alertService = inject(AlertService);
private accountService = inject(AccountService);
private sortService = inject(SortService);

@Input() modelingExercises: ModelingExercise[] = [];
filteredModelingExercises: ModelingExercise[];
// Icons
faPlus = faPlus;
Expand All @@ -39,24 +41,6 @@ export class ModelingExerciseComponent extends ExerciseComponent {
return this.modelingExercises;
}

constructor(
public exerciseService: ExerciseService,
public modelingExerciseService: ModelingExerciseService,
private courseExerciseService: CourseExerciseService,
private alertService: AlertService,
private accountService: AccountService,
private sortService: SortService,
private modalService: NgbModal,
private router: Router,
courseService: CourseManagementService,
translateService: TranslateService,
eventManager: EventManager,
route: ActivatedRoute,
) {
super(courseService, translateService, route, eventManager);
this.modelingExercises = [];
}

protected loadExercises(): void {
this.courseExerciseService.findAllModelingExercisesForCourse(this.courseId).subscribe({
next: (res: HttpResponse<ModelingExercise[]>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { Component, ContentChild, Input, OnDestroy, OnInit, TemplateRef } from '@angular/core';
import { Component, ContentChild, Input, OnDestroy, OnInit, TemplateRef, inject } from '@angular/core';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { merge } from 'rxjs';
import { ProgrammingExercise } from 'app/entities/programming/programming-exercise.model';
import { ProgrammingExerciseInstructorRepositoryType, ProgrammingExerciseService } from './services/programming-exercise.service';
import { ActivatedRoute } from '@angular/router';
import { ExerciseComponent } from 'app/exercises/shared/exercise/exercise.component';
import { TranslateService } from '@ngx-translate/core';
import { ActionType } from 'app/shared/delete-dialog/delete-dialog.model';
import { onError } from 'app/shared/util/global.utils';
import { AccountService } from 'app/core/auth/account.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { FeatureToggle } from 'app/shared/feature-toggle/feature-toggle.service';
import { ExerciseService } from 'app/exercises/shared/exercise/exercise.service';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { SortService } from 'app/shared/service/sort.service';
import { ProgrammingExerciseEditSelectedComponent } from 'app/exercises/programming/manage/programming-exercise-edit-selected.component';
import { ProgrammingExerciseParticipationType } from 'app/entities/programming/programming-exercise-participation.model';
import { AlertService } from 'app/core/util/alert.service';
import { EventManager } from 'app/core/util/event-manager.service';
import { createBuildPlanUrl } from 'app/exercises/programming/shared/utils/programming-exercise.utils';
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { ConsistencyCheckComponent } from 'app/shared/consistency-check/consistency-check.component';
Expand Down Expand Up @@ -46,7 +42,16 @@ import { PROFILE_LOCALCI, PROFILE_LOCALVC, PROFILE_THEIA } from 'app/app.constan
templateUrl: './programming-exercise.component.html',
})
export class ProgrammingExerciseComponent extends ExerciseComponent implements OnInit, OnDestroy {
@Input() programmingExercises: ProgrammingExercise[];
protected exerciseService = inject(ExerciseService);
private programmingExerciseService = inject(ProgrammingExerciseService);
private courseExerciseService = inject(CourseExerciseService);
private accountService = inject(AccountService);
private alertService = inject(AlertService);
private modalService = inject(NgbModal);
private sortService = inject(SortService);
private profileService = inject(ProfileService);

FelixTJDietrich marked this conversation as resolved.
Show resolved Hide resolved
@Input() programmingExercises: ProgrammingExercise[] = [];
filteredProgrammingExercises: ProgrammingExercise[];
readonly ActionType = ActionType;
FeatureToggle = FeatureToggle;
Expand Down Expand Up @@ -82,24 +87,6 @@ export class ProgrammingExerciseComponent extends ExerciseComponent implements O
return this.programmingExercises;
}

constructor(
private programmingExerciseService: ProgrammingExerciseService,
private courseExerciseService: CourseExerciseService,
public exerciseService: ExerciseService,
private accountService: AccountService,
private alertService: AlertService,
private modalService: NgbModal,
private sortService: SortService,
private profileService: ProfileService,
courseService: CourseManagementService,
translateService: TranslateService,
eventManager: EventManager,
route: ActivatedRoute,
) {
super(courseService, translateService, route, eventManager);
this.programmingExercises = [];
}

ngOnInit(): void {
super.ngOnInit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { Component, Input } from '@angular/core';
import { Component, Input, inject } from '@angular/core';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { QuizExercise, QuizMode, QuizStatus } from 'app/entities/quiz/quiz-exercise.model';
import { QuizExerciseService } from './quiz-exercise.service';
import { AccountService } from 'app/core/auth/account.service';
import { ActivatedRoute, Router } from '@angular/router';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { ExerciseComponent } from 'app/exercises/shared/exercise/exercise.component';
import { TranslateService } from '@ngx-translate/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ActionType } from 'app/shared/delete-dialog/delete-dialog.model';
import { SortService } from 'app/shared/service/sort.service';
import { ExerciseService } from 'app/exercises/shared/exercise/exercise.service';
import { AlertService } from 'app/core/util/alert.service';
import { EventManager } from 'app/core/util/event-manager.service';
import { faSort, faTrash } from '@fortawesome/free-solid-svg-icons';
import { isQuizEditable } from 'app/exercises/quiz/shared/quiz-manage-util.service';

Expand All @@ -21,6 +16,12 @@ import { isQuizEditable } from 'app/exercises/quiz/shared/quiz-manage-util.servi
templateUrl: './quiz-exercise.component.html',
})
export class QuizExerciseComponent extends ExerciseComponent {
protected exerciseService = inject(ExerciseService);
protected quizExerciseService = inject(QuizExerciseService);
private accountService = inject(AccountService);
private alertService = inject(AlertService);
private sortService = inject(SortService);

readonly ActionType = ActionType;
readonly QuizStatus = QuizStatus;
readonly QuizMode = QuizMode;
Expand All @@ -36,22 +37,6 @@ export class QuizExerciseComponent extends ExerciseComponent {
return this.quizExercises;
}

constructor(
public quizExerciseService: QuizExerciseService,
private accountService: AccountService,
private alertService: AlertService,
private modalService: NgbModal,
private router: Router,
private sortService: SortService,
public exerciseService: ExerciseService,
courseService: CourseManagementService,
translateService: TranslateService,
eventManager: EventManager,
route: ActivatedRoute,
) {
super(courseService, translateService, route, eventManager);
}

protected loadExercises(): void {
this.quizExerciseService.findForCourse(this.courseId).subscribe({
next: (res: HttpResponse<QuizExercise[]>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, Subject, Subscription, merge } from 'rxjs';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
Expand All @@ -15,6 +15,11 @@ interface DeletionServiceInterface {

@Component({ template: '' })
export abstract class ExerciseComponent implements OnInit, OnDestroy {
protected translateService = inject(TranslateService);
protected eventManager = inject(EventManager);
private courseService = inject(CourseManagementService);
private route = inject(ActivatedRoute);

private eventSubscriber: Subscription;
@Input() embedded = false;
@Input() course: Course;
Expand All @@ -23,8 +28,8 @@ export abstract class ExerciseComponent implements OnInit, OnDestroy {
@Output() filteredExerciseCount = new EventEmitter<number>();
showHeading: boolean;
courseId: number;
predicate: string;
reverse: boolean;
predicate: string = 'id';
reverse: boolean = true;

selectedExercises: Exercise[] = [];
allChecked = false;
Expand All @@ -35,16 +40,6 @@ export abstract class ExerciseComponent implements OnInit, OnDestroy {

protected abstract get exercises(): Exercise[];

protected constructor(
private courseService: CourseManagementService,
protected translateService: TranslateService,
private route: ActivatedRoute,
protected eventManager: EventManager,
) {
this.predicate = 'id';
this.reverse = true;
}

/**
* Fetches an exercise from the server (and if needed the course as well)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TextAssessmentService } from 'app/exercises/text/assess/text-assessment.service';
import { TextAssessmentEvent, TextAssessmentEventType } from 'app/entities/text/text-assesment-event.model';
Expand All @@ -13,6 +13,11 @@ import { Location } from '@angular/common';
*/
@Injectable({ providedIn: 'root' })
export class TextAssessmentAnalytics {
protected assessmentsService = inject(TextAssessmentService);
protected accountService = inject(AccountService);
private location = inject(Location);
private profileService = inject(ProfileService);

FelixTJDietrich marked this conversation as resolved.
Show resolved Hide resolved
private userId: number;
private courseId: number;
private textExerciseId: number;
Expand All @@ -23,12 +28,7 @@ export class TextAssessmentAnalytics {
private route: ActivatedRoute;
public analyticsEnabled = false;

constructor(
protected assessmentsService: TextAssessmentService,
protected accountService: AccountService,
private profileService: ProfileService,
public location: Location,
) {
constructor() {
// retrieve the analytics enabled status from the profile info and set to current property
this.profileService.getProfileInfo().subscribe((profileInfo) => {
this.analyticsEnabled = profileInfo.textAssessmentAnalyticsEnabled || false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Component, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges, inject } from '@angular/core';
import { TextSubmission } from 'app/entities/text/text-submission.model';
import { TextBlockRef } from 'app/entities/text/text-block-ref.model';
import { StringCountService } from 'app/exercises/text/participate/string-count.service';
Expand All @@ -16,6 +16,8 @@ import { GradingCriterion } from 'app/exercises/shared/structured-grading-criter
],
})
export class TextAssessmentAreaComponent implements OnChanges {
private stringCountService = inject(StringCountService);

// inputs
@Input() submission: TextSubmission;
@Input() textBlockRefs: TextBlockRef[];
Expand All @@ -32,8 +34,6 @@ export class TextAssessmentAreaComponent implements OnChanges {
wordCount = 0;
characterCount = 0;

constructor(private stringCountService: StringCountService) {}

/**
* Life cycle hook to indicate component change
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, inject } from '@angular/core';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { TextBlockRef } from 'app/entities/text/text-block-ref.model';
import { TextSubmission } from 'app/entities/text/text-submission.model';
Expand All @@ -17,6 +17,11 @@ import { getCourseFromExercise } from 'app/entities/exercise.model';
template: '',
})
export abstract class TextAssessmentBaseComponent implements OnInit {
protected alertService = inject(AlertService);
protected accountService = inject(AccountService);
protected assessmentsService = inject(TextAssessmentService);
protected structuredGradingCriterionService = inject(StructuredGradingCriterionService);

/*
* Base Component for TextSubmissionAssessmentComponent and ExampleTextSubmissionComponent since they share a lot of same functions.
*/
Expand All @@ -29,13 +34,6 @@ export abstract class TextAssessmentBaseComponent implements OnInit {

readonly getCourseFromExercise = getCourseFromExercise;

protected constructor(
protected alertService: AlertService,
protected accountService: AccountService,
protected assessmentsService: TextAssessmentService,
protected structuredGradingCriterionService: StructuredGradingCriterionService,
) {}

async ngOnInit() {
// Used to check if the assessor is the current user
const identity = await this.accountService.identity();
Expand Down
Loading
Loading