openaire-library/utils/routerHelper.class.ts

56 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

export class RouterHelper {
//Use this class function to create queryParams Objects in format {key1:value1} or {key1:value1,key2:value2,key3:value3,...} for multiple parameters
constructor(){}
// <a [queryParams]="RouterHelper.createQueryParam(filter.filterId,value.id)" routerLinkActive="router-link-active" [routerLink]=baseUrl>Link</a>
[Library | develop & Eosc Explore | develop]: Added font-family "Inter" to align with Marketplace | Updated how back button "Go to search" is build - combine referrer and the new url parameter "pv", which is expected to have the previous url path and params. 1. /assets: Added /media/fonts/inter folder with the "Inter" font-family. 2. eosc-custom.less: Override the default font family to use 'Inter', sans-serif. 3. routerHelper.class.ts: Added method "addQueryParam()" to add a query parameter in already existing or not object with parameters. 4. search-tab.component.ts & searchResult.component & projects-in-modal.component.ts & result/deletedByInference/deletedByInference.component.ts & organization/deletedByInference/deletedByInference.component.ts: Added @Input() prevPath: string = ""; and pass it to the appropriate children components. 5. result-preview.component & fundedBy.component.ts & availableOn.component.ts & relatedDatasourcesTab.component.ts: Added @Input() prevPath: string = ""; and method "addEoscPrevInParams()" and call it when building queryParams of internal links. 6. metrics.component.ts: Added @Input() prevPath: string = ""; and use it when building internal urls. 7. resultLanding.component.ts & project.component.ts & organization.component.ts & dataProvider.component.ts: a. Added fields public referrer: string; and public prevPath: string; b. Read "pv" url property and get referrer. c. Added methods "addEoscPrevInParams()" and "eoscBackLink()". 8. resultLanding.component.html & project.component.html & organization.component.html & dataProvider.component.html: a. Update "Go to Search" back link. b. Call "addEoscPrevInParams()" method when building queryParams of internal links. c. Pass "prevPath" to the appropriate children components.
2023-04-20 19:06:53 +02:00
public addQueryParam(key:string,value:string, obj){
if(!obj) {
obj = {};
}
obj[key] = value;
return obj;
}
public createQueryParam(key:string,value:string){
var obj ={};
obj[key]=value;
return obj;
}
public createQueryParamsPaging(keys:string[],values:string[],pageParameter:string,pageValue:number){
var obj = this.createQueryParams(keys, values);
obj[pageParameter] = ""+pageValue;
return obj;
}
public createQueryParams(keys:string[],values:string[]){
var obj ={};
if(!keys || !values || keys.length != values.length){
return obj;
}else{
for(var i=0; i< keys.length; i++){
obj[keys[i]]=values[i];
}
}
return obj;
}
public createQueryParamsString(keys:string[],values:string[]){
let obj ="?";
if(!keys || !values || keys.length != values.length || keys.length === 0){
return "";
}else{
for(let i=0; i< keys.length; i++){
obj+=(i==0?"":"&")+encodeURIComponent(keys[i])+"="+encodeURIComponent(values[i]);
}
}
return obj;
}
}