import { Component , OnDestroy , OnInit } from '@angular/core' ; import { MatDialog } from '@angular/material' ; import { Meta } from '@angular/platform-browser' ; import { ActivatedRoute , Router } from '@angular/router' ; import { Subscription } from 'rxjs' ; import { filter , map , switchMap , take } from 'rxjs/operators' ; import { AuthenticationService , ProjectService , UserService } from '@core/services/index.service' ; import { DialogListComponent } from '@shared/dialog/list/dialog-list.component' ; import { BreadCrumbModel , ProjectModel , RepositoryModel } from '@shared/models/index.model' ; /**
 * Project View component
 */ @ Component ( { selector : 'dashboard-projects-view' , templateUrl : './view.component.html' , styleUrls : [ './view.component.scss' ] , } ) export class ViewProjectComponent implements OnInit , OnDestroy { private deleteSubscription : Subscription ; private projectSubscription : Subscription ; public typeIcon : string ; public project : ProjectModel ; public isMenuOpen : boolean ; public breadCrumb : BreadCrumbModel [ ] = [ ] ; param route param router param dialog param projectService param authService constructor ( private route , private router , private dialog , private projectService , private authService , private userService , private meta ) { this . route . data . subscribe ( ( data ) => this . project = data . project ) ; } /**
     * Life cycle init method
     */ ngOnInit ( ) { this . projectSubscription = this . projectService . findOneById ( this . route . snapshot . params . projectUid ) . pipe ( map ( ( project ) => this . project = project ) ) . subscribe ( ( project ) => this . typeIcon = project . isPrivate ( ) ? 'lock' : 'lock_open' ) ; this . updateMetaTags ( ) ; } /**
     * Update meta tags for title and image for SEO
     */ public updateMetaTags ( ) { this . meta . updateTag ( { property : 'og:title' , content : this . project . title } ) ; this . meta . updateTag ( { property : 'og:image' , content : this . project . logoUrl ? this . project . logoUrl : 'https://cdn.dashboardhub.io/logo/icon-only-orange-1216x1160.png' , } ) ; } /**
     * Add the repository when click on add from repository dialog
     */ public addRepository ( ) { this . dialog . open ( DialogListComponent , { data : { project : this . project , repositories : this . authService . profile . repositories , } , } ) . afterClosed ( ) . pipe ( take ( 1 ) , filter ( ( selectedRepositories ) => ! ! selectedRepositories ) , switchMap ( ( selectedRepositories ) => this . projectService . saveRepositories ( this . project , selectedRepositories . map ( ( item ) => item . value ) . filter ( ( value ) => value . uid ) ) ) ) . subscribe ( ) ; } /**
     * Increase the followers count by 1 and update the followings in the users collection
     */ public follow ( ) { this . userService . updateFollowing ( this . project . uid , true ) . subscribe ( ( ) => this . projectService . updateFollowers ( this . project . uid , true ) ) ; } /**
     * Decrease the followers count by 1 and update the followings in the users collection
     */ public unfollow ( ) { this . userService . updateFollowing ( this . project . uid , false ) . subscribe ( ( ) => this . projectService . updateFollowers ( this . project . uid , false ) ) ; } /**
     * Show the delete confirmation dialog and delete the project
     */ delete ( ) { this . projectSubscription . unsubscribe ( ) ; this . deleteSubscription = this . projectService . showDeleteDialog ( this . project . uid ) . subscribe ( ( ) => this . router . navigate ( [ '/projects' ] ) ) ; } /**
     * Check if logged in user is also owner of the project
     */ public isAdmin ( ) { return this . project . isAdmin ( this . authService . profile . uid ) ; } /**
     * Check if user is logged in
     */ public isLoggedIn ( ) { return this . authService . isAuthenticated ; } /**
     * Set the followers flag true if user uid is present in the database else set false
     */ public isFollowing ( ) { return Array . isArray ( this . authService . profile . following ) ? this . authService . profile . following . includes ( this . project . uid ) : false ; } /**
     * Life cycle destroy method
     */ public ngOnDestroy ( ) { this . projectSubscription . unsubscribe ( ) ; if ( this . deleteSubscription ) { this . deleteSubscription . unsubscribe ( ) ; } } }