migration

This commit is contained in:
_Bastler 2022-01-21 22:38:31 +01:00
parent 5cf6230005
commit 578e6e6981
36 changed files with 1473 additions and 1012 deletions

View File

@ -47,28 +47,30 @@ export class AuthenticatedGuard implements CanActivate {
return that.router.navigateByUrl(that.router.parseUrl('/login?target=' + encodeURIComponent(state.url)), { skipLocationChange: true, replaceUrl: true }); return that.router.navigateByUrl(that.router.parseUrl('/login?target=' + encodeURIComponent(state.url)), { skipLocationChange: true, replaceUrl: true });
} }
this.profileService.get([ "locale", "darkTheme" ]).subscribe((profileFields: any) => { this.profileService.get([ "locale", "darkTheme" ]).subscribe({
let updateLocale = false; next: (profileFields: any) => {
let darktheme = 'false'; let updateLocale = false;
let updateTheme = false; let darktheme = 'false';
for (let profileField of profileFields) { let updateTheme = false;
if (profileField.name == "darkTheme") { for (let profileField of profileFields) {
darktheme = profileField.value; if (profileField.name == "darkTheme") {
} else if (profileField.name == "locale" && this.i18nService.locales.indexOf(profileField.value) != -1 && localStorage.getItem("bstly.locale") != profileField.value) { darktheme = profileField.value;
if (this.i18nService.locale != profileField.value) { } else if (profileField.name == "locale" && this.i18nService.locales.indexOf(profileField.value) != -1 && localStorage.getItem("bstly.locale") != profileField.value) {
localStorage.setItem("bstly.locale", profileField.value); if (this.i18nService.locale != profileField.value) {
updateLocale = true; localStorage.setItem("bstly.locale", profileField.value);
updateLocale = true;
}
} }
} }
}
if (darktheme != localStorage.getItem("bstly.darkTheme")) { if (darktheme != localStorage.getItem("bstly.darkTheme")) {
localStorage.setItem("bstly.darkTheme", darktheme); localStorage.setItem("bstly.darkTheme", darktheme);
updateTheme = true; updateTheme = true;
} }
if (updateLocale || updateTheme) { if (updateLocale || updateTheme) {
window.location.reload(); window.location.reload();
}
} }
}) })

View File

