From b54024889b4bdf6d78a6b51ea9b667263fd877dc Mon Sep 17 00:00:00 2001 From: christophenne Date: Tue, 7 Jan 2025 15:40:35 +0100 Subject: [PATCH 1/8] WIP: charts Signed-off-by: christophenne --- .../charts/type/chart-type.component.html | 10 +- .../charts/type/chart-type.component.ts | 93 +++++++++---------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html index b399093d..ef1ebbc9 100644 --- a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html +++ b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html @@ -1,6 +1,7 @@ +

Deployments per Manager

@if (chartOptions) { + [legend]="chartOptions.legend!"> +} @else if (loading) { +

Loading...

+} @else { +

Nothing to display right now.

} diff --git a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.ts b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.ts index e002f008..9267f369 100644 --- a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.ts +++ b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.ts @@ -17,62 +17,59 @@ export class ChartTypeComponent implements OnDestroy { private readonly destroyed$ = new Subject(); + loading: boolean = true; + constructor() { this.deploymentTargets$.pipe(takeUntil(this.destroyed$)).subscribe((dts) => { - this.chartOptions = { - series: [], - labels: [], - colors: ['#0db7ed', '#326CE5', '#174c76'], - chart: { - height: 192, - type: 'donut', - sparkline: { - enabled: true, + this.loading = false; + + if (dts.length > 0) { + this.chartOptions = { + series: [], + labels: [], + colors: ['#0db7ed', '#326CE5', '#174c76'], + chart: { + height: 192, + type: 'donut', + sparkline: { + enabled: true, + }, + }, + stroke: { + curve: 'smooth', }, - }, - stroke: { - curve: 'smooth', - }, - tooltip: { - enabled: false, - }, - legend: { - show: true, - position: 'top', - fontFamily: 'Inter', - labels: { - colors: 'rgb(156, 163, 175)', - useSeriesColors: false, + tooltip: { + enabled: false, }, - }, - title: { - text: 'Deployment Managers', - align: 'center', - offsetY: 10, - style: { - color: 'rgb(156, 163, 175)', - fontFamily: 'Poppins', + legend: { + show: true, + position: 'top', + fontFamily: 'Inter', + labels: { + colors: 'rgb(156, 163, 175)', + useSeriesColors: false, + }, }, - }, - plotOptions: { - pie: { - customScale: 0.8, + plotOptions: { + pie: { + customScale: 0.8, + }, }, - }, - }; - const managers: {[key: string]: UserAccountWithRole} = {}; - const counts: {[key: string]: number} = {}; - for (const dt of dts) { - if (dt.createdBy?.id && !managers[dt.createdBy.id]) { - managers[dt.createdBy.id] = dt.createdBy; - counts[dt.createdBy.id] = 1; - } else if (dt.createdBy?.id && managers[dt.createdBy.id]) { - counts[dt.createdBy.id] = counts[dt.createdBy.id] + 1; + }; + const managers: {[key: string]: UserAccountWithRole} = {}; + const counts: {[key: string]: number} = {}; + for (const dt of dts) { + if (dt.createdBy?.id && !managers[dt.createdBy.id]) { + managers[dt.createdBy.id] = dt.createdBy; + counts[dt.createdBy.id] = 1; + } else if (dt.createdBy?.id && managers[dt.createdBy.id]) { + counts[dt.createdBy.id] = counts[dt.createdBy.id] + 1; + } } - } - this.chartOptions.labels = Object.values(managers).map((v) => v.name ?? v.email); - this.chartOptions.series = Object.values(counts); + this.chartOptions.labels = Object.values(managers).map((v) => v.name ?? v.email); + this.chartOptions.series = Object.values(counts); + } }); } From c8883a6e7299514b5b42ab86cad6b881ad3883ec Mon Sep 17 00:00:00 2001 From: christophenne Date: Tue, 7 Jan 2025 16:20:25 +0100 Subject: [PATCH 2/8] WIP: charts Signed-off-by: christophenne --- .../charts/uptime/chart-uptime.component.html | 11 ++++++++--- .../charts/uptime/chart-uptime.component.ts | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html index f3e4f792..21d868c1 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html @@ -1,12 +1,17 @@ +

Deployment Uptime

@if (chartOptions) { + [legend]="chartOptions.legend!"> +} @else if (loading) { +

Loading...

+} @else { +

Nothing to display right now.

} + diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts index 7ad0a7c7..08f8c567 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts @@ -17,6 +17,8 @@ export class ChartUptimeComponent implements OnInit { private readonly metrics = inject(MetricsService); + loading = true; + async ngOnInit() { const dts = await firstValueFrom(this.deploymentTargets$); for (const dt of dts) { @@ -29,6 +31,7 @@ export class ChartUptimeComponent implements OnInit { continue; } this.metrics.getUptimeForDeployment(deployment.id!).subscribe((uptimes) => { + this.loading = false; this.chartOptions = { series: [ { From 32e05123c62a04dc0e4dab2b04e774080e8b25af Mon Sep 17 00:00:00 2001 From: christophenne Date: Wed, 8 Jan 2025 09:06:55 +0100 Subject: [PATCH 3/8] fix: uptime chart positioning Signed-off-by: christophenne --- .../charts/uptime/chart-uptime.component.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts index 08f8c567..e7c47d85 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts @@ -46,7 +46,9 @@ export class ChartUptimeComponent implements OnInit { }, ], chart: { - height: 220, + offsetY: 20, + //width: '100%', + //height: '80%', type: 'bar', stacked: true, sparkline: { @@ -67,20 +69,13 @@ export class ChartUptimeComponent implements OnInit { show: true, position: 'top', fontFamily: 'Inter', - offsetY: -18, + offsetY: -5, + floating: true, labels: { colors: 'rgb(156, 163, 175)', useSeriesColors: false, }, }, - title: { - text: `${dt.name}`, - align: 'center', - style: { - color: 'rgb(156, 163, 175)', - fontFamily: 'Poppins', - }, - }, }; }); return; From fb693b70f57d3f4953b417c0a096e4f6b6c7e487 Mon Sep 17 00:00:00 2001 From: christophenne Date: Wed, 8 Jan 2025 09:35:22 +0100 Subject: [PATCH 4/8] WIP select Signed-off-by: christophenne --- .../charts/uptime/chart-uptime.component.html | 39 ++++++++++++++++++- .../charts/uptime/chart-uptime.component.ts | 18 ++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html index 21d868c1..ffc565fa 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html @@ -1,4 +1,41 @@ -

Deployment Uptime

+
+

Deployment Uptime

+ + + +
+ + +
+
    +
  • + +
  • +
+
+
+ @if (chartOptions) { Date: Wed, 8 Jan 2025 09:47:31 +0100 Subject: [PATCH 5/8] WIP select Signed-off-by: christophenne --- .../charts/uptime/chart-uptime.component.html | 20 +++--- .../charts/uptime/chart-uptime.component.ts | 62 +++++++++++++++++-- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html index ffc565fa..571615e7 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html @@ -23,15 +23,17 @@

    -
  • - -
  • + @for (dt of deploymentTargets$ | async; track dt.id ) { +
  • + +
  • + }
diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts index 64b3b579..5de565eb 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.ts @@ -7,18 +7,20 @@ import {FaIconComponent} from '@fortawesome/angular-fontawesome'; import {faEllipsis, faEllipsisVertical} from '@fortawesome/free-solid-svg-icons'; import {CdkConnectedOverlay, CdkOverlayOrigin} from '@angular/cdk/overlay'; import {dropdownAnimation} from '../../../animations/dropdown'; +import {AsyncPipe} from '@angular/common'; +import {DeploymentTarget} from '../../../types/deployment-target'; @Component({ selector: 'app-chart-uptime', templateUrl: './chart-uptime.component.html', - imports: [NgApexchartsModule, FaIconComponent, CdkOverlayOrigin, CdkConnectedOverlay], + imports: [NgApexchartsModule, FaIconComponent, CdkOverlayOrigin, CdkConnectedOverlay, AsyncPipe], animations: [dropdownAnimation], }) export class ChartUptimeComponent implements OnInit { public chartOptions?: ApexOptions; private readonly deploymentTargets = inject(DeploymentTargetsService); - private readonly deploymentTargets$ = this.deploymentTargets.list(); + readonly deploymentTargets$ = this.deploymentTargets.list(); private readonly metrics = inject(MetricsService); @@ -30,7 +32,7 @@ export class ChartUptimeComponent implements OnInit { async ngOnInit() { const dts = await firstValueFrom(this.deploymentTargets$); - for (const dt of dts) { + /*for (const dt of dts) { if (dt.currentStatus) { let deployment; try { @@ -89,11 +91,59 @@ export class ChartUptimeComponent implements OnInit { }); return; } - } + }*/ } - selectDeploymentTarget() { - // TODO + async selectDeploymentTarget(dt: DeploymentTarget) { this.showDropdown = false; + const deployment = await lastValueFrom(this.deploymentTargets.latestDeploymentFor(dt.id!)); + this.metrics.getUptimeForDeployment(deployment.id!).subscribe((uptimes) => { + this.loading = false; + this.chartOptions = { + series: [ + { + name: 'available', + data: uptimes.map((ut) => ut.total - ut.unknown), + color: '#00bfa5', + }, + { + name: 'unknown', + data: uptimes.map((ut) => ut.unknown), + color: '#feb019', + }, + ], + chart: { + offsetY: 10, + //width: '100%', + //height: '80%', + type: 'bar', + stacked: true, + sparkline: { + enabled: true, + }, + }, + stroke: { + curve: 'smooth', + }, + tooltip: { + enabled: false, + }, + xaxis: { + type: 'datetime', + categories: uptimes.map((ut) => ut.hour), + }, + legend: { + show: true, + position: 'top', + fontFamily: 'Inter', + offsetY: -5, + floating: true, + labels: { + colors: 'rgb(156, 163, 175)', + useSeriesColors: false, + }, + }, + }; + }); } } From 7b19765f4d6735593c7963592ea73b1c014c5b8f Mon Sep 17 00:00:00 2001 From: christophenne Date: Wed, 8 Jan 2025 11:58:17 +0100 Subject: [PATCH 6/8] feat: store and read from local storage Signed-off-by: christophenne --- .../charts/type/chart-type.component.html | 4 +- .../charts/uptime/chart-uptime.component.html | 23 ++- .../charts/uptime/chart-uptime.component.ts | 173 +++++++----------- 3 files changed, 76 insertions(+), 124 deletions(-) diff --git a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html index ef1ebbc9..56d69fee 100644 --- a/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html +++ b/frontend/cloud-ui/src/app/components/charts/type/chart-type.component.html @@ -11,8 +11,6 @@

D [xaxis]="chartOptions.xaxis!" [legend]="chartOptions.legend!"> -} @else if (loading) { -

Loading...

} @else { -

Nothing to display right now.

+

Nothing to display right now.

} diff --git a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html index 571615e7..6ce4dc0c 100644 --- a/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html +++ b/frontend/cloud-ui/src/app/components/charts/uptime/chart-uptime.component.html @@ -1,14 +1,16 @@
-

Deployment Uptime

+

+ Uptime{{ selectedDeploymentTarget ? ': ' + selectedDeploymentTarget.name : '' }} +

- -
    - @for (dt of deploymentTargets$ | async; track dt.id ) { + @for (dt of deploymentTargets$ | async; track dt.id) {