From 71fa02d6dbf799d948676e87b433be3aa106c307 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 12 Aug 2019 16:51:20 +0200 Subject: [PATCH] fix --- src/backend/FrontblockLib.ts | 2 + .../apiclient-consumptions.component.ts | 90 ++++++++++++ .../apiclient-dev/apiclient-dev.component.ts | 12 +- .../apiclient-settings-form.component.ts | 5 +- .../apiclient-subscriptions.component.ts | 88 ++++++++++++ src/frontend/dashboard/src/app/app.module.ts | 7 +- .../apiclient-dev/apiclient-dev.component.ts | 26 ++++ .../apiclient-settings-form.component.ts | 135 ++++++++++++++++++ 8 files changed, 359 insertions(+), 6 deletions(-) create mode 100644 src/frontend/dashboard/src/app/apiclient-dev/apiclient-consumptions.component.ts create mode 100644 src/frontend/dashboard/src/app/apiclient-dev/apiclient-subscriptions.component.ts create mode 100644 src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-dev.component.ts create mode 100644 src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-settings-form.component.ts diff --git a/src/backend/FrontblockLib.ts b/src/backend/FrontblockLib.ts index 2b29b64..143a3b0 100644 --- a/src/backend/FrontblockLib.ts +++ b/src/backend/FrontblockLib.ts @@ -62,10 +62,12 @@ export class FrontblockConfigLib{ return res } )()` ) } + private unhookGenerator(fnName, fnArgs): Function{ return eval( `( () => async (`+fnArgs+`) => { const r = await this.socket.call("`+fnName+`", `+fnArgs+`) const res = await this.parseResponse(r) + console.log(res) if(res.uid != null) this.socket.unhook(res.uid) return res diff --git a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-consumptions.component.ts b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-consumptions.component.ts new file mode 100644 index 0000000..6d4cb29 --- /dev/null +++ b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-consumptions.component.ts @@ -0,0 +1,90 @@ +import { Component, OnInit } from '@angular/core'; +import { fbind } from 'q'; +import { FrontblockApiConf } from 'frontblock'; +import { SubscriptionResponse, parseResponse, SuccessResponse } from 'frontblock-generic/Types.js'; + + +declare const fb + +@Component({ + selector: 'consumptions', + template: ` +
+
+ Consumptions +
+ + + + {{entry.message}} + + + + +
+ +
+
+
+ + + + + + + + + + + + + + + + + +
UUIDExpiryCreation
{{line.uid}}{{line.expiry}}{{line.created}}
+
+
+ +
+ ` +}) +export class ApiclientConsumptionComponent implements OnInit { + loading:boolean = false + actionName:string = "load" + entries:SubscriptionResponse[] = [{ + uid: "1231", + message: "", + result: "Success" + }] + alerts: { + severity: "danger" | "warning" | "success" + message: string + }[] = [] + + constructor() { } + + ngOnInit() { } + + async load(){ + this.loading = true + this.entries = await fb.ApiClient.getConsumptions() + this.loading = false + this.actionName = "refresh" + } + + async quit(uid:string){ + const r = await fb.ApiClient.quit(uid) + const res = parseResponse(r) + if(res instanceof SuccessResponse){ + this.alerts.push({ severity: "success", message: "Quit consuming "+uid}) + this.load() + }else{ + this.alerts.push({ severity: "danger", message: "Error "+res.message}) + } + } +} diff --git a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-dev.component.ts b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-dev.component.ts index ca8b2de..c02c347 100644 --- a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-dev.component.ts +++ b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-dev.component.ts @@ -5,10 +5,20 @@ declare const fb selector: 'apiclient', //!!!! template: `
-
+
+
+
+ +
+
+
+
+ +
+
` }) export class ApiclientDevComponent implements OnInit { diff --git a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-settings-form.component.ts b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-settings-form.component.ts index 25fd5af..e955b2a 100644 --- a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-settings-form.component.ts +++ b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-settings-form.component.ts @@ -10,12 +10,9 @@ declare const fb template: `
- Configuration + Settings
-
- Settings -
diff --git a/src/frontend/dashboard/src/app/apiclient-dev/apiclient-subscriptions.component.ts b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-subscriptions.component.ts new file mode 100644 index 0000000..036758e --- /dev/null +++ b/src/frontend/dashboard/src/app/apiclient-dev/apiclient-subscriptions.component.ts @@ -0,0 +1,88 @@ +import { Component, OnInit } from '@angular/core'; +import { fbind } from 'q'; +import { FrontblockApiConf } from 'frontblock'; +import { SubscriptionResponse, SuccessResponse, ErrorResponse, parseResponse } from 'frontblock-generic/Types.js'; + + +declare const fb + +@Component({ + selector: 'subscriptions', + template: ` +
+
+ Subscriptions +
+ + + + + {{entry.message}} + + + + +
+ +
+
+
+ + + + + + + + + + + + + + + + + +
UUIDExpiryCreation
{{line.uid}}{{line.expiry}}{{line.created}}
+
+
+ +
+ ` +}) +export class ApiclientSubscriptionComponent implements OnInit { + loading:boolean = false + actionName:string = "load" + entries:SubscriptionResponse[] = [] + alerts: { + severity: "danger" | "warning" | "success" + message: string + }[] = [] + + constructor() { } + + ngOnInit() { } + + async load(){ + this.loading = true + this.entries = await fb.ApiClient.getSubscriptions() + this.loading = false + this.actionName = "refresh" + } + + async quit(uid:string){ + const r = await fb.ApiClient.unsubscribe(uid) + const res = parseResponse(r) + if(res instanceof SuccessResponse){ + this.alerts.push({ severity: "success", message: "Stopped subscription "+uid}) + this.load() + }else{ + this.alerts.push({ severity: "danger", message: "Error "+res.message}) + } + } + +} diff --git a/src/frontend/dashboard/src/app/app.module.ts b/src/frontend/dashboard/src/app/app.module.ts index 97053a3..c660b3f 100644 --- a/src/frontend/dashboard/src/app/app.module.ts +++ b/src/frontend/dashboard/src/app/app.module.ts @@ -18,6 +18,8 @@ import { PluginmanagerDevComponent } from './pluginmanager-dev/pluginmanager-dev import { HeaderBarComponent } from './header-bar/header-bar.component'; import { ApiclientDevComponent } from './apiclient-dev/apiclient-dev.component'; import { ApiclientFormComponent } from './apiclient-dev/apiclient-settings-form.component'; +import { ApiclientConsumptionComponent } from './apiclient-dev/apiclient-consumptions.component'; +import { ApiclientSubscriptionComponent } from './apiclient-dev/apiclient-subscriptions.component'; export function createCompiler(fn: CompilerFactory): Compiler { return fn.createCompiler(); @@ -36,7 +38,10 @@ const entryComps = [] PluginmanagerDevComponent, HeaderBarComponent, ApiclientDevComponent, - ApiclientFormComponent + ApiclientFormComponent, + ApiclientConsumptionComponent, + ApiclientSubscriptionComponent + ], imports: [ FormsModule, diff --git a/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-dev.component.ts b/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-dev.component.ts new file mode 100644 index 0000000..ca8b2de --- /dev/null +++ b/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-dev.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit } from '@angular/core'; +import { SidebarEntry } from 'frontblock-generic/Plugin'; +declare const fb +@Component({ + selector: 'apiclient', //!!!! + template: ` +
+
+ +
+
+ ` +}) +export class ApiclientDevComponent implements OnInit { + + constructor() { } + + ngOnInit() { } + +} + +export const sidebarEntry:SidebarEntry = { + icon: "wrench", + route: "dev/apiclient", + text: "DEV ApiClient", +} diff --git a/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-settings-form.component.ts b/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-settings-form.component.ts new file mode 100644 index 0000000..25fd5af --- /dev/null +++ b/src/frontend/dashboard/src/app/dynamic-loader/apiclient-dev/apiclient-settings-form.component.ts @@ -0,0 +1,135 @@ +import { Component, OnInit } from '@angular/core'; +import { fbind } from 'q'; +import { FrontblockApiConf } from 'frontblock'; + + +declare const fb + +@Component({ + selector: 'settings', + template: ` +
+
+ Configuration +
+
+
+ Settings +
+
+ + + + We need your first name for legal compliance + + + + + + + We need your first name for legal compliance + + + + + + This field is required! + + + + + + + + + + + Valid range 1024 - 65536 + + + + + +
+
+ +
+ ` +}) +export class ApiclientFormComponent implements OnInit { + testnet:boolean = true + saving:boolean = false + advanced:boolean = false + data:FrontblockApiConf = { + apiHost: "api.testnet.frontblock.me", + apiPort: 10001, + tls: false, + apiKey: "" + } + + constructor() { } + + ngOnInit() { } + + setAdvanced(){ this.advanced = true } + + checkData():boolean{ + return ( + typeof this.data.apiPort === "number" && + typeof this.data.apiHost === "string" && + typeof this.data.tls === "boolean" && + typeof this.data.apiKey === "string" + ) + } + + updateTestnet(){ + if(this.testnet){ + this.data.apiHost = "api.testnet.frontblock.me" + this.data.apiPort = 10001 + }else{ + this.data.apiHost = "api.frontblock.me" + this.data.apiPort = 10000 + } + } + + updatePort(obj){ + switch (this.data.apiHost) { + case "api.testnet.frontblock.me": + this.data.apiPort = 10001 + break; + case "api.frontblock.me": + this.data.apiPort = 10000 + break; + + default: + console.warn("A non-standard api host was chosen: "+this.data.apiPort) + break; + } + console.log(this.data) + } + + async save(){ + this.saving = true; + if(typeof this.data.apiPort === "string") + this.data.apiPort = parseInt(this.data.apiPort) + + if(this.checkData()){ + const conf = await fb.ApiClient.setConfig(this.data) + console.log(conf) + }else{ + //show error in gui + console.error("bad data :(") + } + this.saving = false + } +}