diff --git a/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/model/GenerateDocumentProperties.kt b/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/model/GenerateDocumentProperties.kt new file mode 100644 index 0000000..6cefce8 --- /dev/null +++ b/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/model/GenerateDocumentProperties.kt @@ -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 +) + +enum class FileFormat { + DOCX, HTML, PDF, XML +} diff --git a/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/plugin/XentialPlugin.kt b/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/plugin/XentialPlugin.kt index 3c23dc3..2a7922c 100644 --- a/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/plugin/XentialPlugin.kt +++ b/backend/plugin/src/main/kotlin/com/ritense/valtimo/xential/plugin/XentialPlugin.kt @@ -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", @@ -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") + } + } diff --git a/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.html b/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.html new file mode 100644 index 0000000..068fed9 --- /dev/null +++ b/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.html @@ -0,0 +1,43 @@ + + + + + + diff --git a/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.ts b/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.ts new file mode 100644 index 0000000..7849826 --- /dev/null +++ b/frontend/projects/valtimo/xential/src/lib/components/generate-document-configuration/generate-document-configuration.component.ts @@ -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; + @Input() disabled$: Observable; + @Input() pluginId: string; + @Input() prefillConfiguration$: Observable; + @Output() valid: EventEmitter = new EventEmitter(); + @Output() configuration: EventEmitter = + new EventEmitter(); + + public fileFormats$ = new BehaviorSubject( + ['DOCX', 'HTML', 'PDF', 'XML'] + .map(format => { + return { + id: format, + text: format + } + }) + ); + + private saveSubscription!: Subscription; + + private readonly formValue$ = new BehaviorSubject(null); + private readonly valid$ = new BehaviorSubject(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); + } + }); + }); + } +} diff --git a/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.scss b/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.scss deleted file mode 100644 index 1be258c..0000000 --- a/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.scss +++ /dev/null @@ -1,15 +0,0 @@ -/*! - * Copyright 2015-2022 Ritense BV, the Netherlands. - * - * Licensed under EUPL, Version 1.2 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.ts b/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.ts index 39236e9..9447c80 100644 --- a/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.ts +++ b/frontend/projects/valtimo/xential/src/lib/components/xential-configuration/xential-configuration.component.ts @@ -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 @@ -37,9 +34,6 @@ export class XentialConfigurationComponent @Output() configuration: EventEmitter = new EventEmitter(); constructor( - private readonly pluginManagementService: PluginManagementService, - private readonly translateService: TranslateService, - private readonly pluginTranslationService: PluginTranslationService ) {} private saveSubscription!: Subscription; diff --git a/frontend/projects/valtimo/xential/src/lib/models/generate-document-config.ts b/frontend/projects/valtimo/xential/src/lib/models/generate-document-config.ts new file mode 100644 index 0000000..ed835b5 --- /dev/null +++ b/frontend/projects/valtimo/xential/src/lib/models/generate-document-config.ts @@ -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} diff --git a/frontend/projects/valtimo/xential/src/lib/models/index.ts b/frontend/projects/valtimo/xential/src/lib/models/index.ts index b0d57f7..af3a5ce 100644 --- a/frontend/projects/valtimo/xential/src/lib/models/index.ts +++ b/frontend/projects/valtimo/xential/src/lib/models/index.ts @@ -15,3 +15,4 @@ */ export * from './config'; +export * from './generate-document-config' diff --git a/frontend/projects/valtimo/xential/src/lib/xential-plugin-module.ts b/frontend/projects/valtimo/xential/src/lib/xential-plugin-module.ts index ae76a05..4552ff1 100644 --- a/frontend/projects/valtimo/xential/src/lib/xential-plugin-module.ts +++ b/frontend/projects/valtimo/xential/src/lib/xential-plugin-module.ts @@ -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 {} diff --git a/frontend/projects/valtimo/xential/src/lib/xential-plugin.specification.ts b/frontend/projects/valtimo/xential/src/lib/xential-plugin.specification.ts index 86ec3ab..30705c5 100644 --- a/frontend/projects/valtimo/xential/src/lib/xential-plugin.specification.ts +++ b/frontend/projects/valtimo/xential/src/lib/xential-plugin.specification.ts @@ -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', }, }, };