Set the default admin view #148

Closed
opened 2017-10-26 11:29:32 +00:00 by kevincam3 · 18 comments
kevincam3 commented 2017-10-26 11:29:32 +00:00 (Migrated from github.com)

I would not like to use the dashboard but instead have the default view in the admin be one of the admin views. Is this possible? And if so how?

I would not like to use the dashboard but instead have the default view in the admin be one of the admin views. Is this possible? And if so how?

We can look at this as a feature request, since at this time adding more tabs to the dashboard is all you can really do to customize it.

We could in the future add a option to link to a custom_admin_view or admin_view. But this is not possible at this time. You can of course use custom scripting to completely change the dashboard.

We can look at this as a feature request, since at this time adding more tabs to the dashboard is all you can really do to customize it. We could in the future add a option to link to a custom_admin_view or admin_view. But this is not possible at this time. You can of course use custom scripting to completely change the dashboard.

I am planning to build this, @kevincam3 will you be able to help with testing this feature?

I am planning to build this, @kevincam3 will you be able to help with testing this feature?
mwweb commented 2018-03-08 20:22:44 +00:00 (Migrated from github.com)

I might be able to assist in testing this as well. Sorry that I have been out of the loop for a while. Had a big project needing to convert from one platform to Joomla!, which showed there were a ton of suppressed error from the prior developer (over 600 of them). Anyway, I am mostly to the milestone of completing that one, so I should have a little time here and there.

I might be able to assist in testing this as well. Sorry that I have been out of the loop for a while. Had a big project needing to convert from one platform to Joomla!, which showed there were a ton of suppressed error from the prior developer (over 600 of them). Anyway, I am mostly to the milestone of completing that one, so I should have a little time here and there.

This is not going to so major, since after some investigation I can see a very easy way to make this work. Soon as I have it ready I will push the changes up, and will be wonderful to just have some feed back once you have time. I totally understand... I mean you being out of the loop at times. now worries!

This little tweak will make it possible to really have smart dashboards 👍

This is not going to so major, since after some investigation I can see a very easy way to make this work. Soon as I have it ready I will push the changes up, and will be wonderful to just have some feed back once you have time. I totally understand... I mean you being out of the loop at times. now worries! This little tweak will make it possible to really have smart dashboards :+1:

@mwweb I have made the adaptation, and it should work. When opening a [Joomla Component]-tab->PHP you will see new button called Dashboard Type by default it must be set to Default which is the old way the dashboard was build. There should be a little explanation, for both options really, you can add to that explanation of you think it is unclear.

So when you select Dynamic there should open a drop-down, under the explanation, of all the linked Admin and Custom Admin Views selecting any of those will make it the new Dashboard or Default view.

So give it a try and give me your feedback.

@mwweb I have made the adaptation, and it should work. When opening a [**Joomla Component**]-_tab_->**PHP** you will see new button called **Dashboard Type** by default it must be set to **Default** which is the old way the dashboard was build. There should be a little explanation, for both options really, you can add to that explanation of you think it is unclear. So when you select **Dynamic** there should open a drop-down, under the explanation, of all the linked **Admin** and **Custom Admin Views** selecting any of those will make it the new Dashboard or Default view. So give it a try and give me your feedback.
mwweb commented 2018-03-09 23:39:14 +00:00 (Migrated from github.com)

I did a test with one of the components that I have been building.

I went into the component, PHP, and changed dashboard type to dynamic, then selected one of my admin views. I compiled, then installed. I don't see any change. If I click on the link item in component, it still loads the dashboard, rather than going to the "fields" view that I selected.

jcb1
jcb2

I did a test with one of the components that I have been building. I went into the component, PHP, and changed dashboard type to dynamic, then selected one of my admin views. I compiled, then installed. I don't see any change. If I click on the link item in component, it still loads the dashboard, rather than going to the "fields" view that I selected. ![jcb1](https://user-images.githubusercontent.com/19194012/37234977-d746ec6a-23af-11e8-907d-127726f8186b.png) ![jcb2](https://user-images.githubusercontent.com/19194012/37234994-022c1a54-23b0-11e8-8712-38aaf93f96a0.png)

