Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE-6447] Feature/feture metrics trunk #400

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/metrics/metric-detail/metric-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ <h2 class="title">{{ metric.name | titlecase }}</h2>
</ng-container>
<ng-container *ngSwitchCase="'institution'">
<ion-button size="default" shape="round" color="ocean" (click)="action('edit')">Edit</ion-button>
<ion-button size="default" shape="round" color="ocean" *ngIf="metric.status === 'active'" (click)="action('setDraft')">Convert to Draft</ion-button>
<ion-button size="default" shape="round" color="ocean" *ngIf="metric.status === 'active'" (click)="action('archive')">Archive</ion-button>
<ion-button size="default" shape="round" color="ocean" *ngIf="metric.status === 'draft' || metric.status === 'archived'" (click)="action('activate')">Set Active</ion-button>
<ion-button size="default" shape="round" color="ocean" *ngIf="metric.status === 'active'" (click)="action('draft')">Convert to Draft</ion-button>
<ion-button size="default" shape="round" color="ocean" *ngIf="metric.status === 'active' || metric.status === 'draft'" (click)="action('archive')">Archive</ion-button>
</ng-container>
<ng-container *ngSwitchDefault>
<ion-button size="default" shape="round" color="ocean" (click)="action('edit')">Edit</ion-button>
Expand Down
36 changes: 24 additions & 12 deletions src/app/metrics/metric-detail/metric-detail.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ModalController, ToastController } from '@ionic/angular';
import { UpdateMetricComponent } from '../update-metric/update-metric.component';
import { Metric, MetricsService } from '../metrics.service';
import { Metric, MetricStatus, MetricsService } from '../metrics.service';
import { first } from 'rxjs';
import { MetricConfigureComponent } from '../metric-configure/metric-configure.component';

Expand Down Expand Up @@ -43,16 +43,16 @@ export class MetricDetailComponent implements OnInit {
this.calculateMetric();
break;
case 'archive':
this.archiveMetric();
this.setStatus('archived');
break;
case 'configure':
this.configureMetric();
break;
case 'activate':
this.setActive();
this.setStatus('active');
break;
case 'setDraft':
this.setDraft();
case 'draft':
this.setStatus('draft');
break;
default:
console.log('Action not recognized');
Expand All @@ -73,14 +73,26 @@ export class MetricDetailComponent implements OnInit {
});
});
}

setDraft() {
}

setActive() {
fetchMetrics() {
this.metricsService.getMetrics(this.from === 'library').pipe(first()).subscribe({
next: (metrics: Metric[]) => {
this.metric = metrics.find(metric => metric.uuid === this.metric.uuid);
},
});
}

archiveMetric() {
setStatus(status: string) {
this.metricsService.setStatus(this.metric.uuid, MetricStatus[status]).pipe(first()).subscribe({
next: res => {
this.toastController.create({
message: res?.updateMetric?.message || `Metric set to ${status}.`,
duration: 1500,
position: 'top',
}).then(toast => toast.present());
this.fetchMetrics();
}
});
}

async configureMetric() {
Expand All @@ -104,7 +116,7 @@ export class MetricDetailComponent implements OnInit {
await toast.present();

if (res?.data?.configureMetric?.success === true) {
this.metricsService.getMetrics(this.from === 'library').pipe(first()).subscribe();
this.fetchMetrics();
}
});
}
Expand All @@ -117,7 +129,7 @@ export class MetricDetailComponent implements OnInit {
duration: 1500,
position: 'top',
}).then(toast => toast.present());
this.metricsService.getMetrics(this.from === 'library').pipe(first()).subscribe();
this.fetchMetrics();
},
error: error => {
this.toastController.create({
Expand Down
18 changes: 4 additions & 14 deletions src/app/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,13 @@ export class MetricsComponent implements OnInit, OnDestroy {
const date = new Date(parseInt(timestamp));
return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
}

private _processRecords(records) {
const dateMap = {}; // Key: date, Value: { valueSum, countSum }
records.forEach(record => {
const date = this._formatDate(record.created);
if (!dateMap[date]) {
dateMap[date] = { value: '', count: '' };
}
dateMap[date].value += record.value;
dateMap[date].count += record.count;
});
return dateMap;
}


// Capitalize the first letter of a string
private _ucFirst(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

// generate a CSV file for download
download() {
this.metricsService.download().pipe(first()).subscribe({
next: response => {
Expand Down
20 changes: 19 additions & 1 deletion src/app/metrics/metrics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,26 @@ export class MetricsService {
);
}

// set metric status only (draft, active, archived)
setStatus(uuid: string, status: MetricStatus) {
return this.graphql.graphQLMutate(`
mutation updateMetric($uuid: ID!, $status: MetricStatus) {
updateMetric(uuid: $uuid, status: $status) {
success
message
}
}`,
{
uuid,
status
}
).pipe(
map(response => response.data),
);
}

saveMetric(variables: {
uuid: number;
uuid: string;
name: string;
description: string;
isPublic: boolean;
Expand Down
3 changes: 0 additions & 3 deletions src/app/shared/services/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,6 @@ export class UtilsService {
return new Delta().insert(plaintext);
});
}

XLSXFormat() {
}

generateXLSX(data, header = null) {
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(data, { header });
Expand Down
Loading