update borrow + fix invite

This commit is contained in:
_Bastler
2021-10-27 17:07:44 +02:00
parent 59ac345933
commit 925a03fd46
45 changed files with 2792 additions and 398 deletions
+44 -32
View File
@@ -1,19 +1,21 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {PageEvent} from '@angular/material/paginator';
import { ActivatedRoute, Router } from '@angular/router';
import { PageEvent } from '@angular/material/paginator';
import {AuthService} from '../../services/auth.service';
import {I18nService} from '../../services/i18n.service';
import {QuotaService} from '../../services/quota.service';
import {InviteService} from '../../services/invites.service';
import {FormControl} from '@angular/forms';
import {debounceTime} from 'rxjs/operators';
import { AuthService } from '../../services/auth.service';
import { I18nService } from '../../services/i18n.service';
import { QuotaService } from '../../services/quota.service';
import { InviteService } from '../../services/invites.service';
import { FormControl } from '@angular/forms';
import { debounceTime } from 'rxjs/operators';
import { InviteEditComponent } from './edit/invite.edit';
import { MatDialog } from '@angular/material/dialog';
@Component({
selector: 'app-invites',
templateUrl: './invites.component.html',
styleUrls: ['./invites.component.scss']
styleUrls: [ './invites.component.scss' ]
})
export class InvitesComponent implements OnInit {
@@ -24,21 +26,20 @@ export class InvitesComponent implements OnInit {
success: boolean;
working: boolean;
datetimeformat: string;
pageSizeOptions: number[] = [5, 10, 25, 50];
pageSizeOptions: number[] = [ 5, 10, 25, 50 ];
searchFormControl = new FormControl();
redeemedFormControl = new FormControl();
searchOthersFormControl = new FormControl();
redeemedOthersFormControl = new FormControl();
inviteColumns = ["starts", "expires", "link", "note", "message", "redeemed"];
otherColumns = ["note", "redeemed"];
inviteColumns = [ "starts", "expires", "link", "note", "message", "redeemed", "actions" ];
otherColumns = [ "note", "redeemed" ];
constructor(
private authService: AuthService,
private inviteService: InviteService,
private i18n: I18nService,
private quotaService: QuotaService,
private router: Router,
public dialog: MatDialog,
private route: ActivatedRoute) {
}
@@ -49,23 +50,23 @@ export class InvitesComponent implements OnInit {
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => {
this.inviteService.getPages(this.quota, 0, this.invites.size, value, this.redeemedFormControl.value).subscribe((data: any) => {
this.invites = data;
}, (error) => {})
}, (error) => { })
})
this.redeemedFormControl.valueChanges.subscribe(value => {
this.inviteService.getPages(this.quota, 0, this.invites.size, this.searchFormControl.value ? this.searchFormControl.value : "", value).subscribe((data: any) => {
this.invites = data;
}, (error) => {})
}, (error) => { })
})
this.searchOthersFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => {
this.inviteService.getOthersPages(this.quota, 0, this.others.size, value, this.redeemedOthersFormControl.value).subscribe((data: any) => {
this.others = data;
}, (error) => {})
}, (error) => { })
})
this.redeemedOthersFormControl.valueChanges.subscribe(value => {
this.inviteService.getOthersPages(this.quota, 0, this.others.size, this.searchOthersFormControl.value ? this.searchOthersFormControl.value : "", value).subscribe((data: any) => {
this.others = data;
}, (error) => {})
}, (error) => { })
})
this.update();
@@ -75,56 +76,67 @@ export class InvitesComponent implements OnInit {
update(): void {
this.inviteQuota = 0;
this.quotaService.quotas().subscribe((data: any) => {
for(let quota of data) {
if(quota.name == "invite_" + this.quota) {
for (let quota of data) {
if (quota.name == "invite_" + this.quota) {
this.inviteQuota = quota.value;
}
}
})
if(!this.invites) {
if (!this.invites) {
this.inviteService.get(this.quota).subscribe((data: any) => {
this.invites = data;
})
} else {
this.inviteService.getPages(this.quota, this.invites.number || 0, this.invites.size || 10, this.searchFormControl.value ? this.searchFormControl.value : "", this.redeemedFormControl.value).subscribe((data: any) => {
this.invites = data;
}, (error) => {})
}, (error) => { })
}
this.inviteService.getOthers(this.quota).subscribe((data: any) => {
this.others = data;
}, (error) => {})
}, (error) => { })
}
updatePages(event: PageEvent) {
this.inviteService.getPages(this.quota, event.pageIndex, event.pageSize, this.searchFormControl.value ? this.searchFormControl.value : "", this.redeemedFormControl.value).subscribe((data: any) => {
this.invites = data;
}, (error) => {})
}, (error) => { })
}
create(): void {
this.working = true;
this.inviteService.create(this.quota, {}).subscribe(response => {
this.update();
this.working = false;
}, (error) => {
this.working = false;
if(error.status == 409) {
if (error.status == 409) {
let errors = {};
for(let code of error.error) {
errors[code.field] = errors[code.field] || {};
errors[code.field][code.code] = true;
for (let code of error.error) {
errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
}
})
}
edit(invite) {
const dialogRef = this.dialog.open(InviteEditComponent, {
data: invite,
minWidth: "400px"
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.update();
}
});
}
updateOthers(event: PageEvent) {
this.inviteService.getOthersPages(this.quota, event.pageIndex, event.pageSize, this.searchOthersFormControl.value ? this.searchOthersFormControl.value : "", this.redeemedOthersFormControl.value).subscribe((data: any) => {
this.others = data;
}, (error) => {})
}, (error) => { })
}
}