The dashboard will still be there if you have the old install, not sure why it will load it as the default... okay can you check some files in the compiled package?

Once it is compiled unzip the package and look to see if there is a model/view/controller with the component name. Since that was usually the dashboard, and with the new package this should not exist. Then if you open the back-end controller it should have the following new code:

/**
 * Constructor.
 *
 * @param   array  $config  An optional associative array of configuration settings.
 * Recognized key values include 'name', 'default_task', 'model_path', and
 * 'view_path' (this list is not meant to be comprehensive).
 *
 * @since   3.0
 */
public function __construct($config = array())
{
	// set the default view
	$config['default_view'] = 'componentbuilder'; /// <--- This should be the admin view you selected
	parent::__construct($config);
}

Let me know and we take it from there.

The dashboard will still be there if you have the old install, not sure why it will load it as the default... okay can you check some files in the compiled package? Once it is compiled unzip the package and look to see if there is a model/view/controller with the component name. Since that was usually the dashboard, and with the new package this should not exist. Then if you open the [back-end controller](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/controller.php) it should have the following new code: ``` /** * Constructor. * * @param array $config An optional associative array of configuration settings. * Recognized key values include 'name', 'default_task', 'model_path', and * 'view_path' (this list is not meant to be comprehensive). * * @since 3.0 */ public function __construct($config = array()) { // set the default view $config['default_view'] = 'componentbuilder'; /// <--- This should be the admin view you selected parent::__construct($config); } ``` Let me know and we take it from there.
mwweb commented 2018-03-10 00:12:55 +00:00 (Migrated from github.com)

This was a fresh compile on a new install of Joomla. I'm doing a complete clone of my existing dev site to test again. But, in looking, there is a model/view/controller with the component name, and the back-end controller has the default view as the component name, not the view I set it to.

After my clone is done, and I can test again, I'll update.

This was a fresh compile on a new install of Joomla. I'm doing a complete clone of my existing dev site to test again. But, in looking, there is a model/view/controller with the component name, and the back-end controller has the default view as the component name, not the view I set it to. After my clone is done, and I can test again, I'll update.

Make sure that the following changes was made to your compiler and the database...

The database there should be a few new fields in the #__componentbuilder_joomla_component table:
dashboard and dashboard_type make sure they are there.

Then in the compiler the following lines:

  • public $dynamicDashboard = false; on line 328 of the b_Structure.php file
  • private function setDynamicDashboard() on line 542 of the b_Structure.php file.

IF those are there I expect the others are there also... now you can check if things work on compilation, by adding the following on line 614

var_dump($this->dynamicDashboard);exit;

This should have the new admin views listview name, if not then we need look at the following values, by changing the dump to:

var_dump($this->componentData->dashboard);
var_dump($this->componentData->dashboard_type);
exit;

Let me know what you find out, since on my side those values come out right...

Make sure that the following changes was made to your compiler and the database... The database there should be a few new fields in the `#__componentbuilder_joomla_component` table: `dashboard` and `dashboard_type` make sure they are there. Then in the compiler the following lines: - `public $dynamicDashboard = false;` on [line 328](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L328) of the b_Structure.php file - `private function setDynamicDashboard()` on [line 542](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L542) of the b_Structure.php file. IF those are there I expect the others are there also... now you can check if things work on compilation, by adding the following on [line 614](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L614) ``` var_dump($this->dynamicDashboard);exit; ``` This should have the new admin views listview name, if not then we need look at the following values, by changing the dump to: ``` var_dump($this->componentData->dashboard); var_dump($this->componentData->dashboard_type); exit; ``` Let me know what you find out, since on my side those values come out right...

The database was updated with this file.

As you will see this file adds those two fields and updates on to be 1 by default.

The database was updated with [this file](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/sql/updates/mysql/2.6.17.sql). As you will see this file adds those two fields and updates on to be 1 by default.

