diff --git a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.html b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.html index 143892f00..6e3f7e20e 100644 --- a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.html +++ b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.html @@ -62,7 +62,7 @@

General settings

Table view

- + - + Searchable columns @@ -115,7 +115,7 @@

Table view

Choose the columns Rocketadmin scans when using the Search bar.
- + Sortable columns @@ -189,7 +189,7 @@

"Edit ro diff --git a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.spec.ts b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.spec.ts index c8066cd40..04d141a6b 100644 --- a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.spec.ts +++ b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.spec.ts @@ -79,6 +79,10 @@ describe('DbTableSettingsComponent', () => { icon: '', search_fields: [], excluded_fields: [], + list_fields: [], + ordering: TableOrdering.Ascending, + ordering_field: "", + columns_view: [], // identification_fields: [], // list_per_page: null, identity_column: '', diff --git a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.ts b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.ts index b76aa0cbf..7fe2cbe3f 100644 --- a/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.ts +++ b/frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.ts @@ -1,5 +1,5 @@ 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'; @@ -7,7 +7,7 @@ import { BreadcrumbsComponent } from '../../../ui-components/breadcrumbs/breadcr 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,7 +60,9 @@ 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: '', @@ -68,6 +70,10 @@ export class DbTableSettingsComponent implements OnInit { 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) { + 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; + } } else { updatedSettings[key] = Boolean(value); } diff --git a/frontend/src/app/components/dashboard/db-tables-data-source.ts b/frontend/src/app/components/dashboard/db-tables-data-source.ts index b03c378bc..0ff513fb5 100644 --- a/frontend/src/app/components/dashboard/db-tables-data-source.ts +++ b/frontend/src/app/components/dashboard/db-tables-data-source.ts @@ -226,6 +226,12 @@ export class TablesDataSource implements DataSource { normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name), selected: res.table_settings.columns_view.includes(item.column_name) } + } else if (res.columns_view && res.columns_view.length !== 0) { + return { + title: item.column_name, + normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name), + selected: res.columns_view.includes(item.column_name) + } } else { if (index < 6) { return { diff --git a/frontend/src/app/models/table.ts b/frontend/src/app/models/table.ts index 251d59d37..3dfb071da 100644 --- a/frontend/src/app/models/table.ts +++ b/frontend/src/app/models/table.ts @@ -26,6 +26,10 @@ export interface TableSettings { display_name: string, autocomplete_columns: string[], identity_column: string, + ordering: TableOrdering, + ordering_field: string, + list_fields: string[], + columns_view: string[], search_fields: string[], excluded_fields: string[], readonly_fields: string[],