mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 13:59:31 +02:00
* Add missing columns dialog
This commit is contained in:
parent
e13451a5ab
commit
4b2aa144df
129
components/pas2js/components/frmaddmissingtablecolumns.lfm
Normal file
129
components/pas2js/components/frmaddmissingtablecolumns.lfm
Normal file
@ -0,0 +1,129 @@
|
||||
object AddMissingTableColumsForm: TAddMissingTableColumsForm
|
||||
Left = 468
|
||||
Height = 326
|
||||
Top = 287
|
||||
Width = 588
|
||||
Caption = 'Add Columns'
|
||||
ClientHeight = 326
|
||||
ClientWidth = 588
|
||||
LCLVersion = '3.99.0.0'
|
||||
object BPFields: TButtonPanel
|
||||
Left = 6
|
||||
Height = 38
|
||||
Top = 282
|
||||
Width = 576
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 0
|
||||
ShowButtons = [pbOK, pbCancel]
|
||||
end
|
||||
object pnlTop: TPanel
|
||||
Left = 0
|
||||
Height = 40
|
||||
Top = 0
|
||||
Width = 588
|
||||
Align = alTop
|
||||
BevelOuter = bvNone
|
||||
Caption = 'The following columns are missing'
|
||||
TabOrder = 1
|
||||
end
|
||||
object sgFields: TStringGrid
|
||||
Left = 0
|
||||
Height = 158
|
||||
Top = 40
|
||||
Width = 588
|
||||
Align = alClient
|
||||
AutoFillColumns = True
|
||||
Columns = <
|
||||
item
|
||||
ReadOnly = True
|
||||
SizePriority = 0
|
||||
Title.Caption = 'Field'
|
||||
Width = 200
|
||||
end
|
||||
item
|
||||
ButtonStyle = cbsCheckboxColumn
|
||||
SizePriority = 0
|
||||
Title.Caption = 'Add'
|
||||
Width = 40
|
||||
end
|
||||
item
|
||||
ButtonStyle = cbsPickList
|
||||
SizePriority = 0
|
||||
Title.Caption = 'Type'
|
||||
Width = 120
|
||||
end
|
||||
item
|
||||
SizePriority = 0
|
||||
Title.Caption = 'Width'
|
||||
Width = 50
|
||||
end
|
||||
item
|
||||
Title.Caption = 'Title'
|
||||
Width = 176
|
||||
end>
|
||||
ExtendedSelect = False
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRowMoving, goEditing, goRowSelect, goSmoothScroll]
|
||||
TabOrder = 2
|
||||
ColWidths = (
|
||||
200
|
||||
40
|
||||
120
|
||||
50
|
||||
176
|
||||
)
|
||||
end
|
||||
object pnlAction: TPanel
|
||||
Left = 0
|
||||
Height = 78
|
||||
Top = 198
|
||||
Width = 588
|
||||
Align = alBottom
|
||||
ClientHeight = 78
|
||||
ClientWidth = 588
|
||||
TabOrder = 3
|
||||
object cbAddAction: TCheckBox
|
||||
Left = 8
|
||||
Height = 23
|
||||
Top = 12
|
||||
Width = 197
|
||||
Caption = 'Add actions column for field'
|
||||
TabOrder = 0
|
||||
end
|
||||
object cbActionField: TComboBox
|
||||
Left = 248
|
||||
Height = 28
|
||||
Top = 9
|
||||
Width = 321
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 1
|
||||
end
|
||||
object cbAddSelect: TCheckBox
|
||||
Left = 10
|
||||
Height = 23
|
||||
Top = 49
|
||||
Width = 220
|
||||
Caption = 'Add select field field for column'
|
||||
TabOrder = 2
|
||||
end
|
||||
object cbSelectField: TComboBox
|
||||
Left = 248
|
||||
Height = 28
|
||||
Top = 46
|
||||
Width = 321
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 3
|
||||
end
|
||||
end
|
||||
end
|
349
components/pas2js/components/frmaddmissingtablecolumns.pas
Normal file
349
components/pas2js/components/frmaddmissingtablecolumns.pas
Normal file
@ -0,0 +1,349 @@
|
||||
unit frmaddmissingtablecolumns;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ExtCtrls, ValEdit, Grids, StdCtrls,
|
||||
db, types, stub.bootstraptablewidget;
|
||||
|
||||
type
|
||||
TFieldProps = record
|
||||
FieldType : TFieldType;
|
||||
DisplayName : string;
|
||||
Size : integer;
|
||||
end;
|
||||
|
||||
TColumnData = record
|
||||
FieldName : string;
|
||||
Title : string;
|
||||
Width : integer;
|
||||
Render : TColumnRenderMode
|
||||
end;
|
||||
TColumnDataArray = Array of TColumnData;
|
||||
|
||||
{ TAddMissingTableColumsForm }
|
||||
|
||||
TAddMissingTableColumsForm = class(TForm)
|
||||
BPFields: TButtonPanel;
|
||||
cbAddAction: TCheckBox;
|
||||
cbActionField: TComboBox;
|
||||
cbSelectField: TComboBox;
|
||||
cbAddSelect: TCheckBox;
|
||||
pnlTop: TPanel;
|
||||
pnlAction: TPanel;
|
||||
sgFields: TStringGrid;
|
||||
private
|
||||
FTable: TDBBootstrapTableWidget;
|
||||
function GetActionColumn: String;
|
||||
function GetNewColumns: TColumnDataArray;
|
||||
function GetSelectColumn: String;
|
||||
procedure MakeRow(aRow: Integer; const aFld: String);
|
||||
procedure SetTable(AValue: TDBBootstrapTableWidget);
|
||||
public
|
||||
Procedure AnalyzeColumns;
|
||||
Procedure FillFieldsCombobox;
|
||||
procedure FillTypesList;
|
||||
class function GetFieldProps(aTable: TDBBootstrapTableWidget; const aFieldName: String; out aProps: TFieldProps): Boolean;
|
||||
class function GetFieldNames(aTable : TDBBootstrapTableWidget): TStringDynArray;
|
||||
class function GetMissingFields(aTable : TDBBootstrapTableWidget; aFields : TStringDynArray): TStringDynArray;
|
||||
class function GetKeyField(aTable: TDBBootstrapTableWidget): String;
|
||||
Property Table : TDBBootstrapTableWidget Read FTable Write SetTable;
|
||||
Property NewColumns : TColumnDataArray Read GetNewColumns;
|
||||
Property ActionColumn : String Read GetActionColumn;
|
||||
Property SelectColumn : String Read GetSelectColumn;
|
||||
end;
|
||||
|
||||
var
|
||||
AddMissingTableColumsForm: TAddMissingTableColumsForm;
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
uses math,typinfo;
|
||||
|
||||
const
|
||||
idxField = 0;
|
||||
idxAdd = 1;
|
||||
idxType = 2;
|
||||
idxWidth = 3;
|
||||
idxTitle = 4;
|
||||
|
||||
|
||||
function RenderModeToString(R : TColumnRenderMode) : String;
|
||||
|
||||
begin
|
||||
Result:=GetEnumName(TypeInfo(TColumnRenderMode),Ord(R));
|
||||
end;
|
||||
|
||||
function StringToRenderMode(const R : String) : TColumnRenderMode;
|
||||
|
||||
var
|
||||
I : integer;
|
||||
|
||||
begin
|
||||
I:=GetEnumValue(TypeInfo(TColumnRenderMode),R);
|
||||
if I=-1 then
|
||||
Result:=crmText
|
||||
else
|
||||
Result:=TColumnRenderMode(I);
|
||||
end;
|
||||
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TAddMissingTableColumsForm }
|
||||
|
||||
procedure TAddMissingTableColumsForm.SetTable(AValue: TDBBootstrapTableWidget);
|
||||
begin
|
||||
if FTable=AValue then Exit;
|
||||
FTable:=AValue;
|
||||
FillFieldsCombobox;
|
||||
FillTypesList;
|
||||
AnalyzeColumns;
|
||||
end;
|
||||
|
||||
class function TAddMissingTableColumsForm.GetFieldNames(aTable: TDBBootstrapTableWidget): TStringDynArray;
|
||||
var
|
||||
DS : TDataset;
|
||||
I : Integer;
|
||||
FD : TFieldDef;
|
||||
F : TField;
|
||||
|
||||
begin
|
||||
Result:=[];
|
||||
Ds:=Nil;
|
||||
if assigned(aTable.Datasource) then
|
||||
ds:=aTable.Datasource.Dataset;
|
||||
if ds=nil then
|
||||
exit;
|
||||
if (ds.Fields.Count=0) then
|
||||
begin
|
||||
SetLength(Result,ds.FieldDefs.Count);
|
||||
for I:=0 to ds.FieldDefs.Count-1 do
|
||||
begin
|
||||
FD:=DS.FieldDefs[I];
|
||||
Result[i]:=FD.Name;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
SetLength(Result,ds.Fields.Count);
|
||||
for I:=0 to ds.Fields.Count-1 do
|
||||
begin
|
||||
F:=DS.Fields[I];
|
||||
Result[i]:=F.FieldName;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TAddMissingTableColumsForm.GetMissingFields(aTable: TDBBootstrapTableWidget; aFields: TStringDynArray
|
||||
): TStringDynArray;
|
||||
|
||||
var
|
||||
Fld: String;
|
||||
aCount : Integer;
|
||||
|
||||
begin
|
||||
Result:=[];
|
||||
SetLength(Result,Length(aFields));
|
||||
aCount:=0;
|
||||
For Fld in aFields do
|
||||
if aTable.Columns.IndexOfColumn(Fld)=-1 then
|
||||
begin
|
||||
Result[aCount]:=Fld;
|
||||
Inc(aCount);
|
||||
end;
|
||||
SetLength(Result,aCount);
|
||||
end;
|
||||
|
||||
class function TAddMissingTableColumsForm.GetKeyField(aTable: TDBBootstrapTableWidget): String;
|
||||
|
||||
var
|
||||
DS : TDataset;
|
||||
I : Integer;
|
||||
FD : TFieldDef;
|
||||
F : TField;
|
||||
|
||||
begin
|
||||
Result:='';
|
||||
if assigned(aTable.Datasource) then
|
||||
ds:=aTable.Datasource.Dataset;
|
||||
if ds=nil then
|
||||
exit;
|
||||
I:=0;
|
||||
While (Result='') and (I<ds.Fields.Count) do
|
||||
begin
|
||||
F:=DS.Fields[I];
|
||||
if (pfInKey in F.ProviderFlags) then
|
||||
Result:=F.FieldName;
|
||||
inc(I);
|
||||
end;
|
||||
I:=0;
|
||||
While (Result='') and (I<ds.FieldDefs.Count) do
|
||||
begin
|
||||
FD:=DS.FieldDefs[I];
|
||||
if FD.DataType=ftAutoInc then
|
||||
Result:=FD.Name;
|
||||
inc(I);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TAddMissingTableColumsForm.MakeRow(aRow : Integer; const aFld : String);
|
||||
|
||||
var
|
||||
Props : TFieldProps;
|
||||
R : TColumnRenderMode;
|
||||
|
||||
begin
|
||||
if not GetFieldProps(Table,aFld,Props) then
|
||||
exit;
|
||||
SGFields.Cells[idxField,aRow]:=aFld;
|
||||
SGFields.Cells[idxAdd,aRow]:='1';
|
||||
R:=crmText;
|
||||
// TColumnRenderMode = (crmText, crmNumeric, crmDateTime, crmTransformedValue, crmCheckBox, crmButton, crmCustom);
|
||||
case Props.fieldtype of
|
||||
ftBoolean : R:=crmCheckBox;
|
||||
ftDate, ftDateTime,ftTime,ftTimeStamp : R:=crmDateTime;
|
||||
ftWord, ftInteger, ftAutoInc, ftLargeint: R:=crmNumeric;
|
||||
ftBlob,
|
||||
ftBytes,
|
||||
ftOraBlob,
|
||||
ftOraClob: R:=crmTransformedValue;
|
||||
end;
|
||||
SGFields.Cells[idxType,aRow]:=RenderModeToString(R);
|
||||
SGFields.Cells[idxWidth,aRow]:=IntToStr(Max(40,Min(Props.Size*8,200)));
|
||||
SGFields.Cells[idxTitle,aRow]:=Props.displayname;
|
||||
end;
|
||||
|
||||
function TAddMissingTableColumsForm.GetActionColumn: String;
|
||||
begin
|
||||
Result:='';
|
||||
if cbAddAction.Checked then
|
||||
Result:=cbActionField.Text;
|
||||
end;
|
||||
|
||||
function TAddMissingTableColumsForm.GetNewColumns: TColumnDataArray;
|
||||
|
||||
var
|
||||
I,Count : Integer;
|
||||
|
||||
begin
|
||||
Count:=0;
|
||||
For I:=1 to SGFields.RowCount-1 do
|
||||
if SGFields.Cells[idxAdd,I]='1' then
|
||||
Inc(Count);
|
||||
SetLength(Result,Count);
|
||||
Count:=0;
|
||||
For I:=1 to SGFields.RowCount-1 do
|
||||
if SGFields.Cells[idxAdd,I]='1' then
|
||||
begin
|
||||
Result[Count].FieldName:=SGFields.Cells[idxField,I];
|
||||
Result[Count].Width:=StrToIntDef(SGFields.Cells[idxWidth,I],120);
|
||||
Result[Count].Render:=StringToRenderMode(SGFields.Cells[idxType,I]);
|
||||
Result[Count].Title:=SGFields.Cells[idxTitle,I];
|
||||
inc(Count);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TAddMissingTableColumsForm.GetSelectColumn: String;
|
||||
begin
|
||||
Result:='';
|
||||
if cbAddSelect.Checked then
|
||||
Result:=cbSelectField.Text;
|
||||
end;
|
||||
|
||||
procedure TAddMissingTableColumsForm.AnalyzeColumns;
|
||||
|
||||
var
|
||||
Fields : TStringDynArray;
|
||||
MissingFields : TStringDynArray;
|
||||
aRow : Integer;
|
||||
Fld : String;
|
||||
|
||||
begin
|
||||
Fields:=GetFieldNames(Table);
|
||||
MissingFields:=GetMissingFields(Table,Fields);
|
||||
sgFields.RowCount:=Length(MissingFields)+1;
|
||||
aRow:=0;
|
||||
For Fld in MissingFields do
|
||||
begin
|
||||
Inc(aRow);
|
||||
MakeRow(aRow,Fld);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TAddMissingTableColumsForm.FillFieldsCombobox;
|
||||
|
||||
var
|
||||
KeyField : String;
|
||||
|
||||
Procedure DoCB(Cb : TCombobox);
|
||||
begin
|
||||
CB.Items.AddStrings(GetFieldNames(Table),True);
|
||||
if (KeyField<>'') then
|
||||
CB.ItemIndex:=CB.Items.IndexOf(KeyField);
|
||||
end;
|
||||
|
||||
begin
|
||||
KeyField:=GetKeyField(Table);
|
||||
DoCB(cbActionField);
|
||||
DoCB(cbSelectField);
|
||||
end;
|
||||
|
||||
procedure TAddMissingTableColumsForm.FillTypesList;
|
||||
|
||||
var
|
||||
R : TColumnRenderMode;
|
||||
|
||||
begin
|
||||
With sgFields.Columns[2].PickList do
|
||||
begin
|
||||
Clear;
|
||||
for r in TColumnRenderMode do
|
||||
Add(RenderModeToString(R));
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TAddMissingTableColumsForm.GetFieldProps(aTable: TDBBootstrapTableWidget; const aFieldName : String; out aProps: TFieldProps): Boolean;
|
||||
var
|
||||
DS : TDataset;
|
||||
I : Integer;
|
||||
FD : TFieldDef;
|
||||
F : TField;
|
||||
|
||||
begin
|
||||
Result:=False;
|
||||
if assigned(aTable.Datasource) then
|
||||
ds:=aTable.Datasource.Dataset;
|
||||
if ds=nil then
|
||||
exit;
|
||||
if (ds.Fields.Count=0) then
|
||||
begin
|
||||
FD:=ds.FieldDefs.Find(aFieldName);
|
||||
Result:=Assigned(FD);
|
||||
if Result then
|
||||
begin
|
||||
aProps.DisplayName:=aFieldName;
|
||||
aProps.FieldType:=FD.DataType;
|
||||
aProps.size:=FD.Size;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
F:=ds.Fields.FindField(aFieldName);
|
||||
Result:=Assigned(F);
|
||||
if Result then
|
||||
begin
|
||||
aProps.DisplayName:=F.DisplayLabel;
|
||||
aProps.FieldType:=F.DataType;
|
||||
aProps.Size:=FD.Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -51,6 +51,21 @@ Type
|
||||
procedure ExecuteVerb({%H-}Index: Integer); override;
|
||||
end;
|
||||
|
||||
{ TBootstrapTableWidgetComponentEditor }
|
||||
|
||||
TBootstrapTableWidgetComponentEditor = class(TComponentEditor)
|
||||
private
|
||||
FTable: TDBBootstrapTableWidget;
|
||||
Public
|
||||
Procedure CreateMissingColumns;
|
||||
constructor Create(AComponent: TComponent;
|
||||
ADesigner: TComponentEditorDesigner); override;
|
||||
destructor Destroy; override;
|
||||
property Table : TDBBootstrapTableWidget read FTable write FTable;
|
||||
function GetVerbCount: Integer; override;
|
||||
function GetVerb({%H-}Index: Integer): string; override;
|
||||
procedure ExecuteVerb({%H-}Index: Integer); override;
|
||||
end;
|
||||
|
||||
{ TPas2JSRPCClientComponentEditor }
|
||||
|
||||
@ -192,7 +207,7 @@ uses
|
||||
Types, IDEWindowIntf, controls, forms, dialogs, formeditingintf, lazideintf, idemsgintf, IDEExternToolIntf, Menuintf,
|
||||
idehtmltools,
|
||||
frmHTMLActionsEditor, strpas2jscomponents, pas2jsrestutils, pas2jsrestcmd, frmpas2jsedithtml, p2jselementactions,
|
||||
frmcreaterpcserviceclient;
|
||||
frmcreaterpcserviceclient, frmaddmissingtablecolumns;
|
||||
|
||||
{ TDBHTMLElementActionFieldProperty }
|
||||
|
||||
@ -410,6 +425,112 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TBootstrapTableWidgetComponentEditor }
|
||||
|
||||
procedure TBootstrapTableWidgetComponentEditor.CreateMissingColumns;
|
||||
|
||||
procedure AddNewColumns(Cols : TColumnDataArray);
|
||||
|
||||
var
|
||||
C : TColumnData;
|
||||
BC: TBSTableColumn;
|
||||
|
||||
begin
|
||||
For C in Cols do
|
||||
begin
|
||||
BC:=Table.Columns.Add;
|
||||
BC.RenderMode:=C.Render;
|
||||
BC.Width:=C.Width;
|
||||
BC.WidthUnits:='px';
|
||||
BC.FieldName:=C.FieldName;
|
||||
BC.Title:=C.Title;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure AddActionColumn(aField : String);
|
||||
|
||||
var
|
||||
BC: TBSTableColumn;
|
||||
|
||||
begin
|
||||
if aField='' then exit;
|
||||
BC:=Table.Columns.Add;
|
||||
BC.FieldName:=aField;
|
||||
BC.RenderMode:=crmAction;
|
||||
BC.Title:='Actions';
|
||||
end;
|
||||
|
||||
procedure AddSelectColumn(aField : String);
|
||||
|
||||
var
|
||||
BC: TBSTableColumn;
|
||||
|
||||
begin
|
||||
if aField='' then exit;
|
||||
BC:=Table.Columns.Add;
|
||||
BC.FieldName:=aField;
|
||||
BC.RenderMode:=crmAction;
|
||||
BC.Title:='?';
|
||||
end;
|
||||
|
||||
Var
|
||||
Frm : TAddMissingTableColumsForm;
|
||||
|
||||
|
||||
begin
|
||||
With TAddMissingTableColumsForm do
|
||||
if Length(GetMissingFields(Self.Table,GetFieldNames(Self.Table)))=0 then
|
||||
begin
|
||||
ShowMessage(rsColumnsForAllFields);
|
||||
Exit;
|
||||
end;
|
||||
Frm:=TAddMissingTableColumsForm.Create(Nil);
|
||||
try
|
||||
Frm.Table:=Self.Table;
|
||||
if Frm.ShowModal=mrOK then
|
||||
begin
|
||||
AddSelectColumn(Frm.SelectColumn);
|
||||
AddNewColumns(Frm.NewColumns);
|
||||
AddActionColumn(Frm.ActionColumn);
|
||||
Modified;
|
||||
end;
|
||||
finally
|
||||
Frm.Free;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
constructor TBootstrapTableWidgetComponentEditor.Create(AComponent: TComponent; ADesigner: TComponentEditorDesigner);
|
||||
begin
|
||||
inherited Create(AComponent, ADesigner);
|
||||
FTable:=aComponent as TDBBootstrapTableWidget;
|
||||
end;
|
||||
|
||||
destructor TBootstrapTableWidgetComponentEditor.Destroy;
|
||||
begin
|
||||
FTable:=Nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TBootstrapTableWidgetComponentEditor.GetVerbCount: Integer;
|
||||
begin
|
||||
Result:=1;
|
||||
end;
|
||||
|
||||
function TBootstrapTableWidgetComponentEditor.GetVerb(Index: Integer): string;
|
||||
begin
|
||||
Case Index of
|
||||
0 : Result:=rsCreateMissingColumns;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TBootstrapTableWidgetComponentEditor.ExecuteVerb(Index: Integer);
|
||||
begin
|
||||
Case Index of
|
||||
0 : CreateMissingColumns;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TBootStrapModalTemplateNamePropertyEditor }
|
||||
|
||||
function TBootStrapModalTemplateNamePropertyEditor.GetTemplateLoader: TCustomTemplateLoader;
|
||||
|
@ -134,6 +134,10 @@
|
||||
<Filename Value="pas2jscompedits.pas"/>
|
||||
<UnitName Value="pas2jscompedits"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Filename Value="frmaddmissingtablecolumns.pas"/>
|
||||
<UnitName Value="frmaddmissingtablecolumns"/>
|
||||
</Item>
|
||||
</Files>
|
||||
<RequiredPkgs>
|
||||
<Item>
|
||||
|
@ -8,14 +8,11 @@ unit pas2jscomponents;
|
||||
interface
|
||||
|
||||
uses
|
||||
regpas2jscomponents, frmHTMLActionsEditor, htmleventnames,
|
||||
strpas2jscomponents, stub.htmlfragment, stub.restdataset, stub.htmlactions,
|
||||
pas2jsrestutils, pas2jsrestcmd, frmRestData, stub.webwidget, Stub.JS,
|
||||
stub.web, stub.bootstrapwidgets, frmpas2jsedithtml, p2jselementactions,
|
||||
Stub.Data.HTMLActions, frmselecthtmlactions, stub.jsondataset,
|
||||
stub.bootstraptablewidget, stub.dbwebwidget, stub.dbhtmlwidgets,
|
||||
stub.htmlwidgets, stub.bulmawidgets, stub.fprpcclient, iderpccodegen,
|
||||
frmcreaterpcserviceclient, pas2jscompedits, LazarusPackageIntf;
|
||||
regpas2jscomponents, frmHTMLActionsEditor, htmleventnames, strpas2jscomponents, stub.htmlfragment, stub.restdataset,
|
||||
stub.htmlactions, pas2jsrestutils, pas2jsrestcmd, frmRestData, stub.webwidget, Stub.JS, stub.web, stub.bootstrapwidgets,
|
||||
frmpas2jsedithtml, p2jselementactions, Stub.Data.HTMLActions, frmselecthtmlactions, stub.jsondataset, stub.bootstraptablewidget,
|
||||
stub.dbwebwidget, stub.dbhtmlwidgets, stub.htmlwidgets, stub.bulmawidgets, stub.fprpcclient, iderpccodegen,
|
||||
frmcreaterpcserviceclient, pas2jscompedits, frmaddmissingtablecolumns, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -88,6 +88,7 @@ procedure TIDEPas2JSRestCommandHandler.RegisterCommands;
|
||||
begin
|
||||
// Form designer menu
|
||||
mnuCompRestSection:=RegisterIDESubMenu(DesignerMenuSectionCustomDynamic,'comPas2JSRest',rsPas2JSRest,Nil,Nil);
|
||||
// DesignerMenuSectionCustomDynamic.AddHandlerOnShow(@CheckDataset);
|
||||
mnuCompRestSection.AddHandlerOnShow(@CheckDataset);
|
||||
// RegisterIDEMenuCommand(mnuCompDDSection,'ddeditfields',SMenuDatadictApply,@IDEDDC.ApplyDD,Nil,Nil);
|
||||
CmdShowData:=RegisterIDEMenuCommand(mnuCompRestSection,'showData',rsMenuRestShowData,@ShowData,Nil,Nil);
|
||||
@ -105,7 +106,9 @@ Var
|
||||
begin
|
||||
DS:=GetDataset;
|
||||
OK:=(DS<>Nil) and (DS.Connection<>Nil) and (DS.ResourceName<>'');
|
||||
mnuCompRestSection.Enabled:=OK;
|
||||
CmdShowData.Enabled:=OK ;
|
||||
CmdGetParamDefs.Enabled:=OK;
|
||||
CmdGetFieldDefs.Enabled:=OK and (DS.Connection.MetaDataResourceName<>'');
|
||||
end;
|
||||
|
||||
|
@ -176,6 +176,7 @@ Procedure RegisterComponentEditors;
|
||||
begin
|
||||
RegisterComponentEditor(THTMLElementActionList,THTMLElementActionListComponentEditor);
|
||||
RegisterComponentEditor(TBootstrapModal,TBootstrapModalComponentEditor);
|
||||
RegisterComponentEditor(TDBBootstrapTableWidget,TBootstrapTableWidgetComponentEditor);
|
||||
RegisterComponentEditor(TPas2JSRPCClient,TPas2JSRPCClientComponentEditor);
|
||||
end;
|
||||
|
||||
|
@ -39,6 +39,9 @@ Resourcestring
|
||||
rsEditingHTMLProp = 'Editing HTML property: %s';
|
||||
rsEditTemplate = 'Edit Template';
|
||||
|
||||
rsCreateMissingColumns = 'Create missing columns';
|
||||
rsColumnsForAllFields = 'There is already a column for all fields.';
|
||||
|
||||
rsStandardHTMLAction = 'Standard HTML Element action.';
|
||||
rsDBEditHTMLAction = 'Standard Data-Aware HTML Element action.';
|
||||
rsDBHTMLAction = 'Standard Data-Aware HTML read-only Element action.';
|
||||
|
@ -13,7 +13,7 @@ type
|
||||
|
||||
TCustomDBBootstrapTableWidget = Class;
|
||||
|
||||
TColumnRenderMode = (crmText, crmNumeric, crmDateTime, crmTransformedValue, crmCheckBox, crmButton, crmCustom);
|
||||
TColumnRenderMode = (crmText, crmNumeric, crmDateTime, crmTransformedValue, crmCheckBox, crmButton, crmCustom, crmAction);
|
||||
TColumnButtonType = (cbtInfo, cbtEdit, cbtDelete, cbtCustom);
|
||||
|
||||
TDataTablesFieldMap = Class(TObject)
|
||||
@ -53,8 +53,45 @@ type
|
||||
|
||||
{ TBSTableColumn }
|
||||
|
||||
{ TBSActionColumn }
|
||||
|
||||
{ TBSColumnAction }
|
||||
|
||||
TBSColumnAction = class(TCollectionItem)
|
||||
private
|
||||
FButtonIconClass: String;
|
||||
FButtonType: TColumnButtonType;
|
||||
FButtonURL: string;
|
||||
FButtonURLTarget: string;
|
||||
FExtraAttributes: String;
|
||||
Public
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
|
||||
Published
|
||||
property ButtonType: TColumnButtonType read FButtonType write FButtonType;
|
||||
// When buttontype is btCustom, use the following class (in <i class="">)
|
||||
Property ButtonIconClass: String Read FButtonIconClass Write FButtonIconClass;
|
||||
// URL to use when the button is clicked
|
||||
property ButtonURL: string read FButtonURL write FButtonURL;
|
||||
// Target of button URL
|
||||
property ButtonURLTarget: string read FButtonURLTarget write FButtonURLTarget;
|
||||
// Add extra attributes to the contents of the column if needed
|
||||
property ExtraAttributes: String read FExtraAttributes write FExtraAttributes;
|
||||
end;
|
||||
|
||||
{ TBSColumnActionList }
|
||||
|
||||
TBSColumnActionList = class(TCollection)
|
||||
private
|
||||
function GetAction(aIndex : Integer): TBSColumnAction;
|
||||
procedure SetAction(aIndex : Integer; AValue: TBSColumnAction);
|
||||
Public
|
||||
Property Actions[aIndex : Integer] : TBSColumnAction Read GetAction Write SetAction;
|
||||
end;
|
||||
|
||||
TBSTableColumn = class(TCollectionItem)
|
||||
private
|
||||
FActions: TBSColumnActionList;
|
||||
FFieldName: string;
|
||||
FFormatting: string;
|
||||
FSelectable: Boolean;
|
||||
@ -75,18 +112,24 @@ type
|
||||
FOnGetValue: TOnCustomValueEvent;
|
||||
FExtraAttributes: String;
|
||||
FWidthUnits: String;
|
||||
function GetActionsStored: Boolean;
|
||||
function GetTitle: string;
|
||||
procedure SetActions(AValue: TBSColumnActionList);
|
||||
protected
|
||||
function GetDisplayName: String; override;
|
||||
function CreateActions: TBSColumnActionList; virtual;
|
||||
{ private declarations }
|
||||
public
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
constructor Create(aOwner: TCollection); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
// Fieldname for this column
|
||||
property FieldName: string read FFieldName write FFieldName;
|
||||
// Title for this column
|
||||
property Title: string read GetTitle write FTitle;
|
||||
// Action column actions
|
||||
Property Actions : TBSColumnActionList Read FActions Write SetActions stored GetActionsStored;
|
||||
// Render mode: text, numer, checkbox, button custom render
|
||||
property RenderMode: TColumnRenderMode read FRenderMode write FRenderMode;
|
||||
// When rendermode is rmButton, what button ?
|
||||
@ -319,6 +362,35 @@ begin
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
{ TBSColumnAction }
|
||||
|
||||
procedure TBSColumnAction.Assign(Source: TPersistent);
|
||||
var
|
||||
aSource: TBSColumnAction absolute Source;
|
||||
begin
|
||||
if Source is TBSColumnAction then
|
||||
begin
|
||||
ExtraAttributes:=aSource.ExtraAttributes;
|
||||
ButtonURLTarget:=aSource.ButtonURLTarget;
|
||||
ButtonURL:=aSource.ButtonURL;
|
||||
ButtonType:=aSource.ButtonType;
|
||||
ButtonIconClass:=aSource.ButtonIconClass;
|
||||
end else
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
{ TBSColumnActionList }
|
||||
|
||||
function TBSColumnActionList.GetAction(aIndex : Integer): TBSColumnAction;
|
||||
begin
|
||||
Result:=Items[aIndex] as TBSColumnAction;
|
||||
end;
|
||||
|
||||
procedure TBSColumnActionList.SetAction(aIndex : Integer; AValue: TBSColumnAction);
|
||||
begin
|
||||
Items[aIndex]:=aValue;
|
||||
end;
|
||||
|
||||
|
||||
{ TBSTableColumn }
|
||||
|
||||
@ -345,6 +417,7 @@ begin
|
||||
Formatting := Src.Formatting;
|
||||
OnGetSortValue := Src.OnGetSortValue;
|
||||
ExtraAttributes := Src.ExtraAttributes;
|
||||
Actions:=Src.Actions;
|
||||
end
|
||||
else
|
||||
inherited;
|
||||
@ -357,6 +430,19 @@ begin
|
||||
FVisible := True;
|
||||
FSortable := True;
|
||||
FSearchable := True;
|
||||
Factions:=CreateActions;
|
||||
end;
|
||||
|
||||
destructor TBSTableColumn.Destroy;
|
||||
|
||||
begin
|
||||
Factions.Free;
|
||||
Inherited;
|
||||
end;
|
||||
|
||||
function TBSTableColumn.CreateActions:TBSColumnActionList;
|
||||
begin
|
||||
Result:=TBSColumnActionList.Create(TBSColumnAction);
|
||||
end;
|
||||
|
||||
function TBSTableColumn.GetDisplayName: String;
|
||||
@ -375,6 +461,17 @@ begin
|
||||
Result:=FieldName;
|
||||
end;
|
||||
|
||||
function TBSTableColumn.GetActionsStored: Boolean;
|
||||
begin
|
||||
Result:=(RenderMode=crmAction);
|
||||
end;
|
||||
|
||||
procedure TBSTableColumn.SetActions(AValue: TBSColumnActionList);
|
||||
begin
|
||||
if FActions=AValue then Exit;
|
||||
FActions.Assign(AValue);
|
||||
end;
|
||||
|
||||
{ TBSTableColumns }
|
||||
|
||||
function TBSTableColumns.Add(const aName: string): TBSTableColumn;
|
||||
|
Loading…
Reference in New Issue
Block a user