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

Commit 69c812c

Browse files
timonbackstavshamir
authored andcommitted
feat: Move anchorLink to channel model
1 parent cc03946 commit 69c812c

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/app/channels/channels.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>Channels</h1>
22
<mat-accordion>
3-
<mat-expansion-panel *ngFor="let channel of channels" [id]="this.getChannelIdentifier(channel)" [expanded]="selectedChannel == this.getChannelIdentifier(channel)" (opened)="this.setChannelSelection(channel)">
3+
<mat-expansion-panel *ngFor="let channel of channels" [id]="channel.anchorIdentifier" [expanded]="selectedChannel == channel.anchorIdentifier" (opened)="this.setChannelSelection(channel)">
44
<mat-expansion-panel-header>
55
<mat-panel-title fxLayout fxLayoutAlign="flex-start center" fxLayoutGap="16px">
66
<div class="badge protocol-badge" >

src/app/channels/channels.component.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { AsyncApiService } from '../shared/asyncapi.service';
3-
import { Channel } from '../shared/models/channel.model';
3+
import {Channel, CHANNEL_ANCHOR_PREFIX} from '../shared/models/channel.model';
44
import { Location } from "@angular/common";
55

66
@Component({
@@ -9,7 +9,6 @@ import { Location } from "@angular/common";
99
styleUrls: ['./channels.component.css']
1010
})
1111
export class ChannelsComponent implements OnInit {
12-
static CHANNEL_ANCHOR_PREFIX = "channel-"
1312

1413
channels: Channel[];
1514
selectedChannel: string;
@@ -42,16 +41,12 @@ export class ChannelsComponent implements OnInit {
4241
}
4342

4443
setChannelSelection(channel: Channel): void {
45-
window.location.hash = '#' + this.getChannelIdentifier(channel)
44+
window.location.hash = '#' + channel.anchorIdentifier
4645
}
4746
setChannelSelectionFromLocation(): void {
4847
const anchor = window.location.hash.substr(1);
49-
if (anchor.startsWith(ChannelsComponent.CHANNEL_ANCHOR_PREFIX)) {
48+
if (anchor.startsWith(CHANNEL_ANCHOR_PREFIX)) {
5049
this.selectedChannel = anchor;
5150
}
5251
}
53-
54-
getChannelIdentifier(channel: Channel) {
55-
return ChannelsComponent.CHANNEL_ANCHOR_PREFIX + channel.name + "-" + channel.operation.protocol + "-" + channel.operation.operation;
56-
}
5752
}

src/app/shared/asyncapi-mapper.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AsyncApi } from './models/asyncapi.model';
22
import { Server } from './models/server.model';
3-
import {Channel, Message, Operation, OperationType} from './models/channel.model';
3+
import {Channel, CHANNEL_ANCHOR_PREFIX, Message, Operation, OperationType} from './models/channel.model';
44
import { Schema } from './models/schema.model';
55
import { Injectable } from '@angular/core';
66
import {Example} from "./models/example.model";
@@ -102,17 +102,19 @@ export class AsyncApiMapperService {
102102
private mapChannel(
103103
topicName: string,
104104
description: ServerAsyncApi["channels"][""]["description"],
105-
operation: ServerAsyncApi["channels"][""]["subscribe"] | ServerAsyncApi["channels"][""]["publish"],
105+
serverOperation: ServerAsyncApi["channels"][""]["subscribe"] | ServerAsyncApi["channels"][""]["publish"],
106106
operationType: OperationType): Channel[]
107107
{
108-
if(operation !== undefined) {
109-
let messages: Message[] = 'oneOf' in operation.message ? operation.message.oneOf : [operation.message];
108+
if(serverOperation !== undefined) {
109+
let messages: Message[] = 'oneOf' in serverOperation.message ? serverOperation.message.oneOf : [serverOperation.message];
110110

111111
return messages.map(message => {
112+
const operation = this.mapOperation(operationType, message, serverOperation.bindings)
112113
return {
113114
name: topicName,
115+
anchorIdentifier: CHANNEL_ANCHOR_PREFIX + topicName + "-" + operation.protocol + "-" + operationType,
114116
description: description,
115-
operation: this.mapOperation(operationType, message, operation.bindings)
117+
operation: operation,
116118
}
117119
})
118120
}

src/app/shared/models/channel.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
export const CHANNEL_ANCHOR_PREFIX = "channel-"
12
export interface Channel {
23
name: string;
4+
anchorIdentifier: string;
35
description?: string;
46
operation: Operation;
57
}

0 commit comments

Comments
 (0)