[Monitor Dashnoard]: Add stakeholder utils and move function from stakeholderCreator.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57770 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2019-11-29 13:35:13 +00:00
parent b3fdeb99c5
commit 9d10f6e745
4 changed files with 97 additions and 23 deletions

View File

@ -4,7 +4,7 @@ import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties"
import {EnvironmentSpecificService} from "../openaireLibrary/utils/properties/environment-specific.service";
import {Stakeholder} from "../utils/entities/stakeholder";
import {Subscriber, zip} from "rxjs";
import {IndicatorUtils, Option, StakeholderUtils} from "../utils/indicator-utils";
import {Option, StakeholderUtils} from "../utils/indicator-utils";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {AlertModal} from "../openaireLibrary/utils/modal/alert";
@ -168,7 +168,7 @@ export class HomeComponent implements OnInit, OnDestroy {
type: this.fb.control(stakeholder.type, Validators.required),
topics: this.fb.control(stakeholder.topics)
});
if(this.index !== -1) {
if(this.index !== -1 && this.stakeholderFb.value.type) {
this.stakeholderFb.get('type').disable();
}
this.editStakeholderModal.cancelButtonText = 'Cancel';
@ -179,7 +179,28 @@ export class HomeComponent implements OnInit, OnDestroy {
}
public saveStakeholder() {
if(this.index === -1) {
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL,
this.stakeholderFb.value.type).subscribe( stakeholders => {
this.stakeholderFb.setControl('topic', this.fb.control(stakeholders[0].topics));
this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => {
if(stakeholder.isDefaultProfile) {
this.defaultStakeholders.push(stakeholder);
} else {
this.stakeholders.push(stakeholder);
}
});
});
} else {
this.stakeholderFb.get('type').enable();
this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => {
if(stakeholder.isDefaultProfile) {
this.defaultStakeholders[this.index] = stakeholder;
} else {
this.stakeholders[this.index] = stakeholder;
}
});
}
}
public deleteStakeholderOpen(stakeholder: Stakeholder, isDefault = false) {

View File

@ -33,7 +33,7 @@ export class InputComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.initValue = HelperFunctions.copy(this.formControl.value);
this.formControl.valueChanges.subscribe(value => {
if(this.initValue.toString() === value.toString()) {
if(this.initValue === value) {
this.formControl.markAsPristine();
}
});

View File

@ -14,7 +14,7 @@ import {StakeholderService} from "../services/stakeholder.service";
import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder";
import {StatisticsService} from "../utils/services/statistics.service";
import {Item, Sidebar} from "../utils/entities/sidebar";
import {IndicatorUtils} from "../utils/indicator-utils";
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
import {StakeholderCreator} from "../utils/entities/stakeholderCreator";
import {LayoutService} from "../library/sharedComponents/sidebar/layout.service";
@ -29,6 +29,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
public status: number;
public loading: boolean = true;
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
public activeTopic: Topic = null;
public activeCategory: Category = null;
public activeSubCategory: SubCategory = null;
@ -76,19 +77,19 @@ export class MonitorComponent implements OnInit, OnDestroy {
// this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
let stakeholder:Stakeholder = null;
if(params['stakeholder']=="fwf"){
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("fwf","funder","fwf_________::FWF",
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile("fwf","funder","fwf_________::FWF",
"Austrian Science Fund (FWF)","FWF",
false,"fwf",true,true, null);
false,"fwf",true,true, null, StakeholderCreator.createFunderDefaultProfile());
stakeholder.logoUrl = "./assets/fwf.png";
}else if(params['stakeholder']=="arc"){
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("arc","funder","arc_________::ARC",
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile("arc","funder","arc_________::ARC",
"Australian Research Council (ARC)","ARC",
false,"arc",true,true, null);
false,"arc",true,true, null, StakeholderCreator.createFunderDefaultProfile());
stakeholder.logoUrl = "./assets/arc1.gif";
}else{
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("ec","funder","ec__________::EC",
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile("ec","funder","ec__________::EC",
"European Commission","EC",
false,"ec",true,true, null);
false,"ec",true,true, null, StakeholderCreator.createFunderDefaultProfile());
stakeholder.logoUrl = "./assets/ec.png";
}

View File

@ -1,4 +1,4 @@
import {ChartHelper, Indicator, IndicatorPath} from "./entities/stakeholder";
import {ChartHelper, Indicator, IndicatorPath, Stakeholder, SubCategory} from "./entities/stakeholder";
import {Validators} from "@angular/forms";
export interface Option {
@ -13,12 +13,12 @@ export class StakeholderUtils {
{value: 'funder', label: 'Funder'}
];
isPublic: Option[] = [
isPublic: Option[] = [
{icon: 'public', value: true, label: 'Public'},
{icon: 'lock', value: false, label: 'Private'},
];
isActive: Option[] = [
isActive: Option[] = [
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
{icon: 'brightness_1', value: false, label: 'Inactive'},
];
@ -29,6 +29,59 @@ export class StakeholderUtils {
]);
isActiveIcon: string = 'brightness_1';
public createFunderFromDefaultProfile(id: string, type: string, index_id, index_name: string, index_shortName: string,
isDefaultProfile: boolean, alias: string, isActive: boolean, isPublic: boolean,
logoUrl: string, funder: Stakeholder): Stakeholder {
funder.initializeFunder(id, type, index_id, index_name, index_shortName, isDefaultProfile, alias, isActive, isPublic, logoUrl);
for (let topic of funder.topics) {
for (let category of topic.categories) {
let subTokeep: SubCategory[] = [];
for (let subCategory of category.subCategories) {
let chartsTokeep: Indicator[] = [];
if (subCategory.recommendedFor.length == 0 || subCategory.recommendedFor.indexOf(id) != -1) {
subTokeep.push(subCategory);
}
for (let indicator of subCategory.charts) {
if (indicator.recommendedFor.length == 0 || indicator.recommendedFor.indexOf(id) != -1) {
chartsTokeep.push(indicator);
}
for (let indicatorPath of indicator.indicatorPaths) {
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
} else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
}
});
}
}
}
subCategory.charts = chartsTokeep;
for (let indicator of subCategory.numbers) {
for (let indicatorPath of indicator.indicatorPaths) {
indicatorPath.url = indicatorPath.url.replace("_funder_id_", funder.index_id);
// if(indicatorPath.parameters) {
// indicatorPath.parameters.forEach((value: string, key: string) => {
// if (value.indexOf("_funder_name_")!=-1) {
// indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
// }else if (value.indexOf("_fsn_")!=-1) {
// indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
// }
// });
// }
}
}
}
category.subCategories = subTokeep;
}
}
console.log(funder);
return funder;
}
}
export class IndicatorUtils {
@ -48,12 +101,12 @@ export class IndicatorUtils {
{value: 'large', label: 'Large'}
];
isPublic: Option[] = [
isPublic: Option[] = [
{icon: 'public', value: true, label: 'Public'},
{icon: 'lock', value: false, label: 'Private'},
];
isActive: Option[] = [
isActive: Option[] = [
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
{icon: 'brightness_1', value: false, label: 'Inactive'},
];
@ -104,8 +157,7 @@ export class IndicatorUtils {
queries["query"]["filters"] = [];
}
//TODO check how it works if the query already has a filter
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["fundingL0"].
replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix, fundingL0)));
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["fundingL0"].replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix, fundingL0)));
}
replacedUrl = JSON.stringify(newJsonObject);
}
@ -120,7 +172,7 @@ export class IndicatorUtils {
form.indicatorPaths.forEach((indicatorPath, index) => {
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if(parameter.key === 'type') {
if (parameter.key === 'type') {
indicator.indicatorPaths[index].type = parameter.value;
}
});
@ -181,7 +233,7 @@ export class IndicatorUtils {
if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) {
funderName = filter["groupFilters"][0]["values"][0];
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "funder_name" + ChartHelper.suffix;
indicatorPath.parameters["funder_name"] = funderName;
indicatorPath.parameters["funder_name"] = funderName;
}
}
}
@ -198,7 +250,7 @@ export class IndicatorUtils {
if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) {
start_year = gfilter["values"][0];
gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix;
indicatorPath.parameters["start_year"] = start_year;
indicatorPath.parameters["start_year"] = start_year;
}
}
}
@ -216,7 +268,7 @@ export class IndicatorUtils {
if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) {
end_year = gfilter["values"][0];
gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix;
indicatorPath.parameters["end_year"] = end_year;
indicatorPath.parameters["end_year"] = end_year;
}
}
}
@ -228,7 +280,7 @@ export class IndicatorUtils {
if (obj["chartDescription"]["title"]) {
title = obj["chartDescription"]["title"]["text"];
obj["chartDescription"]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
indicatorPath.parameters["title"] = title;
indicatorPath.parameters["title"] = title;
}
}