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

Commit 8637534

Browse files
committed
First approach of converting and displaying connector metadata.
1 parent 9e7c624 commit 8637534

File tree

2 files changed

+98
-78
lines changed

2 files changed

+98
-78
lines changed

src/app/pages/betterrepl/betterrepl.component.html

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,30 @@ <h2 class="card--title">Connector types</h2>
5151
</base-card-title>
5252
<base-card-body>
5353
<ul class="typeList">
54-
<li *ngFor="let connectorType of connectorTypes">{{ connectorType }}</li>
54+
<li *ngFor="let connectorType of connectorTypes">{{ connectorType }}
55+
<ul>
56+
<li>{{ connectorMetadata.get(connectorType)?.displayName }}</li>
57+
</ul>
58+
</li>
59+
</ul>
60+
61+
</base-card-body>
62+
</base-card>
63+
</div>
64+
<div class="card--third-size">
65+
<base-card>
66+
<base-card-title>
67+
<h2 class="card--title">Requirement types</h2>
68+
</base-card-title>
69+
<base-card-body>
70+
<ul class="typeList">
71+
<li *ngFor="let inputType of requirementTypes?.input">{{ inputType }}</li>
72+
</ul>
73+
<ul class="typeList">
74+
<li *ngFor="let outputType of requirementTypes?.output">{{ outputType }}</li>
75+
</ul>
76+
<ul class="typeList">
77+
<li *ngFor="let parameterType of requirementTypes?.parameter">{{ parameterType }}</li>
5578
</ul>
5679
<div id="requestTypes">
5780
<div>
@@ -75,25 +98,6 @@ <h2 class="card--title">Connector types</h2>
7598
</button>
7699
</div>
77100
</div>
78-
79-
</base-card-body>
80-
</base-card>
81-
</div>
82-
<div class="card--third-size">
83-
<base-card>
84-
<base-card-title>
85-
<h2 class="card--title">Requirement types</h2>
86-
</base-card-title>
87-
<base-card-body>
88-
<ul class="typeList">
89-
<li *ngFor="let inputType of requirementTypes?.input">{{ inputType }}</li>
90-
</ul>
91-
<ul class="typeList">
92-
<li *ngFor="let outputType of requirementTypes?.output">{{ outputType }}</li>
93-
</ul>
94-
<ul class="typeList">
95-
<li *ngFor="let parameterType of requirementTypes?.parameter">{{ parameterType }}</li>
96-
</ul>
97101
</base-card-body>
98102
</base-card>
99103
</div>

src/app/pages/betterrepl/betterrepl.component.ts

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
import {Component, HostBinding, ViewChild, ElementRef} from "@angular/core";
1+
import {Component, ElementRef, HostBinding, ViewChild} from "@angular/core";
22
import {UpgradableComponent} from "theme/components/upgradable";
33
import {
4-
ResultMessage,
5-
ConfigService,
6-
TypeService,
7-
RequirementTypes,
8-
PluginType,
94
APIAndSpecificType,
10-
SubTypes,
11-
ConnectorService,
12-
InstanceService,
13-
ConnectorKey,
5+
ConfigService,
146
ConnectorDetails,
7+
ConnectorKey,
8+
ConnectorMetadata,
159
ConnectorRef,
10+
ConnectorService,
1611
CredentialsEntry,
1712
EncryptedKeyValuePair,
13+
InstanceService,
1814
PluginInstance,
1915
PluginInstanceRef,
16+
PluginLogMessageDTO,
17+
PluginType,
2018
Requirement,
2119
RequirementInfo,
22-
PluginLogMessageDTO
20+
RequirementTypes,
21+
ResultMessage,
22+
SubTypes,
23+
TypeService
2324
} from "chatoverflow-api";
2425
import {CryptoService} from "../../../crypto.service";
25-
import { EventService } from "../../../event.service";
26+
import {EventService} from "../../../event.service";
2627

