import { Injectable } from '@angular/core' ; import { ListColumnSetting , ListSettings , ListColumnSettingForBadge , ListColumnSettingForLink , ListColumnSettingWithCopyText , ListColumnSettingWithUtcTime , ListColumnSettingWithCustomComponent , ListColumnSettingWithShorten } from '../Models/ListSettings' ; import { NodeStatusConstants , Constants } from '../Common/Constants' ; import { ClusterLoadInformation } from '../Models/DataModels/Cluster' ; import { NodeLoadInformation } from '../Models/DataModels/Node' ; import { MetricsViewModel } from '../ViewModels/MetricsViewModel' ; import { StorageService } from './storage.service' ; import { RepairTaskViewComponent } from '../views/cluster/repair-task-view/repair-task-view.component' ; import { QuestionToolTipComponent } from '../modules/detail-list-templates/question-tool-tip/question-tool-tip.component' ; @ Injectable ( { providedIn : 'root' } ) export class SettingsService { private listSettings : Record < string , ListSettings > ; private iPaginationLimit : number ; private iMetricsViewModel : MetricsViewModel ; public get paginationLimit ( ) : number { return this . iPaginationLimit ; } public set paginationLimit ( limit ) { if ( ! limit ) { return ; } if ( limit < Constants . PaginationLimitMin ) { limit = Constants . PaginationLimitMin ; } else if ( limit > Constants . PaginationLimitMax ) { limit = Constants . PaginationLimitMax ; } this . iPaginationLimit = limit ; this . storage . setValue ( Constants . PaginationLimitStorageKey , limit ) ; this . updatePaginationLimit ( limit ) ; } public constructor ( private storage ) { this . listSettings = { } ; this . iPaginationLimit = storage . getValueNumber ( Constants . PaginationLimitStorageKey , Constants . DefaultPaginationLimit ) ; } public getNewOrExistingMetricsViewModel ( clusterLoadInformation , nodesLoadInformation ) { if ( ! this . iMetricsViewModel ) { this . iMetricsViewModel = new MetricsViewModel ( clusterLoadInformation , nodesLoadInformation ) ; } return this . iMetricsViewModel ; } public getNewOrExistingListSettings ( listName , defaultSortProperties = [ ] , columnSettings = [ ] , secondRowColumnSettings = [ ] , secondRowCollapsible = false , showSecondRow = ( item ) => true , searchable = true ) { const key = listName ; if ( ! this . listSettings [ key ] ) { this . listSettings [ key ] = new ListSettings ( this . paginationLimit , defaultSortProperties , listName , columnSettings , secondRowColumnSettings , secondRowCollapsible , showSecondRow , searchable ) ; } return this . listSettings [ key ] ; } public getNewOrExistingTreeNodeListSettings ( listKey , defaultSortProperties = [ ] , columnSettings = [ ] ) { if ( ! this . listSettings [ listKey ] ) { this . listSettings [ listKey ] = new ListSettings ( this . paginationLimit , defaultSortProperties , 'Tree Node' , columnSettings ) ; } return this . listSettings [ listKey ] ; } public getNewOrExistingUnhealthyEvaluationsListSettings ( listKey = 'unhealthy Evaluations' ) { return this . getNewOrExistingListSettings ( listKey , null , [ new ListColumnSettingForLink ( 'kind' , 'Kind' , ( item ) => item . viewPath ) , new ListColumnSettingForBadge ( 'healthState' , 'Health State' ) , new ListColumnSettingWithCopyText ( 'description' , 'Description' ) , new ListColumnSettingWithUtcTime ( 'sourceTimeStamp' , 'Source UTC' ) , ] ) ; } public getNewOrExistingHealthEventsListSettings ( listKey = 'health Events' ) { return this . getNewOrExistingListSettings ( listKey , [ 'raw.SequenceNumber' ] , [ new ListColumnSettingForBadge ( 'healthState' , 'Health State' ) , new ListColumnSetting ( 'raw.SourceId' , 'Source' ) , new ListColumnSetting ( 'raw.Property' , 'Property' ) , new ListColumnSettingWithUtcTime ( 'sourceUtcTimestamp' , 'Source UTC' ) , new ListColumnSetting ( 'TTL' , 'TTL' ) , new ListColumnSetting ( 'raw.SequenceNumber' , 'Sequence Number' ) , new ListColumnSetting ( 'raw.RemoveWhenExpired' , 'Remove When Expired' ) , new ListColumnSetting ( 'raw.IsExpired' , 'Is Expired' ) ] , [ new ListColumnSetting ( 'placeholder' , 'placeholder' , { enableFilter : false } ) , new ListColumnSettingWithCopyText ( 'description' , 'Description' , { enableFilter : false , colspan : 7 } ) ] , false , ( item ) => item . description . length > 0 ) ; } public getNewOrExistingNodeStatusListSetting ( listKey = 'node Status' ) { return this . getNewOrExistingListSettings ( listKey , null , [ new ListColumnSetting ( 'nodeType' , 'Node Type' ) , new ListColumnSetting ( 'totalCount' , 'Total Node Count' ) , new ListColumnSetting ( `statusTypeCounts.${ NodeStatusConstants . Up }` , NodeStatusConstants . Up ) , new ListColumnSetting ( `statusTypeCounts.${ NodeStatusConstants . Down }` , NodeStatusConstants . Down ) , new ListColumnSetting ( `statusTypeCounts.${ NodeStatusConstants . Disabled }` , NodeStatusConstants . Disabled ) , new ListColumnSetting ( `statusTypeCounts.${ NodeStatusConstants . Disabling }` , NodeStatusConstants . Disabling ) , new ListColumnSetting ( 'errorCount' , 'Error' ) , new ListColumnSetting ( 'warningCount' , 'Warning' ) , ] ) ; } public getNewOrExistingBackupPolicyListSettings ( listKey = 'backup Policies' ) { return this . getNewOrExistingListSettings ( listKey , null , [ new ListColumnSetting ( 'raw.Name' , 'Name' , { enableFilter : false , getDisplayHtml : ( item , property ) => `<span class="link">${ property }</span>` , colspan : 1 , clickEvent : item => item . action . run ( ) } ) , new ListColumnSetting ( 'raw.Schedule.ScheduleKind' , 'ScheduleKind' ) , new ListColumnSetting ( 'raw.Storage.StorageKind' , 'StorageKind' ) , new ListColumnSetting ( 'raw.AutoRestoreOnDataLoss' , 'AutoRestoreOnDataLoss' ) , new ListColumnSetting ( 'raw.MaxIncrementalBackups' , 'MaxIncrementalBackups' ) , ] ) ; } public getNewOrExistingNetworkRequestListSettings ( includeApiDesc = false ) { const listKey = 'requests Data' ; const settings = [ new ListColumnSetting ( 'statusCode' , 'Status Code' ) , new ListColumnSetting ( 'errorMessage' , 'Error Message' ) , new ListColumnSetting ( 'duration' , 'Duration(MS)' ) , new ListColumnSettingWithUtcTime ( 'startTime' , 'Start Time' ) , ] ; if ( includeApiDesc ) { return this . getNewOrExistingListSettings ( listKey + 'andApiDesc' , [ ] , [ new ListColumnSetting ( 'apiDesc' , 'API Description' ) ] . concat ( settings ) ) ; } return this . getNewOrExistingListSettings ( listKey , [ ] , settings ) ; } public getNewOrExistingPendingRepairTaskListSettings ( listKey = 'pendingRepair' ) { return this . getNewOrExistingListSettings ( listKey , [ 'raw.History.CreatedUtcTimestamp' ] , [ new ListColumnSettingWithCustomComponent ( QuestionToolTipComponent , 'raw.TaskId' , 'Task Id' ) , new ListColumnSetting ( 'raw.Action' , 'Action' , { enableFilter : true } ) , new ListColumnSettingWithShorten ( 'raw.Target.NodeNames' , 'Target' , 2 ) , new ListColumnSetting ( 'impactedNodes' , 'Impact' ) , new ListColumnSetting ( 'raw.State' , 'State' , { enableFilter : true } ) , new ListColumnSettingWithUtcTime ( 'raw.History.CreatedUtcTimestamp' , 'Created At' ) , new ListColumnSetting ( 'displayDuration' , 'Duration' , { sortPropertyPaths : [ 'duration' ] } ) , ] , [ new ListColumnSettingWithCustomComponent ( RepairTaskViewComponent , '' , '' , { enableFilter : false , colspan : - 1 } ) ] , true , ( item ) => ( Object . keys ( item ) . length > 0 ) , true ) ; } public getNewOrExistingCompletedRepairTaskListSettings ( listKey = 'completedRepair' ) { return this . getNewOrExistingListSettings ( listKey , [ 'raw.History.CreatedUtcTimestamp' ] , [ new ListColumnSettingWithCustomComponent ( QuestionToolTipComponent , 'raw.TaskId' , 'Task Id' ) , new ListColumnSetting ( 'raw.Action' , 'Action' , { enableFilter : true } ) , new ListColumnSettingWithShorten ( 'raw.Target.NodeNames' , 'Target' , 2 ) , new ListColumnSetting ( 'impactedNodes' , 'Impact' ) , new ListColumnSetting ( 'raw.ResultStatus' , 'Result Status' , { enableFilter : true } ) , new ListColumnSettingWithUtcTime ( 'raw.History.CreatedUtcTimestamp' , 'Created At' ) , new ListColumnSetting ( 'displayDuration' , 'Duration' , { sortPropertyPaths : [ 'duration' ] } ) , ] , [ new ListColumnSettingWithCustomComponent ( RepairTaskViewComponent , '' , '' , { enableFilter : false , colspan : - 1 } ) ] , true , ( item ) => true , true ) ; } private updatePaginationLimit ( limit ) { Object . keys ( this . listSettings ) . forEach ( key => { const item = this . listSettings [ key ] ; item . currentPage = 1 ; item . limit = limit ; } ) ; } }