Skip to content

Commit

Permalink
Use SQL query API in reward codes page
Browse files Browse the repository at this point in the history
  • Loading branch information
lcdr authored and Xiphoseer committed Apr 7, 2024
1 parent c83bf9b commit 64f233f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 61 deletions.
52 changes: 34 additions & 18 deletions src/app/objects/reward-codes/reward-codes.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@
</ul>
<h2>Reward codes</h2>

<ng-container *luxVar="$code_groups | async; let code_groups">
<lux-gate-version-toc [list]="code_groups | paramset:'gate_version' | as_array"></lux-gate-version-toc>
<ng-container *ngIf="'
select
gate_version,
attachmentLOT,
icon_asset,
code,
subjectText_en_US as subjectText,
bodyText_en_US as bodyText
from
RewardCodes rc
left join ComponentsRegistry c on c.id = rc.attachmentLOT
left join RenderComponent r on r.id = c.component_id
where
attachmentLOT is null
or component_type = 2
order by rc.code
' | query | group:'gate_version';
let code_groups">
<lux-gate-version-toc [list]="code_groups | keyset | as_array"></lux-gate-version-toc>

<section [id]="code_group.gate_version | toc:'fg'" *ngFor="let code_group of code_groups">
<h3 *ngIf="code_group.gate_version !== ''">Feature Gate: <small><lux-gate-version-tag
[gate_version]="code_group.gate_version" [float]="false"></lux-gate-version-tag></small></h3>
<h3 *ngIf="code_group.gate_version === ''">No Feature Gate</h3>
<section [id]="v.key | toc:'fg'" *ngFor="let v of code_groups | keys">
<h3 *ngIf="v.key === ''">No Feature Gate</h3>
<h3 *ngIf="v.key !== ''">Feature Gate: <small><lux-gate-version-tag
[gate_version]="v.key" [float]="false"></lux-gate-version-tag></small>
</h3>
<div>
<div *ngFor="let code of code_group.codes">
<div class="item">
<lux-slot [luxFetchItem]="code.attachmentLOT"></lux-slot>
<div *ngFor="let row of v.value">
<div class="item" *ngIf="row.attachmentLOT">
<lux-slot link="/objects/{{row.attachmentLOT}}" [icon]="row.icon_asset | icon" [luxItemTooltip]="row.attachmentLOT"></lux-slot>
</div>
<div class="code-desc" *ngIf="loc(code.id) | async; let code_loc; else no_loc">
<h4>{{code_loc.subjectText}} <code>{{code.code}}</code></h4>
<p>{{code_loc.bodyText}}</p>
<div class="code-desc">
<h4>
<span luxTooltip="subjectText">{{row.subjectText}}</span>
<code luxTooltip="code">{{row.code}}</code>
</h4>
<p><span luxTooltip="bodyText">{{row.bodyText}}</span></p>
</div>
<ng-template #no_loc>
<div class="code-desc">
<h4><code>{{code.code}}</code></h4>
</div>
</ng-template>
<div class="clearfix"></div>
</div>
</div>
</section>
</ng-container>
</ng-container>
45 changes: 2 additions & 43 deletions src/app/objects/reward-codes/reward-codes.component.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { DB_RewardCodes } from '../../../defs/cdclient';
import { Locale_RewardCodes } from '../../../defs/locale';
import { LuCoreDataService } from '../../util/services/lu-core-data.service';
import { ObjectsByComponentComponent } from '../by-component/by-component.component';

type RewardCodeDict = { gate_version: string, codes: DB_RewardCodes[] }[];

function codeSort(a: DB_RewardCodes, b: DB_RewardCodes) {
return a.code.localeCompare(b.code);
}
import { Component } from '@angular/core';

@Component({
selector: 'lux-reward-codes',
templateUrl: './reward-codes.component.html',
styleUrls: ['./reward-codes.component.css']
})
export class RewardCodesComponent implements OnInit {

$code_groups: Observable<RewardCodeDict>;
$loc: Observable<{[key: string]: Locale_RewardCodes}>;

constructor(private luCoreData: LuCoreDataService) { }

ngOnInit(): void {
this.$code_groups = this.luCoreData.getTableEntry("RewardCodes", "all").pipe(map(list => {
let dict: { [key: string]: DB_RewardCodes[] } = {};
for (let code of list) {
let gate = code.gate_version || '';
if (!dict.hasOwnProperty(gate)) {
dict[gate] = [];
};
dict[gate].push(code);
}
return Object.keys(dict).sort().map(gate => {
return { gate_version: gate, codes: dict[gate].sort(codeSort) }
});
}));
this.$loc = this.luCoreData.getLocaleSubtree("RewardCodes");
}

loc(key: number): Observable<Locale_RewardCodes> {
const str = String(key);
return this.$loc.pipe(map(all => all[str]));
}

}
export class RewardCodesComponent {}

0 comments on commit 64f233f

Please sign in to comment.