1
- import { Component , HostBinding , ViewChild , ElementRef } from "@angular/core" ;
1
+ import { Component , ElementRef , HostBinding , ViewChild } from "@angular/core" ;
2
2
import { UpgradableComponent } from "theme/components/upgradable" ;
3
3
import {
4
- ResultMessage ,
5
- ConfigService ,
6
- TypeService ,
7
- RequirementTypes ,
8
- PluginType ,
9
4
APIAndSpecificType ,
10
- SubTypes ,
11
- ConnectorService ,
12
- InstanceService ,
13
- ConnectorKey ,
5
+ ConfigService ,
14
6
ConnectorDetails ,
7
+ ConnectorKey ,
8
+ ConnectorMetadata ,
15
9
ConnectorRef ,
10
+ ConnectorService ,
16
11
CredentialsEntry ,
17
12
EncryptedKeyValuePair ,
13
+ InstanceService ,
18
14
PluginInstance ,
19
15
PluginInstanceRef ,
16
+ PluginLogMessageDTO ,
17
+ PluginType ,
20
18
Requirement ,
21
19
RequirementInfo ,
22
- PluginLogMessageDTO
20
+ RequirementTypes ,
21
+ ResultMessage ,
22
+ SubTypes ,
23
+ TypeService
23
24
} from "chatoverflow-api" ;
24
25
import { CryptoService } from "../../../crypto.service" ;
25
- import { EventService } from "../../../event.service" ;
26
+ import { EventService } from "../../../event.service" ;
26
27
27
28
@Component ( {
28
29
selector : 'better-repl' ,
@@ -41,6 +42,7 @@ export class BetterREPLComponent extends UpgradableComponent {
41
42
private lastPassword = "" ;
42
43
43
44
private connectorTypes : Array < string > ;
45
+ private connectorMetadata : Map < string , ConnectorMetadata > ;
44
46
private requirementTypes : RequirementTypes ;
45
47
private pluginTypes : Array < PluginType > ;
46
48
@@ -74,52 +76,6 @@ export class BetterREPLComponent extends UpgradableComponent {
74
76
this . addEventListeners ( ) ;
75
77
}
76
78
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
-
123
79
reloadEverything ( clearForms : boolean ) {
124
80
if ( clearForms ) {
125
81
this . authKey = "" ;
@@ -143,6 +99,7 @@ export class BetterREPLComponent extends UpgradableComponent {
143
99
this . changeReqValueValue = "" ;
144
100
145
101
this . connectorTypes = [ ] ;
102
+ this . connectorMetadata = new Map ( ) ;
146
103
this . requirementTypes = null ;
147
104
this . pluginTypes = [ ] ;
148
105
this . pluginInstances = [ ] ;
@@ -159,6 +116,7 @@ export class BetterREPLComponent extends UpgradableComponent {
159
116
160
117
requestTypes ( ) {
161
118
this . connectorTypes = [ ] ;
119
+ this . connectorMetadata = new Map ( ) ;
162
120
this . requirementTypes = null ;
163
121
this . pluginTypes = [ ] ;
164
122
@@ -167,6 +125,18 @@ export class BetterREPLComponent extends UpgradableComponent {
167
125
this . connectorTypes = response ;
168
126
} , error => this . logGenericError ( "getConnectorType" ) ) ;
169
127
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
+
170
140
this . typeService . getRequirementType ( this . authKey ) . subscribe ( ( response : RequirementTypes ) => {
171
141
this . logRequest ( "getRequirementType" , true , JSON . stringify ( response ) ) ;
172
142
this . requirementTypes = response ;
@@ -178,6 +148,52 @@ export class BetterREPLComponent extends UpgradableComponent {
178
148
} , error => this . logGenericError ( "getPlugin" ) ) ;
179
149
}
180
150
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
+
181
197
logRequest ( command : string , lastRequestSuccessful : boolean , resultMessage : string ) {
182
198
this . lastRequestCommand = command ;
183
199
this . lastRequestSuccessful = lastRequestSuccessful ;
0 commit comments