* SAAS-1197 - fix publish dialog behaviour for tasks with pending states

* SAAS-1184 - more polish on publishing/podcasting
This commit is contained in:
Duncan Sommerville 2015-11-10 17:54:31 -05:00
parent 308457c9f4
commit de380369ed
5 changed files with 56 additions and 36 deletions

View File

@ -56,21 +56,19 @@ class Application_Service_PublishService {
* ]
*/
public static function getSourceLists($fileId) {
$publishSources = $publishedSources = array();
$sources = array();
foreach (self::$SOURCES as $source => $label) {
$fn = self::$SOURCE_FUNCTIONS[$source];
// Should be in a ternary but PHP doesn't play nice
if (self::$fn($fileId)) {
$publishedSources[$source] = _($label);
} else {
$publishSources[$source] = _($label);
}
$status = self::$fn($fileId);
array_push($sources, array(
"source" => $source,
"label" => _($label),
"status" => $status
));
}
return array(
"toPublish" => $publishSources,
"published" => $publishedSources
);
return $sources;
}
/**
@ -79,8 +77,9 @@ class Application_Service_PublishService {
*
* @param int $fileId the ID of the file to check
*
* @return bool true if the file has been published to SoundCloud,
* otherwise false
* @return int 1 if the file has been published to SoundCloud,
* 0 if the file has yet to be published, or -1 if the
* file is in a pending state
*/
private static function getSoundCloudPublishStatus($fileId) {
$soundcloudService = new Application_Service_SoundcloudService();
@ -94,13 +93,14 @@ class Application_Service_PublishService {
*
* @param int $fileId the ID of the file to check
*
* @return bool true if the file has been published to the Station podcast,
* otherwise false
* @return int 1 if the file has been published to SoundCloud,
* 0 if the file has yet to be published, or -1 if the
* file is in a pending state
*/
private static function getStationPodcastPublishStatus($fileId) {
$stationPodcast = StationPodcastQuery::create()
->findOneByDbPodcastId(Application_Model_Preference::getStationPodcastId());
return $stationPodcast->hasEpisodeForFile($fileId);
return (int) $stationPodcast->hasEpisodeForFile($fileId);
}
}

View File

@ -79,18 +79,22 @@ abstract class Application_Service_ThirdPartyService {
*
* @param int $fileId the cc_files identifier
*
* @return string the service foreign identifier
* @return int 1 if the file has been published,
* 0 if the file has yet to be published,
* or -1 if the file is in a pending state
*/
public function referenceExists($fileId) {
$ref = ThirdPartyTrackReferencesQuery::create()
->filterByDbService(static::$_SERVICE_NAME)
->findOneByDbFileId($fileId); // There shouldn't be duplicates!
->findOneByDbFileId($fileId);
if (!empty($ref)) {
$task = CeleryTasksQuery::create()
->orderByDbDispatchTime(Criteria::DESC)
->findOneByDbTrackReference($ref->getDbId());
return $task->getDbStatus() != CELERY_FAILED_STATUS;
return $task->getDbStatus() == CELERY_PENDING_STATUS ? -1
: ($task->getDbStatus() == CELERY_FAILED_STATUS ? 0 : 1);
}
return false;
return 0;
}
}

View File

@ -18,9 +18,9 @@
<textarea disabled ng-model="media.description"></textarea>
<fieldset>
<legend><?php echo _("Publish to:"); ?></legend>
<div class="publish-sources" ng-repeat="(source, label) in sources.toPublish">
<input ng-model="publishData[source]" type="checkbox" name="publish_sources" id="{{source}}">
<label class="source-name" for="{{source}}">{{label}}</label><br/>
<div class="publish-sources" ng-repeat="source in sources.toPublish">
<input ng-model="publishData[source.source]" type="checkbox" name="publish_sources" id="{{source.source}}">
<label class="source-name" for="{{source.source}}">{{source.label}}</label><br/>
</div>
<div ng-if="sources.toPublish.length == 0">
<?php echo _("You have already published this track to all available sources!") . "<br/>"
@ -29,10 +29,10 @@
</fieldset>
<fieldset>
<legend><?php echo _("Published on:"); ?></legend>
<div class="published-sources" ng-repeat="(source, label) in sources.published">
<div class="published-sources" ng-repeat="source in sources.published">
<span class="sp-checked-icon checked-icon left-floated"></span>
<span class="source-name">{{label}}</span>
<button class="btn btn-small btn-danger" ng-click="remove(source)"><?php echo _("Unpublish") ?></button>
<span class="source-name">{{source.label}}</span>
<button ng-disabled="{{source.status == -1}}" class="btn btn-small btn-danger" ng-click="remove(source.source)"><?php echo _("Unpublish") ?></button>
</div>
<div ng-if="sources.published.length == 0">
<?php echo _("You haven't published this track to any sources!") . "<br/>"

View File

@ -157,7 +157,6 @@ var AIRTIME = (function (AIRTIME) {
self.$scope.tab.assignOnCloseHandler(function () {
self.episodeTable.destroy();
self.episodeTable = null;
self.$scope.tab = null;
self.$scope.$destroy();
});
}
@ -455,7 +454,6 @@ var AIRTIME = (function (AIRTIME) {
self.importListener = setInterval(function () {
var podcastId = self.config.podcastId, pendingRows = [];
if (!podcastId) return false;
console.log(self);
var dt = self.getDatatable(), data = dt.fnGetData();
// Iterate over the table data to check for any rows pending import
$.each(data, function () {

View File

@ -17,8 +17,10 @@ var AIRTIME = (function (AIRTIME) {
var publishApp = angular.module(PUBLISH_APP_NAME, [])
.controller('Publish', function ($scope, $http, mediaId, tab) {
$scope.publishSources = {};
$scope.publishData = {};
var sourceInterval;
function init () {
function fetchSourceData() {
var csrfToken = jQuery("#csrf").val();
$http.get(endpoint + mediaId, {csrf_token: csrfToken})
.success(function (json) {
@ -30,16 +32,30 @@ var AIRTIME = (function (AIRTIME) {
// and their publication state for the file with the given ID
$http.get(endpoint + mediaId + '/publish-sources', {csrf_token: csrfToken})
.success(function (json) {
$scope.sources = json;
// Store the data (whether each source should be published to when publish is clicked)
// in a separate array so we don't overwrite the labels
$scope.publishData = {};
jQuery.each($scope.sources.toPublish, function (k, v) {
$scope.publishData[k] = false;
$scope.sources = { toPublish: [], published: []};
$.each(json, function () {
if (this.status != 0) {
$scope.sources.published.push(this);
} else {
$scope.sources.toPublish.push(this);
}
});
});
}
function init() {
fetchSourceData();
sourceInterval = setInterval(function() {
fetchSourceData();
}, 5000);
tab.assignOnCloseHandler(function () {
clearInterval(sourceInterval);
$scope.$destroy();
});
}
$scope.openEditDialog = function() {
var uid = AIRTIME.library.MediaTypeStringEnum.FILE + "_" + mediaId;
$.get(baseUrl + "library/edit-file-md/id/" + mediaId, {format: "json"}, function (json) {
@ -62,7 +78,9 @@ var AIRTIME = (function (AIRTIME) {
if (data && Object.keys(data).length > 0) {
$http.put(endpoint + mediaId + '/publish', {csrf_token: jQuery("#csrf").val(), sources: data})
.success(function () {
init();
fetchSourceData();
$scope.publishData = {}; // Reset the publishData in case the user publishes
// and unpublishes without closing the tab
});
}
};
@ -74,7 +92,7 @@ var AIRTIME = (function (AIRTIME) {
+ "for this track will be permanently removed."))) {
$http.put(endpoint + mediaId + '/publish', {csrf_token: jQuery("#csrf").val(), sources: data})
.success(function () {
init();
fetchSourceData();
});
}
};