import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { ActivatedRoute, Router } from '@angular/router'; import { animate, style, transition, trigger } from '@angular/animations'; import { Group } from './group.model'; import { GroupService } from './group.service'; import { MeetingService } from '../meeting/meeting.service'; import { AppFocusService } from '../core/focus.service'; import { AuthService } from '../user/auth.service'; import { FollowService } from '../shared/services/follow.service'; import { Title } from '@angular/platform-browser'; @Component({ selector: 'civ-group', template: `

{{group.name}}

`, styleUrls: [ './group.page.scss' ], host: {'[@host]': ''}, animations: [ trigger('host', [ transition('void => *', [ style({transform: 'translateX(100%)'}), animate('250ms 100ms ease-in', style({transform: 'translateX(0)'})) ])/*, transition('* => void', [ animate('250ms 100ms ease-in', style({transform:'translateX(-100%)'})) ])*/ ]) ] }) export class GroupPage implements OnInit { group$: Observable; isAdmin: Observable; numFollows$: Observable; isFollowing$: Observable; baseUrl: Observable; constructor(private groupSvc: GroupService, private followSvc: FollowService, private meetingSvc: MeetingService, private router: Router, private route: ActivatedRoute, private focusSvc: AppFocusService, private authSvc: AuthService, private title: Title) { this.baseUrl = this.route.params.take(1).map(params => [ '/group', params[ 'groupId' ] ] ); const groupId$ = this.route.params.map(params => params['groupId']); this.group$ = this.groupSvc.getActiveGroup().filter(it => !!it); this.group$ .filter(it => !!it) .take(1).subscribe(group => this.title.setTitle(group.name)); this.isAdmin = Observable.combineLatest(this.authSvc.sessionUser$, this.group$, (user, group) => !!user && (user.superuser || group.owner == user.id)); this.numFollows$ = groupId$.flatMap(id => this.followSvc.getFollowCount('group', id)); this.isFollowing$ = groupId$.flatMap(id => this.followSvc.isFollowing('group', id)); } ngOnInit() { } addFollow() { this.group$.take(1).subscribe(group => { this.followSvc.follow('group', group.id).subscribe(result => { console.log('follow result"'); console.log(result); }) }) } unfollow() { this.group$.take(1).subscribe(group => { this.followSvc.unfollow('group', group.id).subscribe(result => { console.log('unfollow result"'); console.log(result); }) }) } }