data source changes

This commit is contained in:
David Lebee 2019-09-06 17:55:58 -05:00
parent bf08782a62
commit 9ec3000b85
3 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@poweredsoft/data",
"version": "0.0.18",
"version": "0.0.20",
"peerDependencies": {
"rxjs": "^6.5.3"
}

View File

@ -51,6 +51,7 @@ export class DataSource<TModel> implements IDataSource<TModel>
this._criteria.filters = copy.filters || this._criteria.filters;
this._criteria.groups = copy.groups || this._criteria.groups;
this._criteria.aggregates = copy.aggregates || this._criteria.aggregates;
this._criteria.sorts = copy.sorts || this._criteria.sorts;
}
protected _initSubjectObservables() {
@ -78,10 +79,10 @@ export class DataSource<TModel> implements IDataSource<TModel>
return this.options.transport.commands[name].adapter.handle(command);
}
query<TQuery extends IQueryCriteria>(query: TQuery) : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
private _query() : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
return Observable.create((o: Observer<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>) => {
this._loadingSubject.next(true);
this.options.transport.query.adapter.handle(query)
this.options.transport.query.adapter.handle(this._criteria)
.pipe(
finalize(() => {
o.complete();
@ -99,8 +100,18 @@ export class DataSource<TModel> implements IDataSource<TModel>
});
}
query<TQuery extends IQueryCriteria>(query: TQuery) {
this._criteria.page = query.page || this._criteria.page;
this._criteria.pageSize = query.pageSize || this._criteria.pageSize;
this._criteria.filters = query.filters || this._criteria.filters;
this._criteria.groups = query.groups || this._criteria.groups;
this._criteria.aggregates = query.aggregates || this._criteria.aggregates;
this._criteria.sorts = query.sorts || this._criteria.sorts;
return this.refresh();
}
refresh() {
return this.query(this._criteria).subscribe(
return this._query().subscribe(
res => {},
err => {}
);

View File

@ -6,7 +6,8 @@ export interface IDataSource<TModel>
{
resolveCommandModelByName<T extends any>(event: IResolveCommandModelEvent<TModel>) : Observable<T>;
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
query<TQuery extends IQueryCriteria>(query: TQuery) : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>;
query<TQuery extends IQueryCriteria>(query: TQuery);
refresh();
data$: Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>;
loading$: Observable<boolean>;