Browse Source

knex config

master
peter 2 years ago
parent
commit
dc5cc34068

+ 333
- 153
package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 0
package.json View File

@@ -28,6 +28,7 @@
28 28
     "@clr/angular": "^2.1.1",
29 29
     "@clr/icons": "^2.1.1",
30 30
     "@clr/ui": "^2.1.1",
31
+    "@types/knex": "^0.16.1",
31 32
     "@webcomponents/custom-elements": "^1.0.0",
32 33
     "btc-hdkey": "0.0.17",
33 34
     "coinselect": "^3.1.11",

+ 1
- 1
src/app/apiclient

@@ -1 +1 @@
1
-Subproject commit 9c23bbf0b2a71d8193f2d413c4a88f9528480193
1
+Subproject commit cf393b0a7debcfe0155de980735ead4f0d109b01

+ 1
- 1
src/app/dynamic-loader/dynamic-loader.component.ts View File

@@ -53,7 +53,7 @@ import { environment } from "../../environments/environment"
53 53
 
54 54
 const fb = environment.production ? window["fb"] : {
55 55
   UpdateManager: {
56
-    getLoadedPluginNames: () => ["ApiClient"]
56
+    getLoadedPluginNames: () => ["ApiClient", "Wallet"]
57 57
   }
58 58
 }
59 59
 

+ 2
- 2
src/app/header-bar/header-bar.component.ts View File

@@ -1,12 +1,12 @@
1 1
 import { Component, OnInit, isDevMode } from '@angular/core';
2
-
2
+import { environment } from '../../environments/environment'
3 3
 @Component({
4 4
   selector: 'header-bar',
5 5
   templateUrl: './header-bar.component.html',
6 6
   styleUrls: ['./header-bar.component.scss']
7 7
 })
