#1 2014-08-26 18:17:42

mariomoretti
Member
From: italy
Registered: 2012-01-29
Posts: 88

how to hide a tSQLRibbonTab

My project contains 23 tables.
I'm trying to let maintain them with a view similar to Synfile project , but i've the need to hide some of them.
Is there a simple way to obtain this ? I've not been able to find it.
tx

Offline

#2 2014-08-27 15:11:00

tech
Member
Registered: 2014-01-13
Posts: 107

Re: how to hide a tSQLRibbonTab

The easy way is to define a dynamic array of TFileRibbonTabParameters that you fill only with the visible tables.
Personally I do that to persist the menu with possiblity of hiding some tables.

Offline

#3 2014-08-28 17:59:44

mariomoretti
Member
From: italy
Registered: 2012-01-29
Posts: 88

Re: how to hide a tSQLRibbonTab

hi tech ,
thanks for reply.
May you give me an axample of how can you use a dynamic array ?
The constructor method of the ribbon apllies this control on line 1448 :

  assert(TableIndex=Tab.PageIndex); // as expected in SetAction()

that is, if i have correctly undertstood : the tfileribbontabparameter must contain exactly the same tables of the model.

Offline

#4 2014-08-30 09:37:11

tech
Member
Registered: 2014-01-13
Posts: 107

Re: how to hide a tSQLRibbonTab

hi mariomoretti,

this is the code of the class :

  TSQLMenus = class(TSQLRecord)
  protected
    fTable: RawUTF8;
    fCustomCaption: PResStringRec;
    fCustomHint: PResStringRec;
    fSelect: RawUTF8;
    fSQLWhere : RawUTF8;
    fGroup: integer;
    fOrdre : integer;
    fFieldWidth: RawUTF8;
    fFieldAlign: RawUTF8;
    fShowID: boolean;
    fOrderFieldIndex: integer;
    fReverseOrder: boolean;
    fLayout: TSQLListLayout;
    fListWidth: integer;
    fNoReport: boolean;
    fAutoRefresh: boolean;
    fEditFieldHints: PResStringRec;
    fEditExpandFieldHints: boolean;
    fEditFieldNameWidth: integer;
    fEditFieldNameToHideCSV: RawUTF8;
    fEditFieldHintsToReport: boolean;
    fVisible : boolean;
  published
    property TableName: RawUTF8 read fTable write fTable;
    property Selection: RawUTF8 read fSelect write fSelect;
    property SQLWhere : RawUTF8 read fSQLWhere write fSQLWhere;
    property Groupe: integer read fGroup write fGroup;
    property Ordre : integer read fOrdre write fOrdre;
    property FieldWidth: RawUTF8 read fFieldWidth write fFieldWidth;
    property FieldAlign: RawUTF8 read fFieldAlign write fFieldAlign;
    property ShowID: boolean read fShowID write fShowID;
    property OrderFieldIndex: integer read fOrderFieldIndex write fOrderFieldIndex;
    property ReverseOrder: boolean read fReverseOrder write fReverseOrder;
    property Layout: TSQLListLayout read fLayout write fLayout;
    property ListWidth: integer read fListWidth write fListWidth;
    property NoReport: boolean read fNoReport write fNoReport;
    property AutoRefresh: boolean read fAutoRefresh write fAutoRefresh;
    property EditExpandFieldHints: boolean read fEditExpandFieldHints write fEditExpandFieldHints;
    property EditFieldNameWidth: integer read fEditFieldNameWidth write fEditFieldNameWidth;
    property EditFieldNameToHideCSV: RawUTF8 read fEditFieldNameToHideCSV write fEditFieldNameToHideCSV;
    property EditFieldHintsToReport: boolean read fEditFieldHintsToReport write fEditFieldHintsToReport;   
    property Visible : boolean read fVisible write fVisible;
  public
    property Operation : TRecOper read fOperation write fOperation;
  end;

This is the code of the main unit :

