Add copy functionallity

master
Max Ehrlicher-Schmidt 4 years ago
parent a5826311ca
commit 7ea40e7f6f

@ -284,7 +284,12 @@
>
<mat-icon>delete</mat-icon>Löschen
</button>
<button mat-menu-item disabled>
<button
mat-menu-item
*ngIf="copyableRows"
[disabled]="false"
(click)="copy(element)"
>
<mat-icon>content_copy</mat-icon>Duplizieren
</button>
</mat-menu>

@ -63,6 +63,9 @@ export class TableComponent implements AfterViewInit {
@Input()
tableDataGQLUpdateInputType: string;
@Input()
copyableRows = false;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@ -97,6 +100,7 @@ export class TableComponent implements AfterViewInit {
@Output() createEvent = new EventEmitter();
@Output() lockEvent = new EventEmitter();
@Output() saveEvent = new EventEmitter();
@Output() copyEvent = new EventEmitter();
@Output() cancelEvent = new EventEmitter();
@Output() deleteEvent = new EventEmitter();
@ -159,6 +163,12 @@ export class TableComponent implements AfterViewInit {
this.reloadingTable = false;
this.isLoaded = true;
for (const row of newTableDataSource) {
if (row.newObject) {
// its a copied object
row.id = this.getNewId();
tempDataSource.push(flatten(row));
continue;
}
const oldRow = this.getRowById(row.id);
/** make sure to not overwrite a row that is being edited */
if (!oldRow) {
@ -340,6 +350,14 @@ export class TableComponent implements AfterViewInit {
this.saveEvent.emit(deepenRow);
}
copy(row: any) {
const deepenRow = this.schemaService.filterObject(
this.tableDataGQLUpdateInputType,
deepen(row)
);
this.copyEvent.emit(deepenRow);
}
cancel(row: any) {
this.cancelEvent.emit(row);
}

@ -10,6 +10,12 @@ query GetCargoBikeById($id: ID!) {
}
}
query copyCargoBikeById($id: ID!) {
copyCargoBikeById(id: $id) {
...CargoBikeFieldsForTable
}
}
query ReloadCargoBikeById($id: ID!) {
cargoBikeById(id: $id) {
...CargoBikeFieldsForTable

@ -2,6 +2,7 @@
[headline]="headline"
[headlineIconName]="headlineIconName"
[columnInfo]="columnInfo"
[copyableRows]="copyableRows"
[dataService]="dataService"
[tableDataGQLType]="tableDataGQLType"
[tableDataGQLCreateInputType]="tableDataGQLCreateInputType"
@ -9,6 +10,7 @@
(createEvent)="create($event)"
(lockEvent)="lock($event)"
(saveEvent)="save($event)"
(copyEvent)="copy($event)"
(cancelEvent)="cancel($event)"
(deleteEvent)="delete($event)"
></app-table>

@ -132,6 +132,7 @@ export class BikesComponent implements OnInit {
headline = 'Lastenräder';
headlineIconName = 'directions_bike';
copyableRows = true;
loadingRowIds: string[] = [];
constructor(private bikesService: BikesService) {}
@ -152,6 +153,10 @@ export class BikesComponent implements OnInit {
this.bikesService.updateBike({ bike: row });
}
copy(row: any) {
this.bikesService.copyBikeById({ id: row.id });
}
cancel(row: any) {
this.bikesService.unlockBike({ id: row.id });
}

@ -16,6 +16,8 @@ import {
DeleteCargoBikeMutationVariables,
GetCargoBikeByIdGQL,
GetCargoBikeByIdQueryVariables,
CopyCargoBikeByIdGQL,
CopyCargoBikeByIdQueryVariables
} from 'src/generated/graphql';
@Injectable({
@ -34,6 +36,7 @@ export class BikesService {
private getCargoBikeByIdGQL: GetCargoBikeByIdGQL,
private reloadCargoBikeByIdGQL: ReloadCargoBikeByIdGQL,
private updateCargoBikeGQL: UpdateCargoBikeGQL,
private copyCargoBikeByIdGQL: CopyCargoBikeByIdGQL,
private lockCargoBikeGQL: LockCargoBikeGQL,
private unlockCargoBikeGQL: UnlockCargoBikeGQL,
private createCargoBikeGQL: CreateCargoBikeGQL,
@ -73,6 +76,19 @@ export class BikesService {
});
}
copyBikeById(variables: CopyCargoBikeByIdQueryVariables) {
this.copyCargoBikeByIdGQL
.fetch(variables)
.subscribe((result) => {
const newBike = result.data.copyCargoBikeById;
newBike["newObject"] = true;
const currentTableData = this.tableData.getValue();
this.tableData.next([newBike, ...this.tableData.getValue()]);
this.tableData.next(currentTableData);
})
}
reloadBike(variables: ReloadCargoBikeByIdQueryVariables) {
this.addLoadingRowId(variables.id);
this.reloadCargoBikeByIdGQL

@ -1813,6 +1813,16 @@ export type GetCargoBikeByIdQuery = { __typename?: 'Query', cargoBikeById?: Mayb
& CargoBikeFieldsForPageFragment
)> };
export type CopyCargoBikeByIdQueryVariables = Exact<{
id: Scalars['ID'];
}>;
export type CopyCargoBikeByIdQuery = { __typename?: 'Query', copyCargoBikeById?: Maybe<(
{ __typename?: 'CargoBike' }
& CargoBikeFieldsForTableFragment
)> };
export type ReloadCargoBikeByIdQueryVariables = Exact<{
id: Scalars['ID'];
}>;
@ -3744,6 +3754,24 @@ export const GetCargoBikeByIdDocument = gql`
export class GetCargoBikeByIdGQL extends Apollo.Query<GetCargoBikeByIdQuery, GetCargoBikeByIdQueryVariables> {
document = GetCargoBikeByIdDocument;
constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const CopyCargoBikeByIdDocument = gql`
query copyCargoBikeById($id: ID!) {
copyCargoBikeById(id: $id) {
...CargoBikeFieldsForTable
}
}
${CargoBikeFieldsForTableFragmentDoc}`;
@Injectable({
providedIn: 'root'
})
export class CopyCargoBikeByIdGQL extends Apollo.Query<CopyCargoBikeByIdQuery, CopyCargoBikeByIdQueryVariables> {
document = CopyCargoBikeByIdDocument;
constructor(apollo: Apollo.Apollo) {
super(apollo);
}

Loading…
Cancel
Save