Skip to content

Commit

Permalink
Make it more apparent refreshing sources has finished (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
niol committed Mar 14, 2017
1 parent afb0751 commit 00ced63
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 66 deletions.
25 changes: 21 additions & 4 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ body * {
outline:0;
}

#error {
#message {
display:none;
position:absolute;
width:100%;
background:#f2dede;
border:1px solid #eed3d7;
color:#b94a48;
background:#e6e6fa;
border:1px solid #00008b;
color:#00008b;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
filter: alpha(opacity=90);
-moz-opacity: 0.9;
Expand All @@ -44,6 +44,23 @@ body * {
padding:10px;
}

#message a {
font-size:0.9em;
text-align:center;
-moz-border-radius:2px;
-webkit-border-radius:2px;
-khtml-border-radius:2px;
border-radius:2px;
cursor:pointer;
background:#cccccc;
}

#message.error {
background:#f2dede;
border-color:#eed3d7;
color:#b94a48;
}


/* navigation */

Expand Down
54 changes: 18 additions & 36 deletions public/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ var selfoss = {
if (textStatus == "abort")
return;
else if (errorThrown)
selfoss.showError('Load list error: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Load list error: '+
textStatus+' '+errorThrown);
selfoss.events.entries();
selfoss.ui.refreshStreamButtons();
$('.stream-error').show();
Expand All @@ -247,10 +247,13 @@ var selfoss = {
var force = (typeof force !== 'undefined') ? force : false;

if( !force && (selfoss.lastUpdate == null ||
Date.now() - selfoss.lastSync < 5*60*1000) )
return;
Date.now() - selfoss.lastSync < 5*60*1000) ) {
var d = $.Deferred();
d.resolve();
return d; // ensure any chained function runs
}

$.ajax({
return $.ajax({
url: 'items/sync',
type: 'GET',
dataType: 'json',
Expand Down Expand Up @@ -291,8 +294,8 @@ var selfoss = {
selfoss.lastUpdate = dataDate;
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showError('Could not sync last changes from server: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Could not sync last changes from server: '+
textStatus+' '+errorThrown);
}
});
},
Expand Down Expand Up @@ -352,8 +355,8 @@ var selfoss = {
selfoss.events.navigation();
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showError('Load tags error: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Load tags error: '+
textStatus+' '+errorThrown);
},
complete: function(jqXHR, textStatus) {
$('#nav-tags').removeClass('loading');
Expand All @@ -374,7 +377,7 @@ var selfoss = {
$('#nav-tags').append(tags);
if( selfoss.filter.tag ) {
if(!selfoss.db.isValidTag(selfoss.filter.tag))
selfoss.showError('Unknown tag: ' + selfoss.filter.tag);
selfoss.ui.showError('Unknown tag: ' + selfoss.filter.tag);

$('#nav-tags li:first').removeClass('active');
$('#nav-tags > li').filter(function( index ) {
Expand Down Expand Up @@ -404,8 +407,8 @@ var selfoss = {
$('#nav-sources').append(sources);
if( selfoss.filter.source ) {
if(!selfoss.db.isValidSource(selfoss.filter.source))
selfoss.showError('Unknown source id: '
+ selfoss.filter.source);
selfoss.ui.showError('Unknown source id: '
+ selfoss.filter.source);

$('#source' + selfoss.filter.source).addClass('active');
$('#nav-tags > li').removeClass('active');
Expand Down Expand Up @@ -436,28 +439,7 @@ var selfoss = {
});
}
},


/**
* show error
*
* @return void
* @param message string
*/
showError: function(message) {
if(typeof(message) == 'undefined') {
var message = "Oops! Something went wrong";
}
var error = $('#error');
error.html(message);
error.show();
window.setTimeout(function() {
error.click();
}, 10000);
error.unbind('click').click(function() {
error.fadeOut();
});
},


/**
* Setup fancyBox image viewer
Expand Down Expand Up @@ -535,8 +517,8 @@ var selfoss = {
$('#content').removeClass('loading');
selfoss.ui.refreshStreamButtons(true, true, hadMore);
selfoss.events.entries();
selfoss.showError('Can not mark all visible item: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Can not mark all visible item: '+
textStatus+' '+errorThrown);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions public/js/selfoss-events-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ selfoss.events.entries = function(e) {
},
error: function(jqXHR, textStatus, errorThrown) {
streamMore.removeClass('loading');
selfoss.showError('Load more error: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Load more error: '+
textStatus+' '+errorThrown);
}
});
});
Expand Down
8 changes: 4 additions & 4 deletions public/js/selfoss-events-entriestoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ selfoss.events.entriesToolbar = function(parent) {
// rollback ui changes
selfoss.ui.entryStarr(id, !starr);
updateStats(!starr);
selfoss.showError('Can not star/unstar item: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Can not star/unstar item: '+
textStatus+' '+errorThrown);
}
});

Expand Down Expand Up @@ -173,8 +173,8 @@ selfoss.events.entriesToolbar = function(parent) {
// rollback ui changes
selfoss.ui.entryMark(id, unread);
updateStats(!unread);
selfoss.showError('Can not mark/unmark item: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Can not mark/unmark item: '+
textStatus+' '+errorThrown);
}
});

Expand Down
24 changes: 16 additions & 8 deletions public/js/selfoss-events-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ selfoss.events.navigation = function() {
selfoss.reloadList();
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showError('Can not save new color: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Can not save new color: '+
textStatus+' '+errorThrown);
}
});

Expand Down Expand Up @@ -120,8 +120,8 @@ selfoss.events.navigation = function() {
selfoss.refreshSources(data.sources);
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showError('Can not load nav stats: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Can not load nav stats: '+
textStatus+' '+errorThrown);
}
});
}else{
Expand Down Expand Up @@ -168,12 +168,20 @@ selfoss.events.navigation = function() {
// hide nav on smartphone
if(selfoss.isSmartphone())
$('#nav-mobile-settings').click();

// refresh list
selfoss.sync(true);

// probe stats and prompt reload to the user
selfoss.sync(true).done(function() {
var refreshed = 'Sources have been refreshed';
if( $('.unread-count').hasClass('unread') ) {
selfoss.ui.showMessage(refreshed, 'Reload list',
function() {
$('#nav-filter-unread').click();
});
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showError('Cannot refresh sources: ' + errorThrown);
selfoss.ui.showError('Cannot refresh sources: ' + errorThrown);
},
complete: function(data) {
$('#nav-refresh').removeClass('loading');
Expand Down
8 changes: 4 additions & 4 deletions public/js/selfoss-events-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ selfoss.events.sources = function() {
},
error: function(jqXHR, textStatus, errorThrown) {
parent.find('.source-edit-delete').removeClass('loading');
selfoss.showError('Error adding source: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Error adding source: '+
textStatus+' '+errorThrown);
}
});
});
Expand Down Expand Up @@ -95,7 +95,7 @@ selfoss.events.sources = function() {
selfoss.events.navigation();
},
error: function(jqXHR, textStatus, errorThrown) {
selfoss.showErrors(parent, $.parseJSON(jqXHR.responseText));
selfoss.ui.showErrors(parent, $.parseJSON(jqXHR.responseText));

This comment has been minimized.

Copy link
@jtojnar

jtojnar Mar 14, 2017

Member

This should not be changed.

},
complete: function(jqXHR, textStatus) {
parent.find('.source-action').removeClass('loading');
Expand Down Expand Up @@ -134,7 +134,7 @@ selfoss.events.sources = function() {
},
error: function(jqXHR, textStatus, errorThrown) {
parent.find('.source-edit-delete').removeClass('loading');
selfoss.showError('Error deleting source: '+errorThrown);
selfoss.ui.showError('Error deleting source: '+errorThrown);
}
});
});
Expand Down
14 changes: 7 additions & 7 deletions public/js/selfoss-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ selfoss.events = {
selfoss.filter.sourcesNav = true;
}
} else if( selfoss.events.subsection != 'all' ) {
selfoss.showError('Invalid subsection: '
+ selfoss.events.subsection);
selfoss.ui.showError('Invalid subsection: '
+ selfoss.events.subsection);
done();
return;
}
Expand All @@ -142,8 +142,8 @@ selfoss.events = {
selfoss.reloadList();
} else if(hash=="sources") { // load sources
if( selfoss.events.subsection ) {
selfoss.showError('Invalid subsection: '
+ selfoss.events.subsection);
selfoss.ui.showError('Invalid subsection: '
+ selfoss.events.subsection);
done();
return;
}
Expand All @@ -164,15 +164,15 @@ selfoss.events = {
if (textStatus == "abort")
return;
else if (errorThrown)
selfoss.showError('Load list error: '+
textStatus+' '+errorThrown);
selfoss.ui.showError('Load list error: '+
textStatus+' '+errorThrown);
},
complete: function(jqXHR, textStatus) {
$('#content').removeClass('loading');
}
});
} else {
selfoss.showError('Invalid section: ' + selfoss.events.section);
selfoss.ui.showError('Invalid section: ' + selfoss.events.section);
}
done();
},
Expand Down
47 changes: 47 additions & 0 deletions public/js/selfoss-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,53 @@ selfoss.ui = {
$('.mark-these-read').hide();
}
}
},


/**
* show error
*
* @return void
* @param message string
*/
showError: function(message) {
selfoss.ui.showMessage(message, 'undefined', 'undefined', true);
},


showMessage: function(message, actionText, action, error) {
var actionText = (typeof actionText !== 'undefined') ? actionText: false;
var action = (typeof action !== 'undefined') ? action : false;
var error = (typeof error !== 'undefined') ? error: false;

if(typeof(message) == 'undefined') {
var message = "Oops! Something went wrong";
}

if( actionText && action ) {
message = message + '. <a>' + actionText + '</a>';
}

var messageContainer = $('#message');
messageContainer.html(message);

if( action ) {
messageContainer.find('a').unbind('click').click(action);
}

if( error ) {
messageContainer.addClass('error');
} else {
messageContainer.removeClass('error');
}

messageContainer.show();
window.setTimeout(function() {
messageContainer.click();
}, 15000);
messageContainer.unbind('click').click(function() {
messageContainer.fadeOut();
});
}


Expand Down
2 changes: 1 addition & 1 deletion templates/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<?= \F3::get('auto_mark_as_read') == 1 ? 'auto_mark_as_read' : ''; ?>
">

<div id="error"></div>
<div id="message"></div>

<!-- language settings for jQuery -->
<span id="lang"
Expand Down

0 comments on commit 00ced63

Please sign in to comment.