|
1 | | -import { OnInit, ChangeDetectorRef, Component, OnDestroy } from '@angular/core'; |
| 1 | +import { OnInit, ChangeDetectorRef, Component, OnDestroy, isDevMode } from '@angular/core'; |
2 | 2 | import { FormControl, FormGroup } from '@angular/forms'; |
3 | 3 | import { UsageReport } from 'github-usage-report/src/types'; |
4 | 4 | import { Observable, Subscription, debounceTime, map, startWith } from 'rxjs'; |
5 | 5 | import { CustomUsageReportLine, UsageReportService } from 'src/app/usage-report.service'; |
6 | 6 | import { DialogBillingNavigateComponent } from './dialog-billing-navigate'; |
7 | 7 | import { MatDialog } from '@angular/material/dialog'; |
8 | 8 | import { ModelUsageReport } from 'github-usage-report'; |
| 9 | +import { HttpClient } from '@angular/common/http'; |
9 | 10 |
|
10 | 11 | @Component({ |
11 | 12 | selector: 'app-usage', |
@@ -42,10 +43,16 @@ export class UsageComponent implements OnInit, OnDestroy { |
42 | 43 | private usageReportService: UsageReportService, |
43 | 44 | public dialog: MatDialog, |
44 | 45 | private cdr: ChangeDetectorRef, |
| 46 | + private http: HttpClient, |
45 | 47 | ) { |
46 | 48 | } |
47 | 49 |
|
48 | 50 | ngOnInit() { |
| 51 | + // Auto-load test data in development mode |
| 52 | + if (isDevMode()) { |
| 53 | + this.loadTestData(); |
| 54 | + } |
| 55 | + |
49 | 56 | this.subscriptions.push( |
50 | 57 | this.range.valueChanges.pipe(debounceTime(500)).subscribe(value => { |
51 | 58 | if (value.start && value.start instanceof Date && !isNaN(value.start.getTime()) && |
@@ -193,4 +200,16 @@ export class UsageComponent implements OnInit, OnDestroy { |
193 | 200 | a.click(); |
194 | 201 | (a as any).parentNode.removeChild(a); |
195 | 202 | } |
| 203 | + |
| 204 | + private async loadTestData() { |
| 205 | + try { |
| 206 | + const response = await this.http.get('assets/github-usage-report.csv', { responseType: 'text' }).toPromise(); |
| 207 | + if (response) { |
| 208 | + console.log('Auto-loading test data in development mode...'); |
| 209 | + await this.onFileText(response, 'metered'); |
| 210 | + } |
| 211 | + } catch (error) { |
| 212 | + console.warn('Could not auto-load test data:', error); |
| 213 | + } |
| 214 | + } |
196 | 215 | } |
0 commit comments