Skip to content
Snippets Groups Projects
Commit 1a69c93c authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel
Browse files

Merge branch...

Merge branch '679-adapt-components-to-roles-based-on-routes-instead-of-the-user-itself' into 'staging'

Resolve "Adapt components to roles based on routes instead of the user itself"

Closes #679 and #709

See merge request arsnova/frag.jetzt!712
parents 035b982d 6089cf9d
No related merge requests found
Showing
with 66 additions and 64 deletions
......@@ -24,7 +24,6 @@ import { TitleService } from '../../../services/util/title.service';
import { DeleteCommentsComponent } from '../_dialogs/delete-comments/delete-comments.component';
import { Export } from '../../../models/export';
import { BonusTokenService } from '../../../services/http/bonus-token.service';
import { TopicCloudFilterComponent } from '../../shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component';
import { RoomDeleteComponent } from '../_dialogs/room-delete/room-delete.component';
import { RoomDeleted } from '../../../models/events/room-deleted';
import { ProfanitySettingsComponent } from '../_dialogs/profanity-settings/profanity-settings.component';
......@@ -437,12 +436,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
dialogRef.componentInstance.room = this.room;
}
showTagCloud(): void{
const dialogRef = this.dialog.open(TopicCloudFilterComponent, {
width:'400px'
});
}
showTagsDialog(): void{
this.updRoom = JSON.parse(JSON.stringify(this.room));
const dialogRef = this.dialog.open(TagsComponent, {
......
......@@ -6,6 +6,6 @@
[onClose]="this.onNoClick.bind(this)"
[isSpinning]="isSendingToSpacy"
[tags]="tags"
[isModerator]="user && user.role > 0">
[isModerator]="userRole > 0">
</app-write-comment>
</ars-row>
......@@ -11,6 +11,7 @@ import { CreateCommentKeywords, KeywordsResultType } from '../../../../utils/cre
import { WriteCommentComponent } from '../../write-comment/write-comment.component';
import { DeepLService } from '../../../../services/http/deep-l.service';
import { SpacyService } from '../../../../services/http/spacy.service';
import { UserRole } from '../../../../models/user-roles.enum';
@Component({
selector: 'app-submit-comment',
......@@ -21,6 +22,7 @@ export class CreateCommentComponent implements OnInit {
@ViewChild(WriteCommentComponent) commentComponent: WriteCommentComponent;
@Input() user: User;
@Input() userRole: UserRole;
@Input() roomId: string;
@Input() tags: string[];
isSendingToSpacy = false;
......@@ -40,7 +42,7 @@ export class CreateCommentComponent implements OnInit {
ngOnInit() {
this.translateService.use(localStorage.getItem('currentLang'));
this.isModerator = this.user && this.user.role > 0;
this.isModerator = this.userRole > 0;
}
onNoClick(): void {
......@@ -60,7 +62,7 @@ export class CreateCommentComponent implements OnInit {
comment.roomId = localStorage.getItem(`roomId`);
comment.body = body;
comment.creatorId = this.user.id;
comment.createdFromLecturer = this.user.role > 0;
comment.createdFromLecturer = this.userRole > 0;
comment.tag = tag;
comment.questionerName = name;
this.isSendingToSpacy = true;
......
......@@ -14,7 +14,6 @@ import {
KeywordOrFulltext,
TopicCloudAdminDataScoringObject, TopicCloudAdminDataScoringKey, keywordsScoringMinMax, ensureDefaultScorings
} from './TopicCloudAdminData';
import { User } from '../../../../models/user';
import { Comment } from '../../../../models/comment';
import { CommentService } from '../../../../services/http/comment.service';
import { TSMap } from 'typescript-map';
......@@ -114,7 +113,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy {
this.profanitywordlist = list;
this.refreshKeywords();
});
this.isCreatorOrMod = this.data.user.role !== UserRole.PARTICIPANT;
this.isCreatorOrMod = this.data.userRole > UserRole.PARTICIPANT;
this.translateService.use(localStorage.getItem('currentLang'));
this.spacyLabels = spacyLabels;
this.wantedLabels = undefined;
......@@ -329,7 +328,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy {
endDate: this.endDate.length ? this.endDate : null,
scorings: this.scorings
};
this.topicCloudAdminService.setAdminData(this.topicCloudAdminData, true, this.data.user.role);
this.topicCloudAdminService.setAdminData(this.topicCloudAdminData, true, this.data.userRole);
}
setDefaultAdminData() {
......@@ -643,7 +642,7 @@ interface Keyword {
}
export interface Data {
user: User;
userRole: UserRole;
}
enum KeywordType {
......
......@@ -60,7 +60,7 @@
<span *ngIf="isMobile()">{{'content.tag-cloud-questions-brainstorming-short' | translate}}</span>
<span *ngIf="!isMobile()">{{'content.tag-cloud-questions-brainstorming' | translate}}</span>
</mat-radio-button>
<mat-form-field *ngIf="user && user.role > 0 && radioButton.checked"
<mat-form-field *ngIf="userRole > 0 && radioButton.checked"
appearance="fill">
<mat-label>{{'content.brainstorming-question' | translate}}</mat-label>
<input matInput
......
......@@ -13,7 +13,6 @@ import { CommentListData } from '../../comment-list/comment-list.component';
import { TopicCloudAdminService } from '../../../../services/util/topic-cloud-admin.service';
import { TopicCloudAdminData } from '../topic-cloud-administration/TopicCloudAdminData';
import { TagCloudDataService } from '../../../../services/util/tag-cloud-data.service';
import { User } from '../../../../models/user';
import { WorkerDialogComponent } from '../worker-dialog/worker-dialog.component';
import { Room } from '../../../../models/room';
import { ThemeService } from '../../../../../theme/theme.service';
......@@ -43,7 +42,7 @@ enum KeywordsSource {
})
export class TopicCloudFilterComponent implements OnInit, OnDestroy {
@Input() target: string;
@Input() user: User;
@Input() userRole: UserRole;
question = '';
continueFilter = 'continueWithAll';
......@@ -122,7 +121,7 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy {
this.continueFilter = 'continueWithAll';
}
if (this.filteredComments.comments === 0 && this.allComments.comments === 0) {
if (this.user && this.user.role > UserRole.PARTICIPANT) {
if (this.userRole > UserRole.PARTICIPANT) {
setTimeout(() => {
this.continueFilter = 'continueWithAllFromNow';
});
......@@ -215,7 +214,7 @@ export class TopicCloudFilterComponent implements OnInit, OnDestroy {
if (newCount + count < 1) {
return false;
}
if (this.user && this.user.role === UserRole.PARTICIPANT) {
if (this.userRole === UserRole.PARTICIPANT) {
return newCount < 1;
}
if (count * 2 / 3 < newCount) {
......
......@@ -4,13 +4,13 @@
<div fxLayout="row"
fxLayoutAlign="center">
<app-comment [comment]="comment"
[userRole]="user.role"></app-comment>
[userRole]="userRole"></app-comment>
</div>
<div fxLayout="row"
fxLayoutAlign="center">
<mat-card class="answer border-answer"
*ngIf="!isStudent || answer">
<app-write-comment [isModerator]="user && user.role > 0"
<app-write-comment [isModerator]="userRole > 0"
[isCommentAnswer]="true"
[placeholder]="'comment-page.your-answer'"
[onClose]="openDeleteAnswerDialog()"
......
......@@ -5,13 +5,10 @@ import { LanguageService } from '../../../services/util/language.service';
import { WsCommentService } from '../../../services/websockets/ws-comment.service';
import { CommentService } from '../../../services/http/comment.service';
import { Comment } from '../../../models/comment';
import { User } from '../../../models/user';
import { AuthenticationService } from '../../../services/http/authentication.service';
import { UserRole } from '../../../models/user-roles.enum';
import { NotificationService } from '../../../services/util/notification.service';
import { MatDialog } from '@angular/material/dialog';
import { DeleteAnswerComponent } from '../../creator/_dialogs/delete-answer/delete-answer.component';
import { LanguagetoolService } from '../../../services/http/languagetool.service';
import { EventService } from '../../../services/util/event.service';
import { WriteCommentComponent } from '../write-comment/write-comment.component';
import { CorrectWrong } from '../../../models/correct-wrong.enum';
......@@ -29,7 +26,7 @@ export class CommentAnswerComponent implements OnInit, OnDestroy {
comment: Comment;
answer: string;
isLoading = true;
user: User;
userRole: UserRole;
isStudent = true;
edit = false;
private _commentSubscription;
......@@ -40,15 +37,13 @@ export class CommentAnswerComponent implements OnInit, OnDestroy {
protected langService: LanguageService,
protected wsCommentService: WsCommentService,
protected commentService: CommentService,
private authenticationService: AuthenticationService,
public languagetoolService: LanguagetoolService,
public dialog: MatDialog,
public eventService: EventService) {
}
ngOnInit() {
this.user = this.authenticationService.getUser();
if (this.user.role !== UserRole.PARTICIPANT) {
this.userRole = this.route.snapshot.data.roles[0];
if (this.userRole !== UserRole.PARTICIPANT) {
this.isStudent = false;
}
this.route.params.subscribe(params => {
......
......@@ -425,7 +425,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
}
writeComment() {
this.createCommentWrapper.openCreateDialog(this.user)
this.createCommentWrapper.openCreateDialog(this.user, this.userRole)
.subscribe(comment => this.focusCommentId = comment && comment.id);
}
......
......@@ -143,11 +143,11 @@
<!-- Moderator board / index -->
<ng-container
*ngIf="user && user.role > 0 && (router.url.endsWith('/moderator/comments') || router.url.includes('/comment/'))">
*ngIf="userRole > 0 && (router.url.endsWith('/moderator/comments') || router.url.includes('/comment/'))">
<button mat-menu-item
tabindex="0"
*ngIf="user.role == 3"
*ngIf="userRole == 3"
routerLink="creator/room/{{shortId}}/comments">
<mat-icon>
forum
......@@ -157,7 +157,7 @@
<button mat-menu-item
tabindex="0"
*ngIf="user.role > 0 && user.role < 3"
*ngIf="userRole > 0 && userRole < 3"
routerLink="moderator/room/{{shortId}}/comments">
<mat-icon>
forum
......@@ -167,7 +167,7 @@
</ng-container>
<ng-container *ngIf="user && user.role == 0 && router.url.includes('/comment/')">
<ng-container *ngIf="userRole == 0 && router.url.includes('/comment/')">
<button mat-menu-item
tabindex="0"
......@@ -184,7 +184,8 @@
<ng-container *ngIf="router.url.endsWith('/comments')">
<button mat-menu-item
*ngIf="user && user.role > 0 && !router.url.includes('/comment/') && !router.url.endsWith('/tagcloud') && !router.url.endsWith('moderator/comments')"
*ngIf="userRole > 0 && !router.url.includes('/comment/') && !router.url.endsWith('/tagcloud') &&
!router.url.endsWith('moderator/comments')"
tabindex="0"
(click)="showQRDialog();">
<mat-icon svgIcon="qrcode"
......@@ -195,7 +196,7 @@
<button mat-menu-item
tabindex="0"
*ngIf="user && user.role > 0 && !router.url.includes('/participant/') &&
*ngIf="userRole > 0 && !router.url.includes('/participant/') &&
!router.url.endsWith('moderator/comments')"
routerLink="moderator/room/{{shortId}}/moderator/comments">
<mat-icon>visibility_off</mat-icon>
......@@ -232,7 +233,8 @@
<!-- Room General Options - bot -->
<ng-container
*ngIf="user && user.role == 3 && !router.url.includes('/participant') && !router.url.endsWith('/comments') && !router.url.includes('/comment/') && !router.url.endsWith('tagcloud')">
*ngIf="userRole == 3 && !router.url.includes('/participant') && !router.url.endsWith('/comments') &&
!router.url.includes('/comment/') && !router.url.endsWith('tagcloud')">
</ng-container>
......@@ -248,7 +250,7 @@
</button>
<button mat-menu-item
*ngIf="user && user.role >0 && router.url.endsWith('/tagcloud')"
*ngIf="userRole > 0 && router.url.endsWith('/tagcloud')"
tabindex="0"
(click)="navigateTopicCloudConfig()">
<mat-icon aria-label="Configuration Icon">cloud</mat-icon>
......@@ -256,7 +258,7 @@
</button>
<button mat-menu-item
*ngIf="user && user.role >0 && router.url.endsWith('/tagcloud')"
*ngIf="userRole > 0 && router.url.endsWith('/tagcloud')"
tabindex="0"
(click)="navigateTopicCloudAdministration()">
<mat-icon aria-hidden="false"
......@@ -268,7 +270,7 @@
<button mat-menu-item
tabindex="0"
*ngIf="user && user.role > 0 && router.url.endsWith('/tagcloud')"
*ngIf="userRole > 0 && router.url.endsWith('/tagcloud')"
(click)="startWorkerDialog()">
<mat-icon>cloud
</mat-icon>
......@@ -290,7 +292,7 @@
<!-- General Options -->
<button mat-menu-item
*ngIf="user && user.role == 0 && !router.url.endsWith('/tagcloud') && !router.url.endsWith('/quiz')"
*ngIf="userRole == 0 && !router.url.endsWith('/tagcloud') && !router.url.endsWith('/quiz')"
(click)="openUserBonusTokenDialog()"
tabindex="0">
<mat-icon class="star">grade</mat-icon>
......@@ -301,7 +303,7 @@
<ng-container *ngIf="router.url.endsWith('/comments') || router.url.endsWith('/tagcloud')">
<button mat-menu-item
*ngIf="user && user.role == 0"
*ngIf="userRole == 0"
tabindex="0"
routerLink="participant/room/{{shortId}}">
<mat-icon>
......@@ -311,7 +313,7 @@
</button>
<button mat-menu-item
*ngIf="user && user.role == 3"
*ngIf="userRole == 3"
tabindex="0"
routerLink="creator/room/{{shortId}}">
<mat-icon>
......@@ -321,7 +323,7 @@
</button>
<button mat-menu-item
*ngIf="user && user.role == 2"
*ngIf="userRole == 2"
tabindex="0"
routerLink="moderator/room/{{shortId}}">
<mat-icon>
......
......@@ -40,6 +40,7 @@ import { ThemeService } from '../../../../theme/theme.service';
export class HeaderComponent implements OnInit, AfterViewInit {
@ViewChild(ArsComposeHostDirective) host: ArsComposeHostDirective;
user: User;
userRole: UserRole;
cTime: string;
shortId: string;
isSafari = 'false';
......@@ -72,7 +73,7 @@ export class HeaderComponent implements OnInit, AfterViewInit {
private topicCloudAdminService: TopicCloudAdminService,
private headerService: HeaderService,
private onboardingService: OnboardingService,
public themeService: ThemeService
public themeService: ThemeService,
) {
}
......@@ -81,6 +82,20 @@ export class HeaderComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
this.router.events.subscribe(e => {
if (e instanceof NavigationEnd) {
const url = e.url.toLowerCase();
if (url.startsWith('/participant/')) {
this.userRole = UserRole.PARTICIPANT;
} else if (url.startsWith('/moderator/')) {
this.userRole = UserRole.EXECUTIVE_MODERATOR;
} else if (url.startsWith('/creator/')) {
this.userRole = UserRole.CREATOR;
} else {
this.userRole = this.user ? this.user.role : UserRole.PARTICIPANT;
}
}
});
this.topicCloudAdminService.getAdminData.subscribe(data => {
this.isAdminConfigEnabled = !TopicCloudAdminService.isTopicRequirementDisabled(data);
});
......@@ -364,7 +379,7 @@ export class HeaderComponent implements OnInit, AfterViewInit {
autoFocus: false
});
confirmDialogRef.componentInstance.target = this.router.url + '/tagcloud';
confirmDialogRef.componentInstance.user = this.user;
confirmDialogRef.componentInstance.userRole = this.userRole;
}
public navigateTopicCloudConfig() {
......
......@@ -16,7 +16,7 @@
{{tagData && tagData.distinctUsers.size}}
</p>
</span>
<button *ngIf="user && user.role >= 1 && isBlacklistActive" mat-button (click)="addBlacklistWord()">
<button *ngIf="userRole > 0 && isBlacklistActive" mat-button (click)="addBlacklistWord()">
<mat-icon matTooltip="{{'tag-cloud.blacklist-topic' | translate}}">gavel</mat-icon>
</button>
</div>
......@@ -42,7 +42,7 @@
</p>
</span>
</div>
<div class="replacementContainer" *ngIf="user && user.role >= 1">
<div class="replacementContainer" *ngIf="userRole > 0">
<mat-form-field>
<mat-label>{{'tag-cloud-popup.tag-correction-placeholder' | translate}}</mat-label>
<input type="text"
......
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { LanguageService } from '../../../../services/util/language.service';
import { AuthenticationService } from '../../../../services/http/authentication.service';
import { User } from '../../../../models/user';
import { TagCloudDataService, TagCloudDataTagEntry } from '../../../../services/util/tag-cloud-data.service';
import { Language, LanguagetoolService } from '../../../../services/http/languagetool.service';
import { FormControl } from '@angular/forms';
......@@ -12,6 +10,7 @@ import { NotificationService } from '../../../../services/util/notification.serv
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { UserRole } from '../../../../models/user-roles.enum';
import { SpacyKeyword } from '../../../../services/http/spacy.service';
import { ActivatedRoute } from '@angular/router';
const CLOSE_TIME = 1500;
......@@ -29,7 +28,7 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
tagData: TagCloudDataTagEntry;
categories: string[];
timePeriodText: string;
user: User;
userRole: UserRole;
selectedLang: Language = 'en-US';
spellingData: string[] = [];
isBlacklistActive = true;
......@@ -39,10 +38,10 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
constructor(private langService: LanguageService,
private translateService: TranslateService,
private authenticationService: AuthenticationService,
private tagCloudDataService: TagCloudDataService,
private languagetoolService: LanguagetoolService,
private commentService: CommentService,
private route: ActivatedRoute,
private notificationService: NotificationService) {
this.langService.langEmitter.subscribe(lang => {
this.translateService.use(lang);
......@@ -50,12 +49,8 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
}
ngOnInit(): void {
this.userRole = this.route.snapshot.data.roles[0];
this.timePeriodText = '...';
this.authenticationService.watchUser.subscribe(newUser => {
if (newUser) {
this.user = newUser;
}
});
}
ngAfterViewInit() {
......@@ -84,7 +79,7 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit {
return;
}
this.spellingData = [];
if (this.user && this.user.role > UserRole.PARTICIPANT) {
if (this.userRole > UserRole.PARTICIPANT) {
this.languagetoolService.checkSpellings(tag, 'auto').subscribe(correction => {
const langKey = correction.language.code.split('-')[0].toUpperCase();
if (['DE', 'FR', 'EN'].indexOf(langKey) < 0) {
......
......@@ -30,12 +30,12 @@
</angular-tag-cloud>
<app-active-user *ngIf="room" [alwaysShowInHeader]="true" [room]="this.room" [top]="120"></app-active-user>
</ars-fill>
<button *ngIf="((user && user.role > 0) || (room && !room.questionsBlocked)) && drawer && !drawer.opened"
<button *ngIf="((userRole > 0) || (room && !room.questionsBlocked)) && drawer && !drawer.opened"
mat-fab
mat-icon-button
aria-labelledby="add"
class="fab_add_comment"
(click)="createCommentWrapper.openCreateDialog(this.user).subscribe()"
(click)="createCommentWrapper.openCreateDialog(user, userRole).subscribe()"
matTooltip="{{ 'comment-list.add-comment' | translate }}">
<mat-icon>add</mat-icon>
</button>
......
......@@ -161,10 +161,11 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit {
}
ngOnInit(): void {
this.userRole = this.route.snapshot.data.roles[0];
this.updateGlobalStyles();
this.headerInterface = this.eventService.on<string>('navigate').subscribe(e => {
if (e === 'createQuestion') {
this.createCommentWrapper.openCreateDialog(this.user).subscribe();
this.createCommentWrapper.openCreateDialog(this.user, this.userRole).subscribe();
} else if (e === 'topicCloudConfig') {
if (this.drawer.opened) {
this.drawer.close();
......@@ -176,7 +177,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit {
minWidth: '50%',
maxHeight: '95%',
data: {
user: this.user
userRole: this.userRole
}
});
} else if (e === 'questionBoard') {
......@@ -200,7 +201,6 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit {
this.user = newUser;
}
});
this.userRole = this.route.snapshot.data.roles[0];
this.route.params.subscribe(params => {
this.shortId = params['shortId'];
this.authenticationService.checkAccess(this.shortId);
......
......@@ -11,6 +11,7 @@ import { observable, Observable, of } from 'rxjs';
import { flatMap } from 'rxjs/internal/operators';
import { tap } from 'rxjs/operators';
import { MatSnackBarConfig } from '@angular/material/snack-bar';
import { UserRole } from '../models/user-roles.enum';
export class CreateCommentWrapper {
constructor(private translateService: TranslateService,
......@@ -20,7 +21,7 @@ export class CreateCommentWrapper {
private room: Room) {
}
openCreateDialog(user: User): Observable<Comment> {
openCreateDialog(user: User, userRole: UserRole): Observable<Comment> {
const dialogRef = this.dialog.open(CreateCommentComponent, {
width: '900px',
maxWidth: '100%',
......@@ -28,6 +29,7 @@ export class CreateCommentWrapper {
autoFocus: false,
});
dialogRef.componentInstance.user = user;
dialogRef.componentInstance.userRole = userRole;
dialogRef.componentInstance.roomId = this.room.id;
dialogRef.componentInstance.tags = this.room.tags || [];
return dialogRef.afterClosed().pipe(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment