Quellcode durchsuchen

Persisted user to database from UI

Kris Blassingame vor 6 Jahren
Ursprung
Commit
467ae76049

+ 2
- 2
frontEnd/package.json Datei anzeigen

12
   },
12
   },
13
   "dependencies": {
13
   "dependencies": {
14
     "@angular/animations": "5.2.11",
14
     "@angular/animations": "5.2.11",
15
-    "@angular/common": "5.2.11",
16
-    "@angular/compiler": "5.2.11",
15
+    "@angular/common": "^5.2.11",
16
+    "@angular/compiler": "^5.2.11",
17
     "@angular/compiler-cli": "5.2.11",
17
     "@angular/compiler-cli": "5.2.11",
18
     "@angular/core": "5.2.11",
18
     "@angular/core": "5.2.11",
19
     "@angular/forms": "5.2.11",
19
     "@angular/forms": "5.2.11",

+ 10
- 2
frontEnd/src/app/app.module.ts Datei anzeigen

9
 import { HomePage } from '../pages/home/home';
9
 import { HomePage } from '../pages/home/home';
10
 import { RegisterPage } from '../pages/register/register';
10
 import { RegisterPage } from '../pages/register/register';
11
 import { MainMenuPage } from '../pages/main-menu/main-menu';
11
 import { MainMenuPage } from '../pages/main-menu/main-menu';
12
+import { HttpClientModule } from '@angular/common/http';
13
+import { GoogleMapPage } from '../pages/googleMap/googleMap';
14
+import { RestProvider } from '../providers/rest/rest';
15
+
12
 
16
 
13
 @NgModule({
17
 @NgModule({
14
   declarations: [
18
   declarations: [
16
     HomePage,
20
     HomePage,
17
     GoogleMapComponent,
21
     GoogleMapComponent,
18
     MainMenuPage,
22
     MainMenuPage,
19
-    RegisterPage
23
+    RegisterPage,
24
+    GoogleMapPage
20
     
25
     
21
   ],
26
   ],
22
   imports: [
27
   imports: [
23
     BrowserModule,
28
     BrowserModule,
29
+    HttpClientModule,
24
     IonicModule.forRoot(MyApp)
30
     IonicModule.forRoot(MyApp)
25
   ],
31
   ],
26
   bootstrap: [IonicApp],
32
   bootstrap: [IonicApp],
29
     HomePage,
35
     HomePage,
30
     GoogleMapComponent,
36
     GoogleMapComponent,
31
     MainMenuPage,
37
     MainMenuPage,
32
-    RegisterPage
38
+    RegisterPage,
39
+    GoogleMapPage
33
   ],
40
   ],
34
   providers: [
41
   providers: [
35
     StatusBar,
42
     StatusBar,
36
     SplashScreen,
43
     SplashScreen,
44
+    RestProvider,
37
     {provide: ErrorHandler, useClass: IonicErrorHandler}
45
     {provide: ErrorHandler, useClass: IonicErrorHandler}
38
   ]
46
   ]
39
 })
47
 })

+ 1
- 1
frontEnd/src/pages/home/home.html Datei anzeigen

13
       <b>Login</b>
13
       <b>Login</b>
14
     </button>
14
     </button>
15
     <button class="regButt" ion-button block (click)="register()">
15
     <button class="regButt" ion-button block (click)="register()">
16
-      <b>Register</b>
16
+      <b>Register new account</b>
17
     </button>
17
     </button>
18
 
18
 
19
     <p>Forgot Username/Password?
19
     <p>Forgot Username/Password?

+ 3
- 3
frontEnd/src/pages/register/register.html Datei anzeigen

11
     <ion-list>
11
     <ion-list>
12
 
12
 
13
         <ion-item>
13
         <ion-item>
14
-          <ion-input type="text" placeholder="Username"></ion-input>
14
+          <ion-input type="text" placeholder="Username" [(ngModel)]  = "user.username"></ion-input>
15
         </ion-item>
15
         </ion-item>
16
 
16
 
17
         <ion-item>
17
         <ion-item>
