1
- // //#region @notForNpm
2
- // //#region imports
3
- // import { Firedev } from 'firedev';
4
- // import { HOST_BACKEND_PORT } from './app.hosts';
5
- // //#region @browser
6
- // import { NgModule, NgZone, ViewEncapsulation } from '@angular/core';
7
- // import { Component, OnInit } from '@angular/core';
8
- // import { PreloadAllModules, RouterModule, Routes } from "@angular/router";
1
+ //#region imports
2
+ import { Firedev , BaseContext } from 'firedev/src' ;
3
+ import { Observable , map } from 'rxjs' ;
4
+ import { HOST_BACKEND_PORT } from './app.hosts' ;
5
+ //#region @browser
6
+ import { NgModule , inject , Injectable } from '@angular/core' ;
7
+ import { Component , OnInit } from '@angular/core' ;
8
+ import { CommonModule } from '@angular/common' ;
9
+ //#endregion
10
+ //#endregion
9
11
10
- // //#endregion
11
- // //#endregion
12
+ console . log ( 'hello world' ) ;
13
+ console . log ( 'Your server will start on port ' + HOST_BACKEND_PORT ) ;
14
+ const host = 'http://localhost:' + HOST_BACKEND_PORT ;
12
15
13
- // //#region @browser
16
+ //#region static-columns component
17
+ //#region @browser
18
+ @Component ( {
19
+ selector : 'app-static-columns' ,
20
+ template : `hello from static-columns<br>
21
+ <br>
22
+ users from backend
23
+ <ul>
24
+ <li *ngFor="let user of (users$ | async)"> {{ user | json }} </li>
25
+ </ul>
26
+ ` ,
27
+ styles : [ ` body { margin: 0px !important; } ` ] ,
28
+ } )
29
+ export class StaticColumnsComponent {
30
+ userApiService = inject ( UserApiService ) ;
31
+ readonly users$ : Observable < User [ ] > = this . userApiService . getAll ( ) ;
32
+ }
33
+ //#endregion
34
+ //#endregion
14
35
15
- // //#region routes
16
- // const routes: Routes = [
17
- // {
18
- // path: '',
19
- // loadChildren: () => import('./app/preview/preview.module')
20
- // .then(m => m.PreviewModule),
21
- // },
22
- // ];
23
- // //#endregion
36
+ //#region static-columns api service
37
+ //#region @browser
38
+ @Injectable ( {
39
+ providedIn :'root'
40
+ } )
41
+ export class UserApiService {
42
+ userControlller = Firedev . inject ( ( ) => MainContext . get ( UserController ) )
43
+ getAll ( ) {
44
+ return this . userControlller . getAll ( )
45
+ . received
46
+ . observable
47
+ . pipe ( map ( r => r . body . json ) ) ;
48
+ }
49
+ }
50
+ //#endregion
51
+ //#endregion
24
52
25
- // //#region main component
26
- // @Component ({
27
- // selector: 'app-static-columns',
28
- // encapsulation: ViewEncapsulation.None,
29
- // styleUrls: ['./app.scss'],
30
- // templateUrl: './app.html',
31
- // })
32
- // export class StaticColumnsComponent {
33
- // constructor(
34
- // private ngZone: NgZone
35
- // ) { }
53
+ //#region static-columns module
54
+ //#region @browser
55
+ @NgModule ( {
56
+ exports : [ StaticColumnsComponent ] ,
57
+ imports : [ CommonModule ] ,
58
+ declarations : [ StaticColumnsComponent ] ,
59
+ } )
60
+ export class StaticColumnsModule { }
61
+ //#endregion
62
+ //#endregion
36
63
37
- // }
38
- // //#endregion
64
+ //#region static-columns entity
65
+ @Firedev . Entity ( { className : 'User' } )
66
+ class User extends Firedev . Base . AbstractEntity {
67
+ public static ctrl ?: UserController ;
68
+ //#region @websql
69
+ @Firedev . Orm . Column . String ( )
70
+ //#endregion
71
+ name ?: string ;
72
+ }
73
+ //#endregion
39
74
40
- // //#region main module
41
- // @NgModule ({
42
- // imports: [
43
- // RouterModule.forRoot(routes, {
44
- // useHash: true,
45
- // preloadingStrategy: PreloadAllModules,
46
- // enableTracing: false,
47
- // }),
48
- // ],
49
- // exports: [StaticColumnsComponent],
50
- // declarations: [StaticColumnsComponent],
51
- // providers: [],
52
- // })
53
- // export class StaticColumnsModule { }
54
- // //#endregion
55
- // //#endregion
75
+ //#region static-columns controller
76
+ @Firedev . Controller ( { className : 'UserController' } )
77
+ class UserController extends Firedev . Base . CrudController < User > {
78
+ entityClassResolveFn = ( ) => User ;
79
+ //#region @websql
80
+ async initExampleDbData ( ) : Promise < void > {
81
+ const superAdmin = new User ( ) ;
82
+ superAdmin . name = 'super-admin' ;
83
+ await this . db . save ( superAdmin ) ;
84
+ }
85
+ //#endregion
86
+ }
87
+ //#endregion
56
88
57
- // //#region firedev start function
58
- // async function start() {
59
- // const host = `http://localhost:${HOST_BACKEND_PORT}`;
60
- // // Firedev.enableProductionMode();
89
+ //#region static-columns context
90
+ const MainContext = Firedev . createContext ( ( ) => ( {
91
+ host,
92
+ contextName : 'MainContext' ,
93
+ contexts :{ BaseContext } ,
94
+ controllers : {
95
+ UserController,
96
+ // PUT FIREDEV CONTORLLERS HERE
97
+ } ,
98
+ entities : {
99
+ User,
100
+ // PUT FIREDEV ENTITIES HERE
101
+ } ,
102
+ database : true ,
103
+ disabledRealtime : true ,
104
+ } ) ) ;
105
+ //#endregion
61
106
62
- // const context = await Firedev.init({
63
- // host,
64
- // controllers: [
65
- // // PUT FIREDEV CONTORLLERS HERE
66
- // ],
67
- // entities: [
68
- // // PUT FIREDEV ENTITIES HERE
69
- // ],
70
- // //#region @websql
71
- // config: {
72
- // type: 'better-sqlite3',
73
- // database: 'tmp-db.sqlite',
74
- // logging: false,
75
- // }
76
- // //#endregion
77
- // });
78
- // //#region @backend
79
- // // if (Firedev.isNode) {
80
- // // context.node.app.get('/hello', (req, res) => {
81
- // // res.send('Hello static-columns')
82
- // // })
83
- // // }
84
- // //#endregion
85
- // }
86
- // //#endregion
107
+ async function start ( ) {
87
108
88
- // export default start;
89
- // //#endregion
109
+ await MainContext . initialize ( ) ;
110
+
111
+ if ( Firedev . isBrowser ) {
112
+ const users = ( await MainContext . getClassInstance ( UserController ) . getAll ( ) . received )
113
+ . body ?. json ;
114
+ console . log ( {
115
+ 'users from backend' : users ,
116
+ } ) ;
117
+ }
118
+ }
119
+
120
+ export default start ;
0 commit comments