From 873277ae5f152d6a19c220d23f825ca1bf3b5e35 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 11 Nov 2014 15:48:13 -0500 Subject: [PATCH] Add loading route support to admin flags --- .../admin/controllers/admin-agree-flag.js.es6 | 4 +- .../controllers/admin-delete-flag.js.es6 | 7 +- ...n-flags.js.es6 => admin-flags-list.js.es6} | 10 +- .../admin/routes/admin-flags-index.js.es6 | 5 + .../admin/routes/admin-flags-list.js.es6 | 24 +++ .../admin/routes/admin_flags_route.js | 41 ----- .../javascripts/admin/routes/admin_routes.js | 3 +- .../admin/templates/flags-list.hbs | 155 +++++++++++++++++ .../javascripts/admin/templates/flags.hbs | 164 +----------------- ..._flags_view.js => admin-flags-list.js.es6} | 5 +- .../views/modals/admin_agree_flag_view.js | 8 - 11 files changed, 195 insertions(+), 231 deletions(-) rename app/assets/javascripts/admin/controllers/{admin-flags.js.es6 => admin-flags-list.js.es6} (84%) create mode 100644 app/assets/javascripts/admin/routes/admin-flags-index.js.es6 create mode 100644 app/assets/javascripts/admin/routes/admin-flags-list.js.es6 delete mode 100644 app/assets/javascripts/admin/routes/admin_flags_route.js create mode 100644 app/assets/javascripts/admin/templates/flags-list.hbs rename app/assets/javascripts/admin/views/{admin_flags_view.js => admin-flags-list.js.es6} (82%) diff --git a/app/assets/javascripts/admin/controllers/admin-agree-flag.js.es6 b/app/assets/javascripts/admin/controllers/admin-agree-flag.js.es6 index ac7fb9c63b0..635b8c87fe7 100644 --- a/app/assets/javascripts/admin/controllers/admin-agree-flag.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-agree-flag.js.es6 @@ -2,10 +2,10 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ObjectController from 'discourse/controllers/object'; export default ObjectController.extend(ModalFunctionality, { - needs: ["adminFlags"], + needs: ["admin-flags-list"], _agreeFlag: function (actionOnPost) { - var adminFlagController = this.get("controllers.adminFlags"); + var adminFlagController = this.get("controllers.admin-flags-list"); var post = this.get("content"); var self = this; diff --git a/app/assets/javascripts/admin/controllers/admin-delete-flag.js.es6 b/app/assets/javascripts/admin/controllers/admin-delete-flag.js.es6 index d0aa6733930..de26828eca3 100644 --- a/app/assets/javascripts/admin/controllers/admin-delete-flag.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-delete-flag.js.es6 @@ -3,13 +3,12 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ObjectController from 'discourse/controllers/object'; export default ObjectController.extend(ModalFunctionality, { - - needs: ["adminFlags"], + needs: ["admin-flags-list"], actions: { deletePostDeferFlag: function () { - var adminFlagController = this.get("controllers.adminFlags"); + var adminFlagController = this.get("controllers.admin-flags-list"); var post = this.get("content"); var self = this; @@ -22,7 +21,7 @@ export default ObjectController.extend(ModalFunctionality, { }, deletePostAgreeFlag: function () { - var adminFlagController = this.get("controllers.adminFlags"); + var adminFlagController = this.get("controllers.admin-flags-list"); var post = this.get("content"); var self = this; diff --git a/app/assets/javascripts/admin/controllers/admin-flags.js.es6 b/app/assets/javascripts/admin/controllers/admin-flags-list.js.es6 similarity index 84% rename from app/assets/javascripts/admin/controllers/admin-flags.js.es6 rename to app/assets/javascripts/admin/controllers/admin-flags-list.js.es6 index de3a74fe795..da81f2e38df 100644 --- a/app/assets/javascripts/admin/controllers/admin-flags.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-flags-list.js.es6 @@ -1,18 +1,10 @@ -/** - This controller supports the interface for dealing with flags in the admin section. - - @class AdminFlagsController - @extends Ember.Controller - @namespace Discourse - @module Discourse -**/ export default Ember.ArrayController.extend({ + query: null, adminOldFlagsView: Em.computed.equal("query", "old"), adminActiveFlagsView: Em.computed.equal("query", "active"), actions: { - disagreeFlags: function (flaggedPost) { var self = this; flaggedPost.disagreeFlags().then(function () { diff --git a/app/assets/javascripts/admin/routes/admin-flags-index.js.es6 b/app/assets/javascripts/admin/routes/admin-flags-index.js.es6 new file mode 100644 index 00000000000..d20793add2f --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-flags-index.js.es6 @@ -0,0 +1,5 @@ +export default Discourse.Route.extend({ + redirect: function() { + this.replaceWith('adminFlags.list', 'active'); + } +}); diff --git a/app/assets/javascripts/admin/routes/admin-flags-list.js.es6 b/app/assets/javascripts/admin/routes/admin-flags-list.js.es6 new file mode 100644 index 00000000000..973c59ae3d3 --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-flags-list.js.es6 @@ -0,0 +1,24 @@ +export default Discourse.Route.extend({ + model: function(params) { + this.filter = params.filter; + return Discourse.FlaggedPost.findAll(params.filter); + }, + + setupController: function(controller, model) { + controller.set('model', model); + controller.set('query', this.filter); + }, + + actions: { + showAgreeFlagModal: function (flaggedPost) { + Discourse.Route.showModal(this, 'admin_agree_flag', flaggedPost); + this.controllerFor('modal').set('modalClass', 'agree-flag-modal'); + }, + + showDeleteFlagModal: function (flaggedPost) { + Discourse.Route.showModal(this, 'admin_delete_flag', flaggedPost); + this.controllerFor('modal').set('modalClass', 'delete-flag-modal'); + } + + } +}); diff --git a/app/assets/javascripts/admin/routes/admin_flags_route.js b/app/assets/javascripts/admin/routes/admin_flags_route.js deleted file mode 100644 index a8c7cc1ecf6..00000000000 --- a/app/assets/javascripts/admin/routes/admin_flags_route.js +++ /dev/null @@ -1,41 +0,0 @@ -Discourse.AdminFlagsIndexRoute = Discourse.Route.extend({ - redirect: function() { - this.transitionTo('adminFlags.active'); - } -}); - -Discourse.AdminFlagsRouteType = Discourse.Route.extend({ - model: function() { - return Discourse.FlaggedPost.findAll(this.get('filter')); - }, - - setupController: function(controller, model) { - var adminFlagsController = this.controllerFor('adminFlags'); - adminFlagsController.set('content', model); - adminFlagsController.set('query', this.get('filter')); - }, - -}); - -Discourse.AdminFlagsActiveRoute = Discourse.AdminFlagsRouteType.extend({ - filter: 'active', - - actions: { - - showAgreeFlagModal: function (flaggedPost) { - Discourse.Route.showModal(this, 'admin_agree_flag', flaggedPost); - this.controllerFor('modal').set('modalClass', 'agree-flag-modal'); - }, - - showDeleteFlagModal: function (flaggedPost) { - Discourse.Route.showModal(this, 'admin_delete_flag', flaggedPost); - this.controllerFor('modal').set('modalClass', 'delete-flag-modal'); - } - - } -}); - - -Discourse.AdminFlagsOldRoute = Discourse.AdminFlagsRouteType.extend({ - filter: 'old' -}); diff --git a/app/assets/javascripts/admin/routes/admin_routes.js b/app/assets/javascripts/admin/routes/admin_routes.js index 7ab29af5a6a..6640df91982 100644 --- a/app/assets/javascripts/admin/routes/admin_routes.js +++ b/app/assets/javascripts/admin/routes/admin_routes.js @@ -30,8 +30,7 @@ Discourse.Route.buildRoutes(function() { this.resource('adminReports', { path: '/reports/:type' }); this.resource('adminFlags', { path: '/flags' }, function() { - this.route('active'); - this.route('old'); + this.route('list', { path: '/:filter' }); }); this.resource('adminLogs', { path: '/logs' }, function() { diff --git a/app/assets/javascripts/admin/templates/flags-list.hbs b/app/assets/javascripts/admin/templates/flags-list.hbs new file mode 100644 index 00000000000..76eec581f6b --- /dev/null +++ b/app/assets/javascripts/admin/templates/flags-list.hbs @@ -0,0 +1,155 @@ +{{#if length}} + + + + + + + + + + + {{#each flaggedPost in content}} + + + + + + + + + + + + + {{#if flaggedPost.topicFlagged}} + + + + + {{/if}} + + {{#each flaggedPost.conversations}} + + + + + {{/each}} + + + + + + {{/each}} + + +
{{i18n admin.flags.flagged_by}}{{#if adminOldFlagsView}}{{i18n admin.flags.resolved_by}}{{/if}}
+ {{#if flaggedPost.postAuthorFlagged}} + {{#if flaggedPost.user}} + {{#link-to 'adminUser' flaggedPost.user}}{{avatar flaggedPost.user imageSize="small"}}{{/link-to}} + {{#if flaggedPost.wasEdited}}{{/if}} + {{/if}} + {{/if}} + {{#if adminActiveFlagsView}} + {{#if flaggedPost.previous_flags_count}} + {{flaggedPost.previous_flags_count}} + {{/if}} + {{/if}} + +

+ {{#if flaggedPost.topic.isPrivateMessage}} + {{fa-icon envelope}} + {{/if}} + {{topic-status topic=flaggedPost.topic}} + {{flaggedPost.topic.title}} +

+ {{#if flaggedPost.postAuthorFlagged}} + {{{flaggedPost.excerpt}}} + {{/if}} +
+ + + {{#each flaggedPost.flaggers}} + + + + + {{/each}} + +
+ {{#link-to 'adminUser' user}} + {{avatar user imageSize="small"}} + {{/link-to}} + + {{#link-to 'adminUser' user}} + {{user.username}} + {{/link-to}} + {{format-age flaggedAt}} +
+ {{flagType}} +
+
+ {{#if adminOldFlagsView}} + + + {{#each flaggedPost.flaggers}} + + + + + {{/each}} + +
+ {{#link-to 'adminUser' disposedBy}} + {{avatar disposedBy imageSize="small"}} + {{/link-to}} + + {{format-age disposedAt}} + {{{dispositionIcon}}} + {{#if tookAction}} + + {{/if}} +
+ {{/if}} +
+
+ {{{i18n admin.flags.topic_flagged}}} {{i18n admin.flags.visit_topic}} +
+
+
+ {{#if response}} +

+ {{#link-to 'adminUser' response.user}}{{avatar response.user imageSize="small"}}{{/link-to}} {{{response.excerpt}}} +

+ {{#if reply}} +

+ {{#link-to 'adminUser' reply.user}}{{avatar reply.user imageSize="small"}}{{/link-to}} {{{reply.excerpt}}} + {{#if hasMore}} + {{i18n admin.flags.more}} + {{/if}} +

+ {{/if}} + + + + {{/if}} +
+
+ {{#if adminActiveFlagsView}} + + {{#if flaggedPost.postHidden}} + + {{else}} + + {{/if}} + + + {{/if}} +
+ {{#if view.loading}} + {{loading-spinner}} + {{/if}} + +{{else}} +

{{i18n admin.flags.no_results}}

+{{/if}} diff --git a/app/assets/javascripts/admin/templates/flags.hbs b/app/assets/javascripts/admin/templates/flags.hbs index d5756938b17..78e11492bf1 100644 --- a/app/assets/javascripts/admin/templates/flags.hbs +++ b/app/assets/javascripts/admin/templates/flags.hbs @@ -1,170 +1,12 @@
- {{#if loading}} - {{loading-spinner}} - {{else}} - {{#if length}} - - - - - - - - - - - {{#each flaggedPost in content}} - - - - - - - - - - - - - {{#if flaggedPost.topicFlagged}} - - - - - {{/if}} - - {{#each flaggedPost.conversations}} - - - - - {{/each}} - - - - - - {{/each}} - - -
{{i18n admin.flags.flagged_by}}{{#if adminOldFlagsView}}{{i18n admin.flags.resolved_by}}{{/if}}
- {{#if flaggedPost.postAuthorFlagged}} - {{#if flaggedPost.user}} - {{#link-to 'adminUser' flaggedPost.user}}{{avatar flaggedPost.user imageSize="small"}}{{/link-to}} - {{#if flaggedPost.wasEdited}}{{/if}} - {{/if}} - {{/if}} - {{#if adminActiveFlagsView}} - {{#if flaggedPost.previous_flags_count}} - {{flaggedPost.previous_flags_count}} - {{/if}} - {{/if}} - -

- {{#if flaggedPost.topic.isPrivateMessage}} - {{fa-icon envelope}} - {{/if}} - {{topic-status topic=flaggedPost.topic}} - {{flaggedPost.topic.title}} -

- {{#if flaggedPost.postAuthorFlagged}} - {{{flaggedPost.excerpt}}} - {{/if}} -
- - - {{#each flaggedPost.flaggers}} - - - - - {{/each}} - -
- {{#link-to 'adminUser' user}} - {{avatar user imageSize="small"}} - {{/link-to}} - - {{#link-to 'adminUser' user}} - {{user.username}} - {{/link-to}} - {{format-age flaggedAt}} -
- {{flagType}} -
-
- {{#if adminOldFlagsView}} - - - {{#each flaggedPost.flaggers}} - - - - - {{/each}} - -
- {{#link-to 'adminUser' disposedBy}} - {{avatar disposedBy imageSize="small"}} - {{/link-to}} - - {{format-age disposedAt}} - {{{dispositionIcon}}} - {{#if tookAction}} - - {{/if}} -
- {{/if}} -
-
- {{{i18n admin.flags.topic_flagged}}} {{i18n admin.flags.visit_topic}} -
-
-
- {{#if response}} -

- {{#link-to 'adminUser' response.user}}{{avatar response.user imageSize="small"}}{{/link-to}} {{{response.excerpt}}} -

- {{#if reply}} -

- {{#link-to 'adminUser' reply.user}}{{avatar reply.user imageSize="small"}}{{/link-to}} {{{reply.excerpt}}} - {{#if hasMore}} - {{i18n admin.flags.more}} - {{/if}} -

- {{/if}} - - - - {{/if}} -
-
- {{#if adminActiveFlagsView}} - - {{#if flaggedPost.postHidden}} - - {{else}} - - {{/if}} - - - {{/if}} -
- {{#if view.loading}} - {{loading-spinner}} - {{/if}} - - {{else}} -

{{i18n admin.flags.no_results}}

- {{/if}} - {{/if}} + {{outlet}}
diff --git a/app/assets/javascripts/admin/views/admin_flags_view.js b/app/assets/javascripts/admin/views/admin-flags-list.js.es6 similarity index 82% rename from app/assets/javascripts/admin/views/admin_flags_view.js rename to app/assets/javascripts/admin/views/admin-flags-list.js.es6 index 52053a53895..b3035fe7421 100644 --- a/app/assets/javascripts/admin/views/admin_flags_view.js +++ b/app/assets/javascripts/admin/views/admin-flags-list.js.es6 @@ -1,12 +1,10 @@ -Discourse.AdminFlagsView = Discourse.View.extend(Discourse.LoadMore, { +export default Discourse.View.extend(Discourse.LoadMore, { loading: false, eyelineSelector: '.admin-flags tbody tr', actions: { - loadMore: function() { var self = this; - if (this.get("loading") || this.get("model.allLoaded")) { return; } this.set("loading", true); @@ -15,7 +13,6 @@ Discourse.AdminFlagsView = Discourse.View.extend(Discourse.LoadMore, { self.set("loading", false); }); } - } }); diff --git a/app/assets/javascripts/admin/views/modals/admin_agree_flag_view.js b/app/assets/javascripts/admin/views/modals/admin_agree_flag_view.js index c28a4aaad48..cabb3c7fde5 100644 --- a/app/assets/javascripts/admin/views/modals/admin_agree_flag_view.js +++ b/app/assets/javascripts/admin/views/modals/admin_agree_flag_view.js @@ -1,11 +1,3 @@ -/** - A modal view for agreeing with a flag. - - @class AdminAgreeFlagView - @extends Discourse.ModalBodyView - @namespace Discourse - @module Discourse -**/ Discourse.AdminAgreeFlagView = Discourse.ModalBodyView.extend({ templateName: 'admin/templates/modal/admin_agree_flag', title: I18n.t('admin.flags.agree_flag_modal_title')