Delete stats profile page. Change get stats profiles endpoint to stats tool.

This commit is contained in:
Konstantinos Triantafyllou 2023-04-25 15:21:55 +03:00
parent 40c68f8f08
commit a63ff6d785
7 changed files with 28 additions and 180 deletions

View File

@ -44,12 +44,6 @@ const routes: Routes = [
canActivateChild: [AdminLoginGuard], canActivateChild: [AdminLoginGuard],
data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true, parentClass: 'monitor'} data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true, parentClass: 'monitor'}
}, },
{
path: 'admin/monitor/admin-tools/stats-profiles',
loadChildren: () => import('./stats-profiles/stats-profiles.module').then(m => m.StatsProfilesModule),
canActivateChild: [AdminLoginGuard],
data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true}
},
{ {
path: 'admin/:stakeholder', path: 'admin/:stakeholder',
loadChildren: () => import('./admin-stakeholder/admin-stakeholder-routing.module').then(m => m.AdminStakeholderRoutingModule), loadChildren: () => import('./admin-stakeholder/admin-stakeholder-routing.module').then(m => m.AdminStakeholderRoutingModule),

View File

@ -15,7 +15,8 @@ import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-fo
import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils"; import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils";
import {Notification} from "../../openaireLibrary/notifications/notifications"; import {Notification} from "../../openaireLibrary/notifications/notifications";
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler"; import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
import {StatsProfilesService} from "../../stats-profiles/stats-profiles.service"; import {StatsProfilesService} from "../../utils/services/stats-profiles.service";
import {error} from "protractor";
@Component({ @Component({
selector: 'edit-stakeholder', selector: 'edit-stakeholder',
@ -43,7 +44,7 @@ import {StatsProfilesService} from "../../stats-profiles/stats-profiles.service"
placeholder="Index Short Name"></div> placeholder="Index Short Name"></div>
</div> </div>
<div class="uk-width-1-2@m"> <div class="uk-width-1-2@m">
<div *ngIf="statsProfiles" input [formInput]="stakeholderFb.get('statsProfile')" [type]="'autocomplete_soft'" <div *ngIf="statsProfiles" input [formInput]="stakeholderFb.get('statsProfile')" [type]="'autocomplete'"
[options]="statsProfiles" [showOptionsOnEmpty]="true" [options]="statsProfiles" [showOptionsOnEmpty]="true"
placeholder="Stats Profile"></div> placeholder="Stats Profile"></div>
</div> </div>
@ -163,9 +164,10 @@ export class EditStakeholderComponent implements OnDestroy {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user; this.user = user;
if(this.isCurator) { if(this.isCurator) {
this.subscriptions.push(this.statsProfileService.getStatsProfile().subscribe(statsProfiles => { this.subscriptions.push(this.statsProfileService.getStatsProfiles().subscribe(statsProfiles => {
this.statsProfiles = statsProfiles.map(statsProfile => statsProfile.name); this.statsProfiles = statsProfiles;
console.log() }, error => {
this.statsProfiles = [];
})); }));
} else { } else {
this.statsProfiles = []; this.statsProfiles = [];

@ -1 +1 @@
Subproject commit f00607f8d308e856d66da8b905d3221361952874 Subproject commit d9d69031c8b4574c2ffe5c5279e268934910da5e

View File

@ -1,126 +0,0 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from "@angular/core";
import {StatsProfilesService} from "./stats-profiles.service";
import {StatsProfile} from "../openaireLibrary/monitor/entities/stakeholder";
import {Subscription} from "rxjs";
import {FormBuilder, UntypedFormArray, Validators} from "@angular/forms";
import {NotificationHandler} from "../openaireLibrary/utils/notification-handler";
@Component({
selector: 'stats-profiles',
template: `
<div page-content>
<div header>
<admin-tabs tab="stats-profiles" [portal]="'monitor'"></admin-tabs>
</div>
<div actions>
<div class="uk-section-xsmall uk-container uk-container-xsmall">
<div class="uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle">
<button class="uk-button uk-button-default uk-margin-small-right" (click)="resetForm()"
[disabled]="loading || statsProfilesForm.pristine" [class.uk-disabled]="loading">
Reset
</button>
<button class="uk-button uk-button-primary" (click)="save()"
[disabled]="loading || statsProfilesForm.pristine || statsProfilesForm.invalid"
[class.uk-disabled]="loading || statsProfilesForm.pristine || statsProfilesForm.invalid">
Save
</button>
</div>
</div>
</div>
<div inner>
<div class="uk-section uk-container uk-container-xsmall uk-position-relative" style="min-height: 60vh">
<div *ngIf="loading" class="uk-position-center">
<loading></loading>
</div>
<div *ngIf="!loading" class="uk-grid uk-child-width-1-1" uk-grid>
<div [id]="'profile-' + i.toString()" *ngFor="let statsProfile of statsProfilesForm.controls; let i=index" class="uk-flex uk-flex-middle">
<div input placeholder="Name" class="uk-width-expand" [formInput]="statsProfile.get('name')"></div>
<button *ngIf="statsProfilesForm.controls.length > 1" class="uk-button uk-button-link uk-margin-small-left" (click)="remove(i)">
<icon name="delete" [ratio]="1.2" [flex]="true"></icon>
</button>
</div>
<div class="uk-flex uk-flex-center">
<button class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="add()">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left uk-text-bold uk-text-uppercase">Add profile</span>
</button>
</div>
</div>
</div>
</div>
</div>
`
})
export class StatsProfilesComponent implements OnInit, OnDestroy {
public statsProfiles: StatsProfile[] = [];
public statsProfilesForm: UntypedFormArray;
public loading: boolean = true;
private subscriptions: any[] = [];
constructor(private statsProfilesService: StatsProfilesService,
private cdr: ChangeDetectorRef,
private fb: FormBuilder) {
}
ngOnInit() {
this.subscriptions.push(this.statsProfilesService.getStatsProfile().subscribe(statsProfiles => {
this.statsProfiles = statsProfiles;
this.resetForm();
this.loading = false;
}));
}
resetForm() {
this.statsProfilesForm = this.fb.array([]);
this.statsProfiles.forEach(statsProfile => {
this.statsProfilesForm.push(this.fb.group({
_id: this.fb.control(statsProfile._id),
name: this.fb.control(statsProfile.name, Validators.required)
}));
});
if(this.statsProfilesForm.length === 0) {
this.add();
}
}
remove(index: number) {
this.statsProfilesForm.removeAt(index);
this.statsProfilesForm.markAsDirty();
this.cdr.detectChanges();
}
add() {
this.statsProfilesForm.push(this.fb.group({
_id: this.fb.control(null),
name: this.fb.control('', Validators.required)
}));
this.statsProfilesForm.markAsDirty();
this.cdr.detectChanges();
if(!this.loading) {
document.getElementById('profile-' + (this.statsProfilesForm.length - 1).toString()).scrollIntoView({behavior: 'smooth'});
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if(subscription instanceof Subscription) {
subscription.unsubscribe();
}
});
}
save() {
this.loading = true;
this.subscriptions.push(this.statsProfilesService.saveStatsProfiles(this.statsProfilesForm.getRawValue()).subscribe(statsProfiles => {
NotificationHandler.rise('Stats Profiles have been successfully saved');
this.statsProfiles = statsProfiles;
this.resetForm();
this.loading = false;
}, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
this.loading = false;
}));
}
}

View File

@ -1,19 +0,0 @@
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {RouterModule} from "@angular/router";
import {StatsProfilesComponent} from "./stats-profiles.component";
import {PageContentModule} from "../openaireLibrary/dashboard/sharedComponents/page-content/page-content.module";
import {AdminTabsModule} from "../openaireLibrary/dashboard/sharedComponents/admin-tabs/admin-tabs.module";
import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {SearchInputModule} from "../openaireLibrary/sharedComponents/search-input/search-input.module";
import {InputModule} from "../openaireLibrary/sharedComponents/input/input.module";
import {LoadingModule} from "../openaireLibrary/utils/loading/loading.module";
@NgModule({
imports: [CommonModule, RouterModule.forChild([
{path: '', component: StatsProfilesComponent}
]), PageContentModule, AdminTabsModule, IconsModule, SearchInputModule, InputModule, LoadingModule],
declarations: [StatsProfilesComponent],
exports: [StatsProfilesComponent]
})
export class StatsProfilesModule {}

View File

@ -1,23 +0,0 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {properties} from "../../environments/environment";
import {Observable} from "rxjs";
import {StatsProfile} from "../openaireLibrary/monitor/entities/stakeholder";
import {CustomOptions} from "../openaireLibrary/services/servicesUtils/customOptions.class";
@Injectable({
providedIn: 'root'
})
export class StatsProfilesService {
constructor(private http: HttpClient) {
}
getStatsProfile(): Observable<StatsProfile[]> {
return this.http.get<StatsProfile[]>(properties.monitorServiceAPIURL + '/stats-profiles', CustomOptions.registryOptions());
}
saveStatsProfiles(statsProfiles: StatsProfile[]): Observable<StatsProfile[]> {
return this.http.post<StatsProfile[]>(properties.monitorServiceAPIURL + '/stats-profiles/bulk', statsProfiles, CustomOptions.registryOptions());
}
}

View File

@ -0,0 +1,20 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {properties} from "../../../environments/environment";
import {Observable} from "rxjs";
import {CustomOptions} from "../../openaireLibrary/services/servicesUtils/customOptions.class";
import {map} from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class StatsProfilesService {
constructor(private http: HttpClient) {
}
getStatsProfiles(): Observable<string[]> {
return this.http.get<any[]>(properties.monitorStatsFrameUrl + 'schema/profiles')
.pipe(map(profiles => profiles.map(profile => profile.name)));
}
}