import { Component , Input , OnDestroy , OnInit } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { take } from 'rxjs/operators' ; import { Breakpoints , BreakpointObserver , BreakpointState } from '@angular/cdk/layout' ; import { RepositoryService , SortingService } from '@core/services/index.service' ; import { ContributorModel , IRepository , MilestoneModel , PullRequestModel , ReleaseModel , RepositoryModel } from '@shared/models/index.model' ; /**
 * Repository component
 */ @ Component ( { selector : 'dashboard-repository' , templateUrl : './repository.component.html' , styleUrls : [ './repository.component.scss' ] , } ) export class RepositoryComponent implements OnInit , OnDestroy { private repositorySubscription : Subscription ; public headerHeight : number ; public isLargeScreen : boolean ; public isAlertEnabled : boolean = false ; @ Input ( ) public isAdmin : boolean = false ; @ Input ( ) public uid : string ; public repository : IRepository ; public numberOfDisplayedUsers : number ; param breakpointObserver param repositoryService param sortingService constructor ( private breakpointObserver , private repositoryService , private sortingService ) { if ( breakpointObserver . isMatched ( Breakpoints . Large || Breakpoints . XLarge ) ) { this . isLargeScreen = true ; this . headerHeight = 200 ; } else { this . isLargeScreen = false ; this . headerHeight = 100 ; } } /**
     * Life cycle init method
     */ ngOnInit ( ) { this . showWebHookAlert ( ) ; this . repositorySubscription = this . repositoryService . findOneById ( this . uid ) . subscribe ( ( repository ) => { this . repository = repository ; if ( this . repository && this . repository . milestones && this . repository . milestones . length > 0 ) { this . sortingService . sortListByDate < MilestoneModel > ( this . repository . milestones , 'updatedAt' ) ; } if ( this . repository && this . repository . releases && this . repository . releases . length > 0 ) { this . sortingService . sortListByDate < ReleaseModel > ( this . repository . releases , 'createdAt' ) ; } if ( this . repository && this . repository . contributors && this . repository . contributors . length > 0 ) { this . sortingService . sortListByNumber < ContributorModel > ( this . repository . contributors , 'total' ) ; } if ( this . repository && this . repository . pullRequests . length > 0 ) { this . sortingService . sortListByDate < PullRequestModel > ( this . repository . pullRequests , 'createdOn' ) ; } if ( this . isLargeScreen ) { this . headerHeight = 200 ; } else { this . headerHeight = 100 ; } } ) ; this . breakpointObserver . observe ( [ Breakpoints . Large ] ) . subscribe ( ( state ) => { if ( state . matches ) { this . numberOfDisplayedUsers = 8 ; this . headerHeight = 200 ; this . isLargeScreen = true ; } } ) ; this . breakpointObserver . observe ( [ Breakpoints . XLarge ] ) . subscribe ( ( state ) => { if ( state . matches ) { this . numberOfDisplayedUsers = 8 ; this . headerHeight = 200 ; this . isLargeScreen = true ; } } ) ; this . breakpointObserver . observe ( [ Breakpoints . Medium ] ) . subscribe ( ( state ) => { if ( state . matches ) { this . headerHeight = 100 ; this . numberOfDisplayedUsers = 8 ; this . isLargeScreen = false ; } } ) ; this . breakpointObserver . observe ( [ Breakpoints . Small ] ) . subscribe ( ( state ) => { if ( state . matches ) { this . numberOfDisplayedUsers = 3 ; this . headerHeight = 100 ; } } ) ; this . breakpointObserver . observe ( [ Breakpoints . XSmall ] ) . subscribe ( ( state ) => { if ( state . matches ) { this . headerHeight = 100 ; this . numberOfDisplayedUsers = 2 ; } } ) ; } param contributor getMoreInformation ( contributor ) { return `${ contributor . owner . username }` + ' \n ' + ` Total commits : ${ contributor . total }` ; } /**
     * Life cycle destroy method
     */ ngOnDestroy ( ) { this . repositorySubscription . unsubscribe ( ) ; } /**
     * Create webhook
     */ public createWebhook ( ) { this . repositoryService . createGitWebhook ( this . repository ) . pipe ( take ( 1 ) ) . subscribe ( ) ; } private showWebHookAlert ( ) { setTimeout ( ( ) => this . isAlertEnabled = true , 10000 ) ; } }