2728
@Component({
2829
selector: 'better-repl',
@@ -41,6 +42,7 @@ export class BetterREPLComponent extends UpgradableComponent {
4142
private lastPassword = "";
4243

4344
private connectorTypes: Array<string>;
45+
private connectorMetadata: Map<string, ConnectorMetadata>;
4446
private requirementTypes: RequirementTypes;
4547
private pluginTypes: Array<PluginType>;
4648

@@ -74,52 +76,6 @@ export class BetterREPLComponent extends UpgradableComponent {
7476
this.addEventListeners();
7577
}
7678

77-
private addEventListeners() {
78-
this.eventService.addEventListener("error", () => {
79-
console.log("Lost connection. Trying to reconnect...");
80-
setTimeout(() => this.login(this.lastPassword), 1000);
81-
});
82-
83-
this.eventService.addEventListener("instance", ({ action, data }) => {
84-
const instance = this.pluginInstances.find(i => i.instanceName === data.name);
85-
if (!instance)
86-
return;
87-
88-
switch (action) {
89-
case "start":
90-
instance.isRunning = true;
91-
break;
92-
case "stop":
93-
instance.isRunning = false;
94-
break;
95-
case "log":
96-
if (data.message && data.timestamp) {
97-
if (!instance.log)
98-
instance.log = [];
99-
100-
instance.log.push({ timestamp: new Date(data.timestamp).toLocaleTimeString(), message: data.message });
101-
if (data.name === this.instanceNameSSValue) {
102-
this.instanceLogOutput = this.getInstanceLog(instance);
103-
this.scrollToLogEnd();
104-
}
105-
}
106-
break;
107-
}
108-
});
109-
}
110-
111-
private scrollToLogEnd(force?: boolean) {
112-
if (this.instanceLog && this.instanceLog.nativeElement) {
113-
const element = this.instanceLog.nativeElement;
114-
if (force || element.scrollTop + element.clientHeight === element.scrollHeight)
115-
setTimeout(() => element.scrollTop = element.scrollHeight, 0);
116-
}
117-
}
118-
119-
private getInstanceLog(instance: PluginInstance) {
120-
return instance.log ? instance.log.map(log => `${log.timestamp} - ${log.message}`) : [];
121-
}
122-
12379
reloadEverything(clearForms: boolean) {
12480
if (clearForms) {
12581
this.authKey = "";
@@ -143,6 +99,7 @@ export class BetterREPLComponent extends UpgradableComponent {
14399
this.changeReqValueValue = "";
144100

145101
this.connectorTypes = [];
102+
this.connectorMetadata = new Map();
146103
this.requirementTypes = null;
147104
this.pluginTypes = [];
148105
this.pluginInstances = [];
@@ -159,6 +116,7 @@ export class BetterREPLComponent extends UpgradableComponent {
159116

160117
requestTypes() {
161118
this.connectorTypes = [];
119+
this.connectorMetadata = new Map();
162120
this.requirementTypes = null;
163121
this.pluginTypes = [];
164122

@@ -167,6 +125,18 @@ export class BetterREPLComponent extends UpgradableComponent {
167125
this.connectorTypes = response;
168126
}, error => this.logGenericError("getConnectorType"));
169127

128+
this.typeService.getConnectorsMetadata(this.authKey).subscribe((response: { [key: string]: ConnectorMetadata }) => {
129+
this.logRequest("getConnectorsMetadata", true, JSON.stringify(response));
130+
131+
// This converts the typescript hash map structure to a "normal" js map
132+
for (let key in response) {
133+
let allValues = response[key];
134+
for (let keyValue in allValues) {
135+
this.connectorMetadata.set(keyValue, allValues[keyValue]);
136+
}
137+
}
138+
}, error => this.logGenericError("getConnectorsMetadata"));
139+
170140
this.typeService.getRequirementType(this.authKey).subscribe((response: RequirementTypes) => {
171141
this.logRequest("getRequirementType", true, JSON.stringify(response));
172142
this.requirementTypes = response;
@@ -178,6 +148,52 @@ export class BetterREPLComponent extends UpgradableComponent {
178148
}, error => this.logGenericError("getPlugin"));
179149
}
180150

151+
private scrollToLogEnd(force?: boolean) {
152+
if (this.instanceLog && this.instanceLog.nativeElement) {
153+
const element = this.instanceLog.nativeElement;
154+
if (force || element.scrollTop + element.clientHeight === element.scrollHeight)
155+
setTimeout(() => element.scrollTop = element.scrollHeight, 0);
156+
}
157+
}
158+
159+
private getInstanceLog(instance: PluginInstance) {
160+
return instance.log ? instance.log.map(log => `${log.timestamp} - ${log.message}`) : [];
161+
}
162+
163+
private addEventListeners() {
164+
this.eventService.addEventListener("error", () => {
165+
console.log("Lost connection. Trying to reconnect...");
166+
setTimeout(() => this.login(this.lastPassword), 1000);
167+
});
168+
169+
this.eventService.addEventListener("instance", ({action, data}) => {
170+
const instance = this.pluginInstances.find(i => i.instanceName === data.name);
171+
if (!instance)
172+
return;
173+
174+
switch (action) {
175+
case "start":
176+
instance.isRunning = true;
177+
break;
178+
case "stop":
179+
instance.isRunning = false;
180+
break;
181+
case "log":
182+
if (data.message && data.timestamp) {
183+
if (!instance.log)
184+
instance.log = [];
185+
186+
instance.log.push({timestamp: new Date(data.timestamp).toLocaleTimeString(), message: data.message});
187+
if (data.name === this.instanceNameSSValue) {
188+
this.instanceLogOutput = this.getInstanceLog(instance);
189+
this.scrollToLogEnd();
190+
}
191+
}
192+
break;
193+
}
194+
});
195+
}
196+
181197
logRequest(command: string, lastRequestSuccessful: boolean, resultMessage: string) {
182198
this.lastRequestCommand = command;
183199
this.lastRequestSuccessful = lastRequestSuccessful;

0 commit comments

Comments
 (0)