REFACTOR: Remove view from badges-show

This commit is contained in:
Robin Ward 2016-03-25 11:37:26 -04:00
parent d129c61a4a
commit d7b568f98e
17 changed files with 272 additions and 265 deletions

View File

@ -1,11 +1,21 @@
import IncomingEmail from 'admin/models/incoming-email'; import IncomingEmail from 'admin/models/incoming-email';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
loading: false,
actions: {
loadMore() { loadMore() {
return IncomingEmail.findAll(this.get("filter"), this.get("model.length")) if (this.get("loading") || this.get("model.allLoaded")) { return; }
this.set('loading', true);
IncomingEmail.findAll(this.get("filter"), this.get("model.length"))
.then(incoming => { .then(incoming => {
if (incoming.length < 50) { this.get("model").set("allLoaded", true); } if (incoming.length < 50) { this.get("model").set("allLoaded", true); }
this.get("model").addObjects(incoming); this.get("model").addObjects(incoming);
}).finally(() => {
this.set('loading', false);
}); });
} }
}
}); });

View File

@ -1,11 +1,20 @@
import EmailLog from 'admin/models/email-log'; import EmailLog from 'admin/models/email-log';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
loading: false,
actions: {
loadMore() { loadMore() {
if (this.get("loading") || this.get("model.allLoaded")) { return; }
this.set('loading', true);
return EmailLog.findAll(this.get("filter"), this.get("model.length")) return EmailLog.findAll(this.get("filter"), this.get("model.length"))
.then(logs => { .then(logs => {
if (logs.length < 50) { this.get("model").set("allLoaded", true); } if (logs.length < 50) { this.get("model").set("allLoaded", true); }
this.get("model").addObjects(logs); this.get("model").addObjects(logs);
}).finally(() => {
this.set('loading', false);
}); });
} }
}
}); });

View File

@ -1,4 +1,5 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<table class='table email-list'>
<thead> <thead>
<tr> <tr>
<th>{{i18n 'admin.email.time'}}</th> <th>{{i18n 'admin.email.time'}}</th>
@ -50,6 +51,7 @@
<tr><td colspan="4">{{i18n 'admin.email.incoming_emails.none'}}</td></tr> <tr><td colspan="4">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
{{/each}} {{/each}}
</table> </table>
{{/load-more}}
{{conditional-loading-spinner condition=view.loading}} {{conditional-loading-spinner condition=loading}}

View File

@ -1,4 +1,5 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<table class='table email-list'>
<thead> <thead>
<tr> <tr>
<th>{{i18n 'admin.email.time'}}</th> <th>{{i18n 'admin.email.time'}}</th>
@ -49,6 +50,7 @@
<tr><td colspan="5">{{i18n 'admin.email.incoming_emails.none'}}</td></tr> <tr><td colspan="5">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
{{/each}} {{/each}}
</table> </table>
{{/load-more}}
{{conditional-loading-spinner condition=view.loading}} {{conditional-loading-spinner condition=loading}}

View File

@ -1,4 +1,5 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<table class='table email-list'>
<thead> <thead>
<tr> <tr>
<th>{{i18n 'admin.email.sent_at'}}</th> <th>{{i18n 'admin.email.sent_at'}}</th>
@ -42,6 +43,7 @@
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr> <tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}} {{/each}}
</table> </table>
{{/load-more}}
{{conditional-loading-spinner condition=view.loading}} {{conditional-loading-spinner condition=loading}}

View File

@ -1,4 +1,5 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<table class='table email-list'>
<thead> <thead>
<tr> <tr>
<th>{{i18n 'admin.email.time'}}</th> <th>{{i18n 'admin.email.time'}}</th>
@ -42,6 +43,7 @@
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr> <tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}} {{/each}}
</table> </table>
{{/load-more}}
{{conditional-loading-spinner condition=view.loading}} {{conditional-loading-spinner condition=loading}}

View File

@ -1,14 +0,0 @@
import LoadMore from "discourse/mixins/load-more";
export default Ember.View.extend(LoadMore, {
loading: false,
eyelineSelector: ".email-list tr",
actions: {
loadMore() {
if (this.get("loading") || this.get("model.allLoaded")) { return; }
this.set("loading", true);
return this.get("controller").loadMore().then(() => this.set("loading", false));
}
}
});

View File

@ -1,14 +0,0 @@
import LoadMore from "discourse/mixins/load-more";
export default Ember.View.extend(LoadMore, {
loading: false,
eyelineSelector: ".email-list tr",
actions: {
loadMore() {
if (this.get("loading") || this.get("model.allLoaded")) { return; }
this.set("loading", true);
return this.get("controller").loadMore().then(() => this.set("loading", false));
}
}
});

