fix
This commit is contained in:
@@ -18,6 +18,9 @@ export class ApiRoutes {
|
||||
static SettingsAccountAccesses = '/api/settings/accounts/:id/access';
|
||||
static SettingsAccountAccess = '/api/settings/accounts/:id/access/:access';
|
||||
static SettingsAccountAccountCategory = '/api/settings/accounts/:id/category/:categoryId';
|
||||
static SettingsAccountInvites = '/api/settings/accounts/invites';
|
||||
static SettingsAccountInviteAccept = '/api/settings/accounts/invites/:id/accept';
|
||||
static SettingsAccountInviteReject = '/api/settings/accounts/invites/:id/reject';
|
||||
|
||||
static SettingsItemCategories = '/api/settings/item-categories';
|
||||
static SettingsItemCategory = '/api/settings/item-categories/:id';
|
||||
|
||||
@@ -24,8 +24,12 @@ export class ErrorInterceptor implements HttpInterceptor {
|
||||
this.authenticationService.logout();
|
||||
location.reload();
|
||||
}
|
||||
console.log(err);
|
||||
const error = err.message || err.error.message || err.statusText;
|
||||
let error = err.message || err.statusText;
|
||||
error = !err.error ? error : err.error.message || err.error.title;
|
||||
|
||||
if (!error) {
|
||||
console.log('not parsed error', err);
|
||||
}
|
||||
return throwError(error);
|
||||
//return throwError(err.error || err);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface AccountInviteModel {
|
||||
id?: string,
|
||||
account?: string,
|
||||
allowWrite: boolean,
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { NgxCurrencyModule } from "ngx-currency";
|
||||
import { MatExpansionModule } from '@angular/material/expansion';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
|
||||
// app
|
||||
import { PagesRoutingModule } from './pages-routing.module';
|
||||
@@ -88,6 +89,7 @@ import { SettingsItemCategoryEditComponent } from './settings/item/edit.item.cat
|
||||
NgxMaskModule,
|
||||
NgxCurrencyModule,
|
||||
MatCheckboxModule,
|
||||
MatMenuModule,
|
||||
],
|
||||
providers: [
|
||||
{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
|
||||
|
||||
@@ -17,13 +17,19 @@
|
||||
</mat-card-subtitle>
|
||||
</mat-card-title-group>
|
||||
<div fxFlex></div>
|
||||
<div *ngIf="invites && invites.length > 0" class="m-r-10">
|
||||
<button mat-raised-button color="warn" [matMenuTriggerFor]="menu">Invites</button>
|
||||
<mat-menu #menu="matMenu">
|
||||
<button *ngFor="let invite of invites" mat-menu-item (click)="startInvite(invite)">{{invite.account}}</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<button class="btn-space " (click)="add()" mat-raised-button color="primary">
|
||||
Add
|
||||
</button>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div class="body table-responsive">
|
||||
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="start">
|
||||
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="start" [(selectedIndex)]="tabIndex">
|
||||
<mat-tab *ngFor="let category of accountCategories" label="{{category.name}}">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { ApiRoutes } from '../../../api-routes';
|
||||
import { AccountModel } from '../../../model/account.model';
|
||||
import { AccountCategoryModel } from '../../../model/account.category.model';
|
||||
import { AccountInviteModel } from '../../../model/account.invite.model';
|
||||
import { SettingsAccountAddComponent } from './add.account.component';
|
||||
import { SettingsAccountEditComponent } from './edit.account.component';
|
||||
import { SettingsAccountAccessComponent } from './access.account.component';
|
||||
@@ -22,6 +23,8 @@ import { AccountCategoryService } from '../../../services/account.category.servi
|
||||
export class SettingsAccountComponent {
|
||||
public accountCategories?: AccountCategoryModel[];
|
||||
public accounts?: AccountModel[];
|
||||
public invites?: AccountInviteModel[];
|
||||
public tabIndex = 0;
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
@@ -32,13 +35,35 @@ export class SettingsAccountComponent {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadCategories();
|
||||
this.loadInvites();
|
||||
}
|
||||
|
||||
private loadAccounts() {
|
||||
private loadAccounts(accountToShow?: string) {
|
||||
this.httpClient
|
||||
.get<AccountModel[]>(ApiRoutes.SettingsAccounts)
|
||||
.subscribe(data => {
|
||||
this.accounts = data;
|
||||
if (accountToShow) {
|
||||
var idx = -1;
|
||||
var account = this.accounts.find(x => x.id === accountToShow);
|
||||
if (account && account.categories && account.categories.length > 0) {
|
||||
for (var i = 0; i < this.accountCategories!.length; i++) {
|
||||
if (account!.categories!.find(c => c.id === this.accountCategories![i].id)) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tabIndex = idx === -1 ? this.accountCategories!.length : idx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadInvites() {
|
||||
return this.httpClient
|
||||
.get<AccountInviteModel[]>(ApiRoutes.SettingsAccountInvites)
|
||||
.subscribe(response => {
|
||||
this.invites = response;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,6 +143,57 @@ export class SettingsAccountComponent {
|
||||
this.loadAccounts();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public startInvite(invite: AccountInviteModel) {
|
||||
Swal.fire({
|
||||
title: 'Accept to invite the account "' + invite.account + '"',
|
||||
input: 'text',
|
||||
inputLabel: 'Accept with name',
|
||||
inputValue: invite.account,
|
||||
showDenyButton: true,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Accept',
|
||||
denyButtonText: 'Reject',
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (input) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.post(ApiRoutes.SettingsAccountInviteAccept.replace(':id', invite.id!), { name: input })
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
Swal.showValidationMessage(error);
|
||||
reject();
|
||||
});
|
||||
|
||||
}).catch(x => {
|
||||
return false;
|
||||
});
|
||||
},
|
||||
preDeny: (x) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.httpClient.post(ApiRoutes.SettingsAccountInviteReject.replace(':id', invite.id!), null)
|
||||
.subscribe(data => {
|
||||
resolve(data);
|
||||
}, error => {
|
||||
Swal.showValidationMessage(error.detail);
|
||||
reject();
|
||||
});
|
||||
|
||||
}).catch(x => {
|
||||
return false;
|
||||
});
|
||||
},
|
||||
allowOutsideClick: () => !Swal.isLoading(),
|
||||
}).then((result) => {
|
||||
var id;
|
||||
if (result.value) {
|
||||
var account = result.value as AccountModel;
|
||||
id = account.id;
|
||||
}
|
||||
this.loadInvites();
|
||||
this.loadAccounts(id);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user