openaire-library/dashboard/plugins/utils/pluginUtils.ts

100 lines
3.9 KiB
TypeScript

import {Option} from "../../../sharedComponents/input/input.component";
import {PluginOpenAIREProducts} from "../components/openaireProducts/plugin-openaire-products.component";
import {PluginDiscoverBySubcommunity} from "../components/discover-by-subcommunity/plugin-discover-by-subcommunity.component";
import {PluginBaseInfo, PluginInfoCards, PluginURL} from "./base-plugin.component";
import {PluginGatewayInformation} from "../components/gateway-information/plugin-gateway-information.component";
import {PluginLearnAndConnect} from "../components/learn-and-connect/plugin-learn-and-connect.component";
import {PluginFeaturedDatasets} from "../components/featured-datasets/plugin-featured-datasets.component";
import {PluginHowToUse} from "../components/how-to-use/plugin-how-to-use.component";
import {PluginSearchDepositLink} from "../components/search-deposit-link/plugin-search-deposit-link.component";
import {PluginOrganizations} from "../components/organizations/plugin-organizations.component";
import {FormArray, FormGroup, Validators} from "@angular/forms";
export class PluginUtils{
public attrTypeOptions: Option[] = [
{label:"Text", value:"text"},
{label:"HTML", value:"HTML"},
{label:"Boolean", value:"boolean"},
{label:"URL", value:"URL"},
];
public availablePluginCodes: Option[] = [
{label:"OpenAIRE products", value:"penaire-products"},
{label:"Discover by subcommunity", value:"discover-by-subcommunity"},
{label:"Gateway information", value:"gateway-information"},
{label:"Search/ deposit/ link", value:"search-deposit-link"},
{label:"Learn and Connect", value:"learn-and-connect"},
{label:"How to use", value:"how-to-use"},
{label:"Suggested Repositories", value:"suggested-repositories"},
{label:"Featured Datasets", value:"featured-datasets"},
{label:"Organizations", value:"organizations"},
{label:"Fos / SDGs", value:"fos-sdgs"},
{label:"Graph info", value:"graph-info"},
{label:"Social", value:"social"},
{label:"Contact us", value:"organizations"},
];
public placementsOptions: Option[] = [
{label:"Right", value:"right"},
{label:"Top", value:"top"},
// {label:"Top Right", value:"top-right"},
// {label:"Center", value:"center"},
{label:"Bottom", value:"bottom"},
{label:"Left", value:"left"},
];
public planOptions: Option[] = [
{value: 'starter', label: 'Starter'},
{value: 'extended', label: 'Extended'}
];
public static initializeObjectAndCompare(code, oldObject = null){
switch(code) {
case 'openaire-products': {
return (new PluginOpenAIREProducts()).compare(oldObject);
}
case 'discover-by-subcommunity': {
return (new PluginDiscoverBySubcommunity()).compare(oldObject);
}
case 'gateway-information': {
return (new PluginGatewayInformation()).compare(oldObject);
}
case 'search-deposit-link': {
return (new PluginSearchDepositLink()).compare(oldObject);
}
case 'learn-and-connect': {
return (new PluginLearnAndConnect()).compare(oldObject);
}
case 'how-to-use': {
return (new PluginHowToUse()).compare(oldObject);
}
case 'suggested-repositories': {
return (new PluginBaseInfo()).compare(oldObject);
}
case 'featured-datasets': {
return (new PluginFeaturedDatasets()).compare(oldObject);
}
case 'organizations': {
return (new PluginOrganizations()).compare(oldObject);
}
default: {
return (new PluginBaseInfo()).compare(oldObject);
}
}
}
//
public static updateExistingObject(oldObject, object ){
if(!oldObject) {
oldObject = Object.assign(object)
}else{
for (let attrKey of Object.keys(object)) {
if (!oldObject[attrKey] && oldObject[attrKey] != false) {
oldObject[attrKey] = Object.assign(object[attrKey])
}
}
}
return oldObject;
}
}