This commit is contained in:
Lurkars
2020-11-02 08:29:52 +01:00
commit b7b4e2d032
126 changed files with 18263 additions and 0 deletions
@@ -0,0 +1,32 @@
<mat-card>
<mat-card-content>
<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>
</mat-card-actions>
</mat-card>
<div *ngIf="vouchers && vouchers[0]">
<h3>{{'vouchers.temp' | i18n}}</h3>
<p>{{'vouchers.temp.info' | i18n}}</p>
<table mat-table [dataSource]="voucherSource">
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> {{'voucher.type' | i18n}} </th>
<td mat-cell *matCellDef="let voucher">{{voucher.type}}</td>
</ng-container>
<ng-container matColumnDef="code">
<th mat-header-cell *matHeaderCellDef> {{'voucher.code' | i18n}} </th>
<td mat-cell *matCellDef="let voucher">{{voucher.code}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="voucherColumns"></tr>
<tr mat-row *matRowDef="let myRowData; columns: voucherColumns"></tr>
</table>
</div>
@@ -0,0 +1,3 @@
table {
width: 100%;
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { VoucherComponent } from './voucher.component';
describe('VoucherComponent', () => {
let component: VoucherComponent;
let fixture: ComponentFixture<VoucherComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ VoucherComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(VoucherComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,81 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatTableDataSource } from '@angular/material/table';
import { VoucherService } from './../../../services/voucher.service';
import { QuotaService } from './../../../services/quota.service';
@Component({
selector: 'app-account-voucher',
templateUrl: './voucher.component.html',
styleUrls: ['./voucher.component.scss']
})
export class VoucherComponent implements OnInit {
public hasRegistration: boolean = false;
model: any = {};
vouchers = [];
voucherSource = new MatTableDataSource<any>();
voucherColumns = ['type', 'code'];
constructor(private voucherService: VoucherService, private quotaService: QuotaService, public dialog: MatDialog) { }
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;
})
})
}
registration() {
this.voucherService.registration().toPromise().then(data => {
this.model.type = "registration";
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 => {
})
}
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 => {
console.log(error);
})
}
}
@Component({
selector: 'app-voucher-dialog',
templateUrl: 'voucher.dialog.html',
styleUrls: ['./voucher.dialog.scss']
})
export class VoucherDialog {
constructor(public dialogRef: MatDialogRef<VoucherDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
onOkClick(): void {
this.dialogRef.close();
}
}
@@ -0,0 +1,12 @@
<h1 mat-dialog-title>{{'voucher' | i18n}}</h1>
<div mat-dialog-content>
<p>{{'vouchers.stored-safely' | i18n}}</p>
<span>{{'vouchers.' + data.type | i18n}}: {{data.code}}</span>
</div>
<div mat-dialog-actions>
<mat-slide-toggle [(ngModel)]="data.confirmClose">
{{'vouchers.stored-safely.confirm' | i18n}}
</mat-slide-toggle>
<button mat-button (click)="onOkClick()" [disabled]="!data.confirmClose">{{'ok' | i18n}}</button>
</div>
@@ -0,0 +1,3 @@
mat-form-field {
display: block;
}