Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import errors from '@js/ui/widget/ui.errors';
import dataSourceAdapterProvider from '@ts/grids/data_grid/m_data_source_adapter';
import { DataSourceController } from '@ts/grids/grid_core/data_source/data_source_controller';
import type { DataSourceAdapterProvider } from '@ts/grids/grid_core/data_source_adapter/types';

export class DataGridDataSourceController extends DataSourceController {
protected getAdapterProvider(): DataSourceAdapterProvider {
return dataSourceAdapterProvider;
}

protected getSpecificDataSourceOption(): unknown {
const dataSource = this.option('dataSource');

if (dataSource && !Array.isArray(dataSource) && this.option('keyExpr')) {
errors.log('W1011');
}

return super.getSpecificDataSourceOption();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import gridCore from '@ts/grids/data_grid/m_core';

import { DataGridDataSourceController } from './data_source_controller';

gridCore.registerModule('dataSource', {
controllers: {
dataSource: DataGridDataSourceController,
},
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './module_not_extended/column_headers';
import './m_columns_controller';
import './m_data_controller';
import './data_source/data_source_module';
import './module_not_extended/data_controller';
import './module_not_extended/sorting';
import './module_not_extended/rows';
import './module_not_extended/context_menu';
Expand All @@ -24,6 +25,7 @@ import gridCore from './m_core';
const DATAGRID_DEPRECATED_TEMPLATE_WARNING = 'Specifying grid templates with the jQuery selector name is now deprecated. Use the DOM Node or the jQuery object that references this selector instead.';

gridCore.registerModulesOrder([
'dataSource',
'stateStoring',
'columns',
'selection',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { dataControllerModule } from '@ts/grids/grid_core/data_controller/data_controller';

import gridCore from '../m_core';

gridCore.registerModule('data', dataControllerModule);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { DataSource as DataSourceClass } from '@js/common/data/data_source/data_source';
import { normalizeDataSourceOptions } from '@js/common/data/data_source/utils';
import type { Callback } from '@js/core/utils/callbacks';
import { deferRender } from '@js/core/utils/common';
import { logger } from '@js/core/utils/console';
import type { DeferredObj } from '@js/core/utils/deferred';
import { Deferred, when } from '@js/core/utils/deferred';
import { extend } from '@js/core/utils/extend';
import { isDefined } from '@js/core/utils/type';
import type { StoreChange } from '@js/data/store';
import errors from '@js/ui/widget/ui.errors';
Expand All @@ -15,9 +12,10 @@ import type Store from '@ts/data/abstract_store';
import type { DataSource } from '@ts/data/data_source/data_source';
import type { ChangingEvent } from '@ts/data/data_source/types';
import type { Column, ColumnsChanges } from '@ts/grids/grid_core/columns_controller/types';
import type { DataSourceController } from '@ts/grids/grid_core/data_source/data_source_controller';
import type DataSourceAdapter from '@ts/grids/grid_core/data_source_adapter/m_data_source_adapter';
import type {
ChangedEvent, DataSourceAdapterProvider, LoadOperation, OperationTypes, RawItemData,
ChangedEvent, LoadOperation, OperationTypes, RawItemData,
} from '@ts/grids/grid_core/data_source_adapter/types';
import { isLocalStore } from '@ts/grids/grid_core/data_source_adapter/utils/store';
import modules from '@ts/grids/grid_core/m_modules';
Expand Down Expand Up @@ -72,8 +70,6 @@ import { generateRowValues } from './utils/row_values';
export class DataController extends modules.Controller {
public _dataSource?: DataSourceAdapter | null;

protected isSharedDataSource?: boolean;

protected _items!: ProcessedItem[];

private _cachedProcessedItems!: ProcessedItem[] | null;
Expand Down Expand Up @@ -126,6 +122,8 @@ export class DataController extends modules.Controller {

public rowIndicesChanged!: Callback<[RowIndexCorrection]>;

protected dataSourceController!: DataSourceController;

// TODO public controller
public _columnsController!: Controllers['columns'];

Expand All @@ -140,6 +138,7 @@ export class DataController extends modules.Controller {
public init(): void {
this._items = [];
this._cachedProcessedItems = null;
this.dataSourceController = this.getController('dataSource');
this._columnsController = this.getController('columns');
Comment thread
anna-shakhova marked this conversation as resolved.

this._isPaging = false;
Expand Down Expand Up @@ -643,22 +642,6 @@ export class DataController extends modules.Controller {
});
}

protected _getSpecificDataSourceOption(): unknown {
const dataSource = this.option('dataSource');

if (Array.isArray(dataSource)) {
return {
store: {
type: 'array',
data: dataSource,
key: this.option('keyExpr'),
},
};
}

return dataSource;
}

/**
* @extended: state_storing, virtual_scrolling
*/
Expand All @@ -672,7 +655,9 @@ export class DataController extends modules.Controller {
protected _initDataSource(): void {
const hadDataSource = !!this._dataSource;

const dataSource = this.recreateDataSource();
this._disposeDataSource();

const dataSource = this.dataSourceController.createDataSource();
this._useSortingGroupingFromColumns = true;
this._cachedProcessedItems = null;

Expand All @@ -686,27 +671,6 @@ export class DataController extends modules.Controller {
}
}

private recreateDataSource(): DataSource | undefined {
const dataSourceOptions = this._getSpecificDataSourceOption();

this._disposeDataSource();

if (!dataSourceOptions) {
this.isSharedDataSource = false;
return undefined;
}

if (dataSourceOptions instanceof DataSourceClass) {
this.isSharedDataSource = true;
return dataSourceOptions as unknown as DataSource;
}

this.isSharedDataSource = false;
return new DataSourceClass(
extend(true, {}, normalizeDataSourceOptions(dataSourceOptions, {})),
) as unknown as DataSource;
}

/**
* @extended: selection, virtual_scrolling
*/
Expand Down Expand Up @@ -1359,18 +1323,6 @@ export class DataController extends modules.Controller {
this.dataSourceChanged.fire();
};

protected _getDataSourceAdapterProvider(): DataSourceAdapterProvider {
throw new Error('Method not implemented.');
}

protected _createDataSourceAdapter(dataSource: DataSource): DataSourceAdapter {
const dataSourceAdapterProvider = this._getDataSourceAdapterProvider();
const dataSourceAdapter = dataSourceAdapterProvider.create(this.component);

dataSourceAdapter.init(dataSource);
return dataSourceAdapter;
}

private subscribeToDataSource(dataSourceAdapter: DataSourceAdapter): void {
dataSourceAdapter.changed.add(this.dataChangedHandlerProxy);
dataSourceAdapter.loadingChanged.add(this.loadingChangedHandler);
Expand All @@ -1389,29 +1341,17 @@ export class DataController extends modules.Controller {
dataSourceAdapter.pushed.remove(this.dataPushedHandlerProxy);
}

private setDataSource(dataSource: DataSource | null): void {
const oldDataSource = this._dataSource;

if (!dataSource && oldDataSource) {
oldDataSource.cancelAll();
this.unsubscribeFromDataSource(oldDataSource);
oldDataSource.dispose(this.isSharedDataSource);
}

const dataSourceAdapter = dataSource
? this._createDataSourceAdapter(dataSource)
: null;
private setDataSource(dataSource: DataSource): void {
const dataSourceAdapter = this.dataSourceController.createAdapter(dataSource);

this._dataSource = dataSourceAdapter;

if (dataSourceAdapter) {
this._isLoading = !dataSourceAdapter.isLoaded();
this._needApplyFilter = true;
this._isAllDataTypesDefined = this._columnsController.isAllDataTypesDefined();
this._isLoading = !dataSourceAdapter.isLoaded();
this._needApplyFilter = true;
this._isAllDataTypesDefined = this._columnsController.isAllDataTypesDefined();

this.changed.add(this.fireDataSourceChanged);
this.subscribeToDataSource(dataSourceAdapter);
}
this.changed.add(this.fireDataSourceChanged);
this.subscribeToDataSource(dataSourceAdapter);
}

/**
Expand Down Expand Up @@ -1650,7 +1590,16 @@ export class DataController extends modules.Controller {
}

protected _disposeDataSource(): void {
this.setDataSource(null);
const oldDataSource = this._dataSource;

if (oldDataSource) {
// Before unsubscribing: cancelling in-flight loads still notifies this controller.
oldDataSource.cancelAll();
this.unsubscribeFromDataSource(oldDataSource);
}

this._dataSource = null;
this.dataSourceController.disposeAdapter();
}

public dispose(): void {
Expand Down
Loading
Loading