Skip to content

Commit 3b6fd10

Browse files
lcdrXiphoseer
authored andcommitted
Use lux-table in objects by type page
1 parent ae273a4 commit 3b6fd10

File tree

3 files changed

+22
-99
lines changed

3 files changed

+22
-99
lines changed

src/app/objects/by-type/by-type.component.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
<h2>Objects <small>Type: "{{type}}"</small></h2>
88

9-
<div class="table-responsive">
10-
<table>
11-
<tr>
12-
<th>ID</th>
13-
<th>Name</th>
14-
<th>Localized Name</th>
15-
</tr>
16-
<tr *ngFor="let object of objects | async">
17-
<td>{{object.id}}</td>
18-
<td><a routerLink="/objects/{{object.id}}">{{object.name ? object.name : '[Unnamed]'}}</a></td>
19-
<td>{{object.id | loc:"Objects" | async | elem:"name" }}</td>
20-
</tr>
21-
</table>
22-
</div>
23-
24-
<app-pagination [prefix]="'/objects/types/' + type" [count]="page_count" [current]="page"></app-pagination>
9+
<lux-table
10+
select="id as ID, name as Name, name_en_US as 'Localized Name'"
11+
from="Objects"
12+
where="type = '{{type}}'"
13+
order-by="ID"
14+
[limit]="100"
15+
[page]="page" #table>
16+
<tr *ngFor="let row of table.rows">
17+
<td>{{row.ID}}</td>
18+
<td><a routerLink="/objects/{{row.ID}}">{{row.Name}}</a></td>
19+
<td>{{row["Localized Name"]}}</td>
20+
</tr>
21+
</lux-table>
Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,19 @@
1-
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
3-
import { Observable } from 'rxjs';
4-
import { map, switchMap, tap } from 'rxjs/operators';
5-
6-
import { LuCoreDataService } from '../../services';
7-
import { DB_ObjectRef_ByType } from '../../../defs/cdclient';
8-
9-
interface ObjectsByTypeEmbedded {
10-
objects: {[key: number]: {id: number, name: number}};
11-
}
12-
13-
interface ObjectsByType {
14-
object_ids: number[];
15-
_embedded: ObjectsByTypeEmbedded;
16-
}
173

184
@Component({
195
selector: 'app-by-type',
206
templateUrl: './by-type.component.html',
217
styleUrls: ['./by-type.component.css']
228
})
23-
export class ObjectsByTypeComponent implements OnInit {
24-
25-
page_size: number = 100;
26-
page: number = -1;
27-
page_count: number = -1;
9+
export class ObjectsByTypeComponent {
2810
type: string = "";
29-
objects: Observable<DB_ObjectRef_ByType[]>;
30-
count: Observable<number[]>;
31-
32-
constructor(
33-
private luCoreData: LuCoreDataService,
34-
private route: ActivatedRoute,
35-
private cd: ChangeDetectorRef,
36-
) { }
37-
38-
ngOnInit() {
39-
this.objects = this.route.paramMap
40-
.pipe(map(this.mapRouteInfo), tap(this.tapRef.bind(this)), switchMap(this.loadDataObservable.bind(this)))
41-
this.objects.subscribe(x => this.cd.detectChanges());
42-
}
43-
44-
mapRouteInfo(map) {
45-
let type = map.get('type');
46-
if (map.has('page')) {
47-
let page = map.get('page');
48-
return { type: type, page: +page };
49-
} else {
50-
return { type: type, page: 0 };
51-
}
52-
}
11+
page: number = 0;
5312

54-
tapRef(ref) {
55-
this.type = ref.type;
56-
this.page = ref.page;
57-
this.cd.detectChanges();
13+
constructor(private route: ActivatedRoute) {
14+
this.route.params.subscribe(p => {
15+
this.type = p.type;
16+
this.page = Number(p.page);
17+
});
5818
}
59-
60-
loadDataObservable(ref) {
61-
return this.luCoreData.getRevEntry<ObjectsByType>('object_types', ref.type)
62-
.pipe(
63-
map((v: ObjectsByType) => v.object_ids.map(id => {
64-
return { id, name: v._embedded.objects[id].name };
65-
})),
66-
tap(this.setPageCounters.bind(this, ref)),
67-
map(this.processData.bind(this, ref))
68-
);
69-
}
70-
71-
setPageCounters(ref, data) {
72-
this.page_count = Math.ceil(data.length / this.page_size);
73-
}
74-
75-
processData(ref, data) {
76-
let sorted = data.sort(this.sortObjectTypeRefs);
77-
let from = this.page_size * ref.page;
78-
let to = from + this.page_size;
79-
let page = sorted.slice(from, to);
80-
return page;
81-
}
82-
83-
sortObjectTypeRefs(a, b) {
84-
return a.id - b.id;
85-
}
86-
87-
88-
8919
}

src/app/objects/objects-routing.module.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ const objectsRoutes: Routes = [
3535
{ path: 'loot/table/:id', component: LootTableComponent, data: { title: params => `LootTable #${params.id}` } },
3636
{ path: 'loot/matrix/:id', component: LootMatrixComponent, data: { title: params => `LootMatrix #${params.id}` } },
3737
{ path: 'search', component: ObjectsSearchComponent, data: { title: "Search" } },
38-
{
39-
path: 'types/:type', component: ObjectsByTypeComponent, data: {
40-
title: params => `Objects (${params['type']})`
41-
}
42-
},
38+
{ path: 'types/:type', redirectTo: "/objects/types/:type/page/0", pathMatch: "full" },
4339
{
4440
path: 'types/:type/page/:page', component: ObjectsByTypeComponent, data: {
4541
title: params => `Objects (${params['type']}; Page ${params['page']})`

0 commit comments

Comments
 (0)