Jump to content

\IPS\Helpers\Chart\Dynamic ajax call issue


GriefCode

Recommended Posts

Posted

Hey,

I have included the class in the title in my code. However, the filters appear not to work with ajax calles. They are always rendering a new page, probably then the chart without any header as it also sets 'noHeader=1'.

 

My Code:
 


  /**
	 * @return	void
	 */
	protected function manage()
	{
    $chart = new \IPS\sharedstats\DbIntegration\DynamicChart( \IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=dashboard' ), 'stats_games', 'datetime', '', array( 'isStacked' => TRUE ), 'LineChart', 'daily' );
    $chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('games'), 'number', 'COUNT(*)' );
    $chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('players'), 'number', '(COUNT(*) * 10)' );
    $chart->title = \IPS\Member::loggedIn()->language()->addToStack('Player Stats');
    $chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );

    /* Display */
    \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'sharedstats_stats_dashboard' );
    \IPS\Output::i()->breadcrumb[]	= array( NULL, \IPS\Output::i()->title );
    \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->dashboard($chart);
	}

I have used my own class as that i need to connect to a remote database. It just changed the database access.

When i call the page it does look like this:
1.thumb.PNG.4282f6bc81db6eac0122366ef8b8e7d5.PNG

Once i change a filter to as example 'weekly', i got this:
2.thumb.PNG.4c2bdf8ee70aac5a262b1ca03264f0f1.PNG

 

I used the same code as on messenger stats on ACP and there it does work. Did I miss something out? Do I need to include any JS file?

Regards

Posted

You can't use

   /* Display */
    \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'sharedstats_stats_dashboard' );
    \IPS\Output::i()->breadcrumb[]	= array( NULL, \IPS\Output::i()->title );
    \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->dashboard($chart);

for the ajax output :)

 

Try something like

if ( \IPS\Request::i()->noheader)
		{
			\IPS\Output::i()->output = $chart;
		}
		else
		{
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'sharedstats_stats_dashboard' );
\IPS\Output::i()->breadcrumb[]	= array( NULL, \IPS\Output::i()->title );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->dashboard($chart);
		}

so that only the chart is returned if it is a ajax request.

Posted
4 minutes ago, Daniel F said:

You can't use


   /* Display */
    \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'sharedstats_stats_dashboard' );
    \IPS\Output::i()->breadcrumb[]	= array( NULL, \IPS\Output::i()->title );
    \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->dashboard($chart);

for the ajax output :)

 

Try something like


if ( \IPS\Request::i()->noheader)
		{
			\IPS\Output::i()->output = $chart;
		}
		else
		{
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'sharedstats_stats_dashboard' );
\IPS\Output::i()->breadcrumb[]	= array( NULL, \IPS\Output::i()->title );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats', 'sharedstats', 'front')->dashboard($chart);
		}

 

Well you are right, but in fact it does still not load over ajax.

Changing that will only show the chart itself and nothing else, that is final for the replacing later. It would have brought up another issue, indeed :) 
5.thumb.PNG.c3295e6f7295acf12dfa4803f5642786.PNG

 

The ajax call issue is also not related to the mixed content blocking.
I've just tested that out, doesn't work eithere when it would be allowed.

Posted

The Dynamic charts, if I recall correctly, were built into the ACP and are not available by default on the front end. In order to get this working you need to include the admin JS libraries in your controller, like this:

\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin.js', 'global' ) );

You also should be sending back the chart (and only the chart) when the call is ajax, like this:

if( \IPS\Request::i()->isAjax() )
{
	\IPS\Output::i()->output = (string)$chart;
	return;
}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...