From 00dc53580cc54e361ea986bf87df084ef6c9a1c8 Mon Sep 17 00:00:00 2001 From: Job Vonk Date: Tue, 29 Oct 2019 15:50:23 +0100 Subject: [PATCH] Add working logic for home --- server/app.js | 2 + server/database/data.json | 206 ++++++++++---------- server/package-lock.json | 10 + server/package.json | 3 + server/routes/index.js | 2 +- src/app/app.module.ts | 4 +- src/app/components/home/home.component.html | 7 +- src/app/components/home/home.component.ts | 7 +- src/app/services/data.service.ts | 12 +- 9 files changed, 146 insertions(+), 107 deletions(-) diff --git a/server/app.js b/server/app.js index c7a42c8..1d29be9 100644 --- a/server/app.js +++ b/server/app.js @@ -3,6 +3,7 @@ var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); +const cors = require('cors'); var indexRouter = require('./routes/index'); @@ -16,6 +17,7 @@ app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); +app.use(cors()) app.use(express.static(path.join(__dirname, 'public'))); app.use('/', indexRouter); diff --git a/server/database/data.json b/server/database/data.json index 01d9236..da72eb0 100644 --- a/server/database/data.json +++ b/server/database/data.json @@ -1,102 +1,104 @@ -[ - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false -] \ No newline at end of file +{ + "data": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ] +} diff --git a/server/package-lock.json b/server/package-lock.json index de5e59a..596e4ad 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -206,6 +206,16 @@ "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.10.tgz", "integrity": "sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA==" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dev": true, + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", diff --git a/server/package.json b/server/package.json index 6fd12b3..7defeb6 100644 --- a/server/package.json +++ b/server/package.json @@ -12,5 +12,8 @@ "http-errors": "~1.6.3", "morgan": "~1.9.1", "pug": "^2.0.4" + }, + "devDependencies": { + "cors": "^2.8.5" } } diff --git a/server/routes/index.js b/server/routes/index.js index f148084..e744cab 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -5,7 +5,7 @@ var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { - res.json(JSON.parse(fs.readFileSync('../database/data.json').toString())); + res.json(JSON.parse(fs.readFileSync(__dirname + '/../database/data.json').toString())); }); module.exports = router; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 826bfe8..b6e6294 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; +import { HttpClientModule } from '@angular/common/http'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -14,7 +15,8 @@ import { LoginComponent } from './components/login/login.component'; ], imports: [ BrowserModule, - AppRoutingModule + AppRoutingModule, + HttpClientModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/components/home/home.component.html b/src/app/components/home/home.component.html index 5f2c53f..953253e 100644 --- a/src/app/components/home/home.component.html +++ b/src/app/components/home/home.component.html @@ -1 +1,6 @@ -

home works!

+
+
+ {{ i + 1 }}. {{ item ? 'Gereserveerd' : 'Niet gereserveerd' }} + Reserveer +
+
diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index f56c8c1..9c957d6 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { ApiData, DataService } from 'src/app/services/data.service'; @Component({ selector: 'app-home', @@ -7,9 +9,12 @@ import { Component, OnInit } from '@angular/core'; }) export class HomeComponent implements OnInit { - constructor() { } + data: Observable; + + constructor(private dataService: DataService) { } ngOnInit() { + this.data = this.dataService.getData(); } } diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index 750557b..bdaa70c 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -1,9 +1,19 @@ import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +export interface ApiData { + data: Array; +} @Injectable({ providedIn: 'root' }) export class DataService { - constructor() { } + constructor(private http: HttpClient) { } + + getData(): Observable { + return this.http.get('http://localhost:3000'); + } }