-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: template for message preview and download (wip)
- Loading branch information
1 parent
beb43ec
commit fedb894
Showing
9 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...s/identity/identity-details/download-message-dialog/download-message-dialog.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.container { | ||
max-width: 400px; | ||
} | ||
|
||
.preview-container { | ||
max-width: 800px; | ||
max-height: 700px; | ||
} |
36 changes: 36 additions & 0 deletions
36
.../identity/identity-details/download-message-dialog/download-message-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="container"> | ||
<div *ngIf="!preview"> | ||
<h2 mat-dialog-title>{{ header }}</h2> | ||
<mat-dialog-content> | ||
<div class="form-details" *ngIf="!loading"> | ||
<mat-form-field class="form-field"> | ||
<mat-label>Client Secret</mat-label> | ||
<input [type]="showSymetricKey ? 'text' : 'password'" [(ngModel)]="symetricKey" matInput /> | ||
<button matSuffix mat-icon-button (click)="toggleSymetricKeyVisibility()" style="cursor: pointer"> | ||
<mat-icon style="text-align: center">visibility</mat-icon> | ||
</button> | ||
<!-- <mat-hint>A Client Secret will be generated if this field is left blank.</mat-hint> --> | ||
</mat-form-field> | ||
</div> | ||
<div *ngIf="loading" class="loading"> | ||
<mat-progress-spinner color="primary" mode="indeterminate"> </mat-progress-spinner> | ||
</div> | ||
</mat-dialog-content> | ||
<mat-dialog-actions align="end"> | ||
<button mat-flat-button color="primary" (click)="previewMessage()" [disabled]="!isValid()">Preview</button> | ||
<button mat-flat-button mat-dialog-close>Cancel</button> | ||
</mat-dialog-actions> | ||
</div> | ||
<!-- [(ngModel)]="max" --> | ||
<!-- [(ngModel)]="client.clientSecret" --> | ||
</div> | ||
<div *ngIf="preview" class="preview-container"> | ||
<h2 mat-dialog-title>{{ header }}</h2> | ||
<mat-dialog-content> | ||
{{ message }} | ||
</mat-dialog-content> | ||
<mat-dialog-actions align="end"> | ||
<button mat-flat-button color="primary" (click)="downloadMessage()" [disabled]="!isValid()">Preview</button> | ||
<button mat-flat-button mat-dialog-close>Close</button> | ||
</mat-dialog-actions> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
...entity/identity-details/download-message-dialog/download-message-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { DownloadMessageDialogComponent } from "./download-message-dialog.component"; | ||
|
||
describe("DownloadMessageDialogComponent", function () { | ||
let component: DownloadMessageDialogComponent; | ||
let fixture: ComponentFixture<DownloadMessageDialogComponent>; | ||
|
||
beforeEach(async function () { | ||
await TestBed.configureTestingModule({ | ||
declarations: [DownloadMessageDialogComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DownloadMessageDialogComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", async function () { | ||
await expect(component).toBeTruthy(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
...as/identity/identity-details/download-message-dialog/download-message-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "app-download-message-dialog", | ||
templateUrl: "./download-message-dialog.component.html", | ||
styleUrl: "./download-message-dialog.component.css" | ||
}) | ||
export class DownloadMessageDialogComponent { | ||
public header: string; | ||
public symetricKey: string; | ||
public message: string; | ||
|
||
public loading: boolean; | ||
public showSymetricKey: boolean; | ||
public preview: boolean; | ||
|
||
public constructor() { | ||
this.header = "Download message"; | ||
this.loading = false; | ||
this.showSymetricKey = false; | ||
this.preview = false; | ||
this.symetricKey = ""; | ||
this.message = "This is a message that will be displayed when a correct symetric key is entered, and this message can be downloaded."; | ||
} | ||
|
||
public isValid(): boolean { | ||
// return this.metric !== undefined && this.period !== undefined && this.max !== null; | ||
return true; | ||
} | ||
|
||
public toggleSymetricKeyVisibility(): void { | ||
this.showSymetricKey = !this.showSymetricKey; | ||
} | ||
|
||
public previewMessage(): void { | ||
if (this.symetricKey === "test") { | ||
this.preview = true; | ||
} | ||
} | ||
|
||
public downloadMessage(): void { | ||
const message = btoa(this.message) | ||
const byteCharacters = atob(message); | ||
const byteArrays = []; | ||
|
||
for (let offset = 0; offset < byteCharacters.length; offset += 512) { | ||
const slice = byteCharacters.slice(offset, offset + 512); | ||
const byteNumbers = new Array(slice.length); | ||
for (let i = 0; i < slice.length; i++) { | ||
byteNumbers[i] = slice.charCodeAt(i); | ||
} | ||
const byteArray = new Uint8Array(byteNumbers); | ||
byteArrays.push(byteArray); | ||
} | ||
|
||
const blob = new Blob(byteArrays, { type: "application/pdf" }); | ||
const url = window.URL.createObjectURL(blob); | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.download = "file.pdf"; | ||
link.click(); | ||
window.URL.revokeObjectURL(url); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...entity/identity-details/identity-details-messages/identity-details-messages.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.container { | ||
min-width: 2400px; | ||
max-width: 2100px; | ||
min-height: 200px; | ||
overflow-x: auto; | ||
} | ||
|
||
.disabled-container { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters