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'; import ObjectController from 'discourse/controllers/object';
/**
This controller previews an email digest
@class AdminEmailPreviewDigestController
@extends ObjectController
@namespace Discourse
@module Discourse
**/
export default ObjectController.extend({ export default ObjectController.extend({
actions: { actions: {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@
@module Discourse @module Discourse
**/ **/
export default Ember.Component.extend({ export default Ember.Component.extend({
loading: Ember.computed.not('loaded'),
loaded: function() { loaded: function() {
var topicList = this.get('topicList'); 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'), }.property('selectedPostsCount'),
hasError: Ember.computed.or('notFoundHtml', 'message'), hasError: Ember.computed.or('notFoundHtml', 'message'),
noErrorYet: Ember.computed.not('hasError'),
multiSelectChanged: function() { multiSelectChanged: function() {
// Deselect all posts when multi select is turned off // Deselect all posts when multi select is turned off

View File

@ -3,7 +3,8 @@
var classify = Ember.String.classify; var classify = Ember.String.classify;
var get = Ember.get; 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, _dummyRoute,
_loadingView; _loadingView;

View File

@ -1,7 +1,25 @@
import ConditionalLoadingSpinner from 'discourse/components/conditional-loading-spinner';
var spinnerHTML = "<div class='spinner'></div>"; 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 }; export { spinnerHTML };

View File

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

View File

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

View File

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

View File

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

View File

@ -71,9 +71,7 @@
</div> </div>
<footer class='topic-list-bottom'> <footer class='topic-list-bottom'>
{{#if loadingMore}} {{loading-spinner condition=loadingMore}}
{{loading-spinner}}
{{/if}}
{{#if allLoaded}} {{#if allLoaded}}
{{#if showDismissRead}} {{#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> <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}} {{#if topics}}
<table class="topic-list"> <table class="topic-list">
<tbody> <tbody>
@ -53,6 +53,4 @@
{{i18n choose_topic.none_found}} {{i18n choose_topic.none_found}}
</div> </div>
{{/if}} {{/if}}
{{else}} {{/loading-spinner}}
{{loading-spinner}}
{{/if}}

View File

@ -24,9 +24,7 @@
</div> </div>
<footer class='topic-list-bottom'> <footer class='topic-list-bottom'>
{{#if loadingMore}} {{loading-spinner condition=loadingMore}}
{{loading-spinner}}
{{/if}}
{{#if allLoaded}} {{#if allLoaded}}
{{#if showDismissRead}} {{#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> <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"> <section class="d-dropdown" id="notifications-dropdown">
{{#unless loadingNotifications}} {{#loading-spinner condition=loadingNotifications}}
{{#if content}} {{#if content}}
<ul> <ul>
{{#each itemController="notification"}} {{#each itemController="notification"}}
@ -12,7 +12,5 @@
{{else}} {{else}}
<div class="none">{{i18n notifications.none}}</div> <div class="none">{{i18n notifications.none}}</div>
{{/if}} {{/if}}
{{else}} {{/loading-spinner}}
{{loading-spinner}}
{{/unless}}
</section> </section>

View File

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

View File

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

View File

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

View File

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

View File

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