diff --git a/backend/src/main/java/appSpring/restController/UserRestController.java b/backend/src/main/java/appSpring/restController/UserRestController.java index a988920..0efc10c 100644 --- a/backend/src/main/java/appSpring/restController/UserRestController.java +++ b/backend/src/main/java/appSpring/restController/UserRestController.java @@ -35,6 +35,7 @@ public class UserRestController { public interface UserDetail extends User.Basic, User.Act, User.Fin, Fine.Basic, Action.Basic {} + public interface UserBasic extends User.LoginInt {} @Autowired private UserService userService; @@ -84,7 +85,7 @@ public ResponseEntity getUser(@PathVariable int id, Authentication authent } @CrossOrigin(origins = "http://localhost:4200") - @JsonView(UserDetail.class) + @JsonView(UserBasic.class) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public ResponseEntity deleteUser(@PathVariable Integer id, HttpSession session, Authentication authentication) { diff --git a/backend/target/appSpring-0.0.1.jar b/backend/target/appSpring-0.0.1.jar index edb645a..1c899f0 100644 Binary files a/backend/target/appSpring-0.0.1.jar and b/backend/target/appSpring-0.0.1.jar differ diff --git a/backend/target/appSpring-0.0.1.jar.original b/backend/target/appSpring-0.0.1.jar.original index 0ca9392..08a8a41 100644 Binary files a/backend/target/appSpring-0.0.1.jar.original and b/backend/target/appSpring-0.0.1.jar.original differ diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 314b013..0b9d5e9 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -9,6 +9,5 @@ import { Component } from '@angular/core'; export class AppComponent { constructor() { - localStorage.clear(); } } diff --git a/frontend/src/app/component/admin/admin-routing.module.ts b/frontend/src/app/component/admin/admin-routing.module.ts index e23eb1d..2589259 100644 --- a/frontend/src/app/component/admin/admin-routing.module.ts +++ b/frontend/src/app/component/admin/admin-routing.module.ts @@ -30,8 +30,8 @@ const adminRoutes: Routes = [ {path: 'loans', component: ManageLoansComponent}, {path: 'fines', component: ManageFinesComponent}, {path: 'users', component: ManageUsersComponent}, - {path: 'user/:id', component: EditUserComponent}, - {path: 'user/new', component: CreateUserComponent}, + {path: 'users/new', component: CreateUserComponent}, + {path: 'users/:id', component: EditUserComponent}, {path: '', component: DashboardComponent} ] } diff --git a/frontend/src/app/component/admin/manage-users/create/create.component.html b/frontend/src/app/component/admin/manage-users/create/create.component.html index 1d22eee..6196ea5 100644 --- a/frontend/src/app/component/admin/manage-users/create/create.component.html +++ b/frontend/src/app/component/admin/manage-users/create/create.component.html @@ -1,66 +1,65 @@ -
- -
-

- Administración de usuarios - Administra los usuarios -

- -
-
-
-
-

Nuevo usuario

-
-
-
-
-
- -
- - - -
-
- - -
-
- - -
-
- -
+ +
+

+ Administración de usuarios + Administra los usuarios +

+ +
+
+
+
+

Nuevo usuario

+
+
+
+
+
+ +
+ + + +
+
+ + +
+
+ +
-
-
- - -
-
- - -
-
- - -
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
-
-
+
+
diff --git a/frontend/src/app/component/admin/manage-users/create/create.component.ts b/frontend/src/app/component/admin/manage-users/create/create.component.ts index eeee5c5..c5d48ec 100644 --- a/frontend/src/app/component/admin/manage-users/create/create.component.ts +++ b/frontend/src/app/component/admin/manage-users/create/create.component.ts @@ -7,7 +7,7 @@ import {SessionService} from '../../../../service/session.service'; import {UserService} from '../../../../service/user.service'; @Component({ - templateUrl: './create.component.html' + templateUrl: 'create.component.html' }) export class CreateUserComponent implements OnInit { @@ -23,9 +23,8 @@ export class CreateUserComponent implements OnInit { create(firstName: string, lastName1: string, lastName2: string, name: string, email: string, password: string, dni: string, telephone: string) { let createdUser: User = { - name: name, dni: dni, firstName: firstName, lastName1: lastName1, lastName2: lastName2, email: email, - telephone: telephone, literaryHobby: [] - }; + name: name, passwordHash: password, dni: dni, firstName: firstName, lastName1: lastName1, lastName2: lastName2, email: email, + telephone: telephone, literaryHobby: [], roles: ["ROLE_USER"]}; this.userService.createUser(createdUser).subscribe( response => { console.log(name + " successfully created."); diff --git a/frontend/src/app/component/admin/manage-users/edit/edit.component.html b/frontend/src/app/component/admin/manage-users/edit/edit.component.html index 828045a..eaab5db 100644 --- a/frontend/src/app/component/admin/manage-users/edit/edit.component.html +++ b/frontend/src/app/component/admin/manage-users/edit/edit.component.html @@ -1,48 +1,47 @@ -
-
-

- Administración de usuarios - Administra los usuarios -

- -
-
-
-
-

Editar {{user?.name}}

-
-
-
-
-
- -
- - - -
-
- - -
-
- - -
-
- -
+
+

+ Administración de usuarios + Administra los usuarios +

+ +
+
+
+
+

Editar {{user?.name}}

+
+
+
+
+
+ +
+ + + +
+
+ + +
+
+ + +
+
+
-
-
+
+
diff --git a/frontend/src/app/component/admin/manage-users/edit/edit.component.ts b/frontend/src/app/component/admin/manage-users/edit/edit.component.ts index d73e146..f527b19 100644 --- a/frontend/src/app/component/admin/manage-users/edit/edit.component.ts +++ b/frontend/src/app/component/admin/manage-users/edit/edit.component.ts @@ -7,7 +7,7 @@ import {SessionService} from '../../../../service/session.service'; import {UserService} from '../../../../service/user.service'; @Component({ - templateUrl: './edit.component.html' + templateUrl: 'edit.component.html' }) export class EditUserComponent implements OnInit { diff --git a/frontend/src/app/component/admin/manage-users/manage-users.component.css b/frontend/src/app/component/admin/manage-users/manage-users.component.css deleted file mode 100644 index e69de29..0000000 diff --git a/frontend/src/app/component/admin/manage-users/manage-users.component.html b/frontend/src/app/component/admin/manage-users/manage-users.component.html index c98ddbf..3317fe4 100644 --- a/frontend/src/app/component/admin/manage-users/manage-users.component.html +++ b/frontend/src/app/component/admin/manage-users/manage-users.component.html @@ -1,55 +1,60 @@ -
-
- ¡Eliminado! {{message}} -
-
- Algo ha ido mal... {{message}} -
-
-

- Administración de usuarios - Administra los usuarios -

- -
-
- - +
+ ¡Eliminado! {{message}} +
+
+ Algo ha ido mal... {{message}} +
+
+

+ Administración de usuarios + Administra los usuarios +

+ +
+
+
+ + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - -
Nombre y apellidosUsuarioRol(es)MultasPréstamosAdministrar
Nombre y apellidosUsuarioRol(es)MultasPréstamosAdministrar{{user?.firstName}} {{user?.lastName1}} {{user?.lastName2}}{{user?.name}}{{user?.roles?.length}}{{user.penalties?.length}}{{user.actions?.length}} + + + +    + +
{{user.firstName}} {{user.lastName1}} {{user.lastName2}}{{user.name}}{{user.roles?.length}}{{user.penalties?.length}}{{user.actions?.length}} - - - -    - -
- - - -
-
+ + + +
+ +
+ + +
+
+ diff --git a/frontend/src/app/component/admin/manage-users/manage-users.component.spec.ts b/frontend/src/app/component/admin/manage-users/manage-users.component.spec.ts deleted file mode 100644 index dbb6995..0000000 --- a/frontend/src/app/component/admin/manage-users/manage-users.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ManageUsersComponent } from './manage-users.component'; - -describe('ManageUsersComponent', () => { - let component: ManageUsersComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ ManageUsersComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(ManageUsersComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/frontend/src/app/component/admin/manage-users/manage-users.component.ts b/frontend/src/app/component/admin/manage-users/manage-users.component.ts index aeb1f52..31cc390 100644 --- a/frontend/src/app/component/admin/manage-users/manage-users.component.ts +++ b/frontend/src/app/component/admin/manage-users/manage-users.component.ts @@ -7,27 +7,87 @@ import {SessionService} from '../../../service/session.service'; import {UserService} from '../../../service/user.service'; @Component({ - selector: 'app-manage-users', - templateUrl: './manage-users.component.html', - styleUrls: ['./manage-users.component.css'] + templateUrl: 'manage-users.component.html' }) export class ManageUsersComponent implements OnInit { errorMessage: boolean; message: String; + showNextPage: boolean; + showPreviousPage: boolean; successMessage: boolean; users: User[]; + usersPage: number; constructor(private router: Router, private userService: UserService, private sessionService: SessionService) { this.successMessage = false; this.errorMessage = false; + this.users = []; + this.usersPage = 0; + this.showNextPage = true; + this.showPreviousPage = false; } ngOnInit() { if (!this.sessionService.checkCredentials()) { - this.router.navigate(['/login']); + this.router.navigate(["/login"]); } else { - this.users = this.userService.getAllUsers(); + this.getUsers(); + } + } + + getUsers() { + this.userService.getUsers(this.usersPage).subscribe( + users => this.users = users, + error => console.log("Fail trying to get current page of users.") + ); + } + + nextPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.usersPage++; + this.getUsers(); + this.checkNextPage(); + this.showPreviousPage = true; + } + + previousPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.usersPage--; + this.getUsers(); + this.checkPreviousPage(); + this.showNextPage = true; + } + + checkNextPage() { + this.userService.getUsers(this.usersPage + 1).subscribe( + users => { + console.log(this.usersPage + 1 + users); + if (Object.keys(users).length === 0) { + this.showNextPage = false; + } else { + this.showNextPage = true; + } + } + ); + } + + checkPreviousPage() { + if (this.usersPage > 0) { + this.userService.getUsers(this.usersPage - 1).subscribe( + users => { + console.log(this.usersPage + users); + if (Object.keys(users).length === 0) { + this.showPreviousPage = false; + } else { + this.showPreviousPage = true; + } + } + ); + } else { + this.showPreviousPage = false; } } @@ -37,7 +97,16 @@ export class ManageUsersComponent implements OnInit { this.successMessage = true; this.errorMessage = false; this.message = 'Usuario eliminado correctamente.'; + this.usersPage = 0; console.log('User successfully deleted.'); + this.userService.getUsers(this.usersPage).subscribe( + users => { + this.users = users; + }, + error => console.log("Fail trying to get all users.") + ); + this.checkNextPage(); + this.checkPreviousPage(); }, error => { this.successMessage = false; diff --git a/frontend/src/app/component/public/home/home.component.ts b/frontend/src/app/component/public/home/home.component.ts index 8ae47cc..fe54ff2 100644 --- a/frontend/src/app/component/public/home/home.component.ts +++ b/frontend/src/app/component/public/home/home.component.ts @@ -59,6 +59,7 @@ export class HomeComponent implements OnInit { this.resourceService.getAllResources('Libro', this.booksPage).subscribe( books => { if (books[1] === undefined) { + console.log('No hay más libros.'); this.moreBooksActive = false; } else if (userReq) { this.moreBooksActive = true; diff --git a/frontend/src/app/service/session.service.ts b/frontend/src/app/service/session.service.ts index ca7ea38..e035e2c 100644 --- a/frontend/src/app/service/session.service.ts +++ b/frontend/src/app/service/session.service.ts @@ -1,4 +1,4 @@ -import {Injectable} from '@angular/core'; +import {Injectable, OnDestroy} from '@angular/core'; import {Headers, Http} from '@angular/http'; import 'rxjs/Rx'; import {Observable} from 'rxjs/Observable'; @@ -13,7 +13,12 @@ import {UserService} from '../service/user.service'; import {ResourceCopyService} from '../service/resource-copy.service'; @Injectable() -export class SessionService { +export class SessionService implements OnDestroy { + + ngOnDestroy() { + console.log("localStorage called from ngOnDestroy"); + localStorage.clear(); + } user: User; authCreds: string; @@ -25,15 +30,17 @@ export class SessionService { private resourceCopyService: ResourceCopyService) { } + + logIn(username: string, password: string) { this.authCreds = btoa(username + ':' + password); let headers: Headers = new Headers(); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.get(LOGIN_URL, {headers: headers}) .map( response => { let id = response.json().id; + localStorage.setItem("creds", this.authCreds); this.userService.setAuthHeaders(this.authCreds); this.userService.getUser(id).subscribe( user => { @@ -43,6 +50,7 @@ export class SessionService { }, error => console.log(error) ); + localStorage.setItem("creds", this.authCreds); localStorage.setItem("user", username); this.actionService.setAuthHeaders(this.authCreds); this.fileService.setAuthHeaders(this.authCreds); diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts index 4fdaeba..77a024b 100644 --- a/frontend/src/app/service/user.service.ts +++ b/frontend/src/app/service/user.service.ts @@ -24,30 +24,17 @@ export class UserService { return this.user; } - getAllUsers() { - let page = 0; - let morePages = true; + getUsers(page: number) { + this.authCreds = localStorage.getItem("creds"); let headers: Headers = new Headers(); headers.append('Authorization', 'Basic ' + this.authCreds); - while (morePages) { - this.http.get(USER_URL + '?page=' + page, {headers: headers}) - .map(response => response.json().content) - .catch(error => Observable.throw('Server error') - ).subscribe( - response => { - if (response[1] === undefined) { - morePages = false; - } else { - this.users = this.users.concat(response); - } - } - ); - page++; - } - return this.users; + return this.http.get(USER_URL + '?page=' + page, {headers: headers}) + .map(response => response.json().content) + .catch(error => Observable.throw('Server error')); } getUser(id: number) { + this.authCreds = localStorage.getItem("creds"); let headers: Headers = new Headers(); headers.append('Authorization', 'Basic ' + this.authCreds); return this.http.get(USER_URL + '/' + id.toString(), {headers: headers}) @@ -59,6 +46,7 @@ export class UserService { } updateUser(user: User, current: boolean) { + this.authCreds = localStorage.getItem("creds"); let body = JSON.stringify(user); let headers: Headers = new Headers(); headers.append('Content-Type', 'application/json'); @@ -87,6 +75,7 @@ export class UserService { } deleteUser(id: number) { + this.authCreds = localStorage.getItem("creds"); let headers: Headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('X-Requested-With', 'XMLHttpRequest'); @@ -97,6 +86,7 @@ export class UserService { } createUser(user: User) { + this.authCreds = localStorage.getItem("creds"); let body = JSON.stringify(user); let headers: Headers = new Headers(); headers.append('Content-Type', 'application/json');