Add working logic for home

This commit is contained in:
corner 2019-10-29 15:50:23 +01:00
parent a3cdbd81c3
commit 00dc53580c
9 changed files with 146 additions and 107 deletions

View File

@ -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);

View File

@ -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
]
{
"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
]
}

View File

@ -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",

View File

@ -12,5 +12,8 @@
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"pug": "^2.0.4"
},
"devDependencies": {
"cors": "^2.8.5"
}
}

View File

@ -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;

View File

@ -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]

View File

@ -1 +1,6 @@
<p>home works!</p>
<div class="container" *ngIf="data | async as data ">
<div *ngFor="let item of data.data; let i = index">
{{ i + 1 }}. {{ item ? 'Gereserveerd' : 'Niet gereserveerd' }}
<a [href]="'mailto:doemiddag.hetheerenlanden@cvo-av.nl?subject=Reservatie Surprise box ' + (i + 1)">Reserveer</a>
</div>
</div>

View File

@ -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<ApiData>;
constructor(private dataService: DataService) { }
ngOnInit() {
this.data = this.dataService.getData();
}
}

View File

@ -1,9 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
export interface ApiData {
data: Array<boolean>;
}
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor() { }
constructor(private http: HttpClient) { }
getData(): Observable<ApiData> {
return this.http.get<ApiData>('http://localhost:3000');
}
}