|
@@ -55,6 +55,13 @@ Type
|
|
|
Procedure HandleRequest(ARequest: TRequest; AResponse: TResponse); override;
|
|
|
end;
|
|
|
|
|
|
+ { TReportListModule }
|
|
|
+
|
|
|
+ TReportListModule = class(TCustomHTTPModule)
|
|
|
+ Public
|
|
|
+ Procedure HandleRequest(ARequest: TRequest; AResponse: TResponse); override;
|
|
|
+ end;
|
|
|
+
|
|
|
implementation
|
|
|
|
|
|
|
|
@@ -73,6 +80,7 @@ uses
|
|
|
fppdf,
|
|
|
fpreportpdfexport,
|
|
|
{$ENDIF}
|
|
|
+ fpjson,
|
|
|
fpmimetypes;
|
|
|
|
|
|
Type
|
|
@@ -108,6 +116,45 @@ Type
|
|
|
|
|
|
Var Counter : Integer;
|
|
|
|
|
|
+{ TReportListModule }
|
|
|
+
|
|
|
+procedure TReportListModule.HandleRequest(ARequest: TRequest; AResponse: TResponse);
|
|
|
+
|
|
|
+Var
|
|
|
+ O,RO : TJSONObject;
|
|
|
+ A : TJSONArray;
|
|
|
+ L : TStrings;
|
|
|
+ I : integer;
|
|
|
+ R : TReportDef;
|
|
|
+ S,D : String;
|
|
|
+
|
|
|
+begin
|
|
|
+ L:=Nil;
|
|
|
+ A:=Nil;
|
|
|
+ O:=TJSONObject.Create();
|
|
|
+ try
|
|
|
+ A:=TJSONArray.Create;
|
|
|
+ O.Add('data',A);
|
|
|
+ L:=TStringList.Create;
|
|
|
+ TReportDemoApplication.GetRegisteredReports(L);
|
|
|
+ For I:=0 to L.Count-1 do
|
|
|
+ begin
|
|
|
+ R:=TReportDef(L.Objects[i]);
|
|
|
+ D:=R.ReportClass.Description;
|
|
|
+ S:=L[i];
|
|
|
+ if D='' then D:=S;
|
|
|
+ A.Add(TJSONObject.Create(['name',S,'description',D]));
|
|
|
+ end;
|
|
|
+ AResponse.ContentType:='application/json';
|
|
|
+ AResponse.Content:=O.AsJSON;
|
|
|
+ AResponse.ContentLength:=Length(AResponse.Content);
|
|
|
+ AResponse.SendContent;
|
|
|
+ finally
|
|
|
+ L.Free;
|
|
|
+ O.Free;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
{ TViewReportModule }
|
|
|
|
|
|
procedure TViewReportModule.HandleRequest(ARequest: TRequest;
|
|
@@ -420,12 +467,18 @@ Var
|
|
|
Fmt : TRenderFormat;
|
|
|
FRunner : TReportRunner;
|
|
|
RC : TFPReportExporterClass;
|
|
|
+ Flds : TStrings;
|
|
|
|
|
|
begin
|
|
|
- D:=ARequest.ContentFields.Values['demo'];
|
|
|
+ if SameText(ARequest.Method,'GET') then
|
|
|
+ flds:=ARequest.QueryFields
|
|
|
+ else
|
|
|
+ flds:=ARequest.ContentFields;
|
|
|
+ flds.SaveToFile('/tmp/vars.txt');
|
|
|
+ D:=Flds.Values['demo'];
|
|
|
if (D='') or (TReportDemoApplication.GetReportClass(D)=Nil) then
|
|
|
Raise Exception.CreateFmt('Invalid or empty demo name : "%s"',[D]);
|
|
|
- F:=ARequest.ContentFields.Values['format'];
|
|
|
+ F:=flds.Values['format'];
|
|
|
Fmt:=High(TRenderFormat);
|
|
|
While (fmt>rfDefault) and (CompareText(TReportDemoApplication.FormatName(fmt),F)<>0) do
|
|
|
fmt:=Pred(fmt);
|
|
@@ -442,7 +495,7 @@ begin
|
|
|
FN:=D+IntToStr(Counter);
|
|
|
FN:=FN+PathDelim+FN+RC.DefaultExtension;
|
|
|
FRunner.BaseOutputFileName:=GetTempDir+FN;
|
|
|
- Conf:= TReportConfigurator.Create(ARequest.ContentFields);
|
|
|
+ Conf:= TReportConfigurator.Create(flds);
|
|
|
Try
|
|
|
FRunner.OnInitExporter:[email protected];
|
|
|
FRunner.Execute;
|
|
@@ -698,10 +751,12 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+
|
|
|
initialization
|
|
|
TPageReportModule.RegisterModule('Page',True);
|
|
|
TGenerateReportModule.RegisterModule('Generate',True);
|
|
|
TViewReportModule.RegisterModule('View',True);
|
|
|
+ TReportListModule.RegisterModule('ReportList',True);
|
|
|
HTTPRouter.RegisterRoute('/*',@ShowPage,true);
|
|
|
end.
|
|
|
|