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

88 lines
3.2 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} 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";
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:"openaire-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"},
];
public placementsOptions: Option[] = [
{label:"Top", value:"top"},
{label:"Bottom", value:"bottom"},
// {label:"Top Right", value:"top-right"},
// {label:"Center", value:"center"},
{label:"Right", value:"right"},
{label:"Left", value:"left"},
];
public planOptions: Option[] = [
{value: 'starter', label: 'Starter'},
{value: 'extended', label: 'Extended'}
];
public static initializeObject(code){
switch(code) {
case 'openaire-products': {
return new PluginOpenAIREProducts();
}
case 'discover-by-subcommunity': {
return new PluginDiscoverBySubcommunity();
}
case 'gateway-information': {
return new PluginGatewayInformation();
}
case 'search-deposit-link': {
return new PluginSearchDepositLink();
}
case 'learn-and-connect': {
return new PluginLearnAndConnect();
}
case 'how-to-use': {
return new PluginHowToUse();
}
case 'suggested-repositories': {
return new PluginBaseInfo();
}
case 'featured-datasets': {
return new PluginFeaturedDatasets();
}
default: {
return new PluginBaseInfo();
}
}
}
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;
}
}