Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't show charts if there's no data
* Click stats chart: don't define data if it's not set
* Show prompt to run the crawler if it hasn't been run before
  • Loading branch information
ginatrapani committed May 4, 2012
1 parent f0fe5d0 commit 8a3c2a2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 55 deletions.
55 changes: 16 additions & 39 deletions tests/TestOfDashboardController.php
Expand Up @@ -177,7 +177,7 @@ public function testLoggedInPosts() {
$_GET['v'] = 'tweets-all';
$controller = new DashboardController(true);
$results = $controller->go();

$this->debug($results);

//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
Expand All @@ -196,13 +196,13 @@ public function testLoggedInPostsFacebook() {
$builders = $this->buildData();
$this->simulateLogin('me@example.com');


//required params
$_GET['u'] ="Joe O\'Malley";
$_GET['n'] = 'facebook';
$_GET['v'] = 'posts-all';
$controller = new DashboardController(true);
$results = $controller->go();
$this->debug($results);

$config = Config::getInstance();
$this->assertPattern('/Export/', $results);
Expand All @@ -222,7 +222,6 @@ public function testLoggedInPostsGooglePlus() {
$this->assertPattern('/Export/', $results);
}


public function testLoggedInPostsWithUsernameApostrophe() {
$builders = $this->buildData();
$this->simulateLogin('me@example.com');
Expand Down Expand Up @@ -261,27 +260,6 @@ public function testNotLoggedInNotPublicInstance() {
$this->assertEqual($error_msg, 'Insufficient privileges');
}

public function testLoggedInConversations() {
$builders = $this->buildData();
//must be logged in
$this->simulateLogin('me@example.com');
//required params
$_GET['u'] = 'ev';
$_GET['n'] = 'twitter';
$_GET['v'] = 'tweets-convo';
$controller = new DashboardController(true);
$results = $controller->go();

//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertEqual($v_mgr->getTemplateDataItem('header'), 'Conversations', 'Header');
$this->assertIsA($v_mgr->getTemplateDataItem('author_replies'), 'array', 'Array of tweets');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('author_replies')), 0);

$config = Config::getInstance();
$this->assertEqual($controller->getCacheKeyString(), '.htdashboard.tpl-me@example.com-ev-twitter-tweets-convo');
}

public function testLoggedInPeople() {
$builders = $this->buildData();
//first, add some people
Expand Down Expand Up @@ -360,26 +338,29 @@ private function buildData($with_xss = false) {
$instance_owner_builder_3 = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>3));

//Insert test data into test table
$user_builder_1 = FixtureBuilder::build('users', array('user_id'=>'13', 'user_name'=>'ev',
'full_name'=>'Ev Williams', 'last_updated'=>'-1d'));
$user_builders = array();

$user_builder_2 = FixtureBuilder::build('users', array('user_id'=>'12', 'user_name'=>'jack',
'last_updated'=>'-5d'));
$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'13', 'user_name'=>'ev',
'full_name'=>'Ev Williams', 'network'=>'twitter', 'last_updated'=>'-1d'));

$user_builder_3 = FixtureBuilder::build('users', array('user_id'=>'14', 'user_name'=>"Joe O'Malley",
$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'12', 'user_name'=>'jack',
'network'=>'twitter', 'last_updated'=>'-5d'));

$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'14', 'user_name'=>"Joe O'Malley",
'last_updated'=>'-5d', 'network'=>'facebook'));

$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'16', 'user_name'=>"Kim",
'last_updated'=>'-5d', 'network'=>'google+'));

//Make public
$instance_builder_1 = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>'13',
'network_username'=>'ev', 'is_public'=>1, 'crawler_last_run'=>'-1d'));
'network_username'=>'ev', 'is_public'=>1, 'crawler_last_run'=>'-1d', 'network'=>'twitter'));

$instance_builder_2 = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>'16',
'network_username'=>"Kim", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'google+'));

$instance_builder_3 = FixtureBuilder::build('instances', array('id'=>3, 'network_user_id'=>'15',
$instance_builder_3 = FixtureBuilder::build('instances', array('id'=>3, 'network_user_id'=>'14',
'network_username'=>"Joe O'Malley", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'facebook'));

$instance_builder_2 = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>'16',
'network_username'=>"Kim", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'google+'));

$post_builders = array();
//Add a bunch of posts
Expand Down Expand Up @@ -407,7 +388,6 @@ private function buildData($with_xss = false) {
'author_username'=>"Joe O'Malley", 'author_fullname'=>"Joe O\'Malley", 'post_text'=>"Joe's post",
'network'=>'facebook'));


$counter = 0;
$post_data = 'This is post ';
while ($counter < 40) {
Expand All @@ -418,13 +398,10 @@ private function buildData($with_xss = false) {
$counter++;
}


return array($owner_builder, $instance_owner_builder_1, $instance_owner_builder_2, $instance_owner_builder_3,
$user_builder_1, $user_builder_2, $instance_builder_1, $instance_builder_2, $instance_builder_3,
$post_builders);
$user_builders, $instance_builder_1, $instance_builder_2, $instance_builder_3, $post_builders);
}


