Fix table editing

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

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

@ -1,4 +1,5 @@
import { Component, Input, Output, EventEmitter } from '@angular/core'; import { Component, Input, Output, EventEmitter } from '@angular/core';
import { catchError } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-string-cell', selector: 'app-string-cell',
@ -15,7 +16,7 @@ export class StringCellComponent {
inputType = 'text'; inputType = 'text';
change(newValue) { change(newValue) {
this.value = newValue; this.value = this.inputType === 'number' ? +newValue : newValue;
this.valueChange.emit(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 uri = environment.apiUrl + '/graphql'; // <-- add the URL of the GraphQL server here
const cleanTypeName = new ApolloLink((operation, forward) => { const authMiddleware = new ApolloLink((operation, forward) => {
if (operation.variables) { //Add token here <-------------------------------------------------------
const omitTypename = (key: string, value: any) =>
key === '__typename' ? undefined : value;
operation.variables = JSON.parse(
JSON.stringify(operation.variables),
omitTypename
);
}
return forward(operation).map((data) => { return forward(operation).map((data) => {
return data; return data;
}); });
@ -27,7 +20,7 @@ const cleanTypeName = new ApolloLink((operation, forward) => {
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> { export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
return { return {
link: concat(cleanTypeName, httpLink.create({ uri })), link: concat(authMiddleware, httpLink.create({ uri })),
cache: new InMemoryCache({}), cache: new InMemoryCache({}),
}; };
} }

@ -1,7 +1,6 @@
<div class="table-page-wrapper"> <div class="table-page-wrapper">
<div class="table-control"> <div class="table-control">
<button mat-raised-button color="primary">Primary</button> <button mat-raised-button color="primary">Alle ausgewählten Fahrräder bearbeiten</button>
<button mat-raised-button color="accent">Accent</button>
</div> </div>
<div class="table-container"> <div class="table-container">
<table <table
@ -86,7 +85,8 @@
*ngIf=" *ngIf="
!element.isGettingEdited && !element.isGettingEdited &&
!element.waitingForEditPermissions && !element.waitingForEditPermissions &&
!element.locked !element.locked &&
!element.saving
" "
> >
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
@ -96,7 +96,8 @@
*ngIf=" *ngIf="
!element.isGettingEdited && !element.isGettingEdited &&
!element.waitingForEditPermissions && !element.waitingForEditPermissions &&
!element.locked !element.locked &&
!element.saving
" "
> >
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
@ -104,7 +105,7 @@
<mat-spinner <mat-spinner
[diameter]="32" [diameter]="32"
*ngIf="element.waitingForEditPermissions" *ngIf="element.waitingForEditPermissions || element.saving"
></mat-spinner> ></mat-spinner>
<button <button

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

Loading…
Cancel
Save