|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { Router, ActivatedRoute } from '@angular/router'; |
| 3 | +import { Observable, forkJoin, combineLatest } from 'rxjs'; |
| 4 | +import { switchMap, map, take } from 'rxjs/operators'; |
| 5 | +import { Insight } from 'models/entities/insights/insight.model'; |
| 6 | +import { Project } from 'models/entities/project.model'; |
| 7 | +import { AuthService } from 'components/auth/auth.service'; |
| 8 | +import { InsightService } from 'components/insight/insight.service'; |
| 9 | +import { ProjectAuthorizationService } from '../project-authorization.service'; |
| 10 | +import { ProjectDataService } from '../project-data.service'; |
| 11 | +import { Thread } from 'models/messaging/thread.model'; |
| 12 | +import { MessagingService } from 'components/messaging/messaging.service'; |
| 13 | + |
| 14 | +@Component({ |
| 15 | + selector: 'project-thread', |
| 16 | + template: require('./project-thread.html'), |
| 17 | + styles: [require('./project-thread.scss')], |
| 18 | +}) |
| 19 | +export class ProjectThreadComponent implements OnInit { |
| 20 | + private project$: Observable<Project>; |
| 21 | + private thread$: Observable<Thread>; |
| 22 | + |
| 23 | + private canEdit = false; // used in html |
| 24 | + private canDelete = false; // used in html |
| 25 | + |
| 26 | + static parameters = [ |
| 27 | + Router, |
| 28 | + ActivatedRoute, |
| 29 | + ProjectDataService, |
| 30 | + MessagingService, |
| 31 | + // ProjectAuthorizationService, |
| 32 | + // InsightService, |
| 33 | + // AuthService, |
| 34 | + ]; |
| 35 | + constructor( |
| 36 | + private router: Router, |
| 37 | + private route: ActivatedRoute, |
| 38 | + private projectDataService: ProjectDataService, |
| 39 | + private messagingService: MessagingService |
| 40 | + ) // private projectAuthorizationService: ProjectAuthorizationService, |
| 41 | + // private insightService: InsightService, |
| 42 | + // private authService: AuthService |
| 43 | + { |
| 44 | + this.project$ = this.projectDataService.project(); |
| 45 | + |
| 46 | + this.router.routeReuseStrategy.shouldReuseRoute = function() { |
| 47 | + return false; |
| 48 | + }; |
| 49 | + } |
| 50 | + |
| 51 | + ngOnInit() { |
| 52 | + this.thread$ = this.route.params.pipe( |
| 53 | + switchMap(params => this.messagingService.getThread(params.threadId)), |
| 54 | + take(1) |
| 55 | + ); |
| 56 | + |
| 57 | + // const canAdminProject$ = this.project$.pipe( |
| 58 | + // switchMap(project => this.projectAuthorizationService.canAdmin(project._id)) |
| 59 | + // ); |
| 60 | + |
| 61 | + // // TODO Check that the author has Write access |
| 62 | + // const isAuthor$ = forkJoin({ |
| 63 | + // authInfo: this.authService.authInfo().pipe(take(1)), |
| 64 | + // insight: this.insight$, |
| 65 | + // }).pipe( |
| 66 | + // map(res => { |
| 67 | + // return res.authInfo.user._id.toString() === res.insight.createdBy._id.toString(); |
| 68 | + // }) |
| 69 | + // ); |
| 70 | + |
| 71 | + // combineLatest(canAdminProject$, isAuthor$).subscribe(([canAdminProject, isAuthor]) => { |
| 72 | + // this.canEdit = canAdminProject || isAuthor; |
| 73 | + // this.canDelete = canAdminProject || isAuthor; |
| 74 | + // }); |
| 75 | + } |
| 76 | +} |
0 commit comments