Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/Turnierplan.Adapter/TurnierplanClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ public sealed partial class TurnierplanClient : IDisposable
{
private const string TurnierplanVersionHeaderName = "x-turnierplan-version";

private static readonly string __turnierplanAdapterVersion;
private static readonly string __turnierplanAdapterVersion =
typeof(TurnierplanClient).Assembly.GetName().Version?.ToString()
?? throw new InvalidOperationException("Could not determine Turnierplan.Adapter version from assembly name.");

private static readonly JsonSerializerOptions __serializerOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
};

static TurnierplanClient()
{
__turnierplanAdapterVersion = typeof(TurnierplanClient).Assembly.GetName().Version?.ToString()
?? throw new InvalidOperationException("Could not determine Turnierplan.Adapter version from assembly name.");
}

private readonly HttpClient _httpClient;
private readonly bool _disposeHttpClient;
private readonly bool _disableIdVerification;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DocumentConfigMatchPlanComponent extends DocumentConfigComponent<Ma
protected matchPlanDateFormats = Object.keys(MatchPlanDateFormat);
protected matchPlanOutcomeTypes = Object.keys(MatchPlanOutcomes);

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(formBuilder: FormBuilder, @Inject(CURRENT_CONFIGURATION) config: MatchPlanDocumentConfiguration) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class DocumentConfigReceiptsComponent extends DocumentConfigComponent<Rec
);

this.amountKeys.push(`${newEntry}`);
this.amountKeys.sort();
this.amountKeys.sort((a, b) => +a - +b);
}

