Skip to content

Commit

Permalink
make all use inject via script
Browse files Browse the repository at this point in the history
  • Loading branch information
cremertim committed Nov 29, 2024
1 parent d47da0a commit eacc8bd
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, ElementRef, OnDestroy, QueryList, ViewChild, ViewChildren, effect, input } from '@angular/core';
import { AfterViewInit, Component, ElementRef, OnDestroy, QueryList, ViewChild, ViewChildren, effect, inject, input } from '@angular/core';
import interact from 'interactjs';
import { Exercise } from 'app/entities/exercise.model';
import { Lecture } from 'app/entities/lecture.model';
Expand Down Expand Up @@ -59,14 +59,14 @@ export class DiscussionSectionComponent extends CourseDiscussionDirective implem
faArrowLeft = faArrowLeft;
faLongArrowRight = faLongArrowRight;

constructor(
protected metisService: MetisService,
private channelService: ChannelService,
private activatedRoute: ActivatedRoute,
private router: Router,
private formBuilder: FormBuilder,
) {
super(metisService);
protected metisService = inject(MetisService);
private channelService = inject(ChannelService);
private activatedRoute = inject(ActivatedRoute);
private router = inject(Router);
private formBuilder = inject(FormBuilder);

constructor() {
super();
effect(() => this.loadData(this.exercise(), this.lecture()));
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/webapp/app/shared/metis/answer-post.service.ts
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 { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand All @@ -9,11 +9,9 @@ type EntityResponseType = HttpResponse<AnswerPost>;

@Injectable({ providedIn: 'root' })
export class AnswerPostService extends PostingService<AnswerPost> {
public resourceUrl = 'api/courses/';
protected http = inject(HttpClient);

constructor(protected http: HttpClient) {
super();
}
public resourceUrl = 'api/courses/';

/**
* creates an answerPost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
Component,
EventEmitter,
HostListener,
Inject,
Input,
OnChanges,
OnInit,
Output,
Renderer2,
ViewChild,
ViewContainerRef,
inject,
input,
} from '@angular/core';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
Expand Down Expand Up @@ -59,6 +59,10 @@ import { EmojiPickerComponent } from 'app/shared/metis/emoji/emoji-picker.compon
],
})
export class AnswerPostComponent extends PostingDirective<AnswerPost> implements OnInit, OnChanges {
changeDetector = inject(ChangeDetectorRef);
renderer = inject(Renderer2);
private document = inject<Document>(DOCUMENT);

@Input() lastReadDate?: dayjs.Dayjs;
@Input() isLastAnswer: boolean;
@Output() openPostingCreateEditModal = new EventEmitter<void>();
Expand All @@ -83,14 +87,6 @@ export class AnswerPostComponent extends PostingDirective<AnswerPost> implements
mayDelete: boolean = false;
@ViewChild(AnswerPostReactionsBarComponent) private reactionsBarComponent!: AnswerPostReactionsBarComponent;

constructor(
public changeDetector: ChangeDetectorRef,
public renderer: Renderer2,
@Inject(DOCUMENT) private document: Document,
) {
super();
}

ngOnInit() {
super.ngOnInit();
this.assignPostingToAnswerPost();
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 { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ChannelDTO, ChannelIdAndNameDTO } from 'app/entities/metis/conversation/channel.model';
Expand All @@ -8,13 +8,11 @@ import { AccountService } from 'app/core/auth/account.service';

@Injectable({ providedIn: 'root' })
export class ChannelService {
public resourceUrl = '/api/courses/';
private http = inject(HttpClient);
private conversationService = inject(ConversationService);
private accountService = inject(AccountService);

constructor(
private http: HttpClient,
private conversationService: ConversationService,
private accountService: AccountService,
) {}
public resourceUrl = '/api/courses/';

getChannelsOfCourse(courseId: number): Observable<HttpResponse<ChannelDTO[]>> {
return this.http.get<ChannelDTO[]>(`${this.resourceUrl}${courseId}/channels/overview`, {
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 { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -32,13 +32,11 @@ export enum ConversationMemberSearchFilter {
}
@Injectable({ providedIn: 'root' })
export class ConversationService {
public resourceUrl = '/api/courses/';
protected http = inject(HttpClient);
protected translationService = inject(TranslateService);
protected accountService = inject(AccountService);

constructor(
protected http: HttpClient,
protected translationService: TranslateService,
protected accountService: AccountService,
) {}
public resourceUrl = '/api/courses/';

getConversationName(conversation: ConversationDTO | undefined, showLogin = false): string {
if (!conversation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { OneToOneChatDTO } from 'app/entities/metis/conversation/one-to-one-chat
import { GroupChatDTO } from 'app/entities/metis/conversation/group-chat.model';
import { Observable, map } from 'rxjs';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, inject } from '@angular/core';
import { AccountService } from 'app/core/auth/account.service';

@Injectable({ providedIn: 'root' })
export class GroupChatService {
public resourceUrl = 'api/courses/';
private http = inject(HttpClient);
private conversationService = inject(ConversationService);
private accountService = inject(AccountService);

constructor(
private http: HttpClient,
private conversationService: ConversationService,
private accountService: AccountService,
) {}
public resourceUrl = 'api/courses/';

create(courseId: number, loginsOfChatPartners: string[]): Observable<HttpResponse<GroupChatDTO>> {
return this.http
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 { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ConversationService } from 'app/shared/metis/conversations/conversation.service';
Expand All @@ -7,12 +7,10 @@ import { OneToOneChatDTO } from 'app/entities/metis/conversation/one-to-one-chat

@Injectable({ providedIn: 'root' })
export class OneToOneChatService {
public resourceUrl = '/api/courses/';
private http = inject(HttpClient);
private conversationService = inject(ConversationService);

constructor(
private http: HttpClient,
private conversationService: ConversationService,
) {}
public resourceUrl = '/api/courses/';

create(courseId: number, loginOfChatPartner: string): Observable<HttpResponse<OneToOneChatDTO>> {
return this.http
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive } from '@angular/core';
import { Directive, inject } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { faFilter, faLongArrowAltDown, faLongArrowAltUp, faPlus, faSearch, faTimes } from '@fortawesome/free-solid-svg-icons';
import { PostContextFilter, PostSortCriterion, SortDirection } from 'app/shared/metis/metis.util';
Expand All @@ -12,6 +12,8 @@ import { MetisService } from 'app/shared/metis/metis.service';
providers: [MetisService],
})
export abstract class CourseDiscussionDirective {
protected metisService = inject(MetisService);

searchText?: string;
currentPostContextFilter: PostContextFilter;
formGroup: FormGroup;
Expand All @@ -37,8 +39,6 @@ export abstract class CourseDiscussionDirective {
faLongArrowAltUp = faLongArrowAltUp;
faLongArrowAltDown = faLongArrowAltDown;

protected constructor(protected metisService: MetisService) {}

/**
* on changing any filter, the metis service is invoked to deliver all posts for the
* currently set context, filtered on the server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, inject } from '@angular/core';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
import { MetisService } from 'app/shared/metis/metis.service';
import { FormBuilder, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
Expand All @@ -21,16 +21,12 @@ import { TranslateDirective } from 'app/shared/language/translate.directive';
imports: [FormsModule, ReactiveFormsModule, PostingMarkdownEditorComponent, TranslateDirective, PostingButtonComponent, ArtemisSharedCommonModule],
})
export class MessageInlineInputComponent extends PostingCreateEditDirective<Post | AnswerPost> implements OnInit {
warningDismissed = false;
protected metisService = inject(MetisService);
protected modalService = inject(NgbModal);
protected formBuilder = inject(FormBuilder);
protected localStorageService = inject(LocalStorageService);

constructor(
protected metisService: MetisService,
protected modalService: NgbModal,
protected formBuilder: FormBuilder,
protected localStorageService: LocalStorageService,
) {
super(metisService, modalService, formBuilder);
}
warningDismissed = false;

ngOnInit(): void {
super.ngOnInit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, input } from '@angular/core';
import { Component, EventEmitter, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject, input } from '@angular/core';
import { AnswerPost } from 'app/entities/metis/answer-post.model';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { MetisService } from 'app/shared/metis/metis.service';
Expand All @@ -21,22 +21,18 @@ import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module';
imports: [FormsModule, ReactiveFormsModule, PostingMarkdownEditorComponent, TranslateDirective, PostingButtonComponent, ArtemisSharedCommonModule],
})
export class MessageReplyInlineInputComponent extends PostingCreateEditDirective<AnswerPost> implements OnInit, OnChanges {
protected metisService = inject(MetisService);
protected modalService = inject(NgbModal);
protected formBuilder = inject(FormBuilder);
protected localStorageService = inject(LocalStorageService);

warningDismissed = false;

readonly activeConversation = input<ConversationDTO>();

@Output()
valueChange = new EventEmitter<void>();

constructor(
protected metisService: MetisService,
protected modalService: NgbModal,
protected formBuilder: FormBuilder,
protected localStorageService: LocalStorageService,
) {
super(metisService, modalService, formBuilder);
}

ngOnInit(): void {
super.ngOnInit();
this.warningDismissed = !!this.localStorageService.retrieve('chatWarningDismissed');
Expand Down
24 changes: 12 additions & 12 deletions src/main/webapp/app/shared/metis/metis-conversation.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Injectable, OnDestroy, inject } from '@angular/core';
import { EMPTY, Observable, ReplaySubject, Subject, Subscription, catchError, finalize, map, of, switchMap, tap } from 'rxjs';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { ConversationService } from 'app/shared/metis/conversations/conversation.service';
Expand Down Expand Up @@ -26,6 +26,16 @@ import { NotificationService } from 'app/shared/notification/notification.servic
*/
@Injectable()
export class MetisConversationService implements OnDestroy {
private groupChatService = inject(GroupChatService);
private oneToOneChatService = inject(OneToOneChatService);
private channelService = inject(ChannelService);
protected conversationService = inject(ConversationService);
private jhiWebsocketService = inject(JhiWebsocketService);
private accountService = inject(AccountService);
private alertService = inject(AlertService);
private router = inject(Router);
private notificationService = inject(NotificationService);

// Stores the conversation of the course where the current user is a member
private conversationsOfUser: ConversationDTO[] = [];
_conversationsOfUser$: ReplaySubject<ConversationDTO[]> = new ReplaySubject<ConversationDTO[]>(1);
Expand All @@ -52,17 +62,7 @@ export class MetisConversationService implements OnDestroy {

private _isServiceSetup$: ReplaySubject<boolean> = new ReplaySubject<boolean>(1);

constructor(
private groupChatService: GroupChatService,
private oneToOneChatService: OneToOneChatService,
private channelService: ChannelService,
protected conversationService: ConversationService,
private jhiWebsocketService: JhiWebsocketService,
private accountService: AccountService,
private alertService: AlertService,
private router: Router,
private notificationService: NotificationService,
) {
constructor() {
this.accountService.identity().then((user: User) => {
this.userId = user.id!;
});
Expand Down
21 changes: 11 additions & 10 deletions src/main/webapp/app/shared/metis/metis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ import { cloneDeep } from 'lodash-es';

@Injectable()
export class MetisService implements OnDestroy {
protected postService = inject(PostService);
protected answerPostService = inject(AnswerPostService);
protected reactionService = inject(ReactionService);
protected accountService = inject(AccountService);
protected exerciseService = inject(ExerciseService);
private jhiWebsocketService = inject(JhiWebsocketService);
private conversationService = inject(ConversationService);

private posts$: ReplaySubject<Post[]> = new ReplaySubject<Post[]>(1);
private tags$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
private totalNumberOfPosts$: ReplaySubject<number> = new ReplaySubject<number>(1);
Expand All @@ -53,16 +61,9 @@ export class MetisService implements OnDestroy {
private courseWideTopicSubscription: Subscription;
private savedPostService: SavedPostService = inject(SavedPostService);

constructor(
protected postService: PostService,
protected answerPostService: AnswerPostService,
protected reactionService: ReactionService,
protected accountService: AccountService,
protected exerciseService: ExerciseService,
private jhiWebsocketService: JhiWebsocketService,
private conversationService: ConversationService,
notificationService: NotificationService,
) {
constructor() {
const notificationService = inject(NotificationService);

this.accountService.identity().then((user: User) => {
this.user = user!;
});
Expand Down
8 changes: 3 additions & 5 deletions src/main/webapp/app/shared/metis/post.service.ts
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 { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand All @@ -13,11 +13,9 @@ type EntityArrayResponseType = HttpResponse<Post[]>;

@Injectable({ providedIn: 'root' })
export class PostService extends PostingService<Post> {
public resourceUrl = 'api/courses/';
protected http = inject(HttpClient);

constructor(protected http: HttpClient) {
super();
}
public resourceUrl = 'api/courses/';

/**
* creates a post
Expand Down
Loading

0 comments on commit eacc8bd

Please sign in to comment.