Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev' into carlos
Browse files Browse the repository at this point in the history
  • Loading branch information
cvazquezlos committed Apr 23, 2017
2 parents 2c870b8 + b72fd21 commit b4fab34
Show file tree
Hide file tree
Showing 44 changed files with 1,228 additions and 427 deletions.
2 changes: 0 additions & 2 deletions backend/src/main/java/appSpring/model/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ protected Action() {

public Action(Date dateLoanInit) {
this.dateLoanInit = dateLoanInit;
dateLoanReturn = new Date(0);
dateLoanGiven = new Date(0);
}

public Integer getID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getUserfile(@PathVariable int id, Authentication authentication, HttpSession session,
HttpServletRequest request) throws IOException {
Expand All @@ -48,7 +38,6 @@ public ResponseEntity<String> getUserfile(@PathVariable int id, Authentication a
}
}

@JsonView(FineDetail.class)
@RequestMapping(value = "/resource/{id}", method = RequestMethod.GET)
public ResponseEntity<String> getResourceFile(@PathVariable int id, Authentication authentication, HttpSession session,
HttpServletRequest request) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,15 @@ public ResponseEntity<Resource> putUserImage(@PathVariable Integer id,
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@JsonView(ResourceDetail.class)
@RequestMapping(value = "/all", method = RequestMethod.GET)
public ResponseEntity<List<Resource>> getAllResources(HttpSession session) {

session.setMaxInactiveInterval(-1);

List<Resource> resources = resourceService.findAll();
return new ResponseEntity<>(resources, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions backend/src/main/java/appSpring/service/LogicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private boolean hasEnoughCopies(Resource resource) {
private boolean hasAnActiveAction(User user, Resource resource) {
List<Action> 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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -184,10 +184,10 @@ public int addReturnDate(Action action, Date date) {
List<Action> 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();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified backend/target/appSpring-0.0.1.jar
Binary file not shown.
Binary file modified backend/target/appSpring-0.0.1.jar.original
Binary file not shown.
11 changes: 11 additions & 0 deletions backend/target/classes/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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

Binary file modified backend/target/classes/appSpring/model/Action.class
Binary file not shown.
Binary file modified backend/target/classes/appSpring/service/LogicService.class
Binary file not shown.
23 changes: 23 additions & 0 deletions backend/target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion backend/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -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
42 changes: 23 additions & 19 deletions frontend/src/app/component/admin/admin-routing.module.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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 }
]
}
]
Expand Down
76 changes: 41 additions & 35 deletions frontend/src/app/component/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -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 {
}
11 changes: 5 additions & 6 deletions frontend/src/app/component/admin/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div *ngIf="errorMessage" class="alert alert-danger">
<strong>Algo ha ido mal...</strong> {{message}}
</div>

<section class="content-header">
<h1>Administración de préstamos <small>Administra los préstamos de los recursos</small></h1>
<ol class="breadcrumb">
<li><a [routerLink]="['/admin']"><i class="fa fa-dashboard"></i> Inicio</a></li>
<li><a [routerLink]="['/admin/loans']">Préstamo</a></li>
<li class="active">Añadir préstamo</li>
</ol>
</section>

<section class="content">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Nuevo préstamo</h3>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-8">
<div class="form-group">
<label>Recursos disponibles a prestar</label>
<br>
<select [(ngModel)]="resourceSelect">
<ng-template ngFor let-resource [ngForOf]="resources">
<option *ngIf="resource.noReservedCopies.length > 0" [ngValue]="resource">{{resource.title}}</option>
</ng-template>
</select>
</div>
<div class="form-group">
<label>Usuario</label>
<br>
<select [(ngModel)]="userSelect">
<option *ngFor="let user of users" [ngValue]="user">{{user.name}}</option>
</select>
</div>
<br>
<div class="pull-left">
<input type="submit" class="btn btn-success" (click)="createLoan()">
</div>
</div>
</div>
</div>
</div>
</section>
Loading

0 comments on commit b4fab34

Please sign in to comment.