Add provider
parent
073de444db
commit
8cec05431d
@ -0,0 +1,45 @@
|
||||
query GetProviders {
|
||||
providers {
|
||||
...ProviderFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
query GetProviderById($id: ID!) {
|
||||
providerById(id: $id) {
|
||||
...ProviderFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
query ReloadProviderById($id: ID!) {
|
||||
providerById(id: $id) {
|
||||
...ProviderFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation CreateProvider($provider: ProviderCreateInput!) {
|
||||
createProvider(provider: $provider) {
|
||||
...ProviderFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation UpdateProvider($provider: ProviderUpdateInput!) {
|
||||
updateProvider(provider: $provider) {
|
||||
...ProviderFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation LockProvider($id: ID!) {
|
||||
lockProvider(id: $id) {
|
||||
...ProviderFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation UnlockProvider($id: ID!) {
|
||||
unlockProvider(id: $id) {
|
||||
...ProviderFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation DeleteProvider($id: ID!) {
|
||||
deleteProvider(id: $id)
|
||||
}
|
@ -1 +1,12 @@
|
||||
<p>provider works!</p>
|
||||
<app-data-page
|
||||
[dataService]="dataService"
|
||||
[propertiesInfo]="propertiesInfo"
|
||||
[headlineDataPath]="headlineDataPath"
|
||||
[getHeadline]="getHeadline"
|
||||
[headlineIconName]="headlineIconName"
|
||||
[pageDataGQLType]="pageDataGQLType"
|
||||
[pageDataGQLUpdateInputType]="pageDataGQLUpdateInputType"
|
||||
(lockEvent)="lock($event)"
|
||||
(saveEvent)="save($event)"
|
||||
(cancelEvent)="cancel($event)"
|
||||
></app-data-page>
|
||||
|
@ -1,25 +0,0 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProviderComponent } from './provider.component';
|
||||
|
||||
describe('ProviderComponent', () => {
|
||||
let component: ProviderComponent;
|
||||
let fixture: ComponentFixture<ProviderComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ProviderComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProviderComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,15 +1,123 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { bindNodeCallback } from 'rxjs';
|
||||
import { BikesService } from 'src/app/services/bikes.service';
|
||||
import { OrganisationsService } from 'src/app/services/organisation.service';
|
||||
import { PersonsService } from 'src/app/services/person.service';
|
||||
import { ProvidersService } from 'src/app/services/provider.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-provider',
|
||||
templateUrl: './provider.component.html',
|
||||
styleUrls: ['./provider.component.scss']
|
||||
styleUrls: ['./provider.component.scss'],
|
||||
})
|
||||
export class ProviderComponent implements OnInit {
|
||||
propertiesInfo = [
|
||||
{
|
||||
type: 'Group',
|
||||
title: 'Allgemein',
|
||||
hideCondition: (data) => data.privatePerson === null,
|
||||
properties: [
|
||||
{
|
||||
type: 'Link',
|
||||
linkText: "Zur Person",
|
||||
link: (data) => {
|
||||
return '/person/' + data['privatePerson.person.id'];
|
||||
},
|
||||
},
|
||||
{ dataPath: 'privatePerson.person.firstName', translation: 'Vorname' },
|
||||
{
|
||||
dataPath: 'privatePerson.person.name',
|
||||
translation: 'Nachname',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.phone',
|
||||
translation: 'Telefonnummer',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.phone2',
|
||||
translation: 'Telefonnummer 2',
|
||||
},
|
||||
{ dataPath: 'privatePerson.email', translation: 'Email' },
|
||||
{ dataPath: 'privatePerson.email2', translation: 'Email 2' },
|
||||
{ dataPath: 'privatePerson.note', translation: 'Anmerkung' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'Group',
|
||||
title: 'Allgemein',
|
||||
hideCondition: (data) => data.organisation === null,
|
||||
properties: [
|
||||
{
|
||||
type: 'Link',
|
||||
linkText: "Zum Unternehmen",
|
||||
link: (data) => {
|
||||
return '/organisation/' + data['organisation.id'];
|
||||
},
|
||||
},
|
||||
{ dataPath: 'organisation.name', translation: 'Name' },
|
||||
{ dataPath: 'organisation.address.street', translation: 'Straße' },
|
||||
{ dataPath: 'organisation.address.number', translation: 'Hausnummer' },
|
||||
{ dataPath: 'organisation.address.zip', translation: 'Postleitzahl' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'ReferenceTable',
|
||||
title: 'Bereitgestellte Lastenräder',
|
||||
dataPath: 'cargoBikes',
|
||||
dataService: null,
|
||||
columnInfo: [
|
||||
{
|
||||
dataPath: 'name',
|
||||
translation: 'Name',
|
||||
link: (row) => '/bike/' + row.id,
|
||||
},
|
||||
],
|
||||
nameToShowInSelection: (bike) => {
|
||||
return bike.name;
|
||||
},
|
||||
linkToTable: (element) => '/table/bikes',
|
||||
propertyNameOfUpdateInput: 'cargoBikeIds',
|
||||
},
|
||||
];
|
||||
|
||||
constructor() { }
|
||||
getHeadline = (pageData) => {
|
||||
return (
|
||||
(pageData['privatePerson.person.firstName']
|
||||
? pageData['privatePerson.person.firstName'] +
|
||||
' ' +
|
||||
pageData['privatePerson.person.name']
|
||||
: pageData['organisation.name']) + ' (Anbieter)'
|
||||
);
|
||||
};
|
||||
headlineDataPath = '';
|
||||
headlineIconName = 'person';
|
||||
pageDataGQLType: string = 'Provider';
|
||||
pageDataGQLUpdateInputType: string = 'ProviderUpdateInput';
|
||||
|
||||
dataService: any;
|
||||
|
||||
constructor(
|
||||
private providersService: ProvidersService,
|
||||
private bikesService: BikesService
|
||||
) {
|
||||
this.propertiesInfo.find(
|
||||
(prop) => prop.dataPath === 'cargoBikes'
|
||||
).dataService = this.bikesService;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dataService = this.providersService;
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.providersService.lockProvider({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.providersService.updateProvider({ provider: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.providersService.unlockProvider({ id: row.id });
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<p>provider works!</p>
|
@ -1,25 +0,0 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProviderComponent } from './provider.component';
|
||||
|
||||
describe('ProviderComponent', () => {
|
||||
let component: ProviderComponent;
|
||||
let fixture: ComponentFixture<ProviderComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ProviderComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProviderComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,15 +0,0 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-provider',
|
||||
templateUrl: './provider.component.html',
|
||||
styleUrls: ['./provider.component.scss']
|
||||
})
|
||||
export class ProviderComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<app-table
|
||||
[headline]="headline"
|
||||
[headlineIconName]="headlineIconName"
|
||||
[columnInfo]="columnInfo"
|
||||
[dataService]="dataService"
|
||||
[tableDataGQLType]="tableDataGQLType"
|
||||
[tableDataGQLCreateInputType]="tableDataGQLCreateInputType"
|
||||
[tableDataGQLUpdateInputType]="tableDataGQLUpdateInputType"
|
||||
(createEvent)="create($event)"
|
||||
(lockEvent)="lock($event)"
|
||||
(saveEvent)="save($event)"
|
||||
(cancelEvent)="cancel($event)"
|
||||
(deleteEvent)="delete($event)"
|
||||
></app-table>
|
@ -0,0 +1,131 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ContactInformationService } from 'src/app/services/contactInformation.service';
|
||||
import { OrganisationsService } from 'src/app/services/organisation.service';
|
||||
import { PersonsService } from 'src/app/services/person.service';
|
||||
import { ProvidersService } from 'src/app/services/provider.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-providers',
|
||||
templateUrl: './providers.component.html',
|
||||
styleUrls: ['./providers.component.scss'],
|
||||
})
|
||||
export class ProvidersComponent implements OnInit {
|
||||
columnInfo = [
|
||||
{
|
||||
dataPath: 'formName',
|
||||
translation: 'Formular Name',
|
||||
},
|
||||
{
|
||||
dataPath: 'organisation.name',
|
||||
translation: 'Anbieter (Unternehmen)',
|
||||
link: (row: any) => {
|
||||
return '/provider/' + row['id'];
|
||||
},
|
||||
possibleObjects: [],
|
||||
nameToShowInSelection: (o) => o.name,
|
||||
propertyPrefixToOverwrite: 'organisation',
|
||||
currentlySelectedObjectId: (provider) => {
|
||||
return provider['organisation.id'];
|
||||
},
|
||||
propertyNameOfReferenceId: 'organisationId',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.person.firstName',
|
||||
translation: 'Anbieter (Person) Vorname',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.person.name',
|
||||
translation: 'Anbieter (Person) Nachname',
|
||||
link: (row: any) => {
|
||||
return '/provider/' + row['id'];
|
||||
},
|
||||
possibleObjects: [],
|
||||
nameToShowInSelection: (contact) => {
|
||||
return (
|
||||
(contact.person.firstName || '') +
|
||||
' ' +
|
||||
(contact.person.name || '') +
|
||||
' ' +
|
||||
(contact.email || '') +
|
||||
' ' +
|
||||
(contact.phone || '') +
|
||||
' ' +
|
||||
(contact.note || '')
|
||||
);
|
||||
},
|
||||
propertyPrefixToOverwrite: 'privatePerson',
|
||||
currentlySelectedObjectId: (provider) => {
|
||||
return provider['privatePerson.id'];
|
||||
},
|
||||
propertyNameOfReferenceId: 'privatePersonId',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.email',
|
||||
translation: 'Anbieter (Person) Email',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.phone',
|
||||
translation: 'Anbieter (Person) Telefonnummer',
|
||||
},
|
||||
{
|
||||
dataPath: 'privatePerson.note',
|
||||
translation: 'Anbieter (Person) Anmerkung',
|
||||
},
|
||||
];
|
||||
|
||||
dataService: any;
|
||||
|
||||
tableDataGQLType: string = 'Provider';
|
||||
tableDataGQLCreateInputType: string = 'ProviderCreateInput';
|
||||
tableDataGQLUpdateInputType: string = 'ProviderUpdateInput';
|
||||
|
||||
headline = 'Anbieter';
|
||||
headlineIconName = 'people';
|
||||
|
||||
loadingRowIds: string[] = [];
|
||||
constructor(
|
||||
private providersService: ProvidersService,
|
||||
private contactInformationService: ContactInformationService,
|
||||
private organisationsService: OrganisationsService
|
||||
) {
|
||||
this.organisationsService.loadTableData();
|
||||
this.organisationsService.tableData.subscribe((data) => {
|
||||
this.columnInfo.find(
|
||||
(column) => column.propertyPrefixToOverwrite === 'organisation'
|
||||
).possibleObjects = data;
|
||||
});
|
||||
|
||||
this.contactInformationService.loadTableData();
|
||||
this.contactInformationService.tableData.subscribe((data) => {
|
||||
this.columnInfo.find(
|
||||
(column) => column.propertyPrefixToOverwrite === 'privatePerson'
|
||||
).possibleObjects = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataService = this.providersService;
|
||||
}
|
||||
|
||||
create(object: { currentId: string; row: any }) {
|
||||
this.providersService.createProvider(object.currentId, {
|
||||
provider: object.row,
|
||||
});
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.providersService.lockProvider({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.providersService.updateProvider({ provider: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.providersService.unlockProvider({ id: row.id });
|
||||
}
|
||||
|
||||
delete(row: any) {
|
||||
this.providersService.deleteProvider({ id: row.id });
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import {
|
||||
GetProvidersGQL,
|
||||
ReloadProviderByIdGQL,
|
||||
ReloadProviderByIdQueryVariables,
|
||||
UpdateProviderGQL,
|
||||
UpdateProviderMutationVariables,
|
||||
LockProviderGQL,
|
||||
LockProviderMutationVariables,
|
||||
UnlockProviderGQL,
|
||||
UnlockProviderMutationVariables,
|
||||
CreateProviderGQL,
|
||||
CreateProviderMutationVariables,
|
||||
DeleteProviderGQL,
|
||||
DeleteProviderMutationVariables,
|
||||
GetProviderByIdGQL,
|
||||
GetProviderByIdQueryVariables,
|
||||
} from '../../generated/graphql';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProvidersService {
|
||||
/** Providers Array */
|
||||
tableData: BehaviorSubject<any[]> = new BehaviorSubject(null);
|
||||
loadingRowIds: BehaviorSubject<string[]> = new BehaviorSubject([]);
|
||||
successfullyCreatedRowWithId: Subject<string> = new Subject();
|
||||
pageData: BehaviorSubject<any> = new BehaviorSubject(null);
|
||||
isLoadingPageData: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||
|
||||
constructor(
|
||||
private getProvidersGQL: GetProvidersGQL,
|
||||
private getProviderByIdGQL: GetProviderByIdGQL,
|
||||
private reloadProviderByIdGQL: ReloadProviderByIdGQL,
|
||||
private updateProviderGQL: UpdateProviderGQL,
|
||||
private lockProviderGQL: LockProviderGQL,
|
||||
private unlockProviderGQL: UnlockProviderGQL,
|
||||
private createProviderGQL: CreateProviderGQL,
|
||||
private deleteProviderGQL: DeleteProviderGQL
|
||||
) {}
|
||||
|
||||
addLoadingRowId(id: string) {
|
||||
this.loadingRowIds.next([...this.loadingRowIds.value, id]);
|
||||
}
|
||||
|
||||
removeLoadingRowId(id: string) {
|
||||
this.loadingRowIds.value.forEach((item, index) => {
|
||||
if (item === id) {
|
||||
this.loadingRowIds.value.splice(index, 1);
|
||||
}
|
||||
});
|
||||
this.loadingRowIds.next(this.loadingRowIds.value);
|
||||
}
|
||||
|
||||
loadTableData() {
|
||||
this.tableData.next(null);
|
||||
this.getProvidersGQL.fetch().subscribe((result) => {
|
||||
this.tableData.next(result.data?.providers);
|
||||
});
|
||||
}
|
||||
|
||||
loadPageData(variables: GetProviderByIdQueryVariables) {
|
||||
this.pageData.next(null);
|
||||
this.isLoadingPageData.next(true);
|
||||
this.getProviderByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.pageData.next(result.data.providerById);
|
||||
})
|
||||
.add(() => {
|
||||
this.isLoadingPageData.next(false);
|
||||
});
|
||||
}
|
||||
|
||||
reloadProvider(variables: ReloadProviderByIdQueryVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.reloadProviderByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.providerById);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
createProvider(currentId: string, variables: CreateProviderMutationVariables) {
|
||||
this.createProviderGQL.mutate(variables).subscribe((result) => {
|
||||
const newProvider = result.data.createProvider;
|
||||
this.tableData.next([newProvider, ...this.tableData.value]);
|
||||
this.successfullyCreatedRowWithId.next(currentId);
|
||||
});
|
||||
}
|
||||
|
||||
updateProvider(variables: UpdateProviderMutationVariables) {
|
||||
this.addLoadingRowId(variables.provider.id);
|
||||
this.updateProviderGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.updateProvider);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.provider.id);
|
||||
});
|
||||
}
|
||||
|
||||
lockProvider(variables: LockProviderMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.lockProviderGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.lockProvider);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
unlockProvider(variables: UnlockProviderMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.unlockProviderGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.unlockProvider);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
deleteProvider(variables: DeleteProviderMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.deleteProviderGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
if (result.data) {
|
||||
this.tableData.next(
|
||||
[...this.tableData.value].filter((provider) => provider.id !== variables.id)
|
||||
);
|
||||
}
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
private updateDataRowFromResponse(rowFromResponse: any) {
|
||||
if (this.tableData.value) {
|
||||
const newTableData = this.tableData.value.map((row) =>
|
||||
rowFromResponse.id === row.id ? rowFromResponse : row
|
||||
);
|
||||
this.tableData.next(newTableData);
|
||||
}
|
||||
if (rowFromResponse.id === this.pageData?.value?.id) {
|
||||
this.pageData.next(rowFromResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue