2020-05-28 22:35:45 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2023-01-17 08:52:26 +01:00
|
|
|
// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team
|
2020-05-28 22:35:45 +02:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// This IDE expert is based off of the one included with the DUnitX }
|
|
|
|
// project. Original source by Robert Love. Adapted by Nick Hodges. }
|
|
|
|
//
|
|
|
|
// The DUnitX project is run by Vincent Parrett and can be found at: }
|
|
|
|
//
|
|
|
|
// https://github.com/VSoftTechnologies/DUnitX }
|
|
|
|
// ***************************************************************************
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
unit DMVC.Expert.Forms.NewProjectWizard;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
WinAPI.Windows,
|
|
|
|
WinAPI.Messages,
|
2016-11-24 20:07:45 +01:00
|
|
|
WinAPI.ShellAPI,
|
2016-02-23 01:41:13 +01:00
|
|
|
System.SysUtils,
|
|
|
|
System.Variants,
|
|
|
|
System.Classes,
|
|
|
|
VCL.Graphics,
|
|
|
|
VCL.Controls,
|
|
|
|
VCL.Forms,
|
|
|
|
VCL.Dialogs,
|
2016-11-24 20:07:45 +01:00
|
|
|
VCL.StdCtrls,
|
2023-01-17 09:03:19 +01:00
|
|
|
VCL.Imaging.pngimage,
|
|
|
|
VCL.ExtCtrls,
|
|
|
|
System.Actions,
|
|
|
|
Vcl.ActnList,
|
|
|
|
Vcl.AppEvnts;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
type
|
|
|
|
TfrmDMVCNewProject = class(TForm)
|
|
|
|
btnOK: TButton;
|
|
|
|
btnCancel: TButton;
|
|
|
|
chkAddToProjectGroup: TCheckBox;
|
|
|
|
edtWebModuleName: TEdit;
|
|
|
|
lblWbModule: TLabel;
|
2016-02-24 22:37:13 +01:00
|
|
|
edtServerPort: TEdit;
|
|
|
|
Label2: TLabel;
|
2016-11-24 20:07:45 +01:00
|
|
|
Image1: TImage;
|
2017-05-09 10:49:28 +02:00
|
|
|
lblFrameworkVersion: TLabel;
|
2022-07-25 10:36:30 +02:00
|
|
|
Panel2: TPanel;
|
|
|
|
gbControllerUnitOptions: TGroupBox;
|
|
|
|
lblClassName: TLabel;
|
|
|
|
Label1: TLabel;
|
|
|
|
chkCreateIndexMethod: TCheckBox;
|
|
|
|
edtClassName: TEdit;
|
|
|
|
chkCreateActionFiltersMethods: TCheckBox;
|
|
|
|
chkCreateCRUDMethods: TCheckBox;
|
|
|
|
chkCreateControllerUnit: TCheckBox;
|
|
|
|
Shape1: TShape;
|
2022-08-13 00:21:00 +02:00
|
|
|
GroupBox1: TGroupBox;
|
|
|
|
chkAnalyticsMiddleware: TCheckBox;
|
|
|
|
chkCompression: TCheckBox;
|
|
|
|
chkStaticFiles: TCheckBox;
|
|
|
|
chkTrace: TCheckBox;
|
|
|
|
chkCORS: TCheckBox;
|
2022-08-13 10:35:53 +02:00
|
|
|
chkETAG: TCheckBox;
|
|
|
|
lblBook: TLabel;
|
2022-08-13 16:10:19 +02:00
|
|
|
chkActiveRecord: TCheckBox;
|
|
|
|
EdtFDConnDefFileName: TEdit;
|
|
|
|
GroupBoxJSONRPC: TGroupBox;
|
|
|
|
Label3: TLabel;
|
|
|
|
EdtJSONRPCClassName: TEdit;
|
|
|
|
chkJSONRPC: TCheckBox;
|
|
|
|
Label4: TLabel;
|
|
|
|
Bevel1: TBevel;
|
|
|
|
Label5: TLabel;
|
|
|
|
EdtConnDefName: TEdit;
|
|
|
|
ApplicationEvents: TApplicationEvents;
|
2023-01-17 09:03:19 +01:00
|
|
|
lblCopyRight: TLabel;
|
2023-10-23 11:05:07 +02:00
|
|
|
chkMSHeap: TCheckBox;
|
2016-02-23 01:41:13 +01:00
|
|
|
procedure chkCreateControllerUnitClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
2016-11-24 20:07:45 +01:00
|
|
|
procedure Image1Click(Sender: TObject);
|
2020-08-22 15:37:08 +02:00
|
|
|
procedure lblBookMouseEnter(Sender: TObject);
|
|
|
|
procedure lblBookMouseLeave(Sender: TObject);
|
|
|
|
procedure lblBookClick(Sender: TObject);
|
2022-07-25 10:36:30 +02:00
|
|
|
procedure lblFrameworkVersionMouseEnter(Sender: TObject);
|
|
|
|
procedure lblFrameworkVersionMouseLeave(Sender: TObject);
|
|
|
|
procedure lblFrameworkVersionClick(Sender: TObject);
|
2022-08-13 16:10:19 +02:00
|
|
|
procedure ApplicationEventsIdle(Sender: TObject; var Done: Boolean);
|
|
|
|
procedure btnOKClick(Sender: TObject);
|
2016-02-23 01:41:13 +01:00
|
|
|
private
|
|
|
|
{ Private declarations }
|
|
|
|
function GetAddToProjectGroup: boolean;
|
|
|
|
function GetCreateIndexMethod: boolean;
|
|
|
|
function GetCreateControllerUnit: boolean;
|
|
|
|
function GetControllerClassName: string;
|
|
|
|
function GetWebModuleClassName: string;
|
2016-02-24 22:37:13 +01:00
|
|
|
function GetCreateActionFiltersMethods: boolean;
|
|
|
|
function GetServerPort: Integer;
|
2017-05-17 22:32:45 +02:00
|
|
|
function GetCreateCRUDMethods: boolean;
|
2018-08-05 20:31:33 +02:00
|
|
|
function GetMiddlewares: TArray<String>;
|
2022-07-25 10:36:30 +02:00
|
|
|
function GetCreateJSONRPCInterface: boolean;
|
|
|
|
function GetJSONRPCClassName: String;
|
2023-10-23 11:05:07 +02:00
|
|
|
function GetUseMSHeapOnWindows: Boolean;
|
2016-02-23 01:41:13 +01:00
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
// Read Only Properties to extract values without having to know control values.
|
|
|
|
property ControllerClassName: string read GetControllerClassName;
|
2016-02-24 22:37:13 +01:00
|
|
|
property CreateControllerUnit: boolean read GetCreateControllerUnit;
|
2022-07-25 10:36:30 +02:00
|
|
|
property JSONRPCClassName: String read GetJSONRPCClassName;
|
2016-02-24 22:37:13 +01:00
|
|
|
property AddToProjectGroup: boolean read GetAddToProjectGroup;
|
|
|
|
property CreateIndexMethod: boolean read GetCreateIndexMethod;
|
2017-05-17 22:32:45 +02:00
|
|
|
property CreateCRUDMethods: boolean read GetCreateCRUDMethods;
|
2018-08-05 20:31:33 +02:00
|
|
|
property Middlewares: TArray<String> read GetMiddlewares;
|
2016-02-24 22:37:13 +01:00
|
|
|
property CreateActionFiltersMethods: boolean
|
|
|
|
read GetCreateActionFiltersMethods;
|
2016-02-23 01:41:13 +01:00
|
|
|
property WebModuleClassName: string read GetWebModuleClassName;
|
2016-02-24 22:37:13 +01:00
|
|
|
property ServerPort: Integer read GetServerPort;
|
2023-10-23 11:05:07 +02:00
|
|
|
property UseMSHeapOnWindows: Boolean read GetUseMSHeapOnWindows;
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
frmDMVCNewProject: TfrmDMVCNewProject;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2017-05-09 10:49:28 +02:00
|
|
|
DMVC.Expert.CodeGen.Templates,
|
2023-01-17 09:03:19 +01:00
|
|
|
MVCFramework.Commons,
|
|
|
|
System.StrUtils;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2022-08-13 16:10:19 +02:00
|
|
|
procedure TfrmDMVCNewProject.ApplicationEventsIdle(Sender: TObject;
|
|
|
|
var Done: Boolean);
|
|
|
|
begin
|
|
|
|
EdtFDConnDefFileName.Enabled := chkActiveRecord.Checked;
|
|
|
|
EdtConnDefName.Enabled := chkActiveRecord.Checked;
|
|
|
|
EdtJSONRPCClassName.Enabled := chkJSONRPC.Checked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.btnOKClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if chkActiveRecord.Checked then
|
|
|
|
begin
|
|
|
|
ShowMessage('Remember to include required FireDAC units in your project');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
procedure TfrmDMVCNewProject.chkCreateControllerUnitClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
chkCreateIndexMethod.Enabled := chkCreateControllerUnit.Checked;
|
2016-10-10 16:09:43 +02:00
|
|
|
chkCreateActionFiltersMethods.Enabled := chkCreateControllerUnit.Checked;
|
2020-05-28 22:35:45 +02:00
|
|
|
chkCreateCRUDMethods.Enabled := chkCreateControllerUnit.Checked;
|
2016-02-23 01:41:13 +01:00
|
|
|
edtClassName.Enabled := chkCreateControllerUnit.Checked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
edtClassName.TextHint := sDefaultControllerName;
|
|
|
|
edtWebModuleName.TextHint := sDefaultWebModuleName;
|
2016-02-24 22:37:13 +01:00
|
|
|
edtServerPort.TextHint := sDefaultServerPort;
|
2022-08-13 16:10:19 +02:00
|
|
|
lblFrameworkVersion.Caption := 'dmvcframework-' + DMVCFRAMEWORK_VERSION;
|
2022-07-25 10:36:30 +02:00
|
|
|
chkJSONRPC.Checked := False;
|
2023-01-17 09:03:19 +01:00
|
|
|
lblCopyRight.Caption := TMVCConstants.COPYRIGHT;
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TfrmDMVCNewProject.GetAddToProjectGroup: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkAddToProjectGroup.Checked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TfrmDMVCNewProject.GetCreateIndexMethod: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkCreateIndexMethod.Checked;
|
|
|
|
end;
|
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
function TfrmDMVCNewProject.GetCreateJSONRPCInterface: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkJSONRPC.Checked;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TfrmDMVCNewProject.GetJSONRPCClassName: String;
|
|
|
|
begin
|
|
|
|
if GetCreateJSONRPCInterface then
|
|
|
|
begin
|
|
|
|
Result := EdtJSONRPCClassName.Text;
|
|
|
|
if Result.IsEmpty then
|
|
|
|
begin
|
|
|
|
Result := EdtJSONRPCClassName.TextHint;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-08-05 20:31:33 +02:00
|
|
|
function TfrmDMVCNewProject.GetMiddlewares: TArray<String>;
|
2022-08-13 00:21:00 +02:00
|
|
|
const
|
|
|
|
M_ANALYTICS = 'FMVC.AddMiddleware(TMVCAnalyticsMiddleware.Create(GetAnalyticsDefaultLogger));';
|
|
|
|
M_STATICFILES = 'FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create(''/static'', TPath.Combine(ExtractFilePath(GetModuleName(HInstance)), ''www'')));';
|
|
|
|
M_TRACE = 'FMVC.AddMiddleware(TMVCTraceMiddleware.Create);';
|
2022-08-13 10:35:53 +02:00
|
|
|
M_COMPRESSION = 'FMVC.AddMiddleware(TMVCCompressionMiddleware.Create);';
|
|
|
|
M_ETAG = 'FMVC.AddMiddleware(TMVCETagMiddleware.Create);';
|
2022-08-13 00:21:00 +02:00
|
|
|
M_CORS = 'FMVC.AddMiddleware(TMVCCORSMiddleware.Create);';
|
2023-06-06 13:00:21 +02:00
|
|
|
M_ACTIVERECORD = 'FMVC.AddMiddleware(TMVCActiveRecordMiddleware.Create(' + sLineBreak +
|
|
|
|
' dotEnv.Env(''firedac.connection_definition_name'', ''%s''), ' + sLineBreak +
|
|
|
|
' dotEnv.Env(''firedac.connection_definitions_filename'', ''%s'')' + sLineBreak +
|
|
|
|
' ));';
|
2022-08-13 16:10:19 +02:00
|
|
|
|
|
|
|
function GetText(const Edit: TCustomEdit): String;
|
|
|
|
begin
|
|
|
|
if Edit.Text = '' then
|
|
|
|
begin
|
|
|
|
Result := Edit.TextHint;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result := Edit.Text;
|
|
|
|
end;
|
|
|
|
end;
|
2018-08-05 20:31:33 +02:00
|
|
|
begin
|
|
|
|
Result := [];
|
2023-06-06 13:00:21 +02:00
|
|
|
Result := Result + ['', '// Analytics middleware generates a csv log, useful to do traffic analysis'];
|
2022-08-13 00:21:00 +02:00
|
|
|
Result := Result + [ifthen(not chkAnalyticsMiddleware.Checked, '//') + M_ANALYTICS];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// The folder mapped as documentroot for TMVCStaticFilesMiddleware must exists!'];
|
2022-08-13 00:21:00 +02:00
|
|
|
Result := Result + [ifthen(not chkStaticFiles.Checked, '//') + M_STATICFILES];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// Trace middlewares produces a much detailed log for debug purposes'];
|
2022-08-13 00:21:00 +02:00
|
|
|
Result := Result + [ifthen(not chkTrace.Checked, '//') + M_TRACE];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// CORS middleware handles... well, CORS'];
|
2022-08-13 00:21:00 +02:00
|
|
|
Result := Result + [ifthen(not chkCORS.Checked, '//') + M_CORS];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// Simplifies TMVCActiveRecord connection definition'];
|
2023-06-06 17:33:37 +02:00
|
|
|
Result := Result + [
|
|
|
|
ifthen(not chkActiveRecord.Checked, '{') + sLineBreak +
|
|
|
|
' ' + Format(M_ACTIVERECORD, [GetText(EdtConnDefName), GetText(EdtFDConnDefFileName)]) + sLineBreak +
|
|
|
|
ifthen(not chkActiveRecord.Checked, ' }') + sLineBreak
|
|
|
|
];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// Compression middleware must be the last in the chain, just before the ETag, if present.'];
|
2022-08-13 00:21:00 +02:00
|
|
|
Result := Result + [ifthen(not chkCompression.Checked, '//') + M_COMPRESSION];
|
2022-08-13 16:10:19 +02:00
|
|
|
Result := Result + ['', '// ETag middleware must be the latest in the chain'];
|
2022-08-13 10:35:53 +02:00
|
|
|
Result := Result + [ifthen(not chkETAG.Checked, '//') + M_ETAG];
|
2018-08-05 20:31:33 +02:00
|
|
|
end;
|
|
|
|
|
2016-02-24 22:37:13 +01:00
|
|
|
function TfrmDMVCNewProject.GetServerPort: Integer;
|
|
|
|
var
|
|
|
|
lServerPort: Integer;
|
|
|
|
begin
|
|
|
|
Result := StrToInt(sDefaultServerPort);
|
|
|
|
if (Trim(edtServerPort.Text) <> '') and TryStrToInt(edtServerPort.Text,
|
|
|
|
lServerPort) then
|
|
|
|
begin
|
|
|
|
if (lServerPort > 0) and (lServerPort < 65535) then
|
|
|
|
Result := lServerPort;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2023-10-23 11:05:07 +02:00
|
|
|
function TfrmDMVCNewProject.GetUseMSHeapOnWindows: Boolean;
|
|
|
|
begin
|
|
|
|
Result := chkMSHeap.Checked;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
function TfrmDMVCNewProject.GetWebModuleClassName: string;
|
|
|
|
begin
|
|
|
|
if Trim(edtWebModuleName.Text) = '' then
|
|
|
|
begin
|
|
|
|
Result := sDefaultWebModuleName
|
2016-02-24 22:37:13 +01:00
|
|
|
end
|
|
|
|
else
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
|
|
|
Result := Trim(edtWebModuleName.Text);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-11-24 20:07:45 +01:00
|
|
|
procedure TfrmDMVCNewProject.Image1Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ShellExecute(0, PChar('open'),
|
2020-08-22 15:37:08 +02:00
|
|
|
PChar('https://github.com/danieleteti/delphimvcframework'),
|
2016-11-24 20:07:45 +01:00
|
|
|
nil, nil, SW_SHOW);
|
|
|
|
end;
|
|
|
|
|
2020-08-22 15:37:08 +02:00
|
|
|
procedure TfrmDMVCNewProject.lblBookClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ShellExecute(0, PChar('open'),
|
|
|
|
PChar('https://leanpub.com/delphimvcframework'),
|
|
|
|
nil, nil, SW_SHOW);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.lblBookMouseEnter(Sender: TObject);
|
|
|
|
begin
|
|
|
|
lblBook.Font.Color := clHighlight;
|
|
|
|
lblBook.Font.Style := lblBook.Font.Style + [fsUnderline];
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.lblBookMouseLeave(Sender: TObject);
|
|
|
|
begin
|
|
|
|
lblBook.Font.Color := Font.Color;
|
|
|
|
lblBook.Font.Style := lblBook.Font.Style - [fsUnderline];
|
|
|
|
end;
|
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
procedure TfrmDMVCNewProject.lblFrameworkVersionClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ShellExecute(0, PChar('open'),
|
|
|
|
PChar('https://github.com/danieleteti/delphimvcframework/releases/latest'),
|
|
|
|
nil, nil, SW_SHOW);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.lblFrameworkVersionMouseEnter(Sender: TObject);
|
|
|
|
begin
|
|
|
|
lblFrameworkVersion.Font.Color := clHighlight;
|
|
|
|
lblFrameworkVersion.Font.Style := lblFrameworkVersion.Font.Style + [fsUnderline];
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmDMVCNewProject.lblFrameworkVersionMouseLeave(Sender: TObject);
|
|
|
|
begin
|
|
|
|
lblFrameworkVersion.Font.Color := Font.Color;
|
|
|
|
lblFrameworkVersion.Font.Style := lblFrameworkVersion.Font.Style - [fsUnderline];
|
|
|
|
end;
|
|
|
|
|
2016-02-24 22:37:13 +01:00
|
|
|
function TfrmDMVCNewProject.GetCreateActionFiltersMethods: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkCreateActionFiltersMethods.Checked;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
function TfrmDMVCNewProject.GetCreateControllerUnit: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkCreateControllerUnit.Checked;
|
|
|
|
end;
|
|
|
|
|
2017-05-17 22:32:45 +02:00
|
|
|
function TfrmDMVCNewProject.GetCreateCRUDMethods: boolean;
|
|
|
|
begin
|
|
|
|
Result := chkCreateCRUDMethods.Checked;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
function TfrmDMVCNewProject.GetControllerClassName: string;
|
|
|
|
begin
|
|
|
|
if Trim(edtClassName.Text) = '' then
|
|
|
|
begin
|
|
|
|
Result := sDefaultControllerName
|
2016-02-24 22:37:13 +01:00
|
|
|
end
|
|
|
|
else
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
|
|
|
Result := Trim(edtClassName.Text);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|