diff --git a/backend/src/main/java/appSpring/model/Action.java b/backend/src/main/java/appSpring/model/Action.java index 3b461f3..bbdd951 100644 --- a/backend/src/main/java/appSpring/model/Action.java +++ b/backend/src/main/java/appSpring/model/Action.java @@ -58,8 +58,6 @@ protected Action() { public Action(Date dateLoanInit) { this.dateLoanInit = dateLoanInit; - dateLoanReturn = new Date(0); - dateLoanGiven = new Date(0); } public Integer getID() { diff --git a/backend/src/main/java/appSpring/restController/FileRestController.java b/backend/src/main/java/appSpring/restController/FileRestController.java index d7611a9..a48aba7 100644 --- a/backend/src/main/java/appSpring/restController/FileRestController.java +++ b/backend/src/main/java/appSpring/restController/FileRestController.java @@ -14,28 +14,18 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.annotation.JsonView; - -import appSpring.model.Fine; -import appSpring.model.ResourceCopy; -import appSpring.model.User; - import appSpring.service.UserService; import appSpring.service.ResourceService; @RestController @RequestMapping("/api/files") public class FileRestController { - - public interface FineDetail extends Fine.Basic, Fine.ResoCopy, Fine.Usr, ResourceCopy.Basic, User.Basic { - } @Autowired private UserService userService; @Autowired private ResourceService resourceService; - @JsonView(FineDetail.class) @RequestMapping(value = "/user/{id}", method = RequestMethod.GET) public ResponseEntity getUserfile(@PathVariable int id, Authentication authentication, HttpSession session, HttpServletRequest request) throws IOException { @@ -48,7 +38,6 @@ public ResponseEntity getUserfile(@PathVariable int id, Authentication a } } - @JsonView(FineDetail.class) @RequestMapping(value = "/resource/{id}", method = RequestMethod.GET) public ResponseEntity getResourceFile(@PathVariable int id, Authentication authentication, HttpSession session, HttpServletRequest request) throws IOException { diff --git a/backend/src/main/java/appSpring/restController/ResourceRestController.java b/backend/src/main/java/appSpring/restController/ResourceRestController.java index 4bea1b2..d1d3a71 100644 --- a/backend/src/main/java/appSpring/restController/ResourceRestController.java +++ b/backend/src/main/java/appSpring/restController/ResourceRestController.java @@ -151,5 +151,15 @@ public ResponseEntity putUserImage(@PathVariable Integer id, return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } + + @JsonView(ResourceDetail.class) + @RequestMapping(value = "/all", method = RequestMethod.GET) + public ResponseEntity> getAllResources(HttpSession session) { + + session.setMaxInactiveInterval(-1); + + List resources = resourceService.findAll(); + return new ResponseEntity<>(resources, HttpStatus.OK); + } } diff --git a/backend/src/main/java/appSpring/security/RestSecurityConfiguration.java b/backend/src/main/java/appSpring/security/RestSecurityConfiguration.java index 580fa7f..e5b779d 100644 --- a/backend/src/main/java/appSpring/security/RestSecurityConfiguration.java +++ b/backend/src/main/java/appSpring/security/RestSecurityConfiguration.java @@ -27,7 +27,7 @@ protected void configure(HttpSecurity http) throws Exception { "/api/genres/{id}", "/api/resourcetypes", "/api/resourcetypes/{id}").permitAll(); http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users/{id}", "/api/loans", "/api/loans/{id}", "/api/fines", "/api/fines/{id}", "/api/resourcecopies", "/api/resourcecopies/{id}").hasAnyRole("USER"); - http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users").hasAnyRole("ADMIN"); + http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/users", "/api/resources/all").hasAnyRole("ADMIN"); http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/users").hasAnyRole("ADMIN"); http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/loans").hasAnyRole("USER", "ADMIN"); http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/resources", "/api/genres", "/api/resourcetypes", diff --git a/backend/src/main/java/appSpring/service/LogicService.java b/backend/src/main/java/appSpring/service/LogicService.java index 14376a9..82e727a 100644 --- a/backend/src/main/java/appSpring/service/LogicService.java +++ b/backend/src/main/java/appSpring/service/LogicService.java @@ -55,7 +55,7 @@ private boolean hasEnoughCopies(Resource resource) { private boolean hasAnActiveAction(User user, Resource resource) { List actions = user.getActions(); for (Action action : actions) { - if (action.getResource().getResource() == resource && action.getDateLoanReturn() == new Date(0)) { + if (action.getResource().getResource() == resource && action.getDateLoanReturn() == null) { return true; } } @@ -105,7 +105,7 @@ public Action getAction() { } private boolean deleteLoanAvaible(Action loan) { - return (loan.getDateLoanReturn() == new Date(0)); + return (loan.getDateLoanReturn() == null); } public int deleteALoan(Action loan) { @@ -143,11 +143,11 @@ public int createAnUser(User user) { } private boolean itIsPossibleToReturn(Action action) { - return ((action.getDateLoanGiven() == new Date(0)) && (action.getDateLoanReturn() == new Date(0))); + return ((action.getDateLoanGiven() != null) && (action.getDateLoanReturn() == null)); } private boolean itIsPossibleToGive(Action action) { - return ((action.getDateLoanGiven() == new Date(0)) && (action.getDateLoanReturn() == new Date(0))); + return ((action.getDateLoanGiven() == null) && (action.getDateLoanReturn() == null)); } public int addGiveDate(Action action, Date date) { @@ -184,10 +184,10 @@ public int addReturnDate(Action action, Date date) { List currentActions = actionService.findByUser(action.getUser()); for (Action currentAction : currentActions) { Date date1 = currentAction.getDateLoanGiven(); - if (date1 == new Date(0)) + if (date1 == null) continue; Date date3 = currentAction.getDateLoanReturn(); - if (date3 == new Date(0)) + if (date3 != null) continue; date1.setMinutes(date1.getMinutes() + 1); Date date2 = new Date(); diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 04e45e5..b7290b3 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -6,7 +6,7 @@ spring.h2.console.enabled=true spring.datasource.url = jdbc:mysql://localhost/brems?verifyServerCertificate=false&useSSL=true spring.datasource.username = root -spring.datasource.password = 1234 +spring.datasource.password = root spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto = create-drop diff --git a/backend/target/appSpring-0.0.1.jar b/backend/target/appSpring-0.0.1.jar index 3b3b4ef..289a904 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 0a900ee..0caf241 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/backend/target/classes/META-INF/MANIFEST.MF b/backend/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0043377 --- /dev/null +++ b/backend/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Implementation-Title: appSpring +Implementation-Version: 0.0.1 +Built-By: jherel +Implementation-Vendor-Id: es.urjc.daw +Build-Jdk: 1.8.0_121 +Implementation-URL: http://projects.spring.io/spring-boot/appSpring/ +Created-By: Maven Integration for Eclipse +Implementation-Vendor: Pivotal Software, Inc. +Main-Class: appSpring.Application + diff --git a/backend/target/classes/appSpring/model/Action.class b/backend/target/classes/appSpring/model/Action.class index 2b688a5..3bbb864 100644 Binary files a/backend/target/classes/appSpring/model/Action.class and b/backend/target/classes/appSpring/model/Action.class differ diff --git a/backend/target/classes/appSpring/service/LogicService.class b/backend/target/classes/appSpring/service/LogicService.class index 4fbf393..b445d58 100644 Binary files a/backend/target/classes/appSpring/service/LogicService.class and b/backend/target/classes/appSpring/service/LogicService.class differ diff --git a/backend/target/classes/application.properties b/backend/target/classes/application.properties new file mode 100644 index 0000000..b7290b3 --- /dev/null +++ b/backend/target/classes/application.properties @@ -0,0 +1,23 @@ +server.port = 8443 +server.ssl.key-store = classpath:keystore.jks +server.ssl.key-store-password = password +server.ssl.key-password = secret +spring.h2.console.enabled=true + +spring.datasource.url = jdbc:mysql://localhost/brems?verifyServerCertificate=false&useSSL=true +spring.datasource.username = root +spring.datasource.password = root +spring.datasource.driverClassName = com.mysql.jdbc.Driver +spring.jpa.hibernate.ddl-auto = create-drop + +spring.mail.host = smtp.gmail.com +spring.mail.port = 587 +spring.mail.username = bremslibrerias@gmail.com +spring.mail.password = BrEmSbReMs7102 + +spring.mail.properties.mail.smtp.auth = true +spring.mail.properties.mail.smtp.socketFactory.port = 465 +spring.mail.properties.mail.smtp.starttls.required = false +spring.mail.properties.mail.smtp.starttls.enable = true +spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory +spring.mail.properties.mail.smtp.socketFactory.fallback = false diff --git a/backend/target/maven-archiver/pom.properties b/backend/target/maven-archiver/pom.properties index c44ec00..906616e 100644 --- a/backend/target/maven-archiver/pom.properties +++ b/backend/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Apache Maven -#Fri Apr 07 18:09:30 CEST 2017 +#Sun Apr 23 00:32:37 CEST 2017 version=0.0.1 groupId=es.urjc.daw artifactId=appSpring diff --git a/frontend/src/app/component/admin/admin-routing.module.ts b/frontend/src/app/component/admin/admin-routing.module.ts index 2589259..3bc339a 100644 --- a/frontend/src/app/component/admin/admin-routing.module.ts +++ b/frontend/src/app/component/admin/admin-routing.module.ts @@ -1,20 +1,22 @@ -import {NgModule} from '@angular/core'; -import {RouterModule, Routes} from '@angular/router'; +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; -import {AdminComponent} from './admin.component'; +import { AdminComponent } from './admin.component'; -import {DashboardComponent} from './dashboard/dashboard.component'; +import { DashboardComponent } from './dashboard/dashboard.component'; -import {ManageResourcesComponent} from './manage-resources/manage-resources.component'; -import {EditResourceComponent} from './manage-resources/edit/edit.component'; +import { ManageResourcesComponent } from './manage-resources/manage-resources.component'; +import { EditResourceComponent } from './manage-resources/edit/edit.component'; +import { CreateResourceComponent } from './manage-resources/create/create.component'; -import {ManageLoansComponent} from './manage-loans/manage-loans.component'; +import { ManageLoansComponent } from './manage-loans/manage-loans.component'; +import { CreateLoanComponent } from './manage-loans/create/create.component'; -import {ManageFinesComponent} from './manage-fines/manage-fines.component'; +import { ManageFinesComponent } from './manage-fines/manage-fines.component'; -import {CreateUserComponent} from './manage-users/create/create.component'; -import {EditUserComponent} from './manage-users/edit/edit.component'; -import {ManageUsersComponent} from './manage-users/manage-users.component'; +import { CreateUserComponent } from './manage-users/create/create.component'; +import { EditUserComponent } from './manage-users/edit/edit.component'; +import { ManageUsersComponent } from './manage-users/manage-users.component'; const adminRoutes: Routes = [ @@ -25,14 +27,16 @@ const adminRoutes: Routes = [ { path: '', children: [ - {path: 'resources', component: ManageResourcesComponent}, - {path: 'resource/:id', component: EditResourceComponent}, - {path: 'loans', component: ManageLoansComponent}, - {path: 'fines', component: ManageFinesComponent}, - {path: 'users', component: ManageUsersComponent}, - {path: 'users/new', component: CreateUserComponent}, - {path: 'users/:id', component: EditUserComponent}, - {path: '', component: DashboardComponent} + { path: 'resources', component: ManageResourcesComponent }, + { path: 'resources/new', component: CreateResourceComponent }, + { path: 'resources/:id', component: EditResourceComponent }, + { path: 'loans', component: ManageLoansComponent }, + { path: 'loans/new', component: CreateLoanComponent }, + { path: 'fines', component: ManageFinesComponent }, + { path: 'users', component: ManageUsersComponent }, + { path: 'users/new', component: CreateUserComponent }, + { path: 'users/:id', component: EditUserComponent }, + { path: '', component: DashboardComponent } ] } ] diff --git a/frontend/src/app/component/admin/admin.module.ts b/frontend/src/app/component/admin/admin.module.ts index 0995dcd..cae974f 100644 --- a/frontend/src/app/component/admin/admin.module.ts +++ b/frontend/src/app/component/admin/admin.module.ts @@ -1,42 +1,48 @@ -import {NgModule} from '@angular/core'; -import {CommonModule} from '@angular/common'; -import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; -import {FormsModule} from '@angular/forms'; +import { NgModule } from '@angular/core'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { CommonModule } from '@angular/common'; +import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; -import {AdminComponent} from './admin.component'; +import { AdminComponent } from './admin.component'; -import {AdminRoutingModule} from './admin-routing.module'; -import {HeaderComponent} from './header/header.component'; -import {SidebarComponent} from './sidebar/sidebar.component'; -import {ManageResourcesComponent} from './manage-resources/manage-resources.component'; -import {EditResourceComponent} from './manage-resources/edit/edit.component'; -import {EditUserComponent} from './manage-users/edit/edit.component'; -import {ManageLoansComponent} from './manage-loans/manage-loans.component'; -import {ManageFinesComponent} from './manage-fines/manage-fines.component'; -import {CreateUserComponent} from './manage-users/create/create.component'; -import {ManageUsersComponent} from './manage-users/manage-users.component'; -import {DashboardComponent} from './dashboard/dashboard.component'; +import { AdminRoutingModule } from './admin-routing.module'; +import { HeaderComponent } from './header/header.component'; +import { SidebarComponent } from './sidebar/sidebar.component'; + +import { ManageResourcesComponent } from './manage-resources/manage-resources.component'; +import { EditResourceComponent } from './manage-resources/edit/edit.component'; +import { CreateResourceComponent } from './manage-resources/create/create.component'; + +import { EditUserComponent } from './manage-users/edit/edit.component'; +import { ManageLoansComponent } from './manage-loans/manage-loans.component'; +import { CreateLoanComponent } from './manage-loans/create/create.component'; +import { ManageFinesComponent } from './manage-fines/manage-fines.component'; +import { CreateUserComponent } from './manage-users/create/create.component'; +import { ManageUsersComponent } from './manage-users/manage-users.component'; +import { DashboardComponent } from './dashboard/dashboard.component'; @NgModule({ - imports: [ - CommonModule, - AdminRoutingModule, - NgbModule, - FormsModule - ], - declarations: [ - AdminComponent, - HeaderComponent, - SidebarComponent, - ManageResourcesComponent, - EditResourceComponent, - ManageLoansComponent, - ManageFinesComponent, - CreateUserComponent, - EditUserComponent, - ManageUsersComponent, - DashboardComponent - ] + imports: [ + CommonModule, + AdminRoutingModule, + FormsModule, + ReactiveFormsModule + ], + declarations: [ + AdminComponent, + HeaderComponent, + SidebarComponent, + DashboardComponent, + ManageResourcesComponent, + EditResourceComponent, + ManageLoansComponent, + CreateLoanComponent, + ManageFinesComponent, + ManageUsersComponent, + CreateUserComponent, + EditUserComponent, + CreateResourceComponent + ] }) export class AdminModule { } diff --git a/frontend/src/app/component/admin/header/header.component.ts b/frontend/src/app/component/admin/header/header.component.ts index a0f2f7c..5ad1c67 100644 --- a/frontend/src/app/component/admin/header/header.component.ts +++ b/frontend/src/app/component/admin/header/header.component.ts @@ -1,11 +1,11 @@ import { Component, OnInit } from '@angular/core'; -import {DomSanitizer} from '@angular/platform-browser'; -import {ADMIN_IMG_URL} from '../../../util'; +import { DomSanitizer } from '@angular/platform-browser'; +import { ADMIN_IMG_URL } from '../../../util'; -import {User} from '../../../model/user.model'; +import { User } from '../../../model/user.model'; -import {FileService} from '../../../service/file.service'; -import {UserService} from '../../../service/user.service'; +import { FileService } from '../../../service/file.service'; +import { UserService } from '../../../service/user.service'; @Component({ selector: 'app-admin-header', @@ -20,7 +20,6 @@ export class HeaderComponent implements OnInit { constructor(private fileService: FileService, private sanitizer: DomSanitizer, private userService: UserService) { } ngOnInit() { - console.log(Number(localStorage.getItem('id'))); this.userService.getUser(Number(localStorage.getItem('id'))).subscribe( user => this.user = user, error => console.log("Fail trying to get user information.") diff --git a/frontend/src/app/component/admin/manage-loans/create/create.component.html b/frontend/src/app/component/admin/manage-loans/create/create.component.html new file mode 100644 index 0000000..1e8a422 --- /dev/null +++ b/frontend/src/app/component/admin/manage-loans/create/create.component.html @@ -0,0 +1,46 @@ +
+ Algo ha ido mal... {{message}} +
+ +
+

Administración de préstamos Administra los préstamos de los recursos

+ +
+ +
+
+
+

Nuevo préstamo

+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+
+
+
+
diff --git a/frontend/src/app/component/admin/manage-loans/create/create.component.ts b/frontend/src/app/component/admin/manage-loans/create/create.component.ts new file mode 100644 index 0000000..c02a85e --- /dev/null +++ b/frontend/src/app/component/admin/manage-loans/create/create.component.ts @@ -0,0 +1,82 @@ +import { Component, OnInit } from '@angular/core'; +import { Router, ActivatedRoute } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; + +import { Action } from 'app/model/action.model'; +import { User } from 'app/model/user.model'; +import { Resource } from 'app/model/resource.model'; +import { ResourceCopy } from 'app/model/resource-copy.model'; + +import { SessionService } from 'app/service/session.service'; +import { ActionService } from 'app/service/action.service'; +import { UserService } from 'app/service/user.service'; +import { ResourceService } from 'app/service/resource.service'; + +@Component({ + templateUrl: './create.component.html' +}) +export class CreateLoanComponent implements OnInit { + + loan: Action = null; + users: User[]; + resources: Resource[]; + + userSelect: User = null; + resourceSelect: Resource = null; + + errorMessage: boolean; + message: String; + + constructor(private router: Router, + private activatedRoute: ActivatedRoute, + private sessionService: SessionService, + private actionService: ActionService, + private userService: UserService, + private resourceService: ResourceService) { + this.errorMessage = false; + + } + + ngOnInit() { + if (!this.sessionService.checkCredentials()) { + this.router.navigate(["/login"]); + } else { + this.userService.getUsers().subscribe( + users => this.users = users, + error => console.log(error) + ); + this.resourceService.getAllListResources().subscribe( + resources => this.resources = resources, + error => console.log(error) + ); + } + } + + createLoan() { + let copy: ResourceCopy; + + if (this.resourceSelect.noReservedCopies.length != 0) { + copy = this.resourceSelect.copies.find(x => x.locationCode == this.resourceSelect.noReservedCopies[0]); + copy.resource = { + id: this.resourceSelect.id, + title: this.resourceSelect.title, + author: this.resourceSelect.author, + editorial: this.resourceSelect.editorial, + avaiblereserve: this.resourceSelect.avaiblereserve, + description: this.resourceSelect.description, + hasPhoto: this.resourceSelect.hasPhoto, + noReservedCopies: this.resourceSelect.noReservedCopies + }; + + this.loan = { copy: copy, user: this.userSelect }; + + this.actionService.postAction(this.loan).subscribe( + response => this.router.navigate(["/admin/loans"]), + error => { + this.errorMessage = true; + this.message = 'No se ha podido realizar la acción.' + } + ); + } + } +} \ No newline at end of file diff --git a/frontend/src/app/component/admin/manage-loans/manage-loans.component.css b/frontend/src/app/component/admin/manage-loans/manage-loans.component.css index e69de29..fb5336f 100644 --- a/frontend/src/app/component/admin/manage-loans/manage-loans.component.css +++ b/frontend/src/app/component/admin/manage-loans/manage-loans.component.css @@ -0,0 +1,3 @@ +table { + background-color: white !important; +} diff --git a/frontend/src/app/component/admin/manage-loans/manage-loans.component.html b/frontend/src/app/component/admin/manage-loans/manage-loans.component.html index 46deacc..88082fa 100644 --- a/frontend/src/app/component/admin/manage-loans/manage-loans.component.html +++ b/frontend/src/app/component/admin/manage-loans/manage-loans.component.html @@ -1,3 +1,69 @@ -

- manage-loans works! -

+
+ ¡Acción realizada! {{message}} +
+
+ Algo ha ido mal... {{message}} +
+ +
+

Administración de préstamos Administra los préstamos de los recursos

+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
IdentificadorUsuarioRecursoPeticiónPréstamoDevoluciónAdministrar
{{ loan.copy.locationCode }}{{ loan.user.name }}{{ loan.copy.resource.title }}{{ loan.dateLoanInit }} +
{{ loan.dateLoanGiven }}
+ + + +
+
{{ loan.dateLoanReturn }}
+ + + +
+ +
+ +
+ +
+ + +
+
+
diff --git a/frontend/src/app/component/admin/manage-loans/manage-loans.component.ts b/frontend/src/app/component/admin/manage-loans/manage-loans.component.ts index 48a3c36..c2d491e 100644 --- a/frontend/src/app/component/admin/manage-loans/manage-loans.component.ts +++ b/frontend/src/app/component/admin/manage-loans/manage-loans.component.ts @@ -1,15 +1,126 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Action } from 'app/model/action.model'; + +import { SessionService } from 'app/service/session.service'; +import { ActionService } from 'app/service/action.service'; @Component({ - selector: 'app-manage-loans', - templateUrl: './manage-loans.component.html', - styleUrls: ['./manage-loans.component.css'] + templateUrl: './manage-loans.component.html', + styleUrls: ['./manage-loans.component.css'] }) export class ManageLoansComponent implements OnInit { - constructor() { } + loans: Action[] = []; + errorMessage: boolean; + message: String; + showNextPage: boolean; + showPreviousPage: boolean; + successMessage: boolean; + private loansPage: number; + + constructor(private router: Router, + private sessionService: SessionService, + private actionService: ActionService) { + this.successMessage = false; + this.errorMessage = false; + this.loansPage = 0; + this.showNextPage = false; + this.showPreviousPage = false; + } + + ngOnInit() { + if (!this.sessionService.checkCredentials()) { + this.router.navigate(["/login"]); + } else { + this.getLoans(); + this.checkNextPage(); + this.checkPreviousPage(); + } + } + + getLoans() { + this.actionService.getAllActions(this.loansPage).subscribe( + loans => this.loans = loans, + error => console.log(error) + ); + } + + nextPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.loansPage++; + this.getLoans(); + this.checkNextPage(); + this.showPreviousPage = true; + } + + previousPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.loansPage--; + this.getLoans(); + this.checkPreviousPage(); + this.showNextPage = true; + } + + checkNextPage() { + this.actionService.getAllActions(this.loansPage + 1).subscribe( + loans => this.showNextPage = (Object.keys(loans).length === 0) ? false : true + ); + } + + checkPreviousPage() { + if (this.loansPage > 0) { + this.actionService.getAllActions(this.loansPage - 1).subscribe( + loans => this.showPreviousPage = (Object.keys(loans).length === 0) ? false : true); + } else { + this.showPreviousPage = false; + } + } + + updateLoan(id: number, action: String) { + let loan: Action; + loan = this.loans.find(x => x.id === id); + + this.actionService.updateAction(loan, action).subscribe( + response => { + this.successMessage = true; + this.errorMessage = false; + this.message = 'Realizado correctamente.'; + this.loansPage = 0; + this.getLoans(); + this.checkNextPage(); + this.checkPreviousPage(); + }, + error => { + this.successMessage = false; + this.errorMessage = true; + this.message = 'No se ha podido realizar la acción.' + } + ); + } - ngOnInit() { - } + deleteLoan(id: number) { + this.actionService.deleteAction(id).subscribe( + response => { + this.successMessage = true; + this.errorMessage = false; + this.message = 'Prestamo eliminado correctamente.'; + this.loansPage = 0; + console.log('Loan successfully deleted.'); + this.getLoans(); + this.checkNextPage(); + this.checkPreviousPage(); + }, + error => { + this.successMessage = false; + this.errorMessage = true; + this.message = 'No se ha podido eliminar el prestamo.' + console.log('Fail trying to delete selected loan.'); + } + ); + } } diff --git a/frontend/src/app/component/admin/manage-resources/create/create.component.css b/frontend/src/app/component/admin/manage-resources/create/create.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/component/admin/manage-resources/create/create.component.html b/frontend/src/app/component/admin/manage-resources/create/create.component.html new file mode 100644 index 0000000..977d8ae --- /dev/null +++ b/frontend/src/app/component/admin/manage-resources/create/create.component.html @@ -0,0 +1,59 @@ +
+

Administraión de recursos Administra los libros o las revistas

+ +
+ +
+
+
+

Nuevo libro

+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
diff --git a/frontend/src/app/component/admin/manage-resources/create/create.component.ts b/frontend/src/app/component/admin/manage-resources/create/create.component.ts new file mode 100644 index 0000000..13e8fb0 --- /dev/null +++ b/frontend/src/app/component/admin/manage-resources/create/create.component.ts @@ -0,0 +1,81 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Resource } from 'app/model/resource.model'; +import { Genre } from 'app/model/genre.model'; +import { ResourceType } from 'app/model/resource-type.model'; + +import { SessionService } from 'app/service/session.service'; +import { ResourceService } from 'app/service/resource.service'; +import { GenreService } from 'app/service/genre.service'; + +@Component({ + templateUrl: './create.component.html', + styleUrls: ['./create.component.css'] +}) +export class CreateResourceComponent implements OnInit { + + resource: Resource; + genres: Genre[]; + types: ResourceType[]; + + newResource: any = {}; + resourceImage: any; + + errorMessage: boolean; + message: string; + + constructor( + private router: Router, + private sessionService: SessionService, + private resourceService: ResourceService, + private genreService: GenreService + ) { + this.newResource = { + title: '', + author: '', + editorial: '', + description: '', + genre: null, + resourceType: null + } + } + + ngOnInit() { + if (!this.sessionService.checkCredentials()) { + this.router.navigate(["/login"]); + } else { + this.genreService.getAllGenres().subscribe( + genres => this.genres = genres, + error => console.log(error) + ); + this.resourceService.getResourcesTypes().subscribe( + types => this.types = types, + error => console.log(error) + ) + } + } + + createResource() { + this.resource = this.newResource; + + this.resourceService.createResource(this.resource).subscribe( + response => { + if (this.resourceImage !== undefined) { + let formData = new FormData(); + formData.append('file', this.resourceImage, this.resourceImage.name); + this.resourceService.updateFile(formData, response.id).subscribe(); + } + this.router.navigate(['/admin/resources']); + }, + error => { + this.errorMessage = true; + this.message = 'No se ha podido crear el recurso.' + } + ); + } + + selectFile($event) { + this.resourceImage = $event.target.files[0]; + } +} diff --git a/frontend/src/app/component/admin/manage-resources/edit/edit.component.1.html b/frontend/src/app/component/admin/manage-resources/edit/edit.component.1.html deleted file mode 100644 index 984e0f7..0000000 --- a/frontend/src/app/component/admin/manage-resources/edit/edit.component.1.html +++ /dev/null @@ -1,57 +0,0 @@ -
-

Administraión de recursosAdministra los libros o las revistas

-
- -
-
-
-

Editar {{ resource.title }}

-
-
-
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-
-
-
-
-
diff --git a/frontend/src/app/component/admin/manage-resources/edit/edit.component.html b/frontend/src/app/component/admin/manage-resources/edit/edit.component.html index 14b689f..f1bf2b3 100644 --- a/frontend/src/app/component/admin/manage-resources/edit/edit.component.html +++ b/frontend/src/app/component/admin/manage-resources/edit/edit.component.html @@ -1,3 +1,74 @@ +
+ ¡Modificado! {{message}} +
+
+ Algo ha ido mal... {{message}} +
+

Administraión de recursosAdministra los libros o las revistas

+ +
+ +
+
+
+

Editar {{ resource?.title }}

+
+
+
+
+
+
+ +
+ + + + + +
+
+
+
+ + +
+
+ + +
+
+ : {{resource.genre?.name}} +
+ +
+
+ + +
+
+ : {{resource.resourceType?.name}} +
+ +
+
+ + +
+
+ +
+
+
+
+
diff --git a/frontend/src/app/component/admin/manage-resources/edit/edit.component.ts b/frontend/src/app/component/admin/manage-resources/edit/edit.component.ts index e277af3..46be4f3 100644 --- a/frontend/src/app/component/admin/manage-resources/edit/edit.component.ts +++ b/frontend/src/app/component/admin/manage-resources/edit/edit.component.ts @@ -1,9 +1,15 @@ import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; +import { DomSanitizer } from '@angular/platform-browser'; import { Resource } from 'app/model/resource.model'; +import { Genre } from 'app/model/genre.model'; +import { ResourceType } from 'app/model/resource-type.model'; +import { SessionService } from 'app/service/session.service'; import { ResourceService } from 'app/service/resource.service'; +import { GenreService } from 'app/service/genre.service'; +import { FileService } from 'app/service/file.service'; @Component({ templateUrl: './edit.component.html', @@ -11,24 +17,84 @@ import { ResourceService } from 'app/service/resource.service'; }) export class EditResourceComponent implements OnInit { - private resource: Resource; + resource: any = {}; + genres: Genre[]; + types: ResourceType[]; + + genreSelect: Genre; + + resourceImage: any; + + successMessage: boolean; + errorMessage: boolean; + message: String; constructor(private router: Router, - activatedRoute: ActivatedRoute, service: ResourceService) { - let id = activatedRoute.snapshot.params['id']; + private activatedRoute: ActivatedRoute, + public sanitizer: DomSanitizer, + private sessionService: SessionService, + private resourceService: ResourceService, + private genreService: GenreService, + private fileService: FileService) { + } - service.getResource(id).subscribe( - resource => this.resource = resource, - error => console.error(error) - ); - console.log(this.resource); + ngOnInit() { + if (!this.sessionService.checkCredentials()) { + this.router.navigate(["/login"]); + } else { + this.getResource(); + this.genreService.getAllGenres().subscribe( + genres => this.genres = genres, + error => console.log(error) + ); + this.resourceService.getResourcesTypes().subscribe( + types => this.types = types, + error => console.log(error) + ) + } } - ngOnInit() { } + getResource() { + let id = this.activatedRoute.snapshot.params['id']; + this.resourceService.getResource(id).subscribe( + resource => { + this.resource = resource; + this.fileService.getResourceFile(resource.id).subscribe( + data => { + let dataRecieved: string[] = data.split('"'); + resource.image = 'data:image/png;base64,' + dataRecieved[3]; + }, + error => console.log('Fail adding resource ' + resource.title + 'image.') + ); + }, + error => console.log(error) + ); + } - gotoResources() { this.router.navigate(['/resources']); } + saveResource() { - saveResource() { } + this.resourceService.updateResource(this.resource).subscribe( + response => { + if (this.resourceImage !== undefined) { + let formData = new FormData(); + formData.append('file', this.resourceImage, this.resourceImage.name); + this.resourceService.updateFile(formData, response.id).subscribe(); + } + this.successMessage = true; + this.errorMessage = false; + this.message = 'Recurso editado correctamente.'; + this.getResource(); + }, + error => { + this.successMessage = false; + this.errorMessage = true; + this.message = 'No se ha podido editar el recurso.' + } + ); + } + selectFile($event) { + this.resourceImage = $event.target.files[0]; + } } diff --git a/frontend/src/app/component/admin/manage-resources/manage-resources.component.css b/frontend/src/app/component/admin/manage-resources/manage-resources.component.css index e69de29..fb5336f 100644 --- a/frontend/src/app/component/admin/manage-resources/manage-resources.component.css +++ b/frontend/src/app/component/admin/manage-resources/manage-resources.component.css @@ -0,0 +1,3 @@ +table { + background-color: white !important; +} diff --git a/frontend/src/app/component/admin/manage-resources/manage-resources.component.html b/frontend/src/app/component/admin/manage-resources/manage-resources.component.html index a4c0c34..0aa7754 100644 --- a/frontend/src/app/component/admin/manage-resources/manage-resources.component.html +++ b/frontend/src/app/component/admin/manage-resources/manage-resources.component.html @@ -1,9 +1,20 @@ +
+ ¡Eliminado! {{message}} +
+
+ Algo ha ido mal... {{message}} +
+

Administración de recursos Administra los libros o las revistas

+
- +
@@ -23,21 +34,31 @@

Administración de recursos Administra los libros o las revistas{{ resource.copies.length }}

- - + +
Título{{ resource.noReservedCopies.length }} {{ resource.author }}{{ resource.genre.name }}{{ resource.resourceType.name }}{{ resource.genre?.name }}{{ resource.resourceType?.name }} - + - - - +
- - - +
+ +
+ + +
+
diff --git a/frontend/src/app/component/admin/manage-resources/manage-resources.component.ts b/frontend/src/app/component/admin/manage-resources/manage-resources.component.ts index 7e23425..33d4145 100644 --- a/frontend/src/app/component/admin/manage-resources/manage-resources.component.ts +++ b/frontend/src/app/component/admin/manage-resources/manage-resources.component.ts @@ -1,34 +1,102 @@ import { Component, OnInit } from '@angular/core'; -import { Http } from '@angular/http'; +import { Router } from '@angular/router'; + +import { Resource } from 'app/model/resource.model'; + +import { SessionService } from 'app/service/session.service'; +import { ResourceService } from 'app/service/resource.service'; @Component({ - selector: 'app-manage-resources', templateUrl: './manage-resources.component.html', styleUrls: ['./manage-resources.component.css'] }) export class ManageResourcesComponent implements OnInit { - private resources: Object[] = []; + private resources: Resource[] = []; + successMessage: boolean; + errorMessage: boolean; + message: String; + showNextPage: boolean; + showPreviousPage: boolean; + resourcesPage: number; - constructor(private http: Http) { + constructor(private router: Router, + private sessionService: SessionService, + private ResourceService: ResourceService) { + this.successMessage = false; + this.errorMessage = false; + this.resourcesPage = 0; + this.showNextPage = false; + this.showPreviousPage = false; } ngOnInit() { - this.getResources(); + if (!this.sessionService.checkCredentials()) { + this.router.navigate(["/login"]); + } else { + this.getResources(); + this.checkNextPage(); + this.checkPreviousPage(); + } } getResources() { - this.resources = []; - let url = "https://localhost:8443/api/resources"; + this.ResourceService.getPageResources(this.resourcesPage).subscribe( + resources => this.resources = resources, + error => console.log("Fail trying to get current page of resources.") + ); + } + + nextPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.resourcesPage++; + this.getResources(); + this.checkNextPage(); + this.showPreviousPage = true; + } + + previousPage() { + this.showNextPage = false; + this.showPreviousPage = false; + this.resourcesPage--; + this.getResources(); + this.checkPreviousPage(); + this.showNextPage = true; + } + + checkNextPage() { + this.ResourceService.getPageResources(this.resourcesPage + 1).subscribe( + resources => this.showNextPage = (Object.keys(resources).length === 0) ? false : true + ); + } + + checkPreviousPage() { + if (this.resourcesPage > 0) { + this.ResourceService.getPageResources(this.resourcesPage - 1).subscribe( + resources => this.showPreviousPage = (Object.keys(resources).length === 0) ? false : true + ); + } else { + this.showPreviousPage = false; + } + } - this.http.get(url).subscribe( + deleteResource(id: number) { + this.ResourceService.deleteResource(id).subscribe( response => { - let data = response.json().content; - data.forEach(element => { - this.resources.push(element); - }); + this.successMessage = true; + this.errorMessage = false; + this.message = 'Recurso eliminado correctamente.'; + this.resourcesPage = 0; + this.getResources(); + this.checkNextPage(); + this.checkPreviousPage(); }, - error => console.error(error) + error => { + this.successMessage = false; + this.errorMessage = true; + this.message = 'No se ha podido eliminar el recurso.' + } ); } 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 ba44a0c..4f4f571 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 @@ -46,6 +46,7 @@

+
diff --git a/frontend/src/app/component/public/home/home.component.html b/frontend/src/app/component/public/home/home.component.html index e069eea..7e100b7 100644 --- a/frontend/src/app/component/public/home/home.component.html +++ b/frontend/src/app/component/public/home/home.component.html @@ -17,100 +17,114 @@ diff --git a/frontend/src/app/component/public/user/profile.component.html b/frontend/src/app/component/public/user/profile.component.html index ffe940a..6545574 100644 --- a/frontend/src/app/component/public/user/profile.component.html +++ b/frontend/src/app/component/public/user/profile.component.html @@ -23,33 +23,32 @@

Información Básica -

- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
Nombre completo{{user?.firstName}} {{user?.lastName1}} {{user?.lastName2}}
Usuario{{user?.name}}
Email{{user?.email}}
Teléfono{{user?.telephone}}
Última vezhace 34 minutos
Nombre completo{{user?.firstName}} {{user?.lastName1}} {{user?.lastName2}}
Usuario{{user?.name}}
Email{{user?.email}}
Teléfono{{user?.telephone}}
Última vezhace 34 minutos
@@ -83,103 +82,104 @@


- ver libro - - - -
- - - - - - - - - - - - - - - -
Título{{action.copy.resource.title}}
Autor{{action.copy.resource.author}}
Fecha de solicitud de préstamo{{action.dateLoanInit}}
-
- - + ver + libro + + - - - - + + + - - - - - - + + + + + + + + + diff --git a/frontend/src/app/component/public/user/profile.component.ts b/frontend/src/app/component/public/user/profile.component.ts index eb7820e..b91c3e5 100644 --- a/frontend/src/app/component/public/user/profile.component.ts +++ b/frontend/src/app/component/public/user/profile.component.ts @@ -13,8 +13,8 @@ import {FineService} from '../../../service/fine.service'; import {FileService} from '../../../service/file.service'; import {SessionService} from '../../../service/session.service'; import {UserService} from '../../../service/user.service'; -import {ModalProfileEdit} from "./modal.profile.component/modal-profile-edit"; -import {ModalBiographyEdit} from "./modal.biography.component/modal-biography-edit"; +import {ModalProfileEdit} from './modal.profile.component/modal-profile-edit'; +import {ModalBiographyEdit} from './modal.biography.component/modal-biography-edit'; @Component({ templateUrl: 'profile.component.html' @@ -61,7 +61,7 @@ export class ProfileComponent implements OnInit, DoCheck { this.currentActionsPage++; this.downloadImages(resources); }, - error => console.log("Fail trying to charge " + this.user.name + " current loans.") + error => console.log('Fail trying to charge ' + this.user.name + " current loans.") ); this.fineService.getAllFines(this.finePage).subscribe( fines => { diff --git a/frontend/src/app/model/resource-type.model.ts b/frontend/src/app/model/resource-type.model.ts new file mode 100644 index 0000000..04abf0b --- /dev/null +++ b/frontend/src/app/model/resource-type.model.ts @@ -0,0 +1,4 @@ +export interface ResourceType { + id?: number; + name: string; +} diff --git a/frontend/src/app/model/resource.model.ts b/frontend/src/app/model/resource.model.ts index 59df9d5..35972ca 100644 --- a/frontend/src/app/model/resource.model.ts +++ b/frontend/src/app/model/resource.model.ts @@ -1,3 +1,6 @@ +import { ResourceCopy } from './resource-copy.model'; +import { Genre } from './genre.model'; + export interface Resource { id?: number; title: string; @@ -5,7 +8,9 @@ export interface Resource { editorial: string; image?: any; avaiblereserve: boolean; + copies?: ResourceCopy[]; description: string; hasPhoto: boolean; noReservedCopies: string[]; + genre?: Genre; } diff --git a/frontend/src/app/service/action.service.ts b/frontend/src/app/service/action.service.ts index 852dc57..64a0524 100644 --- a/frontend/src/app/service/action.service.ts +++ b/frontend/src/app/service/action.service.ts @@ -1,39 +1,74 @@ -import {Injectable} from '@angular/core'; -import {Headers, Http} from '@angular/http'; +import { Injectable } from '@angular/core'; +import { Headers, Http } from '@angular/http'; import 'rxjs/Rx'; -import {Observable} from 'rxjs/Observable'; -import {ACTION_URL} from "../util"; +import { Observable } from 'rxjs/Observable'; +import { ACTION_URL } from "../util"; -import {Action} from "../model/action.model"; +import { Action } from "../model/action.model"; @Injectable() export class ActionService { - authCreds: string; - - constructor(private http: Http) { - } - - setAuthHeaders(authCreds: string) { - this.authCreds = authCreds; - } - - getAllActions(page: number, finished: boolean) { - let headers: Headers = new Headers(); - headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.get(ACTION_URL + '?page=' + page + '&finished=' + finished, {headers: headers}) - .map(response => response.json().content) - .catch(error => Observable.throw('Server error')); - } - - postAction(action: Action) { - let body = JSON.stringify(action); - let headers: Headers = new Headers(); - headers.append('Content-Type', 'application/json'); - headers.append('X-Requested-With', 'XMLHttpRequest'); - headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.post(ACTION_URL, body, {headers: headers}) - .map(response => response.json()) - .catch(error => Observable.throw('Server error')); - } + authCreds: string; + + constructor(private http: Http) { + } + + setAuthHeaders(authCreds: string) { + this.authCreds = authCreds; + } + + getAllActions(page?: number, finished?: boolean) { + this.authCreds = localStorage.getItem("creds"); + + let headers: Headers = new Headers(); + headers.append('Authorization', 'Basic ' + this.authCreds); + + /*let url = ACTION_URL; + if (page) + url += '?page=' + page; + if (finished) + url += '&finished=' + finished;*/ + + return this.http.get(ACTION_URL + '?page=' + page + '&finished=' + finished, { headers: headers }) + .map(response => response.json().content) + .catch(error => Observable.throw('Server error')); + } + + postAction(action: Action) { + this.authCreds = localStorage.getItem("creds"); + let body = JSON.stringify(action); + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + return this.http.post(ACTION_URL, body, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } + + updateAction(loan: Action, action: String) { + this.authCreds = localStorage.getItem("creds"); + let body = JSON.stringify(loan); + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + + let url = ACTION_URL + '/' + loan.id + '?action=' + action; + return this.http.put(url, body, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } + + deleteAction(id: number) { + this.authCreds = localStorage.getItem("creds"); + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + return this.http.delete(ACTION_URL + '/' + id, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } } diff --git a/frontend/src/app/service/genre.service.ts b/frontend/src/app/service/genre.service.ts index 102d0cc..bdf6d39 100644 --- a/frontend/src/app/service/genre.service.ts +++ b/frontend/src/app/service/genre.service.ts @@ -1,8 +1,8 @@ -import {Injectable} from '@angular/core'; -import {Http} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; import 'rxjs/Rx'; -import {GENRE_URL} from "../util"; +import { GENRE_URL } from "../util"; @Injectable() export class GenreService { @@ -10,8 +10,9 @@ export class GenreService { constructor(private http: Http) { } - getAllGenres(page: number) { - return this.http.get(GENRE_URL + '?page=' + page) + getAllGenres(page?: number) { + let url = (page) ? GENRE_URL + '?page=' + page : GENRE_URL ; + return this.http.get(url) .map(response => response.json().content) .catch(error => Observable.throw('Server error')); } diff --git a/frontend/src/app/service/resource.service.ts b/frontend/src/app/service/resource.service.ts index 0121854..67b6ead 100644 --- a/frontend/src/app/service/resource.service.ts +++ b/frontend/src/app/service/resource.service.ts @@ -1,23 +1,46 @@ -import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import { Injectable } from '@angular/core'; +import { Headers, Http, Response } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; import 'rxjs/Rx'; -import {RESOURCES_URL} from "../util"; +import { RESOURCES_URL } from "../util"; + +import { Resource } from 'app/model/resource.model'; @Injectable() export class ResourceService { + authCreds: string; + constructor(private http: Http) { } + setAuthHeaders(authCreds: string) { + this.authCreds = authCreds; + } + getResource(id: number) { return this.http.get(RESOURCES_URL + '/' + id) .map(response => response.json()) .catch(error => Observable.throw('Server error')) } - getAllResources(type: string, page: number) { - return this.http.get(RESOURCES_URL + '?type=' + type + '&page=' + page) + getAllResources(type?: string, page?: number) { + let url = RESOURCES_URL + '?type=' + type + '&page=' + page; + return this.http.get(url) + .map(response => response.json().content) + .catch(error => Observable.throw('Server error')); + } + + getAllListResources() { + let url = RESOURCES_URL + '/all'; + return this.http.get(url) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } + + getPageResources(page?: number) { + let url = (page) ? RESOURCES_URL + '?page=' + page : RESOURCES_URL; + return this.http.get(url) .map(response => response.json().content) .catch(error => Observable.throw('Server error')); } @@ -27,4 +50,62 @@ export class ResourceService { .map(response => response.json().content) .catch(error => Observable.throw('Server error')); } + + updateResource(resource: Resource) { + let body = JSON.stringify(resource); + + this.authCreds = localStorage.getItem("creds"); + + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + + return this.http.put(RESOURCES_URL + '/' + resource.id, body, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } + + createResource(resource: Resource) { + let body = JSON.stringify(resource); + + this.authCreds = localStorage.getItem("creds"); + + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + return this.http.post(RESOURCES_URL, body, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')) + } + + updateFile(formData: FormData, id: number) { + let headers: Headers = new Headers(); + headers.append('Accept', 'application/json'); + headers.append('Authorization', 'Basic ' + this.authCreds); + return this.http.put(RESOURCES_URL + '/' + id + '/upload', formData, { headers: headers }) + .map(response => console.log("Success. The file has been successfully added to server directories.")) + .catch(error => Observable.throw('Server error')); + } + + deleteResource(id: number) { + this.authCreds = localStorage.getItem("creds"); + + let headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('X-Requested-With', 'XMLHttpRequest'); + headers.append('Authorization', 'Basic ' + this.authCreds); + + return this.http.delete(RESOURCES_URL + '/' + id, { headers: headers }) + .map(response => response.json()) + .catch(error => Observable.throw('Server error')); + } + + getResourcesTypes() { + let url = 'https://localhost:8443/api/resourcetypes'; + return this.http.get(url) + .map(response => response.json().content) + .catch(error => Observable.throw('Server error')); + } } diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts index 77a024b..1a9a4a4 100644 --- a/frontend/src/app/service/user.service.ts +++ b/frontend/src/app/service/user.service.ts @@ -1,10 +1,10 @@ -import {Injectable} from '@angular/core'; -import {Headers, Http} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import { Injectable } from '@angular/core'; +import { Headers, Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; import 'rxjs/Rx'; -import {USER_URL} from "../util"; +import { USER_URL } from "../util"; -import {User} from '../model/user.model'; +import { User } from '../model/user.model'; @Injectable() export class UserService { @@ -24,11 +24,12 @@ export class UserService { return this.user; } - getUsers(page: number) { + getUsers(page?: number) { this.authCreds = localStorage.getItem("creds"); let headers: Headers = new Headers(); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.get(USER_URL + '?page=' + page, {headers: headers}) + let url = (page) ? USER_URL + '?page=' + page : USER_URL; + return this.http.get(url, { headers: headers }) .map(response => response.json().content) .catch(error => Observable.throw('Server error')); } @@ -37,7 +38,7 @@ export class UserService { 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}) + return this.http.get(USER_URL + '/' + id.toString(), { headers: headers }) .map(response => { this.user = response.json(); return response.json(); @@ -52,7 +53,7 @@ export class UserService { headers.append('Content-Type', 'application/json'); headers.append('X-Requested-With', 'XMLHttpRequest'); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.put(USER_URL + '/' + user.id, body, {headers: headers}) + return this.http.put(USER_URL + '/' + user.id, body, { headers: headers }) .map(response => { if (current) { this.getUser(user.id).subscribe( @@ -69,7 +70,7 @@ export class UserService { let headers: Headers = new Headers(); headers.append('Accept', 'application/json'); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.put(USER_URL + '/' + user.id + '/upload', formData, {headers: headers}) + return this.http.put(USER_URL + '/' + user.id + '/upload', formData, { headers: headers }) .map(response => console.log("Success. The file has been successfully added to server directories.")) .catch(error => Observable.throw('Server error')); } @@ -80,7 +81,7 @@ export class UserService { headers.append('Content-Type', 'application/json'); headers.append('X-Requested-With', 'XMLHttpRequest'); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.delete(USER_URL + '/' + id, {headers: headers}) + return this.http.delete(USER_URL + '/' + id, { headers: headers }) .map(response => response.json()) .catch(error => Observable.throw('Server error')); } @@ -92,7 +93,7 @@ export class UserService { headers.append('Content-Type', 'application/json'); headers.append('X-Requested-With', 'XMLHttpRequest'); headers.append('Authorization', 'Basic ' + this.authCreds); - return this.http.post(USER_URL, body, {headers: headers}) + return this.http.post(USER_URL, body, { headers: headers }) .map(response => response.json()) .catch(error => Observable.throw('Server error')) } diff --git a/frontend/src/assets/img/icon-profile.png b/frontend/src/assets/img/icon-profile.png new file mode 100644 index 0000000..7d694b1 Binary files /dev/null and b/frontend/src/assets/img/icon-profile.png differ diff --git a/frontend/src/assets/img/loadingElements.gif b/frontend/src/assets/img/loadingElements.gif new file mode 100644 index 0000000..a1de684 Binary files /dev/null and b/frontend/src/assets/img/loadingElements.gif differ