@ -1,11 +1,11 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {AuthService} from './../../services/auth.service'; import { AuthService } from './../../services/auth.service';
@Component({ @Component({
selector: 'app-account', selector: 'app-account',
templateUrl: './account.component.html', templateUrl: './account.component.html',
styleUrls: ['./account.component.scss'] styleUrls: [ './account.component.scss' ]
}) })
export class AccountComponent implements OnInit { export class AccountComponent implements OnInit {
@ -13,8 +13,10 @@ export class AccountComponent implements OnInit {
auth; auth;
constructor(private authService: AuthService) { constructor(private authService: AuthService) {
this.authService.auth.subscribe(data => { this.authService.auth.subscribe({
this.auth = data; next: (data) => {
this.auth = data;
}
}) })
} }

View File

@ -1,16 +1,16 @@
import {Component, OnInit, ViewChild} from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import {QuotaService} from '../../../services/quota.service'; import { QuotaService } from '../../../services/quota.service';
import {I18nService} from '../../../services/i18n.service'; import { I18nService } from '../../../services/i18n.service';
import {Sort} from '@angular/material/sort'; import { Sort } from '@angular/material/sort';
import {UserAliasService} from '../../../services/useralias.service'; import { UserAliasService } from '../../../services/useralias.service';
import {FormBuilder, FormGroup, Validators, NgForm} from '@angular/forms'; import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms';
import {MatDialog} from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import {ConfirmDialog} from '../../../ui/confirm/confirm.component'; import { ConfirmDialog } from '../../../ui/confirm/confirm.component';
@Component({ @Component({
selector: 'app-account-aliases', selector: 'app-account-aliases',
templateUrl: './aliases.component.html', templateUrl: './aliases.component.html',
styleUrls: ['./aliases.component.scss'] styleUrls: [ './aliases.component.scss' ]
}) })
export class AliasesComponent implements OnInit { export class AliasesComponent implements OnInit {
@ -24,21 +24,21 @@ export class AliasesComponent implements OnInit {
success: boolean; success: boolean;
working: boolean; working: boolean;
aliasesColumns = ["alias", "visibility", "delete"]; aliasesColumns = [ "alias", "visibility", "delete" ];
visibilities = ["PRIVATE", "PROTECTED", "PUBLIC"]; visibilities = [ "PRIVATE", "PROTECTED", "PUBLIC" ];
constructor( constructor(
private quotaService: QuotaService, private quotaService: QuotaService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private userAliasService: UserAliasService, private userAliasService: UserAliasService,
private i18n : I18nService, private i18n: I18nService,
public dialog: MatDialog) {} public dialog: MatDialog) { }
ngOnInit(): void { ngOnInit(): void {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
alias: ['', Validators.required], alias: [ '', Validators.required ],
visibility: ['', Validators.required], visibility: [ '', Validators.required ],
}); });
this.update(); this.update();
@ -46,47 +46,57 @@ export class AliasesComponent implements OnInit {
create(): void { create(): void {
this.working = true; this.working = true;
this.userAliasService.create(this.alias).subscribe(response => { this.userAliasService.create(this.alias).subscribe(
this.update(); {
this.formDirective.resetForm(); next: (response) => {
this.alias = { this.update();
visibility: "PROTECTED" this.formDirective.resetForm();
}; this.alias = {
this.working = false; visibility: "PROTECTED"
}, (error) => { };
this.working = false; this.working = false;
if(error.status == 409) { },
let errors = {}; error: (error) => {
for(let code of error.error) { this.working = false;
errors[code.field] = errors[code.field] || {}; if (error.status == 409) {
errors[code.field][code.code] = true; let errors = {};
} for (let code of error.error) {
errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for(let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[code]); this.form.get(code).setErrors(errors[ code ]);
}
}
} }
} })
})
} }
updateAlias(alias) { updateAlias(alias) {
this.userAliasService.update(alias).subscribe((response: any) => { this.userAliasService.update(alias).subscribe({
alias = response; next: (response: any) => {
alias = response;
}
}) })
} }
update() { update() {
this.aliasCreation = 0; this.aliasCreation = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe({
for(let quota of data) { next: (data: any) => {
if(quota.name == "alias_creation") { for (let quota of data) {
this.aliasCreation = quota.value; if (quota.name == "alias_creation") {
this.aliasCreation = quota.value;
}
} }
} }
}) })
this.userAliasService.get().subscribe((data: any) => { this.userAliasService.get().subscribe({
this.aliases = data; next: (data: any) => {
this.aliases = data;
}
}) })
} }
@ -94,29 +104,33 @@ export class AliasesComponent implements OnInit {
const dialogRef = this.dialog.open(ConfirmDialog, { const dialogRef = this.dialog.open(ConfirmDialog, {
data: { data: {
'label': 'user.aliases.confirmDelete', 'label': 'user.aliases.confirmDelete',
'args': [alias.alias] 'args': [ alias.alias ]
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if(result) { next: (result) => {
this.userAliasService.delete(alias.id).subscribe((result: any) => { if (result) {
this.update(); this.userAliasService.delete(alias.id).subscribe({
}) next: (result: any) => {
this.update();
}
})
}
} }
}); });
} }
sortData(sort: Sort) { sortData(sort: Sort) {
const data = this.aliases.slice(); const data = this.aliases.slice();
if(!sort.active || sort.direction === '') { if (!sort.active || sort.direction === '') {
this.aliases = data; this.aliases = data;
return; return;
} }
this.aliases = data.sort((a, b) => { this.aliases = data.sort((a, b) => {
const isAsc = sort.direction === 'asc'; const isAsc = sort.direction === 'asc';
switch(sort.active) { switch (sort.active) {
case 'alias': return this.compare(a.alias, b.alias, isAsc); case 'alias': return this.compare(a.alias, b.alias, isAsc);
case 'visibility': return this.compare(this.i18n.get('visibility.' + a.visibility, []), this.i18n.get('visibility.' + b.visibility, []), isAsc); case 'visibility': return this.compare(this.i18n.get('visibility.' + a.visibility, []), this.i18n.get('visibility.' + b.visibility, []), isAsc);
default: return 0; default: return 0;
@ -124,9 +138,9 @@ export class AliasesComponent implements OnInit {
}); });
} }
compare(a: number | string , b: number | string , isAsc: boolean) { compare(a: number | string, b: number | string, isAsc: boolean) {
if (typeof a === 'string' && typeof b === 'string') { if (typeof a === 'string' && typeof b === 'string') {
return a.localeCompare(b,undefined, { sensitivity: 'accent' } ) * (isAsc ? 1 : -1); return a.localeCompare(b, undefined, { sensitivity: 'accent' }) * (isAsc ? 1 : -1);
} }
return (a < b ? -1 : 1) * (isAsc ? 1 : -1); return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
} }

View File

@ -46,38 +46,45 @@ export class DomainsComponent implements OnInit {
create(): void { create(): void {
this.working = true; this.working = true;
this.userDomainService.create(this.domain).subscribe(response => { this.userDomainService.create(this.domain).subscribe({
this.update(); next: (response) => {
this.formDirective.resetForm(); this.update();
this.domain = { this.formDirective.resetForm();
visibility: "PRIVATE" this.domain = {
}; visibility: "PRIVATE"
this.working = false; };
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
} }
updateDomain(domain) { updateDomain(domain) {
this.userDomainService.update(domain).subscribe((response: any) => { this.userDomainService.update(domain).subscribe({
domain = response; next: (response: any) => {
domain = response;
}
}) })
} }
update() { update() {
this.userDomainService.get().subscribe((data: any) => { this.userDomainService.get().subscribe({
this.domains = data; next: (data: any) => {
this.domains = data;
}
}) })
} }
@ -89,11 +96,15 @@ export class DomainsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.userDomainService.delete(domain.id).subscribe((result: any) => { if (result) {
this.update(); this.userDomainService.delete(domain.id).subscribe({
}) next: (result: any) => {
this.update();
}
})
}
} }
}); });
} }

View File

@ -1,26 +1,30 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {PermissionService} from './../../../services/permission.service'; import { PermissionService } from './../../../services/permission.service';
import {QuotaService} from './../../../services/quota.service'; import { QuotaService } from './../../../services/quota.service';
@Component({ @Component({
selector: 'app-account-info', selector: 'app-account-info',
templateUrl: './info.component.html', templateUrl: './info.component.html',
styleUrls: ['./info.component.scss'] styleUrls: [ './info.component.scss' ]
}) })
export class InfoComponent implements OnInit { export class InfoComponent implements OnInit {
permissions = []; permissions = [];
quotas = []; quotas = [];
constructor(private permissionService: PermissionService, private quotaService: QuotaService) {} constructor(private permissionService: PermissionService, private quotaService: QuotaService) { }
ngOnInit(): void { ngOnInit(): void {
this.permissionService.permissions().subscribe((data: any) => { this.permissionService.permissions().subscribe({
this.permissions = data; next: (data: any) => {
this.permissions = data;
}
}) })
this.quotaService.quotasAll().subscribe((data: any) => { this.quotaService.quotasAll().subscribe({
this.quotas = data; next: (data: any) => {
this.quotas = data;
}
}) })
} }

View File

@ -1,15 +1,15 @@
import {Component, OnInit, ViewChild, Inject} from '@angular/core'; import { Component, OnInit, ViewChild, Inject } from '@angular/core';
import {FormBuilder, FormGroup, FormControl, Validators, NgForm} from '@angular/forms'; import { FormBuilder, FormGroup, FormControl, Validators, NgForm } from '@angular/forms';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import {Auth2FAService} from './../../../services/auth.2fa.service'; import { Auth2FAService } from './../../../services/auth.2fa.service';
import {UserService} from './../../../services/user.service'; import { UserService } from './../../../services/user.service';
import {MatchingValidator} from './../../../utils/matching.validator'; import { MatchingValidator } from './../../../utils/matching.validator';
@Component({ @Component({
selector: 'app-account-security', selector: 'app-account-security',
templateUrl: './security.component.html', templateUrl: './security.component.html',
styleUrls: ['./security.component.scss'] styleUrls: [ './security.component.scss' ]
}) })
export class SecurityComponent implements OnInit { export class SecurityComponent implements OnInit {
@ -20,7 +20,7 @@ export class SecurityComponent implements OnInit {
public successStatus: boolean; public successStatus: boolean;
public totp: boolean = false; public totp: boolean = false;
statuses = ["NORMAL", "SLEEP", "PURGE"]; statuses = [ "NORMAL", "SLEEP", "PURGE" ];
passwordForm: FormGroup; passwordForm: FormGroup;
statusForm: FormGroup; statusForm: FormGroup;
@ -30,54 +30,60 @@ export class SecurityComponent implements OnInit {
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private userService: UserService, private userService: UserService,
private auth2FAService: Auth2FAService, private auth2FAService: Auth2FAService,
public dialog: MatDialog) {} public dialog: MatDialog) { }
ngOnInit(): void { ngOnInit(): void {
this.passwordForm = this.formBuilder.group({ this.passwordForm = this.formBuilder.group({
oldPassword: ['', Validators.required], oldPassword: [ '', Validators.required ],
password: ['', Validators.required], password: [ '', Validators.required ],
password2: ['', Validators.required] password2: [ '', Validators.required ]
}, { }, {
validator: MatchingValidator('password', 'password2') validator: MatchingValidator('password', 'password2')
}); });
this.statusForm = this.formBuilder.group({ this.statusForm = this.formBuilder.group({
status: ['', Validators.required] status: [ '', Validators.required ]
}); });
this.userService.get().subscribe((response: any) => { this.userService.get().subscribe({
this.model.status = response.status; next: (response: any) => {
}, error => { this.model.status = response.status;
}, error: (error) => { }
}) })
this.auth2FAService.isEnabled('totp').subscribe(response => { this.auth2FAService.isEnabled('totp').subscribe({
this.totp = true; next: (response) => {
}, error => { this.totp = true;
this.totp = false; },
error: (error) => {
this.totp = false;
}
}) })
} }
changePassword() { changePassword() {
if(this.passwordForm.valid && !this.working) { if (this.passwordForm.valid && !this.working) {
this.working = true; this.working = true;
this.userService.password(this.model).subscribe((result: any) => { this.userService.password(this.model).subscribe({
this.passwordFormDirective.resetForm(); next: (result: any) => {
this.success = true; this.passwordFormDirective.resetForm();
this.working = false; this.success = true;
}, (error) => { this.working = false;
this.working = false; },
if(error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for(let code of error.error) { if (error.status == 409) {
errors[code.field] = errors[code.field] || {}; let errors = {};
errors[code.field][code.code] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for(let code in errors) { for (let code in errors) {
this.passwordForm.get(code).setErrors(errors[code]); this.passwordForm.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
@ -86,37 +92,48 @@ export class SecurityComponent implements OnInit {
changeStatus() { changeStatus() {
if(this.statusForm.valid && !this.working) { if (this.statusForm.valid && !this.working) {
this.working = true; this.working = true;
this.userService.update({status : this.model.status}).subscribe((result: any) => { this.userService.update({ status: this.model.status }).subscribe({
this.successStatus = true; next: (result: any) => {
this.working = false; this.successStatus = true;
}, (error) => { this.working = false;
this.working = false; },
error: (error) => {
this.working = false;
}
}) })
} }
} }
createTotp() { createTotp() {
this.auth2FAService.create('totp').subscribe((result: any) => { this.auth2FAService.create('totp').subscribe({
const dialogRef = this.dialog.open(SecurityTotpDialog, { next: (result: any) => {
closeOnNavigation: false, const dialogRef = this.dialog.open(SecurityTotpDialog, {
disableClose: true, closeOnNavigation: false,
data: result disableClose: true,
}); data: result
});
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if(result) { next: (result) => {
this.auth2FAService.enable('totp', result).subscribe((result: any) => { if (result) {
this.totp = true; this.auth2FAService.enable('totp', result).subscribe({
}) next: (result: any) => {
} else { this.totp = true;
this.auth2FAService.remove('totp').subscribe((result: any) => { }
this.totp = false; })
}) } else {
} this.auth2FAService.remove('totp').subscribe({
}); next: (result: any) => {
this.totp = false;
}
})
}
}
});
}
}) })
} }
@ -130,8 +147,10 @@ export class SecurityComponent implements OnInit {
} }
removeTotp() { removeTotp() {
this.auth2FAService.remove('totp').subscribe((result: any) => { this.auth2FAService.remove('totp').subscribe({
this.totp = false; next: (result: any) => {
this.totp = false;
}
}) })
} }
@ -141,7 +160,7 @@ export class SecurityComponent implements OnInit {
@Component({ @Component({
selector: 'app-security-totp-dialog', selector: 'app-security-totp-dialog',
templateUrl: 'security-totp.dialog.html', templateUrl: 'security-totp.dialog.html',
styleUrls: ['./security.component.scss'] styleUrls: [ './security.component.scss' ]
}) })
export class SecurityTotpDialog { export class SecurityTotpDialog {
@ -150,9 +169,9 @@ export class SecurityTotpDialog {
constructor( constructor(
public dialogRef: MatDialogRef<SecurityTotpDialog>, public dialogRef: MatDialogRef<SecurityTotpDialog>,
@Inject(MAT_DIALOG_DATA) public data: any @Inject(MAT_DIALOG_DATA) public data: any
) {} ) { }
ngOnInit(): void { ngOnInit(): void {
this.code = new FormControl('', [Validators.required, Validators.pattern("[0-9]{6}")]); this.code = new FormControl('', [ Validators.required, Validators.pattern("[0-9]{6}") ]);
} }
} }

View File

@ -23,8 +23,10 @@ export class VoucherComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.voucherSource.data = this.vouchers; this.voucherSource.data = this.vouchers;
this.voucherService.get().subscribe((data: any) => { this.voucherService.get().subscribe({
this.available = data; next: (data: any) => {
this.available = data;
}
}) })
} }

View File

@ -33,39 +33,55 @@ export class BorrowItemsComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.authService.auth.subscribe((auth: any) => { this.authService.auth.subscribe({
if (auth.principal && auth.principal.userId) { next: (auth: any) => {
this.userId = auth.principal.userId; if (auth.principal && auth.principal.userId) {
this.userId = auth.principal.userId;
}
} }
}); });
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => { this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe({
this.borrowItemsService.getItems(0, this.page.size, this.page.sort, this.page.desc, value, this.ownerFormControl.value).subscribe((data: any) => { next: (value) => {
this.borrowItems = data; this.borrowItemsService.getItems(0, this.page.size, this.page.sort, this.page.desc, value, this.ownerFormControl.value).subscribe(
}, (error) => { }) {
next: (data: any) => {
this.borrowItems = data;
}, error: (error) => { }
})
}
}) })
this.ownerFormControl.valueChanges.subscribe(value => { this.ownerFormControl.valueChanges.subscribe({
this.borrowItemsService.getItems(0, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, value).subscribe((data: any) => { next: (value) => {
this.borrowItems = data; this.borrowItemsService.getItems(0, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, value).subscribe({
}, (error) => { }) next: (data: any) => {
this.borrowItems = data;
}, error: (error) => { }
})
}
}) })
this.refresh(); this.refresh();
} }
refresh(): void { refresh(): void {
this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe((data: any) => { this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe({
this.borrowItems = data; next: (data: any) => {
this.borrowItems = data;
}
}) })
} }
updatePages(event: PageEvent) { updatePages(event: PageEvent) {
this.page.page = event.pageIndex; this.page.page = event.pageIndex;
this.page.size = event.pageSize; this.page.size = event.pageSize;
this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe((data: any) => { this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe({
this.borrowItems = data; next: (data: any) => {
}, (error) => { }) this.borrowItems = data;
},
error: (error) => { }
})
} }
updateSort(sort: Sort) { updateSort(sort: Sort) {
@ -76,9 +92,13 @@ export class BorrowItemsComponent implements OnInit {
this.page.sort = sort.active; this.page.sort = sort.active;
this.page.desc = sort.direction == "desc"; this.page.desc = sort.direction == "desc";
} }
this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe((data: any) => { this.borrowItemsService.getItems(this.page.page, this.page.size, this.page.sort, this.page.desc, this.searchFormControl.value, this.ownerFormControl.value).subscribe({
this.borrowItems = data; next: (data: any) => {
}, (error) => { }) this.borrowItems = data;
},
error: (error) => { }
})
} }
edit(borrowItem) { edit(borrowItem) {
@ -87,9 +107,11 @@ export class BorrowItemsComponent implements OnInit {
minWidth: '80%' minWidth: '80%'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -100,9 +122,11 @@ export class BorrowItemsComponent implements OnInit {
minWidth: '80%' minWidth: '80%'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: result => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -115,9 +139,11 @@ export class BorrowItemsComponent implements OnInit {
} }
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -130,11 +156,15 @@ export class BorrowItemsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.borrowItemsService.deleteItem(borrowItem.id).subscribe((result: any) => { if (result) {
this.refresh(); this.borrowItemsService.deleteItem(borrowItem.id).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }
@ -172,12 +202,14 @@ export class BorrowItemEditComponent {
slots: this.formBuilder.array([]) slots: this.formBuilder.array([])
}, { validators: [ durationValidator ] }) }, { validators: [ durationValidator ] })
this.form.get('availability').valueChanges.subscribe((value) => { this.form.get('availability').valueChanges.subscribe({
this.slots.clear(); next: (value) => {
if (value == 'MANUAL') { this.slots.clear();
this.addManualSlot('', '', ''); if (value == 'MANUAL') {
} else if (value == 'PERIOD') { this.addManualSlot('', '', '');
this.addPeriodSlot('', '', '', '', ''); } else if (value == 'PERIOD') {
this.addPeriodSlot('', '', '', '', '');
}
} }
}) })
@ -285,18 +317,21 @@ export class BorrowItemEditComponent {
save() { save() {
this.borrowItemsService.createOrUpdateItem(this.formToBorrowItem()).subscribe((data: any) => { this.borrowItemsService.createOrUpdateItem(this.formToBorrowItem()).subscribe({
this.dialogRef.close(data); next: (data: any) => {
}, (error) => { this.dialogRef.close(data);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });
@ -312,11 +347,15 @@ export class BorrowItemEditComponent {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.borrowItemsService.deleteItem(borrowItem.id).subscribe((result: any) => { if (result) {
this.dialogRef.close(true); this.borrowItemsService.deleteItem(borrowItem.id).subscribe({
}) next: (result: any) => {
this.dialogRef.close(true);
}
})
}
} }
}); });
} }

View File

@ -38,8 +38,10 @@ export class BorrowProvingComponent implements AfterViewInit {
if (this.cameras.length) { if (this.cameras.length) {
this.noCamera = false; this.noCamera = false;
this.camera.setValue(this.cameras[ 0 ].id, { emitEvent: false }); this.camera.setValue(this.cameras[ 0 ].id, { emitEvent: false });
this.camera.valueChanges.subscribe((value) => { this.camera.valueChanges.subscribe({
this.qrScanner.setCamera(value); next: (value) => {
this.qrScanner.setCamera(value);
}
}) })
} }
}) })
@ -47,11 +49,13 @@ export class BorrowProvingComponent implements AfterViewInit {
this.qrScanner.hasFlash().then(hasFlash => { this.qrScanner.hasFlash().then(hasFlash => {
if (hasFlash) { if (hasFlash) {
this.toggleFlash.enable(); this.toggleFlash.enable();
this.toggleFlash.valueChanges.subscribe(value => { this.toggleFlash.valueChanges.subscribe({
if (value) { next: (value) => {
this.qrScanner.turnFlashOn(); if (value) {
} else { this.qrScanner.turnFlashOn();
this.qrScanner.turnFlashOff(); } else {
this.qrScanner.turnFlashOff();
}
} }
}); });
} else { } else {
@ -64,10 +68,13 @@ export class BorrowProvingComponent implements AfterViewInit {
onResult(result: string) { onResult(result: string) {
this.qrScanner.pause(); this.qrScanner.pause();
this.borrowRequestService.verifyRequest(result).subscribe((response) => { this.borrowRequestService.verifyRequest(result).subscribe({
this.openResultDialog(response, true); next: (response) => {
}, (error) => { this.openResultDialog(response, true);
this.openResultDialog(error, false); },
error: (error) => {
this.openResultDialog(error, false);
}
}); });
} }
@ -80,8 +87,10 @@ export class BorrowProvingComponent implements AfterViewInit {
disableClose: true, disableClose: true,
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
this.qrScanner.start(); next: (result) => {
this.qrScanner.start();
}
}); });
} }
} }

View File

@ -33,34 +33,46 @@ export class BorrowRequestsComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.authService.auth.subscribe((auth: any) => { this.authService.auth.subscribe({
if (auth.principal && auth.principal.userId) { next: (auth: any) => {
this.userId = auth.principal.userId; if (auth.principal && auth.principal.userId) {
this.userId = auth.principal.userId;
}
} }
}); });
this.ownerFormControl.valueChanges.subscribe(value => { this.ownerFormControl.valueChanges.subscribe({
this.borrowRequestsService.getRequests(0, this.page.size, this.page.sort, this.page.desc, value).subscribe((data: any) => { next: (value) => {
this.borrowRequests = data; this.borrowRequestsService.getRequests(0, this.page.size, this.page.sort, this.page.desc, value).subscribe({
}, (error) => { }) next: (data: any) => {
this.borrowRequests = data;
},
error: (error) => { }
})
}
}) })
this.refresh(); this.refresh();
} }
refresh(): void { refresh(): void {
this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe((data: any) => { this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe({
this.borrowRequests = data; next: (data: any) => {
this.borrowRequests = data;
}
}) })
} }
updatePages(event: PageEvent) { updatePages(event: PageEvent) {
this.page.page = event.pageIndex; this.page.page = event.pageIndex;
this.page.size = event.pageSize; this.page.size = event.pageSize;
this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe((data: any) => { this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe({
this.borrowRequests = data; next: (data: any) => {
}, (error) => { }) this.borrowRequests = data;
},
error: (error) => { }
})
} }
updateSort(sort: Sort) { updateSort(sort: Sort) {
@ -71,9 +83,12 @@ export class BorrowRequestsComponent implements OnInit {
this.page.sort = sort.active; this.page.sort = sort.active;
this.page.desc = sort.direction == "desc"; this.page.desc = sort.direction == "desc";
} }
this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe((data: any) => { this.borrowRequestsService.getRequests(this.page.page, this.page.size, this.page.sort, this.page.desc, this.ownerFormControl.value).subscribe({
this.borrowRequests = data; next: (data: any) => {
}, (error) => { }) this.borrowRequests = data;
},
error: (error) => { }
})
} }
edit(borrowRequest) { edit(borrowRequest) {
@ -81,9 +96,11 @@ export class BorrowRequestsComponent implements OnInit {
data: borrowRequest data: borrowRequest
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -96,11 +113,15 @@ export class BorrowRequestsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.borrowRequestsService.deleteRequest(borrowRequest.id).subscribe((result: any) => { if (result) {
this.refresh(); this.borrowRequestsService.deleteRequest(borrowRequest.id).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }
@ -143,18 +164,21 @@ export class BorrowRequestEditComponent {
save() { save() {
this.borrowRequestsService.createOrUpdateRequest(this.formToBorrowRequest()).subscribe((data: any) => { this.borrowRequestsService.createOrUpdateRequest(this.formToBorrowRequest()).subscribe({
this.dialogRef.close(data); next: (data: any) => {
}, (error) => { this.dialogRef.close(data);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });
@ -170,11 +194,15 @@ export class BorrowRequestEditComponent {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.borrowRequestsService.deleteRequest(borrowRequest.id).subscribe((result: any) => { if (result) {
this.dialogRef.close(true); this.borrowRequestsService.deleteRequest(borrowRequest.id).subscribe({
}) next: (result: any) => {
this.dialogRef.close(true);
}
})
}
} }
}); });
} }

View File

@ -1,44 +1,48 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import {environment} from '../../../environments/environment'; import { environment } from '../../../environments/environment';
import {Auth2FAService} from '../../services/auth.2fa.service'; import { Auth2FAService } from '../../services/auth.2fa.service';
@Component({ @Component({
selector: 'app-form-login-2fa', selector: 'app-form-login-2fa',
templateUrl: './form-login-2fa.component.html', templateUrl: './form-login-2fa.component.html',
styleUrls: ['./form-login-2fa.component.scss'] styleUrls: [ './form-login-2fa.component.scss' ]
}) })
export class FormLogin2FAComponent implements OnInit { export class FormLogin2FAComponent implements OnInit {
loginInvalid: boolean; loginInvalid: boolean;
keep: boolean = false; keep: boolean = false;
apiUrl = environment.apiUrl; apiUrl = environment.apiUrl;
selectedProvider = {id: "", request: false}; selectedProvider = { id: "", request: false };
providers = []; providers = [];
constructor( constructor(
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private auth2FAService: Auth2FAService) {} private auth2FAService: Auth2FAService) { }
async ngOnInit() { async ngOnInit() {
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if(params['error'] || params['error'] == '') { next: (params) => {
this.loginInvalid = true; if (params[ 'error' ] || params[ 'error' ] == '') {
this.router.navigate([], {queryParams: {error: null}, queryParamsHandling: 'merge'}); this.loginInvalid = true;
} this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge' });
if(params['keep'] || params['keep'] == '') { }
this.keep = true; if (params[ 'keep' ] || params[ 'keep' ] == '') {
this.router.navigate([], {queryParams: {keep: null}, queryParamsHandling: 'merge'}); this.keep = true;
this.router.navigate([], { queryParams: { keep: null }, queryParamsHandling: 'merge' });
}
} }
}); });
this.auth2FAService.getEnabled().subscribe((providers: any) => { this.auth2FAService.getEnabled().subscribe({
this.providers = providers; next: (providers: any) => {
if(this.providers[0]) { this.providers = providers;
this.selectedProvider = this.providers[0]; if (this.providers[ 0 ]) {
this.selectedProvider = this.providers[ 0 ];
}
} }
}) })

View File

@ -20,14 +20,16 @@ export class FormLoginComponent implements OnInit {
private route: ActivatedRoute) { } private route: ActivatedRoute) { }
async ngOnInit() { async ngOnInit() {
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params[ 'target' ]) { next: (params) => {
this.targetRoute = params[ 'target' ]; if (params[ 'target' ]) {
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', replaceUrl: true }); this.targetRoute = params[ 'target' ];
} this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', replaceUrl: true });
if (params[ 'error' ] || params[ 'error' ] == '') { }
this.loginInvalid = true; if (params[ 'error' ] || params[ 'error' ] == '') {
this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge', replaceUrl: true }); this.loginInvalid = true;
this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge', replaceUrl: true });
}
} }
}); });

View File

@ -35,8 +35,10 @@ export class InviteCodeComponent implements OnInit {
private i18n: I18nService, private i18n: I18nService,
public dialog: MatDialog, public dialog: MatDialog,
private route: ActivatedRoute) { private route: ActivatedRoute) {
this.authService.auth.subscribe(data => { this.authService.auth.subscribe({
this.auth = data; next: (data) => {
this.auth = data;
}
}) })
} }
@ -53,37 +55,44 @@ export class InviteCodeComponent implements OnInit {
}); });
const code = this.route.snapshot.paramMap.get('code'); const code = this.route.snapshot.paramMap.get('code');
this.inviteService.code(code).subscribe((data) => { this.inviteService.code(code).subscribe({
this.invite = data; next: (data) => {
this.invite = data;
if (this.invite.redeemed) { if (this.invite.redeemed) {
this.error = "ALREADY_REDEEMED"; this.error = "ALREADY_REDEEMED";
} }
if (this.invite.owner == this.auth.principal.userId) { if (this.invite.owner == this.auth.principal.userId) {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
message: [ '', Validators.nullValidator ], message: [ '', Validators.nullValidator ],
note: [ '', Validators.nullValidator ], note: [ '', Validators.nullValidator ],
}); });
this.form.get("message").setValue(this.invite.message); this.form.get("message").setValue(this.invite.message);
this.form.get("note").setValue(this.invite.note); this.form.get("note").setValue(this.invite.note);
} }
this.working = false; this.working = false;
}, (error) => { },
this.working = false; error: (error) => {
if (error.status == 406) { this.working = false;
this.error = "INVALID_CODE"; if (error.status == 406) {
this.error = "INVALID_CODE";
}
} }
}) })
this.inviteService.permissions(code).subscribe((data: any) => { this.inviteService.permissions(code).subscribe({
this.permissions = data; next: (data: any) => {
this.permissions = data;
}
}) })
this.inviteService.quotas(code).subscribe((data: any) => { this.inviteService.quotas(code).subscribe({
this.quotas = data; next: (data: any) => {
this.quotas = data;
}
}) })
} }
@ -108,26 +117,29 @@ export class InviteCodeComponent implements OnInit {
model.password = this.form.get("password").value; model.password = this.form.get("password").value;
model.password2 = this.form.get("password2").value; model.password2 = this.form.get("password2").value;
this.inviteService.register(model).subscribe((result: any) => { this.inviteService.register(model).subscribe({
this.working = false; next: (result: any) => {
this.success = true; this.working = false;
}, (error) => { this.success = true;
this.working = false; },
if (error.status == 401) { error: (error) => {
this.error = "NO_CODE"; this.working = false;
} else if (error.status == 406) { if (error.status == 401) {
this.error = "INVALID_CODE"; this.error = "NO_CODE";
} else if (error.status == 410) { } else if (error.status == 406) {
this.error = "ALREADY_REDEEMED"; this.error = "INVALID_CODE";
} else if (error.status == 409) { } else if (error.status == 410) {
let errors = {}; this.error = "ALREADY_REDEEMED";
for (let code of error.error) { } else if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
@ -140,24 +152,27 @@ export class InviteCodeComponent implements OnInit {
this.working = true; this.working = true;
this.invite.message = this.form.get("message").value; this.invite.message = this.form.get("message").value;
this.invite.note = this.form.get("note").value; this.invite.note = this.form.get("note").value;
this.inviteService.update(this.invite).subscribe((result: any) => { this.inviteService.update(this.invite).subscribe({
this.invite = result; next: (result: any) => {
this.working = false; this.invite = result;
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 406) { error: (error) => {
this.error = "INVALID_CODE"; this.working = false;
} if (error.status == 410) { if (error.status == 406) {
this.error = "ALREADY_REDEEMED"; this.error = "INVALID_CODE";
} else if (error.status == 409) { } if (error.status == 410) {
let errors = {}; this.error = "ALREADY_REDEEMED";
for (let code of error.error) { } else if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })

View File

@ -44,24 +44,27 @@ export class InviteEditComponent {
this.invite.message = this.form.get("message").value; this.invite.message = this.form.get("message").value;
this.invite.note = this.form.get("note").value; this.invite.note = this.form.get("note").value;
this.inviteService.update(this.invite).subscribe((result: any) => { this.inviteService.update(this.invite).subscribe({
this.working = false; next: (result: any) => {
this.dialogRef.close(result); this.working = false;
}, (error) => { this.dialogRef.close(result);
this.working = false; },
if (error.status == 406) { error: (error) => {
this.error = "INVALID_CODE"; this.working = false;
} if (error.status == 410) { if (error.status == 406) {
this.error = "ALREADY_REDEEMED"; this.error = "INVALID_CODE";
} else if (error.status == 409) { } if (error.status == 410) {
let errors = {}; this.error = "ALREADY_REDEEMED";
for (let code of error.error) { } else if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })

View File

@ -47,26 +47,46 @@ export class InvitesComponent implements OnInit {
this.datetimeformat = this.i18n.get('format.datetime', []); this.datetimeformat = this.i18n.get('format.datetime', []);
this.quota = this.route.snapshot.paramMap.get('quota'); this.quota = this.route.snapshot.paramMap.get('quota');
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => { this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe({
this.inviteService.getPages(this.quota, 0, this.invites.size, value, this.redeemedFormControl.value).subscribe((data: any) => { next: (value) => {
this.invites = data; this.inviteService.getPages(this.quota, 0, this.invites.size, value, this.redeemedFormControl.value).subscribe({
}, (error) => { }) next: (data: any) => {
this.invites = data;
},
error: (error) => { }
})
}
}) })
this.redeemedFormControl.valueChanges.subscribe(value => { this.redeemedFormControl.valueChanges.subscribe({
this.inviteService.getPages(this.quota, 0, this.invites.size, this.searchFormControl.value ? this.searchFormControl.value : "", value).subscribe((data: any) => { next: (value) => {
this.invites = data; this.inviteService.getPages(this.quota, 0, this.invites.size, this.searchFormControl.value ? this.searchFormControl.value : "", value).subscribe({
}, (error) => { }) next: (data: any) => {
this.invites = data;
},
error: (error) => { }
})
}
}) })
this.searchOthersFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => { this.searchOthersFormControl.valueChanges.pipe(debounceTime(500)).subscribe({
this.inviteService.getOthersPages(this.quota, 0, this.others.size, value, this.redeemedOthersFormControl.value).subscribe((data: any) => { next: (value) => {
this.others = data; this.inviteService.getOthersPages(this.quota, 0, this.others.size, value, this.redeemedOthersFormControl.value).subscribe({
}, (error) => { }) next: (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.redeemedOthersFormControl.valueChanges.subscribe({
this.others = data; next: (value) => {
}, (error) => { }) this.inviteService.getOthersPages(this.quota, 0, this.others.size, this.searchOthersFormControl.value ? this.searchOthersFormControl.value : "", value).subscribe({
next: (data: any) => {
this.others = data;
}, error: (error) => { }
})
}
}) })
this.update(); this.update();
@ -75,47 +95,63 @@ export class InvitesComponent implements OnInit {
update(): void { update(): void {
this.inviteQuota = 0; this.inviteQuota = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe({
for (let quota of data) { next: (data: any) => {
if (quota.name == "invite_" + this.quota) { for (let quota of data) {
this.inviteQuota = quota.value; 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.inviteService.get(this.quota).subscribe({
this.invites = data; next: (data: any) => {
this.invites = data;
}
}) })
} else { } 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.inviteService.getPages(this.quota, this.invites.number || 0, this.invites.size || 10, this.searchFormControl.value ? this.searchFormControl.value : "", this.redeemedFormControl.value).subscribe({
this.invites = data; next: (data: any) => {
}, (error) => { }) this.invites = data;
},
error: (error) => { }
})
} }
this.inviteService.getOthers(this.quota).subscribe((data: any) => { this.inviteService.getOthers(this.quota).subscribe({
this.others = data; next: (data: any) => {
}, (error) => { }) this.others = data;
},
error: (error) => { }
})
} }
updatePages(event: PageEvent) { 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.inviteService.getPages(this.quota, event.pageIndex, event.pageSize, this.searchFormControl.value ? this.searchFormControl.value : "", this.redeemedFormControl.value).subscribe({
this.invites = data; next: (data: any) => {
}, (error) => { }) this.invites = data;
},
error: (error) => { }
})
} }
create(): void { create(): void {
this.working = true; this.working = true;
this.inviteService.create(this.quota, {}).subscribe(response => { this.inviteService.create(this.quota, {}).subscribe({
this.update(); next: (response) => {
this.working = false; this.update();
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
} }
} }
}) })
@ -127,16 +163,21 @@ export class InvitesComponent implements OnInit {
minWidth: "400px" minWidth: "400px"
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.update(); if (result) {
this.update();
}
} }
}); });
} }
updateOthers(event: PageEvent) { 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.inviteService.getOthersPages(this.quota, event.pageIndex, event.pageSize, this.searchOthersFormControl.value ? this.searchOthersFormControl.value : "", this.redeemedOthersFormControl.value).subscribe({
this.others = data; next: (data: any) => {
}, (error) => { }) this.others = data;
},
error: (error) => { }
})
} }
} }

View File

@ -61,22 +61,25 @@ export class JitsiComponent implements OnInit {
this.jitsiRoom.moderationStarts = null; this.jitsiRoom.moderationStarts = null;
} }
this.jitsiService.create(this.jitsiRoom).subscribe(response => { this.jitsiService.create(this.jitsiRoom).subscribe({
this.refresh(); next: (response) => {
this.formDirective.resetForm(); this.refresh();
this.jitsiRoom = {}; this.formDirective.resetForm();
this.working = false; this.jitsiRoom = {};
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
@ -85,27 +88,34 @@ export class JitsiComponent implements OnInit {
refresh() { refresh() {
this.jitsiRoomsQuota = 0; this.jitsiRoomsQuota = 0;
this.shortenedUrlQuota = 0; this.shortenedUrlQuota = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe({
for (let quota of data) { next: (data: any) => {
if (quota.name == "jitsi") { for (let quota of data) {
this.jitsiRoomsQuota = quota.value; if (quota.name == "jitsi") {
} else if (quota.name == "url_shortener") { this.jitsiRoomsQuota = quota.value;
this.shortenedUrlQuota = quota.value; } else if (quota.name == "url_shortener") {
this.shortenedUrlQuota = quota.value;
}
} }
} }
}) })
this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe((data: any) => { this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe({
this.jitsiRooms = data; next: (data: any) => {
this.jitsiRooms = data;
}
}) })
} }
updatePages(event: PageEvent) { updatePages(event: PageEvent) {
this.page.page = event.pageIndex; this.page.page = event.pageIndex;
this.page.size = event.pageSize; this.page.size = event.pageSize;
this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe((data: any) => { this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe({
this.jitsiRooms = data; next: (data: any) => {
}, (error) => { }) this.jitsiRooms = data;
},
error: (error) => { }
})
} }
updateSort(sort: Sort) { updateSort(sort: Sort) {
@ -116,9 +126,12 @@ export class JitsiComponent implements OnInit {
this.page.sort = sort.active; this.page.sort = sort.active;
this.page.desc = sort.direction == "desc"; this.page.desc = sort.direction == "desc";
} }
this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe((data: any) => { this.jitsiService.get(this.page.page, this.page.size, this.page.sort, this.page.desc).subscribe({
this.jitsiRooms = data; next: (data: any) => {
}, (error) => { }) this.jitsiRooms = data;
},
error: (error) => { }
})
} }
confirmDelete(jitsiRoom) { confirmDelete(jitsiRoom) {
@ -129,11 +142,15 @@ export class JitsiComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.jitsiService.delete(jitsiRoom.id).subscribe((result: any) => { if (result) {
this.refresh(); this.jitsiService.delete(jitsiRoom.id).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }
@ -150,10 +167,13 @@ export class JitsiComponent implements OnInit {
} }
createShortenedUrl(jitsiRoom: any) { createShortenedUrl(jitsiRoom: any) {
this.jitsiService.createShortUrl(jitsiRoom.id).subscribe((result: any) => { this.jitsiService.createShortUrl(jitsiRoom.id).subscribe({
this.refresh(); next: (result: any) => {
}, (error: any) => { this.refresh();
this.snackBar.open(this.i18n.get("urlshortener.noQuota", []), this.i18n.get("close", [])); },
error: (error: any) => {
this.snackBar.open(this.i18n.get("urlshortener.noQuota", []), this.i18n.get("close", []));
}
}); });
} }
@ -176,9 +196,11 @@ export class JitsiComponent implements OnInit {
minWidth: '400px', minWidth: '400px',
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -222,18 +244,21 @@ export class JitsiEditDialog {
} }
save() { save() {
this.jitsiService.update(this.jitsiRoom).subscribe((result: any) => { this.jitsiService.update(this.jitsiRoom).subscribe({
this.dialogRef.close(result); next: (result: any) => {
}, (error) => { this.dialogRef.close(result);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });

View File

@ -4,29 +4,44 @@
<mat-card-header> <mat-card-header>
<mat-card-title>{{'jukebox' | i18n}}</mat-card-title> <mat-card-title>{{'jukebox' | i18n}}</mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-title-group *ngIf="currentTrack"> <ng-container *ngIf="!checking">
<img *ngIf="getImageUrl(currentTrack)" mat-card-sm-image [src]="getImageUrl(currentTrack)"> <mat-card-title-group *ngIf="currentTrack">
<mat-card-title><small>{{'jukebox.current' | i18n}}</small></mat-card-title> <img *ngIf="getImageUrl(currentTrack)" mat-card-sm-image [src]="getImageUrl(currentTrack)">
<mat-card-title>{{currentTrack.name}}</mat-card-title> <mat-card-title><small>{{'jukebox.current' | i18n}}</small></mat-card-title>
<mat-card-subtitle> <mat-card-title>{{currentTrack.name}}</mat-card-title>
<span *ngFor="let artist of currentTrack.artists; let i = index"> <mat-card-subtitle>
{{artist.name}}<span *ngIf="(i+1) < currentTrack.artists.length">, </span> <span *ngFor="let artist of currentTrack.artists; let i = index">
</span> {{artist.name}}<span *ngIf="(i+1) < currentTrack.artists.length">, </span>
</mat-card-subtitle> </span>
</mat-card-title-group> </mat-card-subtitle>
<mat-card-content> </mat-card-title-group>
<mat-divider></mat-divider> <mat-card-content>
<br /> <mat-divider></mat-divider>
<mat-form-field> <br />
<input matInput [formControl]="searchFormControl" placeholder="{{'jukebox.search' | i18n}}"> <mat-form-field>
</mat-form-field> <input matInput [formControl]="searchFormControl" placeholder="{{'jukebox.search' | i18n}}">
</mat-card-content> </mat-form-field>
<mat-card-actions> </mat-card-content>
<button mat-raised-button type="submit" [disabled]="!searchFormControl.value || timeout > 0 || searchDisabled"> <mat-card-actions>
<mat-icon inline="true">{{'jukebox.search.icon' | i18n}}</mat-icon> <button mat-raised-button type="submit"
{{'jukebox.search.submit' | i18n}} [disabled]="!searchFormControl.value || timeout > 0 || searchDisabled">
</button> <mat-icon inline="true">{{'jukebox.search.icon' | i18n}}</mat-icon>
</mat-card-actions> {{'jukebox.search.submit' | i18n}}
</button>
</mat-card-actions>
<mat-card-footer>
<a (click)="check()" class="help-button" mat-fab color="accent">
<mat-icon>refresh</mat-icon>
</a>
</mat-card-footer>
</ng-container>
<ng-container *ngIf="checking">
<mat-card-actions>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-card-actions>
</ng-container>
</mat-card> </mat-card>
</form> </form>

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
@ -15,18 +15,20 @@ import { Data } from '@angular/router';
templateUrl: './jukebox.component.html', templateUrl: './jukebox.component.html',
styleUrls: [ './jukebox.component.scss' ] styleUrls: [ './jukebox.component.scss' ]
}) })
export class JukeboxComponent implements OnInit { export class JukeboxComponent implements OnInit, OnDestroy {
timeout: number = 0; timeout: number = 0;
timer; timer;
searchResult: any; searchResult: any;
currentTrack: any; currentTrack: any;
checking: boolean = false;
active: boolean = false; active: boolean = false;
wait: boolean = false; wait: boolean = false;
forbidden: boolean = false; forbidden: boolean = false;
unavailable: boolean = false; unavailable: boolean = false;
searchDisabled = true; searchDisabled = true;
searchFormControl = new FormControl(); searchFormControl = new FormControl();
automaticCheck;
constructor( constructor(
public dialog: MatDialog, public dialog: MatDialog,
@ -37,61 +39,84 @@ export class JukeboxComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.check(); this.check();
this.searchFormControl.valueChanges.subscribe(value => { this.searchFormControl.valueChanges.subscribe({
this.searchDisabled = false; next: (value) => {
this.searchDisabled = false;
}
}) })
this.automaticCheck = setInterval(() => {
this.check();
}, 15000);
}
ngOnDestroy(): void {
if (this.automaticCheck) {
clearInterval(this.automaticCheck);
}
} }
check() { check() {
this.timeout = 0; this.timeout = 0;
this.wait = false; this.wait = false;
this.checking = true;
this.forbidden = false; this.forbidden = false;
this.unavailable = false; this.unavailable = false;
this.jukeboxService.check().subscribe((response) => { this.jukeboxService.check().subscribe({
if (response) { next: (response) => {
this.currentTrack = response; if (response) {
}
this.active = true;
}, (error) => {
this.active = false;
if (error.status == 403) {
this.forbidden = true;
} else if (error.status == 410) {
this.unavailable = true;
} else if (error.status == 402) {
this.wait = true;
this.timeout = 60 - error.error;
this.jukeboxService.current().subscribe((response) => {
this.currentTrack = response; this.currentTrack = response;
}); }
this.active = true;
this.checking = false;
},
error: (error) => {
this.active = false;
if (error.status == 403) {
this.forbidden = true;
} else if (error.status == 410) {
this.unavailable = true;
} else if (error.status == 402) {
this.wait = true;
this.timeout = 60 - error.error;
this.timer = setInterval(() => { this.jukeboxService.current().subscribe({
this.timeout--; next: (response) => {
if (this.timeout == 0) { this.currentTrack = response;
clearInterval(this.timer); }
this.check(); });
}
}, 1000) this.timer = setInterval(() => {
this.timeout--;
if (this.timeout == 0) {
clearInterval(this.timer);
this.check();
}
}, 1000)
}
this.checking = false;
} }
}) })
} }
search() { search() {
this.searchDisabled = true; this.searchDisabled = true;
this.jukeboxService.search(this.searchFormControl.value).subscribe((data: any) => { this.jukeboxService.search(this.searchFormControl.value).subscribe({
this.searchResult = data.tracks; next: (data: any) => {
this.searchResult = data.tracks;
}
}) })
} }
searchMore() { searchMore() {
this.searchDisabled = true; this.searchDisabled = true;
this.jukeboxService.searchOffset(this.searchFormControl.value, this.searchResult.offset + this.searchResult.limit).subscribe((data: any) => { this.jukeboxService.searchOffset(this.searchFormControl.value, this.searchResult.offset + this.searchResult.limit).subscribe({
this.searchResult.offset = data.tracks.offset; next: (data: any) => {
this.searchResult.total = data.tracks.total; this.searchResult.offset = data.tracks.offset;
for (let track of data.tracks.items) { this.searchResult.total = data.tracks.total;
this.searchResult.items.push(track); for (let track of data.tracks.items) {
this.searchResult.items.push(track);
}
} }
}) })
} }
@ -117,28 +142,33 @@ export class JukeboxComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.jukeboxService.queue(track.uri).subscribe(() => { if (result) {
this.active = false; this.jukeboxService.queue(track.uri).subscribe({
this.wait = true; next: () => {
this.timeout = 60; this.active = false;
this.timer = setInterval(() => { this.wait = true;
this.timeout--; this.timeout = 60;
if (this.timeout == 0) { this.timer = setInterval(() => {
clearInterval(this.timer); this.timeout--;
this.check(); if (this.timeout == 0) {
} clearInterval(this.timer);
}, 1000) this.check();
}
}, 1000)
this.snackBar.open(this.i18n.get("jukebox.addToQueue.success", []), this.i18n.get("close", []), { this.snackBar.open(this.i18n.get("jukebox.addToQueue.success", []), this.i18n.get("close", []), {
duration: 3000 duration: 3000
}); });
}, (error) => { },
this.snackBar.open(this.i18n.get("jukebox.addToQueue.error", []), this.i18n.get("close", []), { error: (error) => {
duration: 3000 this.snackBar.open(this.i18n.get("jukebox.addToQueue.error", []), this.i18n.get("close", []), {
}); duration: 3000
}) });
}
})
}
} }
}); });
} }

View File

@ -1,14 +1,14 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import {Auth2FAService} from '../../services/auth.2fa.service'; import { Auth2FAService } from '../../services/auth.2fa.service';
import {Router, ActivatedRoute} from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import {environment} from '../../../environments/environment'; import { environment } from '../../../environments/environment';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
templateUrl: './login-totp.component.html', templateUrl: './login-totp.component.html',
styleUrls: ['./login-totp.component.scss'] styleUrls: [ './login-totp.component.scss' ]
}) })
export class LoginTotpComponent implements OnInit { export class LoginTotpComponent implements OnInit {
@ -17,29 +17,34 @@ export class LoginTotpComponent implements OnInit {
public apiUrl = environment.apiUrl; public apiUrl = environment.apiUrl;
targetRoute = '/account/info'; targetRoute = '/account/info';
constructor(private formBuilder: FormBuilder, private auth2FAService: Auth2FAService, private router: Router, private route: ActivatedRoute) {} constructor(private formBuilder: FormBuilder, private auth2FAService: Auth2FAService, private router: Router, private route: ActivatedRoute) { }
ngOnInit() { ngOnInit() {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
code: ['', Validators.required], code: [ '', Validators.required ],
keep: [''] keep: [ '' ]
}); });
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if(params['target']) { next: (params) => {
this.targetRoute = params['target']; if (params[ 'target' ]) {
this.targetRoute = params[ 'target' ];
}
} }
}); });
} }
async loginTotp() { async loginTotp() {
this.loginInvalid = false; this.loginInvalid = false;
if(this.form.valid) { if (this.form.valid) {
this.auth2FAService.login('totp', this.form.get('code').value, this.form.get('keep').value).subscribe((response: any) => { this.auth2FAService.login('totp', this.form.get('code').value, this.form.get('keep').value).subscribe({
this.router.navigate([this.targetRoute]); next: (response: any) => {
}, error => { this.router.navigate([ this.targetRoute ]);
this.loginInvalid = true; },
error: (error) => {
this.loginInvalid = true;
}
}); });
} }

View File

@ -1,14 +1,14 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import {AuthService} from './../../services/auth.service'; import { AuthService } from './../../services/auth.service';
import {Router, ActivatedRoute} from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import {environment} from './../../../environments/environment'; import { environment } from './../../../environments/environment';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
templateUrl: './login.component.html', templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'] styleUrls: [ './login.component.scss' ]
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
@ -22,26 +22,28 @@ export class LoginComponent implements OnInit {
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private authService: AuthService, private authService: AuthService,
private router: Router, private router: Router,
private route: ActivatedRoute) {} private route: ActivatedRoute) { }
async ngOnInit() { async ngOnInit() {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
username: ['', Validators.required], username: [ '', Validators.required ],
password: ['', Validators.required], password: [ '', Validators.required ],
keep: [''] keep: [ '' ]
}); });
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if(params['target']) { next: (params) => {
this.targetRoute = params['target']; if (params[ 'target' ]) {
this.router.navigate([], {queryParams: {target: null}, queryParamsHandling: 'merge'}); this.targetRoute = params[ 'target' ];
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge' });
}
} }
}); });
} }
async login() { async login() {
this.loginInvalid = false; this.loginInvalid = false;
if(this.form.valid) { if (this.form.valid) {
const loginModel = { const loginModel = {
username: this.form.get('username').value, username: this.form.get('username').value,
@ -49,13 +51,16 @@ export class LoginComponent implements OnInit {
keep: this.form.get('keep').value keep: this.form.get('keep').value
}; };
this.authService.login(loginModel).subscribe((response: any) => { this.authService.login(loginModel).subscribe({
this.router.navigate([this.targetRoute]); next: (response: any) => {
}, error => { this.router.navigate([ this.targetRoute ]);
if(error.status == 428) { },
this.router.navigate(["/login/totp"], {queryParams: {target: this.targetRoute}}); error: (error) => {
} else { if (error.status == 428) {
this.loginInvalid = true; this.router.navigate([ "/login/totp" ], { queryParams: { target: this.targetRoute } });
} else {
this.loginInvalid = true;
}
} }
}); });

View File

@ -41,22 +41,25 @@ export class MinetestAccountsComponent implements OnInit {
create(): void { create(): void {
this.working = true; this.working = true;
this.minetestAccountsService.create(this.minetestAccount).subscribe(response => { this.minetestAccountsService.create(this.minetestAccount).subscribe({
this.refresh(); next: (response) => {
this.formDirective.resetForm(); this.refresh();
this.minetestAccount = {}; this.formDirective.resetForm();
this.working = false; this.minetestAccount = {};
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
@ -64,16 +67,20 @@ export class MinetestAccountsComponent implements OnInit {
refresh() { refresh() {
this.minetestAccountsQuota = 0; this.minetestAccountsQuota = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe({
for (let quota of data) { next: (data: any) => {
if (quota.name == "minetest_accounts") { for (let quota of data) {
this.minetestAccountsQuota = quota.value; if (quota.name == "minetest_accounts") {
this.minetestAccountsQuota = quota.value;
}
} }
} }
}) })
this.minetestAccountsService.get().subscribe((data: any) => { this.minetestAccountsService.get().subscribe({
this.minetestAccounts = data; next: (data: any) => {
this.minetestAccounts = data;
}
}) })
} }
@ -86,11 +93,15 @@ export class MinetestAccountsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.minetestAccountsService.delete(name).subscribe((result: any) => { if (result) {
this.refresh(); this.minetestAccountsService.delete(name).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }

View File

@ -16,17 +16,19 @@ export class ParteyComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.parteyTagsService.get().subscribe((data: any[]) => { this.parteyTagsService.get().subscribe({
this.tags = data; next: (data: any[]) => {
this.tags = data;
}
}) })
} }
toDate(value : string) { toDate(value: string) {
return new Date(value); return new Date(value);
} }
activeTag(tag: any) { activeTag(tag: any) {
return !tag.starts && !tag.expires; return !tag.starts && !tag.expires;
} }
upcomingTag(tag: any) { upcomingTag(tag: any) {

View File

@ -56,9 +56,11 @@ export class ParteyTimeslotsComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.authService.auth.subscribe((auth: any) => { this.authService.auth.subscribe({
if (auth.principal && auth.principal.userId) { next: (auth: any) => {
this.userId = auth.principal.userId; if (auth.principal && auth.principal.userId) {
this.userId = auth.principal.userId;
}
} }
}); });
@ -78,29 +80,51 @@ export class ParteyTimeslotsComponent implements OnInit {
this.filter.after = moment.utc().format(); this.filter.after = moment.utc().format();
this.afterFormControl.setValue(new Date()); this.afterFormControl.setValue(new Date());
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => { this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe({
this.filter.search = value; next: (value) => {
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { this.filter.search = value;
this.timeslots = data; this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
}, (error) => { }) next: (data: any) => {
this.timeslots = data;
},
error: (error) => { }
})
}
}) })
this.ownerFormControl.valueChanges.subscribe(value => {
this.filter.owner = value; this.ownerFormControl.valueChanges.subscribe({
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { next: (value) => {
this.timeslots = data; this.filter.owner = value;
}, (error) => { }) this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
next: (data: any) => {
this.timeslots = data;
},
error: (error) => { }
})
}
}) })
this.typeFormControl.valueChanges.subscribe(value => { this.typeFormControl.valueChanges.subscribe({
this.filter.type = value; next: (value) => {
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { this.filter.type = value;
this.timeslots = data; this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
}, (error) => { }) next: (data: any) => {
this.timeslots = data;
},
error: (error) => { }
})
}
}) })
this.afterFormControl.valueChanges.subscribe((value: Date) => {
this.filter.after = value && moment.utc(value).format() || undefined; this.afterFormControl.valueChanges.subscribe({
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { next: (value: Date) => {
this.timeslots = data; this.filter.after = value && moment.utc(value).format() || undefined;
}, (error) => { }) this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
next: (data: any) => {
this.timeslots = data;
},
error: (error) => { }
})
}
}) })
this.refresh(); this.refresh();
@ -109,21 +133,28 @@ export class ParteyTimeslotsComponent implements OnInit {
refresh() { refresh() {
this.timeslotsQuota = 0; this.timeslotsQuota = 0;
this.parteyTimeslotsService.quota().subscribe((data: number) => { this.parteyTimeslotsService.quota().subscribe({
this.timeslotsQuota = data; next: (data: number) => {
this.timeslotsQuota = data;
}
}) })
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
this.timeslots = data; next: (data: any) => {
this.timeslots = data;
}
}) })
} }
updatePages(event: PageEvent) { updatePages(event: PageEvent) {
this.page.page = event.pageIndex; this.page.page = event.pageIndex;
this.page.size = event.pageSize; this.page.size = event.pageSize;
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
this.timeslots = data; next: (data: any) => {
}, (error) => { }) this.timeslots = data;
},
error: (error) => { }
})
} }
updateSort(sort: Sort) { updateSort(sort: Sort) {
@ -134,9 +165,12 @@ export class ParteyTimeslotsComponent implements OnInit {
this.page.sort = sort.active; this.page.sort = sort.active;
this.page.desc = sort.direction == "desc"; this.page.desc = sort.direction == "desc";
} }
this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe((data: any) => { this.parteyTimeslotsService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.filter).subscribe({
this.timeslots = data; next: (data: any) => {
}, (error) => { }) this.timeslots = data;
},
error: (error) => { }
})
} }
confirmDelete(timeslot) { confirmDelete(timeslot) {
@ -147,11 +181,15 @@ export class ParteyTimeslotsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.parteyTimeslotsService.delete(timeslot.id).subscribe((result: any) => { if (result) {
this.refresh(); this.parteyTimeslotsService.delete(timeslot.id).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }
@ -162,9 +200,11 @@ export class ParteyTimeslotsComponent implements OnInit {
minWidth: '400px' minWidth: '400px'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -176,9 +216,11 @@ export class ParteyTimeslotsComponent implements OnInit {
minWidth: '400px' minWidth: '400px'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
@ -229,36 +271,42 @@ export class ParteyTimeslotDialog {
} }
create(timeslot) { create(timeslot) {
this.parteyTimeslotsService.create(timeslot).subscribe((result: any) => { this.parteyTimeslotsService.create(timeslot).subscribe({
this.dialogRef.close(timeslot); next: (result: any) => {
}, (error) => { this.dialogRef.close(timeslot);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });
} }
save(timeslot) { save(timeslot) {
this.parteyTimeslotsService.update(timeslot).subscribe((result: any) => { this.parteyTimeslotsService.update(timeslot).subscribe({
this.dialogRef.close(timeslot); next: (result: any) => {
}, (error) => { this.dialogRef.close(timeslot);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });

View File

@ -8,7 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router';
@Component({ @Component({
selector: 'app-password-reset', selector: 'app-password-reset',
templateUrl: './password-reset.component.html', templateUrl: './password-reset.component.html',
styleUrls: ['./password-reset.component.scss'] styleUrls: [ './password-reset.component.scss' ]
}) })
export class PasswordResetComponent implements OnInit { export class PasswordResetComponent implements OnInit {
@ -26,15 +26,17 @@ export class PasswordResetComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
password: ['', Validators.required], password: [ '', Validators.required ],
password2: ['', Validators.required] password2: [ '', Validators.required ]
}, { }, {
validator: MatchingValidator('password', 'password2') validator: MatchingValidator('password', 'password2')
}); });
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params.token) { next: (params) => {
this.model.token = params.token; if (params.token) {
this.model.token = params.token;
}
} }
}); });
@ -42,22 +44,25 @@ export class PasswordResetComponent implements OnInit {
passwordReset() { passwordReset() {
this.working = true; this.working = true;
this.authService.passwordReset(this.model).subscribe(response => { this.authService.passwordReset(this.model).subscribe({
this.success = true; next: (response) => {
}, (error) => { this.success = true;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[code.field] = errors[code.field] || {}; let errors = {};
errors[code.field][code.code] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[code]); this.form.get(code).setErrors(errors[ code ]);
}
} else {
this.tokenInvalid = true;
} }
} else {
this.tokenInvalid = true;
} }
}) })
} }

View File

@ -8,7 +8,7 @@ var openpgp = require('openpgp');
@Component({ @Component({
selector: 'app-password', selector: 'app-password',
templateUrl: './password.component.html', templateUrl: './password.component.html',
styleUrls: ['./password.component.scss'] styleUrls: [ './password.component.scss' ]
}) })
export class PasswordComponent implements OnInit { export class PasswordComponent implements OnInit {
@ -20,32 +20,34 @@ export class PasswordComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
username: ['', Validators.required], username: [ '', Validators.required ],
privateKey: [''] privateKey: [ '' ]
}); });
} }
async passwordRequest() { async passwordRequest() {
this.working = true; this.working = true;
const { keys: [privateKey] } = await openpgp.key.readArmored(this.model.privateKey); const { keys: [ privateKey ] } = await openpgp.key.readArmored(this.model.privateKey);
const model = { const model = {
username: this.model.username username: this.model.username
} }
this.authService.passwordRequest(this.model.username).subscribe(async response => { this.authService.passwordRequest(this.model.username).subscribe({
next: async response => {
if (privateKey) { if (privateKey) {
const message = await openpgp.message.readArmored(response); const message = await openpgp.message.readArmored(response);
const decrypted = await openpgp.decrypt({ const decrypted = await openpgp.decrypt({
message: message, message: message,
privateKeys: [privateKey] privateKeys: [ privateKey ]
}); });
this.working = false; this.working = false;
this.router.navigate(['/password-reset'], { queryParams: { token: decrypted.data.trim() } }); this.router.navigate([ '/password-reset' ], { queryParams: { token: decrypted.data.trim() } });
} else { } else {
this.working = false; this.working = false;
}
} }
}) })

View File

@ -60,17 +60,23 @@ export class RegisterComponent implements OnInit {
validator: MatchingValidator('password', 'password2') validator: MatchingValidator('password', 'password2')
}); });
this.itemService.items().subscribe((data: any) => { this.itemService.items().subscribe({
this.items = data; next: (data: any) => {
this.items = data;
}
}); });
this.permissionService.permissionsNew().subscribe((data: any) => { this.permissionService.permissionsNew().subscribe({
this.permissions = data; next: (data: any) => {
}) this.permissions = data;
}
});
this.quotaService.quotasNew().subscribe((data: any) => { this.quotaService.quotasNew().subscribe({
this.quotas = data; next: (data: any) => {
}) this.quotas = data;
}
});
} }
onPrimaryChange() { onPrimaryChange() {
@ -119,37 +125,42 @@ export class RegisterComponent implements OnInit {
this.model.profileFields.push({ "name": "primaryEmail", "type": "BOOL", "visibility": "PRIVATE", "value": this.model.primaryEmail }); this.model.profileFields.push({ "name": "primaryEmail", "type": "BOOL", "visibility": "PRIVATE", "value": this.model.primaryEmail });
} }
this.userService.register(this.model).subscribe((result: any) => { this.userService.register(this.model).subscribe({
result.privateKey = privKey; next: (result: any) => {
result.privateKey = privKey;
const dialogRef = this.dialog.open(RegisterDialog, { const dialogRef = this.dialog.open(RegisterDialog, {
closeOnNavigation: false, closeOnNavigation: false,
disableClose: true, disableClose: true,
data: result data: result
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.success = true; if (result) {
} this.success = true;
}); }
}
});
this.working = false; this.working = false;
}, (error) => { },
this.working = false; error: (error) => {
if (error.status == 401) { this.working = false;
this.missingToken = true; if (error.status == 401) {
} if (error.status == 423) { this.missingToken = true;
this.lockedToken = true; } if (error.status == 423) {
} else if (error.status == 409) { this.lockedToken = true;
let errors = {}; } else if (error.status == 409) {
for (let code of error.error) { let errors = {};
errors[ code.field ] = errors[ code.field ] || {}; for (let code of error.error) {
errors[ code.field ][ code.code ] = true; errors[ code.field ] = errors[ code.field ] || {};
} errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })

View File

@ -20,19 +20,21 @@ export class ServicesComponent implements OnInit {
this.view = localStorage.getItem("bstly.servicesView") || 'grid'; this.view = localStorage.getItem("bstly.servicesView") || 'grid';
this.serviceService.services().subscribe((data: Array<any>) => { this.serviceService.services().subscribe({
let that = this; next: (data: Array<any>) => {
that.baseServices = []; let that = this;
data.forEach(function (service) { that.baseServices = [];
if (!service.category || service.category == "") { data.forEach(function (service) {
that.baseServices.push(service); if (!service.category || service.category == "") {
} else { that.baseServices.push(service);
if (!that.serviceCategory[ service.category ]) { } else {
that.serviceCategory[ service.category ] = []; if (!that.serviceCategory[ service.category ]) {
that.serviceCategory[ service.category ] = [];
}
that.serviceCategory[ service.category ].push(service);
} }
that.serviceCategory[ service.category ].push(service); })
} }
})
}) })
} }

View File

@ -12,7 +12,7 @@ import { QuotaService } from './../../services/quota.service';
@Component({ @Component({
selector: 'app-tokens', selector: 'app-tokens',
templateUrl: './tokens.component.html', templateUrl: './tokens.component.html',
styleUrls: ['./tokens.component.scss'] styleUrls: [ './tokens.component.scss' ]
}) })
export class TokensComponent implements OnInit { export class TokensComponent implements OnInit {
@ -37,8 +37,10 @@ export class TokensComponent implements OnInit {
this.currentLocale = this.i18n.getLocale(); this.currentLocale = this.i18n.getLocale();
this.authService.auth.subscribe(data => { this.authService.auth.subscribe({
this.auth = data; next: (data) => {
this.auth = data;
}
}) })
this.update(); this.update();
@ -46,21 +48,26 @@ export class TokensComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
token: ['', Validators.required] token: [ '', Validators.required ]
}); });
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params.token) { next: (params) => {
this.itemService.redeemSecret(params.token).subscribe((data: any) => { if (params.token) {
this.update(); this.itemService.redeemSecret(params.token).subscribe({
}, error => { next: (data: any) => {
this.form.get('token').patchValue(params.token); this.update();
if (error.status == 410) { },
this.tokenRedeemed = true; error: error => {
} else { this.form.get('token').patchValue(params.token);
this.tokenInvalid = true; if (error.status == 410) {
} this.tokenRedeemed = true;
}) } else {
this.tokenInvalid = true;
}
}
})
}
} }
}); });
} }
@ -70,46 +77,60 @@ export class TokensComponent implements OnInit {
this.tokenRedeemed = false; this.tokenRedeemed = false;
if (this.form.valid) { if (this.form.valid) {
const secret = this.form.get('token').value; const secret = this.form.get('token').value;
this.itemService.redeemSecret(secret).subscribe((data: any) => { this.itemService.redeemSecret(secret).subscribe({
this.formDirective.resetForm(); next: (data: any) => {
this.update(); this.formDirective.resetForm();
}, error => { this.update();
if (error.status == 410) { },
this.tokenRedeemed = true; error: (error) => {
} else { if (error.status == 410) {
this.tokenInvalid = true; this.tokenRedeemed = true;
} else {
this.tokenInvalid = true;
}
} }
}) })
} }
} }
removeSecret(secret: String) { removeSecret(secret: String) {
this.itemService.removeSecret(secret).subscribe((data: any) => { this.itemService.removeSecret(secret).subscribe({
this.update(); next: (data: any) => {
}, error => { this.update();
},
error: (error) => {
}
}) })
} }
redeem() { redeem() {
if (this.auth.authenticated) { if (this.auth.authenticated) {
this.itemService.redeem().subscribe((data: any) => { this.itemService.redeem().subscribe({
this.router.navigate(["/account/info"]); next: (data: any) => {
this.router.navigate([ "/account/info" ]);
}
}) })
} }
} }
update() { update() {
this.authService.getAuth().then(response => { this.authService.getAuth().then(response => {
this.itemService.items().subscribe((data: any) => { this.itemService.items().subscribe({
this.items = data; next: (data: any) => {
this.items = data;
}
}); });
this.permissionService.permissionsNew().subscribe((data: any) => { this.permissionService.permissionsNew().subscribe({
this.permissions = data; next: (data: any) => {
this.permissions = data;
}
}) })
this.quotaService.quotasNew().subscribe((data: any) => { this.quotaService.quotasNew().subscribe({
this.quotas = data; next: (data: any) => {
this.quotas = data;
}
}) })
}).catch(function (error) { });; }).catch(function (error) { });;
} }

