new voucher system

This commit is contained in:
_Bastler 2021-10-06 15:24:57 +02:00
parent d1c598a8e1
commit 3a29e2db87
3 changed files with 15 additions and 34 deletions

View File

@ -3,11 +3,8 @@
<p>{{'vouchers.info' | i18n}}</p>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click)="registration()" [disabled]="!hasRegistration">
{{'vouchers.registration' | i18n}}
</button>
<button mat-raised-button color="accent" (click)="addon()">
{{'vouchers.add-on' | i18n}}
<button *ngFor="let name of available" mat-raised-button (click)="create(name)" matTooltip="{{'vouchers.' + name + '.text' | i18n}}">
{{'vouchers.' + name | i18n}}
</button>
</mat-card-actions>
<mat-card-footer>

View File

@ -14,6 +14,7 @@ export class VoucherComponent implements OnInit {
public hasRegistration: boolean = false;
model: any = {};
available = [];
vouchers = [];
voucherSource = new MatTableDataSource<any>();
voucherColumns = [ 'type', 'code' ];
@ -22,16 +23,14 @@ export class VoucherComponent implements OnInit {
ngOnInit(): void {
this.voucherSource.data = this.vouchers;
this.quotaService.quotas().subscribe((data: any) => {
this.hasRegistration = data && data.some(function (quota) {
return quota.name == "registration_vouchers" && quota.value > 0;
})
this.voucherService.get().subscribe((data: any) => {
this.available = data;
})
}
registration() {
this.voucherService.registration().toPromise().then(data => {
this.model.type = "registration";
create(name: string) {
this.voucherService.create(name).toPromise().then(data => {
this.model.type = name;
this.model.code = data;
this.vouchers.push(this.model);
this.voucherSource.data = this.vouchers;
@ -45,21 +44,6 @@ export class VoucherComponent implements OnInit {
})
}
addon() {
this.voucherService.addon().subscribe((data: any) => {
this.model.type = "add-on";
this.model.code = data;
this.vouchers.push(this.model);
this.voucherSource.data = this.vouchers;
const dialogRef = this.dialog.open(VoucherDialog, {
closeOnNavigation: false,
disableClose: true,
data: this.model
});
}, error => {
})
}
}

View File

@ -11,11 +11,11 @@ export class VoucherService {
constructor(private http: HttpClient) {
}
registration() {
return this.http.post(environment.apiUrl + "/vouchers/registration", {});
get() {
return this.http.get(environment.apiUrl + "/vouchers");
}
addon() {
return this.http.post(environment.apiUrl + "/vouchers/addon", {});
create(name: string) {
return this.http.post(environment.apiUrl + "/vouchers/" + name, {});
}
}