-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from cvazquezlos/carlos
Carlos
- Loading branch information
Showing
13 changed files
with
90 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 63 additions & 64 deletions
127
frontend/src/app/component/admin/manage-resources/create/create.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,80 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
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 {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 {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'] | ||
templateUrl: './create.component.html', | ||
styleUrls: ['./create.component.css'] | ||
}) | ||
export class CreateResourceComponent implements OnInit { | ||
|
||
resource: Resource; | ||
genres: Genre[]; | ||
types: ResourceType[]; | ||
resource: Resource; | ||
genres: Genre[]; | ||
types: ResourceType[]; | ||
|
||
newResource: any = {}; | ||
resourceImage: any; | ||
newResource: any = {}; | ||
resourceImage: any; | ||
|
||
errorMessage: boolean; | ||
message: string; | ||
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 | ||
} | ||
constructor(private router: Router, | ||
private sessionService: SessionService, | ||
private resourceService: ResourceService, | ||
private genreService: GenreService) { | ||
this.newResource = { | ||
title: '', | ||
author: '', | ||
editorial: '', | ||
description: '', | ||
genre: null, | ||
resourceType: null, | ||
resourceCopiesNumber: 1 | ||
} | ||
} | ||
|
||
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) | ||
) | ||
} | ||
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; | ||
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.' | ||
} | ||
); | ||
} | ||
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]; | ||
} | ||
selectFile($event) { | ||
this.resourceImage = $event.target.files[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters