/**
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import { Component , OnDestroy , ElementRef , OnInit } from '@angular/core' ; import { ProjectService } from '../../services/project/project.service' ; import { Subscription } from 'rxjs' ; import { MatDialog } from '@angular/material/dialog' ; import { UserProfilePopupComponent } from '../user-profile-popup/user-profile-popup.component' ; import { Project } from '../../shared/models/project.model' ; import { NavigationService } from '../../services/navigation/navigation.service' ; import { List } from 'immutable' ; @ Component ( { selector : 'app-project-list' , templateUrl : './project-list.component.html' , styleUrls : [ './project-list.component.scss' ] , } ) export class ProjectListComponent implements OnInit , OnDestroy { projects = List < Project > ( ) ; private subscription = new Subscription ( ) ; constructor ( private projectService , private navigationService , private dialog ) { } ngOnInit ( ) { const allProjects = this . projectService . getAccessibleProjects$ ( ) ; this . subscription . add ( allProjects ?. subscribe ( projects => { this . projects = projects ; } ) ) ; } onProjectClicked ( index ) { this . navigationService . selectProject ( this . projects . get ( index ) ! . id ) ; } onNewProject ( ) { this . navigationService . newProject ( ) ; } /**
     * Clean up Rx subscription when cleaning up the component.
     */ ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } openProfileDialog ( evt ) { const target = new ElementRef ( evt . currentTarget ) ; this . dialog . open ( UserProfilePopupComponent , { data : { trigger : target } , } ) ; } }