mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-16 18:09:06 +02:00
* Support for sorting server result
This commit is contained in:
parent
4a425c3263
commit
926b346609
@ -102,6 +102,8 @@ Type
|
|||||||
FParams: TQueryParams;
|
FParams: TQueryParams;
|
||||||
FResourceID: String;
|
FResourceID: String;
|
||||||
FResourceName: String;
|
FResourceName: String;
|
||||||
|
FServerSortDescFields: String;
|
||||||
|
FServerSortFields: String;
|
||||||
FSQL: TStrings;
|
FSQL: TStrings;
|
||||||
function CleanSQL: String;
|
function CleanSQL: String;
|
||||||
function CustomViewResourceName: String;
|
function CustomViewResourceName: String;
|
||||||
@ -110,6 +112,8 @@ Type
|
|||||||
procedure SetParams(AValue: TQueryParams);
|
procedure SetParams(AValue: TQueryParams);
|
||||||
procedure SetResourceID(AValue: String);
|
procedure SetResourceID(AValue: String);
|
||||||
procedure SetResourceName(AValue: String);
|
procedure SetResourceName(AValue: String);
|
||||||
|
procedure SetServerSortDescFields(AValue: String);
|
||||||
|
procedure SetServerSortFields(AValue: String);
|
||||||
procedure SetSQL(AValue: TStrings);
|
procedure SetSQL(AValue: TStrings);
|
||||||
Protected
|
Protected
|
||||||
Procedure DoAfterPost; override;
|
Procedure DoAfterPost; override;
|
||||||
@ -148,11 +152,15 @@ Type
|
|||||||
Property OnGetQueryParams : TGetQueryParamsEvent Read FOnGetQueryParams Write FOnGetQueryParams;
|
Property OnGetQueryParams : TGetQueryParamsEvent Read FOnGetQueryParams Write FOnGetQueryParams;
|
||||||
// Always immediatly call ApplyUpdates after post and delete.
|
// Always immediatly call ApplyUpdates after post and delete.
|
||||||
Property AutoApplyUpdates : Boolean Read FAutoApplyUpdates Write FAutoApplyUpdates;
|
Property AutoApplyUpdates : Boolean Read FAutoApplyUpdates Write FAutoApplyUpdates;
|
||||||
|
// Fields to sort on the server
|
||||||
|
Property ServerSortFields : String Read FServerSortFields Write SetServerSortFields;
|
||||||
|
// Fields in ServerSortFields that must be descending
|
||||||
|
Property ServerSortDescFields : String Read FServerSortDescFields Write SetServerSortDescFields;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses DateUtils;
|
uses Types, StrUtils, DateUtils;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
|
|
||||||
@ -437,6 +445,8 @@ function TSQLDBRestDataset.GetURLQueryParams(IsRead :Boolean) : string;
|
|||||||
|
|
||||||
Var
|
Var
|
||||||
I : Integer;
|
I : Integer;
|
||||||
|
Sort,S,FN : String;
|
||||||
|
DFN : TStringDynArray;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
@ -446,6 +456,22 @@ begin
|
|||||||
AddToResult('SQL='+EncodeURIComponent(CleanSQL));
|
AddToResult('SQL='+EncodeURIComponent(CleanSQL));
|
||||||
For I:=0 to Params.Count-1 do
|
For I:=0 to Params.Count-1 do
|
||||||
AddToResult(Params[I].AsQuery);
|
AddToResult(Params[I].AsQuery);
|
||||||
|
Sort:='';
|
||||||
|
DFN:=StrUtils.SplitString(ServerSortDescFields,',');
|
||||||
|
For S in StrUtils.SplitString(ServerSortFields,',') do
|
||||||
|
begin
|
||||||
|
FN:=Trim(S);
|
||||||
|
if (FN<>'') then
|
||||||
|
begin
|
||||||
|
if Sort<>'' then
|
||||||
|
Sort:=Sort+',';
|
||||||
|
Sort:=Sort+EncodeURIComponent(FN);
|
||||||
|
if TJSArray(DFN).indexOf(FN)<>-1 then
|
||||||
|
Sort:=Sort+EncodeURIComponent(' desc');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if Sort<>'' then
|
||||||
|
AddToResult('sort='+Sort);
|
||||||
end;
|
end;
|
||||||
if Assigned(FOnGetQueryParams) then
|
if Assigned(FOnGetQueryParams) then
|
||||||
FOnGetQueryParams(Self,IsRead,Result);
|
FOnGetQueryParams(Self,IsRead,Result);
|
||||||
@ -483,6 +509,19 @@ begin
|
|||||||
FResourceName:=AValue;
|
FResourceName:=AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSQLDBRestDataset.SetServerSortDescFields(AValue: String);
|
||||||
|
begin
|
||||||
|
CheckInactive;
|
||||||
|
if FServerSortDescFields=AValue then Exit;
|
||||||
|
FServerSortDescFields:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSQLDBRestDataset.SetServerSortFields(AValue: String);
|
||||||
|
begin
|
||||||
|
if FServerSortFields=AValue then Exit;
|
||||||
|
FServerSortFields:=AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSQLDBRestDataset.CustomViewResourceName : String;
|
function TSQLDBRestDataset.CustomViewResourceName : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user