public function testGetHotPostVisualizationData() {
$hot_posts = array(
(object)array(
Expand Down
3 changes: 1 addition & 2 deletions tests/WebTestOfUpgradeDatabase.php
Expand Up @@ -454,7 +454,6 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
* @return str Path to download file
*/
private function getInstall($url, $version, $path) {

$ch = curl_init();
$zipfile = $path . '/' . $version . '.zip';

Expand All @@ -467,7 +466,7 @@ private function getInstall($url, $version, $path) {
$data = curl_exec($ch);
if ( !$data) {
$zipfile = false;
$this->fail("Unable to download zipfile: $url " . curl_error($ch) );
$this->fail("Unable to download zip file: $url " . curl_error($ch) );
return false;
}
file_put_contents($zipfile, $data);
Expand Down
6 changes: 6 additions & 0 deletions webapp/_lib/controller/class.DashboardController.php
Expand Up @@ -173,6 +173,11 @@ private function setInstance() {
$user_dao = DAOFactory::getDAO('UserDAO');
$user = $user_dao->getDetails($this->instance->network_user_id, $this->instance->network);
$this->addToView('user_details', $user);
if (Session::isLoggedIn() && !isset($user)) {
$this->addInfoMessage("Oops! There's no information about ".$this->instance->network_username.
" on ".ucfirst($this->instance->network)." to display.");
$this->addToView('show_update_now_button', true);
}

SessionCache::put('selected_instance_network', $this->instance->network);
SessionCache::put('selected_instance_username', $this->instance->network_username);
Expand All @@ -190,6 +195,7 @@ private function setInstance() {
SessionCache::put('selected_instance_network', null);
SessionCache::put('selected_instance_username', null);
}

$this->addToView('developer_log', $config->getValue('is_log_verbose'));
}

Expand Down
9 changes: 0 additions & 9 deletions webapp/_lib/controller/class.UpgradeApplicationController.php
Expand Up @@ -28,10 +28,6 @@
*
*/
class UpgradeApplicationController extends ThinkUpAuthController {
/**
* @var bool
*/
static $DEBUG = false;
/**
* Constructor
* @param bool $session_started
Expand All @@ -40,8 +36,6 @@ class UpgradeApplicationController extends ThinkUpAuthController {
public function __construct($session_started=false) {
parent::__construct($session_started);
$this->setViewTemplate('install.upgrade-application.tpl');
$config = Config::getInstance();
self::$DEBUG = $config->getValue('debug');
}

public function authControl() {
Expand Down Expand Up @@ -87,9 +81,6 @@ public function runUpdate($file_path, $verify_updatable = false) {
// do we have the disk space we need?
$disk_util = new AppUpgraderDiskUtil($app_dir);
$disk_space_megs = $disk_util->getAvailableDiskSpace();
if (self::$DEBUG) {
printf("%.2f megs of disk space available\n", $disk_space_megs);
}
// do we have the perms to do what we need?
$disk_util->validateUpdatePermissions($app_dir);

Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/model/class.AppUpgraderClient.php
Expand Up @@ -89,7 +89,7 @@ public function getLatestVersionZip($url) {
* @return request response data
*/
private function fetchURLData($url) {
if (strpos($url, "/") == 0) { // we are a file path, so use file_get_contents
if (strpos($url, "/") == 0 || strpos($url, ".") == 0) { // we are a file path, so use file_get_contents
$contents = file_get_contents($url);
} else { // else we are a url, so use our Util::getURLContents
$contents = Utils::getURLContents(URLProcessor::getFinalURL($url));
Expand Down
18 changes: 14 additions & 4 deletions webapp/_lib/view/dashboard.tpl
Expand Up @@ -3,7 +3,6 @@

<div class="container_24">
<div class="clearfix">

<!-- begin left nav -->
<div class="grid_4 alpha omega">
{if $instance}
Expand Down Expand Up @@ -36,6 +35,10 @@
<div class="prefix_1 suffix_1">

{include file="_usermessage.tpl"}
{if $show_update_now_button eq true}
<br>
<a href="{$site_root_path}crawler/updatenow.php{if $developer_log}?log=full{/if}" class="linkbutton emphasized">Load Data Now</a>
{/if}

{if $instance}
<!--begin public user dashboard-->
Expand All @@ -56,12 +59,10 @@
</div>
</div>
</div>
{/if}

{if $data_template}
{include file=$data_template}
{else} <!-- else if no $data_template -->

{if $hot_posts_data}
<div class="section">
<h2>Response Rates</h2>
Expand Down Expand Up @@ -216,14 +217,18 @@
function drawCharts() {
{/literal}
{if $follower_count_history_by_day.history && $follower_count_history_by_week.history}
var follower_count_history_by_day_data = new google.visualization.DataTable(
{$follower_count_history_by_day.vis_data});
var follower_count_history_by_week_data = new google.visualization.DataTable(
{$follower_count_history_by_week.vis_data});
{/if}
var hot_posts_data = new google.visualization.DataTable({$hot_posts_data});
var client_usage_data = new google.visualization.DataTable({$all_time_clients_usage});
{if $click_stats_data}
var click_stats_data = new google.visualization.DataTable({$click_stats_data});
{/if}
{literal}
Expand Down Expand Up @@ -284,6 +289,7 @@
{/literal}
{/if}
{if $follower_count_history_by_day.history && $follower_count_history_by_week.history}
{literal}
formatter.format(follower_count_history_by_day_data, 1);
formatter_date.format(follower_count_history_by_day_data, 0);
Expand Down Expand Up @@ -340,6 +346,9 @@
},
});
follower_count_history_by_week_chart.draw();
{/literal}
{/if}
{literal}
if (typeof(replies) != 'undefined') {
var post_types = new google.visualization.DataTable();
Expand Down Expand Up @@ -397,6 +406,7 @@
</script>
{/if} <!-- end if $data_template -->
{/if}
{/if}
{if !$instance}
Expand Down

0 comments on commit 8a3c2a2

Please sign in to comment.