Okay I just added a few tweaks to the setDynamicDashboard method to give some error messages when things do not line-up. Make sure to try this new push to the staging branch.

Okay I just added a few tweaks to the `setDynamicDashboard` method to give some error messages when things do not line-up. Make sure to try this new push to the staging branch.
mwweb commented 2018-03-10 08:52:35 +00:00 (Migrated from github.com)

Well, it's doing something at least. I'm getting the wonderful error message:

Error
The admin view (A_139) is not available in your component! Please insure to only used admin views, for a dynamic dashboard, that are still linked to your component.

The problem is...the view I selected is an admin view, and it is available in the component. I'll have to test more when I'm not so tired.

Well, it's doing something at least. I'm getting the wonderful error message: Error The admin view (A_139) is not available in your component! Please insure to only used admin views, for a dynamic dashboard, that are still linked to your component. The problem is...the view I selected is an admin view, and it is available in the component. I'll have to test more when I'm not so tired.

Well this is the code:

$getter = explode('_',$this->componentData->dashboard);
if (count($getter) == 2 && is_numeric($getter[1]))
{
	// the pointers
	$t = ComponentbuilderHelper::safeString($getter[0], 'U');
	$id = (int) $getter[1];
	// the dynamic stuff
	$targets = array('A' => 'admin_views', 'C' => 'custom_admin_views');
	$names = array('A' => 'admin view', 'C' => 'custom admin view');
	$types = array('A' => 'adminview', 'C' => 'customadminview');
	$keys = array('A' => 'name_list', 'C' => 'code');
	// check the target values
	if (isset($targets[$t]) && $id > 0)
	{
		// set the type name
		$type_names = ComponentbuilderHelper::safeString($targets[$t], 'w');
		// set the dynamic dash
		if (isset($this->componentData->{$targets[$t]}) && ComponentbuilderHelper::checkArray($this->componentData->{$targets[$t]}))
		{
			// search the target views
			$dashboard = (array) array_filter($this->componentData->{$targets[$t]}, function($view) use($id, $t, $types){
				if (isset($view[$types[$t]]) && $id == $view[$types[$t]])
				{
					return true;
				}
				return false;
			});
			// check if view was found (this should be true)
			if (count($dashboard) && isset($dashboard[0]['settings']) && isset($dashboard[0]['settings']->{$keys[$t]}))
			{
				$this->dynamicDashboard = ComponentbuilderHelper::safeString($dashboard[0]['settings']->{$keys[$t]});
			}
			else
			{
				// set massage that something is wrong
				$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error');
			}
		}
		else
		{
			// set massage that something is wrong
			$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error');
		}
	}
}

So there is a few checks happening here that you can investigate:

  • if (count($getter) == 2 && is_numeric($getter[1]))
  • if (isset($targets[$t]) && $id > 0)
  • if (isset($this->componentData->{$targets[$t]}) && ComponentbuilderHelper::checkArray($this->componentData->{$targets[$t]}))
  • if (count($dashboard) && isset($dashboard[0]['settings']) && isset($dashboard[0]['settings']->{$keys[$t]}))

All the above should be true, and if not the related values should be looked at, to see why it is not true. I would so like to test things in your environment, since this must be an environment diff that is at play. I mean your environment is different from mine. I should spin up a VM with PHP7 to see these diffs more directly... soon 👍 I still run on PHP 5.6

Anyway thanks for your help with this.

