Add organisation, contactinformation, person
parent
3347f778cd
commit
28049baab6
@ -0,0 +1,45 @@
|
||||
query GetOrganisations {
|
||||
organisations {
|
||||
...OrganisationFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
query GetOrganisationById($id: ID!) {
|
||||
organisationById(id: $id) {
|
||||
...OrganisationFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
query ReloadOrganisationById($id: ID!) {
|
||||
organisationById(id: $id) {
|
||||
...OrganisationFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation CreateOrganisation($organisation: OrganisationCreateInput!) {
|
||||
createOrganisation(organisation: $organisation) {
|
||||
...OrganisationFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation UpdateOrganisation($organisation: OrganisationUpdateInput!) {
|
||||
updateOrganisation(organisation: $organisation) {
|
||||
...OrganisationFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation LockOrganisation($id: ID!) {
|
||||
lockOrganisation(id: $id) {
|
||||
...OrganisationFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation UnlockOrganisation($id: ID!) {
|
||||
unlockOrganisation(id: $id) {
|
||||
...OrganisationFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation DeleteOrganisation($id: ID!) {
|
||||
deleteOrganisation(id: $id)
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
query GetPersons {
|
||||
persons {
|
||||
...PersonFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
query GetPersonById($id: ID!) {
|
||||
personById(id: $id) {
|
||||
...PersonFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
query ReloadPersonById($id: ID!) {
|
||||
personById(id: $id) {
|
||||
...PersonFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation CreatePerson($person: PersonCreateInput!) {
|
||||
createPerson(person: $person) {
|
||||
...PersonFieldsForTable
|
||||
}
|
||||
}
|
||||
|
||||
mutation UpdatePerson($person: PersonUpdateInput!) {
|
||||
updatePerson(person: $person) {
|
||||
...PersonFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation LockPerson($id: ID!) {
|
||||
lockPerson(id: $id) {
|
||||
...PersonFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation UnlockPerson($id: ID!) {
|
||||
unlockPerson(id: $id) {
|
||||
...PersonFieldsForPage
|
||||
}
|
||||
}
|
||||
|
||||
mutation DeletePerson($id: ID!) {
|
||||
deletePerson(id: $id)
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<app-data-page
|
||||
[dataService]="dataService"
|
||||
[propertiesInfo]="propertiesInfo"
|
||||
[headlineDataPath]="headlineDataPath"
|
||||
[headlineIconName]="headlineIconName"
|
||||
[pageDataGQLType]="pageDataGQLType"
|
||||
[pageDataGQLUpdateInputType]="pageDataGQLUpdateInputType"
|
||||
(lockEvent)="lock($event)"
|
||||
(saveEvent)="save($event)"
|
||||
(cancelEvent)="cancel($event)"
|
||||
></app-data-page>
|
@ -0,0 +1,135 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ContactInformationService } from 'src/app/services/contactInformation.service';
|
||||
import { OrganisationsService } from 'src/app/services/organisation.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-organisation',
|
||||
templateUrl: './organisation.component.html',
|
||||
styleUrls: ['./organisation.component.scss'],
|
||||
})
|
||||
export class OrganisationComponent implements OnInit {
|
||||
propertiesInfo = [
|
||||
{
|
||||
type: 'Group',
|
||||
title: 'Allgemein',
|
||||
properties: [
|
||||
{ dataPath: 'name', translation: 'Name' },
|
||||
{ dataPath: 'address.number', translation: 'Hausnummer' },
|
||||
{ dataPath: 'address.street', translation: 'Straße' },
|
||||
{ dataPath: 'address.zip', translation: 'Postleitzahl' },
|
||||
|
||||
{ dataPath: 'associationNo', translation: 'Vereinsnummer' },
|
||||
{ dataPath: 'registeredAt', translation: 'Eingetragen seit' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'Group',
|
||||
title: 'Kontaktinformationen',
|
||||
possibleObjects: [],
|
||||
nameToShowInSelection: (contact) => {
|
||||
return (
|
||||
contact.person.firstName +
|
||||
' ' +
|
||||
contact.person.name +
|
||||
' ' +
|
||||
contact.email +
|
||||
' ' +
|
||||
contact.phone +
|
||||
' ' +
|
||||
contact.note
|
||||
);
|
||||
},
|
||||
propertyPrefixToOverwrite: 'contactInformation',
|
||||
currentlySelectedObjectId: (station) => {
|
||||
return station['contactInformation.id'];
|
||||
},
|
||||
propertyNameOfReferenceId: 'contactInformationId',
|
||||
properties: [
|
||||
{
|
||||
dataPath: 'contactInformation.person.firstName',
|
||||
translation: 'Vorname Ansprechpartner',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.person.name',
|
||||
translation: 'Nachname Ansprechpartner',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.phone',
|
||||
translation: 'Telefonnummer',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.phone2',
|
||||
translation: 'Telefonnummer 2',
|
||||
},
|
||||
{ dataPath: 'contactInformation.email', translation: 'Email' },
|
||||
{ dataPath: 'contactInformation.email2', translation: 'Email 2' },
|
||||
{ dataPath: 'contactInformation.note', translation: 'Anmerkung' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'ReferenceTable',
|
||||
title: 'Bereitgestellte Lastenräder',
|
||||
dataPath: 'provider.cargoBikes',
|
||||
dataService: null,
|
||||
columnInfo: [
|
||||
{
|
||||
dataPath: 'name',
|
||||
translation: 'Lastenrad',
|
||||
link: (row) => '/bike/' + row['cargoBike.id'],
|
||||
},
|
||||
],
|
||||
editableReferences: false,
|
||||
linkToTable: () => '/table/provider',
|
||||
},
|
||||
/*{
|
||||
type: 'ReferenceTable',
|
||||
title: 'Fahrräder',
|
||||
dataPath: 'contactInformation',
|
||||
dataService: null,
|
||||
columnInfo: [
|
||||
{ dataPath: 'email', translation: 'Email' },
|
||||
{ dataPath: 'email2', translation: 'Email 2' },
|
||||
{ dataPath: 'phone', translation: 'Telefonnummer' },
|
||||
{ dataPath: 'phone2', translation: 'Telefonnummer 2' },
|
||||
{ dataPath: 'note', translation: 'Anmerkung' },
|
||||
],
|
||||
editableReferences: false,
|
||||
linkToTable: () => '/table/contactInformation',
|
||||
},*/
|
||||
];
|
||||
|
||||
headlineDataPath = 'name';
|
||||
headlineIconName = 'organisation';
|
||||
pageDataGQLType: string = 'Organisation';
|
||||
pageDataGQLUpdateInputType: string = 'OrganisationUpdateInput';
|
||||
|
||||
dataService: any;
|
||||
|
||||
constructor(
|
||||
private organisationsService: OrganisationsService,
|
||||
private contactInformationService: ContactInformationService
|
||||
) {
|
||||
this.contactInformationService.loadTableData();
|
||||
this.contactInformationService.tableData.subscribe((data) => {
|
||||
this.propertiesInfo.find(
|
||||
(prop) => prop.propertyPrefixToOverwrite === 'contactInformation'
|
||||
).possibleObjects = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dataService = this.organisationsService;
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.organisationsService.lockOrganisation({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.organisationsService.updateOrganisation({ organisation: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.organisationsService.unlockOrganisation({ id: row.id });
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<app-data-page
|
||||
[dataService]="dataService"
|
||||
[propertiesInfo]="propertiesInfo"
|
||||
[headlineDataPath]="headlineDataPath"
|
||||
[headlineIconName]="headlineIconName"
|
||||
[pageDataGQLType]="pageDataGQLType"
|
||||
[pageDataGQLUpdateInputType]="pageDataGQLUpdateInputType"
|
||||
(lockEvent)="lock($event)"
|
||||
(saveEvent)="save($event)"
|
||||
(cancelEvent)="cancel($event)"
|
||||
></app-data-page>
|
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PersonComponent } from './person.component';
|
||||
|
||||
describe('PersonComponent', () => {
|
||||
let component: PersonComponent;
|
||||
let fixture: ComponentFixture<PersonComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ PersonComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PersonComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,62 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { PersonsService } from 'src/app/services/person.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person',
|
||||
templateUrl: './person.component.html',
|
||||
styleUrls: ['./person.component.scss']
|
||||
})
|
||||
export class PersonComponent implements OnInit {
|
||||
propertiesInfo = [
|
||||
{
|
||||
type: 'Group',
|
||||
title: 'Allgemein',
|
||||
properties: [
|
||||
{ dataPath: 'firstName', translation: 'Vorname' },
|
||||
{ dataPath: 'name', translation: 'Nachname' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'ReferenceTable',
|
||||
title: 'KontaktInformationen',
|
||||
dataPath: 'contactInformation',
|
||||
dataService: null,
|
||||
columnInfo: [
|
||||
{ dataPath: 'email', translation: 'Email' },
|
||||
{ dataPath: 'email2', translation: 'Email 2' },
|
||||
{ dataPath: 'phone', translation: 'Telefonnummer' },
|
||||
{ dataPath: 'phone2', translation: 'Telefonnummer 2' },
|
||||
{ dataPath: 'note', translation: 'Anmerkung' },
|
||||
],
|
||||
editableReferences: false,
|
||||
linkToTable: () => '/table/contactInformation',
|
||||
},
|
||||
];
|
||||
|
||||
headlineDataPath = 'name';
|
||||
headlineIconName = 'person';
|
||||
pageDataGQLType: string = 'Person';
|
||||
pageDataGQLUpdateInputType: string = 'PersonUpdateInput';
|
||||
|
||||
dataService: any;
|
||||
|
||||
constructor(
|
||||
private personsService: PersonsService,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dataService = this.personsService;
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.personsService.lockPerson({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.personsService.updatePerson({ person: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.personsService.unlockPerson({ id: row.id });
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<p>provider works!</p>
|
@ -0,0 +1,25 @@
|
||||
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();
|
||||
});
|
||||
});
|
@ -0,0 +1,15 @@
|
||||
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,90 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ContactInformationService } from 'src/app/services/contactInformation.service';
|
||||
import { PersonsService } from 'src/app/services/person.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contact-information',
|
||||
templateUrl: './contact-information.component.html',
|
||||
styleUrls: ['./contact-information.component.scss'],
|
||||
})
|
||||
export class ContactInformationComponent implements OnInit {
|
||||
columnInfo = [
|
||||
{
|
||||
dataPath: 'person.firstName',
|
||||
translation: 'Vorname',
|
||||
sticky: true,
|
||||
link: (row: any) => {
|
||||
return '/person/' + row['person.id'];
|
||||
},
|
||||
},
|
||||
{
|
||||
dataPath: 'person.name',
|
||||
translation: 'Nachname',
|
||||
sticky: true,
|
||||
link: (row: any) => {
|
||||
return '/person/' + row['person.id'];
|
||||
},
|
||||
possibleObjects: [],
|
||||
nameToShowInSelection: (person) => person.firstName + ' ' + person.name,
|
||||
propertyPrefixToOverwrite: 'person',
|
||||
currentlySelectedObjectId: (timeFrame) => {
|
||||
return timeFrame['cargoBike.id'];
|
||||
},
|
||||
propertyNameOfReferenceId: 'personId',
|
||||
},
|
||||
{ dataPath: 'email', translation: 'Email' },
|
||||
{ dataPath: 'email2', translation: 'Email 2' },
|
||||
{ dataPath: 'phone', translation: 'Telefonnummer' },
|
||||
{ dataPath: 'phone2', translation: 'Telefonnummer 2' },
|
||||
{ dataPath: 'note', translation: 'Anmerkung' },
|
||||
];
|
||||
dataService: any;
|
||||
|
||||
tableDataGQLType: string = 'ContactInformation';
|
||||
tableDataGQLCreateInputType: string = 'ContactInformationCreateInput';
|
||||
tableDataGQLUpdateInputType: string = 'ContactInformationUpdateInput';
|
||||
|
||||
headline = 'Kontaktinformationen';
|
||||
headlineIconName = 'contact_page';
|
||||
|
||||
loadingRowIds: string[] = [];
|
||||
constructor(
|
||||
private contactInformationService: ContactInformationService,
|
||||
private personsService: PersonsService
|
||||
) {
|
||||
this.personsService.loadTableData();
|
||||
this.personsService.tableData.subscribe((data) => {
|
||||
this.columnInfo.find(
|
||||
(column) => column.dataPath === 'person.name'
|
||||
).possibleObjects = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataService = this.contactInformationService;
|
||||
}
|
||||
|
||||
create(object: { currentId: string; row: any }) {
|
||||
this.contactInformationService.createContactInformation(object.currentId, {
|
||||
contactInformation: object.row,
|
||||
});
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.contactInformationService.lockContactInformation({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.contactInformationService.updateContactInformation({
|
||||
contactInformation: row,
|
||||
});
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.contactInformationService.unlockContactInformation({ id: row.id });
|
||||
}
|
||||
|
||||
delete(row: any) {
|
||||
this.contactInformationService.deleteContactInformation({ id: row.id });
|
||||
}
|
||||
}
|
@ -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,83 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { OrganisationsService } from 'src/app/services/organisation.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-organisations',
|
||||
templateUrl: './organisations.component.html',
|
||||
styleUrls: ['./organisations.component.scss'],
|
||||
})
|
||||
export class OrganisationsComponent implements OnInit {
|
||||
columnInfo = [
|
||||
{
|
||||
dataPath: 'name',
|
||||
translation: 'Name',
|
||||
sticky: true,
|
||||
link: (row: any) => {
|
||||
return '/organisation/' + row.id;
|
||||
},
|
||||
},
|
||||
{ dataPath: 'address.number', translation: 'Hausnummer' },
|
||||
{ dataPath: 'address.street', translation: 'Straße' },
|
||||
{ dataPath: 'address.zip', translation: 'Postleitzahl' },
|
||||
|
||||
{ dataPath: 'associationNo', translation: 'Vereinsnummer' },
|
||||
{ dataPath: 'registeredAt', translation: 'Eingetragen seit' },
|
||||
|
||||
{
|
||||
dataPath: 'contactInformation.person.firstName',
|
||||
translation: 'Vorname Ansprechpartner',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.person.name',
|
||||
translation: 'Nachname Ansprechpartner',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.phone',
|
||||
translation: 'Telefonnummer',
|
||||
},
|
||||
{
|
||||
dataPath: 'contactInformation.phone2',
|
||||
translation: 'Telefonnummer 2',
|
||||
},
|
||||
{ dataPath: 'contactInformation.email', translation: 'Email' },
|
||||
{ dataPath: 'contactInformation.email2', translation: 'Email 2' },
|
||||
];
|
||||
|
||||
dataService: any;
|
||||
|
||||
tableDataGQLType: string = 'Organisation';
|
||||
tableDataGQLCreateInputType: string = 'OrganisationCreateInput';
|
||||
tableDataGQLUpdateInputType: string = 'OrganisationUpdateInput';
|
||||
|
||||
headline = 'Unternehmen';
|
||||
headlineIconName = 'business';
|
||||
|
||||
loadingRowIds: string[] = [];
|
||||
constructor(private organisationsService: OrganisationsService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataService = this.organisationsService;
|
||||
}
|
||||
|
||||
create(object: { currentId: string; row: any }) {
|
||||
this.organisationsService.createOrganisation(object.currentId, {
|
||||
organisation: object.row,
|
||||
});
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.organisationsService.lockOrganisation({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.organisationsService.updateOrganisation({ organisation: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.organisationsService.unlockOrganisation({ id: row.id });
|
||||
}
|
||||
|
||||
delete(row: any) {
|
||||
this.organisationsService.deleteOrganisation({ id: row.id });
|
||||
}
|
||||
}
|
@ -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,65 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { PersonsService } from 'src/app/services/person.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-persons',
|
||||
templateUrl: './persons.component.html',
|
||||
styleUrls: ['./persons.component.scss'],
|
||||
})
|
||||
export class PersonsComponent implements OnInit {
|
||||
columnInfo = [
|
||||
{
|
||||
dataPath: 'firstName',
|
||||
translation: 'Vorname',
|
||||
sticky: true,
|
||||
link: (row: any) => {
|
||||
return '/person/' + row.id;
|
||||
},
|
||||
},
|
||||
{
|
||||
dataPath: 'name',
|
||||
translation: 'Nachname',
|
||||
link: (row: any) => {
|
||||
return '/person/' + row.id;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
dataService: any;
|
||||
|
||||
tableDataGQLType: string = 'Person';
|
||||
tableDataGQLCreateInputType: string = 'PersonCreateInput';
|
||||
tableDataGQLUpdateInputType: string = 'PersonUpdateInput';
|
||||
|
||||
headline = 'Personen';
|
||||
headlineIconName = 'person';
|
||||
|
||||
loadingRowIds: string[] = [];
|
||||
constructor(private personsService: PersonsService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataService = this.personsService;
|
||||
}
|
||||
|
||||
create(object: { currentId: string; row: any }) {
|
||||
this.personsService.createPerson(object.currentId, {
|
||||
person: object.row,
|
||||
});
|
||||
}
|
||||
|
||||
lock(row: any) {
|
||||
this.personsService.lockPerson({ id: row.id });
|
||||
}
|
||||
|
||||
save(row: any) {
|
||||
this.personsService.updatePerson({ person: row });
|
||||
}
|
||||
|
||||
cancel(row: any) {
|
||||
this.personsService.unlockPerson({ id: row.id });
|
||||
}
|
||||
|
||||
delete(row: any) {
|
||||
this.personsService.deletePerson({ id: row.id });
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<p>provider works!</p>
|
@ -0,0 +1,25 @@
|
||||
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();
|
||||
});
|
||||
});
|
@ -0,0 +1,15 @@
|
||||
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,160 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import {
|
||||
GetOrganisationsGQL,
|
||||
ReloadOrganisationByIdGQL,
|
||||
ReloadOrganisationByIdQueryVariables,
|
||||
UpdateOrganisationGQL,
|
||||
UpdateOrganisationMutationVariables,
|
||||
LockOrganisationGQL,
|
||||
LockOrganisationMutationVariables,
|
||||
UnlockOrganisationGQL,
|
||||
UnlockOrganisationMutationVariables,
|
||||
CreateOrganisationGQL,
|
||||
CreateOrganisationMutationVariables,
|
||||
DeleteOrganisationGQL,
|
||||
DeleteOrganisationMutationVariables,
|
||||
GetOrganisationByIdGQL,
|
||||
GetOrganisationByIdQueryVariables,
|
||||
} from '../../generated/graphql';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OrganisationsService {
|
||||
/** Organisations 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 getOrganisationsGQL: GetOrganisationsGQL,
|
||||
private getOrganisationByIdGQL: GetOrganisationByIdGQL,
|
||||
private reloadOrganisationByIdGQL: ReloadOrganisationByIdGQL,
|
||||
private updateOrganisationGQL: UpdateOrganisationGQL,
|
||||
private lockOrganisationGQL: LockOrganisationGQL,
|
||||
private unlockOrganisationGQL: UnlockOrganisationGQL,
|
||||
private createOrganisationGQL: CreateOrganisationGQL,
|
||||
private deleteOrganisationGQL: DeleteOrganisationGQL
|
||||
) {}
|
||||
|
||||
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.getOrganisationsGQL.fetch().subscribe((result) => {
|
||||
this.tableData.next(result.data?.organisations);
|
||||
});
|
||||
}
|
||||
|
||||
loadPageData(variables: GetOrganisationByIdQueryVariables) {
|
||||
this.pageData.next(null);
|
||||
this.isLoadingPageData.next(true);
|
||||
this.getOrganisationByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.pageData.next(result.data.organisationById);
|
||||
})
|
||||
.add(() => {
|
||||
this.isLoadingPageData.next(false);
|
||||
});
|
||||
}
|
||||
|
||||
reloadOrganisation(variables: ReloadOrganisationByIdQueryVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.reloadOrganisationByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.organisationById);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
createOrganisation(currentId: string, variables: CreateOrganisationMutationVariables) {
|
||||
this.createOrganisationGQL.mutate(variables).subscribe((result) => {
|
||||
const newOrganisation = result.data.createOrganisation;
|
||||
this.tableData.next([newOrganisation, ...this.tableData.value]);
|
||||
this.successfullyCreatedRowWithId.next(currentId);
|
||||
});
|
||||
}
|
||||
|
||||
updateOrganisation(variables: UpdateOrganisationMutationVariables) {
|
||||
this.addLoadingRowId(variables.organisation.id);
|
||||
this.updateOrganisationGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.updateOrganisation);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.organisation.id);
|
||||
});
|
||||
}
|
||||
|
||||
lockOrganisation(variables: LockOrganisationMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.lockOrganisationGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.lockOrganisation);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
unlockOrganisation(variables: UnlockOrganisationMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.unlockOrganisationGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.unlockOrganisation);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
deleteOrganisation(variables: DeleteOrganisationMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.deleteOrganisationGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
if (result.data) {
|
||||
this.tableData.next(
|
||||
[...this.tableData.value].filter((organisation) => organisation.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,160 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import {
|
||||
GetPersonsGQL,
|
||||
ReloadPersonByIdGQL,
|
||||
ReloadPersonByIdQueryVariables,
|
||||
UpdatePersonGQL,
|
||||
UpdatePersonMutationVariables,
|
||||
LockPersonGQL,
|
||||
LockPersonMutationVariables,
|
||||
UnlockPersonGQL,
|
||||
UnlockPersonMutationVariables,
|
||||
CreatePersonGQL,
|
||||
CreatePersonMutationVariables,
|
||||
DeletePersonGQL,
|
||||
DeletePersonMutationVariables,
|
||||
GetPersonByIdGQL,
|
||||
GetPersonByIdQueryVariables,
|
||||
} from '../../generated/graphql';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PersonsService {
|
||||
/** Persons 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 getPersonsGQL: GetPersonsGQL,
|
||||
private getPersonByIdGQL: GetPersonByIdGQL,
|
||||
private reloadPersonByIdGQL: ReloadPersonByIdGQL,
|
||||
private updatePersonGQL: UpdatePersonGQL,
|
||||
private lockPersonGQL: LockPersonGQL,
|
||||
private unlockPersonGQL: UnlockPersonGQL,
|
||||
private createPersonGQL: CreatePersonGQL,
|
||||
private deletePersonGQL: DeletePersonGQL
|
||||
) {}
|
||||
|
||||
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.getPersonsGQL.fetch().subscribe((result) => {
|
||||
this.tableData.next(result.data?.persons);
|
||||
});
|
||||
}
|
||||
|
||||
loadPageData(variables: GetPersonByIdQueryVariables) {
|
||||
this.pageData.next(null);
|
||||
this.isLoadingPageData.next(true);
|
||||
this.getPersonByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.pageData.next(result.data.personById);
|
||||
})
|
||||
.add(() => {
|
||||
this.isLoadingPageData.next(false);
|
||||
});
|
||||
}
|
||||
|
||||
reloadPerson(variables: ReloadPersonByIdQueryVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.reloadPersonByIdGQL
|
||||
.fetch(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.personById);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
createPerson(currentId: string, variables: CreatePersonMutationVariables) {
|
||||
this.createPersonGQL.mutate(variables).subscribe((result) => {
|
||||
const newPerson = result.data.createPerson;
|
||||
this.tableData.next([newPerson, ...this.tableData.value]);
|
||||
this.successfullyCreatedRowWithId.next(currentId);
|
||||
});
|
||||
}
|
||||
|
||||
updatePerson(variables: UpdatePersonMutationVariables) {
|
||||
this.addLoadingRowId(variables.person.id);
|
||||
this.updatePersonGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.updatePerson);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.person.id);
|
||||
});
|
||||
}
|
||||
|
||||
lockPerson(variables: LockPersonMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.lockPersonGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.lockPerson);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
unlockPerson(variables: UnlockPersonMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.unlockPersonGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
this.updateDataRowFromResponse(result.data.unlockPerson);
|
||||
})
|
||||
.add(() => {
|
||||
this.removeLoadingRowId(variables.id);
|
||||
});
|
||||
}
|
||||
|
||||
deletePerson(variables: DeletePersonMutationVariables) {
|
||||
this.addLoadingRowId(variables.id);
|
||||
this.deletePersonGQL
|
||||
.mutate(variables)
|
||||
.subscribe((result) => {
|
||||
if (result.data) {
|
||||
this.tableData.next(
|
||||
[...this.tableData.value].filter((person) => person.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