diff --git a/src/app/components/components.module.ts b/src/app/components/components.module.ts
index 1220ee4..1b137c3 100644
--- a/src/app/components/components.module.ts
+++ b/src/app/components/components.module.ts
@@ -44,6 +44,7 @@ import {PageLinkRendererComponent} from './editor/database/renderers/page-link-r
import {PageLinkEditorComponent} from './editor/database/editors/page-link/page-link-editor.component';
import {FormInputComponent} from './nodes/form-input/form-input.component';
import {FormInputOptionsComponent} from './nodes/form-input/options/form-input-options.component';
+import {DatabaseLinkComponent} from './editor/forms/database-link.component';
@NgModule({
declarations: [
@@ -81,6 +82,7 @@ import {FormInputOptionsComponent} from './nodes/form-input/options/form-input-o
PageLinkEditorComponent,
FormInputComponent,
FormInputOptionsComponent,
+ DatabaseLinkComponent,
],
imports: [
CommonModule,
@@ -131,6 +133,7 @@ import {FormInputOptionsComponent} from './nodes/form-input/options/form-input-o
PageLinkEditorComponent,
FormInputComponent,
FormInputOptionsComponent,
+ DatabaseLinkComponent,
],
exports: [
NodePickerComponent,
@@ -167,6 +170,7 @@ import {FormInputOptionsComponent} from './nodes/form-input/options/form-input-o
PageLinkEditorComponent,
FormInputComponent,
FormInputOptionsComponent,
+ DatabaseLinkComponent,
]
})
export class ComponentsModule {}
diff --git a/src/app/components/editor/forms/database-link.component.html b/src/app/components/editor/forms/database-link.component.html
new file mode 100644
index 0000000..0e0ca90
--- /dev/null
+++ b/src/app/components/editor/forms/database-link.component.html
@@ -0,0 +1,92 @@
+
+
+
+
+
+ Destination Database
+
+
+ {{ port.name }}
+
+
+
+
+
+
+
+ Form-to-Database Mapping
+ In order for the form to save properly, define a mapping of which form fields should be stored in which database fields.
+
+
+
+
+
+ Form Field (Source)
+
+
+
+
+
+ Database Column (Destination)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/app/components/editor/forms/database-link.component.scss b/src/app/components/editor/forms/database-link.component.scss
new file mode 100644
index 0000000..d2ad0ea
--- /dev/null
+++ b/src/app/components/editor/forms/database-link.component.scss
@@ -0,0 +1,35 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+
+ .header {
+ background: lightgrey;
+ display: flex;
+ flex-direction: row;
+
+ .title {
+ flex: 1;
+ padding: 10px;
+ font-size: 1.2em;
+ }
+
+ .close {
+ padding: 10px 15px;
+ background: #ff6666;
+ color: white;
+ }
+
+ .revert {
+ color: red;
+ background: #eaeaea;
+ }
+ }
+
+ .contents {
+ height: 100%;
+ overflow-y: hidden;
+ display: flex;
+ flex-direction: column;
+ }
+}
\ No newline at end of file
diff --git a/src/app/components/editor/forms/database-link.component.ts b/src/app/components/editor/forms/database-link.component.ts
new file mode 100644
index 0000000..0a1b022
--- /dev/null
+++ b/src/app/components/editor/forms/database-link.component.ts
@@ -0,0 +1,106 @@
+import {Component, Input, OnInit} from '@angular/core';
+import {AlertController, ModalController} from '@ionic/angular';
+import {EditorService} from '../../../service/editor.service';
+import {debug} from '../../../utility';
+import {NodeTypeIcons} from '../../../structures/node-types';
+import {Database, DatabaseColumn} from '../../../structures/db-api';
+import {DbApiService} from '../../../service/db-api.service';
+import HostRecord from '../../../structures/HostRecord';
+
+export interface FormDatabaseMap {
+ formNodeId?: string;
+ databaseColumnId?: string;
+
+ formNode?: any;
+ databaseColumn?: DatabaseColumn;
+}
+
+@Component({
+ selector: 'noded-form-database-link',
+ templateUrl: './database-link.component.html',
+ styleUrls: ['./database-link.component.scss'],
+})
+export class DatabaseLinkComponent implements OnInit {
+ @Input() pageId: string;
+ @Input() editorUUID: string;
+
+ public readonly typeIcons = NodeTypeIcons;
+ public databases: Database[] = [];
+ public selectedDatabase?: Database;
+ public selectedDatabaseColumns: DatabaseColumn[] = [];
+ public mapping: FormDatabaseMap[] = [];
+ public formFields: any[] = [];
+
+ constructor(
+ protected alerts: AlertController,
+ protected modals: ModalController,
+ protected editorService: EditorService,
+ protected dbApi: DbApiService,
+ ) {}
+
+ async ngOnInit() {
+ debug('Database link component', this);
+ this.editorService = this.editorService.getEditor(this.editorUUID);
+
+ this.databases = await this.dbApi.getDatabases();
+
+ this.formFields = this.editorService.immutableNodes
+ .filter(x => x.isForm())
+ .map(x => {
+ const data = {...x.AdditionalData};
+ data.NodeId = x.UUID;
+ return data;
+ });
+
+ const meta = this.editorService.metadata;
+ if ( meta?.formDatabaseId ) {
+ this.selectedDatabase = this.databases.find(x => x.uuid === meta.formDatabaseId);
+ await this.onDatabaseChange();
+ }
+
+ if ( Array.isArray(meta?.formMapping) ) {
+ this.mapping = meta.formMapping.map(x => {
+ return {
+ formNode: this.formFields.find(field => field.NodeId === x.formNodeId),
+ databaseColumn: this.selectedDatabaseColumns.find(column => column.uuid === x.databaseColumnId),
+ };
+ });
+ }
+ }
+
+ onAddMappingClick(event) {
+ this.mapping.push({} as FormDatabaseMap);
+ }
+
+ async onDatabaseChange() {
+ this.mapping = [];
+ this.selectedDatabaseColumns = await this.selectedDatabase.columns();
+ }
+
+ onMappingDelete(item) {
+ this.mapping = this.mapping.filter(x => x !== item);
+ }
+
+ dismiss(save = false) {
+ if ( save ) {
+ const merge = {
+ formDatabaseId: this.selectedDatabase?.uuid,
+ formMapping: this.mapping.map(x => {
+ return {
+ formNodeId: x.formNode?.NodeId || x.formNodeId,
+ databaseColumnId: x.databaseColumn?.uuid || x.databaseColumnId,
+ };
+ }),
+ };
+
+ this.editorService.metadata = {
+ ...this.editorService.metadata,
+ ...merge,
+ };
+
+ this.editorService.triggerSave();
+ }
+
+ this.modals.dismiss();
+ }
+}
diff --git a/src/app/pages/editor/editor.page.html b/src/app/pages/editor/editor.page.html
index dacf9a0..3321da4 100644
--- a/src/app/pages/editor/editor.page.html
+++ b/src/app/pages/editor/editor.page.html
@@ -27,7 +27,7 @@
{{ (editorService.isSaving || editorService.willSave) ? 'Saving...' : 'Saved!' }}