Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit c67e23f

Browse files
committed
Add message binding to the request made by PublisherService so that the backend can use the message binding to construct a message
1 parent 8c96a9d commit c67e23f

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/app/channels/channel-main/channel-main.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ button {
3333
padding: 6px;
3434
font-weight: normal;
3535
}
36+
37+
[hidden] {
38+
display: none !important;
39+
}

src/app/channels/channel-main/channel-main.component.html

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h4>{{ operation.message.description }}</h4>
77
<mat-tab-group animationDuration="0ms">
88
<mat-tab label="Example">
99
<div fxLayout="column">
10-
<div *ngIf="isEmptyObject(operation.message.bindings.get(protocolName))" fxLayout="column" fxLayoutGap="5px">
10+
<div [hidden]="isEmptyObject(operation.message.bindings.get(protocolName))" fxLayout="column" fxLayoutGap="5px">
1111
<h4>Binding</h4>
1212
<textarea spellcheck="false"
1313
#bindingTextArea
@@ -16,14 +16,16 @@ <h4>Binding</h4>
1616
(keyup)="recalculateLineCount('massageBindingExample', bindingTextArea.value)"
1717
></textarea>
1818
</div>
19-
<div *ngIf="headers" fxLayout="column" fxLayoutGap="0px">
20-
<h4>Header</h4>
21-
<textarea spellcheck="false"
22-
#headersTextArea
23-
[rows]="headersTextAreaLineCount"
24-
[value]="headersExample?.value"
25-
(keyup)="recalculateLineCount('headers', headersTextArea.value)"
26-
></textarea>
19+
<div [hidden]="!(headersExample?.lineCount > 1)" fxLayout="column" fxLayoutGap="0px">
20+
21+
<h4>Header</h4>
22+
<textarea spellcheck="false"
23+
#headersTextArea
24+
[rows]="headersTextAreaLineCount"
25+
[value]="headersExample?.value"
26+
(keyup)="recalculateLineCount('headers', headersTextArea.value)"
27+
></textarea>
28+
2729
</div>
2830
<div fxLayout="column" fxLayoutGap="5px">
2931
<h4>Message</h4>
@@ -35,11 +37,18 @@ <h4>Message</h4>
3537
></textarea>
3638
</div>
3739
<div fxLayout fxLayoutGap="8px">
38-
<button mat-raised-button color="primary" (click)="publish(messageTextArea.value, headersTextArea?.value)">
40+
<button mat-raised-button color="primary"
41+
(click)="publish(messageTextArea.value, headersTextArea?.value, bindingTextArea?.value)">
3942
Publish
4043
</button>
4144
<button mat-raised-button color="primary"
42-
(click)="messageTextArea.value = defaultExample.value; exampleTextAreaLineCount=defaultExample.lineCount">
45+
(click)="
46+
messageTextArea.value = defaultExample.value;
47+
exampleTextAreaLineCount = defaultExample.lineCount || 0;
48+
headersTextArea.value = headersExample?.value;
49+
headersTextAreaLineCount = headersExample?.lineCount || 0;
50+
bindingTextArea.value = createMessageBindingExample(operation.message.bindings.get(protocolName))?.value;
51+
messageBindingExampleTextAreaLineCount = messageBindingExample?.lineCount || 0">
4352
Default
4453
</button>
4554
<button mat-raised-button color="primary" [cdkCopyToClipboard]="messageTextArea.value">Copy</button>

src/app/channels/channel-main/channel-main.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export class ChannelMainComponent implements OnInit {
2929
protocolName: string;
3030
messageBindingExample?: Example;
3131
messageBindingExampleTextAreaLineCount: number;
32-
headersTextArea?: HTMLTextAreaElement;
3332

3433
constructor(
3534
private asyncApiService: AsyncApiService,
@@ -60,7 +59,7 @@ export class ChannelMainComponent implements OnInit {
6059
}
6160

6261
isEmptyObject(object?: any): boolean {
63-
return (object === undefined || object === null) || Object.keys(object).length > 0;
62+
return (object === undefined || object === null) || Object.keys(object).length === 0;
6463
}
6564

6665
createMessageBindingExample(messageBinding?: MessageBinding): Example | undefined {
@@ -104,12 +103,13 @@ export class ChannelMainComponent implements OnInit {
104103
}
105104
}
106105

107-
publish(example: string, headers?: string): void {
106+
publish(example: string, headers?: string, bindings?: string): void {
108107
try {
109108
const payloadJson = JSON.parse(example);
110109
const headersJson = JSON.parse(headers);
110+
const bindingsJson = JSON.parse(bindings);
111111

112-
this.publisherService.publish(this.protocolName, this.channelName, payloadJson, headersJson).subscribe(
112+
this.publisherService.publish(this.protocolName, this.channelName, payloadJson, headersJson, bindingsJson).subscribe(
113113
_ => this.handlePublishSuccess(),
114114
err => this.handlePublishError(err)
115115
);

src/app/shared/publisher.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { Injectable } from '@angular/core';
1+
import {Injectable} from '@angular/core';
22
import {HttpClient, HttpParams} from '@angular/common/http';
3-
import { Observable } from 'rxjs';
4-
import { Endpoints } from './endpoints';
3+
import {Observable} from 'rxjs';
4+
import {Endpoints} from './endpoints';
55

66
@Injectable()
77
export class PublisherService {
88

99
constructor(private http: HttpClient) { }
1010

11-
publish(protocol: string, topic: string, payload: object, headers: object): Observable<unknown> {
11+
publish(protocol: string, topic: string, payload: object, headers: object, bindings: object): Observable<unknown> {
1212
const url = Endpoints.getPublishEndpoint(protocol);
1313
const params = new HttpParams().set('topic', topic);
14-
const body = {"payload" : payload, "headers" : headers }
14+
const body = {payload, headers, bindings};
1515
console.log(`Publishing to ${url}`);
1616
return this.http.post(url, body, { params });
1717
}

0 commit comments

Comments
 (0)