Skip to content

Commit 4249443

Browse files
trKhaledZitrone44
andauthored
1482 web fronted for sql playground sharing (#1523)
* added button and its functionality; Service still needs to be updated * changed uri display to dialog * changed service function * changed service path * refactoring --------- Co-authored-by: Jonas Kuche <Zitrone44@users.noreply.github.com>
1 parent cca7e3c commit 4249443

File tree

9 files changed

+137
-4
lines changed

9 files changed

+137
-4
lines changed

modules/fbs-core/web/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import { HighlightedInputComponent } from "./page-components/sql-playground/sql-
108108
import "mathlive";
109109
import "@cortex-js/compute-engine";
110110
import { MathInputComponent } from "./tool-components/math-input/math-input.component";
111+
import { SharePlaygroundLinkDialogComponent } from "./dialogs/share-playground-link-dialog/share-playground-link-dialog.component";
111112
import { FbsModellingComponent } from "./page-components/fbs-modelling/fbs-modelling.component";
112113
import { I18NextModule } from "angular-i18next";
113114
import { I18N_PROVIDERS } from "./util/i18n";
@@ -213,6 +214,7 @@ export const httpInterceptorProviders = [
213214
ExportTasksDialogComponent,
214215
HighlightedInputComponent,
215216
MathInputComponent,
217+
SharePlaygroundLinkDialogComponent,
216218
FbsModellingComponent,
217219
LanguageMenuComponent,
218220
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="container">
2+
<div matDialogTitle>Temporäre Datenbank URI</div>
3+
<mat-dialog-content style="max-height: 100%; overflow: hidden">
4+
<mat-card-content class="content">
5+
<mat-label>
6+
<h3>{{ data.message }}</h3>
7+
</mat-label>
8+
<div class="uri">
9+
<mat-label
10+
><i>{{ data.uri }}</i></mat-label
11+
>
12+
<button mat-icon-button (click)="copyURI()" matTooltip="URI kopieren">
13+
<mat-icon>content_copy</mat-icon>
14+
</button>
15+
</div>
16+
</mat-card-content>
17+
</mat-dialog-content>
18+
<mat-dialog-actions class="actions">
19+
<button mat-flat-button color="warn" (click)="closeDialog()">
20+
Abbrechen
21+
</button>
22+
</mat-dialog-actions>
23+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.container {
2+
height: 100%;
3+
}
4+
5+
.actions {
6+
display: flex;
7+
justify-content: flex-end;
8+
button {
9+
margin-left: 16px;
10+
}
11+
}
12+
13+
.content {
14+
display: block;
15+
margin-top: 10px;
16+
}
17+
18+
.uri{
19+
margin-top: 30px;
20+
button {
21+
margin-left: 20px;
22+
}
23+
}
24+
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, Inject } from "@angular/core";
2+
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
3+
import { MatSnackBar } from "@angular/material/snack-bar";
4+
5+
@Component({
6+
selector: "app-db-uri-link-dialog",
7+
templateUrl: "./share-playground-link-dialog.component.html",
8+
styleUrls: ["./share-playground-link-dialog.component.scss"],
9+
})
10+
export class SharePlaygroundLinkDialogComponent {
11+
constructor(
12+
@Inject(MAT_DIALOG_DATA)
13+
public data: {
14+
message: string;
15+
uri: string;
16+
},
17+
public dialogRef: MatDialogRef<SharePlaygroundLinkDialogComponent>,
18+
private snackbar: MatSnackBar
19+
) {}
20+
21+
copyURI() {
22+
navigator.clipboard.writeText(this.data.uri).then(
23+
() => {
24+
this.snackbar.open("URI erfolgreich kopiert!", "Ok", {
25+
duration: 3000,
26+
});
27+
},
28+
(error) => {
29+
console.error("URI konnte nicht kopiert werden: ", error);
30+
this.snackbar.dismiss();
31+
}
32+
);
33+
}
34+
35+
closeDialog() {
36+
this.dialogRef.close({ success: false });
37+
}
38+
}

modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/db-control-db-overview/db-control-db-overview.component.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,14 @@
5757
| i18nextEager
5858
}}
5959
</button>
60+
61+
<button
62+
mat-raised-button
63+
class="url-btn"
64+
(click)="getTempURI()"
65+
[disabled]="collaborativeMode"
66+
>
67+
Verbindungs-URL anfordern
68+
</button>
6069
</div>
6170
</div>

modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/db-control-db-overview/db-control-db-overview.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ mat-form-field {
3131
grid-column: 1 / 3;
3232
}
3333

34+
.url-btn {
35+
color: white;
36+
background-color: rgba(25, 105, 243, 0.792);
37+
grid-column: 1 / 3;
38+
}
39+
3440
button {
3541
height: 30px;
3642
display: flex;

modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/db-control-db-overview/db-control-db-overview.component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { JWTToken } from "src/app/model/JWTToken";
88
import { TextConfirmDialogComponent } from "../../../../dialogs/text-confirm-dialog/text-confirm-dialog.component";
99
import { NewDbDialogComponent } from "../../../../dialogs/new-db-dialog/new-db-dialog.component";
1010
import { MatDialog } from "@angular/material/dialog";
11+
import { SharePlaygroundLinkDialogComponent } from "src/app/dialogs/share-playground-link-dialog/share-playground-link-dialog.component";
1112

1213
@Component({
1314
selector: "app-db-control-db-overview",
@@ -31,6 +32,7 @@ export class DbControlDbOverviewComponent implements OnInit {
3132
selectedDb: number = 0;
3233
token: JWTToken = this.authService.getToken();
3334
pending: boolean = false;
35+
dbURI: string = "";
3436

3537
ngOnInit(): void {
3638
this.sqlPlaygroundService.getDatabases(this.token.id).subscribe(
@@ -180,6 +182,22 @@ export class DbControlDbOverviewComponent implements OnInit {
180182
return dialogRef.afterClosed();
181183
}
182184

185+
getTempURI() {
186+
const selectedDb = this.dbs.find((db) => db.id == this.selectedDb);
187+
this.sqlPlaygroundService
188+
.getSharePlaygroundURI(this.token.id, selectedDb.id)
189+
.subscribe((uri) => (this.dbURI = uri));
190+
this.dialog.open(SharePlaygroundLinkDialogComponent, {
191+
height: "auto",
192+
width: "50%",
193+
autoFocus: false,
194+
data: {
195+
message: `Der URI-Link zu deiner Datenbank \" ${selectedDb.name} \" ist nur für 24 Stunden verfügbar!\n`,
196+
uri: this.dbURI,
197+
},
198+
});
199+
}
200+
183201
addDb() {
184202
this.dialog
185203
.open(NewDbDialogComponent, {

modules/fbs-core/web/src/app/page-components/sql-playground/sql-playground.component.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
.db-grid {
3232
width: 100%;
3333
grid-row-start: 1;
34-
grid-row-end: 4;
34+
grid-row-end: 5;
3535
grid-column-start: 8;
3636
grid-column-end: 11;
3737
padding: none;
38+
margin-bottom: 35px;
3839
}
3940

4041
.db-schema-grid {
4142
width: 100%;
42-
margin-top: 20px;
43-
grid-row-start: 4;
43+
grid-row-start: 5;
4444
grid-row-end: 9;
4545
grid-column-start: 8;
4646
grid-column-end: 11;

modules/fbs-core/web/src/app/service/sql-playground.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient } from "@angular/common/http";
22
import { Injectable } from "@angular/core";
3-
import { Observable } from "rxjs";
3+
import { Observable, of } from "rxjs";
44
import { Constraint } from "../model/sql_playground/Constraint";
55
import { Database } from "../model/sql_playground/Database";
66
import { Routine } from "../model/sql_playground/Routine";
@@ -9,6 +9,7 @@ import { SQLResponse } from "../model/sql_playground/SQLResponse";
99
import { Table } from "../model/sql_playground/Table";
1010
import { Trigger } from "../model/sql_playground/Trigger";
1111
import { View } from "../model/sql_playground/View";
12+
import { map } from "rxjs/operators";
1213

1314
@Injectable({
1415
providedIn: "root",
@@ -79,6 +80,17 @@ export class SqlPlaygroundService {
7980
);
8081
}
8182

83+
/**
84+
* Get Database Temp URI
85+
* @return the temporary database URI
86+
*/
87+
getSharePlaygroundURI(uid: number, dbId: number): Observable<string> {
88+
return this.http.post<any>(
89+
`/api/v2/playground/${uid}/databases/${dbId}/dump`,
90+
{}
91+
);
92+
}
93+
8294
/**
8395
* get the result of a query
8496
* @param uid User id

0 commit comments

Comments
 (0)