Create stats profile admin page
This commit is contained in:
parent
0b793bba40
commit
7b59267582
|
@ -44,6 +44,12 @@ const routes: Routes = [
|
|||
canActivateChild: [AdminLoginGuard],
|
||||
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',
|
||||
loadChildren: () => import('./admin-stakeholder/admin-stakeholder-routing.module').then(m => m.AdminStakeholderRoutingModule),
|
||||
|
|
|
@ -62,7 +62,8 @@ import {NotificationHandler} from "../../openaireLibrary/utils/notification-hand
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'" [formInput]="stakeholderFb.get('logoUrl')"></div>
|
||||
<div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'"
|
||||
[formInput]="stakeholderFb.get('logoUrl')"></div>
|
||||
</div>
|
||||
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
|
||||
<div class="uk-card uk-card-default uk-text-center uk-border-circle">
|
||||
|
@ -101,7 +102,8 @@ import {NotificationHandler} from "../../openaireLibrary/utils/notification-hand
|
|||
</ng-container>
|
||||
</div>
|
||||
</form>
|
||||
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div>
|
||||
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form
|
||||
class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div>
|
||||
`,
|
||||
styleUrls: ['edit-stakeholder.component.less']
|
||||
})
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f49149c99e7bf08179d95b56a1aac9848a850344
|
||||
Subproject commit 6a2ac8cc4e1a77c10f632eccfd73b91082fe4a4a
|
|
@ -0,0 +1,125 @@
|
|||
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 => {
|
||||
this.statsProfiles = statsProfiles;
|
||||
this.resetForm();
|
||||
this.loading = false;
|
||||
}, error => {
|
||||
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
|
||||
this.loading = false;
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 {}
|
|
@ -0,0 +1,23 @@
|
|||
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());
|
||||
}
|
||||
}
|
|
@ -208,6 +208,7 @@ export class IndicatorUtils {
|
|||
['bar', 'notes'],
|
||||
['other', 'perm_media']
|
||||
]);
|
||||
|
||||
getChartTypes(initialType) {
|
||||
let types: Option[] = [];
|
||||
if (this.basicChartTypes.indexOf(initialType) != -1) {
|
||||
|
@ -228,6 +229,7 @@ export class IndicatorUtils {
|
|||
return this.allChartTypes;
|
||||
}
|
||||
}
|
||||
|
||||
isPublicIcon: Map<boolean, string> = new Map([
|
||||
[true, 'public'],
|
||||
[false, 'lock']
|
||||
|
@ -315,6 +317,7 @@ export class IndicatorUtils {
|
|||
}
|
||||
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
|
||||
}
|
||||
|
||||
public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false): string {
|
||||
indicatorPath.filtersApplied = 0;
|
||||
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
|
||||
|
@ -387,6 +390,7 @@ export class IndicatorUtils {
|
|||
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
|
||||
|
||||
}
|
||||
|
||||
private addFilter(replacedUrl, filterType: FilterType, filterValue) {
|
||||
let newJsonObject = JSON.parse(replacedUrl);
|
||||
let filterApplied: boolean = false;
|
||||
|
@ -528,6 +532,7 @@ export class IndicatorUtils {
|
|||
// console.debug(values);
|
||||
return values.length > 1;
|
||||
}
|
||||
|
||||
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type: IndicatorType, addParameters: boolean = true): Indicator {
|
||||
let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
|
||||
form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
|
||||
|
@ -545,6 +550,7 @@ export class IndicatorUtils {
|
|||
});
|
||||
return indicator;
|
||||
}
|
||||
|
||||
generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder: Stakeholder, jsonPath = [], sourceServices: string[] = []): IndicatorPath {
|
||||
let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath);
|
||||
if (source === 'stats-tool') {
|
||||
|
@ -582,6 +588,7 @@ export class IndicatorUtils {
|
|||
}
|
||||
return indicatorPath;
|
||||
}
|
||||
|
||||
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder: Stakeholder): IndicatorPath {
|
||||
let indicatorPath = new IndicatorPath(type, source, null, null, []);
|
||||
try {
|
||||
|
@ -640,6 +647,7 @@ export class IndicatorUtils {
|
|||
}
|
||||
return indicatorPath;
|
||||
}
|
||||
|
||||
private getQueryObjectName(obj) {
|
||||
if ((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")) {
|
||||
return "queriesInfo";
|
||||
|
@ -647,6 +655,7 @@ export class IndicatorUtils {
|
|||
return "queries";
|
||||
}
|
||||
}
|
||||
|
||||
private getDescriptionObjectName(obj) {
|
||||
if (obj.hasOwnProperty("mapDescription")) {
|
||||
return "mapDescription";
|
||||
|
@ -658,6 +667,7 @@ export class IndicatorUtils {
|
|||
return "series";
|
||||
}
|
||||
}
|
||||
|
||||
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
|
||||
let type = (obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"]) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"] : "";
|
||||
if (this.basicChartTypes.indexOf(type) == -1) {
|
||||
|
@ -668,11 +678,13 @@ export class IndicatorUtils {
|
|||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
|
||||
this.extractFunder(obj, indicatorPath, stakeholder);
|
||||
this.extractRI(obj, indicatorPath, stakeholder);
|
||||
this.extractOrganization(obj, indicatorPath, stakeholder);
|
||||
}
|
||||
|
||||
private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
|
||||
if (stakeholder.type != "funder") {
|
||||
return;
|
||||
|
@ -744,6 +756,7 @@ export class IndicatorUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extractStartYear(obj, indicatorPath: IndicatorPath) {
|
||||
let start_year;
|
||||
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
|
||||
|
@ -819,6 +832,7 @@ export class IndicatorUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extractDataTitle(obj, indicatorPath: IndicatorPath) {
|
||||
let index = 0;
|
||||
if (!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
|
||||
|
@ -833,6 +847,7 @@ export class IndicatorUtils {
|
|||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private extractTitle(obj, indicatorPath: IndicatorPath) {
|
||||
let title = "";
|
||||
if (obj[this.getDescriptionObjectName(obj)]["title"]) {
|
||||
|
@ -923,6 +938,7 @@ export class IndicatorUtils {
|
|||
public checkForSchemaEnhancements(url: string): boolean {
|
||||
return url != this.applySchemaEnhancements(url);
|
||||
}
|
||||
|
||||
public applySchemaEnhancements(url: string): string {
|
||||
let resultEnhancements = [
|
||||
[".project.acronym", ".project acronym"],
|
||||
|
|
Loading…
Reference in New Issue