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

Commit 1a8654a

Browse files
committed
Remove multiple documents support
1 parent 71acf82 commit 1a8654a

12 files changed

+717
-792
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Schema } from 'src/app/shared/models/schema.model';
55
import { PublisherService } from 'src/app/shared/publisher.service';
66
import { MatSnackBar } from '@angular/material/snack-bar';
77
import { Operation } from 'src/app/shared/models/channel.model';
8-
import { Subscription } from 'rxjs';
98
import { STATUS } from 'angular-in-memory-web-api';
109

1110
@Component({
@@ -39,7 +38,7 @@ export class ChannelMainComponent implements OnInit {
3938
ngOnInit(): void {
4039
this.asyncApiService.getAsyncApis().subscribe(
4140
asyncapi => {
42-
let schemas: Map<string, Schema> = asyncapi.get(this.docName).components.schemas;
41+
let schemas: Map<string, Schema> = asyncapi.components.schemas;
4342
this.schemaName = this.operation.message.payload.$ref.slice(this.operation.message.payload.$ref.lastIndexOf('/') + 1)
4443
this.schema = schemas[this.schemaName];
4544

src/app/channels/channels.component.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AsyncApiService } from '../shared/asyncapi.service';
33
import { Channel } from '../shared/models/channel.model';
4-
import { subscribeOn } from 'rxjs/operators';
5-
import { Subscription } from 'rxjs';
6-
import {Location} from "@angular/common";
4+
import { Location } from "@angular/common";
75

86
@Component({
97
selector: 'app-channels',
@@ -15,31 +13,27 @@ export class ChannelsComponent implements OnInit {
1513

1614
channels: Channel[];
1715
selectedChannel: string;
18-
nameSubscription: Subscription;
1916
docName: string;
2017

2118
constructor(private asyncApiService: AsyncApiService, private location: Location) {
2219
this.setChannelSelectionFromLocation()
2320
}
2421

2522
ngOnInit(): void {
26-
this.location.subscribe(() : void => this.setChannelSelectionFromLocation())
23+
this.location.subscribe((): void => this.setChannelSelectionFromLocation())
2724

28-
this.nameSubscription = this.asyncApiService.getCurrentAsyncApiName().subscribe(name => {
29-
this.docName = name;
30-
this.asyncApiService.getAsyncApis().subscribe(asyncapi => {
31-
this.channels = this.sortChannels(asyncapi.get(name).channels);
32-
});
25+
this.asyncApiService.getAsyncApis().subscribe(asyncapi => {
26+
this.channels = this.sortChannels(asyncapi.channels);
3327
});
3428
}
3529

3630
private sortChannels(channels: Array<Channel>): Array<Channel> {
37-
return channels.sort((a,b) => {
38-
if(a?.operation?.protocol === b?.operation?.protocol) {
39-
if(a?.operation?.operation === b?.operation.operation) {
31+
return channels.sort((a, b) => {
32+
if (a?.operation?.protocol === b?.operation?.protocol) {
33+
if (a?.operation?.operation === b?.operation.operation) {
4034
return a.name?.localeCompare(b.name);
4135
} else {
42-
return a?.operation?.operation?.localeCompare(b?.operation?.operation);
36+
return a?.operation?.operation?.localeCompare(b?.operation?.operation);
4337
}
4438
} else {
4539
return a?.operation?.protocol?.localeCompare(b?.operation?.protocol);
@@ -52,7 +46,7 @@ export class ChannelsComponent implements OnInit {
5246
}
5347
setChannelSelectionFromLocation(): void {
5448
const anchor = window.location.hash.substr(1);
55-
if(anchor.startsWith(ChannelsComponent.CHANNEL_ANCHOR_PREFIX)) {
49+
if (anchor.startsWith(ChannelsComponent.CHANNEL_ANCHOR_PREFIX)) {
5650
this.selectedChannel = anchor;
5751
}
5852
}

src/app/header/header.component.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<mat-toolbar color="primary" fxLayout fxLayoutAlign="space-between center">
2-
<div fxLayout fxLayoutAlign="center center" fxLayoutGap="16px">
3-
<h2>springwolf</h2>
4-
<select [(ngModel)]="selectedDocumentMod">
5-
<option disabled>Choose a doc</option>
6-
<option *ngFor="let doc of documents" [ngValue]="doc">{{ doc }}</option>
7-
</select>
8-
</div>
2+
<h2>springwolf</h2>
93
<a href="https://github.com/stavshamir/springwolf">
104
<i class="fa fa-github fa-2x"></i>
115
</a>
12-
</mat-toolbar>
6+
</mat-toolbar>

src/app/header/header.component.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
1-
import { Component, OnInit } from '@angular/core';
2-
import { AsyncApiService } from 'src/app/shared/asyncapi.service';
1+
import { Component } from '@angular/core';
32

43
@Component({
54
selector: 'app-header',
65
templateUrl: './header.component.html',
76
styleUrls: ['./header.component.css']
87
})
9-
export class HeaderComponent implements OnInit {
10-
private static URL_SEARCH_DOCUMENT_PARAM = "document"
11-
12-
documents: string[];
13-
selectedDocument: string;
14-
location: Location;
15-
16-
constructor(private asyncApiService: AsyncApiService) {
17-
this.location = window.location
18-
this.selectedDocument = new URLSearchParams(window.location.search).get(HeaderComponent.URL_SEARCH_DOCUMENT_PARAM)
19-
}
20-
21-
ngOnInit(): void {
22-
this.asyncApiService.getAsyncApis().subscribe(docsMap => {
23-
this.documents = [...docsMap.keys()];
24-
if(!this.documents.includes(this.selectedDocument)) {
25-
this.selectedDocument = this.documents[0]
26-
}
27-
this.asyncApiService.setCurrentAsyncApiName(this.selectedDocument);
28-
});
29-
}
30-
31-
get selectedDocumentMod() {
32-
return this.selectedDocument;
33-
}
34-
35-
set selectedDocumentMod(value) {
36-
let updatedSearchParams = new URLSearchParams(window.location.search)
37-
updatedSearchParams.set(HeaderComponent.URL_SEARCH_DOCUMENT_PARAM, value)
38-
this.location.search = updatedSearchParams.toString()
39-
}
40-
8+
export class HeaderComponent {
419
}

src/app/info/info.component.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
22
import { AsyncApi } from '../shared/models/asyncapi.model';
33
import { Info } from '../shared/models/info.model';
44
import { AsyncApiService } from '../shared/asyncapi.service';
5-
import { Subscription } from 'rxjs';
65

76
@Component({
87
selector: 'app-info',
@@ -13,16 +12,13 @@ export class InfoComponent implements OnInit {
1312

1413
asyncApiData: AsyncApi;
1514
info: Info;
16-
nameSubscription: Subscription;
1715

1816
constructor(private asyncApiService: AsyncApiService) { }
1917

2018
ngOnInit(): void {
21-
this.nameSubscription = this.asyncApiService.getCurrentAsyncApiName().subscribe(name => {
22-
this.asyncApiService.getAsyncApis().subscribe(asyncapi => {
23-
this.asyncApiData = asyncapi.get(name);
24-
this.info = asyncapi.get(name).info;
25-
});
19+
this.asyncApiService.getAsyncApis().subscribe(asyncapi => {
20+
this.asyncApiData = asyncapi;
21+
this.info = asyncapi.info;
2622
});
2723
}
2824

src/app/schemas/schemas.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Location } from '@angular/common';
3-
import { Subscription, SubscriptionLike } from 'rxjs';
43
import { AsyncApiService } from '../shared/asyncapi.service';
54
import { Schema } from '../shared/models/schema.model';
65

@@ -14,18 +13,14 @@ export class SchemasComponent implements OnInit {
1413

1514
schemas: Map<string, Schema>;
1615
selectedSchema: string;
17-
nameSubscription: Subscription;
1816

1917
constructor(private asyncApiService: AsyncApiService, private location: Location) {
2018
this.setSchemaSelectionFromLocation()
2119
}
2220

2321
ngOnInit(): void {
2422
this.location.subscribe(() : void => this.setSchemaSelectionFromLocation())
25-
26-
this.nameSubscription = this.asyncApiService.getCurrentAsyncApiName().subscribe(name => {
27-
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.schemas = asyncapi.get(name).components.schemas);
28-
});
23+
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.schemas = asyncapi.components.schemas);
2924
}
3025

3126
setSchemaSelection(schema: string): void {

src/app/servers/servers.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { forkJoin, Subscription, zip } from 'rxjs';
3-
import { mergeMap } from 'rxjs/operators';
42
import { AsyncApiService } from '../shared/asyncapi.service';
53
import { Server } from '../shared/models/server.model';
64

@@ -12,14 +10,11 @@ import { Server } from '../shared/models/server.model';
1210
export class ServersComponent implements OnInit {
1311

1412
servers: Map<String, Server>;
15-
nameSubscription: Subscription;
1613

1714
constructor(private asyncApiService: AsyncApiService) { }
1815

1916
ngOnInit(): void {
20-
this.nameSubscription = this.asyncApiService.getCurrentAsyncApiName().subscribe(name => {
21-
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.servers = asyncapi.get(name).servers );
22-
});
17+
this.asyncApiService.getAsyncApis().subscribe(asyncapi => this.servers = asyncapi.servers );
2318
}
2419

2520
}

src/app/shared/asyncapi.service.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Channel, Message, Operation } from './models/channel.model';
44
import { Schema } from './models/schema.model';
55
import { HttpClient } from '@angular/common/http';
66
import { Injectable } from '@angular/core';
7-
import { Observable, of, Subject } from 'rxjs';
7+
import { Observable, of } from 'rxjs';
88
import { map } from 'rxjs/operators';
99
import { Info } from './models/info.model';
1010
import { Endpoints } from './endpoints';
@@ -39,39 +39,23 @@ interface ServerAsyncApi {
3939
@Injectable()
4040
export class AsyncApiService {
4141

42-
private nameSubject: Subject<string>;
43-
private docs: Map<string, AsyncApi>;
42+
private docs: AsyncApi;
4443

4544
constructor(private http: HttpClient) {
46-
this.nameSubject = new Subject<string>();
4745
}
4846

49-
public setCurrentAsyncApiName(currnetAsyncApiName: string) {
50-
this.nameSubject.next(currnetAsyncApiName);
51-
}
52-
53-
public getCurrentAsyncApiName(): Observable<string> {
54-
return this.nameSubject.asObservable();
55-
}
56-
57-
public getAsyncApis(): Observable<Map<string, AsyncApi>> {
47+
public getAsyncApis(): Observable<AsyncApi> {
5848
if (this.docs) {
5949
return of(this.docs);
6050
}
6151

62-
return this.http.get<Map<string, ServerAsyncApi>>(Endpoints.docs).pipe(map(item => {
63-
this.docs = this.toAsyncApiMap(item);
52+
return this.http.get<ServerAsyncApi>(Endpoints.docs).pipe(map(item => {
53+
this.docs = this.toAsyncApi(item);
6454
return this.docs;
6555
}));
6656
}
6757

68-
toAsyncApiMap(response: Map<string, ServerAsyncApi>): Map<string, AsyncApi> {
69-
const docs = new Map<string, AsyncApi>();
70-
Object.entries(response).forEach(([docName, doc]) => docs.set(docName, this.toAsyncApi(doc)));
71-
return docs;
72-
}
73-
74-
toAsyncApi(item: ServerAsyncApi): AsyncApi {
58+
private toAsyncApi(item: ServerAsyncApi): AsyncApi {
7559
return {
7660
info: item.info,
7761
servers: this.mapServers(item.servers),
@@ -104,9 +88,8 @@ export class AsyncApiService {
10488
topicName: string,
10589
description: ServerAsyncApi["channels"][""]["description"],
10690
operation: ServerAsyncApi["channels"][""]["subscribe"] | ServerAsyncApi["channels"][""]["publish"],
107-
operationName: string): Channel[]
108-
{
109-
if(operation !== undefined) {
91+
operationName: string): Channel[] {
92+
if (operation !== undefined) {
11093
let messages: Message[] = 'oneOf' in operation.message ? operation.message.oneOf : [operation.message];
11194

11295
return messages.map(message => {

src/app/shared/mock/mock-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class MockServer implements InMemoryDbService {
2020
return reqInfo.utils.createResponse$(() => {
2121
return {
2222
status: STATUS.OK,
23-
body: mockAsyncApi
23+
body: mockSpringwolfKafka
2424
}
2525
});
2626
}

0 commit comments

Comments
 (0)