18
-            <ion-input type="text" placeholder="Email"></ion-input>
18
+            <ion-input type="text" placeholder="Email" [(ngModel)]  = "user.email"></ion-input>
19
           </ion-item>
19
           </ion-item>
20
       
20
       
21
         <ion-item>
21
         <ion-item>
22
-          <ion-input type="password" placeholder="Password"></ion-input>
22
+          <ion-input type="password" placeholder="Password" [(ngModel)]  = "user.password"></ion-input>
23
         </ion-item>
23
         </ion-item>
24
       
24
       
25
       </ion-list>
25
       </ion-list>

+ 2
- 0
frontEnd/src/pages/register/register.module.ts Datei anzeigen

1
 import { NgModule } from '@angular/core';
1
 import { NgModule } from '@angular/core';
2
 import { IonicPageModule } from 'ionic-angular';
2
 import { IonicPageModule } from 'ionic-angular';
3
 import { RegisterPage } from './register';
3
 import { RegisterPage } from './register';
4
+import { RestProvider } from '../../providers/rest/rest';
4
 
5
 
5
 @NgModule({
6
 @NgModule({
6
   declarations: [
7
   declarations: [
7
     RegisterPage,
8
     RegisterPage,
9
+    RestProvider
8
   ],
10
   ],
9
   imports: [
11
   imports: [
10
     IonicPageModule.forChild(RegisterPage),
12
     IonicPageModule.forChild(RegisterPage),

+ 8
- 3
frontEnd/src/pages/register/register.ts Datei anzeigen

1
 import { Component } from '@angular/core';
1
 import { Component } from '@angular/core';
2
 import { IonicPage, NavController, NavParams } from 'ionic-angular';
2
 import { IonicPage, NavController, NavParams } from 'ionic-angular';
3
 import { MainMenuPage } from '../main-menu/main-menu';
3
 import { MainMenuPage } from '../main-menu/main-menu';
4
-
4
+import { RestProvider } from '../../providers/rest/rest';
5
 
5
 
6
 @IonicPage()
6
 @IonicPage()
7
 @Component({
7
 @Component({
10
 })
10
 })
11
 export class RegisterPage {
11
 export class RegisterPage {
12
 
12
 
13
-  constructor(public navCtrl: NavController, public navParams: NavParams) {
13
+  user = { username: '', email: '', password: '' }
14
+
15
+  constructor(public navCtrl: NavController, public navParams: NavParams, public rest: RestProvider) {
14
   }
16
   }
15
 
17
 
16
   ionViewDidLoad() {
18
   ionViewDidLoad() {
17
     console.log('ionViewDidLoad RegisterPage');
19
     console.log('ionViewDidLoad RegisterPage');
18
   }
20
   }
19
 
21
 
22
+
23
+
20
   register() {
24
   register() {
25
+    console.log(this.user);
26
+    this.rest.addUser(this.user);
21
     this.navCtrl.setRoot(MainMenuPage);
27
     this.navCtrl.setRoot(MainMenuPage);
22
 
28
 
23
   }
29
   }
24
-
25
 }
30
 }

+ 35
- 0
frontEnd/src/providers/rest/rest.ts Datei anzeigen

1
+import { HttpClient } from '@angular/common/http';
2
+import { Injectable } from '@angular/core';
3
+
4
+
5
+
6
+@Injectable()
7
+export class RestProvider {
8
+
9
+  apiUrl = 'http://localhost:8080';
10
+
11
+  constructor(public http: HttpClient) {
12
+    console.log('Hello RestProvider Provider');
13
+  }
14
+
15
+  getUsers() {
16
+    return new Promise(resolve => {
17
+      this.http.get(this.apiUrl + '/getUsers/').subscribe(data => {
18
+        resolve(data);
19
+      }, err => {
20
+        console.log(err);
21
+      });
22
+    });
23
+  }
24
+
25
+  addUser(data) {
26
+    return new Promise((resolve, reject) => {
27
+      this.http.post(this.apiUrl + '/register', data)
28
+        .subscribe(res => {
29
+          resolve(res);
30
+        }, (err) => {
31
+          reject(err);
32
+        });
33
+    });
34
+  }
35
+}