var globalClient: TSQLHttpClient;
     globalModel: TSQLModel;

function CopyFromFileTabs:boolean;
var i : integer;
begin
  result := false;
  SetLength(menuTabs, length(FileTabs));
  for i:=Low(FileTabs) to high(FileTabs) do
  begin
    menuTabs[i].Table    := FileTabs[i].Table;
    menuTabs[i].Select   := FileTabs[i].Select;
    menuTabs[i].SQLWhere := FileTabs[i].SQLWhere;
    menuTabs[i].Group    := FileTabs[i].Group;
    menuTabs[i].FieldWidth := FileTabs[i].FieldWidth;
    menuTabs[i].FieldAlign := FileTabs[i].FieldAlign;
    menuTabs[i].ShowID     := FileTabs[i].ShowID;
    menuTabs[i].OrderFieldIndex := FileTabs[i].OrderFieldIndex;
    menuTabs[i].ReverseOrder := FileTabs[i].ReverseOrder;
    menuTabs[i].Layout       := FileTabs[i].Layout;
    menuTabs[i].ListWidth    := FileTabs[i].ListWidth;
    menuTabs[i].NoReport     := FileTabs[i].NoReport;
    menuTabs[i].AutoRefresh  := FileTabs[i].AutoRefresh;
  end;
  result := True;
end;

procedure TMainForm.FormCreate(Sender: TObject);
var menuTabs : array of TFileRibbonTabParameters;
     menu : TSQLMenus;
begin

  try
    menu := TSQLMenus.CreateAndFillPrepare(globalParam, 'visible=? order by ordre', [True]);
    while menu.FillOne do
    begin
      SetLength(menuTabs, length(menuTabs)+1);
      with menuTabs[high(menuTabs)] do
      begin
        Table := globalModel.Table[menu.TableName];
        Select := menu.Selection;
        SQLWhere := menu.SQLWhere;
        FieldWidth := menu.FieldWidth;
        FieldAlign := menu.FieldAlign;
        Group      := menu.Groupe;
        ShowID     := menu.ShowID;
        OrderFieldIndex := menu.OrderFieldIndex;
        ReverseOrder    := menu.ReverseOrder;
        Layout          := menu.Layout;
        ListWidth       := menu.ListWidth;
        NoReport        := menu.NoReport;
        AutoRefresh     := menu.AutoRefresh;
      end;
    end;
  finally
    menu.Free;
  end;

  LoadImageListFromEmbeddedZip(ImgListe32,'buttons.bmp');
  ImageListStretch(ImgListe32,ImgList16);
  if length(menutabs) = 0 then
  begin
    if CopyFromFileTabs then
      Ribbon := TSQLRibbon.Create(self, nil, nil, ImgListe32, ImgList16,
      globalClient, ALL_ACCESS_RIGHTS, ValueText, globalClient.OnSetAction, sFileActionsToolbar,
      sFileActionsHints, nil, ActionClick, integer(faRefresh), 1, false,
      length(menutabs), @menutabs[0], sizeof(menutabs[0]),
      sFileTabsGroup, ',BannerData,BannerSafe',true)
    else
    Ribbon := TSQLRibbon.Create(self, nil, nil, ImgListe32, ImgList16,
        globalClient, ALL_ACCESS_RIGHTS, ValueText, globalClient.OnSetAction, sFileActionsToolbar,
        sFileActionsHints, nil, ActionClick, integer(faRefresh), 1, false,
        length(FileTabs), @FileTabs[0], sizeof(FileTabs[0]),
        sFileTabsGroup, ',BannerData,BannerSafe',true);
  end
  else
    Ribbon := TSQLRibbon.Create(self, nil, nil, ImgListe32, ImgList16,
      globalClient, ALL_ACCESS_RIGHTS, ValueText, globalClient.OnSetAction, sFileActionsToolbar,
      sFileActionsHints, nil, ActionClick, integer(faRefresh), 1, false,
      length(menutabs), @menutabs[0], sizeof(menutabs[0]),
      sFileTabsGroup, ',BannerData,BannerSafe',true);

  Ribbon.ToolBar.Caption.Caption := Caption;
  Ribbon.ToolBar.HelpButton.OnClick := HelpClick;
  for P := 0 to high(Ribbon.Page) do
    with Ribbon.Page[P] do
      if Lister<>nil then
      begin
        Lister.Grid.OnDblClick := ListDblClick;
      end;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var menu : TSQLMenus;
    i : integer;
    old : boolean;
    Results: TIntegerDynArray;
