add song reporting
This commit is contained in:
@@ -5,5 +5,10 @@
|
||||
<app-user-name [userId]="show.owner"></app-user-name>
|
||||
</div>
|
||||
<div>{{ show.showType | showType }}</div>
|
||||
<div>
|
||||
@if (showStatusBadge) {
|
||||
<app-badge [type]="showStatusBadgeType">{{ showStatusBadge }}</app-badge>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.list-item {
|
||||
padding: 5px 20px;
|
||||
display: grid;
|
||||
grid-template-columns: 100px 150px auto;
|
||||
grid-template-columns: 100px 150px auto 160px;
|
||||
min-height: 21px;
|
||||
|
||||
& > div {
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
||||
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {BehaviorSubject, of} from 'rxjs';
|
||||
import {ListItemComponent} from './list-item.component';
|
||||
import {UserService} from '../../../../services/user/user.service';
|
||||
|
||||
describe('ListItemComponent', () => {
|
||||
let component: ListItemComponent;
|
||||
let fixture: ComponentFixture<ListItemComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
void TestBed.configureTestingModule({
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ListItemComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: UserService,
|
||||
useValue: {
|
||||
user$: new BehaviorSubject<unknown>({id: 'user-1'}).asObservable(),
|
||||
userId$: new BehaviorSubject<string | null>('user-1').asObservable(),
|
||||
loggedIn$: () => of(true),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ListItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
void expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render a status badge when provided', () => {
|
||||
component.show = {date: {toDate: () => new Date('2026-03-15')} as never, owner: 'user-1', showType: 'misc-private'} as never;
|
||||
component.showStatusBadge = 'nicht gemeldet';
|
||||
component.showStatusBadgeType = 'error';
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const badge = fixture.nativeElement.querySelector('app-badge .badge');
|
||||
expect(badge?.textContent?.trim()).toBe('nicht gemeldet');
|
||||
expect(badge?.className).toContain('error');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,16 @@ import {Show} from '../../services/show';
|
||||
import {DatePipe} from '@angular/common';
|
||||
import {UserNameComponent} from '../../../../services/user/user-name/user-name.component';
|
||||
import {ShowTypePipe} from '../../../../widget-modules/pipes/show-type-translater/show-type.pipe';
|
||||
import {BadgeComponent, BadgeType} from '../../../../widget-modules/components/badge/badge.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-list-item',
|
||||
templateUrl: './list-item.component.html',
|
||||
styleUrls: ['./list-item.component.less'],
|
||||
imports: [UserNameComponent, DatePipe, ShowTypePipe],
|
||||
imports: [UserNameComponent, DatePipe, ShowTypePipe, BadgeComponent],
|
||||
})
|
||||
export class ListItemComponent {
|
||||
@Input() public show: Show | null = null;
|
||||
@Input() public showStatusBadge: string | null = null;
|
||||
@Input() public showStatusBadgeType: BadgeType = 'none';
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
@for (show of shows | sortBy: 'desc':'date'; track trackBy($index, show)) {
|
||||
<app-list-item
|
||||
[routerLink]="show.id"
|
||||
[showStatusBadge]="show.published ? 'nicht gemeldet' : 'unveröffentlicht'"
|
||||
[showStatusBadgeType]="show.published ? 'error' : 'none'"
|
||||
[show]="show"
|
||||
></app-list-item>
|
||||
}
|
||||
|
||||
@@ -1,24 +1,73 @@
|
||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
||||
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {BehaviorSubject, of} from 'rxjs';
|
||||
import {ListComponent} from './list.component';
|
||||
import {ShowService} from '../services/show.service';
|
||||
import {UserService} from '../../../services/user/user.service';
|
||||
import {FilterStoreService} from '../../../services/filter-store.service';
|
||||
|
||||
describe('ListComponent', () => {
|
||||
let component: ListComponent;
|
||||
let fixture: ComponentFixture<ListComponent>;
|
||||
let shows$: BehaviorSubject<unknown[]>;
|
||||
let user$: BehaviorSubject<unknown>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
void TestBed.configureTestingModule({
|
||||
beforeEach(async () => {
|
||||
shows$ = new BehaviorSubject<unknown[]>([]);
|
||||
user$ = new BehaviorSubject<unknown>({id: 'user-1'});
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ListComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ShowService,
|
||||
useValue: {
|
||||
list$: () => shows$.asObservable(),
|
||||
listPublicSince$: () => of([]),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: UserService,
|
||||
useValue: {
|
||||
user$: user$.asObservable(),
|
||||
},
|
||||
},
|
||||
FilterStoreService,
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
void expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should list own drafts and pending published shows in my shows', done => {
|
||||
shows$.next([
|
||||
{id: 'draft-own', owner: 'user-1', published: false, reportedType: null},
|
||||
{id: 'pending-own', owner: 'user-1', published: true, reportedType: 'pending'},
|
||||
{id: 'reported-own', owner: 'user-1', published: true, reportedType: 'reported'},
|
||||
{id: 'draft-other', owner: 'user-2', published: false, reportedType: null},
|
||||
] as never);
|
||||
|
||||
component.privateShows$.subscribe(shows => {
|
||||
expect(shows.map(show => show.id)).toEqual(['draft-own', 'pending-own']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore show filters for my shows', done => {
|
||||
const filterStore = TestBed.inject(FilterStoreService);
|
||||
filterStore.updateShowFilter({time: 0, showType: 'service-worship'});
|
||||
shows$.next([
|
||||
{id: 'older-draft', owner: 'user-1', published: false, reportedType: null, showType: 'misc-private'},
|
||||
{id: 'pending-own', owner: 'user-1', published: true, reportedType: 'pending', showType: 'home-group'},
|
||||
] as never);
|
||||
|
||||
component.privateShows$.subscribe(shows => {
|
||||
expect(shows.map(show => show.id)).toEqual(['older-draft', 'pending-own']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import {FilterComponent} from './filter/filter.component';
|
||||
import {CardComponent} from '../../../widget-modules/components/card/card.component';
|
||||
import {ListItemComponent} from './list-item/list-item.component';
|
||||
import {SortByPipe} from '../../../widget-modules/pipes/sort-by/sort-by.pipe';
|
||||
import {UserService} from '../../../services/user/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-list',
|
||||
@@ -25,14 +26,19 @@ import {SortByPipe} from '../../../widget-modules/pipes/sort-by/sort-by.pipe';
|
||||
export class ListComponent {
|
||||
private showService = inject(ShowService);
|
||||
private filterStore = inject(FilterStoreService);
|
||||
private userService = inject(UserService);
|
||||
|
||||
public filter$ = this.filterStore.showFilter$;
|
||||
public lastMonths$ = this.filter$.pipe(map((filterValues: FilterValues) => filterValues.time || 1));
|
||||
public owner$ = this.filter$.pipe(map((filterValues: FilterValues) => filterValues.owner));
|
||||
public showType$ = this.filter$.pipe(map((filterValues: FilterValues) => filterValues.showType));
|
||||
public shows$ = this.showService.list$();
|
||||
public privateShows$ = combineLatest([this.shows$, this.filter$]).pipe(
|
||||
map(([shows, filter]) => shows.filter(show => !show.published).filter(show => this.matchesPrivateFilter(show, filter)))
|
||||
public privateShows$ = combineLatest([this.shows$, this.userService.user$]).pipe(
|
||||
map(([shows, user]) =>
|
||||
shows
|
||||
.filter(show => show.owner === user?.id)
|
||||
.filter(show => !show.published || show.reportedType === 'pending')
|
||||
)
|
||||
);
|
||||
public queriedPublicShows$ = this.lastMonths$.pipe(switchMap(lastMonths => this.showService.listPublicSince$(lastMonths)));
|
||||
public fallbackPublicShows$ = combineLatest([this.shows$, this.lastMonths$]).pipe(
|
||||
@@ -50,10 +56,6 @@ export class ListComponent {
|
||||
|
||||
public trackBy = (index: number, show: unknown) => (show as Show).id;
|
||||
|
||||
private matchesPrivateFilter(show: Show, filter: FilterValues): boolean {
|
||||
return this.matchesTimeFilter(show, filter.time || 1) && (!filter.showType || show.showType === filter.showType);
|
||||
}
|
||||
|
||||
private matchesTimeFilter(show: Show, lastMonths: number): boolean {
|
||||
const startDate = new Date();
|
||||
startDate.setHours(0, 0, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user