From 034b8e961f9e2fae0ee730bd1580a58f8704eef6 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Wed, 20 Dec 2023 18:48:01 +0200 Subject: [PATCH] b --- backend/files/system/sql/databases.get.hl | 131 +++++++++--------- .../codemirror-sql-formly.component.ts | 48 ++++--- .../components/codemirror-sql-formly.scss | 14 ++ .../parametrise-action-dialog.component.scss | 4 + 4 files changed, 112 insertions(+), 85 deletions(-) diff --git a/backend/files/system/sql/databases.get.hl b/backend/files/system/sql/databases.get.hl index 230f9b29c6..a81ebfbe90 100644 --- a/backend/files/system/sql/databases.get.hl +++ b/backend/files/system/sql/databases.get.hl @@ -77,90 +77,85 @@ cache.try-get:x:@strings.concat // Iterating through databases. for-each:x:@.result/* - try - // Retrieving tables. + // Retrieving tables. + strings.concat + .:magic.db. + get-value:x:@.databaseType + .:.tables + unwrap:x:+/* + signal:x:@strings.concat + connection-string:x:@.connection-string + database:x:@.dp/#/*/name + for-each:x:@signal/* + + // Retrieving columns. + unwrap:x:+/*/*/* + add:x:@for-each/@.dp/#/*/tables + . + . + name:x:@.dp/#/*/table + columns strings.concat .:magic.db. get-value:x:@.databaseType - .:.tables + .:.columns unwrap:x:+/* signal:x:@strings.concat connection-string:x:@.connection-string - database:x:@.dp/#/*/name + database:x:@for-each/@.dp/#/*/name + table:x:@.dp/#/*/table for-each:x:@signal/* - - // Retrieving columns. unwrap:x:+/*/*/* - add:x:@for-each/@.dp/#/*/tables + add:x:@for-each/@for-each/@.dp/#/*/tables/0/-/*/columns . . - name:x:@.dp/#/*/table - columns - strings.concat - .:magic.db. - get-value:x:@.databaseType - .:.columns - unwrap:x:+/* - signal:x:@strings.concat - connection-string:x:@.connection-string - database:x:@for-each/@.dp/#/*/name - table:x:@.dp/#/*/table - for-each:x:@signal/* - unwrap:x:+/*/*/* - add:x:@for-each/@for-each/@.dp/#/*/tables/0/-/*/columns - . - . - name:x:@.dp/#/*/name - db:x:@.dp/#/*/db - nullable:x:@.dp/#/*/nullable - primary:x:@.dp/#/*/primary - automatic:x:@.dp/#/*/automatic - hl:x:@.dp/#/*/hl - - // Retrieving foreign keys. - add:x:@for-each/@for-each/@.dp/#/*/tables/0/- + name:x:@.dp/#/*/name + db:x:@.dp/#/*/db + nullable:x:@.dp/#/*/nullable + primary:x:@.dp/#/*/primary + automatic:x:@.dp/#/*/automatic + hl:x:@.dp/#/*/hl + + // Retrieving foreign keys. + add:x:@for-each/@for-each/@.dp/#/*/tables/0/- + . + foreign_keys + strings.concat + .:magic.db. + get-value:x:@.databaseType + .:.foreign_keys + unwrap:x:+/* + signal:x:@strings.concat + connection-string:x:@.connection-string + database:x:@for-each/@for-each/@.dp/#/*/name + table:x:@.dp/#/*/table + for-each:x:@signal/* + add:x:+/*/* + get-nodes:x:@.dp/#/* + add:x:@for-each/@for-each/@for-each/@.dp/#/*/tables/0/-/*/foreign_keys . - foreign_keys - strings.concat - .:magic.db. - get-value:x:@.databaseType - .:.foreign_keys - unwrap:x:+/* - signal:x:@strings.concat - connection-string:x:@.connection-string - database:x:@for-each/@for-each/@.dp/#/*/name - table:x:@.dp/#/*/table - for-each:x:@signal/* - add:x:+/*/* - get-nodes:x:@.dp/#/* - add:x:@for-each/@for-each/@for-each/@.dp/#/*/tables/0/-/*/foreign_keys . - . - // Retrieving indexes. - add:x:@for-each/@for-each/@for-each/@.dp/#/*/tables/0/- + // Retrieving indexes. + add:x:@for-each/@for-each/@for-each/@.dp/#/*/tables/0/- + . + indexes + strings.concat + .:magic.db. + get-value:x:@.databaseType + .:.indexes + unwrap:x:+/* + signal:x:@strings.concat + connection-string:x:@.connection-string + database:x:@for-each/@for-each/@for-each/@.dp/#/*/name + table:x:@.dp/#/*/table + for-each:x:@signal/* + add:x:+/*/* + get-nodes:x:@.dp/#/* + add:x:@for-each/@for-each/@for-each/@for-each/@.dp/#/*/tables/0/-/*/indexes . - indexes - strings.concat - .:magic.db. - get-value:x:@.databaseType - .:.indexes - unwrap:x:+/* - signal:x:@strings.concat - connection-string:x:@.connection-string - database:x:@for-each/@for-each/@for-each/@.dp/#/*/name - table:x:@.dp/#/*/table - for-each:x:@signal/* - add:x:+/*/* - get-nodes:x:@.dp/#/* - add:x:@for-each/@for-each/@for-each/@for-each/@.dp/#/*/tables/0/-/*/indexes . - . - .catch - - // Silently ignoring, after logging, probably don't have access to database. - log.info:x:@.arguments/*/message // Returning database to caller. lambda2hyper:x:@.result/* diff --git a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.component.ts b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.component.ts index b0e41a9c78..e6f9ea7fb0 100644 --- a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.component.ts +++ b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.component.ts @@ -7,6 +7,7 @@ import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; import { CodemirrorComponent } from '@ctrl/ngx-codemirror'; import { FieldType, FieldTypeConfig } from '@ngx-formly/core'; +import { debounceTime, distinctUntilChanged, tap } from 'rxjs'; import { Databases } from 'src/app/models/databases.model'; import { CodemirrorActionsService } from 'src/app/services/codemirror-actions.service'; import { GeneralService } from 'src/app/services/general.service'; @@ -17,7 +18,7 @@ import { SqlService } from 'src/app/services/sql.service'; */ @Component({ selector: 'app-codemirror-formly', - template: ``, + template: `{{connected ? 'check_circle' : 'report_problem'}}`, styleUrls: ['./codemirror-sql-formly.scss'] }) export class CodemirrorSqlFormlyComponent extends FieldType implements OnInit { @@ -26,6 +27,7 @@ export class CodemirrorSqlFormlyComponent extends FieldType imp @ViewChild('editor') private editor: CodemirrorComponent; cmOptions: any = null; ready: boolean = false; + connected: boolean = false; constructor( private sqlService: SqlService, @@ -72,16 +74,18 @@ export class CodemirrorSqlFormlyComponent extends FieldType imp this.getDatabaseTables(); } }); - this.form.controls['connection-string'].valueChanges.subscribe({ - next : () => { - this.getDatabaseTables(); - } - }); - this.form.controls['database'].valueChanges.subscribe({ - next : () => { - this.databaseChanged(); - } - }); + this.form.controls['connection-string'].valueChanges.pipe( + debounceTime(400), + distinctUntilChanged(), + tap(() => { + this.getDatabaseTables(); + })).subscribe(); + this.form.controls['database'].valueChanges.pipe( + debounceTime(400), + distinctUntilChanged(), + tap(() => { + this.databaseChanged(); + })).subscribe(); } }, 1); }, 250); @@ -109,13 +113,16 @@ export class CodemirrorSqlFormlyComponent extends FieldType imp this.generalService.hideLoading(); this.databases = result; + this.connected = true; + this.cdn.detectChanges(); this.databaseChanged(); }, error: () => { this.generalService.hideLoading(); - this.generalService.showFeedback('Not a valid database-type/connection-string combination', 'errorMessage'); + this.connected = false; + this.cdn.detectChanges(); } }); } @@ -123,9 +130,16 @@ export class CodemirrorSqlFormlyComponent extends FieldType imp private databaseChanged() { let hintTables = (this.databases.databases || []).find((db: any) => db.name === this.model['database'])?.tables || []; - const hints = Object.fromEntries(hintTables.map((x: any) => [x.name, x.columns.map((y: any) => y.name)])); - this.cmOptions.hintOptions = { - tables: hints, - }; -} + if (hintTables.length === 0) { + this.connected = false; + this.cdn.detectChanges(); + } else { + const hints = Object.fromEntries(hintTables.map((x: any) => [x.name, x.columns.map((y: any) => y.name)])); + this.cmOptions.hintOptions = { + tables: hints, + }; + this.connected = true; + this.cdn.detectChanges(); + } + } } diff --git a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.scss b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.scss index 2f029b72a3..bc7fe5d6de 100644 --- a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.scss +++ b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/components/codemirror-sql-formly.scss @@ -2,3 +2,17 @@ ::ng-deep .sql-formly-editor .CodeMirror { max-height: 150px; } +mat-icon { + position: absolute; + z-index: 100000; + position: absolute; + right: -5px; + top: 18px; + font-size: 1rem; +} +mat-icon.connected { + color: #a0ffa0; +} +mat-icon.disconnected { + color: #ffa0a0; +} diff --git a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/parametrise-action-dialog.component.scss b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/parametrise-action-dialog.component.scss index e69de29bb2..649772a568 100644 --- a/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/parametrise-action-dialog.component.scss +++ b/frontend/src/app/components/protected/create/hyper-ide/components/parametrise-action-dialog/parametrise-action-dialog.component.scss @@ -0,0 +1,4 @@ + +::ng-deep app-codemirror-formly { + position: relative; +}