Skip to content

Commit 2535b92

Browse files
committed
Show report and formReport funcinality added
1 parent eded5d0 commit 2535b92

File tree

8 files changed

+80
-30
lines changed

8 files changed

+80
-30
lines changed

angular/wallypop/src/app/app.routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const appRoutes = [
1919
{ path: 'newaccount', component: NewaccountComponent },
2020
{ path: 'profile', component: ProfileComponent },
2121
{ path: 'category', component: CategoryComponent},
22-
{ path: 'formReport', component: FormReportComponent},
22+
{ path: 'formReport/:id', component: FormReportComponent},
2323
{ path: 'reports', component: ReportsComponent},
2424
{ path: 'showReport', component: ShowReportComponent},
2525
{ path: 'categoryList', component: CategoryListComponent},

angular/wallypop/src/app/components/articles/post.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h3 class="text-info">Envía tu mensaje</h3>
163163
</p>
164164
<div id="map"></div>
165165
<br>
166-
<a href="/{{article.id_ARTICLE}}/formularioReporte">¿ES INAPROPIADO? REPORTAR ESTE ANUNCIO</a>
166+
<a (click)="newForm()">¿ES INAPROPIADO? REPORTAR ESTE ANUNCIO</a>
167167
<div class="page-header">
168168
<!-- <h3 class="text-light text-center">Comparte este anuncio</small></h1> -->
169169
</div>

angular/wallypop/src/app/components/articles/post.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {CategoryService} from '../../services/category.service';
77
import {User} from '../../models/user.model';
88
import {Observable} from 'rxjs';
99
import {ActivatedRoute, Router} from '@angular/router';
10+
import { ReportService } from 'src/app/services/report.service';
1011

1112
@Component({
1213
selector: 'post',
@@ -18,7 +19,7 @@ export class PostComponent implements OnInit {
1819
categories: Category[];
1920
idArticle: number;
2021
// tslint:disable-next-line:max-line-length
21-
constructor(private articleService: ArticleService, private categoryService: CategoryService, public loginService: LoginService, private routing: ActivatedRoute, private router: Router) {
22+
constructor(private reportService:ReportService,private articleService: ArticleService, private categoryService: CategoryService, public loginService: LoginService, private routing: ActivatedRoute, private router: Router) {
2223
this.idArticle = -1;
2324
}
2425

@@ -66,4 +67,9 @@ export class PostComponent implements OnInit {
6667
isReserved(): boolean {
6768
return this.article.reserved;
6869
}
70+
71+
newForm() {
72+
this.router.navigate(['/formReport/'+this.article.id_ARTICLE]);
73+
}
74+
6975
}

angular/wallypop/src/app/components/report/formReport.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ <h3 class="text-info">Formulario</h3>
1212
<div class="form-group">
1313
<label class="col-sm-3 control-label">Email</label>
1414
<div class="col-sm-7">
15-
<input class="form-control" [(ngModel)]="report.email" placeholder=" email" required="" type="email">
15+
<input class="form-control" #email placeholder=" email" required="" type="email">
1616
</div>
1717
</div>
1818
<div class="form-group">
1919
<label class="col-sm-3 control-label">Descripción de la incidencia</label>
2020
<div class="col-sm-7">
21-
<textarea class="form-control" [(ngModel)]="report.description" placeholder="description"
21+
<textarea #description class="form-control" placeholder="description"
2222
required="" type="text"></textarea>
2323
</div>
2424
</div>
@@ -38,7 +38,7 @@ <h3 class="text-info">Ficheros</h3>
3838
Política de Privacidad</a>
3939
</p>
4040
<p class="text-center">
41-
<button (click)="save()" class="btn btn-info" type="submit" value="Continuar">Continuar</button>
41+
<button (click)="save($event,email.value,description.value)" class="btn btn-info" type="submit" value="Continuar">Continuar</button>
4242
</p>
4343
</form>
4444
</div>

angular/wallypop/src/app/components/report/formReport.component.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,41 @@ import {ReportService} from '../../services/report.service';
22
import {Component, ViewChild} from '@angular/core';
33
import { Report } from 'src/app/models/report.model';
44
import { ActivatedRoute, Router } from '@angular/router';
5+
import { ArticleService } from 'src/app/services/article.service';
6+
import { Article } from 'src/app/models/article.model';
57

68
@Component({
79
selector: 'formReport',
810
templateUrl: './formReport.component.html'
911
})
1012
export class FormReportComponent {
1113
report: Report;
14+
article:Article;
1215
@ViewChild("file")
1316
file: any;
17+
1418

1519

16-
constructor(public reportService: ReportService,private router: Router,activatedRoute: ActivatedRoute) {
17-
this.report = { article:null,email:'', description: ''};
20+
constructor(public reportService: ReportService,private router: Router,private activatedRoute: ActivatedRoute,private articleService:ArticleService) {
21+
}
22+
id_article:number;
23+
ngOnInit(): void {
24+
this.id_article = this.activatedRoute.snapshot.params['id'];
25+
this.articleService.getArticle(this.id_article).subscribe(
26+
article => this.article = article,
27+
error => console.error(error)
28+
);
29+
this.report = { article:this.article ,email:'', description: ''};
1830
}
19-
2031

2132

22-
save() {
23-
this.reportService.addReport(this.report).subscribe(
33+
save(event:any,email:string,description:string) {
34+
console.log('report.save');
35+
this.reportService.addReport(email,description,this.id_article);
36+
/*this.reportService.addReport(this.report).subscribe(
2437
(report: Report) => this.uploadImage(report),
2538
error => alert('Error creating new report: ' + error)
26-
);
39+
);*/
2740
}
2841

2942
uploadImage(reportProof: Report): void {

angular/wallypop/src/app/components/report/showReport.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ <h3 class="text-info">{{report.id_REPORT}}</h3>
3333
<h3 class="text-info">Fichero adjunto por el usuario</h3>
3434
<a download="" >Download</a><!--href="{{ID_REPORT}}/image"-->
3535
<p class="text-center">
36-
<a class="btn btn-success" >ACEPTAR REPORTE</a><!--href="/showReport/{{ID_REPORT}}/deleteArticle" -->
37-
<a class="btn btn-danger" >RECHAZAR REPORTE</a> <!--href="/showReport/{{ID_REPORT}}/delete"> -->
36+
<a (click)="aceptReport()" class="btn btn-success" >ACEPTAR REPORTE</a><!--href="/showReport/{{ID_REPORT}}/deleteArticle" -->
37+
<a (click)="rejectReport()" class="btn btn-danger" >RECHAZAR REPORTE</a> <!--href="/showReport/{{ID_REPORT}}/delete"> -->
3838
</p>
3939
<!-- {{/report}} -->
4040
</form>

angular/wallypop/src/app/components/report/showReport.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ReportService} from '../../services/report.service';
22
import {Component, OnInit} from '@angular/core';
3-
import { ActivatedRoute } from '@angular/router';
3+
import { ActivatedRoute, Router } from '@angular/router';
44
import { Report } from 'src/app/models/report.model';
55

66
@Component({
@@ -10,7 +10,7 @@ import { Report } from 'src/app/models/report.model';
1010
export class ShowReportComponent implements OnInit{
1111
report:Report;
1212

13-
constructor(private reportService: ReportService,private activatedRoute: ActivatedRoute) {
13+
constructor(private reportService: ReportService,private activatedRoute: ActivatedRoute,private router: Router) {
1414
}
1515

1616
ngOnInit(): void {
@@ -22,5 +22,24 @@ export class ShowReportComponent implements OnInit{
2222
console.log(this.report);
2323
}
2424

25+
rejectReport() {
26+
this.reportService.deleteReport(this.report).subscribe(
27+
_ => this.router.navigate(['/reports']),
28+
error => console.error(error)
29+
);
30+
}
2531

26-
}
32+
aceptReport() {
33+
this.reportService.aceptReport(this.report).subscribe(
34+
_ => this.router.navigate(['/reports']),
35+
error => console.error(error)
36+
);
37+
}
38+
39+
downloadProof() {
40+
this.reportService.proof(this.report).subscribe(
41+
error => console.error(error)
42+
);
43+
}
44+
45+
}

angular/wallypop/src/app/services/report.service.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Injectable } from "@angular/core";
33
import { Router } from "@angular/router";
44
import { Observable , throwError} from "rxjs";
55
import { catchError } from "rxjs/operators";
6+
import { Article } from "../models/article.model";
67
import { Report } from "../models/report.model";
78

89

@@ -26,27 +27,38 @@ export class ReportService {
2627
}
2728

2829
deleteReport(report: Report) {
29-
return this.httpClient.delete(BASE_URL + report.id_REPORT).pipe(
30+
this.httpClient.delete(BASE_URL +"admin/reports/"+report.id_REPORT+"/rejectReport").pipe(
3031
catchError(error => this.handleError(error))
3132
);
33+
this.router.navigate(['reports']);
3234
}
3335

36+
aceptReport(report: Report) {
37+
this.httpClient.delete(BASE_URL +"admin/reports/"+report.id_REPORT+"/aceptReport").pipe(
38+
catchError(error => this.handleError(error))
39+
);
40+
this.router.navigate(['reports']);
41+
}
3442

35-
addReport(report: Report) {
36-
//Deberia ser (id_article:number) y abajo BASE_URL+"reports/"+id_article
37-
if (!report.id_REPORT) {
38-
return this.httpClient.post(BASE_URL + "reports/3", report)
39-
.pipe(
40-
catchError(error => this.handleError({ error }))
41-
);
42-
} else {
43-
return this.httpClient.put(BASE_URL + "reports" + report.id_REPORT, report).pipe(
44-
catchError(error => this.handleError({ error }))
45-
);
46-
}
43+
proof(report: Report) {
44+
return this.httpClient.get(BASE_URL +"admin/reports/"+report.id_REPORT+"/proof").pipe(
45+
catchError(error => this.handleError(error))
46+
);
47+
}
48+
49+
50+
addReport(email:string,description:string,id:number) {
51+
this.httpClient.post(BASE_URL + "reports/"+id, {email,description})
52+
.subscribe(
53+
(response) => this.router.navigate(['post/'+id]),
54+
(error) => alert('Ha ocurrido un error en el reporte')
55+
);
4756

4857
}
4958

59+
createForm(article:Article){
60+
return this.httpClient.post(BASE_URL + "reports/" +article.id_ARTICLE,article);
61+
}
5062

5163
setReportProof(report: Report, formData: FormData) {
5264
return this.httpClient.post(BASE_URL +'reports/'+ report.id_REPORT + '/proof', formData)

0 commit comments

Comments
 (0)