Skip to content

Commit e6ae138

Browse files
committed
Create ability to add project names
1 parent 6d154b6 commit e6ae138

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

webapp/src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import { TopicListComponent } from './components/topic-list/topic-list.component
3838
SubscriptionDetailsComponent,
3939
TopicDetailsComponent,
4040
NewTopicDialogComponent,
41-
NewSubscriptionDialogComponent
41+
NewSubscriptionDialogComponent,
42+
4243
],
4344
imports: [
4445
BrowserModule,

webapp/src/app/components/index/index.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h3>Select a Project from the list:</h3>
1111
{{project}}
1212
</button>
1313

14-
<button mat-stroked-button class="new-project">
14+
<button mat-stroked-button class="new-project" (click)="addNewProject()">
1515
<mat-icon>add_circle</mat-icon>
1616
Attach new project
1717
</button>

webapp/src/app/components/index/index.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { Observable } from 'rxjs';
2+
import { MatDialog } from '@angular/material/dialog';
3+
import { Observable, filter } from 'rxjs';
34
import { PubsubService } from 'src/app/services/pubsub.service';
5+
import { InputDialogComponent } from '../input-dialog/input-dialog.component';
46

57
@Component({
68
selector: 'app-index',
@@ -11,11 +13,22 @@ export class IndexComponent implements OnInit {
1113

1214
projectList$: Observable<string[]>
1315

14-
constructor(private pubsub: PubsubService) {
16+
constructor(private pubsub: PubsubService, private matDialog: MatDialog) {
1517
this.projectList$ = pubsub.projectList$
1618
}
1719

1820
ngOnInit(): void {
1921
}
2022

23+
addNewProject() {
24+
const ref = this.matDialog.open(InputDialogComponent)
25+
26+
ref.afterClosed()
27+
.pipe(filter(r => !!r))
28+
.subscribe((result: { project_id: string }) => {
29+
console.log(result)
30+
this.pubsub.attachProject(result.project_id)
31+
})
32+
}
33+
2134
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<mat-dialog-content>
2+
<mat-form-field appearance="outline" color="accent">
3+
<mat-label>Enter a value</mat-label>
4+
<input matInput type="text" autocomplete="off" [formControl]="input">
5+
</mat-form-field>
6+
</mat-dialog-content>
7+
<mat-dialog-actions>
8+
<button mat-raised-button [disabled]="input.invalid" (click)="save()">save</button>
9+
</mat-dialog-actions>

webapp/src/app/components/input-dialog/input-dialog.component.scss

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { InputDialogComponent } from './input-dialog.component';
4+
5+
describe('InputDialogComponent', () => {
6+
let component: InputDialogComponent;
7+
let fixture: ComponentFixture<InputDialogComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [InputDialogComponent]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(InputDialogComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component } from '@angular/core';
2+
import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
3+
import { MatButtonModule } from '@angular/material/button';
4+
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
5+
import { MatFormFieldModule } from '@angular/material/form-field';
6+
import { MatInputModule } from '@angular/material/input';
7+
8+
@Component({
9+
selector: 'app-input-dialog',
10+
standalone: true,
11+
imports: [MatDialogModule, MatButtonModule, MatInputModule, ReactiveFormsModule, MatFormFieldModule],
12+
templateUrl: './input-dialog.component.html',
13+
styleUrl: './input-dialog.component.scss'
14+
})
15+
export class InputDialogComponent {
16+
17+
input = new FormControl('', Validators.required)
18+
19+
constructor(private dialogRef: MatDialogRef<InputDialogComponent>){
20+
21+
}
22+
23+
save(){
24+
this.dialogRef.close({project_id: this.input.value})
25+
}
26+
27+
}

0 commit comments

Comments
 (0)