|
|
@ -33,8 +33,7 @@ export class BikesService {
|
|
|
|
tableData: BehaviorSubject<CargoBikeResult[]> = new BehaviorSubject([]);
|
|
|
|
tableData: BehaviorSubject<CargoBikeResult[]> = new BehaviorSubject([]);
|
|
|
|
loadingRowIds: BehaviorSubject<string[]> = new BehaviorSubject([]);
|
|
|
|
loadingRowIds: BehaviorSubject<string[]> = new BehaviorSubject([]);
|
|
|
|
pageData: BehaviorSubject<any> = new BehaviorSubject([]);
|
|
|
|
pageData: BehaviorSubject<any> = new BehaviorSubject([]);
|
|
|
|
loadingBike: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
|
|
|
isLoadingPageData: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
private getCargoBikesGQL: GetCargoBikesGQL,
|
|
|
|
private getCargoBikesGQL: GetCargoBikesGQL,
|
|
|
@ -44,7 +43,7 @@ export class BikesService {
|
|
|
|
private lockCargoBikeGQL: LockCargoBikeGQL,
|
|
|
|
private lockCargoBikeGQL: LockCargoBikeGQL,
|
|
|
|
private unlockCargoBikeGQL: UnlockCargoBikeGQL,
|
|
|
|
private unlockCargoBikeGQL: UnlockCargoBikeGQL,
|
|
|
|
private createCargoBikeGQL: CreateCargoBikeGQL,
|
|
|
|
private createCargoBikeGQL: CreateCargoBikeGQL,
|
|
|
|
private deleteCargoBikeGQL: DeleteCargoBikeGQL,
|
|
|
|
private deleteCargoBikeGQL: DeleteCargoBikeGQL
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
addLoadingRowId(id: string) {
|
|
|
|
addLoadingRowId(id: string) {
|
|
|
@ -57,25 +56,25 @@ export class BikesService {
|
|
|
|
this.loadingRowIds.value.splice(index, 1);
|
|
|
|
this.loadingRowIds.value.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loadingRowIds.next(this.loadingRowIds.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loadTableData() {
|
|
|
|
loadTableData() {
|
|
|
|
this.getCargoBikesGQL.fetch().subscribe((result) => {
|
|
|
|
this.getCargoBikesGQL.fetch().subscribe((result) => {
|
|
|
|
this.tableData.next(result.data.cargoBikes);
|
|
|
|
this.tableData.next(result.data.cargoBikes);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loadPageData(variables: GetCargoBikeByIdQueryVariables) {
|
|
|
|
loadPageData(variables: GetCargoBikeByIdQueryVariables) {
|
|
|
|
this.pageData.next(null);
|
|
|
|
this.pageData.next(null);
|
|
|
|
this.loadingBike.next(true);
|
|
|
|
this.isLoadingPageData.next(true);
|
|
|
|
this.getCargoBikeByIdGQL
|
|
|
|
this.getCargoBikeByIdGQL
|
|
|
|
.fetch(variables)
|
|
|
|
.fetch(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
this.pageData.next(result.data.cargoBikeById);
|
|
|
|
this.pageData.next(result.data.cargoBikeById);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
|
this.loadingBike.next(false);
|
|
|
|
this.isLoadingPageData.next(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -84,12 +83,7 @@ export class BikesService {
|
|
|
|
this.reloadCargoBikeByIdGQL
|
|
|
|
this.reloadCargoBikeByIdGQL
|
|
|
|
.fetch(variables)
|
|
|
|
.fetch(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
const newBike = result.data.cargoBikeById;
|
|
|
|
this.updateDataRowFromResponse(result.data.cargoBikeById)
|
|
|
|
this.tableData.next(
|
|
|
|
|
|
|
|
this.tableData.value.map((bike) =>
|
|
|
|
|
|
|
|
newBike.id === bike.id ? newBike : bike
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
@ -97,14 +91,10 @@ export class BikesService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createBike(variables: CreateCargoBikeMutationVariables) {
|
|
|
|
createBike(variables: CreateCargoBikeMutationVariables) {
|
|
|
|
this.createCargoBikeGQL
|
|
|
|
this.createCargoBikeGQL.mutate(variables).subscribe((result) => {
|
|
|
|
.mutate(variables)
|
|
|
|
|
|
|
|
.subscribe((result) => {
|
|
|
|
|
|
|
|
const newBike = result.data.createCargoBike;
|
|
|
|
const newBike = result.data.createCargoBike;
|
|
|
|
this.tableData.next(
|
|
|
|
this.tableData.next([newBike, ...this.tableData.value]);
|
|
|
|
[newBike, ...this.tableData.value]
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateBike(variables: UpdateCargoBikeMutationVariables) {
|
|
|
|
updateBike(variables: UpdateCargoBikeMutationVariables) {
|
|
|
@ -112,12 +102,7 @@ export class BikesService {
|
|
|
|
this.updateCargoBikeGQL
|
|
|
|
this.updateCargoBikeGQL
|
|
|
|
.mutate(variables)
|
|
|
|
.mutate(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
const newBike = result.data.updateCargoBike;
|
|
|
|
this.updateDataRowFromResponse(result.data.updateCargoBike);
|
|
|
|
this.tableData.next(
|
|
|
|
|
|
|
|
this.tableData.value.map((bike) =>
|
|
|
|
|
|
|
|
newBike.id === bike.id ? newBike : bike
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
|
this.removeLoadingRowId(variables.bike.id);
|
|
|
|
this.removeLoadingRowId(variables.bike.id);
|
|
|
@ -129,12 +114,7 @@ export class BikesService {
|
|
|
|
this.lockCargoBikeGQL
|
|
|
|
this.lockCargoBikeGQL
|
|
|
|
.mutate(variables)
|
|
|
|
.mutate(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
const lockedBike = result.data.lockCargoBike;
|
|
|
|
this.updateDataRowFromResponse(result.data.lockCargoBike);
|
|
|
|
this.tableData.next(
|
|
|
|
|
|
|
|
this.tableData.value.map((bike) =>
|
|
|
|
|
|
|
|
lockedBike.id === bike.id ? lockedBike : bike
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
@ -146,12 +126,7 @@ export class BikesService {
|
|
|
|
this.unlockCargoBikeGQL
|
|
|
|
this.unlockCargoBikeGQL
|
|
|
|
.mutate(variables)
|
|
|
|
.mutate(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
const unlockedBike = result.data.unlockCargoBike;
|
|
|
|
this.updateDataRowFromResponse(result.data.unlockCargoBike);
|
|
|
|
this.tableData.next(
|
|
|
|
|
|
|
|
this.tableData.value.map((bike) =>
|
|
|
|
|
|
|
|
unlockedBike.id === bike.id ? unlockedBike : bike
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
|
this.removeLoadingRowId(variables.id);
|
|
|
@ -163,8 +138,10 @@ export class BikesService {
|
|
|
|
this.deleteCargoBikeGQL
|
|
|
|
this.deleteCargoBikeGQL
|
|
|
|
.mutate(variables)
|
|
|
|
.mutate(variables)
|
|
|
|
.subscribe((result) => {
|
|
|
|
.subscribe((result) => {
|
|
|
|
if(result.data.deleteCargoBike) {
|
|
|
|
if (result.data.deleteCargoBike) {
|
|
|
|
this.tableData.next([...this.tableData.value].filter(bike => bike.id !== variables.id));
|
|
|
|
this.tableData.next(
|
|
|
|
|
|
|
|
[...this.tableData.value].filter((bike) => bike.id !== variables.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.add(() => {
|
|
|
|
.add(() => {
|
|
|
@ -172,7 +149,13 @@ export class BikesService {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
relockBike(variables: LockCargoBikeMutationVariables) {
|
|
|
|
private updateDataRowFromResponse(rowFromResponse: any) {
|
|
|
|
this.lockCargoBikeGQL.mutate(variables).subscribe();
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|