Skip to content

Commit

Permalink
add create loan
Browse files Browse the repository at this point in the history
  • Loading branch information
jherel committed Apr 21, 2017
1 parent ebe1edd commit df473a0
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 127 deletions.
4 changes: 2 additions & 2 deletions backend/src/main/java/appSpring/service/LogicService.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public int createAnUser(User user) {
}

private boolean itIsPossibleToReturn(Action action) {
return ((action.getDateLoanGiven() == new Date(0)) && (action.getDateLoanReturn() == new Date(0)));
return ((action.getDateLoanGiven() != new Date(0)) && (action.getDateLoanReturn() == new Date(0)));
}

private boolean itIsPossibleToGive(Action action) {
Expand Down Expand Up @@ -187,7 +187,7 @@ public int addReturnDate(Action action, Date date) {
if (date1 == new Date(0))
continue;
Date date3 = currentAction.getDateLoanReturn();
if (date3 == new Date(0))
if (date3 != new Date(0))
continue;
date1.setMinutes(date1.getMinutes() + 1);
Date date2 = new Date();
Expand Down
Binary file modified backend/target/classes/appSpring/service/LogicService.class
Binary file not shown.
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/:id', component: EditResourceComponent },
{ path: 'resources/new', component: CreateResourceComponent },
{ 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
30 changes: 17 additions & 13 deletions frontend/src/app/component/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ 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 { 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';
import { CreateResourceComponent } from './manage-resources/create/create.component';

@NgModule({
imports: [
imports: [
CommonModule,
AdminRoutingModule,
FormsModule,
Expand All @@ -32,10 +34,12 @@ import {DashboardComponent} from './dashboard/dashboard.component';
ManageResourcesComponent,
EditResourceComponent,
ManageLoansComponent,
CreateLoanComponent,
ManageFinesComponent,
ManageUsersComponent,
CreateUserComponent,
EditUserComponent,
CreateResourceComponent,

]
})
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>
Original file line number Diff line number Diff line change
@@ -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.getAllResources().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.'
}
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,73 +1,69 @@
<div *ngIf="successMessage" class="alert alert-success">
<strong>¡Eliminado!</strong> {{message}}
<strong>¡Eliminado!</strong> {{message}}
</div>
<div *ngIf="errorMessage" class="alert alert-danger">
<strong>Algo ha ido mal...</strong> {{message}}
<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 class="active">Prestamos</li>
</ol>
<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 class="active">Prestamos</li>
</ol>
</section>

<section class="content">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="10%">Identificador</th>
<th width="15%">Usuario</th>
<th>Recurso</th>
<th>Petición</th>
<th>Préstamo</th>
<th>Devolución</th>
<th>Administrar</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let loan of loans">
<td>{{ loan.copy.locationCode }}</td>
<td>{{ loan.user.name }}</td>
<td>{{ loan.copy.resource.title }}</td>
<td>{{ loan.dateLoanInit }}</td>
<td>
<div *ngIf="loan.dateLoanGiven; else elseBlock">{{ loan.dateLoanGiven }}</div>
<ng-template #elseBlock>
<a>
<button type="button" class="btn btn-primary"><span class="fa fa-bookmark-o"></span> &nbsp; Prestar</button>
</a>
</ng-template>
</td>
<td>
<div *ngIf="loan.dateLoanReturn; else elseBlock">{{ loan.dateLoanReturn }}</div>
<ng-template #elseBlock>
<a>
<button type="button" class="btn btn-primary"><span class="fa fa-bookmark"></span> &nbsp; Devolución</button>
</a>
</ng-template>
</td>
<td>
<button type="button" class="btn btn-warning" (click)="deleteLoan(loan.id)"><span class="fa fa-trash"></span></button>
</td>
</tr>
</tbody>
</table>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="10%">Identificador</th>
<th width="15%">Usuario</th>
<th>Recurso</th>
<th>Petición</th>
<th>Préstamo</th>
<th>Devolución</th>
<th>Administrar</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let loan of loans">
<td>{{ loan.copy.locationCode }}</td>
<td>{{ loan.user.name }}</td>
<td>{{ loan.copy.resource.title }}</td>
<td>{{ loan.dateLoanInit }}</td>
<td>
<div *ngIf="loan.dateLoanGiven != '1970-01-01 00:00:00' ; else elseBlockLoanGiven">{{ loan.dateLoanGiven }}</div>
<ng-template #elseBlockLoanGiven>
<button type="button" class="btn btn-primary" (click)="updateLoan(loan.id, 'give')"><span class="fa fa-bookmark-o"></span> &nbsp; Prestar</button>
</ng-template>
</td>
<td>
<div *ngIf="loan.dateLoanReturn != '1970-01-01 00:00:00' ; else elseBlockLoanReturn">{{ loan.dateLoanReturn }}</div>
<ng-template #elseBlockLoanReturn>
<button type="button" class="btn btn-primary" (click)="updateLoan(loan.id, 'return')"><span class="fa fa-bookmark"></span> &nbsp; Devolución</button>
</ng-template>
</td>
<td>
<button type="button" class="btn btn-warning" (click)="deleteLoan(loan.id)"><span class="fa fa-trash"></span></button>
</td>
</tr>
</tbody>
</table>

<div>
<div class="pull-left">
<a [routerLink]="['/admin/users/new']">
<button type="button" class="btn btn-primary"><span class="fa fa-plus-circle"> </span>&nbsp;Añadir préstamo</button>
</a>
</div>
<div class="pull-right">
<button *ngIf="showPreviousPage" type="button" class="btn btn-primary" (click)="previousPage()">
<div>
<div class="pull-left">
<a [routerLink]="['/admin/loans/new']">
<button type="button" class="btn btn-primary"><span class="fa fa-plus-circle"> </span>&nbsp;Añadir préstamo</button>
</a>
</div>
<div class="pull-right">
<button *ngIf="showPreviousPage" type="button" class="btn btn-primary" (click)="previousPage()">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</button>
<button *ngIf="showNextPage" type="button" class="btn btn-primary" (click)="nextPage()">
<button *ngIf="showNextPage" type="button" class="btn btn-primary" (click)="nextPage()">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
</button>
</div>
</div>
</div>
</section>
</section>
Loading

0 comments on commit df473a0

Please sign in to comment.