diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index d54fe904b1bfbd75a69ab856c1c786469ca56b19..cc9c9c68b1e1ee2224a21ad2cb6e62b8096640a4 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -1,9 +1,8 @@ -import { AfterContentInit, AfterViewInit, Component, EventEmitter, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { RoomService } from '../../../services/http/room.service'; import { ActivatedRoute, Router } from '@angular/router'; import { RoomPageComponent } from '../../shared/room-page/room-page.component'; import { Room } from '../../../models/room'; -import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; import { Location } from '@angular/common'; import { NotificationService } from '../../../services/util/notification.service'; import { MatDialog } from '@angular/material/dialog'; @@ -21,7 +20,6 @@ import { AuthenticationService } from '../../../services/http/authentication.ser import { User } from '../../../models/user'; import { HeaderService } from '../../../services/util/header.service'; import { ArsComposeService } from '../../../../../projects/ars/src/lib/services/ars-compose.service'; -import { RoomPageEdit } from '../../shared/room-page/room-page-edit/room-page-edit'; @Component({ selector:'app-room-creator-page', @@ -36,67 +34,54 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni commentThreshold: number; updCommentThreshold: number; deviceType = localStorage.getItem('deviceType'); - viewModuleCount = 1; moderatorCommentCounter: number; commentCounterEmitSubscription: any; urlToCopy = `${window.location.protocol}//${window.location.hostname}/participant/room/`; headerInterface = null; - onDestroyListener: EventEmitter<void> = new EventEmitter<void>(); - onAfterViewInitListener: EventEmitter<void> = new EventEmitter<void>(); - onInitListener: EventEmitter<void> = new EventEmitter<void>(); - roomPageEdit:RoomPageEdit; constructor(protected roomService: RoomService, protected notification: NotificationService, protected route: ActivatedRoute, protected location: Location, - public dialog: MatDialog, + protected dialog: MatDialog, private translateService: TranslateService, protected langService: LanguageService, protected wsCommentService: WsCommentService, protected commentService: CommentService, private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, - public eventService: EventService, - public titleService: TitleService, - private notificationService: NotificationService, - private bonusTokenService: BonusTokenService, - public router: Router, - public translationService: TranslateService, - public authenticationService: AuthenticationService, - public headerService: HeaderService, - public composeService: ArsComposeService){ - super(roomService, route, location, wsCommentService, commentService, eventService); - this.commentCounterEmitSubscription = this.commentCounterEmit.subscribe(e => { - this.titleService.attachTitle('(' + e + ')'); - }); - langService.langEmitter.subscribe(lang => translateService.use(lang)); - this.roomPageEdit=new RoomPageEdit( - dialog, - translationService, - notification, + protected eventService: EventService, + protected titleService: TitleService, + protected notificationService: NotificationService, + protected bonusTokenService: BonusTokenService, + protected router: Router, + protected translationService: TranslateService, + protected authenticationService: AuthenticationService, + protected headerService: HeaderService, + protected composeService: ArsComposeService){ + super( roomService, - eventService, + route, location, + wsCommentService, commentService, + eventService, + dialog, + translateService, bonusTokenService, headerService, composeService, - authenticationService, - route, - { - onInitListener:this.onInitListener, - onAfterViewInitListener:this.onAfterViewInitListener, - onDestroyListener:this.onDestroyListener, - updateCommentSettings(settings: CommentSettingsDialog){ - this.updateCommentSettings(settings); - } - } + notification, + authenticationService ); + this.commentCounterEmitSubscription = this.commentCounterEmit.subscribe(e => { + this.titleService.attachTitle('(' + e + ')'); + }); + langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngAfterViewInit(){ - this.onAfterViewInitListener.emit(); + super.ngAfterViewInit(); } ngOnDestroy(){ @@ -106,7 +91,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni if (this.headerInterface){ this.headerInterface.unsubscribe(); } - this.onDestroyListener.emit(); } ngAfterContentInit(): void{ @@ -116,6 +100,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni } ngOnInit(){ + super.ngOnInit(); window.scroll(0, 0); this.translateService.use(localStorage.getItem('currentLang')); this.route.params.subscribe(params => { @@ -148,7 +133,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni this.eventService.makeFocusOnInputFalse(); } }); - this.onInitListener.emit(); } public announce(){ @@ -205,18 +189,5 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni }); } - updateCommentSettings(settings: CommentSettingsDialog){ - this.room.tags = settings.tags; - - if (this.moderationEnabled && !settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount - 1; - }else if (!this.moderationEnabled && settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount + 1; - } - - this.moderationEnabled = settings.enableModeration; - localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); - } - } diff --git a/src/app/components/moderator/moderator-comment-page/moderator-comment-page.component.ts b/src/app/components/moderator/moderator-comment-page/moderator-comment-page.component.ts index d1c321f8c28c7c4ca06aa8b36f55319ab1930e33..f12908cd5cc029a4656608e0f7a924f8594bf0c9 100644 --- a/src/app/components/moderator/moderator-comment-page/moderator-comment-page.component.ts +++ b/src/app/components/moderator/moderator-comment-page/moderator-comment-page.component.ts @@ -1,4 +1,4 @@ -import { AfterContentInit, AfterViewInit, Component, EventEmitter, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { User } from '../../../models/user'; import { NotificationService } from '../../../services/util/notification.service'; @@ -11,16 +11,11 @@ import { Room } from '../../../models/room'; import { HeaderService } from '../../../services/util/header.service'; import { RoomService } from '../../../services/http/room.service'; import { ArsComposeService } from '../../../../../projects/ars/src/lib/services/ars-compose.service'; -import { RoomPageEdit } from '../../shared/room-page/room-page-edit/room-page-edit'; -import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; -import { DialogActionButtonsComponent } from '../../shared/dialog/dialog-action-buttons/dialog-action-buttons.component'; import { MatDialog } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; import { Location } from '@angular/common'; import { CommentService } from '../../../services/http/comment.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; -import { throwError } from 'rxjs'; -import { RoomPageComponent } from '../../shared/room-page/room-page.component'; import { WsCommentService } from '../../../services/websockets/ws-comment.service'; @Component({ @@ -28,15 +23,10 @@ import { WsCommentService } from '../../../services/websockets/ws-comment.servic templateUrl: './moderator-comment-page.component.html', styleUrls: ['./moderator-comment-page.component.scss'] }) -export class ModeratorCommentPageComponent extends RoomPageComponent implements OnInit, OnDestroy, AfterContentInit, AfterViewInit { +export class ModeratorCommentPageComponent implements OnInit, OnDestroy, AfterContentInit, AfterViewInit { roomId: string; user: User; room: Room; - onDestroyListener: EventEmitter<void> = new EventEmitter<void>(); - onAfterViewInitListener: EventEmitter<void> = new EventEmitter<void>(); - onInitListener: EventEmitter<void> = new EventEmitter<void>(); - roomPageEdit:RoomPageEdit; - viewModuleCount = 1; listenerFn: () => void; @@ -55,29 +45,6 @@ export class ModeratorCommentPageComponent extends RoomPageComponent implements public commentService:CommentService, public bonusTokenService:BonusTokenService, public wsCommentService:WsCommentService) { - super(roomService, route, location, wsCommentService, commentService, eventService); - this.roomPageEdit=new RoomPageEdit( - dialog, - translationService, - notification, - roomService, - eventService, - location, - commentService, - bonusTokenService, - headerService, - composeService, - authenticationService, - route, - { - onInitListener:this.onInitListener, - onAfterViewInitListener:this.onAfterViewInitListener, - onDestroyListener:this.onDestroyListener, - updateCommentSettings(settings: CommentSettingsDialog){ - this.updateCommentSettings(settings); - } - } - ); } ngAfterContentInit(): void { @@ -87,7 +54,6 @@ export class ModeratorCommentPageComponent extends RoomPageComponent implements } ngAfterViewInit(){ - this.onAfterViewInitListener.emit(); } ngOnInit(): void { @@ -117,26 +83,11 @@ export class ModeratorCommentPageComponent extends RoomPageComponent implements document.getElementById('sort-button').focus(); } }); - this.onInitListener.emit(); } ngOnDestroy() { this.listenerFn(); this.eventService.makeFocusOnInputFalse(); - this.onDestroyListener.emit(); - } - - updateCommentSettings(settings: CommentSettingsDialog){ - this.room.tags = settings.tags; - - if (this.moderationEnabled && !settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount - 1; - }else if (!this.moderationEnabled && settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount + 1; - } - - this.moderationEnabled = settings.enableModeration; - localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); } public announce() { diff --git a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts index 466dc34e6c8ac31f174be4617257fa90e2fed111..e133b7dcfd77fafad64cefc72144570b3a805e10 100644 --- a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts +++ b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Renderer2, OnDestroy, AfterContentInit } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { Room } from '../../../models/room'; import { RoomPageComponent } from '../../shared/room-page/room-page.component'; import { Location } from '@angular/common'; @@ -14,19 +14,23 @@ import { LiveAnnouncer } from '@angular/cdk/a11y'; import { EventService } from '../../../services/util/event.service'; import { KeyboardUtils } from '../../../utils/keyboard'; import { KeyboardKey } from '../../../utils/keyboard/keys'; +import { MatDialog } from '@angular/material/dialog'; +import { BonusTokenService } from '../../../services/http/bonus-token.service'; +import { HeaderService } from '../../../services/util/header.service'; +import { ArsComposeService } from '../../../../../projects/ars/src/lib/services/ars-compose.service'; +import { AuthenticationService } from '../../../services/http/authentication.service'; @Component({ selector: 'app-room-moderator-page', templateUrl: './room-moderator-page.component.html', styleUrls: ['./room-moderator-page.component.scss'] }) -export class RoomModeratorPageComponent extends RoomPageComponent implements OnInit, OnDestroy, AfterContentInit { +export class RoomModeratorPageComponent extends RoomPageComponent implements OnInit, OnDestroy, AfterContentInit, AfterViewInit { room: Room; isLoading = true; deviceType = localStorage.getItem('deviceType'); moderatorCommentCounter: number; - viewModuleCount = 1; constructor(protected location: Location, protected roomService: RoomService, @@ -38,8 +42,27 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI protected notification: NotificationService, public eventService: EventService, private liveAnnouncer: LiveAnnouncer, - private _r: Renderer2) { - super(roomService, route, location, wsCommentService, commentService, eventService); + private _r: Renderer2, + protected dialog:MatDialog, + protected bonusTokenService:BonusTokenService, + protected headerService:HeaderService, + protected composeService:ArsComposeService, + protected authenticationService:AuthenticationService) { + super( + roomService, + route, + location, + wsCommentService, + commentService, + eventService, + dialog, + translateService, + bonusTokenService, + headerService, + composeService, + notification, + authenticationService + ); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -94,7 +117,16 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI }, 700); } + ngAfterViewInit(){ + super.ngAfterViewInit(); + } + + ngOnDestroy(){ + super.ngOnDestroy(); + } + ngOnInit() { + super.ngOnInit(); window.scroll(0, 0); this.route.params.subscribe(params => { this.initializeRoom(params['shortId']); diff --git a/src/app/components/participant/room-participant-page/room-participant-page.component.ts b/src/app/components/participant/room-participant-page/room-participant-page.component.ts index 9f71b7cf90e93affa5f80d19d029f87678b79829..c604d760e88146a9a1f3d4d4fc90d0afe320bc5a 100644 --- a/src/app/components/participant/room-participant-page/room-participant-page.component.ts +++ b/src/app/components/participant/room-participant-page/room-participant-page.component.ts @@ -1,4 +1,4 @@ -import { AfterContentInit, AfterViewInit, Component, EventEmitter, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { Room } from '../../../models/room'; import { User } from '../../../models/user'; import { UserRole } from '../../../models/user-roles.enum'; @@ -18,7 +18,6 @@ import { KeyboardKey } from '../../../utils/keyboard/keys'; import { map } from 'rxjs/operators'; import { Observable, of } from 'rxjs'; import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; -import { RoomPageEdit } from '../../shared/room-page/room-page-edit/room-page-edit'; import { MatDialog } from '@angular/material/dialog'; import { NotificationService } from '../../../services/util/notification.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; @@ -36,11 +35,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O isLoading = true; deviceType = localStorage.getItem('deviceType'); user: User; - viewModuleCount = 1; - roomPageEdit:RoomPageEdit; - onDestroyListener: EventEmitter<void> = new EventEmitter<void>(); - onAfterViewInitListener: EventEmitter<void> = new EventEmitter<void>(); - onInitListener: EventEmitter<void> = new EventEmitter<void>(); constructor(protected location: Location, protected roomService: RoomService, @@ -58,35 +52,26 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O public bonusTokenService:BonusTokenService, public headerService:HeaderService, public composeService:ArsComposeService) { - super(roomService, route, location, wsCommentService, commentService, eventService); - langService.langEmitter.subscribe(lang => translateService.use(lang)); - this.roomPageEdit=new RoomPageEdit( - dialog, - translateService, - notification, + super( roomService, - eventService, + route, location, + wsCommentService, commentService, + eventService, + dialog, + translateService, bonusTokenService, headerService, composeService, - authenticationService, - route, - { - onInitListener:this.onInitListener, - onAfterViewInitListener:this.onAfterViewInitListener, - onDestroyListener:this.onDestroyListener, - updateCommentSettings(settings: CommentSettingsDialog){ - this.updateCommentSettings(settings); - } - } + notification, + authenticationService ); + langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnDestroy(){ super.ngOnDestroy(); - this.onDestroyListener.emit(); } ngAfterContentInit(): void { @@ -96,10 +81,11 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O } ngAfterViewInit(){ - this.onAfterViewInitListener.emit(); + super.ngAfterViewInit() } ngOnInit() { + super.ngOnInit(); window.scroll(0, 0); this.route.params.subscribe(params => { this.initializeRoom(params['shortId']); @@ -120,7 +106,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O this.eventService.makeFocusOnInputFalse(); } }); - this.onInitListener.emit(); } public announce() { @@ -152,19 +137,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O } } - updateCommentSettings(settings: CommentSettingsDialog){ - this.room.tags = settings.tags; - - if (this.moderationEnabled && !settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount - 1; - }else if (!this.moderationEnabled && settings.enableModeration){ - this.viewModuleCount = this.viewModuleCount + 1; - } - - this.moderationEnabled = settings.enableModeration; - localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); - } - postRoomLoadHook() { if (!this.authenticationService.hasAccess(this.room.shortId, UserRole.PARTICIPANT)) { this.authenticationService.setAccess(this.room.shortId, UserRole.PARTICIPANT); diff --git a/src/app/components/shared/room-page/room-page.component.ts b/src/app/components/shared/room-page/room-page.component.ts index 75646e1ef38f157c0e25bfc20c9cf071c8bacbc3..923341342ba0483a58215b141572048d52d26602 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -1,21 +1,29 @@ -import { Component, OnInit, OnDestroy, EventEmitter } from '@angular/core'; +import { AfterViewInit, Component, EventEmitter, OnDestroy, OnInit } from '@angular/core'; import { Room } from '../../../models/room'; -import { User } from '../../../models/user'; import { RoomService } from '../../../services/http/room.service'; import { ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; import { WsCommentService } from '../../../services/websockets/ws-comment.service'; import { CommentService } from '../../../services/http/comment.service'; import { EventService } from '../../../services/util/event.service'; -import { Message, IMessage } from '@stomp/stompjs'; -import { Observable, Subscription, of } from 'rxjs'; +import { IMessage, Message } from '@stomp/stompjs'; +import { Observable, of, Subscription } from 'rxjs'; +import { RoomPageEdit } from './room-page-edit/room-page-edit'; +import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; +import { MatDialog } from '@angular/material/dialog'; +import { TranslateService } from '@ngx-translate/core'; +import { BonusTokenService } from '../../../services/http/bonus-token.service'; +import { HeaderService } from '../../../services/util/header.service'; +import { ArsComposeService } from '../../../../../projects/ars/src/lib/services/ars-compose.service'; +import { NotificationService } from '../../../services/util/notification.service'; +import { AuthenticationService } from '../../../services/http/authentication.service'; @Component({ selector: 'app-room-page', templateUrl: './room-page.component.html', styleUrls: ['./room-page.component.scss'] }) -export class RoomPageComponent implements OnInit, OnDestroy { +export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { room: Room = null; isLoading = true; commentCounter: number; @@ -24,15 +32,53 @@ export class RoomPageComponent implements OnInit, OnDestroy { protected commentWatch: Observable<IMessage>; protected listenerFn: () => void; public commentCounterEmit: EventEmitter<number> = new EventEmitter<number>(); + public onDestroyListener: EventEmitter<void> = new EventEmitter<void>(); + public onAfterViewInitListener: EventEmitter<void> = new EventEmitter<void>(); + public onInitListener: EventEmitter<void> = new EventEmitter<void>(); public encodedShortId:string; + public roomPageEdit:RoomPageEdit; + public viewModuleCount = 1; constructor(protected roomService: RoomService, protected route: ActivatedRoute, protected location: Location, protected wsCommentService: WsCommentService, protected commentService: CommentService, - protected eventService: EventService + protected eventService: EventService, + protected dialog:MatDialog, + protected translate:TranslateService, + protected bonusTokenService:BonusTokenService, + protected headerService:HeaderService, + protected composeService:ArsComposeService, + protected notification:NotificationService, + protected authenticationService:AuthenticationService ) { + this.roomPageEdit=new RoomPageEdit( + dialog, + translate, + notification, + roomService, + eventService, + location, + commentService, + bonusTokenService, + headerService, + composeService, + authenticationService, + route, + { + onInitListener:this.onInitListener, + onAfterViewInitListener:this.onAfterViewInitListener, + onDestroyListener:this.onDestroyListener, + updateCommentSettings(settings: CommentSettingsDialog){ + this.updateCommentSettings(settings); + } + } + ); + } + + ngAfterViewInit(){ + this.onAfterViewInitListener.emit(); } ngOnInit() { @@ -40,6 +86,7 @@ export class RoomPageComponent implements OnInit, OnDestroy { this.initializeRoom(params['shortId']); this.encodedShortId = params['shortId']; }); + this.onInitListener.emit(); } ngOnDestroy() { @@ -48,6 +95,7 @@ export class RoomPageComponent implements OnInit, OnDestroy { if (this.sub) { this.sub.unsubscribe(); } + this.onDestroyListener.emit(); } protected preRoomLoadHook(): Observable<any> { @@ -93,4 +141,15 @@ export class RoomPageComponent implements OnInit, OnDestroy { this.roomService.deleteRoom(room.id).subscribe(); this.location.back(); } + + updateCommentSettings(settings: CommentSettingsDialog){ + this.room.tags = settings.tags; + if (this.moderationEnabled && !settings.enableModeration){ + this.viewModuleCount = this.viewModuleCount - 1; + }else if (!this.moderationEnabled && settings.enableModeration){ + this.viewModuleCount = this.viewModuleCount + 1; + } + this.moderationEnabled = settings.enableModeration; + localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); + } }