diff --git a/src/app/components/dashboard/dashboard.component.css b/src/app/components/dashboard/dashboard.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html new file mode 100644 index 0000000..bc9da8d --- /dev/null +++ b/src/app/components/dashboard/dashboard.component.html @@ -0,0 +1,76 @@ +
+

Tableau de bord

+ + +
+
+

Utilisateurs

+

{{ stats.general.total_users }}

+

+{{ stats.last_30_days.new_users }} ce mois

+
+ +
+

Pins

+

{{ stats.general.total_pins }}

+

+{{ stats.last_30_days.new_pins }} ce mois

+
+ +
+

Images

+

{{ stats.general.total_images }}

+

+{{ stats.last_30_days.new_images }} ce mois

+
+ +
+

Amis

+

{{ stats.general.total_friends }}

+
+ +
+

Stockage

+

{{ formatBytes(stats.general.total_storage_bytes) }}

+
+
+ + +
+

Top utilisateurs

+
+ + + + + + + + + + + + + +
UtilisateurNombre de pins
{{ user.username }}{{ user.pin_count }}
+
+
+ + +
+

Top pins partagés

+
+ + + + + + + + + + + + + +
TitreNombre de partages
{{ pin.title }}{{ pin.share_count }}
+
+
+
\ No newline at end of file diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts new file mode 100644 index 0000000..17ec797 --- /dev/null +++ b/src/app/components/dashboard/dashboard.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpClient } from '@angular/common/http'; +import { StatisticsService } from '../../services/statistics.service'; +import { Stats } from '../../model/Stats'; + +@Component({ + selector: 'app-dashboard', + templateUrl: './dashboard.component.html', + styleUrls: ['./dashboard.component.css'], + imports: [CommonModule] +}) +export class DashboardComponent implements OnInit { + stats: Stats = { + general: { + total_users: 0, + total_pins: 0, + total_images: 0, + total_friends: 0, + total_storage_bytes: 0 + }, + last_30_days: { + new_users: 0, + new_pins: 0, + new_images: 0 + }, + top_users: [], + top_shared_pins: [] + }; + + constructor(private http: HttpClient, private statisticsService: StatisticsService) {} + + ngOnInit(): void { + this.statisticsService.loadStats().subscribe(stats => { + this.stats = stats; + }); + } + + formatBytes(bytes: number | undefined): string { + if (!bytes) return '0 B'; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; + } +} \ No newline at end of file