Fix table editing

pull/1/head
Max Ehrlicher-Schmidt 4 years ago
parent 02c2054158
commit 70911a76fa

@ -1,6 +1,6 @@
overwrite: true
schema: "http://localhost:4000/graphql"
documents: "src/app/graphqlOperations/**/*"
documents: "src/app/graphqlOperations/**/*.graphql"
generates:
src/generated/graphql.ts:
plugins:

@ -1,4 +1,5 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { catchError } from 'rxjs/operators';
@Component({
selector: 'app-string-cell',
@ -15,7 +16,7 @@ export class StringCellComponent {
inputType = 'text';
change(newValue) {
this.value = newValue;
this.valueChange.emit(newValue);
this.value = this.inputType === 'number' ? +newValue : newValue;
this.valueChange.emit(this.value);
}
}

@ -11,15 +11,8 @@ import { environment } from '../environments/environment';
const uri = environment.apiUrl + '/graphql'; // <-- add the URL of the GraphQL server here
const cleanTypeName = new ApolloLink((operation, forward) => {
if (operation.variables) {
const omitTypename = (key: string, value: any) =>
key === '__typename' ? undefined : value;
operation.variables = JSON.parse(
JSON.stringify(operation.variables),
omitTypename
);
}
const authMiddleware = new ApolloLink((operation, forward) => {
//Add token here <-------------------------------------------------------
return forward(operation).map((data) => {
return data;
});
@ -27,7 +20,7 @@ const cleanTypeName = new ApolloLink((operation, forward) => {
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
return {
link: concat(cleanTypeName, httpLink.create({ uri })),
link: concat(authMiddleware, httpLink.create({ uri })),
cache: new InMemoryCache({}),
};
}

@ -86,7 +86,8 @@
*ngIf="
!element.isGettingEdited &&
!element.waitingForEditPermissions &&
!element.locked
!element.locked &&
!element.saving
"
>
<mat-icon>edit</mat-icon>
@ -96,7 +97,8 @@
*ngIf="
!element.isGettingEdited &&
!element.waitingForEditPermissions &&
!element.locked
!element.locked &&
!element.saving
"
>
<mat-icon>delete</mat-icon>
@ -104,7 +106,7 @@
<mat-spinner
[diameter]="32"
*ngIf="element.waitingForEditPermissions"
*ngIf="element.waitingForEditPermissions || element.saving"
></mat-spinner>
<button

@ -4,10 +4,11 @@ import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
import { deepCopy } from 'src/app/helperFunctions/deepCopy';
import { filter } from 'graphql-anywhere';
import {CargoBikeFieldsMutableFragmentDoc} from 'src/generated/graphql';
import {CargoBikeFieldsMutableFragmentDoc, CargoBikeUpdateInput} from 'src/generated/graphql';
type CargoBikeDataRow = CargoBikeResult & {
waitingForEditPermissions: boolean;
saving: boolean;
isGettingEdited: boolean;
locked: boolean;
};
@ -37,6 +38,7 @@ export class BikesComponent {
waitingForEditPermissions: false,
isGettingEdited: false,
locked: false,
saving: false
});
});
if (this.bikes.length > 6) {
@ -56,15 +58,17 @@ export class BikesComponent {
}
save(row: CargoBikeDataRow) {
//remove lock
this.bikesService.updateBike({bike: filter(CargoBikeFieldsMutableFragmentDoc, row)})
//TODO: remove lock
row.saving = true;
row.isGettingEdited = false;
const bike: CargoBikeUpdateInput = filter(CargoBikeFieldsMutableFragmentDoc, row)
this.bikesService.updateBike({bike})
}
cancel(row: CargoBikeDataRow) {
//fetch it again
//TODO: remove lock
this.bikesService.reloadBike({ id: row.id });
console.log('cancel');
}
drop(event: CdkDragDrop<string[]>) {

Loading…
Cancel
Save