new voucher system
This commit is contained in:
parent
d1c598a8e1
commit
3a29e2db87
@ -3,11 +3,8 @@
|
|||||||
<p>{{'vouchers.info' | i18n}}</p>
|
<p>{{'vouchers.info' | i18n}}</p>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
<mat-card-actions>
|
<mat-card-actions>
|
||||||
<button mat-raised-button color="primary" (click)="registration()" [disabled]="!hasRegistration">
|
<button *ngFor="let name of available" mat-raised-button (click)="create(name)" matTooltip="{{'vouchers.' + name + '.text' | i18n}}">
|
||||||
{{'vouchers.registration' | i18n}}
|
{{'vouchers.' + name | i18n}}
|
||||||
</button>
|
|
||||||
<button mat-raised-button color="accent" (click)="addon()">
|
|
||||||
{{'vouchers.add-on' | i18n}}
|
|
||||||
</button>
|
</button>
|
||||||
</mat-card-actions>
|
</mat-card-actions>
|
||||||
<mat-card-footer>
|
<mat-card-footer>
|
||||||
|
@ -8,30 +8,29 @@ import { QuotaService } from './../../../services/quota.service';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-account-voucher',
|
selector: 'app-account-voucher',
|
||||||
templateUrl: './voucher.component.html',
|
templateUrl: './voucher.component.html',
|
||||||
styleUrls: ['./voucher.component.scss']
|
styleUrls: [ './voucher.component.scss' ]
|
||||||
})
|
})
|
||||||
export class VoucherComponent implements OnInit {
|
export class VoucherComponent implements OnInit {
|
||||||
|
|
||||||
public hasRegistration: boolean = false;
|
public hasRegistration: boolean = false;
|
||||||
model: any = {};
|
model: any = {};
|
||||||
|
available = [];
|
||||||
vouchers = [];
|
vouchers = [];
|
||||||
voucherSource = new MatTableDataSource<any>();
|
voucherSource = new MatTableDataSource<any>();
|
||||||
voucherColumns = ['type', 'code'];
|
voucherColumns = [ 'type', 'code' ];
|
||||||
|
|
||||||
constructor(private voucherService: VoucherService, private quotaService: QuotaService, public dialog: MatDialog) { }
|
constructor(private voucherService: VoucherService, private quotaService: QuotaService, public dialog: MatDialog) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.voucherSource.data = this.vouchers;
|
this.voucherSource.data = this.vouchers;
|
||||||
this.quotaService.quotas().subscribe((data: any) => {
|
this.voucherService.get().subscribe((data: any) => {
|
||||||
this.hasRegistration = data && data.some(function (quota) {
|
this.available = data;
|
||||||
return quota.name == "registration_vouchers" && quota.value > 0;
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
registration() {
|
create(name: string) {
|
||||||
this.voucherService.registration().toPromise().then(data => {
|
this.voucherService.create(name).toPromise().then(data => {
|
||||||
this.model.type = "registration";
|
this.model.type = name;
|
||||||
this.model.code = data;
|
this.model.code = data;
|
||||||
this.vouchers.push(this.model);
|
this.vouchers.push(this.model);
|
||||||
this.voucherSource.data = this.vouchers;
|
this.voucherSource.data = this.vouchers;
|
||||||
@ -45,28 +44,13 @@ 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 => {
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-voucher-dialog',
|
selector: 'app-voucher-dialog',
|
||||||
templateUrl: 'voucher.dialog.html',
|
templateUrl: 'voucher.dialog.html',
|
||||||
styleUrls: ['./voucher.dialog.scss']
|
styleUrls: [ './voucher.dialog.scss' ]
|
||||||
})
|
})
|
||||||
export class VoucherDialog {
|
export class VoucherDialog {
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ export class VoucherService {
|
|||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
registration() {
|
get() {
|
||||||
return this.http.post(environment.apiUrl + "/vouchers/registration", {});
|
return this.http.get(environment.apiUrl + "/vouchers");
|
||||||
}
|
}
|
||||||
|
|
||||||
addon() {
|
create(name: string) {
|
||||||
return this.http.post(environment.apiUrl + "/vouchers/addon", {});
|
return this.http.post(environment.apiUrl + "/vouchers/" + name, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user