import { Component , OnInit , OnDestroy } from '@angular/core' ; import { fadeInOut } from "../../animations" ; import { Subscription } from "rxjs" ; import { Organization } from "../../services/api-services/models/organization.class" ; import { Router , ActivatedRoute } from "@angular/router" ; import { OrganizationService } from "../../services/api-services/organization.service" ; import { WsTitleService } from "../../services/ui-services/ws-title.service" ; import { WsBreadcrumbsService } from "../../services/ui-services/ws-breadcrumbs.service" ; import { ManyApiResponse } from "../../services/api-services/models/responses/many-api-response.interface" ; import { SslSupport } from "../../services/api-services/models/ssl-support.class" ; import { QueryFilter } from "../../services/api-services/models/requests/query-filter.class" ; import { DetailItem } from "../../components/ws-widgets/models/detail-item.interface" ; import { SslSupportAnalytics } from "../../services/api-services/models/analytics/ssl-support-analytics.class" ; import { QueryOrdering } from "../../services/api-services/models/requests/query-ordering.class" ; import { SslSupportViewstate } from "../../services/ui-services/models/viewstates/ssl-support-viewstate.class" ; import { WsViewstateService } from "../../services/ui-services/ws-viewstate.service" ; import { PresentationResponse } from "../../services/api-services/models/responses/presentation-response.interface" ; import { WsSslSupportService } from "../../services/api-services/ws-ssl-support.service" ; import { WsDialogService } from "../../components/ws-dialogs/ws-dialog.service" ; @ Component ( { selector : 'ws-topography-ssl-support' , templateUrl : './topography-ssl-support-list.component.html' , styleUrls : [ './topography-ssl-support-list.component.sass' ] , host : { '[@fadeInOut]' : 'true' , 'class' : 'page-swap' , } , animations : [ fadeInOut , ] } ) export class TopographySslSupportListComponent implements OnInit , OnDestroy { private sslSupportApiResponse : ManyApiResponse < SslSupport [ ] > ; private sslSupportAnalytics : SslSupportAnalytics ; private subscriptions : Subscription [ ] = [ ] ; private _organization : Organization ; private _orgUuid : string ; private _queryFilters : QueryFilter [ ] = [ ] ; private _searchTerm : string = null ; private _queryOrdering : QueryOrdering ; private _currentPage : number = 1 ; private sslSupportPresentation : PresentationResponse ; constructor ( private route , private router , private orgService , private titleService , private breadcrumbsService , private viewstateService , private sslSupportService , private dialogService ) { } ngOnDestroy ( ) { for ( let subscription of this . subscriptions ) { subscription . unsubscribe ( ) ; } } ngOnInit ( ) { this . titleService . currentTitle = 'SSL Support' ; this . loadViewstate ( ) ; this . subscriptions . push ( this . route . params . subscribe ( params => this . orgUuid = params [ 'orgId' ] ) ) ; } private addQueryFilter ( filter ) { let currentFilters = this . queryFilters . slice ( 0 ) ; currentFilters . push ( filter ) ; this . queryFilters = currentFilters ; } private createQueryFilter ( key , value , label ) { let newFilter = new QueryFilter ( key , value , label ) ; let currentFilters = this . queryFilters . slice ( 0 ) ; currentFilters . push ( newFilter ) ; this . queryFilters = currentFilters ; } private fetchAll ( ) { this . fetchOrganization ( ) ; this . fetchSslSupportPresentation ( ) ; this . fetchAllSslSupport ( ) ; } private fetchAllSslSupport ( ) { this . fetchSslSupport ( ) ; this . fetchSslSupportAnalytics ( ) ; } private fetchOrganization ( ) { this . orgService . getOrganization ( this . orgUuid ) . subscribe ( organization => this . organization = organization , error => { if ( error . status_code == 404 ) { this . router . navigate ( [ '/organizatons/mine' ] ) ; } } ) ; } private fetchSslSupport ( ) { this . orgService . getSslSupport ( this . orgUuid , this . currentPage , this . queryFilters , this . searchTerm , this . queryOrdering ) . subscribe ( response => { console . log ( 'Got SSL support' ) ; console . log ( response ) ; this . sslSupportApiResponse = response ; } ) ; } private fetchSslSupportPresentation ( ) { this . sslSupportService . getPresentation ( this . orgUuid ) . subscribe ( presentation => this . sslSupportPresentation = presentation ) ; } private fetchSslSupportAnalytics ( ) { this . orgService . getSslSupportAnalytics ( this . orgUuid , this . queryFilters , this . searchTerm ) . subscribe ( analytics => { console . log ( 'Got analytics' ) ; console . log ( analytics ) ; this . sslSupportAnalytics = analytics ; } ) ; } private loadViewstate ( ) { let viewstate = this . viewstateService . getViewstate ( ) ; console . log ( 'Viewstate is ' ) ; console . log ( viewstate ) ; if ( viewstate ) { this . _queryOrdering = viewstate . queryOrdering ; this . _searchTerm = viewstate . searchTerm ; this . _currentPage = viewstate . page ; this . _queryFilters = viewstate . queryFilters ; } } private onExportClicked ( exportType ) { this . dialogService . showExportDataDialog ( this . orgService . getSslSupportExportUrl ( this . orgUuid ) , this . queryFilters , this . queryOrdering , this . searchTerm , this . sslSupportPresentation . fields ) ; } private onFilterCreated ( filter ) { this . addQueryFilter ( filter ) ; } private onIsExpiredClicked ( event ) { let title = '' ; if ( event ) { title = 'Certificate Is Expired' ; } else { title = 'Certificate Is Not Expired' ; } this . createQueryFilter ( 'cert_expired' , event , title ) ; } private onIssuerOrgClicked ( event ) { this . createQueryFilter ( 'cert_issuer_organization' , event , 'Issued By ' + event ) ; } private onIsValidClicked ( event ) { let title = '' ; if ( event ) { title = 'Certificate Is Valid' ; } else { title = 'Certificate Is Not Valid' ; } this . createQueryFilter ( 'cert_is_valid' , event , title ) ; } private onPageChanged ( page ) { this . currentPage = page ; this . fetchSslSupport ( ) ; } private onQueryFiltersChanged ( queryFilters ) { this . queryFilters = queryFilters ; } private onQueryOrderingChanged ( ordering ) { this . queryOrdering = ordering ; } private onSearchTermChanged ( term ) { this . searchTerm = term ; } private onVulnerableClicked ( event ) { let title = '' ; if ( event ) { title = 'Is Vulnerable' ; } else { title = 'Is Not Vulnerable' ; } this . createQueryFilter ( 'is_vulnerable' , event , title ) ; } private setViewstate ( ) { this . viewstateService . setViewstate ( this . viewstate ) ; } get currentPage ( ) : number { return this . _currentPage ; } set currentPage ( newValue ) { this . _currentPage = newValue ; this . setViewstate ( ) ; } get organization ( ) : Organization { return this . _organization ; } set organization ( newValue ) { this . _organization = newValue ; } get orgUuid ( ) : string { return this . _orgUuid ; } set orgUuid ( newValue ) { this . _orgUuid = newValue ; this . breadcrumbsService . setBreadcrumbsForSslSupportList ( newValue ) ; this . fetchAll ( ) ; } get queryFilters ( ) : QueryFilter [ ] { return this . _queryFilters ; } set queryFilters ( newValue ) { this . _queryFilters = newValue ; this . currentPage = 1 ; this . fetchAllSslSupport ( ) ; } get queryOrdering ( ) : QueryOrdering { return this . _queryOrdering ; } set queryOrdering ( newValue ) { this . _queryOrdering = newValue ; this . setViewstate ( ) ; this . fetchSslSupport ( ) ; } get searchTerm ( ) : string { return this . _searchTerm ; } set searchTerm ( newValue ) { if ( newValue == '' ) { this . _searchTerm = null ; } else { this . _searchTerm = newValue ; } this . setViewstate ( ) ; this . fetchAllSslSupport ( ) ; } get viewstate ( ) : SslSupportViewstate { return new SslSupportViewstate ( this . currentPage , this . queryFilters , this . queryOrdering , this . searchTerm ) ; } }