Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { Component, OnInit, OnDestroy } from '@angular/core';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
import { JhiEventManager, JhiParseLinks } from 'ng-jhipster';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
import { ITEMS_PER_PAGE } from 'app/shared/constants/pagination.constants';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { UserWatchListDeleteDialogComponent } from './user-watch-list-delete-dialog.component';
@Component({
selector: 'jhi-bookmarks',
templateUrl: './bookmarks.component.html',
})
export class BookmarkComponent implements OnInit, OnDestroy {
userWatchLists: IUserWatchList[];
eventSubscriber?: Subscription;
itemsPerPage: number;
links: any;
page: number;
predicate: string;
ascending: boolean;
currentSearch: string;
constructor(
protected userWatchListService: UserWatchListService,
protected eventManager: JhiEventManager,
protected modalService: NgbModal,
protected parseLinks: JhiParseLinks,
protected activatedRoute: ActivatedRoute
) {
this.userWatchLists = [];
this.itemsPerPage = ITEMS_PER_PAGE;
this.page = 0;
this.links = {
last: 0,
};
this.predicate = 'id';
this.ascending = true;
this.currentSearch =
this.activatedRoute.snapshot && this.activatedRoute.snapshot.queryParams['search']
? this.activatedRoute.snapshot.queryParams['search']
: '';
}
loadAll(): void {
if (this.currentSearch) {
this.userWatchListService
.search({
query: this.currentSearch,
page: this.page,
size: this.itemsPerPage,
sort: this.sort(),
})
.subscribe((res: HttpResponse<IUserWatchList[]>) => this.paginateUserWatchLists(res.body, res.headers));
return;
}
this.userWatchListService
.query({
page: this.page,
size: this.itemsPerPage,
sort: this.sort(),
})
.subscribe((res: HttpResponse<IUserWatchList[]>) => this.paginateUserWatchLists(res.body, res.headers));
}
reset(): void {
this.page = 0;
this.userWatchLists = [];
this.loadAll();
}
loadPage(page: number): void {
this.page = page;
this.loadAll();
}
search(query: string): void {
this.userWatchLists = [];
this.links = {
last: 0,
};
this.page = 0;
if (query) {
this.predicate = '_score';
this.ascending = false;
} else {
this.predicate = 'id';
this.ascending = true;
}
this.currentSearch = query;
this.loadAll();
}
ngOnInit(): void {
this.loadAll();
this.registerChangeInUserWatchLists();
}
ngOnDestroy(): void {
if (this.eventSubscriber) {
this.eventManager.destroy(this.eventSubscriber);
}
}
trackId(index: number, item: IUserWatchList): number {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return item.id!;
}
registerChangeInUserWatchLists(): void {
this.eventSubscriber = this.eventManager.subscribe('userWatchListListModification', () => this.reset());
}
delete(userWatchList: IUserWatchList): void {
const modalRef = this.modalService.open(UserWatchListDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.userWatchList = userWatchList;
}
sort(): string[] {
const result = [this.predicate + ',' + (this.ascending ? 'asc' : 'desc')];
if (this.predicate !== 'id') {
result.push('id');
}
return result;
}
protected paginateUserWatchLists(data: IUserWatchList[] | null, headers: HttpHeaders): void {
const headersLink = headers.get('link');
this.links = this.parseLinks.parse(headersLink ? headersLink : '');
if (data) {
for (let i = 0; i < data.length; i++) {
this.userWatchLists.push(data[i]);
}
}
}
}