View File

@ -1,5 +0,0 @@
import AdminEmailIncomingsView from "admin/views/admin-email-incomings";
export default AdminEmailIncomingsView.extend({
templateName: "admin/templates/email-received"
});

View File

@ -1,5 +0,0 @@
import AdminEmailIncomingsView from "admin/views/admin-email-incomings";
export default AdminEmailIncomingsView.extend({
templateName: "admin/templates/email-rejected"
});

View File

@ -1,5 +0,0 @@
import AdminEmailLogsView from "admin/views/admin-email-logs";
export default AdminEmailLogsView.extend({
templateName: "admin/templates/email-sent"
});

View File

@ -1,5 +0,0 @@
import AdminEmailLogsView from "admin/views/admin-email-logs";
export default AdminEmailLogsView.extend({
templateName: "admin/templates/email-skipped"
});

View File

@ -0,0 +1,11 @@
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
tagName: 'i',
classNameBindings: [':fa', 'iconClass'],
@computed('checked')
iconClass(checked) {
return checked ? 'fa-check' : 'fa-times';
}
});

View File

@ -0,0 +1,16 @@
import LoadMore from "discourse/mixins/load-more";
export default Ember.Component.extend(LoadMore, {
_viaComponent: true,
init() {
this._super();
this.set('eyelineSelector', this.get('selector'));
},
actions: {
loadMore() {
this.sendAction();
}
}
});

View File

@ -5,6 +5,14 @@ import { on } from 'ember-addons/ember-computed-decorators';
// Provides the ability to load more items for a view which is scrolled to the bottom. // Provides the ability to load more items for a view which is scrolled to the bottom.
export default Ember.Mixin.create(Ember.ViewTargetActionSupport, Scrolling, { export default Ember.Mixin.create(Ember.ViewTargetActionSupport, Scrolling, {
init() {
this._super();
if (!this._viaComponent) {
console.warn('Using `LoadMore` as a view mixin is deprecated. Use `{{load-more}}` instead');
}
},
scrolled() { scrolled() {
const eyeline = this.get('eyeline'); const eyeline = this.get('eyeline');
return eyeline && eyeline.update(); return eyeline && eyeline.update();

View File

@ -14,13 +14,16 @@
<div class='badges-listing'> <div class='badges-listing'>
<div class='row'> <div class='row'>
<div class='grant-count'>{{i18n 'badges.granted' count=grantCount}}</div> <div class='grant-count'>{{i18n 'badges.granted' count=grantCount}}</div>
<div class='info'>{{i18n 'badges.allow_title'}} {{{view.allowTitle}}}<br>{{i18n 'badges.multiple_grant'}} {{{view.multipleGrant}}} <div class='info'>
{{i18n 'badges.allow_title'}} {{check-mark checked=model.allow_title}}<br>
{{i18n 'badges.multiple_grant'}} {{check-mark checked=model.multiple_grant}}
</div> </div>
</div> </div>
</div> </div>
{{#if userBadges}} {{#if userBadges}}
<div class="user-badges"> <div class="user-badges">
{{#load-more selector=".badge-info" action="loadMore"}}
{{#each userBadges as |ub|}} {{#each userBadges as |ub|}}
{{#user-info user=ub.user size="medium" class="badge-info" date=ub.granted_at}} {{#user-info user=ub.user size="medium" class="badge-info" date=ub.granted_at}}
<div class="granted-on">{{i18n 'badges.granted_on' date=(inline-date ub.granted_at)}}</div> <div class="granted-on">{{i18n 'badges.granted_on' date=(inline-date ub.granted_at)}}</div>
@ -29,6 +32,7 @@
{{/if}} {{/if}}
{{/user-info}} {{/user-info}}
{{/each}} {{/each}}
{{/load-more}}
{{#unless canLoadMore}} {{#unless canLoadMore}}
{{#if user}} {{#if user}}

View File

@ -1,11 +0,0 @@
import LoadMore from "discourse/mixins/load-more";
export default Ember.View.extend(LoadMore, {
eyelineSelector: '.badge-info',
tickOrX: function(field){
var icon = this.get('controller.model.' + field) ? "fa-check" : "fa-times";
return "<i class='fa " + icon + "'></i>";
},
allowTitle: function() { return this.tickOrX("allow_title"); }.property(),
multipleGrant: function() { return this.tickOrX("multiple_grant"); }.property()
});