1- import { Component , inject , signal } from '@angular/core' ;
1+ import { Component , effect , inject , signal , viewChild } from '@angular/core' ;
22import { HotspotService } from './hotspot.service' ;
33import {
44 AggregatedHotspot ,
@@ -18,11 +18,12 @@ import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
1818import { combineLatest , debounceTime , startWith } from 'rxjs' ;
1919import { EventService } from '../event.service' ;
2020import { takeUntilDestroyed , toObservable } from '@angular/core/rxjs-interop' ;
21- import { LimitsComponent } from " ../ui/limits/limits.component" ;
21+ import { LimitsComponent } from ' ../ui/limits/limits.component' ;
2222import { initLimits } from '../model/limits' ;
2323import { MatSelectModule } from '@angular/material/select' ;
24- import { MatCheckboxModule } from '@angular/material/checkbox' ;
2524import { StatusStore } from '../data/status.store' ;
25+ import { MatProgressBarModule } from '@angular/material/progress-bar' ;
26+ import { MatPaginator , MatPaginatorModule } from '@angular/material/paginator' ;
2627
2728type Option = {
2829 id : ComplexityMetric ;
@@ -38,10 +39,12 @@ type Option = {
3839 MatFormFieldModule ,
3940 MatInputModule ,
4041 MatSelectModule ,
42+ MatProgressBarModule ,
43+ MatPaginatorModule ,
4144 ReactiveFormsModule ,
4245 LimitsComponent ,
4346 FormsModule ,
44- ] ,
47+ ] ,
4548 templateUrl : './hotspot.component.html' ,
4649 styleUrl : './hotspot.component.css' ,
4750} )
@@ -69,24 +72,36 @@ export class HotspotComponent {
6972 metric = signal < ComplexityMetric > ( 'Length' ) ;
7073
7174 metricOptions : Option [ ] = [
72- { id : 'Length' , label : 'File Length' } ,
73- { id : 'McCabe' , label : 'Cyclomatic Complexity' } ,
75+ { id : 'Length' , label : 'File Length' } ,
76+ { id : 'McCabe' , label : 'Cyclomatic Complexity' } ,
7477 ] ;
7578
79+ loadingAggregated = signal ( false ) ;
80+ loadingHotspots = signal ( false ) ;
81+
82+ paginator = viewChild ( MatPaginator ) ;
83+
7684 constructor ( ) {
85+ effect ( ( ) => {
86+ this . detailDataSource . paginator = this . paginator ( ) ;
87+ } ) ;
88+
7789 combineLatest ( [
7890 this . eventService . filterChanged . pipe ( startWith ( null ) ) ,
79- this . minScoreControl . valueChanges . pipe ( startWith ( this . minScoreControl . value ) , debounceTime ( 300 ) ) ,
91+ this . minScoreControl . valueChanges . pipe (
92+ startWith ( this . minScoreControl . value ) ,
93+ debounceTime ( 300 )
94+ ) ,
8095 toObservable ( this . limits ) ,
8196 toObservable ( this . metric ) ,
8297 ] )
83- . pipe ( takeUntilDestroyed ( ) )
84- . subscribe ( ( ) => {
85- this . loadAggregated ( ) ;
86- if ( this . selectedModule ) {
87- this . loadHotspots ( ) ;
88- }
89- } ) ;
98+ . pipe ( takeUntilDestroyed ( ) )
99+ . subscribe ( ( ) => {
100+ this . loadAggregated ( ) ;
101+ if ( this . selectedModule ) {
102+ this . loadHotspots ( ) ;
103+ }
104+ } ) ;
90105 }
91106
92107 selectRow ( row : AggregatedHotspot , index : number ) {
@@ -114,34 +129,44 @@ export class HotspotComponent {
114129 const criteria : HotspotCriteria = {
115130 metric : this . metric ( ) ,
116131 minScore : this . minScoreControl . value ,
117- module : ''
132+ module : '' ,
118133 } ;
119134
120- this . hotspotService
121- . loadAggregated ( criteria , this . limits ( ) )
122- . subscribe ( ( aggregatedResult ) => {
135+ this . loadingAggregated . set ( true ) ;
136+
137+ this . hotspotService . loadAggregated ( criteria , this . limits ( ) ) . subscribe ( {
138+ next : ( aggregatedResult ) => {
123139 this . aggregatedResult = aggregatedResult ;
124140 this . dataSource . data = this . formatAggregated (
125141 aggregatedResult . aggregated
126142 ) ;
127- } ) ;
143+ } ,
144+ complete : ( ) => {
145+ this . loadingAggregated . set ( false ) ;
146+ } ,
147+ } ) ;
128148 }
129149
130150 private loadHotspots ( ) {
131151 const criteria : HotspotCriteria = {
132152 metric : this . metric ( ) ,
133153 minScore : this . minScoreControl . value ,
134- module : this . selectedModule
154+ module : this . selectedModule ,
135155 } ;
136156
137- this . hotspotService
138- . load ( criteria , this . limits ( ) )
139- . subscribe ( ( hotspotResult ) => {
157+ this . loadingHotspots . set ( true ) ;
158+
159+ this . hotspotService . load ( criteria , this . limits ( ) ) . subscribe ( {
160+ next : ( hotspotResult ) => {
140161 this . hotspotResult = hotspotResult ;
141162 this . detailDataSource . data = this . formatHotspots (
142163 hotspotResult . hotspots
143164 ) ;
144- } ) ;
165+ } ,
166+ complete : ( ) => {
167+ this . loadingHotspots . set ( false ) ;
168+ } ,
169+ } ) ;
145170 }
146171}
147172
0 commit comments