Skip to content

Commit eefe3ad

Browse files
authored
Merge pull request #18 from NeoScript/add_multi_project_support
Add multi project support
2 parents 6d154b6 + 9d90f17 commit eefe3ad

9 files changed

+85
-13
lines changed

webapp/src/app/app.module.ts

+2-1
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

+1-1
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

+15-2
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
}
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.
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+
});
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+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export class ProjectsComponent implements OnInit {
1616
topicList2$: Observable<Topic[]> = EMPTY
1717
subscriptionList$: Observable<Subscription[]> = EMPTY
1818

19-
currentProject?: string
19+
currentProject: string = ""
2020
currentTopic?: Topic
2121
currentSubscription?: Subscription
2222

2323
constructor(private route: ActivatedRoute, private pubsub: PubsubService) { }
2424

2525
ngOnInit(): void {
2626
this.route.queryParamMap.subscribe(qpm => {
27-
this.currentProject = qpm.get("project") ?? undefined
27+
this.currentProject = qpm.get("project") ?? ""
2828

2929
console.log("loaded project: ", this.currentProject)
3030
this.pubsub.selectProject(this.currentProject!)

webapp/src/app/services/pubsub.service.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { NewSubscriptionRequest } from '../components/subscription-list/new-subs
77
providedIn: 'root'
88
})
99
export class PubsubService {
10-
project_id = "test-project"
1110
public currentHost = "http://localhost:8681"
1211

13-
private _projectList = new BehaviorSubject<string[]>(["test-project"])
12+
private _projectList = new BehaviorSubject<string[]>([])
1413
private _currentProject = new ReplaySubject<string>()
1514
private _currentTopic = new ReplaySubject<Topic>()
1615
private _currentSubscription = new ReplaySubject<Subscription>()
@@ -39,14 +38,14 @@ export class PubsubService {
3938
this._projectList.next(newList)
4039
}
4140

42-
createTopic(projectId: string = this.project_id, topicId: string){
41+
createTopic(projectId: string, topicId: string){
4342
const url = `${this.currentHost}/v1/projects/${projectId}/topics/${topicId}`
4443

4544
return this.http.put<Topic>(url, {})
4645
}
4746

48-
listTopics(projectId: string = this.project_id) {
49-
return this.http.get<{ topics: Topic[] }>(`${this.currentHost}/v1/projects/${this.project_id}/topics`).pipe(map(incoming => incoming?.topics || []))
47+
listTopics(projectId: string) {
48+
return this.http.get<{ topics: Topic[] }>(`${this.currentHost}/v1/projects/${projectId}/topics`).pipe(map(incoming => incoming?.topics || []))
5049
}
5150

5251
createSubscription(projectId: string, request: NewSubscriptionRequest){
@@ -60,8 +59,8 @@ export class PubsubService {
6059
return this.http.delete(url)
6160
}
6261

63-
listSubscriptions(): Observable<Subscription[]> {
64-
return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${this.project_id}/subscriptions`)
62+
listSubscriptions(projectId: string): Observable<Subscription[]> {
63+
return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${projectId}/subscriptions`)
6564
.pipe(
6665
map(incoming => incoming.subscriptions), // first we pull out the subscriptions object
6766
map(subNames => subNames??[]),

0 commit comments

Comments
 (0)