diff --git a/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts b/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts
index eb71a6f..8552fe0 100644
--- a/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts
+++ b/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts
@@ -1,10 +1,10 @@
-import { Component, OnInit } from '@angular/core';
+import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Month} from '../../models/Month';
import {Observable} from 'rxjs';
import {Term} from '../../models/Term';
import {TermService} from '../../services/term.service';
-import {MatDialog} from '@angular/material';
+import {MatDialog, MatSnackBar} from '@angular/material';
import {DataSources} from '../environments/DataSources';
import {CreateQueryComponent} from '../dialogs/create-query/create-query.component';
import {PeriodicElement} from '../term-list/term-list.component';
@@ -24,7 +24,7 @@ export class TermListAdminComponent implements OnInit {
allTerms$: Observable
>;
- constructor(private termService: TermService, private termAdminService: TermAdminService, public dialog: MatDialog) {
+ constructor(private termService: TermService, private termAdminService: TermAdminService, public dialog: MatDialog, public snackBar: MatSnackBar) {
this.yearsList = DataSources.yearsList;
this.monthsList = DataSources.monthsList;
}
@@ -39,26 +39,24 @@ export class TermListAdminComponent implements OnInit {
}
search() {
- console.log(this.form.value);
this.termService.getTerms(this.form.controls.year.value, this.form.controls.month.value);
}
editTerm(event: Term) {
- console.log('asdasdasd');
this.openDialog(event);
}
deleteTerm(event: Term) {
- const date = new Date(event.date);
- event.date = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDay();
+ event.date = event.date;
event.status = 'wolny';
event.contractno = '';
- console.log('data ', event.date);
- this.termAdminService.deleteTerm(event);
- }
-
- post() {
- this.termAdminService.postTest();
+ this.termAdminService.deleteTerm(event).subscribe(
+ x => {
+ this.openSnackBar('Zwolniono termin !');
+ },
+ error => {
+ this.openSnackBar('Coś poszło nie tak.. Spróbuj ponownie');
+ });
}
openDialog(term: Term): void {
@@ -72,4 +70,10 @@ export class TermListAdminComponent implements OnInit {
});
}
+ openSnackBar(message: string) {
+ this.snackBar.open(message, null, {
+ duration: 2500,
+ });
+ }
+
}
diff --git a/szt-visio-app/src/app/models/NewTerms.ts b/szt-visio-app/src/app/models/NewTerms.ts
new file mode 100644
index 0000000..939192a
--- /dev/null
+++ b/szt-visio-app/src/app/models/NewTerms.ts
@@ -0,0 +1,9 @@
+export class NewTerms {
+ months: number[];
+ year: number
+
+ constructor() {
+ this.months = [];
+ this.year = null;
+ }
+}
diff --git a/szt-visio-app/src/app/services/auth-guards.service.spec.ts b/szt-visio-app/src/app/services/auth-guards.service.spec.ts
new file mode 100644
index 0000000..4a635e5
--- /dev/null
+++ b/szt-visio-app/src/app/services/auth-guards.service.spec.ts
@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { AuthGuardsService } from './auth-guards.service';
+
+describe('AuthGuardsService', () => {
+ beforeEach(() => TestBed.configureTestingModule({}));
+
+ it('should be created', () => {
+ const service: AuthGuardsService = TestBed.get(AuthGuardsService);
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/szt-visio-app/src/app/services/auth-guards.service.ts b/szt-visio-app/src/app/services/auth-guards.service.ts
new file mode 100644
index 0000000..7e5ef7f
--- /dev/null
+++ b/szt-visio-app/src/app/services/auth-guards.service.ts
@@ -0,0 +1,22 @@
+import {Injectable} from '@angular/core';
+import {CanActivate} from '@angular/router/src/interfaces';
+import {ActivatedRouteSnapshot, Router, RouterStateSnapshot} from '@angular/router';
+import {AngularFireAuth} from 'angularfire2/auth';
+import {AuthService} from './auth.service';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AuthGuardsService implements CanActivate {
+
+ constructor(private authService: AuthService, private router: Router) {
+ }
+
+ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
+ if (this.authService.user) {
+ return true;
+ }
+ this.router.navigate(['/login']);
+ return false;
+ }
+}
diff --git a/szt-visio-app/src/app/services/auth.service.spec.ts b/szt-visio-app/src/app/services/auth.service.spec.ts
new file mode 100644
index 0000000..f3d964d
--- /dev/null
+++ b/szt-visio-app/src/app/services/auth.service.spec.ts
@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { AuthService } from './auth.service';
+
+describe('AuthService', () => {
+ beforeEach(() => TestBed.configureTestingModule({}));
+
+ it('should be created', () => {
+ const service: AuthService = TestBed.get(AuthService);
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/szt-visio-app/src/app/services/auth.service.ts b/szt-visio-app/src/app/services/auth.service.ts
new file mode 100644
index 0000000..8b51eca
--- /dev/null
+++ b/szt-visio-app/src/app/services/auth.service.ts
@@ -0,0 +1,40 @@
+import {Injectable} from '@angular/core';
+import {AngularFireAuth} from 'angularfire2/auth';
+import {User} from 'firebase';
+import {Router} from '@angular/router';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AuthService {
+
+ user: User;
+
+ constructor(private angularFireAuth: AngularFireAuth, private router: Router) {
+ angularFireAuth.authState.subscribe(user => {
+ this.user = user;
+ });
+ }
+
+ login(email: string, password: string) {
+ this.angularFireAuth.auth.signInWithEmailAndPassword(email, password).then(user => {
+ console.log(user);
+ this.router.navigate(['/admin']);
+ }).catch(err => {
+ console.log(err);
+ });
+ }
+
+ register() {
+ this.angularFireAuth.auth.createUserWithEmailAndPassword('test@op.pl', 'password').then(user => {
+ console.log(user);
+ }).catch(err => {
+ console.log(err);
+ });
+ }
+
+ logout() {
+ this.angularFireAuth.auth.signOut();
+ this.router.navigate(['']);
+ }
+}
diff --git a/szt-visio-app/src/app/services/termin-admin-service.service.ts b/szt-visio-app/src/app/services/termin-admin-service.service.ts
index 4d9bc7e..a38ca5a 100644
--- a/szt-visio-app/src/app/services/termin-admin-service.service.ts
+++ b/szt-visio-app/src/app/services/termin-admin-service.service.ts
@@ -1,8 +1,9 @@
-import { Injectable } from '@angular/core';
+import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {environment} from '../../environments/environment';
import {Term} from '../models/Term';
import {RequestOptions} from '@angular/http';
+import {NewTerms} from '../models/NewTerms';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
@@ -12,9 +13,10 @@ const httpOptions = {
providedIn: 'root'
})
export class TermAdminService {
- endpoint = 'term'
+ endpoint = 'term';
- constructor(private httpClient: HttpClient) { }
+ constructor(private httpClient: HttpClient) {
+ }
deleteTerm(term: any) {
const headers = new HttpHeaders();
@@ -25,17 +27,10 @@ export class TermAdminService {
// @ts-ignore
return this.httpClient.delete(environment.API_BACK + this.endpoint, new RequestOptions({
+ // @ts-ignore
headers: headers,
body: term
- }))
- .subscribe(
- x => {
- console.log('usunięto');
- },
- err => {
- console.log('błąd usuwania');
- }
- );
+ }));
}
updateTerm(term: any) {
@@ -43,54 +38,12 @@ export class TermAdminService {
headers.set('Content-Type', 'application/json; charset=utf-8');
headers.set('Access-Control-Allow-Origin', '*');
headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
-
-
// @ts-ignore
- return this.httpClient.put(environment.API_BACK + this.endpoint, term, headers)
- .subscribe(
- x => {
- console.log('zaktualizowane');
- },
- err => {
- console.log('niezaktualizowano');
- }
- );
+ return this.httpClient.put(environment.API_BACK + this.endpoint, term, headers);
}
- postTest() {
- console.log('testuje');
- const headers = new HttpHeaders();
- headers.set('Content-Type', 'application/json');
- this.httpClient.post('http://localhost:8080/test', {'asdasd': 15561}, httpOptions)
- .subscribe(
- x => {
- console.log('usunięto');
- },
- err => {
- console.log('błąd usuwania');
- });
- // this.httpClient.delete('http://localhost:8080/test', {headers: headers})
- // .subscribe(
- // x => {
- // console.log('usunięto');
- // },
- // err => {
- // console.log('błąd usuwania');
- // });
+ createTerm(newTerms: NewTerms) {
+ return this.httpClient.post(environment.API_BACK + this.endpoint, newTerms, httpOptions);
}
- deleteTest() {
- const headers = new HttpHeaders();
- headers.set('Content-Type', 'application/json');
- this.httpClient.delete('http://localhost:8080/test', httpOptions)
- .subscribe(
- x => {
- console.log('usunięto');
- },
- err => {
- console.log('błąd usuwania');
- });
- }
-
-
}