Unify `loading-spinner` helper, add conditional support via component

This commit is contained in:
Robin Ward 2014-11-12 15:10:36 -05:00
parent e1dda2337b
commit 03bc91f204
28 changed files with 87 additions and 117 deletions

View File

@ -1,13 +1,5 @@
import ObjectController from 'discourse/controllers/object';
/**
This controller previews an email digest
@class AdminEmailPreviewDigestController
@extends ObjectController
@namespace Discourse
@module Discourse
**/
export default ObjectController.extend({
actions: {

View File

@ -18,14 +18,10 @@
</div>
</div>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if showHtml}}
{{{html_content}}}
{{else}}
<pre>{{{text_content}}}</pre>
{{/if}}
{{/if}}
{{/loading-spinner}}

View File

@ -146,10 +146,8 @@
</tbody>
</table>
{{#if view.loading}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=view.loading}}
{{else}}
<p>{{i18n admin.flags.no_results}}</p>
{{/if}}

View File

@ -1,8 +1,6 @@
<p>{{i18n admin.logs.screened_emails.description}}</p>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if model.length}}
<div class='table screened-emails'>
@ -23,4 +21,4 @@
{{else}}
{{i18n search.no_results}}
{{/if}}
{{/if}}
{{/loading-spinner}}

View File

@ -3,9 +3,7 @@
{{screened-ip-address-form action="recordAdded"}}
<br/>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if model.length}}
<div class='table admin-logs-table screened-ip-addresses'>
@ -25,4 +23,4 @@
{{else}}
{{i18n search.no_results}}
{{/if}}
{{/if}}
{{/loading-spinner}}

View File

@ -1,10 +1,7 @@
<p>{{i18n admin.logs.screened_urls.description}}</p>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if model.length}}
<div class='table screened-urls'>
<div class="heading-container">
<div class="col heading first domain">{{i18n admin.logs.screened_urls.domain}}</div>
@ -17,8 +14,7 @@
{{view 'screened-urls-list' content=controller}}
</div>
{{else}}
{{i18n search.no_results}}
{{/if}}
{{/if}}
{{/loading-spinner}}

View File

@ -43,14 +43,11 @@
<div class="clearfix"></div>
</div>
{{#if loading}}
<br/>
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if model.length}}
{{view "staff-action-logs-list" content=controller}}
{{else}}
{{i18n search.no_results}}
{{/if}}
{{/if}}
{{/loading-spinner}}
</div>

View File