protected removeReducedAmountEntry(amountKey: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DocumentManagerComponent {
protected currentlyLoadingPreview?: string;
protected currentlyUpdatingName?: string;

private configComponents = new Map<DocumentType, Type<DocumentConfigComponent<DocumentConfiguration>>>();
private readonly configComponents = new Map<DocumentType, Type<DocumentConfigComponent<DocumentConfiguration>>>();

constructor(
private readonly injector: Injector,
Expand All @@ -67,7 +67,7 @@ export class DocumentManagerComponent {
return;
}

const configComponent = this.configComponents.get(document.type as DocumentType);
const configComponent = this.configComponents.get(document.type);
if (configComponent === undefined) {
return;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export class DocumentManagerComponent {
}

private getDocumentConfig(document: DocumentDto): Observable<DocumentConfiguration> {
switch (document.type as DocumentType) {
switch (document.type) {
case DocumentType.MatchPlan:
return this.documentService.getMatchPlanDocumentConfiguration({ id: document.id });
case DocumentType.Receipts:
Expand All @@ -215,7 +215,7 @@ export class DocumentManagerComponent {
}

private getDocumentConfigSaveFunction(document: DocumentDto): (config: DocumentConfiguration) => Observable<void> {
switch (document.type as DocumentType) {
switch (document.type) {
case DocumentType.MatchPlan:
return (config) =>
this.documentService.setMatchPlanDocumentConfiguration({ id: document.id, body: config as MatchPlanDocumentConfiguration });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class DurationPickerComponent {
public set duration(value: string) {
// The regex matches duration strings from the .NET TimeSpan class. This allows for the 'days' value
// to be set, however the resulting minutes/seconds is clamped to be at most 23h:59m:59s
const match = value.match(/^(?:(?<d>\d+)\.)?(?<h>\d{2}):(?<m>\d{2}):(?<s>\d{2})(?:\.\d{7})?$/);
const match = /^(?:(?<d>\d+)\.)?(?<h>\d{2}):(?<m>\d{2}):(?<s>\d{2})(?:\.\d{7})?$/.exec(value);

if (match?.groups) {
let hours = +match.groups['h'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class ImageChooserComponent {
next: () => {
if (deleteImageId === this.currentImageId) {
// Close modal with undefined to trigger re-load of tournament page
this.modal.close(undefined);
this.modal.close();
} else {
this.loadImages();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class MatchTreeComponent implements OnChanges, AfterViewInit {

for (const match of currentColumnMatches) {
for (const teamSelector of [match.teamSelectorKeyA, match.teamSelectorKeyB]) {
if (!(teamSelector.charAt(0) === 'W' || teamSelector.charAt(0) === 'L')) {
if (!(teamSelector.startsWith('W') || teamSelector.startsWith('L'))) {
dependentMatchIds.push(undefined);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class RenameDialogComponent {
}
} else if (sanitized.length === 0 && this.allowReset) {
if (sanitizedInitial.length > 0) {
this.modal.close(undefined);
this.modal.close();
} else {
this.modal.dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ <h4 class="modal-title" translate="Portal.ConfigureTournament.ValidationErrors.T
<div class="modal-body d-flex flex-column gap-2">
<div class="mb-4" translate="Portal.ConfigureTournament.ValidationErrors.Info"></div>
<ul>
@for (error of _errors; track error) {
<li>{{ error }}</li>
@for (key of _errorKeys; track key) {
<li>
{{ key }}
<ul>
@for (error of _errors[key]; track error) {
<li>{{ error }}</li>
}
</ul>
</li>
}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
templateUrl: './validation-error-dialog.component.html'
})
export class ValidationErrorDialogComponent {
protected _errors: string[] = [];
protected _errors: { [key: string]: string[] } = {};
protected _errorKeys: string[] = [];

constructor(protected readonly modal: NgbActiveModal) {}

public set errors(value: string[]) {
public set errors(value: { [key: string]: string[] }) {
this._errors = value;
this._errorKeys = Object.keys(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ConfigureTournamentComponent implements OnInit, OnDestroy, DiscardC
protected additionalPlayoffs: { [position: number]: TemporaryAdditionalPlayoff } = {};

// Private variables
private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();
private finalsMatchDefinitions?: FinalsMatchDefinitionDto[];
private originalTournament?: TournamentDto;

Expand Down Expand Up @@ -237,26 +237,35 @@ export class ConfigureTournamentComponent implements OnInit, OnDestroy, DiscardC
next: () => {
this.loadingState = { isLoading: false };
},
error: (error: { response?: string }) => {
if (error.response) {
error: (error: { error?: string }) => {
if (error.error) {
let parsedError: unknown;

try {
const validationErrors = (JSON.parse(error.response) as { errors?: { validations?: string[] } })?.errors?.validations;
if (validationErrors) {
const ref = this.modalService.open(ValidationErrorDialogComponent, {
size: 'md',
fullscreen: 'md',
centered: true
});
(ref.componentInstance as ValidationErrorDialogComponent).errors = validationErrors;
this.loadingState = { isLoading: false };
return;
}
parsedError = JSON.parse(error.error);
} catch (e) {
// ignored
this.loadingState = { isLoading: false, error: error.error };
return;
}
}

this.loadingState = { isLoading: false, error: error };
const validationErrors = (parsedError as { errors?: { [key: string]: string[] } })?.errors;

if (validationErrors) {
const ref = this.modalService.open(ValidationErrorDialogComponent, {
size: 'md',
fullscreen: 'md',
centered: true
});

(ref.componentInstance as ValidationErrorDialogComponent).errors = validationErrors;

this.loadingState = { isLoading: false };
} else {
this.loadingState = { isLoading: false, error: error.error };
}
} else {
this.loadingState = { isLoading: false, error: error };
}
}
});
}
Expand Down Expand Up @@ -377,13 +386,11 @@ export class ConfigureTournamentComponent implements OnInit, OnDestroy, DiscardC

this.additionalPlayoffPositions.push(playoffPosition);

if (this.additionalPlayoffs[playoffPosition] === undefined) {
this.additionalPlayoffs[playoffPosition] = {
isEnabled: false,
teamSelectorA: '',
teamSelectorB: ''
};
}
this.additionalPlayoffs[playoffPosition] ??= {
isEnabled: false,
teamSelectorA: '',
teamSelectorB: ''
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CreateTournamentComponent implements OnDestroy {
protected newFolderName = new FormControl<string | undefined>('');
protected visibility: Visibility = Visibility.Public;

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly organizationService: OrganizationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CreateVenueComponent implements OnDestroy {
protected organization?: OrganizationDto;
protected venueName = new FormControl('', { nonNullable: true });

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly organizationService: OrganizationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class EditMatchPlanComponent implements OnInit, OnDestroy, DiscardChanges
protected localizedTeamSelectors: { [key: string]: string } = {};

// Private variables
private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();
private tournamentId?: string;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class FolderStatisticsComponent implements OnInit, OnDestroy {
datasets: []
};

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly route: ActivatedRoute,
Expand Down Expand Up @@ -65,18 +65,16 @@ export class FolderStatisticsComponent implements OnInit, OnDestroy {
.subscribe({
next: (statistics) => {
if (statistics) {
if (statistics) {
this.folderName = statistics.folderName;
this.organizationId = statistics.organizationId;
this.titleService.setCompoundTitle(statistics.folderName);

if (statistics.goalDistributionExcludedTournaments.length > 0) {
const names = [...statistics.goalDistributionExcludedTournaments.map((x) => x.tournamentName)];
names.sort((a, b) => a.localeCompare(b));
this.goalDistributionExcludedTournaments = names.join(', ');
} else {
this.goalDistributionExcludedTournaments = undefined;
}
this.folderName = statistics.folderName;
this.organizationId = statistics.organizationId;
this.titleService.setCompoundTitle(statistics.folderName);

if (statistics.goalDistributionExcludedTournaments.length > 0) {
const names = [...statistics.goalDistributionExcludedTournaments.map((x) => x.tournamentName)];
names.sort((a, b) => a.localeCompare(b));
this.goalDistributionExcludedTournaments = names.join(', ');
} else {
this.goalDistributionExcludedTournaments = undefined;
}

this.loadingState = { isLoading: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class FolderTimetableComponent implements OnInit, OnDestroy {
protected organizationId?: string;
protected missingTournaments: FolderTimetableTournamentEntry[] = [];

private refresh$ = new BehaviorSubject<boolean>(false);
private destroyed$ = new Subject<void>();
private readonly refresh$ = new BehaviorSubject<boolean>(false);
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly route: ActivatedRoute,
Expand Down Expand Up @@ -83,11 +83,9 @@ export class FolderTimetableComponent implements OnInit, OnDestroy {
.subscribe({
next: (timetable) => {
if (timetable) {
if (timetable) {
this.organizationId = timetable.organizationId;
this.titleService.setCompoundTitle(timetable.folderName);
this.generateTimetableView(timetable);
}
this.organizationId = timetable.organizationId;
this.titleService.setCompoundTitle(timetable.folderName);
this.generateTimetableView(timetable);

this.loadingState = { isLoading: false };
this.showRefreshButton = false;
Expand Down Expand Up @@ -249,8 +247,7 @@ export class FolderTimetableComponent implements OnInit, OnDestroy {
for (const row of day.rows) {
let previousEnd = 0;

for (let i = 0; i < row.entries.length; i++) {
const entry = row.entries[i];
for (const entry of row.entries) {
entry.columnsSpacing = entry.columnsOffset - previousEnd;
previousEnd = entry.columnsOffset + entry.columnsCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ViewOrganizationComponent implements OnInit, OnDestroy {
}
];

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly route: ActivatedRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class ViewTournamentComponent implements OnInit, OnDestroy {
protected isUpdatingVisibility = false;
protected isUpdatingName = false;

private destroyed$ = new Subject<void>();
private readonly destroyed$ = new Subject<void>();

constructor(
private readonly injector: Injector,
Expand Down Expand Up @@ -521,7 +521,7 @@ export class ViewTournamentComponent implements OnInit, OnDestroy {
}

this.groupService
.setGroupName({ groupId: groupId, tournamentId: this.tournament.id, body: { name: name ? name : null } })
.setGroupName({ groupId: groupId, tournamentId: this.tournament.id, body: { name: name ?? null } })
.pipe(switchMap(() => this.tournamentService.getTournament({ id: tournamentId })))
.subscribe({
next: (tournament) => {
Expand Down Expand Up @@ -582,11 +582,8 @@ export class ViewTournamentComponent implements OnInit, OnDestroy {
centered: true
});
const component = ref.componentInstance as MoveTournamentToFolderComponent;
component.initialize(
this.tournament.organizationId,
this.tournament.folderId,
this.tournament.folderName ? this.tournament.folderName : undefined
);

component.initialize(this.tournament.organizationId, this.tournament.folderId, this.tournament.folderName ?? undefined);

component.save$
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ export class TranslateDatePipe implements PipeTransform, OnDestroy {

this.updateValue(this.translateService.currentLang ?? this.translateService.defaultLang);

if (!this.onLangChange) {
this.onLangChange = this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {
if (this.lastDate && this.lastFormat) {
this.updateValue(event.lang);
}
});
}
this.onLangChange ??= this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {
if (this.lastDate && this.lastFormat) {
this.updateValue(event.lang);
}
});

return this.currentValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class PortalComponent implements OnInit, OnDestroy {

private readonly destroyed$ = new Subject<void>();

constructor(private readonly authenticationService: AuthenticationService, @Inject(DOCUMENT) private document: Document) {}
constructor(private readonly authenticationService: AuthenticationService, @Inject(DOCUMENT) private readonly document: Document) {}

public ngOnInit(): void {
this.authenticationService.authentication$.pipe(takeUntil(this.destroyed$)).subscribe((user) => {
Expand Down
Loading
Loading