Commit 1accc1a8 authored by nanahira's avatar nanahira

support multiple accounts things

parent 7ca94f4e
Pipeline #42160 failed with stages
in 2 minutes and 30 seconds
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
</table> </table>
</div> </div>
</div> </div>
<div class="row grid" *ngIf="whitelistResult?.length"> <div class="row grid" *ngIf="whitelistDisplayResult?.length">
<br> <br>
<div class="col-lg-12"> <div class="col-lg-12">
<table class="table table-striped"> <table class="table table-striped">
...@@ -92,17 +92,23 @@ ...@@ -92,17 +92,23 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let item of whitelistResult"> <tr *ngFor="let row of whitelistDisplayResult">
<td>{{item.name || ''}}</td> <td>{{row.item.name || ''}}</td>
<td>{{item.account || ''}}</td>
<td> <td>
<a *ngIf="item.twitter" [href]="getTwitterLink(item.twitter)" target="_blank"> <div *ngFor="let account of row.accounts">
{{ truncateMiddle(item.twitter, 15) }} {{account}}
</a> </div>
</td> </td>
<td>{{item.fee || ''}}</td> <td>
<td>{{item.type || ''}}</td> <div *ngFor="let twitter of row.twitters">
<td>{{item.forbidden || ''}}</td> <a [href]="getTwitterLink(twitter)" target="_blank">
{{ truncateMiddle(twitter, 15) }}
</a>
</div>
</td>
<td>{{row.item.fee || ''}}</td>
<td>{{row.item.type || ''}}</td>
<td>{{row.item.forbidden || ''}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
import { AfterViewInit, Component } from '@angular/core'; import { AfterViewInit, Component } from '@angular/core';
import { ToastService } from './toast.service'; import { ToastService } from './toast.service';
import { ApiService } from './api/services/api.service';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import * as moment from 'moment'; import * as moment from 'moment';
import { import {
Ad, Ad,
BlacklistAccountResultDto, BlacklistAccountResultDto,
WhitelistAccountResultDto, WhitelistAccountResultDto,
WhitelistAccountRefResultDto,
} from './api/models'; } from './api/models';
import {
AdService,
BlacklistAccountService,
WhitelistAccountService,
} from './api/services';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
...@@ -21,7 +26,17 @@ export class AppComponent implements AfterViewInit { ...@@ -21,7 +26,17 @@ export class AppComponent implements AfterViewInit {
ad: Ad | null = null; ad: Ad | null = null;
blacklistResult?: BlacklistAccountResultDto[]; blacklistResult?: BlacklistAccountResultDto[];
whitelistResult?: WhitelistAccountResultDto[]; whitelistResult?: WhitelistAccountResultDto[];
constructor(public toast: ToastService, private api: ApiService) {} whitelistDisplayResult?: Array<{
item: WhitelistAccountResultDto | WhitelistAccountRefResultDto;
accounts: string[];
twitters: string[];
}>;
constructor(
public toast: ToastService,
private adService: AdService,
private blacklistAccountService: BlacklistAccountService,
private whitelistAccountService: WhitelistAccountService
) {}
ngAfterViewInit() { ngAfterViewInit() {
this.initAd(); this.initAd();
...@@ -35,7 +50,9 @@ export class AppComponent implements AfterViewInit { ...@@ -35,7 +50,9 @@ export class AppComponent implements AfterViewInit {
try { try {
const adId = new URLSearchParams(window.location.search).get('ad'); const adId = new URLSearchParams(window.location.search).get('ad');
const { data: ad } = await lastValueFrom( const { data: ad } = await lastValueFrom(
this.api.adControllerGetAd(adId ? { id: parseInt(adId) } : undefined) this.adService.adControllerGetAd(
adId ? { id: parseInt(adId) } : undefined
)
); );
if (ad) { if (ad) {
this.ad = ad; this.ad = ad;
...@@ -55,7 +72,7 @@ export class AppComponent implements AfterViewInit { ...@@ -55,7 +72,7 @@ export class AppComponent implements AfterViewInit {
async onAdClick() { async onAdClick() {
const clickResult = await lastValueFrom( const clickResult = await lastValueFrom(
this.api.adControllerClickAd({ id: this.ad!.id! }) this.adService.adControllerClickAd({ id: this.ad!.id! })
); );
if (clickResult?.data) { if (clickResult?.data) {
this.openInNewTab(clickResult.data); this.openInNewTab(clickResult.data);
...@@ -70,14 +87,16 @@ export class AppComponent implements AfterViewInit { ...@@ -70,14 +87,16 @@ export class AppComponent implements AfterViewInit {
async searchWhitelist(account?: string) { async searchWhitelist(account?: string) {
this.whitelistResult = undefined; this.whitelistResult = undefined;
this.whitelistDisplayResult = undefined;
const { data } = await lastValueFrom( const { data } = await lastValueFrom(
this.api.whitelistAccountControllerFindAll({ this.whitelistAccountService.whitelistAccountControllerFindAll({
recordsPerPage: 5, recordsPerPage: 5,
account: account || undefined, account: account || undefined,
random: account ? 0 : 1, random: account ? 0 : 1,
}) })
); );
this.whitelistResult = data; this.whitelistResult = data;
this.whitelistDisplayResult = this.buildWhitelistDisplayResult(data);
} }
async checkSearch(allowEmpty = false) { async checkSearch(allowEmpty = false) {
...@@ -102,13 +121,14 @@ export class AppComponent implements AfterViewInit { ...@@ -102,13 +121,14 @@ export class AppComponent implements AfterViewInit {
async onBlacklistSearch() { async onBlacklistSearch() {
this.blacklistResult = undefined; this.blacklistResult = undefined;
this.whitelistResult = undefined; this.whitelistResult = undefined;
this.whitelistDisplayResult = undefined;
const search = this.search.trim(); const search = this.search.trim();
if (!(await this.checkSearch())) { if (!(await this.checkSearch())) {
return; return;
} }
try { try {
const { data } = await lastValueFrom( const { data } = await lastValueFrom(
this.api.blacklistAccountControllerFindAll({ this.blacklistAccountService.blacklistAccountControllerFindAll({
recordsPerPage: 100, recordsPerPage: 100,
account: search, account: search,
}) })
...@@ -126,6 +146,7 @@ export class AppComponent implements AfterViewInit { ...@@ -126,6 +146,7 @@ export class AppComponent implements AfterViewInit {
async onWhitelistSearch() { async onWhitelistSearch() {
this.blacklistResult = undefined; this.blacklistResult = undefined;
this.whitelistResult = undefined; this.whitelistResult = undefined;
this.whitelistDisplayResult = undefined;
const search = this.search.trim(); const search = this.search.trim();
if (!(await this.checkSearch())) { if (!(await this.checkSearch())) {
return; return;
...@@ -141,6 +162,7 @@ export class AppComponent implements AfterViewInit { ...@@ -141,6 +162,7 @@ export class AppComponent implements AfterViewInit {
async onRandomSearch() { async onRandomSearch() {
this.blacklistResult = undefined; this.blacklistResult = undefined;
this.whitelistResult = undefined; this.whitelistResult = undefined;
this.whitelistDisplayResult = undefined;
try { try {
await this.searchWhitelist(); await this.searchWhitelist();
...@@ -157,4 +179,40 @@ export class AppComponent implements AfterViewInit { ...@@ -157,4 +179,40 @@ export class AppComponent implements AfterViewInit {
const keep = Math.floor((maxLength - 3) / 2); // -3 for '...' const keep = Math.floor((maxLength - 3) / 2); // -3 for '...'
return text.slice(0, keep) + '...' + text.slice(-keep); return text.slice(0, keep) + '...' + text.slice(-keep);
} }
private buildWhitelistDisplayResult(data?: WhitelistAccountResultDto[]):
| Array<{
item: WhitelistAccountResultDto | WhitelistAccountRefResultDto;
accounts: string[];
twitters: string[];
}>
| undefined {
if (!data) {
return undefined;
}
return data.map((entry) => {
const item = entry.ref ?? entry;
const accounts = this.uniqueNonEmptyStrings([
item.account,
...(item.refs?.map((refEntry) => refEntry.account) || []),
]);
const twitters = this.uniqueNonEmptyStrings([
item.twitter,
...(item.refs?.map((refEntry) => refEntry.twitter) || []),
]).filter((s) => s && !s.includes(''));
return { item, accounts, twitters };
});
}
private uniqueNonEmptyStrings(values: Array<string | undefined>): string[] {
const seen = new Set<string>();
for (const value of values) {
const normalized = value?.trim();
if (!normalized) {
continue;
}
seen.add(normalized);
}
return Array.from(seen);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment