fix
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Consumptions
|
||||
</div>
|
||||
<clr-alert *ngFor="let entry of alerts" [clrAlertType]="entry.severity" (clrAlertClosedChange)="onClose()">
|
||||
<clr-alert-item>
|
||||
<span class="alert-text">
|
||||
{{entry.message}}
|
||||
</span>
|
||||
</clr-alert-item>
|
||||
</clr-alert>
|
||||
|
||||
<div *ngIf="loading" class="card-block">
|
||||
<span class="spinner spinner-inline"></span>
|
||||
</div>
|
||||
<div *ngIf="entries.length !== 0 && !loading" class="card-block">
|
||||
<div class="card-text">
|
||||
<table class="table table-noborder">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="left">UUID</th>
|
||||
<th>Expiry</th>
|
||||
<th>Creation</th>
|
||||
<th class="left"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let line of entries" >
|
||||
<td class="left">{{line.uid}}</td>
|
||||
<td>{{line.expiry}}</td>
|
||||
<td>{{line.created}}</td>
|
||||
<td class="left"><button class="btn btn-link btn-sm" (click)="quit(line.uid)">Quit</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button *ngIf="!loading" class="btn btn-sm btn-link" (click)="load()">{{actionName}}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
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})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,20 @@ declare const fb
|
||||
selector: 'apiclient', //!!!!
|
||||
template: `
|
||||
<div class="clr-row">
|
||||
<div class="clr-col">
|
||||
<div class="clr-col-lg-auto">
|
||||
<settings></settings>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clr-row">
|
||||
<div class="clr-col">
|
||||
<consumptions></consumptions>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clr-row">
|
||||
<div class="clr-col">
|
||||
<subscriptions></subscriptions>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class ApiclientDevComponent implements OnInit {
|
||||
|
||||
@@ -10,12 +10,9 @@ declare const fb
|
||||
template: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Configuration
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<div class="card-title">
|
||||
Settings
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<div class="card-text">
|
||||
<form clrForm clrLayout="vertical">
|
||||
<clr-input-container>
|
||||
|
||||
@@ -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: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Subscriptions
|
||||
</div>
|
||||
|
||||
<clr-alert *ngFor="let entry of alerts" [clrAlertType]="entry.severity" (clrAlertClosedChange)="onClose()">
|
||||
<clr-alert-item>
|
||||
<span class="alert-text">
|
||||
{{entry.message}}
|
||||
</span>
|
||||
</clr-alert-item>
|
||||
</clr-alert>
|
||||
|
||||
<div *ngIf="loading" class="card-block">
|
||||
<span class="spinner spinner-inline"></span>
|
||||
</div>
|
||||
<div *ngIf="entries.length !== 0 && !loading" class="card-block">
|
||||
<div class="card-text">
|
||||
<table class="table table-noborder">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="left">UUID</th>
|
||||
<th>Expiry</th>
|
||||
<th>Creation</th>
|
||||
<th class="left"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let line of entries" >
|
||||
<td class="left">{{line.uid}}</td>
|
||||
<td>{{line.expiry}}</td>
|
||||
<td>{{line.created}}</td>
|
||||
<td class="left"><button class="btn btn-link btn-sm" (click)="quit(line.uid)">Quit</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button *ngIf="!loading" class="btn btn-sm btn-link" (click)="load()">{{actionName}}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { SidebarEntry } from 'frontblock-generic/Plugin';
|
||||
declare const fb
|
||||
@Component({
|
||||
selector: 'apiclient', //!!!!
|
||||
template: `
|
||||
<div class="clr-row">
|
||||
<div class="clr-col">
|
||||
<settings></settings>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class ApiclientDevComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() { }
|
||||
|
||||
}
|
||||
|
||||
export const sidebarEntry:SidebarEntry = {
|
||||
icon: "wrench",
|
||||
route: "dev/apiclient",
|
||||
text: "DEV ApiClient",
|
||||
}
|
||||
+135
@@ -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: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Configuration
|
||||
</div>
|
||||
<div class="card-block">
|
||||
<div class="card-title">
|
||||
Settings
|
||||
</div>
|
||||
<div class="card-text">
|
||||
<form clrForm clrLayout="vertical">
|
||||
<clr-input-container>
|
||||
<label>testnet</label>
|
||||
<clr-control-error>We need your first name for legal compliance</clr-control-error>
|
||||
</clr-input-container>
|
||||
<input type="checkbox" [(ngModel)]="testnet" (change)="updateTestnet($event)" name="testnetToggle" clrToggle />
|
||||
|
||||
<clr-input-container *ngIf="!testnet">
|
||||
<label>API key</label>
|
||||
<input clrInput type="text" name="apiKey" required />
|
||||
<clr-control-error>We need your first name for legal compliance</clr-control-error>
|
||||
</clr-input-container>
|
||||
|
||||
<clr-input-container *ngIf="advanced">
|
||||
<label>API address</label>
|
||||
<input type="text" [(ngModel)]="data.apiHost" (change)="updatePort($event)" clrInput name="apiHost" required />
|
||||
<clr-control-error>This field is required!</clr-control-error>
|
||||
</clr-input-container>
|
||||
|
||||
<clr-checkbox-wrapper *ngIf="advanced" >
|
||||
<input [(ngModel)]="data.tls" type="checkbox" clrCheckbox value="tls" name="options" />
|
||||
<label>Use TLS</label>
|
||||
</clr-checkbox-wrapper>
|
||||
|
||||
<clr-input-container *ngIf="advanced">
|
||||
<label>Port</label>
|
||||
<input [(ngModel)]="data.apiPort" clrInput type="number" name="lastName" required />
|
||||
<clr-control-error>Valid range 1024 - 65536
|
||||
</clr-control-error>
|
||||
</clr-input-container>
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button *ngIf="!saving" class="btn btn-success" (click)="save()">
|
||||
<span>Save</span>
|
||||
</button>
|
||||
|
||||
<button *ngIf="saving" class="btn btn-disabled" (click)="save()" disabled>
|
||||
<span class="spinner spinner-inline"></span>
|
||||
</button>
|
||||
<button *ngIf="!advanced" class="btn btn-sm btn-link" (click)="setAdvanced()">Advanced</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user