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 <mat-icon>delete</mat-icon>Löschen
</button> </button>
<button mat-menu-item disabled> <button
mat-menu-item
*ngIf="copyableRows"
[disabled]="false"
(click)="copy(element)"
>
<mat-icon>content_copy</mat-icon>Duplizieren <mat-icon>content_copy</mat-icon>Duplizieren
</button> </button>
</mat-menu> </mat-menu>

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

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

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

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

@ -16,6 +16,8 @@ import {
DeleteCargoBikeMutationVariables, DeleteCargoBikeMutationVariables,
GetCargoBikeByIdGQL, GetCargoBikeByIdGQL,
GetCargoBikeByIdQueryVariables, GetCargoBikeByIdQueryVariables,
CopyCargoBikeByIdGQL,
CopyCargoBikeByIdQueryVariables
} from 'src/generated/graphql'; } from 'src/generated/graphql';
@Injectable({ @Injectable({
@ -34,6 +36,7 @@ export class BikesService {
private getCargoBikeByIdGQL: GetCargoBikeByIdGQL, private getCargoBikeByIdGQL: GetCargoBikeByIdGQL,
private reloadCargoBikeByIdGQL: ReloadCargoBikeByIdGQL, private reloadCargoBikeByIdGQL: ReloadCargoBikeByIdGQL,
private updateCargoBikeGQL: UpdateCargoBikeGQL, private updateCargoBikeGQL: UpdateCargoBikeGQL,
private copyCargoBikeByIdGQL: CopyCargoBikeByIdGQL,
private lockCargoBikeGQL: LockCargoBikeGQL, private lockCargoBikeGQL: LockCargoBikeGQL,
private unlockCargoBikeGQL: UnlockCargoBikeGQL, private unlockCargoBikeGQL: UnlockCargoBikeGQL,
private createCargoBikeGQL: CreateCargoBikeGQL, 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) { reloadBike(variables: ReloadCargoBikeByIdQueryVariables) {
this.addLoadingRowId(variables.id); this.addLoadingRowId(variables.id);
this.reloadCargoBikeByIdGQL this.reloadCargoBikeByIdGQL

@ -1813,6 +1813,16 @@ export type GetCargoBikeByIdQuery = { __typename?: 'Query', cargoBikeById?: Mayb
& CargoBikeFieldsForPageFragment & CargoBikeFieldsForPageFragment
)> }; )> };
export type CopyCargoBikeByIdQueryVariables = Exact<{
id: Scalars['ID'];
}>;
export type CopyCargoBikeByIdQuery = { __typename?: 'Query', copyCargoBikeById?: Maybe<(
{ __typename?: 'CargoBike' }
& CargoBikeFieldsForTableFragment
)> };
export type ReloadCargoBikeByIdQueryVariables = Exact<{ export type ReloadCargoBikeByIdQueryVariables = Exact<{
id: Scalars['ID']; id: Scalars['ID'];
}>; }>;
@ -3744,6 +3754,24 @@ export const GetCargoBikeByIdDocument = gql`
export class GetCargoBikeByIdGQL extends Apollo.Query<GetCargoBikeByIdQuery, GetCargoBikeByIdQueryVariables> { export class GetCargoBikeByIdGQL extends Apollo.Query<GetCargoBikeByIdQuery, GetCargoBikeByIdQueryVariables> {
document = GetCargoBikeByIdDocument; 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) { constructor(apollo: Apollo.Apollo) {
super(apollo); super(apollo);
} }

Loading…
Cancel
Save