mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 21:09:11 +08:00
REFACTOR: Convert admin flagged posts to a component
This commit is contained in:
parent
3d2ded5d14
commit
bbbd974487
@ -1,41 +0,0 @@
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
query: null,
|
||||
|
||||
adminOldFlagsView: Em.computed.equal("query", "old"),
|
||||
adminActiveFlagsView: Em.computed.equal("query", "active"),
|
||||
|
||||
actions: {
|
||||
disagreeFlags(flaggedPost) {
|
||||
flaggedPost.disagreeFlags().then(() => {
|
||||
this.get('model').removeObject(flaggedPost);
|
||||
}, function () {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
});
|
||||
},
|
||||
|
||||
deferFlags(flaggedPost) {
|
||||
flaggedPost.deferFlags().then(() => {
|
||||
this.get('model').removeObject(flaggedPost);
|
||||
}, function () {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
});
|
||||
},
|
||||
|
||||
doneTopicFlags(item) {
|
||||
this.send("disagreeFlags", item);
|
||||
},
|
||||
|
||||
loadMore() {
|
||||
const flags = this.get('model');
|
||||
return FlaggedPost.findAll(this.get('query'), flags.length+1).then(data => {
|
||||
if (data.length===0) {
|
||||
flags.set("allLoaded",true);
|
||||
}
|
||||
flags.addObjects(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
@ -1,24 +1,19 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
adminFlagsList: Ember.inject.controller(),
|
||||
removeAfter: null,
|
||||
|
||||
_agreeFlag: function (actionOnPost) {
|
||||
const adminFlagController = this.get("adminFlagsList");
|
||||
const post = this.get("content");
|
||||
|
||||
return post.agreeFlags(actionOnPost).then(() => {
|
||||
adminFlagController.get('model').removeObject(post);
|
||||
this.send("closeModal");
|
||||
}, function () {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
_agreeFlag(action) {
|
||||
let flaggedPost = this.get('model');
|
||||
return this.removeAfter(flaggedPost.agreeFlags(action), flaggedPost).then(() => {
|
||||
this.send('closeModal');
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
agreeFlagHidePost: function () { return this._agreeFlag("hide"); },
|
||||
agreeFlagKeepPost: function () { return this._agreeFlag("keep"); },
|
||||
agreeFlagRestorePost: function () { return this._agreeFlag("restore"); }
|
||||
agreeFlagHidePost() { return this._agreeFlag("hide"); },
|
||||
agreeFlagKeepPost() { return this._agreeFlag("keep"); },
|
||||
agreeFlagRestorePost() { return this._agreeFlag("restore"); }
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,30 +1,20 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
adminFlagsList: Ember.inject.controller(),
|
||||
removeAfter: null,
|
||||
|
||||
actions: {
|
||||
deletePostDeferFlag() {
|
||||
const adminFlagController = this.get("adminFlagsList");
|
||||
const post = this.get("content");
|
||||
|
||||
return post.deferFlags(true).then(() => {
|
||||
adminFlagController.get('model').removeObject(post);
|
||||
this.send("closeModal");
|
||||
}, function () {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
let flaggedPost = this.get('model');
|
||||
this.removeAfter(flaggedPost.deferFlags(true), flaggedPost).then(() => {
|
||||
this.send('closeModal');
|
||||
});
|
||||
},
|
||||
|
||||
deletePostAgreeFlag() {
|
||||
const adminFlagController = this.get("adminFlagsList");
|
||||
const post = this.get("content");
|
||||
|
||||
return post.agreeFlags("delete").then(() => {
|
||||
adminFlagController.get('model').removeObject(post);
|
||||
this.send("closeModal");
|
||||
}, function () {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
let flaggedPost = this.get('model');
|
||||
this.removeAfter(flaggedPost.agreeFlags('delete'), flaggedPost).then(() => {
|
||||
this.send('closeModal');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
export default Discourse.Route.extend({
|
||||
redirect() {
|
||||
this.replaceWith('adminFlags.list', 'active');
|
||||
this.replaceWith('adminFlags.postsActive');
|
||||
}
|
||||
});
|
||||
|
@ -1,27 +0,0 @@
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model(params) {
|
||||
this.filter = params.filter;
|
||||
return FlaggedPost.findAll(params.filter);
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set('model', model);
|
||||
controller.set('query', this.filter);
|
||||
},
|
||||
|
||||
actions: {
|
||||
showAgreeFlagModal(model) {
|
||||
showModal('admin-agree-flag', { model, admin: true });
|
||||
this.controllerFor('modal').set('modalClass', 'agree-flag-modal');
|
||||
},
|
||||
|
||||
showDeleteFlagModal(model) {
|
||||
showModal('admin-delete-flag', { model, admin: true });
|
||||
this.controllerFor('modal').set('modalClass', 'delete-flag-modal');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return FlaggedPost.findAll('active');
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return FlaggedPost.findAll('old');
|
||||
},
|
||||
});
|
@ -54,7 +54,8 @@ export default function() {
|
||||
this.route('adminReports', { path: '/reports/:type', resetNamespace: true });
|
||||
|
||||
this.route('adminFlags', { path: '/flags', resetNamespace: true }, function() {
|
||||
this.route('list', { path: '/:filter' });
|
||||
this.route('postsActive', { path: 'active' });
|
||||
this.route('postsOld', { path: 'old' });
|
||||
});
|
||||
|
||||
this.route('adminLogs', { path: '/logs', resetNamespace: true }, function() {
|
||||
|
@ -1,16 +1,16 @@
|
||||
{{#if model.length}}
|
||||
{{#load-more selector="tbody tr" action="loadMore"}}
|
||||
{{#if flaggedPosts}}
|
||||
{{#load-more selector=".flagged-post" action=(action "loadMore")}}
|
||||
<table class="admin-flags">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='excerpt'></th>
|
||||
<th class='flaggers'>{{i18n 'admin.flags.flagged_by'}}</th>
|
||||
<th class='flaggers'>{{#if adminOldFlagsView}}{{i18n 'admin.flags.resolved_by'}}{{/if}}</th>
|
||||
<th class='flaggers'>{{#if showResolvedBy}}{{i18n 'admin.flags.resolved_by'}}{{/if}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each content as |flaggedPost|}}
|
||||
<tr class={{flaggedPost.extraClasses}}>
|
||||
{{#each flaggedPosts as |flaggedPost|}}
|
||||
<tr class="flagged-post {{flaggedPost.extraClasses}}">
|
||||
|
||||
<td class='excerpt'>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{#if adminActiveFlagsView}}
|
||||
{{#if canAct}}
|
||||
{{#if flaggedPost.previous_flags_count}}
|
||||
<span title="{{i18n 'admin.flags.previous_flags_count' count=flaggedPost.previous_flags_count}}" class="badge-notification flagged-posts">{{flaggedPost.previous_flags_count}}</span>
|
||||
{{/if}}
|
||||
@ -68,7 +68,7 @@
|
||||
{{flagger.user.username}}
|
||||
{{/link-to}}
|
||||
{{format-age flagger.flaggedAt}}
|
||||
<br />
|
||||
<br>
|
||||
{{flagger.flagType}}
|
||||
</td>
|
||||
</tr>
|
||||
@ -78,7 +78,7 @@
|
||||
</td>
|
||||
|
||||
<td class='flaggers result'>
|
||||
{{#if adminOldFlagsView}}
|
||||
{{#if showResolvedBy}}
|
||||
<table>
|
||||
<tbody>
|
||||
{{#each flaggedPost.flaggers as |flagger|}}
|
||||
@ -140,22 +140,20 @@
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
||||
{{#unless adminOldFlagsView}}
|
||||
{{#if canAct}}
|
||||
<tr>
|
||||
<td colspan="3" class="action">
|
||||
{{#if adminActiveFlagsView}}
|
||||
<button title='{{i18n 'admin.flags.agree_title'}}' class='btn' {{action "showAgreeFlagModal" flaggedPost}}>{{d-icon "thumbs-o-up"}}{{i18n 'admin.flags.agree'}}…</button>
|
||||
{{#if flaggedPost.postHidden}}
|
||||
<button title='{{i18n 'admin.flags.disagree_flag_unhide_post_title'}}' class='btn' {{action "disagreeFlags" flaggedPost}}>{{d-icon "thumbs-o-down"}}{{i18n 'admin.flags.disagree_flag_unhide_post'}}</button>
|
||||
{{else}}
|
||||
<button title='{{i18n 'admin.flags.disagree_flag_title'}}' class='btn' {{action "disagreeFlags" flaggedPost}}>{{d-icon "thumbs-o-down"}}{{i18n 'admin.flags.disagree_flag'}}</button>
|
||||
{{/if}}
|
||||
<button title='{{i18n 'admin.flags.defer_flag_title'}}' class='btn' {{action "deferFlags" flaggedPost}}>{{d-icon "external-link"}}{{i18n 'admin.flags.defer_flag'}}</button>
|
||||
<button title='{{i18n 'admin.flags.delete_title'}}' class='btn btn-danger' {{action "showDeleteFlagModal" flaggedPost}}>{{d-icon "trash-o"}}{{i18n 'admin.flags.delete'}}…</button>
|
||||
{{#if flaggedPost.postHidden}}
|
||||
<button title='{{i18n 'admin.flags.disagree_flag_unhide_post_title'}}' class='btn' {{action "disagree" flaggedPost}}>{{d-icon "thumbs-o-down"}}{{i18n 'admin.flags.disagree_flag_unhide_post'}}</button>
|
||||
{{else}}
|
||||
<button title='{{i18n 'admin.flags.disagree_flag_title'}}' class='btn' {{action "disagree" flaggedPost}}>{{d-icon "thumbs-o-down"}}{{i18n 'admin.flags.disagree_flag'}}</button>
|
||||
{{/if}}
|
||||
<button title='{{i18n 'admin.flags.defer_flag_title'}}' class='btn' {{action "defer" flaggedPost}}>{{d-icon "external-link"}}{{i18n 'admin.flags.defer_flag'}}</button>
|
||||
<button title='{{i18n 'admin.flags.delete_title'}}' class='btn btn-danger' {{action "showDeleteFlagModal" flaggedPost}}>{{d-icon "trash-o"}}{{i18n 'admin.flags.delete'}}…</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
|
||||
{{/each}}
|
||||
|
@ -0,0 +1 @@
|
||||
{{flagged-posts flaggedPosts=model filter="active"}}
|
@ -0,0 +1 @@
|
||||
{{flagged-posts flaggedPosts=model filter="old"}}
|
@ -1,6 +1,6 @@
|
||||
{{#admin-nav}}
|
||||
{{nav-item route='adminFlags.list' routeParam='active' label='admin.flags.active'}}
|
||||
{{nav-item route='adminFlags.list' routeParam='old' label='admin.flags.old'}}
|
||||
{{nav-item route='adminFlags.postsActive' label='admin.flags.active'}}
|
||||
{{nav-item route='adminFlags.postsOld' label='admin.flags.old'}}
|
||||
{{/admin-nav}}
|
||||
|
||||
<div class="admin-container">
|
||||
|
@ -0,0 +1,52 @@
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
canAct: Ember.computed.equal('filter', 'active'),
|
||||
showResolvedBy: Ember.computed.equal('filter', 'old'),
|
||||
|
||||
removeAfter(promise, flaggedPost) {
|
||||
return promise.then(() => {
|
||||
this.get('flaggedPosts').removeObject(flaggedPost);
|
||||
}).catch(() => {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
});
|
||||
},
|
||||
|
||||
_spawnModal(name, flaggedPost, modalClass) {
|
||||
let controller = showModal(name, {
|
||||
model: flaggedPost,
|
||||
admin: true,
|
||||
modalClass
|
||||
});
|
||||
controller.removeAfter = (p, f) => this.removeAfter(p, f);
|
||||
},
|
||||
|
||||
actions: {
|
||||
disagree(flaggedPost) {
|
||||
this.removeAfter(flaggedPost.disagreeFlags(), flaggedPost);
|
||||
},
|
||||
|
||||
defer(flaggedPost) {
|
||||
this.removeAfter(flaggedPost.deferFlags(), flaggedPost);
|
||||
},
|
||||
|
||||
loadMore() {
|
||||
const flaggedPosts = this.get('flaggedPosts');
|
||||
return FlaggedPost.findAll(this.get('query'), flaggedPosts.length+1).then(data => {
|
||||
if (data.length===0) {
|
||||
flaggedPosts.set("allLoaded",true);
|
||||
}
|
||||
flaggedPosts.addObjects(data);
|
||||
});
|
||||
},
|
||||
|
||||
showAgreeFlagModal(flaggedPost) {
|
||||
this._spawnModal('admin-agree-flag', flaggedPost, 'agree-flag-modal');
|
||||
},
|
||||
|
||||
showDeleteFlagModal(flaggedPost) {
|
||||
this._spawnModal('admin-delete-flag', flaggedPost, 'delete-flag-modal');
|
||||
}
|
||||
}
|
||||
});
|
@ -7,7 +7,7 @@ export default function(name, opts) {
|
||||
const route = container.lookup('route:application');
|
||||
const modalController = route.controllerFor('modal');
|
||||
|
||||
modalController.set('modalClass', null);
|
||||
modalController.set('modalClass', opts.modalClass);
|
||||
|
||||
const controllerName = opts.admin ? `modals/${name}` : name;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user