Skip to content

Commit a96cd1c

Browse files
committed
Commercial showing articles with images only when have not been sold
1 parent a0e3b89 commit a96cd1c

File tree

6 files changed

+241
-15
lines changed

6 files changed

+241
-15
lines changed

angular/wallypop/.idea/workspace.xml

Lines changed: 18 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/wallypop/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import {NewaccountComponent} from './components/login/newaccount.component';
1313
import { ProfileComponent } from './components/profile/profile.component';
1414
import { CategoryComponent } from './components/category/category.component';
1515
import { CategoryListComponent } from './components/category/categoryList.component';
16+
import {CommercialComponent} from './components/articles/commercial.component';
1617

1718
@NgModule({
18-
declarations: [AppComponent, IndexComponent, LoginComponent, SearchComponent, NotFoundComponent, NewaccountComponent, ProfileComponent, CategoryComponent, CategoryListComponent],
19+
// tslint:disable-next-line:max-line-length
20+
declarations: [AppComponent, IndexComponent, LoginComponent, SearchComponent, NotFoundComponent, NewaccountComponent, ProfileComponent, CategoryComponent, CategoryListComponent, CommercialComponent],
1921
imports: [BrowserModule, FormsModule, HttpClientModule, routing],
2022
bootstrap: [AppComponent]
2123
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {NewaccountComponent} from './components/login/newaccount.component';
77
import {ProfileComponent} from './components/profile/profile.component';
88
import { CategoryComponent } from './components/category/category.component';
99
import { CategoryListComponent } from './components/category/categoryList.component';
10+
import {CommercialComponent} from './components/articles/commercial.component';
1011

1112
const appRoutes = [
1213
{ path: '', component: IndexComponent },
@@ -15,6 +16,7 @@ const appRoutes = [
1516
{ path: 'profile', component: ProfileComponent },
1617
{ path: 'category', component: CategoryComponent},
1718
{ path: 'categoryList', component: CategoryListComponent},
19+
{ path: 'commercial', component: CommercialComponent },
1820
{ path: '**', component: NotFoundComponent}
1921
];
2022

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
<!-- ====== Page content ======-->
3+
<section class="section">
4+
<search></search>
5+
<!--{{#ERROR}}
6+
<br>
7+
<div class="container">
8+
<div class="alert alert-danger" role="alert">
9+
<center>El artículo que buscas no existe o ya no está disponible</center>
10+
</div>
11+
</div>
12+
{{/ERROR}} -->
13+
<hr>
14+
<div class="container-fluid">
15+
<div class="row">
16+
<div class="col-xs-12 col-sm-3 col-md-2">
17+
<div class="full-width" style="border: 1px solid #E1E1E1; border-radius: 4px; padding: 5px;">
18+
<button class="btn btn-default btn-block hidden-sm hidden-md hidden-lg btn-dropdown-conatiner"
19+
data-drop-cont=".menu-commercial">
20+
FILTROS <i aria-hidden="true" class="fa fa-sort pull-right"></i>
21+
</button>
22+
<form action="/search/commercial" class="full-width menu-commercial" method="GET">
23+
<h4 class="text-light">CATEGORÍA</h4>
24+
<div class="form-group">
25+
<select class="form-control" name="id_category">
26+
<option disabled selected>Selecciona una categoría</option>
27+
<option *ngFor="let category of categories" name="CATEGORY" value="{{category.id_CATEGORY}}">{{category.title}}</option>
28+
</select>
29+
</div>
30+
<p class="text-center">
31+
<button class="btn btn-success btn-block">APLICAR</button>
32+
</p>
33+
<p class="text-center">
34+
<a class="btn btn-info btn-block" href="/commercial" onclick="" type="reset">BORRAR
35+
FILTROS</a>
36+
</p>
37+
<p>
38+
<small>Anuncios segunda mano . Las mejores ofertas en de segunda mano y de ocasión solo
39+
en </small>
40+
</p>
41+
</form>
42+
</div>
43+
</div>
44+
<div class="col-xs-12 col-sm-9 col-md-10">
45+
<div class="full-width">
46+
<ol class="breadcrumb">
47+
<li *ngFor="let category of categories"><a href="/commercial/{{category.id_CATEGORY}}">{{category.title}}</a></li>
48+
</ol>
49+
</div>
50+
<div class="full-widht">
51+
<i class="fa fa-th-large btn btn-default hidden-xs btn-change-post"></i>
52+
<i class="fa fa-refresh btn btn-default"></i>
53+
<i class="fa fa-angle-right btn btn-default"></i>
54+
</div>
55+
<!-- Article -->
56+
<div class="full-width container-post">
57+
<div class="full-width post" *ngFor="let article of articles">
58+
<ng-template [ngIf]="!article.sold">
59+
<figure class="full-width post-img">
60+
<img alt="" class="img-responsive" src="/api/articles/{{article.id_ARTICLE}}/image">
61+
</figure>
62+
<div class="full-width post-info">
63+
<a class="full-width post-info-title" href="/post/{{article.id_ARTICLE}}">{{article.title}}</a>
64+
<p class="full-width post-info-price">{{article.price}}€</p>
65+
<span class="post-info-zone">{{article.city}}</span>
66+
<span class="post-info-date">{{article.date}}</span>
67+
<a *ngIf="this.loginService.isLogged" href="/addFavorite/{{article.id_ARTICLE}}"><i class="fa fa-heart-o post-info-like"></i></a>
68+
</div>
69+
</ng-template>
70+
</div>
71+
</div>
72+
73+
<!-- End Article -->
74+
<div class="clearfix"></div>
75+
<nav class="text-center">
76+
<ul class="pagination">
77+
<li>
78+
<a aria-label="Previous" href="#">
79+
<span aria-hidden="true">&laquo;</span>
80+
</a>
81+
</li>
82+
<li><a href="#">1</a></li>
83+
<li><a href="#">2</a></li>
84+
<li><a href="#">3</a></li>
85+
<li><a href="#">4</a></li>
86+
<li><a href="#">5</a></li>
87+
<li>
88+
<a aria-label="Next" href="#">
89+
<span aria-hidden="true">&raquo;</span>
90+
</a>
91+
</li>
92+
</ul>
93+
</nav>
94+
</div>
95+
</div>
96+
</div>
97+
</section>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {LoginService} from '../../services/login.service';
3+
import {ArticleService} from '../../services/article.service';
4+
import {Article} from '../../models/article.model';
5+
import {Category} from '../../models/category.model';
6+
import {CategoryService} from '../../services/category.service';
7+
8+
@Component({
9+
selector: 'commercial',
10+
templateUrl: './commercial.component.html'
11+
})
12+
export class CommercialComponent implements OnInit {
13+
articles: Article[];
14+
categories: Category[];
15+
constructor(private articleService: ArticleService, private categoryService: CategoryService, private loginService: LoginService) {
16+
}
17+
18+
ngOnInit(): void {
19+
this.getCategories();
20+
this.getArticles();
21+
}
22+
23+
getCategories(): void {
24+
this.categoryService.getCategories().subscribe(
25+
category => this.categories = category,
26+
error => console.log(error)
27+
);
28+
}
29+
30+
getArticles(): void {
31+
this.articleService.getArticles().subscribe(
32+
article => this.articles = article,
33+
error => console.log(error)
34+
);
35+
}
36+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {Injectable} from '@angular/core';
2+
import {HttpClient} from '@angular/common/http';
3+
import {Observable, throwError} from 'rxjs';
4+
import {catchError} from 'rxjs/operators';
5+
6+
import { User } from 'src/app/models/user.model';
7+
import {Article} from '../models/article.model';
8+
import {Router} from '@angular/router';
9+
import {Category} from '../models/category.model';
10+
11+
import {CategoryService} from '../services/category.service';
12+
13+
14+
const BASE_URL = '/api/';
15+
16+
@Injectable({providedIn: 'root'})
17+
export class ArticleService {
18+
19+
constructor(private httpClient: HttpClient, private router: Router) {
20+
}
21+
22+
getArticles(): Observable<Article[]> {
23+
return this.httpClient.get(BASE_URL + 'articles').pipe(
24+
catchError(error => this.handleError(error))
25+
) as Observable<Article[]>;
26+
}
27+
28+
29+
30+
getArticle(id: number | string): Observable<Article> {
31+
return this.httpClient.get(BASE_URL + 'articles/' + id).pipe(
32+
catchError(error => this.handleError(error))
33+
) as Observable<Article>;
34+
}
35+
36+
37+
38+
addArticle(title: string, description: string, city: string, price: number, postal_code: number) {
39+
40+
this.httpClient.post(BASE_URL + 'admin/articles', {title, description, city, price, postal_code}, {withCredentials: true})
41+
.subscribe(
42+
(response) => this.router.navigate(['profile']),
43+
(error) => alert('Usuario ya existe, inicie sesi�n')
44+
);
45+
}
46+
47+
setArticleImage(article: Article, formData: FormData) {
48+
return this.httpClient.post(BASE_URL + article.id_ARTICLE + '/image', formData)
49+
.pipe(
50+
catchError(error => this.handleError(error))
51+
);
52+
}
53+
54+
deleteArticleImage(article: Article) {
55+
return this.httpClient.delete(BASE_URL + article.id_ARTICLE + '/image')
56+
.pipe(
57+
catchError(error => this.handleError(error))
58+
);
59+
}
60+
61+
deleteArticle(article: Article) {
62+
return this.httpClient.delete(BASE_URL + article.id_ARTICLE).pipe(
63+
catchError(error => this.handleError(error))
64+
);
65+
}
66+
67+
updateArticle(article: Article) {
68+
return this.httpClient.put(BASE_URL + article.id_ARTICLE, article).pipe(
69+
catchError(error => this.handleError(error))
70+
);
71+
}
72+
/*
73+
getCategoriesArticle(article: Article): Observable<Category[]> {
74+
return this.httpClient.get(BASE_URL + article.categories).pipe(
75+
catchError(error => CategoryService.handleError(error))
76+
) as Observable<Category[]>;
77+
} */
78+
79+
private handleError(error: any): Observable<never> {
80+
console.log('ERROR:');
81+
console.error(error);
82+
return throwError('Server error (' + error.status + '): ' + error.text());
83+
}
84+
85+
}

0 commit comments

Comments
 (0)