Merge branch 'saas-dev-usability-hints' of github.com:sourcefabric/Airtime into saas-dev-usability-hints

This commit is contained in:
Albert Santoni 2015-07-14 10:35:47 -04:00
commit 5a2ef8d3db
8 changed files with 135 additions and 1 deletions

View File

@ -2,6 +2,86 @@
class Application_Common_UsabilityHints
{
/**
* @param $userPath User's current location in Airtime (i.e. /Plupload)
* @return string
*/
public static function getUsabilityHint($userPath=null)
{
// We want to display hints in this order:
// 1. Check if files are uploaded
// 2. Check if a show is scheduled
// 3. Check if scheduled show needs content
// Once the user is on the page linked to from the hint we want to
// display a new message further describing what to do. Once this
// action has been done we can hide the message and get the next
// usability hint, if there is one.
$userIsOnCalendarPage = false;
$userIsOnAddMediaPage = false;
// If $userPath is set the request came from AJAX so the user's
// current location inside Airtime gets passed in to this function.
if (!is_null($userPath)) {
// We check if the controller names are in the user's current location
// so we can ignore leading or trailing slashes, special characters like '#',
// and additional controller action names like '/user/add-user'
if (strpos(strtolower($userPath), 'plupload') !== false) {
$userIsOnAddMediaPage = true;
}
if (strpos(strtolower($userPath), 'schedule') !== false) {
$userIsOnCalendarPage = true;
}
} else {
// If $userPath is not set the request came from inside Airtime so
// we can use Zend's Front Controller to get the user's current location.
$currentController = strtolower(Zend_Controller_Front::getInstance()->getRequest()->getControllerName());
if ($currentController == "schedule") {
$userIsOnCalendarPage = true;
}
if ($currentController == "plupload") {
$userIsOnAddMediaPage = true;
}
}
if (self::zeroFilesUploaded()) {
if ($userIsOnAddMediaPage) {
return _("Click the 'Add files' button and select files from your computer to upload.");
} else {
return sprintf(_("It looks like you have not uploaded any audio files yet. %sUpload a file now.%s "),
"<a href=\"/plupload\">",
"</a>");
}
} else if (!self::isFutureOrCurrentShowScheduled()) {
if ($userIsOnCalendarPage) {
return _("Click the 'Create New Show' button and fill out the required fields.");
} else {
return sprintf(_("It looks like you don't have any shows scheduled. %sCreate a show now.%s"),
"<a href=\"/schedule\">",
"</a>");
}
} else if (self::isCurrentOrNextShowEmpty()) {
if ($userIsOnCalendarPage) {
return _("To start broadcasting click on your show and select 'Add / Remove Content'");
} else {
//TODO: break this into two functions (current and next) so message is more clear
return sprintf(_("It looks like your show is empty. %sAdd tracks to your show now.%s"),
"<a href=\"/schedule\">",
"</a>");
}
} else {
return "";
}
}
//TODO: make functions below private?
/**
* Returns true if no files have been uploaded.
*/
@ -48,9 +128,11 @@ class Application_Common_UsabilityHints
if (is_null($futureShow) && is_null($currentShow)) {
return false;
} else {
$now = new DateTime("now", new DateTimeZone("UTC"));
if ($currentShow) {
$scheduledTracks = CcScheduleQuery::create()
->filterByDbInstanceId($currentShow->getDbId())
->filterByDbEnds($now, Criteria::GREATER_EQUAL)
->find();
if ($scheduledTracks->count() == 0) {
return true;
@ -58,6 +140,7 @@ class Application_Common_UsabilityHints
} else if ($futureShow) {
$scheduledTracks = CcScheduleQuery::create()
->filterByDbInstanceId($futureShow->getDbId())
->filterByDbStarts($now, Criteria::GREATER_EQUAL)
->find();
if ($scheduledTracks->count() == 0) {
return true;

View File

@ -64,6 +64,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('update-stream-setting-table' , 'json')
->addActionContext('update-replay-gain-value' , 'json')
->addActionContext('update-cue-values-by-silan' , 'json')
->addActionContext('get-usability-hint' , 'json')
->initContext();
}
@ -1466,5 +1467,13 @@ class ApiController extends Zend_Controller_Action
}
$this->_helper->json->sendJson(array(1));
}
public function getUsabilityHintAction()
{
$userPath = $this->_getParam("userPath");
$hint = Application_Common_UsabilityHints::getUsabilityHint($userPath);
$this->_helper->json->sendJson($hint);
}
}

View File

@ -71,6 +71,15 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
<div class="wrapper" id="content">
<?php
$hint = Application_Common_UsabilityHints::getUsabilityHint();
if ($hint != "") { ?>
<div class="usability_hint"><?php echo $hint; ?></div>
<?php
}
?>
<!--
<?php if (Application_Common_UsabilityHints::zeroFilesUploaded()) { ?>
<div class="usability_hint">
<?php echo sprintf(_("It looks like you have not uploaded any audio files yet. %shere%s to upload a file."), "Click <a href='/plupload'>", "</a>"); ?>
@ -88,6 +97,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
<?php echo sprintf(_("To start broadcasting click %shere%s to schedule a track into your show."), "<a href='/showbuilder'>", "</a>"); ?>
</div>
<?php } ?>
-->
<?php echo $this->layout()->content ?></div>

View File

@ -161,3 +161,28 @@ function removeSuccessMsg() {
$status.fadeOut("slow", function(){$status.empty()});
}
function getUsabilityHint() {
var pathname = window.location.pathname;
$.getJSON("/api/get-usability-hint", {"format": "json", "userPath": pathname}, function(json) {
var $hint_div = $('.usability_hint');
var current_hint = $hint_div.html();
if (json === "") {
// there are no more hints to display to the user
$hint_div.hide();
} else if (current_hint !== json) {
// we only change the message if it is new
if ($hint_div.is(":hidden")) {
$hint_div.show();
}
$hint_div.slideUp("slow");
$hint_div.html(json);
$hint_div.slideDown("slow");
} else {
// hint is the same before we hid it so we just need to show it
if ($hint_div.is(":hidden")) {
$hint_div.show();
}
}
});
}

View File

@ -146,6 +146,9 @@ $(document).ready(function() {
} else {
self.stopRefreshingRecentUploads();
}
// Update usability hint - in common.js
getUsabilityHint();
}
} );
}

View File

@ -359,6 +359,7 @@ function getFullCalendarEvents(start, end, callback) {
var d = new Date();
$.post(url, {format: "json", start: start_date, end: end_date, cachep: d.getTime()}, function(json){
callback(json.events);
getUsabilityHint();
});
}
}

View File

@ -154,6 +154,7 @@ function buildScheduleDialog (json, instance_id) {
"class": "btn",
click: function() {
$(this).dialog("close");
//getUsabilityHint();
}
}
]

View File

@ -283,6 +283,8 @@ var AIRTIME = (function(AIRTIME){
mod.enableUI();
//Unneccessary reload of the library pane after moving tracks in the showbuilder pane.
//$("#library_content").find("#library_display").dataTable().fnStandingRedraw();
getUsabilityHint();
};
mod.getSelectedCursors = function() {
@ -316,7 +318,7 @@ var AIRTIME = (function(AIRTIME){
mod.disableUI();
$.post(baseUrl+"showbuilder/schedule-add",
{"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds},
{"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds},
mod.fnItemCallback
);
};