Well this is the code: ``` $getter = explode('_',$this->componentData->dashboard); if (count($getter) == 2 && is_numeric($getter[1])) { // the pointers $t = ComponentbuilderHelper::safeString($getter[0], 'U'); $id = (int) $getter[1]; // the dynamic stuff $targets = array('A' => 'admin_views', 'C' => 'custom_admin_views'); $names = array('A' => 'admin view', 'C' => 'custom admin view'); $types = array('A' => 'adminview', 'C' => 'customadminview'); $keys = array('A' => 'name_list', 'C' => 'code'); // check the target values if (isset($targets[$t]) && $id > 0) { // set the type name $type_names = ComponentbuilderHelper::safeString($targets[$t], 'w'); // set the dynamic dash if (isset($this->componentData->{$targets[$t]}) && ComponentbuilderHelper::checkArray($this->componentData->{$targets[$t]})) { // search the target views $dashboard = (array) array_filter($this->componentData->{$targets[$t]}, function($view) use($id, $t, $types){ if (isset($view[$types[$t]]) && $id == $view[$types[$t]]) { return true; } return false; }); // check if view was found (this should be true) if (count($dashboard) && isset($dashboard[0]['settings']) && isset($dashboard[0]['settings']->{$keys[$t]})) { $this->dynamicDashboard = ComponentbuilderHelper::safeString($dashboard[0]['settings']->{$keys[$t]}); } else { // set massage that something is wrong $this->app->enqueueMessage(JText::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error'); } } else { // set massage that something is wrong $this->app->enqueueMessage(JText::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error'); } } } ``` So there is a few checks happening here that you can investigate: - `if (count($getter) == 2 && is_numeric($getter[1]))` - `if (isset($targets[$t]) && $id > 0)` - `if (isset($this->componentData->{$targets[$t]}) && ComponentbuilderHelper::checkArray($this->componentData->{$targets[$t]}))` - `if (count($dashboard) && isset($dashboard[0]['settings']) && isset($dashboard[0]['settings']->{$keys[$t]}))` All the above should be true, and if not the related values should be looked at, to see why it is not true. I would so like to test things in your environment, since this must be an environment diff that is at play. I mean your environment is different from mine. I should spin up a VM with PHP7 to see these diffs more directly... soon :+1: I still run on PHP 5.6 Anyway thanks for your help with this.
mwweb commented 2018-03-10 17:18:54 +00:00 (Migrated from github.com)

I ran a test in PHP 5.6 and it ran fine. The problem appears to be an incompatibility with PHP 7.

I ran a test in PHP 5.6 and it ran fine. The problem appears to be an incompatibility with PHP 7.

I thought so... but could you identify what it is? I mean should be simple.

  • Is it this dynamic targeting $this->componentData->{$targets[$t]} ?
  • is it the explode method?

Can only be one of those really... since the rest is basic PHP.

I thought so... but could you identify what it is? I mean should be simple. - Is it this dynamic targeting `$this->componentData->{$targets[$t]}` ? - is it the explode method? Can only be one of those really... since the rest is basic PHP.
Twincarb commented 2018-03-11 21:15:38 +00:00 (Migrated from github.com)

I have just tested the feature on php 7.1.13 and J3.8.6rc and it appears to be working, I was able to select a different view when opening the component admin screen.
I don't have any custom admin views to test it on at the moment...

I have just tested the feature on php 7.1.13 and J3.8.6rc and it appears to be working, I was able to select a different view when opening the component admin screen. I don't have any custom admin views to test it on at the moment...

Yes I have been running test in PHP 7.2.3 and all works well on my end, I did make some other changes to address some PHP7 issues, but they were not related to this issue.

So I am thinking to move forward with this release. Thanks for all the testing, there will soon be a pull request to V2.6.18 we can fine tune this during that process, if it still remains an issue.

Yes I have been running test in PHP 7.2.3 and all works well on my end, I did make some other changes to address some PHP7 issues, but they were not related to this issue. So I am thinking to move forward with this release. Thanks for all the testing, there will soon be a pull request to V2.6.18 we can fine tune this during that process, if it still remains an issue.
ro-ot commented 2018-03-15 01:51:49 +00:00 (Migrated from github.com)

Thanks @Llewellynvdm this feature is excellent! I am surprised at how easy it was to do that with JCB. At times we see OOP deliver on its promise.

Thanks @Llewellynvdm this feature is excellent! I am surprised at how easy it was to do that with JCB. At times we see OOP deliver on its promise.
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#148
No description provided.