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({
loadMore() { loading: false,
return IncomingEmail.findAll(this.get("filter"), this.get("model.length"))
.then(incoming => { actions: {
if (incoming.length < 50) { this.get("model").set("allLoaded", true); }
this.get("model").addObjects(incoming); loadMore() {
}); if (this.get("loading") || this.get("model.allLoaded")) { return; }
this.set('loading', true);
IncomingEmail.findAll(this.get("filter"), this.get("model.length"))
.then(incoming => {
if (incoming.length < 50) { this.get("model").set("allLoaded", true); }
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({
loadMore() { loading: false,
return EmailLog.findAll(this.get("filter"), this.get("model.length"))
.then(logs => { actions: {
if (logs.length < 50) { this.get("model").set("allLoaded", true); } loadMore() {
this.get("model").addObjects(logs); if (this.get("loading") || this.get("model.allLoaded")) { return; }
});
this.set('loading', true);
return EmailLog.findAll(this.get("filter"), this.get("model.length"))
.then(logs => {
if (logs.length < 50) { this.get("model").set("allLoaded", true); }
this.get("model").addObjects(logs);
}).finally(() => {
this.set('loading', false);
});
}
} }
}); });

View File

@ -1,55 +1,57 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<thead> <table class='table email-list'>
<tr> <thead>
<th>{{i18n 'admin.email.time'}}</th> <tr>
<th>{{i18n 'admin.email.incoming_emails.from_address'}}</th> <th>{{i18n 'admin.email.time'}}</th>
<th>{{i18n 'admin.email.incoming_emails.to_addresses'}}</th> <th>{{i18n 'admin.email.incoming_emails.from_address'}}</th>
<th>{{i18n 'admin.email.incoming_emails.subject'}}</th> <th>{{i18n 'admin.email.incoming_emails.to_addresses'}}</th>
<th>{{i18n 'admin.email.incoming_emails.subject'}}</th>
</tr>
</thead>
<tr class="filters">
<td>{{i18n 'admin.email.logs.filters.title'}}</td>
<td>{{text-field value=filter.from placeholderKey="admin.email.incoming_emails.filters.from_placeholder"}}</td>
<td>{{text-field value=filter.to placeholderKey="admin.email.incoming_emails.filters.to_placeholder"}}</td>
<td>{{text-field value=filter.subject placeholderKey="admin.email.incoming_emails.filters.subject_placeholder"}}</td>
</tr> </tr>
</thead>
<tr class="filters"> {{#each email in model}}
<td>{{i18n 'admin.email.logs.filters.title'}}</td> <tr>
<td>{{text-field value=filter.from placeholderKey="admin.email.incoming_emails.filters.from_placeholder"}}</td> <td class="time">{{format-date email.created_at}}</td>
<td>{{text-field value=filter.to placeholderKey="admin.email.incoming_emails.filters.to_placeholder"}}</td> <td class="username">
<td>{{text-field value=filter.subject placeholderKey="admin.email.incoming_emails.filters.subject_placeholder"}}</td> <div>
</tr> {{#if email.user}}
{{#link-to 'adminUser' email.user}}
{{#each email in model}} {{avatar email.user imageSize="tiny"}}
<tr> {{email.from_address}}
<td class="time">{{format-date email.created_at}}</td> {{/link-to}}
<td class="username"> {{else}}
<div> &mdash;
{{#if email.user}} {{/if}}
{{#link-to 'adminUser' email.user}} </div>
{{avatar email.user imageSize="tiny"}} </td>
{{email.from_address}} <td class="addresses">
{{/link-to}} {{#each to in email.to_addresses}}
<p><a href="mailto:{{unbound to}}" title="TO">{{unbound to}}</a></p>
{{/each}}
{{#each cc in email.cc_addresses}}
<p><a href="mailto:{{unbound cc}}" title="CC">{{unbound cc}}</a></p>
{{/each}}
</td>
<td>
{{#if email.post_url}}
<a href="{{email.post_url}}">{{email.subject}}</a>
{{else}} {{else}}
&mdash; {{email.subject}}
{{/if}} {{/if}}
</div> </td>
</td> </tr>
<td class="addresses"> {{else}}
{{#each to in email.to_addresses}} <tr><td colspan="4">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
<p><a href="mailto:{{unbound to}}" title="TO">{{unbound to}}</a></p> {{/each}}
{{/each}}
{{#each cc in email.cc_addresses}}
<p><a href="mailto:{{unbound cc}}" title="CC">{{unbound cc}}</a></p>
{{/each}}
</td>
<td>
{{#if email.post_url}}
<a href="{{email.post_url}}">{{email.subject}}</a>
{{else}}
{{email.subject}}
{{/if}}
</td>
</tr>
{{else}}
<tr><td colspan="4">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
{{/each}}
</table> </table>
{{/load-more}}
{{conditional-loading-spinner condition=view.loading}} {{conditional-loading-spinner condition=loading}}

View File

@ -1,54 +1,56 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<thead> <table class='table email-list'>
<tr> <thead>
<th>{{i18n 'admin.email.time'}}</th> <tr>
<th>{{i18n 'admin.email.incoming_emails.from_address'}}</th> <th>{{i18n 'admin.email.time'}}</th>
<th>{{i18n 'admin.email.incoming_emails.to_addresses'}}</th> <th>{{i18n 'admin.email.incoming_emails.from_address'}}</th>
<th>{{i18n 'admin.email.incoming_emails.subject'}}</th> <th>{{i18n 'admin.email.incoming_emails.to_addresses'}}</th>
<th>{{i18n 'admin.email.incoming_emails.error'}}</th> <th>{{i18n 'admin.email.incoming_emails.subject'}}</th>
<th>{{i18n 'admin.email.incoming_emails.error'}}</th>
</tr>
</thead>
<tr class="filters">
<td>{{i18n 'admin.email.logs.filters.title'}}</td>
<td>{{text-field value=filter.from placeholderKey="admin.email.incoming_emails.filters.from_placeholder"}}</td>
<td>{{text-field value=filter.to placeholderKey="admin.email.incoming_emails.filters.to_placeholder"}}</td>
<td>{{text-field value=filter.subject placeholderKey="admin.email.incoming_emails.filters.subject_placeholder"}}</td>
<td>{{text-field value=filter.error placeholderKey="admin.email.incoming_emails.filters.error_placeholder"}}</td>
</tr> </tr>
</thead>
<tr class="filters"> {{#each email in model}}
<td>{{i18n 'admin.email.logs.filters.title'}}</td> <tr>
<td>{{text-field value=filter.from placeholderKey="admin.email.incoming_emails.filters.from_placeholder"}}</td> <td class="time">{{format-date email.created_at}}</td>
<td>{{text-field value=filter.to placeholderKey="admin.email.incoming_emails.filters.to_placeholder"}}</td> <td class="username">
<td>{{text-field value=filter.subject placeholderKey="admin.email.incoming_emails.filters.subject_placeholder"}}</td> <div>
<td>{{text-field value=filter.error placeholderKey="admin.email.incoming_emails.filters.error_placeholder"}}</td> {{#if email.user}}
</tr> {{#link-to 'adminUser' email.user}}
{{avatar email.user imageSize="tiny"}}
{{email.from_address}}
{{/link-to}}
{{else}}
&mdash;
{{/if}}
</div>
</td>
<td class="addresses">
{{#each to in email.to_addresses}}
<p><a href="mailto:{{unbound to}}" title="TO">{{unbound to}}</a></p>
{{/each}}
{{#each cc in email.cc_addresses}}
<p><a href="mailto:{{unbound cc}}" title="CC">{{unbound cc}}</a></p>
{{/each}}
</td>
<td>{{email.subject}}</td>
<td class="error">
<a {{action "showIncomingEmail" email.id}}>{{email.error}}</a>
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
{{/each}}
{{#each email in model}} </table>
<tr> {{/load-more}}
<td class="time">{{format-date email.created_at}}</td>
<td class="username">
<div>
{{#if email.user}}
{{#link-to 'adminUser' email.user}}
{{avatar email.user imageSize="tiny"}}
{{email.from_address}}
{{/link-to}}
{{else}}
&mdash;
{{/if}}
</div>
</td>
<td class="addresses">
{{#each to in email.to_addresses}}
<p><a href="mailto:{{unbound to}}" title="TO">{{unbound to}}</a></p>
{{/each}}
{{#each cc in email.cc_addresses}}
<p><a href="mailto:{{unbound cc}}" title="CC">{{unbound cc}}</a></p>
{{/each}}
</td>
<td>{{email.subject}}</td>
<td class="error">
<a {{action "showIncomingEmail" email.id}}>{{email.error}}</a>
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>
{{/each}}
</table> {{conditional-loading-spinner condition=loading}}
{{conditional-loading-spinner condition=view.loading}}

View File

@ -1,47 +1,49 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<thead> <table class='table email-list'>
<tr> <thead>
<th>{{i18n 'admin.email.sent_at'}}</th> <tr>
<th>{{i18n 'admin.email.user'}}</th> <th>{{i18n 'admin.email.sent_at'}}</th>
<th>{{i18n 'admin.email.to_address'}}</th> <th>{{i18n 'admin.email.user'}}</th>
<th>{{i18n 'admin.email.email_type'}}</th> <th>{{i18n 'admin.email.to_address'}}</th>
<th>{{i18n 'admin.email.reply_key'}}</th> <th>{{i18n 'admin.email.email_type'}}</th>
<th>{{i18n 'admin.email.reply_key'}}</th>
</tr>
</thead>
<tr class="filters">
<td>{{i18n 'admin.email.logs.filters.title'}}</td>
<td>{{text-field value=filter.user placeholderKey="admin.email.logs.filters.user_placeholder"}}</td>
<td>{{text-field value=filter.address placeholderKey="admin.email.logs.filters.address_placeholder"}}</td>
<td>{{text-field value=filter.type placeholderKey="admin.email.logs.filters.type_placeholder"}}</td>
<td>{{text-field value=filter.reply_key placeholderKey="admin.email.logs.filters.reply_key_placeholder"}}</td>
</tr> </tr>
</thead>
<tr class="filters"> {{#each l in model}}
<td>{{i18n 'admin.email.logs.filters.title'}}</td> <tr>
<td>{{text-field value=filter.user placeholderKey="admin.email.logs.filters.user_placeholder"}}</td> <td>{{format-date l.created_at}}</td>
<td>{{text-field value=filter.address placeholderKey="admin.email.logs.filters.address_placeholder"}}</td> <td>
<td>{{text-field value=filter.type placeholderKey="admin.email.logs.filters.type_placeholder"}}</td> {{#if l.user}}
<td>{{text-field value=filter.reply_key placeholderKey="admin.email.logs.filters.reply_key_placeholder"}}</td> {{#link-to 'adminUser' l.user}}{{avatar l.user imageSize="tiny"}}{{/link-to}}
</tr> {{#link-to 'adminUser' l.user}}{{l.user.username}}{{/link-to}}
{{else}}
&mdash;
{{/if}}
</td>
<td><a href='mailto:{{unbound l.to_address}}'>{{l.to_address}}</a></td>
<td>{{l.email_type}}</td>
<td>
{{#if l.post_url}}
<a href="{{l.post_url}}">{{l.reply_key}}</a>
{{else}}
{{l.reply_key}}
{{/if}}
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}}
{{#each l in model}} </table>
<tr> {{/load-more}}
<td>{{format-date l.created_at}}</td>
<td>
{{#if l.user}}
{{#link-to 'adminUser' l.user}}{{avatar l.user imageSize="tiny"}}{{/link-to}}
{{#link-to 'adminUser' l.user}}{{l.user.username}}{{/link-to}}
{{else}}
&mdash;
{{/if}}
</td>
<td><a href='mailto:{{unbound l.to_address}}'>{{l.to_address}}</a></td>
<td>{{l.email_type}}</td>
<td>
{{#if l.post_url}}
<a href="{{l.post_url}}">{{l.reply_key}}</a>
{{else}}
{{l.reply_key}}
{{/if}}
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}}
</table> {{conditional-loading-spinner condition=loading}}
{{conditional-loading-spinner condition=view.loading}}

View File

@ -1,47 +1,49 @@
<table class='table email-list'> {{#load-more selector=".email-list tr" action="loadMore"}}
<thead> <table class='table email-list'>
<tr> <thead>
<th>{{i18n 'admin.email.time'}}</th> <tr>
<th>{{i18n 'admin.email.user'}}</th> <th>{{i18n 'admin.email.time'}}</th>
<th>{{i18n 'admin.email.to_address'}}</th> <th>{{i18n 'admin.email.user'}}</th>
<th>{{i18n 'admin.email.email_type'}}</th> <th>{{i18n 'admin.email.to_address'}}</th>
<th>{{i18n 'admin.email.skipped_reason'}}</th> <th>{{i18n 'admin.email.email_type'}}</th>
<th>{{i18n 'admin.email.skipped_reason'}}</th>
</tr>
</thead>
<tr class="filters">
<td>{{i18n 'admin.email.logs.filters.title'}}</td>
<td>{{text-field value=filter.user placeholderKey="admin.email.logs.filters.user_placeholder"}}</td>
<td>{{text-field value=filter.address placeholderKey="admin.email.logs.filters.address_placeholder"}}</td>
<td>{{text-field value=filter.type placeholderKey="admin.email.logs.filters.type_placeholder"}}</td>
<td>{{text-field value=filter.skipped_reason placeholderKey="admin.email.logs.filters.skipped_reason_placeholder"}}</td>
</tr> </tr>
</thead>
<tr class="filters"> {{#each l in model}}
<td>{{i18n 'admin.email.logs.filters.title'}}</td> <tr>
<td>{{text-field value=filter.user placeholderKey="admin.email.logs.filters.user_placeholder"}}</td> <td>{{format-date l.created_at}}</td>
<td>{{text-field value=filter.address placeholderKey="admin.email.logs.filters.address_placeholder"}}</td> <td>
<td>{{text-field value=filter.type placeholderKey="admin.email.logs.filters.type_placeholder"}}</td> {{#if l.user}}
<td>{{text-field value=filter.skipped_reason placeholderKey="admin.email.logs.filters.skipped_reason_placeholder"}}</td> {{#link-to 'adminUser' l.user}}{{avatar l.user imageSize="tiny"}}{{/link-to}}
</tr> {{#link-to 'adminUser' l.user}}{{l.user.username}}{{/link-to}}
{{else}}
&mdash;
{{/if}}
</td>
<td><a href='mailto:{{unbound l.to_address}}'>{{l.to_address}}</a></td>
<td>{{l.email_type}}</td>
<td>
{{#if l.post_url}}
<a href="{{l.post_url}}">{{l.skipped_reason}}</a>
{{else}}
{{l.skipped_reason}}
{{/if}}
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}}
{{#each l in model}} </table>
<tr> {{/load-more}}
<td>{{format-date l.created_at}}</td>
<td>
{{#if l.user}}
{{#link-to 'adminUser' l.user}}{{avatar l.user imageSize="tiny"}}{{/link-to}}
{{#link-to 'adminUser' l.user}}{{l.user.username}}{{/link-to}}
{{else}}
&mdash;
{{/if}}
</td>
<td><a href='mailto:{{unbound l.to_address}}'>{{l.to_address}}</a></td>
<td>{{l.email_type}}</td>
<td>
{{#if l.post_url}}
<a href="{{l.post_url}}">{{l.skipped_reason}}</a>
{{else}}
{{l.skipped_reason}}
{{/if}}
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.logs.none'}}</td></tr>
{{/each}}
</table> {{conditional-loading-spinner condition=loading}}
{{conditional-loading-spinner condition=view.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,21 +14,25 @@
<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">
{{#each userBadges as |ub|}} {{#load-more selector=".badge-info" action="loadMore"}}
{{#user-info user=ub.user size="medium" class="badge-info" date=ub.granted_at}} {{#each userBadges as |ub|}}
<div class="granted-on">{{i18n 'badges.granted_on' date=(inline-date ub.granted_at)}}</div> {{#user-info user=ub.user size="medium" class="badge-info" date=ub.granted_at}}
{{#if ub.post_number}} <div class="granted-on">{{i18n 'badges.granted_on' date=(inline-date ub.granted_at)}}</div>
<a class="post-link" href="{{unbound ub.topic.url}}/{{unbound ub.post_number}}">{{{ub.topic.fancyTitle}}}</a> {{#if ub.post_number}}
{{/if}} <a class="post-link" href="{{unbound ub.topic.url}}/{{unbound ub.post_number}}">{{{ub.topic.fancyTitle}}}</a>
{{/user-info}} {{/if}}
{{/each}} {{/user-info}}
{{/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()
});