How to present different tablename.tv to different groups!

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

How to present different tablename.tv to different groups!

Post by ronwill » 2023-10-12 23:15

I was looking for and found a way to solve the following that may be useful to others with a similar need:

Current situation:
When logged in as Admin or other controlling group member I normally like my template.tv to present records in a table as a normal list. However when a user logs in and is set to view only their own few records I like to show them the template.tv in the form of Cards i.e. BS4 BOX CARDS etc.
Until now it's been either/or for all groups for any particular table.

Solution:
I've now discovered that is is quite easy to have a different template.tv for given groups, suiting my requirement perfectly.
The inspiration, solution came from fter viewing help from A.Gneady's post: https://bigprof.com/blog/appgini/how-to ... ser-group/
- It was not the direct solution to my senario but gave me the insite on how to do it:

If you follow the well detailed easy to follow instructions from A.Gneady in the link and ignore steps: 4+6 regarding hiding the customers column (unless you also want a column removed) and proceed to the end.

You now have a hooks file where you can edit your template.tv that will not be overwritten and is easily updated to suit whatever layout you want to use for the template.tv for diferent groups
Done!

This is the code I used in my project on a simple small table: Templatename.php hooks folder

Code: Select all

	function member_init(&$options, $memberInfo, &$args) {
		$hide_groups = array('All Members');
		if(in_array($memberInfo['group'], $hide_groups)) {
			$options->ColWidth = [150, 150, 150, 150, 100, ];
			$options->ColCaption = ['Profile Pic', 'Name', 'Mobile or Phone', 'Group', 'Your Horse(s):', ];
			$options->ColFieldName = ['profile_pic', 'name', 'mobile', 'group', '%your_horse.name%', ];
			$options->ColNumber  = [4, 6, 8, 10, -1, ];
			$options->ShowTableHeader = 0;
 			
			// template paths below are based on the app main directory
			$options->Template = 'hooks/member_templateTV.html';
			$options->SelectedTemplate = 'hooks/member_templateTVS.html';
		}
		return TRUE;
	}
This is the code I placed in the template.tv that was saved in my hooks folder:

Code: Select all

<style>
	.panel-heading{
		margin-top: 1px;
		height: 70px;
		overflow: auto;
	}

	.panel-footer{
		margin-top: 0px;
		height: 80px;
		overflow: auto;
	}
</style>

    <div class="col-xs-12 col-sm-6 col-md-4 col-lg-2">
       
	  <hr>
		<div class="panel panel-default" style="margin-top: 5px; min-height: 650px; max-height: 850px; overflow: auto; border-style:solid; border-width:1px; border-color:default">
		<button type="button" class="btn btn-info btn-sm btn-block"></button>
        <div class="panel-heading"><big><b><%%VALUE(name)%%></b></big><%%SELECT%%><big>More details</big><%%ENDSELECT%%></div>
        <div class="panel-body">
<big>
		<dd id="member-profile_pic-<%%VALUE(id)%%>" class="member-profile_pic"><a href="<%%TRANSLATION(ImageFolder)%%><%%VALUE(profile_pic)%%>" data-lightbox="member-profile_pic"><img src="images/<%%VALUE(profile_pic)%%>"style="width:100%"></a></dd>
		<dd id="member-name-<%%VALUE(id)%%>" class="member-name">Name: <%%SELECT%%><%%VALUE(name)%%><%%ENDSELECT%%></dd>
		<dd id="member-mobile-<%%VALUE(id)%%>" class="member-mobile">Mobile: <%%SELECT%%><%%VALUE(mobile)%%><%%ENDSELECT%%></dd>
		<dd id="member-group-<%%VALUE(id)%%>" class="member-group">Group: <%%SELECT%%><%%VALUE(group)%%><%%ENDSELECT%%></dd>

</big>
		</div>
        </div>
    </div>
	
<script>
    $j("#order-by-selector").closest("tr").hide().remove();
    $j("#select_all_records").closest("th").hide().remove();
    $j(".record_selector").closest("td").hide().remove();
</script>

Now when a someone logs in under my 'All Members' group they will see their member.tv shown as a card instead of the standard table layout (note the script to remove the standard table elements). If someone logs in under admin or other control group where I want them to see all records listed as normal in long table etc., thats what they will get/see.

Hope that is of help to someone.
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: How to present different tablename.tv to different groups!

Post by ronwill » 2023-10-12 23:45

Couple of images showing card / table of another table as an example - same template.tv data different views to member/admin groups

with Table:
card1.jpg
card1.jpg (21.53 KiB) Viewed 1384 times
with card:
card2.jpg
card2.jpg (26.79 KiB) Viewed 1384 times
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

Post Reply