mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 11:00:40 +08:00
Use scrm-label in table component
- Use the scrm-label component in template - Add module to table config to allow using modStrings - Remove language related observable streams from vm$ - Remove translatedLabel calculation in table adapters - Remove translatedLabel property from model
This commit is contained in:
parent
e4f35db209
commit
860b384051
9 changed files with 19 additions and 61 deletions
|
@ -3,7 +3,6 @@ import {FieldDefinition} from '@app-common/record/field.model';
|
||||||
export interface ViewFieldDefinition {
|
export interface ViewFieldDefinition {
|
||||||
name?: string;
|
name?: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
translatedLabel?: string;
|
|
||||||
link?: boolean;
|
link?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
fieldDefinition?: FieldDefinition;
|
fieldDefinition?: FieldDefinition;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
scope="col"
|
scope="col"
|
||||||
class="primary-table-header">
|
class="primary-table-header">
|
||||||
|
|
||||||
{{column.translatedLabel}}
|
<scrm-label [labelKey]="column.label" [module]="config.module || ''"></scrm-label>
|
||||||
<scrm-sort-button *ngIf="config.sort$ && column.sortable"
|
<scrm-sort-button *ngIf="config.sort$ && column.sortable"
|
||||||
[state]="getFieldSort(column)">
|
[state]="getFieldSort(column)">
|
||||||
</scrm-sort-button>
|
</scrm-sort-button>
|
||||||
|
@ -61,7 +61,9 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div *ngIf="!vm.loading && vm.records.length === 0">
|
<div *ngIf="!vm.loading && vm.records.length === 0">
|
||||||
<p class="lead text-center pt-3">{{vm.language.appStrings.MSG_LIST_VIEW_NO_RESULTS_BASIC}}</p>
|
<p class="lead text-center pt-3">
|
||||||
|
<scrm-label labelKey="MSG_LIST_VIEW_NO_RESULTS_BASIC"></scrm-label>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="vm.loading" [class.m-5]="!vm.records || vm.records.length === 0">
|
<div *ngIf="vm.loading" [class.m-5]="!vm.records || vm.records.length === 0">
|
||||||
<scrm-loading-spinner [overlay]="true"></scrm-loading-spinner>
|
<scrm-loading-spinner [overlay]="true"></scrm-loading-spinner>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
import {Component, Input, OnInit} from '@angular/core';
|
||||||
import {combineLatest, Observable, of} from 'rxjs';
|
import {combineLatest, Observable, of} from 'rxjs';
|
||||||
import {map, shareReplay} from 'rxjs/operators';
|
import {map, shareReplay} from 'rxjs/operators';
|
||||||
import {LanguageStore, LanguageStrings} from '@store/language/language.store';
|
|
||||||
import {Record} from '@app-common/record/record.model';
|
import {Record} from '@app-common/record/record.model';
|
||||||
import {Field} from '@app-common/record/field.model';
|
import {Field} from '@app-common/record/field.model';
|
||||||
import {ColumnDefinition} from '@app-common/metadata/list.metadata.model';
|
import {ColumnDefinition} from '@app-common/metadata/list.metadata.model';
|
||||||
|
@ -14,7 +13,6 @@ import {RecordSelection} from '@app-common/views/list/record-selection.model';
|
||||||
import {FieldManager} from '@services/record/field/field.manager';
|
import {FieldManager} from '@services/record/field/field.manager';
|
||||||
|
|
||||||
interface TableViewModel {
|
interface TableViewModel {
|
||||||
language: LanguageStrings;
|
|
||||||
columns: ColumnDefinition[];
|
columns: ColumnDefinition[];
|
||||||
lineActions: LineAction[];
|
lineActions: LineAction[];
|
||||||
selection: RecordSelection;
|
selection: RecordSelection;
|
||||||
|
@ -31,12 +29,10 @@ interface TableViewModel {
|
||||||
})
|
})
|
||||||
export class TableBodyComponent implements OnInit {
|
export class TableBodyComponent implements OnInit {
|
||||||
@Input() config: TableConfig;
|
@Input() config: TableConfig;
|
||||||
language$: Observable<LanguageStrings> = this.language.vm$;
|
|
||||||
maxColumns = 4;
|
maxColumns = 4;
|
||||||
vm$: Observable<TableViewModel>;
|
vm$: Observable<TableViewModel>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected language: LanguageStore,
|
|
||||||
protected fieldManager: FieldManager
|
protected fieldManager: FieldManager
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@ -47,7 +43,6 @@ export class TableBodyComponent implements OnInit {
|
||||||
const loading$ = this.config.loading$ || of(false).pipe(shareReplay(1));
|
const loading$ = this.config.loading$ || of(false).pipe(shareReplay(1));
|
||||||
|
|
||||||
this.vm$ = combineLatest([
|
this.vm$ = combineLatest([
|
||||||
this.language$,
|
|
||||||
this.config.columns,
|
this.config.columns,
|
||||||
lineAction$,
|
lineAction$,
|
||||||
selection$,
|
selection$,
|
||||||
|
@ -57,7 +52,6 @@ export class TableBodyComponent implements OnInit {
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map((
|
map((
|
||||||
[
|
[
|
||||||
language,
|
|
||||||
columns,
|
columns,
|
||||||
lineActions,
|
lineActions,
|
||||||
selection,
|
selection,
|
||||||
|
@ -85,7 +79,6 @@ export class TableBodyComponent implements OnInit {
|
||||||
const selectionStatus = selection && selection.status || SelectionStatus.NONE;
|
const selectionStatus = selection && selection.status || SelectionStatus.NONE;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
language,
|
|
||||||
columns,
|
columns,
|
||||||
lineActions,
|
lineActions,
|
||||||
selection,
|
selection,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {FieldModule} from '@fields/field.module';
|
||||||
import {SortButtonModule} from '@components/sort-button/sort-button.module';
|
import {SortButtonModule} from '@components/sort-button/sort-button.module';
|
||||||
import {LineActionModule} from '@components/line-action-menu/line-action-menu.module';
|
import {LineActionModule} from '@components/line-action-menu/line-action-menu.module';
|
||||||
import {LoadingSpinnerModule} from '@components/loading-spinner/loading-spinner.module';
|
import {LoadingSpinnerModule} from '@components/loading-spinner/loading-spinner.module';
|
||||||
|
import {LabelModule} from '@components/label/label.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [TableBodyComponent],
|
declarations: [TableBodyComponent],
|
||||||
|
@ -21,7 +22,8 @@ import {LoadingSpinnerModule} from '@components/loading-spinner/loading-spinner.
|
||||||
FieldModule,
|
FieldModule,
|
||||||
SortButtonModule,
|
SortButtonModule,
|
||||||
LineActionModule,
|
LineActionModule,
|
||||||
LoadingSpinnerModule
|
LoadingSpinnerModule,
|
||||||
|
LabelModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class TableBodyModule {
|
export class TableBodyModule {
|
||||||
|
|
|
@ -111,7 +111,6 @@ export const tableConfigMock: TableConfig = {
|
||||||
importable: 'required',
|
importable: 'required',
|
||||||
merge_filter: 'selected'
|
merge_filter: 'selected'
|
||||||
},
|
},
|
||||||
translatedLabel: 'Name'
|
|
||||||
} as ColumnDefinition
|
} as ColumnDefinition
|
||||||
]),
|
]),
|
||||||
maxColumns$: of(4).pipe(shareReplay(1)),
|
maxColumns$: of(4).pipe(shareReplay(1)),
|
||||||
|
|
|
@ -26,6 +26,8 @@ export interface TableConfig {
|
||||||
bulkActions?: BulkActionDataSource;
|
bulkActions?: BulkActionDataSource;
|
||||||
pagination?: PaginationDataSource;
|
pagination?: PaginationDataSource;
|
||||||
|
|
||||||
|
module?: string;
|
||||||
|
|
||||||
toggleRecordSelection(id: string): void;
|
toggleRecordSelection(id: string): void;
|
||||||
|
|
||||||
updateSorting(orderBy: string, sortOrder: SortDirection): void;
|
updateSorting(orderBy: string, sortOrder: SortDirection): void;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {combineLatest, Observable, of} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {LanguageStore} from '@store/language/language.store';
|
|
||||||
import {SortDirection} from '@components/sort-button/sort-button.model';
|
import {SortDirection} from '@components/sort-button/sort-button.model';
|
||||||
import {TableConfig} from '@components/table/table.model';
|
import {TableConfig} from '@components/table/table.model';
|
||||||
import {ColumnDefinition} from '@app-common/metadata/list.metadata.model';
|
import {ColumnDefinition} from '@app-common/metadata/list.metadata.model';
|
||||||
|
@ -10,10 +9,7 @@ import {map} from 'rxjs/operators';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubpanelTableAdapter {
|
export class SubpanelTableAdapter {
|
||||||
|
|
||||||
constructor(
|
constructor(protected store: SubpanelStore) {
|
||||||
protected store: SubpanelStore,
|
|
||||||
protected language: LanguageStore
|
|
||||||
) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTable(): TableConfig {
|
getTable(): TableConfig {
|
||||||
|
@ -21,6 +17,8 @@ export class SubpanelTableAdapter {
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
showFooter: true,
|
showFooter: true,
|
||||||
|
|
||||||
|
module: this.store.metadata.headerModule,
|
||||||
|
|
||||||
columns: this.getColumns(),
|
columns: this.getColumns(),
|
||||||
sort$: this.store.recordList.sort$,
|
sort$: this.store.recordList.sort$,
|
||||||
maxColumns$: of(5),
|
maxColumns$: of(5),
|
||||||
|
@ -40,21 +38,6 @@ export class SubpanelTableAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getColumns(): Observable<ColumnDefinition[]> {
|
protected getColumns(): Observable<ColumnDefinition[]> {
|
||||||
|
return this.store.metadata$.pipe(map(metadata => metadata.columns));
|
||||||
return combineLatest([this.language.vm$, this.store.metadata$]).pipe(
|
|
||||||
map(([languages, metadata]) => {
|
|
||||||
const mapped: ColumnDefinition[] = [];
|
|
||||||
|
|
||||||
metadata.columns.forEach(column => {
|
|
||||||
const translatedLabel = this.language.getFieldLabel(column.label, metadata.headerModule, languages);
|
|
||||||
mapped.push({
|
|
||||||
...column,
|
|
||||||
translatedLabel
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return mapped;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class SubpanelComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.adapter = new SubpanelTableAdapter(this.store, this.languages);
|
this.adapter = new SubpanelTableAdapter(this.store);
|
||||||
this.tableConfig = this.adapter.getTable();
|
this.tableConfig = this.adapter.getTable();
|
||||||
if (this.maxColumns$) {
|
if (this.maxColumns$) {
|
||||||
this.tableConfig.maxColumns$ = this.maxColumns$;
|
this.tableConfig.maxColumns$ = this.maxColumns$;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import {combineLatest, Observable, of} from 'rxjs';
|
import {of} from 'rxjs';
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {MetadataStore} from '@store/metadata/metadata.store.service';
|
import {MetadataStore} from '@store/metadata/metadata.store.service';
|
||||||
import {map} from 'rxjs/operators';
|
|
||||||
import {LanguageStore} from '@store/language/language.store';
|
|
||||||
import {SortDirection} from '@components/sort-button/sort-button.model';
|
import {SortDirection} from '@components/sort-button/sort-button.model';
|
||||||
import {TableConfig} from '@components/table/table.model';
|
import {TableConfig} from '@components/table/table.model';
|
||||||
import {ColumnDefinition} from '@app-common/metadata/list.metadata.model';
|
|
||||||
import {ListViewStore} from '../store/list-view/list-view.store';
|
import {ListViewStore} from '../store/list-view/list-view.store';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -14,7 +11,6 @@ export class TableAdapter {
|
||||||
constructor(
|
constructor(
|
||||||
protected store: ListViewStore,
|
protected store: ListViewStore,
|
||||||
protected metadata: MetadataStore,
|
protected metadata: MetadataStore,
|
||||||
protected language: LanguageStore
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +19,9 @@ export class TableAdapter {
|
||||||
showHeader: true,
|
showHeader: true,
|
||||||
showFooter: true,
|
showFooter: true,
|
||||||
|
|
||||||
columns: this.getColumns(),
|
module: this.store.getModuleName(),
|
||||||
|
|
||||||
|
columns: this.store.columns$,
|
||||||
lineActions$: this.store.lineActions$,
|
lineActions$: this.store.lineActions$,
|
||||||
selection$: this.store.selection$,
|
selection$: this.store.selection$,
|
||||||
sort$: this.store.sort$,
|
sort$: this.store.sort$,
|
||||||
|
@ -44,24 +42,4 @@ export class TableAdapter {
|
||||||
},
|
},
|
||||||
} as TableConfig;
|
} as TableConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getColumns(): Observable<ColumnDefinition[]> {
|
|
||||||
return combineLatest(
|
|
||||||
[this.language.vm$, this.store.columns$, this.store.moduleName$]
|
|
||||||
).pipe(
|
|
||||||
map(([languages, columns, module]) => {
|
|
||||||
const mapped: ColumnDefinition[] = [];
|
|
||||||
|
|
||||||
columns.forEach(column => {
|
|
||||||
const translatedLabel = this.language.getFieldLabel(column.label, module, languages);
|
|
||||||
mapped.push({
|
|
||||||
...column,
|
|
||||||
translatedLabel
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return mapped;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue