nicer let syntax for fb
This commit is contained in:
@@ -3,11 +3,7 @@ import { FrontblockApiConf } from 'frontblock';
|
||||
import { SubscriptionResponse, parseResponse, SuccessResponse } from 'frontblock-generic/Types.js';
|
||||
import { environment } from "../../environments/environment"
|
||||
|
||||
let fb
|
||||
if(environment.production){
|
||||
fb = window["fb"]
|
||||
}else{
|
||||
fb = {
|
||||
const fb = environment.production?window["fb"]:{
|
||||
ApiClient : {
|
||||
setConfig: async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
@@ -32,9 +28,7 @@ if(environment.production){
|
||||
},
|
||||
unsubscribe: (uid) => new SuccessResponse(),
|
||||
quit: (uid) => new SuccessResponse()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@Component({
|
||||
selector: 'consumptions',
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { fbind } from 'q';
|
||||
import { FrontblockApiConf } from 'frontblock';
|
||||
import { environment } from "../../environments/environment"
|
||||
|
||||
let fb
|
||||
if(environment.production){
|
||||
fb = window["fb"]
|
||||
}else{
|
||||
fb = {
|
||||
ApiClient : {
|
||||
setConfig: async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Promise A win!');
|
||||
}, 500)
|
||||
})}
|
||||
const fb = environment.production ? window["fb"] : {
|
||||
ApiClient: {
|
||||
setConfig: async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Promise A win!');
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'settings',
|
||||
template: `
|
||||
selector: 'settings',
|
||||
template: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Settings
|
||||
@@ -77,10 +73,10 @@ if(environment.production){
|
||||
`
|
||||
})
|
||||
export class ApiclientFormComponent implements OnInit {
|
||||
testnet:boolean = true
|
||||
saving:boolean = false
|
||||
advanced:boolean = false
|
||||
data:FrontblockApiConf = {
|
||||
testnet: boolean = true
|
||||
saving: boolean = false
|
||||
advanced: boolean = false
|
||||
data: FrontblockApiConf = {
|
||||
apiHost: "api.testnet.frontblock.me",
|
||||
apiPort: 10001,
|
||||
tls: false,
|
||||
@@ -91,28 +87,28 @@ export class ApiclientFormComponent implements OnInit {
|
||||
|
||||
ngOnInit() { }
|
||||
|
||||
setAdvanced(){ this.advanced = true }
|
||||
setAdvanced() { this.advanced = true }
|
||||
|
||||
checkData():boolean{
|
||||
checkData(): boolean {
|
||||
return (
|
||||
typeof this.data.apiPort === "number" &&
|
||||
typeof this.data.apiPort === "number" &&
|
||||
typeof this.data.apiHost === "string" &&
|
||||
typeof this.data.tls === "boolean" &&
|
||||
typeof this.data.apiKey === "string"
|
||||
)
|
||||
typeof this.data.apiKey === "string"
|
||||
)
|
||||
}
|
||||
|
||||
updateTestnet(){
|
||||
if(this.testnet){
|
||||
updateTestnet() {
|
||||
if (this.testnet) {
|
||||
this.data.apiHost = "api.testnet.frontblock.me"
|
||||
this.data.apiPort = 10001
|
||||
}else{
|
||||
} else {
|
||||
this.data.apiHost = "api.frontblock.me"
|
||||
this.data.apiPort = 10000
|
||||
}
|
||||
}
|
||||
|
||||
updatePort(obj){
|
||||
updatePort(obj) {
|
||||
switch (this.data.apiHost) {
|
||||
case "api.testnet.frontblock.me":
|
||||
this.data.apiPort = 10001
|
||||
@@ -120,23 +116,23 @@ export class ApiclientFormComponent implements OnInit {
|
||||
case "api.frontblock.me":
|
||||
this.data.apiPort = 10000
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
console.warn("A non-standard api host was chosen: "+this.data.apiPort)
|
||||
console.warn("A non-standard api host was chosen: " + this.data.apiPort)
|
||||
break;
|
||||
}
|
||||
console.log(this.data)
|
||||
}
|
||||
|
||||
async save(){
|
||||
async save() {
|
||||
this.saving = true;
|
||||
if(typeof this.data.apiPort === "string")
|
||||
if (typeof this.data.apiPort === "string")
|
||||
this.data.apiPort = parseInt(this.data.apiPort)
|
||||
|
||||
if(this.checkData()){
|
||||
|
||||
if (this.checkData()) {
|
||||
const conf = await fb.ApiClient.setConfig(this.data)
|
||||
console.log(conf)
|
||||
}else{
|
||||
} else {
|
||||
//show error in gui
|
||||
console.error("bad data :(")
|
||||
}
|
||||
|
||||
@@ -1,46 +1,39 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { fbind } from 'q';
|
||||
import { FrontblockApiConf } from 'frontblock';
|
||||
import { SubscriptionResponse, SuccessResponse, ErrorResponse, parseResponse } from 'frontblock-generic/Types.js';
|
||||
import { SubscriptionResponse, SuccessResponse, parseResponse } from 'frontblock-generic/Types.js';
|
||||
import { environment } from "../../environments/environment"
|
||||
|
||||
let fb
|
||||
if(environment.production){
|
||||
fb = window["fb"]
|
||||
}else{
|
||||
fb = {
|
||||
ApiClient : {
|
||||
setConfig: async () => {
|
||||
const fb = environment.production ? window["fb"] : {
|
||||
ApiClient: {
|
||||
setConfig: async () => {
|
||||
await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Promise A win!');
|
||||
}, 500)
|
||||
})
|
||||
setTimeout(() => {
|
||||
resolve('Promise A win!');
|
||||
}, 500)
|
||||
})
|
||||
},
|
||||
getConsumptions: async () => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve([new SubscriptionResponse("654", "321"), new SubscriptionResponse("456", "123")]);
|
||||
resolve([new SubscriptionResponse("654", "321"), new SubscriptionResponse("456", "123")]);
|
||||
}, 500)
|
||||
})
|
||||
},
|
||||
getSubscriptions: async () => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve([new SubscriptionResponse("321"), new SubscriptionResponse("123")]);
|
||||
resolve([new SubscriptionResponse("321"), new SubscriptionResponse("123")]);
|
||||
}, 500)
|
||||
})
|
||||
},
|
||||
unsubscribe: (uid) => new SuccessResponse(),
|
||||
quit: (uid) => new SuccessResponse()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'subscriptions',
|
||||
template: `
|
||||
selector: 'subscriptions',
|
||||
template: `
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Subscriptions
|
||||
@@ -87,9 +80,9 @@ if(environment.production){
|
||||
`
|
||||
})
|
||||
export class ApiclientSubscriptionComponent implements OnInit {
|
||||
loading:boolean = false
|
||||
actionName:string = "load"
|
||||
entries:SubscriptionResponse[] = []
|
||||
loading: boolean = false
|
||||
actionName: string = "load"
|
||||
entries: SubscriptionResponse[] = []
|
||||
alerts: {
|
||||
severity: "danger" | "warning" | "success"
|
||||
message: string
|
||||
@@ -99,24 +92,24 @@ export class ApiclientSubscriptionComponent implements OnInit {
|
||||
|
||||
ngOnInit() { }
|
||||
|
||||
async load(){
|
||||
async load() {
|
||||
this.loading = true
|
||||
this.entries = await fb.ApiClient.getSubscriptions()
|
||||
if(this.entries.length === 0){
|
||||
this.alerts.push({ severity: "warning", message: "0 results were returned"})
|
||||
if (this.entries.length === 0) {
|
||||
this.alerts.push({ severity: "warning", message: "0 results were returned" })
|
||||
}
|
||||
this.loading = false
|
||||
this.actionName = "refresh"
|
||||
}
|
||||
|
||||
async quit(uid:string){
|
||||
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})
|
||||
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})
|
||||
} else {
|
||||
this.alerts.push({ severity: "danger", message: "Error " + res.message })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,90 +36,82 @@ SystemJS.config({ meta: { '*': { authorization: true } } });
|
||||
/** --------- */
|
||||
|
||||
|
||||
import { AfterViewInit, Component, Input, ViewChild } from '@angular/core';
|
||||
import { AfterViewInit, Component } from '@angular/core';
|
||||
import { SidebarComponent } from '../sidebar/sidebar.component';
|
||||
import { Router } from '@angular/router';
|
||||
import { FrontendPlugin, SidebarEntries, SidebarEntry } from "frontblock-generic/Plugin"
|
||||
import { SidebarEntryService } from '../sidebar-entry-service.service';
|
||||
import { environment } from "../../environments/environment"
|
||||
|
||||
|
||||
let fb
|
||||
if(environment.production){
|
||||
fb = window["fb"]
|
||||
}else{
|
||||
|
||||
fb = {
|
||||
PluginManager : {
|
||||
getLoadedPluginNames: () => ["ApiClient", "PluginManager"]
|
||||
}
|
||||
const fb = environment.production ? window["fb"] : {
|
||||
PluginManager: {
|
||||
getLoadedPluginNames: () => ["ApiClient", "PluginManager"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'dynamic-loader',
|
||||
templateUrl: './dynamic-loader.component.html',
|
||||
styleUrls: ['./dynamic-loader.component.scss']
|
||||
})
|
||||
export class DynamicLoaderComponent implements AfterViewInit {
|
||||
sidebar:SidebarComponent
|
||||
sidebar: SidebarComponent
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private sidebarService:SidebarEntryService
|
||||
private sidebarService: SidebarEntryService
|
||||
) {
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
const _this = this;
|
||||
(function awaitSidebar(){
|
||||
(function awaitSidebar() {
|
||||
const sb = _this.sidebarService.getSidebar()
|
||||
if(sb != null){
|
||||
if (sb != null) {
|
||||
_this.sidebar = sb
|
||||
_this.loadWidgets()
|
||||
return
|
||||
}
|
||||
setTimeout(awaitSidebar,25)
|
||||
setTimeout(awaitSidebar, 25)
|
||||
})()
|
||||
}
|
||||
|
||||
private async loadWidgets(){
|
||||
while(!fb.PluginManager){
|
||||
private async loadWidgets() {
|
||||
while (!fb.PluginManager) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||
}
|
||||
const pluginNames = await fb.PluginManager.getLoadedPluginNames()
|
||||
pluginNames.forEach(element => this.installWidget(element));
|
||||
}
|
||||
|
||||
private async installWidget(pluginName:string){
|
||||
let module: FrontendPlugin
|
||||
if(environment.production)
|
||||
module = await SystemJS.import("plugins/"+pluginName+".js");
|
||||
private async installWidget(pluginName: string) {
|
||||
let module: FrontendPlugin
|
||||
if (environment.production)
|
||||
module = await SystemJS.import("plugins/" + pluginName + ".js");
|
||||
else
|
||||
module = await import("../"+pluginName+"/module")
|
||||
module = await import("../" + pluginName + "/module")
|
||||
|
||||
const plugin = new module['PluginModule']()
|
||||
const entry:SidebarEntries | SidebarEntry = plugin.getSidebarEntry()
|
||||
const entry: SidebarEntries | SidebarEntry = plugin.getSidebarEntry()
|
||||
const rc = this.router.config
|
||||
|
||||
|
||||
switch (typeof (<any>entry).links) {
|
||||
case "undefined":
|
||||
const e:SidebarEntry = <SidebarEntry>entry
|
||||
e.route = "plugin/" + e.route
|
||||
const e: SidebarEntry = <SidebarEntry>entry
|
||||
e.route = "plugin/" + e.route
|
||||
|
||||
this.sidebar.entries.push(e)
|
||||
rc.unshift({
|
||||
path: "plugin",
|
||||
loadChildren: async () => module['PluginModule']
|
||||
})
|
||||
|
||||
|
||||
break;
|
||||
case "object":
|
||||
const m:SidebarEntries = <SidebarEntries>entry
|
||||
const m: SidebarEntries = <SidebarEntries>entry
|
||||
|
||||
m.links = m.links.map(link => {
|
||||
return {text: link.text, route: m.parentRoute + "/" + link.route }
|
||||
return { text: link.text, route: m.parentRoute + "/" + link.route }
|
||||
})
|
||||
|
||||
this.sidebar.multientires.push(m)
|
||||
@@ -127,7 +119,7 @@ export class DynamicLoaderComponent implements AfterViewInit {
|
||||
path: m.parentRoute,
|
||||
loadChildren: async () => module['PluginModule']
|
||||
})
|
||||
break;
|
||||
break;
|
||||
}
|
||||
this.router.resetConfig(rc)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user