@ -3,7 +3,7 @@
<div>
{{i18n admin.dashboard.reports.start_date}} {{input type="date" value=startDate}}
{{i18n admin.dashboard.reports.end_date}} {{input type="date" value=endDate}}
<button {{action refreshReport}} class='btn btn-primary'>{{i18n admin.dashboard.reports.refresh_report}}</button>
<button {{action "refreshReport"}} class='btn btn-primary'>{{i18n admin.dashboard.reports.refresh_report}}</button>
</div>
<div class='view-options'>
@ -20,9 +20,7 @@
{{/if}}
</div>
{{#if refreshing}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=refreshing}}
<table class='table report'>
<tr>
<th>{{xaxis}}</th>
@ -45,4 +43,4 @@
</tr>
{{/each}}
</table>
{{/if}}
{{/loading-spinner}}

View File

@ -6,9 +6,7 @@
</div>
</div>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
<div class='admin-container user-badges'>
<h2>{{i18n admin.badges.grant_badge}}</h2>
{{#if noBadges}}
@ -56,4 +54,4 @@
{{/each}}
</table>
</div>
{{/if}}
{{/loading-spinner}}

View File

@ -37,9 +37,7 @@
</div>
</div>
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#if model.length}}
<table class='table'>
<tr>
@ -101,5 +99,5 @@
{{else}}
<p>{{i18n search.no_results}}</p>
{{/if}}
{{/if}}
{{/loading-spinner}}
</div>

View File

@ -7,6 +7,7 @@
@module Discourse
**/
export default Ember.Component.extend({
loading: Ember.computed.not('loaded'),
loaded: function() {
var topicList = this.get('topicList');

View File

@ -0,0 +1,3 @@
export default Ember.Component.extend({
layoutName: 'components/conditional-loading-spinner'
});

View File

@ -486,6 +486,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
}.property('selectedPostsCount'),
hasError: Ember.computed.or('notFoundHtml', 'message'),
noErrorYet: Ember.computed.not('hasError'),
multiSelectChanged: function() {
// Deselect all posts when multi select is turned off

View File

@ -3,7 +3,8 @@
var classify = Ember.String.classify;
var get = Ember.get;
var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags', 'user', 'preferences'],
var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags',
'user', 'preferences', 'adminEmail'],
_dummyRoute,
_loadingView;

View File

@ -1,7 +1,25 @@
import ConditionalLoadingSpinner from 'discourse/components/conditional-loading-spinner';
var spinnerHTML = "<div class='spinner'></div>";
Handlebars.registerHelper('loading-spinner', function() {
return new Handlebars.SafeString(spinnerHTML);
/**
If you use it as a regular helper {{loading-spinner}} you'll just get the
HTML for a spinner.
If you provide an `condition=xyz` parameter, it will be bound to that property
and only show when it's truthy.
If you use the block form `{{#loading-spinner}} ... {{/loading-spinner}`,
the contents will shown when the loading condition finishes.
**/
Handlebars.registerHelper('loading-spinner', function(options) {
var hash = options.hash;
if (hash && hash.condition) {
var types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, ConditionalLoadingSpinner, options);
} else {
return new Handlebars.SafeString(spinnerHTML);
}
});
export { spinnerHTML };

View File

@ -35,10 +35,10 @@
</div>
{{/each}}
</div>
{{#if canLoadMore}}
{{loading-spinner}}
{{else}}
{{loading-spinner condition=canLoadMore}}
{{#unless canLoadMore}}
{{custom-html "footer"}}
{{/if}}
{{/unless}}
{{/if}}
</div>

View File

@ -1,4 +1,4 @@
{{#if loaded}}
{{#loading-spinner condition=loading}}
{{#if topics}}
<table class="topic-list">
<thead>
@ -55,6 +55,4 @@
{{i18n choose_topic.none_found}}
</div>
{{/if}}
{{else}}
{{loading-spinner}}
{{/if}}
{{/loading-spinner}}

View File

@ -0,0 +1,5 @@
{{#if condition}}
{{loading-spinner}}
{{else}}
{{yield}}
{{/if}}

View File

@ -10,9 +10,7 @@
</div>
</div>
{{#if loading}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=loading}}
<div {{bind-attr class=":container :list-container loading:hidden"}}>
<div class="row">

View File

@ -71,9 +71,7 @@
</div>
<footer class='topic-list-bottom'>
{{#if loadingMore}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=loadingMore}}
{{#if allLoaded}}
{{#if showDismissRead}}
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" id='dismiss-topics' class='btn dismiss-read' {{action "dismissRead" "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>

View File

@ -1,4 +1,4 @@
{{#if loaded}}
{{#loading-spinner condition=loading}}
{{#if topics}}
<table class="topic-list">
<tbody>
@ -53,6 +53,4 @@
{{i18n choose_topic.none_found}}
</div>
{{/if}}
{{else}}
{{loading-spinner}}
{{/if}}
{{/loading-spinner}}

View File

@ -24,9 +24,7 @@
</div>
<footer class='topic-list-bottom'>
{{#if loadingMore}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=loadingMore}}
{{#if allLoaded}}
{{#if showDismissRead}}
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" id='dismiss-topics' class='btn dismiss-read' {{action "dismissRead" "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>

View File

@ -1,5 +1,5 @@
<section class="d-dropdown" id="notifications-dropdown">
{{#unless loadingNotifications}}
{{#loading-spinner condition=loadingNotifications}}
{{#if content}}
<ul>
{{#each itemController="notification"}}
@ -12,7 +12,5 @@
{{else}}
<div class="none">{{i18n notifications.none}}</div>
{{/if}}
{{else}}
{{loading-spinner}}
{{/unless}}
{{/loading-spinner}}
</section>

View File

@ -71,9 +71,7 @@
{{render 'topic-progress'}}
{{#if postStream.loadingAbove}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=postStream.loadingAbove}}
{{#unless postStream.loadingFilter}}
{{cloaked-collection cloakView="post"
@ -88,9 +86,7 @@
offsetFixedBottom="#reply-control"}}
{{/unless}}
{{#if postStream.loadingBelow}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=postStream.loadingBelow}}
</div>
<div id='topic-bottom'></div>
@ -120,31 +116,25 @@
</div>
{{else}}
{{#if hasError}}
<div class='container'>
{{#if notFoundHtml}}
{{{notFoundHtml}}}
{{else}}
<div class="topic-error">
<div>{{message}}</div>
{{#if noRetry}}
{{#unless currentUser}}
<button {{action "showLogin"}} class='btn btn-primary topic-retry'>{{fa-icon user}} {{i18n log_in}}</button>
{{/unless}}
{{else}}
<button class="btn btn-primary topic-retry" {{action "retryLoading"}}>{{fa-icon "refresh"}} {{i18n errors.buttons.again}}</button>
{{/if}}
</div>
{{#if retrying}}
{{loading-spinner}}
<div class='container'>
{{#loading-spinner condition=noErrorYet}}
{{#if notFoundHtml}}
{{{notFoundHtml}}}
{{else}}
<div class="topic-error">
<div>{{message}}</div>
{{#if noRetry}}
{{#unless currentUser}}
<button {{action "showLogin"}} class='btn btn-primary topic-retry'>{{fa-icon user}} {{i18n log_in}}</button>
{{/unless}}
{{else}}
<button class="btn btn-primary topic-retry" {{action "retryLoading"}}>{{fa-icon "refresh"}} {{i18n errors.buttons.again}}</button>
{{/if}}
</div>
{{loading-spinner condition=retrying}}
{{/if}}
{{/if}}
</div>
{{else}}
<div class='container'>
{{loading-spinner}}
</div>
{{/if}}
{{/loading-spinner}}
</div>
{{/if}}
{{#if postStream.loadedAllPosts}}

View File

@ -69,9 +69,7 @@
</tr>
{{/each}}
</table>
{{#if invitesLoading}}
{{loading-spinner}}
{{/if}}
{{loading-spinner condition=invitesLoading}}
{{else}}
{{#if canBulkInvite}}

View File

@ -23,9 +23,7 @@
</div>
{{/each}}
{{#if loading}}
{{loading-spinner}}
{{else}}
{{#loading-spinner condition=loading}}
{{#unless canLoadMore}}
{{#if showDismissButton}}
<div class='notification-buttons'>
@ -33,4 +31,4 @@
</div>
{{/if}}
{{/unless}}
{{/if}}
{{/loading-spinner}}

View File

@ -26,6 +26,3 @@
</p>
</div>
{{/each}}
{{#if loading}}
{{loading-spinner}}
{{/if}}

View File

@ -43,6 +43,7 @@
//= require ./discourse/components/top-title
//= require ./discourse/components/text-field
//= require ./discourse/components/visible
//= require ./discourse/components/conditional-loading-spinner
//= require ./discourse/helpers/user-avatar
//= require ./discourse/helpers/cold-age-class
//= require ./discourse/helpers/loading-spinner