Skip to content

Commit 0fedea1

Browse files
authored
Merge pull request #19 from NeoScript/add_emulator_host_configuration
Add emulator host configuration
2 parents 815e180 + eb2f93e commit 0fedea1

11 files changed

+71
-30
lines changed

webapp/angular.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"prefix": "app",
1919
"architect": {
2020
"build": {
21-
"builder": "@angular-devkit/build-angular:browser",
21+
"builder": "@angular-devkit/build-angular:browser-esbuild",
2222
"options": {
2323
"outputPath": "dist/webapp",
2424
"index": "src/index.html",
@@ -59,12 +59,9 @@
5959
"outputHashing": "all"
6060
},
6161
"development": {
62-
"buildOptimizer": false,
6362
"optimization": false,
64-
"vendorChunk": true,
6563
"extractLicenses": false,
66-
"sourceMap": true,
67-
"namedChunks": true
64+
"sourceMap": true
6865
}
6966
},
7067
"defaultConfiguration": "production"

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class IndexComponent implements OnInit {
2525

2626
ref.afterClosed()
2727
.pipe(filter(r => !!r))
28-
.subscribe((result: { project_id: string }) => {
28+
.subscribe((result: { user_input: string }) => {
2929
console.log(result)
30-
this.pubsub.attachProject(result.project_id)
30+
this.pubsub.attachProject(result.user_input)
3131
})
3232
}
3333

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<mat-dialog-content>
2-
<mat-form-field appearance="outline" color="accent">
2+
<mat-form-field appearance="outline" color="accent" style="min-width: 20em;">
33
<mat-label>Enter a value</mat-label>
44
<input matInput type="text" autocomplete="off" [formControl]="input">
55
</mat-form-field>
66
</mat-dialog-content>
77
<mat-dialog-actions>
8-
<button mat-raised-button [disabled]="input.invalid" (click)="save()">save</button>
8+
<button mat-raised-button color="accent" [disabled]="input.invalid" (click)="save()">save</button>
99
</mat-dialog-actions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mat-dialog-actions{
2+
display: flex;
3+
justify-content: end;
4+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class InputDialogComponent {
2121
}
2222

2323
save(){
24-
this.dialogRef.close({project_id: this.input.value})
24+
this.dialogRef.close({user_input: this.input.value})
2525
}
2626

2727
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ <h3>pubsub-ui</h3>
1111
</div>
1212

1313
<div class="config">
14-
<h4>current host: {{this.currentHost}}</h4>
14+
<div class="links">
15+
<button mat-icon-button (click)="updateHostUrl()">
16+
<mat-icon>settings</mat-icon>
17+
</button>
18+
19+
@if (this.currentHost|async; as host) {
20+
<h4>current host: <a [href]="host">{{host}}</a></h4>
21+
}
22+
</div>
1523
</div>
1624
</div>
1725

webapp/src/app/components/navbar/navbar.component.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
align-items: center;
1515
}
1616

17-
.home-btn {
17+
button {
1818
&:hover {
1919
color: lightgreen;
2020
}
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-navbar',
@@ -9,12 +11,20 @@ import { PubsubService } from 'src/app/services/pubsub.service';
911
})
1012
export class NavbarComponent implements OnInit {
1113

12-
currentHost: string
13-
constructor(private pubsub: PubsubService) {
14-
this.currentHost = pubsub.currentHost;
15-
}
14+
currentHost: Observable<string>
15+
constructor(private pubsub: PubsubService, private dialog: MatDialog) {
16+
this.currentHost = pubsub._currentHost$.asObservable();
17+
}
1618

1719
ngOnInit(): void {
1820
}
1921

22+
updateHostUrl() {
23+
const ref = this.dialog.open(InputDialogComponent)
24+
ref.afterClosed().pipe(filter(result => !!result))
25+
.subscribe((result: { user_input: string }) => {
26+
this.pubsub.setHost(result.user_input)
27+
})
28+
}
29+
2030
}

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

+29-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NewSubscriptionRequest } from '../components/subscription-list/new-subs
77
providedIn: 'root'
88
})
99
export class PubsubService {
10-
public currentHost = "http://localhost:8681"
10+
public _currentHost$ = new BehaviorSubject<string>("http://localhost:8681")
1111

1212
private _projectList = new BehaviorSubject<string[]>([])
1313
private _currentProject = new ReplaySubject<string>()
@@ -21,12 +21,27 @@ export class PubsubService {
2121
public currentSubscription$ = this._currentSubscription.asObservable()
2222

2323
constructor(private http: HttpClient) {
24+
const prevHost = localStorage.getItem("host")
25+
if(prevHost){
26+
console.log('loaded previous host', prevHost)
27+
this._currentHost$.next(prevHost)
28+
}
29+
30+
const prevProjects = localStorage.getItem("projects") ?? "[]"
31+
const projects: string[] = JSON.parse(prevProjects) ?? []
32+
this._projectList.next(projects)
2433

2534
this.currentProject$.subscribe(project =>
2635
this.topicList$ = this.listTopics(project)
2736
)
2837
}
2938

39+
setHost(hostUrl: string){
40+
this._currentHost$.next(hostUrl)
41+
42+
localStorage.setItem("host", hostUrl)
43+
}
44+
3045
selectProject(projectId: string) {
3146
this._currentProject.next(projectId)
3247
}
@@ -36,31 +51,34 @@ export class PubsubService {
3651
newList.push(newProject)
3752

3853
this._projectList.next(newList)
54+
55+
const jsonList = JSON.stringify(newList)
56+
localStorage.setItem("projects", jsonList)
3957
}
4058

4159
createTopic(projectId: string, topicId: string){
42-
const url = `${this.currentHost}/v1/projects/${projectId}/topics/${topicId}`
60+
const url = `${this._currentHost$.value}/v1/projects/${projectId}/topics/${topicId}`
4361

4462
return this.http.put<Topic>(url, {})
4563
}
4664

4765
listTopics(projectId: string) {
48-
return this.http.get<{ topics: Topic[] }>(`${this.currentHost}/v1/projects/${projectId}/topics`).pipe(map(incoming => incoming?.topics || []))
66+
return this.http.get<{ topics: Topic[] }>(`${this._currentHost$.value}/v1/projects/${projectId}/topics`).pipe(map(incoming => incoming?.topics || []))
4967
}
5068

5169
createSubscription(projectId: string, request: NewSubscriptionRequest){
52-
const url = `${this.currentHost}/v1/projects/${projectId}/subscriptions/${request.name}`
70+
const url = `${this._currentHost$.value}/v1/projects/${projectId}/subscriptions/${request.name}`
5371

5472
return this.http.put<Subscription>(url, {topic: request.topic, pushConfig: request.pushConfig})
5573
}
5674

5775
deleteSubscription(subscriptionPath: string){
58-
const url = `${this.currentHost}/v1/${subscriptionPath}`
76+
const url = `${this._currentHost$.value}/v1/${subscriptionPath}`
5977
return this.http.delete(url)
6078
}
6179

6280
listSubscriptions(projectId: string): Observable<Subscription[]> {
63-
return this.http.get<{ subscriptions?: string[] }>(`${this.currentHost}/v1/projects/${projectId}/subscriptions`)
81+
return this.http.get<{ subscriptions?: string[] }>(`${this._currentHost$.value}/v1/projects/${projectId}/subscriptions`)
6482
.pipe(
6583
map(incoming => incoming.subscriptions), // first we pull out the subscriptions object
6684
map(subNames => subNames??[]),
@@ -70,7 +88,7 @@ export class PubsubService {
7088

7189
listSubscriptionsOnTopic(topicPath: string): Observable<Subscription[]> {
7290
console.log('looking up subscriptions on', topicPath)
73-
const url = `${this.currentHost}/v1/${topicPath}/subscriptions`
91+
const url = `${this._currentHost$.value}/v1/${topicPath}/subscriptions`
7492
console.log('request url', url)
7593
return this.http.get<{ subscriptions?: string[] }>(url)
7694
.pipe(
@@ -81,25 +99,25 @@ export class PubsubService {
8199
}
82100

83101
getSubscriptionDetails(subscriptionPath: string){
84-
const url = `${this.currentHost}/v1/${subscriptionPath}`
102+
const url = `${this._currentHost$.value}/v1/${subscriptionPath}`
85103
return this.http.get<Subscription>(url)
86104
}
87105

88106
fetchMessages(subPath: string, maxMessages: number) {
89107
return this.http
90108
.post<{ receivedMessages: ReceivedMessage[] }>(
91-
`${this.currentHost}/v1/${subPath}:pull`,
109+
`${this._currentHost$.value}/v1/${subPath}:pull`,
92110
{ returnImmediately: true, maxMessages }
93111
).pipe(map(incoming => incoming.receivedMessages ?? []))
94112
}
95113

96114
ackMessage(subscriptionPath:string, ackIds: string[]){
97-
const url = `${this.currentHost}/v1/${subscriptionPath}:acknowledge`
115+
const url = `${this._currentHost$.value}/v1/${subscriptionPath}:acknowledge`
98116
return this.http.post(url, {ackIds})
99117
}
100118

101119
publishMessages(topicPath: string, messages: PubsubMessage[]){
102-
const url = `${this.currentHost}/v1/${topicPath}:publish`
120+
const url = `${this._currentHost$.value}/v1/${topicPath}:publish`
103121
return this.http.post<{messageIds: string[]}>(url, {messages})
104122
}
105123
}

webapp/src/assets/icon.png

24.2 KB
Loading

webapp/src/index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>Webapp</title>
5+
<title>pubsub-ui</title>
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8-
<link rel="icon" type="image/x-icon" href="favicon.ico">
8+
<link rel="icon" type="image/x-icon" href="assets/icon.png">
9+
10+
<!-- icon source -->
11+
<!-- <a href="https://www.flaticon.com/free-icons/food-and-restaurant" title="food and restaurant icons">Food and restaurant icons created by Nikita Golubev - Flaticon</a> -->
12+
913
<link rel="preconnect" href="https://fonts.gstatic.com">
1014
<!-- <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet"> -->
1115
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

0 commit comments

Comments
 (0)