Commit 159804b5 authored by Lukas Burgey's avatar Lukas Burgey

Handle when the user has not yet uploaded a key

parent eef0cde5
...@@ -24,6 +24,7 @@ import { CookieService } from 'ngx-cookie-service'; ...@@ -24,6 +24,7 @@ import { CookieService } from 'ngx-cookie-service';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { SnackBarService } from './snackbar.service'; import { SnackBarService } from './snackbar.service';
import { DialogService } from './dialog.service';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { MgmtComponent } from './mgmt/mgmt.component'; import { MgmtComponent } from './mgmt/mgmt.component';
...@@ -81,6 +82,7 @@ const routes = [ ...@@ -81,6 +82,7 @@ const routes = [
CookieService, CookieService,
UserService, UserService,
SnackBarService, SnackBarService,
DialogService,
JsonPipe, JsonPipe,
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
......
import { TestBed, inject } from '@angular/core/testing';
import { DialogService } from './dialog.service';
describe('DialogService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [DialogService]
});
});
it('should be created', inject([DialogService], (service: DialogService) => {
expect(service).toBeTruthy();
}));
});
import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ProfileComponent } from './profile/profile.component';
import { SshKeysComponent } from './ssh-keys/ssh-keys.component';
@Injectable()
export class DialogService {
profileDialog: MatDialogRef<any>;
sshKeysDialog: MatDialogRef<any>;
constructor(
public dialog: MatDialog,
) { }
public openProfile() {
this.profileDialog = this.dialog.open(
ProfileComponent,
{
width: '80%',
}
);
}
public openSshKeys() {
this.sshKeysDialog = this.dialog.open(
SshKeysComponent,
{
width: '80%',
}
);
}
}
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
<button mat-raised-button color="accent" (click)="userService.login()">Login</button> <button mat-raised-button color="accent" (click)="userService.login()">Login</button>
</span> </span>
<span *ngIf="userService.loggedIn"> <span *ngIf="userService.loggedIn">
<button mat-button mat-icon-button (click)="openSshKeys()"> <button mat-button mat-icon-button (click)="dialog.openSshKeys()">
<mat-icon>vpn_key</mat-icon> <mat-icon>vpn_key</mat-icon>
</button> </button>
<button mat-button (click)="openProfile()"> <button mat-button (click)="dialog.openProfile()">
{{ userService.user?.username }} {{ userService.user?.username }}
</button> </button>
<button mat-raised-button color="accent" (click)="userService.logout()">Logout</button> <button mat-raised-button color="accent" (click)="userService.logout()">Logout</button>
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ProfileComponent } from '../profile/profile.component'; import { DialogService } from '../dialog.service';
import { SshKeysComponent } from '../ssh-keys/ssh-keys.component';
import { UserService } from '../user.service'; import { UserService } from '../user.service';
@Component({ @Component({
...@@ -15,24 +13,6 @@ export class LoginComponent { ...@@ -15,24 +13,6 @@ export class LoginComponent {
constructor( constructor(
public userService: UserService, public userService: UserService,
public dialog: MatDialog, public dialog: DialogService,
) { } ) { }
public openProfile() {
this.profileDialog = this.dialog.open(
ProfileComponent,
{
width: '80%',
}
);
}
public openSshKeys() {
this.profileDialog = this.dialog.open(
SshKeysComponent,
{
width: '80%',
}
);
}
} }
...@@ -19,14 +19,19 @@ ...@@ -19,14 +19,19 @@
</ul> </ul>
<mat-action-row> <mat-action-row>
<span style="margin-right: 15px"> <div *ngIf="userService.user.ssh_keys.length > 0">
Deployed keys: <span style="margin-right: 15px">
</span><br/> Deployed keys:
<mat-checkbox *ngFor="let key of userService.user.ssh_keys" </span><br/>
style="margin-right: 10px" <mat-checkbox *ngFor="let key of userService.user.ssh_keys"
[checked]="isDeployed(key)" style="margin-right: 8px"
(change)="deploymentChange(key)"> [checked]="isDeployed(key)"
{{ key.name }} (change)="deploymentChange(key)">
</mat-checkbox> {{ key.name }}
</mat-checkbox>
</div>
<div *ngIf="userService.user.ssh_keys.length === 0">
<button mat-icon-button (click)="dialog.openSshKeys()"><mat-icon>vpn_key</mat-icon></button>
</div>
</mat-action-row> </mat-action-row>
</mat-expansion-panel> </mat-expansion-panel>
...@@ -2,6 +2,8 @@ import { Component, OnInit, Input } from '@angular/core'; ...@@ -2,6 +2,8 @@ import { Component, OnInit, Input } from '@angular/core';
import { MatCheckboxChange } from '@angular/material/checkbox'; import { MatCheckboxChange } from '@angular/material/checkbox';
import { UserService } from '../user.service'; import { UserService } from '../user.service';
import { DialogService } from '../dialog.service';
import { SshKeysComponent } from '../ssh-keys/ssh-keys.component';
@Component({ @Component({
selector: 'app-service', selector: 'app-service',
...@@ -13,6 +15,7 @@ export class ServiceComponent implements OnInit { ...@@ -13,6 +15,7 @@ export class ServiceComponent implements OnInit {
constructor( constructor(
public userService: UserService, public userService: UserService,
public dialog: DialogService,
) { ) {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment