Skip to content

Commit e16fca3

Browse files
Merge pull request #1517 from rocket-admin/table-settings-restore-settings
table settings: restore order_by, column order and visible by default columns
2 parents 432477c + 4b8d0ce commit e16fca3

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ <h2 class="mat-heading-2 settings-fields__heading">General settings</h2>
6262
</mat-slide-toggle>
6363

6464
<h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
65-
<!--<mat-form-field appearance="outline">
65+
<mat-form-field appearance="outline">
6666
<mat-label>Columns visible by default</mat-label>
6767
<mat-select multiple
6868
name="columns_view"
6969
[(ngModel)]="tableSettings.columns_view">
7070
<mat-option *ngFor="let field of fields" [value]="field">{{field}}</mat-option>
7171
</mat-select>
7272
<mat-hint>Choose the columns you want users to see when they first open this table. Changes made to a table's Columns view are saved over the default values.</mat-hint>
73-
</mat-form-field>-->
73+
</mat-form-field>
7474

75-
<!--<div class="order-settings">
75+
<div class="order-settings">
7676
<div class="order-settings__panel">
7777
<span class="order__title">
7878
Columns order
@@ -103,7 +103,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
103103
(click)="resetColumnsOrder()">
104104
<mat-icon>restart_alt</mat-icon>
105105
</button>
106-
</div>-->
106+
</div>
107107

108108
<mat-form-field appearance="outline">
109109
<mat-label>Searchable columns</mat-label>
@@ -115,7 +115,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
115115
<mat-hint>Choose the columns Rocketadmin scans when using the Search bar.</mat-hint>
116116
</mat-form-field>
117117

118-
<!--<div class="form-group-ordering">
118+
<div class="form-group-ordering">
119119
<mat-form-field appearance="outline" class="form-group-ordering__ordering-by">
120120
<mat-label>Order by</mat-label>
121121
<mat-select name="ordering_field" [(ngModel)]="tableSettings.ordering_field">
@@ -132,7 +132,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
132132
<mat-radio-button value="ASC" checked>Ascending</mat-radio-button>
133133
<mat-radio-button value="DESC">Descending</mat-radio-button>
134134
</mat-radio-group>
135-
</div>-->
135+
</div>
136136

137137
<mat-form-field appearance="outline">
138138
<mat-label>Sortable columns</mat-label>
@@ -189,7 +189,7 @@ <h2 class="mat-heading-2" style="margin-bottom: -4px; margin-top: 12px">"Edit ro
189189
<button mat-flat-button color="primary"
190190
type="submit"
191191
class="settings-form__save-button"
192-
[disabled]="(submitting || tableSettingsForm.form.invalid || tableSettingsForm.form.pristine) && !iconChanged">
192+
[disabled]="(submitting || tableSettingsForm.form.invalid || tableSettingsForm.form.pristine) && !orderChanged && !iconChanged">
193193
Save
194194
</button>
195195
</div>

frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ describe('DbTableSettingsComponent', () => {
7979
icon: '',
8080
search_fields: [],
8181
excluded_fields: [],
82+
list_fields: [],
83+
ordering: TableOrdering.Ascending,
84+
ordering_field: "",
85+
columns_view: [],
8286
// identification_fields: [],
8387
// list_per_page: null,
8488
identity_column: '',

frontend/src/app/components/dashboard/db-table-view/db-table-settings/db-table-settings.component.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { TableField, TableSettings } from 'src/app/models/table';
2+
import { TableField, TableOrdering, TableSettings } from 'src/app/models/table';
33

44
import { AlertComponent } from '../../../ui-components/alert/alert.component';
55
import { Angulartics2 } from 'angulartics2';
66
import { BreadcrumbsComponent } from '../../../ui-components/breadcrumbs/breadcrumbs.component';
77
import { CommonModule } from '@angular/common';
88
import { CompanyService } from 'src/app/services/company.service';
99
import { ConnectionsService } from 'src/app/services/connections.service';
10-
import { DragDropModule } from '@angular/cdk/drag-drop';
10+
import { CdkDragDrop, DragDropModule, moveItemInArray } from '@angular/cdk/drag-drop';
1111
import { FormsModule } from '@angular/forms';
1212
import { IconPickerComponent } from '../../../ui-components/icon-picker/icon-picker.component';
1313
import { Location } from '@angular/common';
@@ -60,14 +60,20 @@ export class DbTableSettingsComponent implements OnInit {
6060
public loading: boolean = true;
6161
public fields: string[];
6262
public fields_to_exclude: string[];
63+
public orderChanged: boolean = false;
6364
public iconChanged: boolean = false;
65+
public listFieldsOrder: string[];
6466
public tableSettingsInitial: TableSettings = {
6567
connection_id: '',
6668
table_name: '',
6769
icon: '',
6870
display_name: '',
6971
autocomplete_columns: [],
7072
identity_column: '',
73+
ordering: TableOrdering.Ascending,
74+
ordering_field: '',
75+
list_fields: [],
76+
columns_view: [],
7177
search_fields: [],
7278
excluded_fields: [],
7379
readonly_fields: [],
@@ -137,9 +143,13 @@ export class DbTableSettingsComponent implements OnInit {
137143
if (Object.keys(res).length !== 0) {
138144
this.isSettingsExist = true
139145
this.tableSettings = res;
146+
this.listFieldsOrder = [...res.list_fields];
140147
} else {
141148
this.tableSettings = this.tableSettingsInitial;
142149
};
150+
if (Object.keys(res).length === 0 || (res && res.list_fields && !res.list_fields.length)) {
151+
this.listFieldsOrder = [...this.fields];
152+
};
143153
this.title.setTitle(`${res.display_name || this.displayTableName} - Table settings | ${this._company.companyTabTitle || 'Rocketadmin'}`);
144154
}
145155
);
@@ -150,6 +160,18 @@ export class DbTableSettingsComponent implements OnInit {
150160
this.iconChanged = true;
151161
}
152162

163+
drop(event: CdkDragDrop<string[]>) {
164+
moveItemInArray(this.listFieldsOrder, event.previousIndex, event.currentIndex);
165+
this.tableSettings.list_fields = [...this.listFieldsOrder];
166+
this.orderChanged = true;
167+
}
168+
169+
resetColumnsOrder() {
170+
this.tableSettings.list_fields = [];
171+
this.listFieldsOrder = [...this.fields];
172+
this.orderChanged = true;
173+
}
174+
153175
updateSettings() {
154176
this.submitting = true;
155177
this.tableSettings.connection_id = this.connectionID;
@@ -160,7 +182,11 @@ export class DbTableSettingsComponent implements OnInit {
160182
for (const [key, value] of Object.entries(this.tableSettings)) {
161183
if (key !== 'connection_id' && key !== 'table_name' && key !== 'ordering') {
162184
if (Array.isArray(value)) {
163-
updatedSettings[key] = value.length > 0
185+
if (key === 'list_fields') {
186+
updatedSettings[key] = this.orderChanged;
187+
} else {
188+
updatedSettings[key] = value.length > 0;
189+
}
164190
} else {
165191
updatedSettings[key] = Boolean(value);
166192
}

frontend/src/app/components/dashboard/db-tables-data-source.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ export class TablesDataSource implements DataSource<Object> {
226226
normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name),
227227
selected: res.table_settings.columns_view.includes(item.column_name)
228228
}
229+
} else if (res.columns_view && res.columns_view.length !== 0) {
230+
return {
231+
title: item.column_name,
232+
normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name),
233+
selected: res.columns_view.includes(item.column_name)
234+
}
229235
} else {
230236
if (index < 6) {
231237
return {

frontend/src/app/models/table.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface TableSettings {
2626
display_name: string,
2727
autocomplete_columns: string[],
2828
identity_column: string,
29+
ordering: TableOrdering,
30+
ordering_field: string,
31+
list_fields: string[],
32+
columns_view: string[],
2933
search_fields: string[],
3034
excluded_fields: string[],
3135
readonly_fields: string[],

0 commit comments

Comments
 (0)