Skip to content

Commit

Permalink
Merge pull request #18 from NeoScript/add_multi_project_support
Browse files Browse the repository at this point in the history
Add multi project support
  • Loading branch information
NeoScript authored Feb 9, 2024
2 parents 6d154b6 + 9d90f17 commit eefe3ad
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 13 deletions.
3 changes: 2 additions & 1 deletion webapp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import { TopicListComponent } from './components/topic-list/topic-list.component
SubscriptionDetailsComponent,
TopicDetailsComponent,
NewTopicDialogComponent,
NewSubscriptionDialogComponent
NewSubscriptionDialogComponent,

],
imports: [
BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/app/components/index/index.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3>Select a Project from the list:</h3>
{{project}}
</button>

<button mat-stroked-button class="new-project">
<button mat-stroked-button class="new-project" (click)="addNewProject()">
<mat-icon>add_circle</mat-icon>
Attach new project
</button>
Expand Down
17 changes: 15 additions & 2 deletions webapp/src/app/components/index/index.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -11,11 +13,22 @@ export class IndexComponent implements OnInit {

projectList$: Observable<string[]>

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)
})
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<mat-dialog-content>
<mat-form-field appearance="outline" color="accent">
<mat-label>Enter a value</mat-label>
<input matInput type="text" autocomplete="off" [formControl]="input">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button [disabled]="input.invalid" (click)="save()">save</button>
</mat-dialog-actions>
Empty file.
Original file line number Diff line number Diff line change
@@ -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<InputDialogComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [InputDialogComponent]
})
.compileComponents();

fixture = TestBed.createComponent(InputDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
27 changes: 27 additions & 0 deletions webapp/src/app/components/input-dialog/input-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -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<InputDialogComponent>){

}

save(){
this.dialogRef.close({project_id: this.input.value})
}

}
4 changes: 2 additions & 2 deletions webapp/src/app/components/projects/projects.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export class ProjectsComponent implements OnInit {
topicList2$: Observable<Topic[]> = EMPTY
subscriptionList$: Observable<Subscription[]> = EMPTY

currentProject?: string
currentProject: string = ""
currentTopic?: Topic
currentSubscription?: Subscription

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

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!)
Expand Down
13 changes: 6 additions & 7 deletions webapp/src/app/services/pubsub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(["test-project"])
private _projectList = new BehaviorSubject<string[]>([])
private _currentProject = new ReplaySubject<string>()
private _currentTopic = new ReplaySubject<Topic>()
private _currentSubscription = new ReplaySubject<Subscription>()
Expand Down Expand Up @@ -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<Topic>(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){
Expand All @@ -60,8 +59,8 @@ export class PubsubService {
return this.http.delete(url)
}

listSubscriptions(): Observable<Subscription[]> {
return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${this.project_id}/subscriptions`)
listSubscriptions(projectId: string): Observable<Subscription[]> {
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??[]),
Expand Down

0 comments on commit eefe3ad

Please sign in to comment.