-
-
Notifications
You must be signed in to change notification settings - Fork 18
table settings: restore order_by, column order and visible by default columns #1517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e4708d
5043c2a
9ee561a
4b8d0ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { Component, OnInit } from '@angular/core'; | ||
| import { TableField, TableSettings } from 'src/app/models/table'; | ||
| import { TableField, TableOrdering, TableSettings } from 'src/app/models/table'; | ||
|
|
||
| import { AlertComponent } from '../../../ui-components/alert/alert.component'; | ||
| import { Angulartics2 } from 'angulartics2'; | ||
| import { BreadcrumbsComponent } from '../../../ui-components/breadcrumbs/breadcrumbs.component'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { CompanyService } from 'src/app/services/company.service'; | ||
| import { ConnectionsService } from 'src/app/services/connections.service'; | ||
| import { DragDropModule } from '@angular/cdk/drag-drop'; | ||
| import { CdkDragDrop, DragDropModule, moveItemInArray } from '@angular/cdk/drag-drop'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { IconPickerComponent } from '../../../ui-components/icon-picker/icon-picker.component'; | ||
| import { Location } from '@angular/common'; | ||
|
|
@@ -60,14 +60,20 @@ export class DbTableSettingsComponent implements OnInit { | |
| public loading: boolean = true; | ||
| public fields: string[]; | ||
| public fields_to_exclude: string[]; | ||
| public orderChanged: boolean = false; | ||
| public iconChanged: boolean = false; | ||
| public listFieldsOrder: string[]; | ||
| public tableSettingsInitial: TableSettings = { | ||
| connection_id: '', | ||
| table_name: '', | ||
| icon: '', | ||
| display_name: '', | ||
| autocomplete_columns: [], | ||
| identity_column: '', | ||
| ordering: TableOrdering.Ascending, | ||
| ordering_field: '', | ||
| list_fields: [], | ||
| columns_view: [], | ||
| search_fields: [], | ||
| excluded_fields: [], | ||
| readonly_fields: [], | ||
|
|
@@ -137,9 +143,13 @@ export class DbTableSettingsComponent implements OnInit { | |
| if (Object.keys(res).length !== 0) { | ||
| this.isSettingsExist = true | ||
| this.tableSettings = res; | ||
| this.listFieldsOrder = [...res.list_fields]; | ||
| } else { | ||
| this.tableSettings = this.tableSettingsInitial; | ||
| }; | ||
| if (Object.keys(res).length === 0 || (res && res.list_fields && !res.list_fields.length)) { | ||
| this.listFieldsOrder = [...this.fields]; | ||
| }; | ||
| this.title.setTitle(`${res.display_name || this.displayTableName} - Table settings | ${this._company.companyTabTitle || 'Rocketadmin'}`); | ||
| } | ||
| ); | ||
|
|
@@ -150,6 +160,18 @@ export class DbTableSettingsComponent implements OnInit { | |
| this.iconChanged = true; | ||
| } | ||
|
|
||
| drop(event: CdkDragDrop<string[]>) { | ||
| moveItemInArray(this.listFieldsOrder, event.previousIndex, event.currentIndex); | ||
| this.tableSettings.list_fields = [...this.listFieldsOrder]; | ||
| this.orderChanged = true; | ||
| } | ||
|
|
||
| resetColumnsOrder() { | ||
| this.tableSettings.list_fields = []; | ||
| this.listFieldsOrder = [...this.fields]; | ||
| this.orderChanged = true; | ||
| } | ||
|
|
||
| updateSettings() { | ||
| this.submitting = true; | ||
| this.tableSettings.connection_id = this.connectionID; | ||
|
|
@@ -160,7 +182,11 @@ export class DbTableSettingsComponent implements OnInit { | |
| for (const [key, value] of Object.entries(this.tableSettings)) { | ||
| if (key !== 'connection_id' && key !== 'table_name' && key !== 'ordering') { | ||
| if (Array.isArray(value)) { | ||
| updatedSettings[key] = value.length > 0 | ||
| if (key === 'list_fields') { | ||
| updatedSettings[key] = this.orderChanged; | ||
| } else { | ||
| updatedSettings[key] = value.length > 0; | ||
| } | ||
|
Comment on lines
+185
to
+189
|
||
| } else { | ||
| updatedSettings[key] = Boolean(value); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization of listFieldsOrder at line 146 will fail when res.list_fields is undefined or null, as spreading undefined/null will throw a runtime error. The check at line 150 only handles empty arrays, not the case where list_fields doesn't exist on the response object. This can occur when table settings exist but don't have list_fields populated, which would cause a crash when trying to spread the undefined value.