Skip to content

Commit

Permalink
add generate document action configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
floris-thijssen-ritense committed Oct 10, 2024
1 parent c99c5c9 commit 3ee39f2
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ritense.valtimo.xential.model

data class GenerateDocumentProperties(
val templateId: String,
val fileFormat: FileFormat,
val documentId: String,
val templateData: Map<String, String>
)

enum class FileFormat {
DOCX, HTML, PDF, XML
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package com.ritense.valtimo.xential.plugin

import com.ritense.plugin.annotation.Plugin
import com.ritense.plugin.annotation.PluginAction
import com.ritense.plugin.annotation.PluginProperty
import com.ritense.processlink.domain.ActivityTypeWithEventName
import com.ritense.valtimo.xential.model.GenerateDocumentProperties
import org.camunda.bpm.engine.delegate.DelegateExecution

@Plugin(
key = "xential",
Expand All @@ -30,4 +34,14 @@ class XentialPlugin(
@PluginProperty(key = "clientId", secret = false)
private lateinit var clientId: String

@PluginAction(
key = "generate-document",
title = "Generate document",
description = "Generate a document using xential.",
activityTypes = [ActivityTypeWithEventName.SERVICE_TASK_START]
)
fun generateDocument(execution: DelegateExecution, generateDocumentProperties: GenerateDocumentProperties) {
println("$clientId, $generateDocumentProperties")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<v-form
(valueChange)="formValueChange($event)"
*ngIf="{
disabled: disabled$ | async,
prefill: prefillConfiguration$ ? (prefillConfiguration$ | async) : null,
fileFormats: fileFormats$ | async,
} as obs"
>
<v-input
name="templateId"
[title]="'templateId' | pluginTranslate: pluginId | async"
[margin]="true"
[defaultValue]="obs.prefill?.templateId"
[disabled]="obs.disabled"
[required]="true"
/>
<v-select
name="fileFormat"
[title]="'fileFormat' | pluginTranslate: pluginId | async"
[margin]="true"
[defaultSelectionId]="obs.prefill?.fileFormat"
[disabled]="obs.disabled"
[required]="true"
[items]="obs.fileFormats"
/>
<v-input
name="documentId"
[title]="'documentId' | pluginTranslate: pluginId | async"
[margin]="true"
[defaultValue]="obs.prefill?.documentId"
[disabled]="obs.disabled"
[required]="true"
/>
<valtimo-carbon-multi-input
name="templateData"
[title]="'templateData' | pluginTranslate: pluginId | async"
type="keyValue"
[disabled]="obs.disabled"
[defaultValues]="obs.prefill?.templateData"
[margin]="true"
[required]="false"
></valtimo-carbon-multi-input>
</v-form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import {FunctionConfigurationComponent} from '@valtimo/plugin';
import {BehaviorSubject, combineLatest, Observable, Subscription, take} from 'rxjs';
import {FileFormat, GenerateDocumentConfig} from "../../models";
import {SelectItem} from "@valtimo/components";

@Component({
selector: 'xential-generate-document-configuration',
templateUrl: './generate-document-configuration.component.html'
})
export class GenerateDocumentConfigurationComponent implements FunctionConfigurationComponent, OnInit, OnDestroy {
@Input() save$: Observable<void>;
@Input() disabled$: Observable<boolean>;
@Input() pluginId: string;
@Input() prefillConfiguration$: Observable<GenerateDocumentConfig>;
@Output() valid: EventEmitter<boolean> = new EventEmitter<boolean>();
@Output() configuration: EventEmitter<GenerateDocumentConfig> =
new EventEmitter<GenerateDocumentConfig>();

public fileFormats$ = new BehaviorSubject<SelectItem[]>(
['DOCX', 'HTML', 'PDF', 'XML']
.map(format => {
return {
id: format,
text: format
}
})
);

private saveSubscription!: Subscription;

private readonly formValue$ = new BehaviorSubject<GenerateDocumentConfig | null>(null);
private readonly valid$ = new BehaviorSubject<boolean>(false);

ngOnInit(): void {
this.openSaveSubscription();
}

ngOnDestroy() {
this.saveSubscription?.unsubscribe();
}

formValueChange(formValue: GenerateDocumentConfig): void {
this.formValue$.next(formValue);
this.handleValid(formValue);
}

private handleValid(formValue: GenerateDocumentConfig): void {
const valid = !!(
formValue.templateId &&
formValue.documentId &&
formValue.fileFormat &&
!formValue.templateData.find((entry) => !(entry.key && entry.value))
);

this.valid$.next(valid);
this.valid.emit(valid);
}

private openSaveSubscription(): void {
this.saveSubscription = this.save$?.subscribe(save => {
combineLatest([this.formValue$, this.valid$])
.pipe(take(1))
.subscribe(([formValue, valid]) => {
if (valid) {
this.configuration.emit(formValue);
}
});
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import {PluginConfigurationComponent, PluginConfigurationData} from '@valtimo/plugin';
import {BehaviorSubject, combineLatest, map, Observable, Subscription, take} from 'rxjs';
import {BehaviorSubject, combineLatest, Observable, Subscription, take} from 'rxjs';
import {XentialConfig} from '../../models';
import {PluginManagementService, PluginTranslationService} from '@valtimo/plugin';
import {TranslateService} from '@ngx-translate/core';

@Component({
selector: 'valtimo-xential-configuration',
templateUrl: './xential-configuration.component.html',
styleUrls: ['./xential-configuration.component.scss'],
})
export class XentialConfigurationComponent
implements PluginConfigurationComponent, OnInit, OnDestroy
Expand All @@ -37,9 +34,6 @@ export class XentialConfigurationComponent
@Output() configuration: EventEmitter<PluginConfigurationData> = new EventEmitter<PluginConfigurationData>();

constructor(
private readonly pluginManagementService: PluginManagementService,
private readonly translateService: TranslateService,
private readonly pluginTranslationService: PluginTranslationService
) {}

private saveSubscription!: Subscription;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface GenerateDocumentConfig {
templateId: string;
fileFormat: FileFormat;
documentId: string;
templateData: Array<{key: string; value: string}>
}

type FileFormat = 'DOCX' | 'PDF' | 'XML' | 'HTML';

export {GenerateDocumentConfig, FileFormat}
1 change: 1 addition & 0 deletions frontend/projects/valtimo/xential/src/lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

export * from './config';
export * from './generate-document-config'
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ import {NgModule} from '@angular/core';
import {XentialConfigurationComponent} from './components/xential-configuration/xential-configuration.component';
import {CommonModule} from '@angular/common';
import {PluginTranslatePipeModule} from '@valtimo/plugin';
import {FormModule, InputModule} from '@valtimo/components';
import {CarbonMultiInputModule, FormModule, InputModule, SelectModule} from '@valtimo/components';
import {
GenerateDocumentConfigurationComponent
} from "./components/generate-document-configuration/generate-document-configuration.component";
import {DropdownModule} from "carbon-components-angular";

@NgModule({
declarations: [
XentialConfigurationComponent,
GenerateDocumentConfigurationComponent,
],
imports: [CommonModule, PluginTranslatePipeModule, FormModule, InputModule],
imports: [CommonModule, PluginTranslatePipeModule, FormModule, InputModule, SelectModule, DropdownModule, CarbonMultiInputModule],
exports: [
XentialConfigurationComponent,
GenerateDocumentConfigurationComponent,
],
})
export class XentialPluginModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,50 @@
import {PluginSpecification} from '@valtimo/plugin';
import {XentialConfigurationComponent} from './components/xential-configuration/xential-configuration.component';
import {XENTIAL_PLUGIN_LOGO_BASE64} from './assets';
import {
GenerateDocumentConfigurationComponent
} from "./components/generate-document-configuration/generate-document-configuration.component";

const XentialPluginSpecification: PluginSpecification = {
pluginId: 'xential',
pluginConfigurationComponent: XentialConfigurationComponent,
pluginLogoBase64: XENTIAL_PLUGIN_LOGO_BASE64,
functionConfigurationComponents: {
'generate-document': GenerateDocumentConfigurationComponent
},
pluginTranslations: {
nl: {
title: 'Xential',
description: 'Xential plugin',
configurationTitle: 'Configuratie naam',
clientId: 'Client ID',
'generate-document': 'Genereer document',
templateId: 'Template ID',
fileFormat: 'Bestandsformaat',
documentId: 'Document kenmerk',
templateData: 'Sjabloon vuldata',
},
en: {
title: 'Xential',
description: 'Xential plugin',
configurationTitle: 'Configuration name',
clientId: 'Client ID',
'generate-document': 'Generate document',
templateId: 'Sjabloon ID',
fileFormat: 'File format',
documentId: 'Document ID',
templateData: 'Template data',
},
de: {
title: 'Xential',
description: 'Xential plugin',
configurationTitle: 'Konfigurationsname',
clientId: 'Client ID',
'generate-document': 'Dokument generieren',
templateId: 'Vorlage ID',
fileFormat: 'Dateiformat',
documentId: 'Dokument-ID',
templateData: 'Vorlagendaten',
},
},
};
Expand Down

0 comments on commit 3ee39f2

Please sign in to comment.