begin

  try
    menu := TSQLMenus.Create();
    if globalClient.TransactionBegin(TSQLMenus, 20) then
    try
      if globalClient.BatchStart(TSQLMenus) then
      begin
        for i:=low(menuTabs) to high(menuTabs) do
        begin
          old := False;
          menu.FillPrepare(globalParam, 'TableName=?', [menuTabs[i].Table.SQLTableName]);
          old := menu.FillOne;

          menu.TableName  := menuTabs[i].Table.SQLTableName;
          menu.Selection  := menuTabs[i].Select;
          menu.SQLWhere   := menuTabs[i].SQLWhere;
          menu.Groupe     := menuTabs[i].Group;
          menu.Ordre      := i;
          menu.FieldWidth := menuTabs[i].FieldWidth;
          menu.FieldAlign := menuTabs[i].FieldAlign;
          menu.ShowID     := menuTabs[i].ShowID;
          menu.OrderFieldIndex := menuTabs[i].OrderFieldIndex;
          menu.ReverseOrder := menuTabs[i].ReverseOrder;
          menu.Layout       := menuTabs[i].Layout;
          menu.ListWidth    := menuTabs[i].ListWidth;
          menu.NoReport     := menuTabs[i].NoReport;
          menu.AutoRefresh  := menuTabs[i].AutoRefresh;
          menu.Visible      := True;
          if not old then
            globalClient.Add(menu, True)
          else
            globalClient.Update(menu);
        end;
        globalClient.BatchSend(Results);
      end;
      globalClient.Commit(0);
    except
      globalClient.RollBack(0);
    end;
  finally
    menu.Free;
  end;
end;

For the moment I hide menu manually by editing the visibile property on the table. For the future I want to add the ability of selecting menus to each user.

Offline

#5 2014-09-07 22:00:13

mariomoretti
Member
From: italy
Registered: 2012-01-29
Posts: 88

Re: how to hide a tSQLRibbonTab

Tech,
thank you very much.

Offline

#6 2014-09-10 16:30:43

mariomoretti
Member
From: italy
Registered: 2012-01-29
Posts: 88

Re: how to hide a tSQLRibbonTab

Hi tech,
sorry to noise you but, where do you apply the visible property of tSQlMenus to menutabs ?

Offline

#7 2014-09-10 19:44:20

tech
Member
Registered: 2014-01-13
Posts: 107

Re: how to hide a tSQLRibbonTab

Hi,
For the moment I set this property on database, but you can create a UI for admin only where you can update this visibility.

Offline

#8 2014-09-11 02:58:04

mariomoretti
Member
From: italy
Registered: 2012-01-29
Posts: 88

Re: how to hide a tSQLRibbonTab

Well,
thank you for your quick support.
This incredible framework has so feature that , also if documented with a two thousands page pdf , often requires a debugging to find answers.
Perhaps the problem resides in my english : what i'm asking is how to hide a tab and not how to persist it's visible property.
There is a simple answer : you have to set properly the aUserRights parameter of the tSQLRibbon.create metod. This parameter is a set [0..63]  integer that has to contain the indexes of the tables that can be managed by the user.
Perhaps a visible property in TSQLRibbonTabParameters could help : i'll  open a ticket.

Offline

#9 2014-09-11 09:09:32

tech
Member
Registered: 2014-01-13
Posts: 107

Re: how to hide a tSQLRibbonTab

Good information.

Offline

Board footer

Powered by FluxBB