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

Commit 54e2a76

Browse files
committed
Added full reloading and ping/pong to the GUI.
1 parent 881b0c4 commit 54e2a76

File tree

1 file changed

+96
-5
lines changed

1 file changed

+96
-5
lines changed

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

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
PluginLogMessageDTO
2323
} from "chatoverflow-api";
2424
import {CryptoService} from "../../../crypto.service";
25+
import {interval} from "rxjs";
2526

2627
@Component({
2728
selector: 'better-repl',
@@ -36,6 +37,7 @@ export class BetterREPLComponent extends UpgradableComponent {
3637
private lastRequestSuccessful = true;
3738

3839
private authKey = "";
40+
private lastPassword = "";
3941

4042
private connectorTypes: Array<string>;
4143
private requirementTypes: RequirementTypes;
@@ -63,21 +65,66 @@ export class BetterREPLComponent extends UpgradableComponent {
6365
private changeReqTypeValue = "";
6466
private changeReqValueValue = "";
6567

68+
private pingpongCounter = interval(5000);
69+
private pingpongStarted = false;
70+
private pingPongSubscriber = null;
71+
6672
constructor(private configService: ConfigService, private typeService: TypeService,
6773
private connectorService: ConnectorService, private instanceService: InstanceService,
6874
private cryptoService: CryptoService) {
6975
super();
7076
}
7177

78+
reloadEverything(clearForms: boolean) {
79+
if (clearForms) {
80+
this.authKey = "";
81+
this.instanceLogOutput = [];
82+
this.instanceRequirements = [];
83+
84+
this.mcSourceIdentifierValue = "";
85+
this.mcConnectorTypeValue = "";
86+
this.mcrSourceIdentifierValue = "";
87+
this.mcrConnectorTypeValue = "";
88+
89+
this.instanceNameSSValue = "";
90+
this.miPluginNameValue = "";
91+
this.miPluginAuthorValue = "";
92+
this.miInstanceNameValue = "";
93+
this.requirementsInstanceNameValue = "";
94+
95+
this.changeReqInstanceNameValue = "";
96+
this.changeReqIDValue = "";
97+
this.changeReqTypeValue = "";
98+
this.changeReqValueValue = "";
99+
100+
this.connectorTypes = [];
101+
this.requirementTypes = null;
102+
this.pluginTypes = [];
103+
this.pluginInstances = [];
104+
this.connectorKeys = [];
105+
106+
} else {
107+
108+
this.requestTypes();
109+
this.getRegisteredConnectors();
110+
this.getInstances();
111+
}
112+
113+
}
114+
72115
requestTypes() {
116+
this.connectorTypes = [];
117+
this.requirementTypes = null;
118+
this.pluginTypes = [];
119+
73120
this.typeService.getConnectorType(this.authKey).subscribe((response: Array<string>) => {
74121
this.logRequest("getConnectorType", true, JSON.stringify(response));
75122
this.connectorTypes = response;
76123
}, error => this.logGenericError("getConnectorType"));
77124

78125
this.typeService.getRequirementType(this.authKey).subscribe((response: RequirementTypes) => {
79126
this.logRequest("getRequirementType", true, JSON.stringify(response));
80-
this.requirementTypes = response
127+
this.requirementTypes = response;
81128
}, error => this.logGenericError("getRequirementType"));
82129

83130
this.typeService.getPlugin(this.authKey).subscribe((response: Array<PluginType>) => {
@@ -105,19 +152,61 @@ export class BetterREPLComponent extends UpgradableComponent {
105152
this.logResultMessage("postLogin", response);
106153
if (response.success) {
107154
this.authKey = response.message;
108-
this.requestTypes();
155+
this.lastPassword = password;
156+
}
157+
this.reloadEverything(!response.success);
158+
this.handlePingpong(true);
159+
}, error => {
160+
this.logGenericError("postLogin");
161+
this.reloadEverything(true);
162+
});
163+
}
164+
165+
handlePingpong(start: boolean) {
166+
if (start) {
167+
if (!this.pingpongStarted) {
168+
this.pingPongSubscriber = this.pingpongCounter.subscribe(n => this.pingpong());
169+
this.pingpongStarted = true;
170+
}
171+
} else {
172+
if (this.pingPongSubscriber != null) {
173+
this.pingPongSubscriber.unsubscribe();
174+
}
175+
this.pingpongStarted = false;
176+
}
177+
}
178+
179+
pingpong() {
180+
this.configService.postPing(this.authKey).subscribe((response: ResultMessage) => {
181+
if (response.success) {
182+
// Pong
183+
} else {
184+
this.reloadEverything(true);
185+
}
186+
}, error => {
187+
if (error.status == 401 || error.status == 400) {
188+
// Try to login again
189+
this.login(this.lastPassword);
190+
191+
} else if (error.status == 0) {
192+
this.reloadEverything(true);
109193
}
110-
}, error => this.logGenericError("postLogin"));
194+
})
111195
}
112196

113197
register(password: string) {
114198
this.configService.postRegister({password: password}).subscribe((response: ResultMessage) => {
115199
this.logResultMessage("postRegister", response);
116200
if (response.success) {
117201
this.authKey = response.message;
118-
this.requestTypes();
202+
this.reloadEverything(false);
119203
}
120-
}, error => this.logGenericError("postRegister"));
204+
this.reloadEverything(!response.success);
205+
this.handlePingpong(true);
206+
}, error => {
207+
this.logGenericError("postRegister");
208+
this.reloadEverything(true);
209+
});
121210
}
122211

123212
getRequirementImpl(apiType: string) {
@@ -133,6 +222,7 @@ export class BetterREPLComponent extends UpgradableComponent {
133222
}
134223

135224
getRegisteredConnectors() {
225+
this.connectorKeys = [];
136226
this.connectorService.getConnectors(this.authKey).subscribe((response: Array<ConnectorKey>) => {
137227
this.logRequest("getConnectors", true, JSON.stringify(response));
138228
this.connectorKeys = response;
@@ -213,6 +303,7 @@ export class BetterREPLComponent extends UpgradableComponent {
213303
}
214304

215305
getInstances() {
306+
this.pluginInstances = [];
216307
this.instanceService.getInstances(this.authKey).subscribe((response: Array<PluginInstance>) => {
217308
this.pluginInstances = response;
218309
this.logRequest("getInstances", true, JSON.stringify(response));

0 commit comments

Comments
 (0)