mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 11:00:40 +08:00
Add Record List Modal Store
- Use base record list store - Get metadata for the initialized module -- Add metadataLoading Observable - Load data after metadata is returned - Add store factory - Split record list meta from listview meta -- Use record list meta definition
This commit is contained in:
parent
eb56608933
commit
c455b862fd
4 changed files with 107 additions and 2 deletions
|
@ -5,13 +5,16 @@ import {ChartTypesMap} from '@app-common/containers/chart/chart.model';
|
|||
import {WidgetMetadata} from '@app-common/metadata/widget.metadata';
|
||||
import {FieldDefinition} from '@app-common/record/field.model';
|
||||
|
||||
export interface ListViewMeta {
|
||||
export interface RecordListMeta {
|
||||
fields: ColumnDefinition[];
|
||||
bulkActions: BulkActionsMap;
|
||||
lineActions: LineAction[];
|
||||
filters: Filter[];
|
||||
}
|
||||
|
||||
export interface ListViewMeta extends RecordListMeta {
|
||||
chartTypes: ChartTypesMap;
|
||||
sidebarWidgets?: WidgetMetadata[];
|
||||
filters: Filter[];
|
||||
}
|
||||
|
||||
export interface Filter {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {RecordListStoreFactory} from '@store/record-list/record-list.store.factory';
|
||||
import {RecordListModalStore} from '@containers/record-list-modal/store/record-list-modal/record-list-modal.store';
|
||||
import {MetadataStore} from '@store/metadata/metadata.store.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RecordListModalStoreFactory {
|
||||
|
||||
constructor(
|
||||
protected listStoreFactory: RecordListStoreFactory,
|
||||
protected metadataStore: MetadataStore,
|
||||
) {
|
||||
}
|
||||
|
||||
create(): RecordListModalStore {
|
||||
return new RecordListModalStore(this.listStoreFactory, this.metadataStore);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import {RecordListModalStoreFactory} from '@containers/record-list-modal/store/record-list-modal/record-list-modal.store.factory';
|
||||
import {metadataStoreMock} from '@store/metadata/metadata.store.spec.mock';
|
||||
import {listStoreFactoryMock} from '@store/record-list/record-list.store.spec.mock';
|
||||
|
||||
export const recordlistModalStoreFactoryMock = new RecordListModalStoreFactory(
|
||||
listStoreFactoryMock,
|
||||
metadataStoreMock
|
||||
);
|
|
@ -0,0 +1,74 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {StateStore} from '@store/state';
|
||||
import {RecordList, RecordListStore} from '@store/record-list/record-list.store';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {RecordListStoreFactory} from '@store/record-list/record-list.store.factory';
|
||||
import {ColumnDefinition, RecordListMeta} from '@app-common/metadata/list.metadata.model';
|
||||
import {MetadataStore} from '@store/metadata/metadata.store.service';
|
||||
import {map, take, tap} from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class RecordListModalStore implements StateStore {
|
||||
|
||||
recordList: RecordListStore;
|
||||
metadata$: Observable<RecordListMeta>;
|
||||
columns$: Observable<ColumnDefinition[]>;
|
||||
metadata: RecordListMeta;
|
||||
loading$: Observable<boolean>;
|
||||
metadataLoading$: Observable<boolean>;
|
||||
protected metadataLoadingState: BehaviorSubject<boolean>;
|
||||
|
||||
constructor(
|
||||
protected listStoreFactory: RecordListStoreFactory,
|
||||
protected meta: MetadataStore,
|
||||
) {
|
||||
this.recordList = listStoreFactory.create();
|
||||
this.loading$ = this.recordList.loading$;
|
||||
|
||||
this.metadataLoadingState = new BehaviorSubject(false);
|
||||
this.metadataLoading$ = this.metadataLoadingState.asObservable();
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.recordList.clear();
|
||||
this.recordList = null;
|
||||
}
|
||||
|
||||
clearAuthBased(): void {
|
||||
this.recordList.clearAuthBased();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial list records load if not cached and update state.
|
||||
* Returns observable to be used in resolver if needed
|
||||
*
|
||||
* @param {string} module name
|
||||
*/
|
||||
public init(module: string): void {
|
||||
|
||||
this.metadataLoadingState.next(true);
|
||||
this.metadata$ = this.meta.getMetadata(module).pipe(
|
||||
map(meta => meta.listView),
|
||||
tap(() => {
|
||||
this.metadataLoadingState.next(false);
|
||||
this.recordList.load().pipe(
|
||||
take(1)
|
||||
).subscribe();
|
||||
})
|
||||
);
|
||||
this.recordList.init(module, false, 'list_max_entries_per_subpanel');
|
||||
this.columns$ = this.metadata$.pipe(map(metadata => metadata.fields));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load / reload records using current pagination and criteria
|
||||
*
|
||||
* @param {boolean} useCache if to use cache
|
||||
* @returns {object} Observable<RecordList>
|
||||
*/
|
||||
public load(useCache = true): Observable<RecordList> {
|
||||
|
||||
return this.recordList.load(useCache);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue