[plugin-functionalities | WIP] : improvements in template forms (options for plugin code, filter pages based on portaltype, prefill plan option, initialize properly object

This commit is contained in:
argirok 2024-01-22 12:37:48 +02:00
parent d0b4fa7750
commit a373357ccf
6 changed files with 21 additions and 11 deletions

View File

@ -81,7 +81,7 @@ export class PluginOpenaireProductsComponent extends PluginBaseComponent{
}
ngOnInit(): void {
if(this.pluginTemplate && !this.pluginDefaultObject){
if(this.pluginTemplate && (!this.pluginDefaultObject || !this.pluginDefaultObject.title)){
this.pluginTemplate.object = new PluginOpenAIREProducts();
}
}

View File

@ -63,7 +63,7 @@ export class PluginTestComponent extends PluginBaseComponent{
}
ngOnInit(): void {
if(this.pluginTemplate && !this.pluginDefaultObject){
if(this.pluginTemplate && (!this.pluginDefaultObject || !this.pluginDefaultObject.title)){
this.pluginTemplate.object = new PluginTest();
}
}

View File

@ -274,7 +274,7 @@ export class PluginsComponent implements OnInit {
active: this._fb.control(plugin.active),
isPriorTo: this._fb.control(plugin.priorTo),
values: this._fb.array([]),
object: this._fb.group(plugin.object?plugin.object:this.selectedTemplate.object)
object: this._fb.group(plugin.object?plugin.object:(this.selectedTemplate.object?this.selectedTemplate.object:{}))
});
if (template.settings) {
for (let attrKey of Object.keys(template.settings)) {
@ -310,7 +310,7 @@ export class PluginsComponent implements OnInit {
active: this._fb.control(false),
isPriorTo: this._fb.control(false),
values: this._fb.array([]),
object: this._fb.control(null)
object: this._fb.control({})
});
for (let attrKey of Object.keys(this.selectedTemplate.settings)) {
(this.templateForm.get("values") as FormArray).push(this._fb.group({

View File

@ -111,13 +111,13 @@
[okDisabled]="templateForm && (templateForm.invalid || !templateForm.dirty)" classTitle="uk-background-primary uk-light">
<form *ngIf="templateForm" [formGroup]="templateForm" class="uk-grid uk-child-width-1-2" uk-grid>
<div input [formInput]="templateForm.get('name')" placeholder="Template Name"></div>
<div input [formInput]="templateForm.get('code')" placeholder="Template Code"></div>
<div input [formInput]="templateForm.get('code')" placeholder="Template Code" [options]="availablePluginCodes" type="select"></div>
<div class="uk-width-1-1" input [formInput]="templateForm.get('description')" placeholder="Description" type="textarea"> </div>
<div input [formInput]="templateForm.get('plan')" placeholder="Plan" [options]="plans" type="select"></div>
<div input [formInput]="templateForm.get('image')" placeholder="Image"></div>
<div input [formInput]="templateForm.get('portalType')" placeholder="Portal Type" [options]="portalUtils.portalTypes" type="select"></div>
<!-- <div input [formInput]="templateForm.get('portalType')" placeholder="Portal Type" [options]="portalUtils.portalTypes" type="select"></div>-->
<div input [formInput]="templateForm.get('placements')" placeholder="Placements" [options]="placementsOptions" type="chips"></div>
<div input [formInput]="templateForm.get('pages')" placeholder="Pages" [options]="allPages" type="chips"></div>
<div input [formInput]="templateForm.get('pages')" placeholder="Pages" [options]="templateForm.get('portalType').value?getPagesByPortal(templateForm.get('portalType').value):allPages" type="chips"></div>
<plugin-wrapper *ngIf="index>= 0 " [editMode]="true" [wrapperEditMode]="false" [pluginTemplate]="this.templateForm.getRawValue()"
class="uk-width-1-1" [editTemplate]="true" (changed)="pluginFieldChanged($event)"></plugin-wrapper>
<!--<div *ngIf="pluginEditEvent">

View File

@ -57,6 +57,12 @@ export class PluginTemplatesComponent implements OnInit {
{label:"Boolean", value:"boolean"},
{label:"URL", value:"URL"},
];
public availablePluginCodes: Option[] = [
{label:"Test", value:"test"},
{label:"openaire-products", value:"openaire-products"},
{label:"results-numbers", value:"results-numbers"},
];
public placementsOptions: Option[] = [
{label:"Top", value:"top"},
{label:"Bottom", value:"bottom"},
@ -192,10 +198,10 @@ export class PluginTemplatesComponent implements OnInit {
code: this._fb.control(pluginTemplate.code, Validators.required),
description: this._fb.control(pluginTemplate.description),
plan: this._fb.control('', Validators.required),
plan: this._fb.control(pluginTemplate.plan, Validators.required),
placements: this._fb.array(pluginTemplate.placements),
settings:this._fb.array([]),
object: this._fb.group(pluginTemplate.object)
object: this._fb.group(pluginTemplate.object?pluginTemplate.object:{})
});
this.templateForm.get('portalType').disable();
for (let i = 0; i < pluginTemplate.pages.length; i++) {
@ -225,13 +231,13 @@ export class PluginTemplatesComponent implements OnInit {
_id: this._fb.control(null),
name: this._fb.control('', Validators.required),
code: this._fb.control('', Validators.required),
plan: this._fb.control('', Validators.required),
plan: this._fb.control('starter', Validators.required),
description: this._fb.control(''),
pages: this.pagesCtrl,
portalType: this._fb.control('community', Validators.required),
placements: this._fb.array([]),
settings:this._fb.array([]),
object: this._fb.control(null)
object: this._fb.control({})
});
// this.addNewAttr();
this.modalOpen("Create template", "Create");
@ -383,4 +389,7 @@ export class PluginTemplatesComponent implements OnInit {
this.templateForm.get("object").setValue(object);
this.templateForm.markAsDirty();
}
public getPagesByPortal(portal) {
return this.allPages.filter(option => option.value.portalType == portal);
}
}

View File

@ -7,6 +7,7 @@ export class PluginTemplate{
description: string;
image: string;
pages: string[];
plan: "starter" | "extended";
placements: string[];
portalType: string;
settings: {};