View File

@ -16,10 +16,12 @@ export class UnavailableComponent implements OnInit {
private route: ActivatedRoute) { } private route: ActivatedRoute) { }
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params[ 'target' ]) { next: (params) => {
this.targetRoute = params[ 'target' ]; if (params[ 'target' ]) {
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', skipLocationChange: true }); this.targetRoute = params[ 'target' ];
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', skipLocationChange: true });
}
} }
}); });

View File

@ -60,16 +60,22 @@ export class UrlShortenerComponent implements OnInit {
}); });
this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe(value => { this.searchFormControl.valueChanges.pipe(debounceTime(500)).subscribe({
this.page.search = this.searchFormControl.value ? this.searchFormControl.value : ""; next: (value) => {
this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe((data: any) => { this.page.search = this.searchFormControl.value ? this.searchFormControl.value : "";
this.shortenedUrls = data; this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe({
}) next: (data: any) => {
this.shortenedUrls = data;
}
})
}
}) })
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params.url) { next: (params) => {
this.shortenedUrl.url = decodeURIComponent(params.url); if (params.url) {
this.shortenedUrl.url = decodeURIComponent(params.url);
}
} }
}) })
@ -79,22 +85,25 @@ export class UrlShortenerComponent implements OnInit {
create(): void { create(): void {
this.working = true; this.working = true;
this.urlShortenerService.create(this.shortenedUrl).subscribe(response => { this.urlShortenerService.create(this.shortenedUrl).subscribe({
this.refresh(); next: (response) => {
this.formDirective.resetForm(); this.refresh();
this.shortenedUrl = {}; this.formDirective.resetForm();
this.working = false; this.shortenedUrl = {};
}, (error) => { this.working = false;
this.working = false; },
if (error.status == 409) { error: (error) => {
let errors = {}; this.working = false;
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}) })
@ -102,35 +111,45 @@ export class UrlShortenerComponent implements OnInit {
refresh() { refresh() {
this.shortenedUrlQuota = 0; this.shortenedUrlQuota = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe({
for (let quota of data) { next: (data: any) => {
if (quota.name == "url_shortener") { for (let quota of data) {
this.shortenedUrlQuota = quota.value; if (quota.name == "url_shortener") {
this.shortenedUrlQuota = quota.value;
}
} }
} }
}) })
this.page.search = this.searchFormControl.value ? this.searchFormControl.value : ""; this.page.search = this.searchFormControl.value ? this.searchFormControl.value : "";
this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe((data: any) => { this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe({
this.shortenedUrls = data; next: (data: any) => {
this.shortenedUrls = data;
}
}) })
} }
updateSearch() { updateSearch() {
this.page.search = this.searchFormControl.value ? this.searchFormControl.value : ""; this.page.search = this.searchFormControl.value ? this.searchFormControl.value : "";
this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe((data: any) => { this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe({
this.shortenedUrls = data; next: (data: any) => {
}, (error) => { }) this.shortenedUrls = data;
},
error: (error) => { }
})
} }
updatePages(event: PageEvent) { updatePages(event: PageEvent) {
this.page.page = event.pageIndex; this.page.page = event.pageIndex;
this.page.size = event.pageSize; this.page.size = event.pageSize;
this.page.search = this.searchFormControl.value ? this.searchFormControl.value : ""; this.page.search = this.searchFormControl.value ? this.searchFormControl.value : "";
this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe((data: any) => { this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe({
this.shortenedUrls = data; next: (data: any) => {
}, (error) => { }) this.shortenedUrls = data;
},
error: (error) => { }
})
} }
updateSort(sort: Sort) { updateSort(sort: Sort) {
@ -142,9 +161,12 @@ export class UrlShortenerComponent implements OnInit {
this.page.desc = sort.direction == "desc"; this.page.desc = sort.direction == "desc";
} }
this.page.search = this.searchFormControl.value ? this.searchFormControl.value : ""; this.page.search = this.searchFormControl.value ? this.searchFormControl.value : "";
this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe((data: any) => { this.urlShortenerService.get(this.page.page, this.page.size, this.page.sort, this.page.desc, this.page.search).subscribe({
this.shortenedUrls = data; next: (data: any) => {
}, (error) => { }) this.shortenedUrls = data;
},
error: (error) => { }
})
} }
confirmDelete(shortenedUrl) { confirmDelete(shortenedUrl) {
@ -155,11 +177,15 @@ export class UrlShortenerComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.urlShortenerService.delete(shortenedUrl.code).subscribe((result: any) => { if (result) {
this.refresh(); this.urlShortenerService.delete(shortenedUrl.code).subscribe({
}) next: (result: any) => {
this.refresh();
}
})
}
} }
}); });
} }
@ -177,9 +203,11 @@ export class UrlShortenerComponent implements OnInit {
minWidth: '400px', minWidth: '400px',
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.refresh(); if (result) {
this.refresh();
}
} }
}); });
} }
@ -236,18 +264,21 @@ export class UrlShortenerEditDialog {
} }
save() { save() {
this.urlShortenerService.update(this.shortenedUrlModel).subscribe((result: any) => { this.urlShortenerService.update(this.shortenedUrlModel).subscribe({
this.dialogRef.close(result); next: (result: any) => {
}, (error) => { this.dialogRef.close(result);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });
@ -308,9 +339,11 @@ export class UrlShortenerPasswordComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.code = this.route.snapshot.paramMap.get('code'); this.code = this.route.snapshot.paramMap.get('code');
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe({
if (params[ 'error' ] || params[ 'error' ] == '') { next: (params) => {
this.invalidPassword = true; if (params[ 'error' ] || params[ 'error' ] == '') {
this.invalidPassword = true;
}
} }
}); });
} }

View File

@ -1,9 +1,9 @@
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import {AuthService} from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import {ProfileService} from '../../services/profile.service'; import { ProfileService } from '../../services/profile.service';
@Component({ @Component({
selector: 'app-user', selector: 'app-user',
@ -20,19 +20,24 @@ export class UserComponent implements OnInit {
constructor( constructor(
private authService: AuthService, private authService: AuthService,
private profileService: ProfileService, private profileService: ProfileService,
private route: ActivatedRoute) {} private route: ActivatedRoute) { }
async ngOnInit() { async ngOnInit() {
this.username = this.route.snapshot.paramMap.get('username'); this.username = this.route.snapshot.paramMap.get('username');
this.profileService.getForUser(this.username).subscribe((data: any) => { this.profileService.getForUser(this.username).subscribe({
this.success = true; next: (data: any) => {
this.model = data; this.success = true;
this.model = data;
this.authService.auth.subscribe((auth: any) => { this.authService.auth.subscribe({
this.isMe = auth && auth.principal && auth.principal.username == this.model.username; next: (auth: any) => {
}); this.isMe = auth && auth.principal && auth.principal.username == this.model.username;
}, error => { }
this.error = error; });
},
error: (error) => {
this.error = error;
}
}) })

View File

@ -29,31 +29,37 @@ export class DurationpickerComponent implements OnInit, ControlValueAccessor {
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {
this.days.valueChanges.subscribe(value => { this.days.valueChanges.subscribe({
if (value < this.model.days()) { next: (value) => {
this.model.subtract((this.model.days() - value), "days"); if (value < this.model.days()) {
} else { this.model.subtract((this.model.days() - value), "days");
this.model.add((value - this.model.days()), "days"); } else {
this.model.add((value - this.model.days()), "days");
}
this.checkValue();
} }
this.checkValue();
}) })
this.hours.valueChanges.subscribe(value => { this.hours.valueChanges.subscribe({
if (value < this.model.hours()) { next: (value) => {
this.model.subtract((this.model.hours() - value), "hours"); if (value < this.model.hours()) {
} else { this.model.subtract((this.model.hours() - value), "hours");
this.model.add((value - this.model.hours()), "hours"); } else {
this.model.add((value - this.model.hours()), "hours");
}
this.checkValue();
} }
this.checkValue();
}) })
this.minutes.valueChanges.subscribe(value => { this.minutes.valueChanges.subscribe({
if (value < this.model.minutes()) { next: (value) => {
this.model.subtract((this.model.minutes() - value), "minutes"); if (value < this.model.minutes()) {
} else { this.model.subtract((this.model.minutes() - value), "minutes");
this.model.add((value - this.model.minutes()), "minutes"); } else {
this.model.add((value - this.model.minutes()), "minutes");
}
this.checkValue();
} }
this.checkValue();
}) })
} }

View File

@ -17,7 +17,7 @@ import { MatSidenav } from '@angular/material/sidenav';
}) })
export class MainComponent { export class MainComponent {
opened : boolean = true; opened: boolean = true;
darkTheme = "false"; darkTheme = "false";
title = 'we.bstly'; title = 'we.bstly';
currentLocale: String; currentLocale: String;
@ -44,8 +44,10 @@ export class MainComponent {
this.datetimeformat = this.i18n.get('format.datetime', []); this.datetimeformat = this.i18n.get('format.datetime', []);
this.currentLocale = this.i18n.getLocale(); this.currentLocale = this.i18n.getLocale();
this.locales = this.i18n.getLocales(); this.locales = this.i18n.getLocales();
this.authService.auth.subscribe(data => { this.authService.auth.subscribe({
this.auth = data; next: (data) => {
this.auth = data;
}
}) })
this._adapter.setLocale(this.currentLocale); this._adapter.setLocale(this.currentLocale);
@ -69,20 +71,24 @@ export class MainComponent {
localStorage.setItem("bstly.locale", locale); localStorage.setItem("bstly.locale", locale);
if (this.auth && this.auth.authenticated) { if (this.auth && this.auth.authenticated) {
this.profileService.getField("locale").subscribe((profileField: any) => { this.profileService.getField("locale").subscribe({
next: (profileField: any) => {
if (profileField == null) { if (profileField == null) {
profileField = { profileField = {
"name": "locale", "name": "locale",
"type": "TEXT", "type": "TEXT",
"visibility": "PRIVATE" "visibility": "PRIVATE"
}
} }
}
profileField.value = locale; profileField.value = locale;
this.profileService.createOrUpdate(profileField).subscribe((response) => { this.profileService.createOrUpdate(profileField).subscribe({
window.location.reload(); next: (response) => {
}) window.location.reload();
}
})
}
}) })
} else { } else {
window.location.reload(); window.location.reload();
@ -99,20 +105,24 @@ export class MainComponent {
localStorage.setItem("bstly.darkTheme", this.darkTheme); localStorage.setItem("bstly.darkTheme", this.darkTheme);
if (this.auth && this.auth.authenticated) { if (this.auth && this.auth.authenticated) {
this.profileService.getField("darkTheme").subscribe((profileField: any) => { this.profileService.getField("darkTheme").subscribe({
next: (profileField: any) => {
if (profileField == null) { if (profileField == null) {
profileField = { profileField = {
"name": "darkTheme", "name": "darkTheme",
"type": "BOOL", "type": "BOOL",
"visibility": "PRIVATE" "visibility": "PRIVATE"
}
} }
}
profileField.value = this.darkTheme; profileField.value = this.darkTheme;
this.profileService.createOrUpdate(profileField).subscribe((response) => { this.profileService.createOrUpdate(profileField).subscribe({
window.location.reload(); next: (response) => {
}) window.location.reload();
}
})
}
}) })
} else { } else {
window.location.reload(); window.location.reload();
@ -121,10 +131,12 @@ export class MainComponent {
} }
logout() { logout() {
this.authService.logout().subscribe(data => { this.authService.logout().subscribe({
this.router.navigate([ "" ]).then(() => { next: (data) => {
window.location.reload(); this.router.navigate([ "" ]).then(() => {
}); window.location.reload();
});
}
}) })
} }
@ -151,28 +163,34 @@ export class MainComponent {
} }
touchEvents(): void { touchEvents(): void {
fromEvent(document, 'touchstart').subscribe((event: TouchEvent) => { fromEvent(document, 'touchstart').subscribe({
if (event.touches[ 0 ]) { next: (event: TouchEvent) => {
this.touchStartX = event.touches[ 0 ].screenX; if (event.touches[ 0 ]) {
this.touchStartX = event.touches[ 0 ].screenX;
}
} }
}) })
fromEvent(document, 'touchmove').subscribe((event: TouchEvent) => { fromEvent(document, 'touchmove').subscribe({
if (event.touches[ 0 ]) { next: (event: TouchEvent) => {
this.touchX = event.touches[ 0 ].screenX; if (event.touches[ 0 ]) {
this.touchX = event.touches[ 0 ].screenX;
}
} }
}) })
fromEvent(document, 'touchend').subscribe((event: TouchEvent) => { fromEvent(document, 'touchend').subscribe({
if (this.touchX != 0) { next: (event: TouchEvent) => {
const touchDiff = this.touchStartX - this.touchX; if (this.touchX != 0) {
this.touchStartX = 0; const touchDiff = this.touchStartX - this.touchX;
this.touchX = 0; this.touchStartX = 0;
if (touchDiff < 0 && touchDiff < (this.touchThresh * -1) && !this.opened) { this.touchX = 0;
this.opened = true; if (touchDiff < 0 && touchDiff < (this.touchThresh * -1) && !this.opened) {
} else if (touchDiff > 0 && touchDiff > this.touchThresh && this.opened) { this.opened = true;
this.opened = false; } else if (touchDiff > 0 && touchDiff > this.touchThresh && this.opened) {
this.opened = false;
}
} }
} }
}) })

View File

@ -29,25 +29,26 @@ export class ProfileFieldPgpBlob implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.authService.auth.subscribe((auth: any) => { this.authService.auth.subscribe({
if (!auth.authenticated) { next: (auth: any) => {
return; if (!auth.authenticated) {
return;
}
let pgpOption = {
userIds: [ { name: auth.principal.username, email: auth.principal.username + "@we.bstly.de" } ],
curve: "ed25519",
}
openpgp.generateKey(pgpOption).then((key) => {
this.data = {};
this.data.privateKey = key.privateKeyArmored;
this.data.publicKey = key.publicKeyArmored;
this.downloadKey.nativeElement.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(this.data.privateKey));
this.downloadKey.nativeElement.setAttribute('download', auth.principal.username + ".private.key");
});
} }
let pgpOption = {
userIds: [ { name: auth.principal.username, email: auth.principal.username + "@we.bstly.de" } ],
curve: "ed25519",
}
openpgp.generateKey(pgpOption).then((key) => {
this.data = {};
this.data.privateKey = key.privateKeyArmored;
this.data.publicKey = key.publicKeyArmored;
this.downloadKey.nativeElement.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(this.data.privateKey));
this.downloadKey.nativeElement.setAttribute('download', auth.principal.username + ".private.key");
});
}); });
} }

View File

@ -41,12 +41,16 @@ export class ProfileFieldsComponent implements OnInit {
update() { update() {
if (this.username) { if (this.username) {
this.profileService.getForUser(this.username).subscribe((data: any) => { this.profileService.getForUser(this.username).subscribe({
this.profileFields = data.profileFields; next: (data: any) => {
this.profileFields = data.profileFields;
}
}) })
} else { } else {
this.profileService.get().subscribe((data: any) => { this.profileService.get().subscribe({
this.profileFields = data; next: (data: any) => {
this.profileFields = data;
}
}) })
} }
} }
@ -87,15 +91,17 @@ export class ProfileFieldsComponent implements OnInit {
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.profileService.createOrUpdate(result).subscribe(); if (result) {
} else { this.profileService.createOrUpdate(result);
profileField.name = resetProfileField.name; } else {
profileField.value = resetProfileField.value; profileField.name = resetProfileField.name;
profileField.type = resetProfileField.type; profileField.value = resetProfileField.value;
profileField.visibility = resetProfileField.visibility; profileField.type = resetProfileField.type;
profileField.index = resetProfileField.index; profileField.visibility = resetProfileField.visibility;
profileField.index = resetProfileField.index;
}
} }
}); });
@ -110,11 +116,15 @@ export class ProfileFieldsComponent implements OnInit {
} }
}) })
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.profileService.delete(profileField.name).subscribe((result: any) => { if (result) {
this.update(); this.profileService.delete(profileField.name).subscribe({
}) next: (result: any) => {
this.update();
}
})
}
} }
}); });
} }
@ -125,9 +135,11 @@ export class ProfileFieldsComponent implements OnInit {
minWidth: '400px' minWidth: '400px'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
this.update(); if (result) {
this.update();
}
} }
}); });
@ -185,18 +197,21 @@ export class ProfileFieldDialog {
save(profileField) { save(profileField) {
this.profileService.createOrUpdate(profileField).subscribe((result: any) => { this.profileService.createOrUpdate(profileField).subscribe({
this.dialogRef.close(profileField); next: (result: any) => {
}, (error) => { this.dialogRef.close(profileField);
if (error.status == 409) { },
let errors = {}; error: (error) => {
for (let code of error.error) { if (error.status == 409) {
errors[ code.field ] = errors[ code.field ] || {}; let errors = {};
errors[ code.field ][ code.code ] = true; for (let code of error.error) {
} errors[ code.field ] = errors[ code.field ] || {};
errors[ code.field ][ code.code ] = true;
}
for (let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[ code ]); this.form.get(code).setErrors(errors[ code ]);
}
} }
} }
}); });
@ -207,9 +222,11 @@ export class ProfileFieldDialog {
minWidth: '400px' minWidth: '400px'
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe({
if (result) { next: (result) => {
profileField.blob = result; if (result) {
profileField.blob = result;
}
} }
}); });

View File

@ -6,7 +6,7 @@ import { I18nService } from './../../services/i18n.service';
@Component({ @Component({
selector: 'app-html', selector: 'app-html',
templateUrl: './html.component.html', templateUrl: './html.component.html',
styleUrls: ['./html.component.scss'] styleUrls: [ './html.component.scss' ]
}) })
export class HtmlComponent implements OnInit { export class HtmlComponent implements OnInit {
@ -26,7 +26,9 @@ export class HtmlComponent implements OnInit {
{ {
headers: headers, headers: headers,
responseType: 'text' responseType: 'text'
}).subscribe(response => this.htmlTemplate = response); }).subscribe({
next: (response) => this.htmlTemplate = response
});
} }
} }