8 8
 export class HeaderBarComponent implements OnInit {
9
-  devmode = isDevMode()?"{ ng-DEV }":""
9
+  devmode = isDevMode()?(environment.loadLocal?"{ ng-DEV }":"{ ng-PRODLIKE }"):""
10 10
   constructor() { }
11 11
 
12 12
   ngOnInit() {

+ 188
- 7
src/app/knex-config/knex-config.component.ts View File

@@ -1,15 +1,196 @@
1
-import { Component, OnInit } from '@angular/core';
1
+import { Component, OnInit, Input } from '@angular/core';
2
+
3
+declare const fb
2 4
 
3 5
 @Component({
4
-  selector: 'knex-config',
5
-  templateUrl: './knex-config.component.html',
6
-  styleUrls: ['./knex-config.component.scss']
6
+    selector: 'knex-config',
7
+    template: `
8
+    <div class="clr-row">
9
+        <div class="card clr-col-12 clr-col-sm-12 clr-col-md-12 clr-col-lg-auto clr-col-xl-auto">
10
+            <div class="card-header">
11
+            Database configuration
12
+            </div>
13
+            <div class="card-block">
14
+                <div class="card-text">
15
+                  <clr-tabs>
16
+                    <clr-tab>
17
+                      <button clrTabLink id="link1">mySQL</button>
18
+                      <ng-template [(clrIfActive)]="mode['mysql']">
19
+                        <clr-tab-content id="content1">
20
+                          <form clrForm clrLayout="horizontal">
21
+                            <clr-input-container >
22
+                              <label class="clr-col-12 clr-col-md-4">host</label>
23
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="mysql-host" [(ngModel)]="mysql['connection']['host']" placeholder="127.0.0.1" required />
24
+                            </clr-input-container>
25
+                            <clr-input-container >
26
+                              <label class="clr-col-12 clr-col-md-4">user</label>
27
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="mysql-user" [(ngModel)]="mysql['connection']['user']" placeholder="root" required />
28
+                            </clr-input-container>
29
+                            <clr-input-container >
30
+                              <label class="clr-col-12 clr-col-md-4">password</label>
31
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="password" name="mysql-password" [(ngModel)]="mysql['connection']['password']" placeholder="*****" required />
32
+                            </clr-input-container>
33
+                            <clr-input-container >
34
+                              <label class="clr-col-12 clr-col-md-4">database</label>
35
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="mysql-database" [(ngModel)]="mysql['connection']['database']" placeholder="db_name" required />
36
+                            </clr-input-container>
37
+                            <clr-input-container >
38
+                              <label class="clr-col-12 clr-col-md-4">version</label>
39
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="mysql-version" [(ngModel)]="mysql['version']" placeholder="5.7" required />
40
+                            </clr-input-container>
41
+                          </form>
42
+                        </clr-tab-content>
43
+                      </ng-template>
44
+                    </clr-tab>
45
+                    <clr-tab>
46
+                      <button clrTabLink>pgSQL</button>
47
+                      <ng-template [(clrIfActive)]="mode['pg']">
48
+                        <clr-tab-content>
49
+                          <form clrForm clrLayout="horizontal">
50
+                          <clr-input-container >
51
+                          <label class="clr-col-12 clr-col-md-4">host</label>
52
+                          <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="pg-host" [(ngModel)]="pg['connection']['host']" placeholder="127.0.0.1" required />
53
+                        </clr-input-container>
54
+                        <clr-input-container >
55
+                          <label class="clr-col-12 clr-col-md-4">user</label>
56
+                          <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="pg-host" [(ngModel)]="pg['connection']['user']" placeholder="root" required />
57
+                        </clr-input-container>
58
+                        <clr-input-container >
59
+                          <label class="clr-col-12 clr-col-md-4">password</label>
60
+                          <input class="clr-col-12 clr-col-md-8" clrInput type="password" name="pg-host" [(ngModel)]="pg['connection']['password']" placeholder="*****" required />
61
+                        </clr-input-container>
62
+                        <clr-input-container >
63
+                          <label class="clr-col-12 clr-col-md-4">database</label>
64
+                          <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="pg-host" [(ngModel)]="pg['connection']['database']" placeholder="db_name" required />
65
+                        </clr-input-container>
66
+                        <clr-input-container >
67
+                          <label class="clr-col-12 clr-col-md-4">version</label>
68
+                          <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="pg-host" [(ngModel)]="pg['version']" placeholder="7.2" required />
69
+                        </clr-input-container>
70
+                          </form>
71
+                        </clr-tab-content>
72
+                      </ng-template>
73
+                    </clr-tab>
74
+                    <clr-tab>
75
+                      <button clrTabLink>SQLite3</button>
76
+                      <ng-template [(clrIfActive)]="mode['sqlite3']">
77
+                        <clr-tab-content>
78
+                          <form clrForm clrLayout="horizontal">
79
+                            <clr-input-container >
80
+                              <label class="clr-col-12 clr-col-md-4">file</label>
81
+                              <input class="clr-col-12 clr-col-md-8" clrInput type="text" name="sqlite-file" [(ngModel)]="sqlite3['connection']['filename']" placeholder="./data/benis.sqlite" required />
82
+                            </clr-input-container>
83
+                          </form>
84
+                        </clr-tab-content>
85
+                      </ng-template>
86
+                    </clr-tab>
87
+                  </clr-tabs>
88
+                </div>
89
+            </div>
90
+            <div class="card-footer">
91
+                <button *ngIf="!saving" class="btn btn-success-outline" (click)="save()">
92
+                <span>Save</span>
93
+                </button>
94
+            </div>
95
+        </div>
96
+    </div>
97
+  `
7 98
 })
8
-export class KnexConfigComponent implements OnInit {
99
+export class KnexConfigComponent implements OnInit{
100
+
101
+  @Input("fbPlugin")
102
+  fbPlugin:string
103
+  conf: KnexConfig
104
+
105
+  pg:PgConfig = {
106
+    client: "pg",
107
+    version: "",
108
+    connection: {
109
+      database: "",
110
+      host: "",
111
+      password: "",
112
+      user: ""
113
+    }
114
+  }
115
+
116
+  mysql:MysqlConfig = {
117
+    client: 'mysql',
118
+    version: "",
119
+    connection: {
120
+      database: "",
121
+      host: "",
122
+      password: "",
123
+      user: ""
124
+    }
125
+  }
126
+
127
+  sqlite3:SqliteConfig = {
128
+    client: "sqlite3",
129
+    connection: {
130
+      filename: ""
131
+    }
132
+  }
133
+
134
+  mode:{[key in KnexDrivers]: boolean} = {
135
+    pg: false,
136
+    mysql: false,
137
+    sqlite3: true
138
+  }
139
+
140
+  async ngOnInit(){
141
+    if(!fb[this.fbPlugin]){
142
+      throw new Error("Knex config component doesn't have fb."+this.fbPlugin)
143
+    }
144
+    const c = await fb[this.fbPlugin].getConfig()
145
+    this.conf = c.dbConf
146
+
147
+    Object.keys(this.mode).forEach(knexType => {
148
+      this.mode[knexType] = knexType === this.conf.client
149
+      if(this.mode[knexType]){
150
+        console.log(knexType, this.conf)
151
+        this[knexType] = this.conf
152
+      }
153
+    })
9 154
 
10
-  constructor() { }
155
+    window['knex'] = this
156
+  }
157
+  
158
+  save(){
159
+    const modeName = Object.entries(this.mode).find(([key, active]) => active)[0]
160
+    fb[this.fbPlugin].setConfigKey('dbConf', this[modeName]).then(console.log)
161
+  }
162
+}
163
+
164
+type KnexDrivers = "pg" | "mysql" | "sqlite3"
165
+
166
+type BaseConfig<Driver extends KnexDrivers> = {
167
+  client: Driver
168
+}
11 169
 
12
-  ngOnInit() {
170
+type PgConfig = BaseConfig<'pg'> & {
171
+  version: string
172
+  connection: {
173
+    host: string,
174
+    user: string,
175
+    password: string,
176
+    database: string
13 177
   }
178
+}
179
+
180
+type MysqlConfig = BaseConfig<'mysql'> &  {
181
+  version: string
182
+  connection: {
183
+    host: string,
184
+    user: string,
185
+    password: string,
186
+    database: string
187
+  }
188
+}
14 189
 
190
+type SqliteConfig = BaseConfig<'sqlite3'> &  {
191
+  connection: {
192
+    filename: string
193
+  }
15 194
 }
195
+
196
+type KnexConfig = SqliteConfig | PgConfig | MysqlConfig

+ 1
- 1
src/app/wallet

@@ -1 +1 @@
1
-Subproject commit 55bbb852bf21a0b90fed1271f8d01b94a89c1c60
1
+Subproject commit ed63a7fc8068a967c57c5eb251ee9e1fdf501dc0

Loading…
Cancel
Save