diff --git a/webapp/src/app/app.module.ts b/webapp/src/app/app.module.ts index 2183d74..3ec138c 100644 --- a/webapp/src/app/app.module.ts +++ b/webapp/src/app/app.module.ts @@ -38,7 +38,8 @@ import { TopicListComponent } from './components/topic-list/topic-list.component SubscriptionDetailsComponent, TopicDetailsComponent, NewTopicDialogComponent, - NewSubscriptionDialogComponent + NewSubscriptionDialogComponent, + ], imports: [ BrowserModule, diff --git a/webapp/src/app/components/index/index.component.html b/webapp/src/app/components/index/index.component.html index 716c7df..29fd389 100644 --- a/webapp/src/app/components/index/index.component.html +++ b/webapp/src/app/components/index/index.component.html @@ -11,7 +11,7 @@

Select a Project from the list:

{{project}} - diff --git a/webapp/src/app/components/index/index.component.ts b/webapp/src/app/components/index/index.component.ts index a64feb6..a9dae8d 100644 --- a/webapp/src/app/components/index/index.component.ts +++ b/webapp/src/app/components/index/index.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; +import { MatDialog } from '@angular/material/dialog'; +import { Observable, filter } from 'rxjs'; import { PubsubService } from 'src/app/services/pubsub.service'; +import { InputDialogComponent } from '../input-dialog/input-dialog.component'; @Component({ selector: 'app-index', @@ -11,11 +13,22 @@ export class IndexComponent implements OnInit { projectList$: Observable - constructor(private pubsub: PubsubService) { + constructor(private pubsub: PubsubService, private matDialog: MatDialog) { this.projectList$ = pubsub.projectList$ } ngOnInit(): void { } + addNewProject() { + const ref = this.matDialog.open(InputDialogComponent) + + ref.afterClosed() + .pipe(filter(r => !!r)) + .subscribe((result: { project_id: string }) => { + console.log(result) + this.pubsub.attachProject(result.project_id) + }) + } + } diff --git a/webapp/src/app/components/input-dialog/input-dialog.component.html b/webapp/src/app/components/input-dialog/input-dialog.component.html new file mode 100644 index 0000000..7e9fab8 --- /dev/null +++ b/webapp/src/app/components/input-dialog/input-dialog.component.html @@ -0,0 +1,9 @@ + + + Enter a value + + + + + + \ No newline at end of file diff --git a/webapp/src/app/components/input-dialog/input-dialog.component.scss b/webapp/src/app/components/input-dialog/input-dialog.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/webapp/src/app/components/input-dialog/input-dialog.component.spec.ts b/webapp/src/app/components/input-dialog/input-dialog.component.spec.ts new file mode 100644 index 0000000..60c58b3 --- /dev/null +++ b/webapp/src/app/components/input-dialog/input-dialog.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { InputDialogComponent } from './input-dialog.component'; + +describe('InputDialogComponent', () => { + let component: InputDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [InputDialogComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(InputDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/webapp/src/app/components/input-dialog/input-dialog.component.ts b/webapp/src/app/components/input-dialog/input-dialog.component.ts new file mode 100644 index 0000000..1fa4e9b --- /dev/null +++ b/webapp/src/app/components/input-dialog/input-dialog.component.ts @@ -0,0 +1,27 @@ +import { Component } from '@angular/core'; +import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; + +@Component({ + selector: 'app-input-dialog', + standalone: true, + imports: [MatDialogModule, MatButtonModule, MatInputModule, ReactiveFormsModule, MatFormFieldModule], + templateUrl: './input-dialog.component.html', + styleUrl: './input-dialog.component.scss' +}) +export class InputDialogComponent { + + input = new FormControl('', Validators.required) + + constructor(private dialogRef: MatDialogRef){ + + } + + save(){ + this.dialogRef.close({project_id: this.input.value}) + } + +} diff --git a/webapp/src/app/components/projects/projects.component.ts b/webapp/src/app/components/projects/projects.component.ts index 784d53a..cbd5ed4 100644 --- a/webapp/src/app/components/projects/projects.component.ts +++ b/webapp/src/app/components/projects/projects.component.ts @@ -16,7 +16,7 @@ export class ProjectsComponent implements OnInit { topicList2$: Observable = EMPTY subscriptionList$: Observable = EMPTY - currentProject?: string + currentProject: string = "" currentTopic?: Topic currentSubscription?: Subscription @@ -24,7 +24,7 @@ export class ProjectsComponent implements OnInit { ngOnInit(): void { this.route.queryParamMap.subscribe(qpm => { - this.currentProject = qpm.get("project") ?? undefined + this.currentProject = qpm.get("project") ?? "" console.log("loaded project: ", this.currentProject) this.pubsub.selectProject(this.currentProject!) diff --git a/webapp/src/app/services/pubsub.service.ts b/webapp/src/app/services/pubsub.service.ts index 1f10a09..43408f4 100644 --- a/webapp/src/app/services/pubsub.service.ts +++ b/webapp/src/app/services/pubsub.service.ts @@ -7,10 +7,9 @@ import { NewSubscriptionRequest } from '../components/subscription-list/new-subs providedIn: 'root' }) export class PubsubService { - project_id = "test-project" public currentHost = "http://localhost:8681" - private _projectList = new BehaviorSubject(["test-project"]) + private _projectList = new BehaviorSubject([]) private _currentProject = new ReplaySubject() private _currentTopic = new ReplaySubject() private _currentSubscription = new ReplaySubject() @@ -39,14 +38,14 @@ export class PubsubService { this._projectList.next(newList) } - createTopic(projectId: string = this.project_id, topicId: string){ + createTopic(projectId: string, topicId: string){ const url = `${this.currentHost}/v1/projects/${projectId}/topics/${topicId}` return this.http.put(url, {}) } - listTopics(projectId: string = this.project_id) { - return this.http.get<{ topics: Topic[] }>(`${this.currentHost}/v1/projects/${this.project_id}/topics`).pipe(map(incoming => incoming?.topics || [])) + listTopics(projectId: string) { + return this.http.get<{ topics: Topic[] }>(`${this.currentHost}/v1/projects/${projectId}/topics`).pipe(map(incoming => incoming?.topics || [])) } createSubscription(projectId: string, request: NewSubscriptionRequest){ @@ -60,8 +59,8 @@ export class PubsubService { return this.http.delete(url) } - listSubscriptions(): Observable { - return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${this.project_id}/subscriptions`) + listSubscriptions(projectId: string): Observable { + return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${projectId}/subscriptions`) .pipe( map(incoming => incoming.subscriptions), // first we pull out the subscriptions object map(subNames => subNames??[]),