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 cc9c9c68b1e1ee2224a21ad2cb6e62b8096640a4..d54fe904b1bfbd75a69ab856c1c786469ca56b19 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,8 +1,9 @@ -import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, EventEmitter, 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'; @@ -20,6 +21,7 @@ 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', @@ -34,54 +36,67 @@ 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, - protected dialog: MatDialog, + public dialog: MatDialog, private translateService: TranslateService, protected langService: LanguageService, protected wsCommentService: WsCommentService, protected commentService: CommentService, private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, - 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( + 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, roomService, - route, + eventService, location, - wsCommentService, commentService, - eventService, - dialog, - translateService, bonusTokenService, headerService, composeService, - notification, - authenticationService + authenticationService, + route, + { + onInitListener:this.onInitListener, + onAfterViewInitListener:this.onAfterViewInitListener, + onDestroyListener:this.onDestroyListener, + updateCommentSettings(settings: CommentSettingsDialog){ + this.updateCommentSettings(settings); + } + } ); - this.commentCounterEmitSubscription = this.commentCounterEmit.subscribe(e => { - this.titleService.attachTitle('(' + e + ')'); - }); - langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngAfterViewInit(){ - super.ngAfterViewInit(); + this.onAfterViewInitListener.emit(); } ngOnDestroy(){ @@ -91,6 +106,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni if (this.headerInterface){ this.headerInterface.unsubscribe(); } + this.onDestroyListener.emit(); } ngAfterContentInit(): void{ @@ -100,7 +116,6 @@ 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 => { @@ -133,6 +148,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni this.eventService.makeFocusOnInputFalse(); } }); + this.onInitListener.emit(); } public announce(){ @@ -189,5 +205,18 @@ 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 f12908cd5cc029a4656608e0f7a924f8594bf0c9..d1c321f8c28c7c4ca06aa8b36f55319ab1930e33 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, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, EventEmitter, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { User } from '../../../models/user'; import { NotificationService } from '../../../services/util/notification.service'; @@ -11,11 +11,16 @@ 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({ @@ -23,10 +28,15 @@ import { WsCommentService } from '../../../services/websockets/ws-comment.servic templateUrl: './moderator-comment-page.component.html', styleUrls: ['./moderator-comment-page.component.scss'] }) -export class ModeratorCommentPageComponent implements OnInit, OnDestroy, AfterContentInit, AfterViewInit { +export class ModeratorCommentPageComponent extends RoomPageComponent 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; @@ -45,6 +55,29 @@ export class ModeratorCommentPageComponent implements OnInit, OnDestroy, AfterCo 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 { @@ -54,6 +87,7 @@ export class ModeratorCommentPageComponent implements OnInit, OnDestroy, AfterCo } ngAfterViewInit(){ + this.onAfterViewInitListener.emit(); } ngOnInit(): void { @@ -83,11 +117,26 @@ export class ModeratorCommentPageComponent implements OnInit, OnDestroy, AfterCo 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 e133b7dcfd77fafad64cefc72144570b3a805e10..466dc34e6c8ac31f174be4617257fa90e2fed111 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 { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { Component, OnInit, Renderer2, OnDestroy, AfterContentInit } from '@angular/core'; import { Room } from '../../../models/room'; import { RoomPageComponent } from '../../shared/room-page/room-page.component'; import { Location } from '@angular/common'; @@ -14,23 +14,19 @@ 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, AfterViewInit { +export class RoomModeratorPageComponent extends RoomPageComponent implements OnInit, OnDestroy, AfterContentInit { room: Room; isLoading = true; deviceType = localStorage.getItem('deviceType'); moderatorCommentCounter: number; + viewModuleCount = 1; constructor(protected location: Location, protected roomService: RoomService, @@ -42,27 +38,8 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI protected notification: NotificationService, public eventService: EventService, private liveAnnouncer: LiveAnnouncer, - 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 - ); + private _r: Renderer2) { + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -117,16 +94,7 @@ 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 c604d760e88146a9a1f3d4d4fc90d0afe320bc5a..9f71b7cf90e93affa5f80d19d029f87678b79829 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, OnDestroy, OnInit, Renderer2 } from '@angular/core'; +import { AfterContentInit, AfterViewInit, Component, EventEmitter, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { Room } from '../../../models/room'; import { User } from '../../../models/user'; import { UserRole } from '../../../models/user-roles.enum'; @@ -18,6 +18,7 @@ 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'; @@ -35,6 +36,11 @@ 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, @@ -52,26 +58,35 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O public bonusTokenService:BonusTokenService, public headerService:HeaderService, public composeService:ArsComposeService) { - super( + super(roomService, route, location, wsCommentService, commentService, eventService); + langService.langEmitter.subscribe(lang => translateService.use(lang)); + this.roomPageEdit=new RoomPageEdit( + dialog, + translateService, + notification, roomService, - route, + eventService, location, - wsCommentService, commentService, - eventService, - dialog, - translateService, bonusTokenService, headerService, composeService, - notification, - authenticationService + authenticationService, + route, + { + onInitListener:this.onInitListener, + onAfterViewInitListener:this.onAfterViewInitListener, + onDestroyListener:this.onDestroyListener, + updateCommentSettings(settings: CommentSettingsDialog){ + this.updateCommentSettings(settings); + } + } ); - langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnDestroy(){ super.ngOnDestroy(); + this.onDestroyListener.emit(); } ngAfterContentInit(): void { @@ -81,11 +96,10 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O } ngAfterViewInit(){ - super.ngAfterViewInit() + this.onAfterViewInitListener.emit(); } ngOnInit() { - super.ngOnInit(); window.scroll(0, 0); this.route.params.subscribe(params => { this.initializeRoom(params['shortId']); @@ -106,6 +120,7 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O this.eventService.makeFocusOnInputFalse(); } }); + this.onInitListener.emit(); } public announce() { @@ -137,6 +152,19 @@ 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 923341342ba0483a58215b141572048d52d26602..75646e1ef38f157c0e25bfc20c9cf071c8bacbc3 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -1,29 +1,21 @@ -import { AfterViewInit, Component, EventEmitter, OnDestroy, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy, EventEmitter } 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 { 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'; +import { Message, IMessage } from '@stomp/stompjs'; +import { Observable, Subscription, of } from 'rxjs'; @Component({ selector: 'app-room-page', templateUrl: './room-page.component.html', styleUrls: ['./room-page.component.scss'] }) -export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { +export class RoomPageComponent implements OnInit, OnDestroy { room: Room = null; isLoading = true; commentCounter: number; @@ -32,53 +24,15 @@ export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { 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 dialog:MatDialog, - protected translate:TranslateService, - protected bonusTokenService:BonusTokenService, - protected headerService:HeaderService, - protected composeService:ArsComposeService, - protected notification:NotificationService, - protected authenticationService:AuthenticationService + protected eventService: EventService ) { - 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() { @@ -86,7 +40,6 @@ export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { this.initializeRoom(params['shortId']); this.encodedShortId = params['shortId']; }); - this.onInitListener.emit(); } ngOnDestroy() { @@ -95,7 +48,6 @@ export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { if (this.sub) { this.sub.unsubscribe(); } - this.onDestroyListener.emit(); } protected preRoomLoadHook(): Observable<any> { @@ -141,15 +93,4 @@ export class RoomPageComponent implements OnInit, OnDestroy, AfterViewInit { 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)); - } }