Skip to content

Commit

Permalink
feat: add new row functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Badura committed Aug 8, 2024
1 parent e52ff98 commit 3303818
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 35 deletions.
22 changes: 22 additions & 0 deletions src/app/product-store/app-detail/add-row.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Directive, Input, HostListener } from '@angular/core'
import { Table } from 'primeng/table'

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[pAddRow]'
})
export class AddRowDirective {
@Input() table!: Table
@Input() newRow: any

@HostListener('click', ['$event'])
onClick(event: Event) {
// Insert a new row
this.table.value.push(this.newRow)

// Set the new row in edit mode
this.table.initRowEdit(this.newRow)

event.preventDefault()
}
}
65 changes: 39 additions & 26 deletions src/app/product-store/app-detail/app-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
[header]="'DIALOG.TABS.ENDPOINTS' | translate"
[tooltip]="'DIALOG.TABS.TOOLTIPS.ENDPOINTS' | translate"
>
<p-table [value]="endpoints" [tableStyle]="{ 'min-width': '50rem' }">
<p-table #epTable [value]="endpoints" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header">
<tr>
<th [pTooltip]="'APP.TOOLTIPS.ENDPOINTS.NAME' | translate" tooltipPosition="top" tooltipEvent="hover">
Expand Down Expand Up @@ -464,40 +464,53 @@
<ng-template pTemplate="output"> {{ endpoint.path }} </ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn]="newEndpoint.name" pEditableColumnField="name">
<!-- <td [pEditableColumn]="newEndpoint.name" pEditableColumnField="name">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="newEndpoint.name" />
</ng-template>
<ng-template pTemplate="output">{{ newEndpoint.name }}</ng-template>
</p-cellEditor>
</td>
</td> -->
</tr>
</ng-template>
<!-- <ng-template pTemplate="body">
<tr>
<td [pEditableColumn]="newEndpoint.name" pEditableColumnField="name">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="newEndpoint.name" />
</ng-template>
<ng-template pTemplate="output">{{ newEndpoint.name }}</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn]="newEndpoint.path" pEditableColumnField="path">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="newEndpoint.path" />
</ng-template>
<ng-template pTemplate="output">{{ newEndpoint.path }}</ng-template>
</p-cellEditor>
</td>
<td>
<button pButton type="button" icon="pi pi-check" (click)="addNewEndpoint()"></button>
</td>
</tr>
</ng-template> -->
</p-table>
<!-- <ng-template pTemplate="body">
<input pInputText type="text" [(ngModel)]="newEndpoint.name" />
<input pInputText type="text" [(ngModel)]="newEndpoint.path" />
<tr>
<td [pEditableColumn]="newEndpoint.name" pEditableColumnField="name">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="newEndpoint.name" />
</ng-template>
<ng-template pTemplate="output">{{ newEndpoint.name }}</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn]="newEndpoint.path" pEditableColumnField="path">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="newEndpoint.path" />
</ng-template>
<ng-template pTemplate="output">{{ newEndpoint.path }}</ng-template>
</p-cellEditor>
</td>
<td>
<button pButton type="button" icon="pi pi-check" (click)="addNewEndpoint()"></button>
</td>
</tr>
</ng-template> -->
<button
pButton
type="button"
icon="pi pi-plus"
class="ui-button-info"
[label]="'Add'"
pAddRow
[table]="epTable"
[newRow]="addNewRow()"
></button>
</p-tabPanel>
</p-tabView>

Expand Down
16 changes: 10 additions & 6 deletions src/app/product-store/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class AppDetailComponent implements OnInit, OnChanges {
this.mfe = { ...this.formGroupMfe.value, id: this.mfe?.id }
if (this.mfe) {
this.mfe.classifications = this.convertToUniqueStringArray(this.formGroupMfe.controls['classifications'].value)
this.mfe.endpoints = this.endpoints
this.mfe.endpoints = this.endpoints.filter((endpoint) => !(endpoint.name === '' && endpoint.path === ''))
}
this.changeMode === 'CREATE' ? this.createMfe() : this.updateMfe()
}
Expand Down Expand Up @@ -361,10 +361,14 @@ export class AppDetailComponent implements OnInit, OnChanges {
})
}

public addNewEndpoint() {
if (this.newEndpoint.name || this.newEndpoint.path) {
this.endpoints.push(this.newEndpoint)
this.newEndpoint = { name: '', path: '' }
}
// public addNewEndpoint() {
// if (this.newEndpoint.name || this.newEndpoint.path) {
// this.endpoints.push(this.newEndpoint)
// this.newEndpoint = { name: '', path: '' }
// }
// }

public addNewRow() {
return { name: '', path: '' }
}
}
4 changes: 3 additions & 1 deletion src/app/product-store/product-store.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ProductInternComponent } from './product-detail/product-intern/product-
import { ProductAppsComponent } from './product-detail/product-apps/product-apps.component'
import { SlotSearchComponent } from './slot-search/slot-search.component'
import { SlotDeleteComponent } from './slot-delete/slot-delete.component'
import { AddRowDirective } from './app-detail/add-row.directive'

const routes: Routes = [
{
Expand Down Expand Up @@ -67,7 +68,8 @@ const routes: Routes = [
ProductInternComponent,
ProductAppsComponent,
SlotSearchComponent,
SlotDeleteComponent
SlotDeleteComponent,
AddRowDirective
],
imports: [
CommonModule,
Expand Down
4 changes: 2 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"MS.HEADER": "Edit Microservice",
"APP": {
"TOOLTIP": "Edit App properties",
"OK": "Das App wurde erfolgreich geändert",
"NOK": "Ein Fehler ist aufgetreten. Das App wurde nicht geändert."
"OK": "The Application was changed successfully",
"NOK": "An error has occurred. The Application was not changed."
},
"PRODUCT": {
"HEADER": "Edit Application",
Expand Down

0 comments on commit 3303818

Please sign in to comment.