This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/controllers
Tarek Khalil f8480ed911
FEATURE: Exposing a way to add a generic report filter (#6816)
* FEATURE: Exposing a way to add a generic report filter

## Why do we need this change?

Part of the work discussed [here](https://meta.discourse.org/t/gain-understanding-of-file-uploads-usage/104994), and implemented a first spike [here](https://github.com/discourse/discourse/pull/6809), I am trying to expose a single generic filter selector per report.

## How does this work?

We basically expose a simple, single generic filter that is computed and displayed based on backend values passed into the report.

This would be a simple contract between the frontend and the backend.

**Backend changes:** we simply need to return a list of dropdown / select options, and enable the report's newly introduced `custom_filtering` property.

For example, for our [Top Uploads](https://github.com/discourse/discourse/pull/6809/files#diff-3f97cbb8726f3310e0b0c386dbe89e22R1423) report, it can look like this on the backend:

```ruby
report.custom_filtering = true
report.custom_filter_options = [{ id: "any", name: "Any" }, { id: "jpg", name: "JPEG" } ]
```

In our javascript report HTTP call, it will look like:

```js
{
  "custom_filtering": true,
  "custom_filter_options": [
    {
      "id": "any",
      "name": "Any"
    },
    {
      "id": "jpg",
      "name": "JPG"
    }
  ]
}
```

**Frontend changes:** We introduced a generic `filter` param and a `combo-box` which hooks up into the existing framework for fetching a report.

This works alright, with the limitation of being a single custom filter per report. If we wanted to add, for an instance a `filesize filter`, this will not work for us. _I went through with this approach because it is hard to predict and build abstractions for requirements or problems we don't have yet, or might not have._

## How does it look like?

![a1ktg1odde](https://user-images.githubusercontent.com/45508821/50485875-f17edb80-09ee-11e9-92dd-1454ab041fbb.gif)

## More on the bigger picture

The major concern here I have is the solution I introduced might serve the `think small` version of the reporting work, but I don't think it serves the `think big`, I will try to shed some light into why.

Within the current design, It is hard to maintain QueryParams for dynamically generated params (based on the idea of introducing more than one custom filter per report).

To allow ourselves to have more than one generic filter, we will need to:

a. Use the Route's model to retrieve the report's payload (we are now dependent on changes of the QueryParams via computed properties)
b. After retrieving the payload, we can use the `setupController` to define our dynamic QueryParams based on the custom filters definitions we received from the backend
c. Load a custom filter specific Ember component based on the definitions we received from the backend
2019-03-15 12:15:38 +00:00
..
admin FEATURE: Exposing a way to add a generic report filter (#6816) 2019-03-15 12:15:38 +00:00
users FIX: Return authenticated=true when reconnecting 2018-12-11 17:40:02 +00:00
about_controller.rb FIX: static page title should be consistent on client side and server side 2018-11-27 22:03:52 +05:30
application_controller.rb FEATURE: Enforce two-factor authentication. (#6348) 2019-03-15 13:09:37 +02:00
badges_controller.rb PERF: N+1 queries on badges page. 2018-03-19 14:36:09 +08:00
categories_controller.rb FIX: validate parent category/subcategories permissions 2019-02-14 16:38:52 +11:00
category_hashtags_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00
clicks_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
composer_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00
composer_messages_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00
csp_reports_controller.rb allow CSP reports to be sent when header isn't set by Discourse (#6594) 2018-11-14 16:23:29 -05:00
directory_items_controller.rb FEATURE: show avatar flair on group, badges and directory pages (#6732) 2018-12-06 12:18:52 +01:00
draft_controller.rb FIX: only check for conflict on edit drafts 2018-11-15 13:14:07 +11:00
drafts_controller.rb raise error early in drafts controller 2018-09-13 08:40:57 -04:00
email_controller.rb FIX: stop adding email to unsubscribe url 2018-05-22 09:07:03 +10:00
embed_controller.rb FIX: store the topic links using the cooked upload url 2018-08-14 12:23:32 +02:00
exceptions_controller.rb UX: Replace Google search with Discourse search on not found page 2018-08-15 11:53:04 +10:00
export_csv_controller.rb FEATURE: Log entity export in staff logs 2018-09-19 03:16:45 +05:30
extra_locales_controller.rb FEATURE: Enforce two-factor authentication. (#6348) 2019-03-15 13:09:37 +02:00
finish_installation_controller.rb FEATURE: Make initial admins TL1 2018-08-22 15:45:24 +10:00
forums_controller.rb FIX: ForumsController doesn't need to inherit from ApplicationController. 2019-01-21 14:37:04 +08:00
groups_controller.rb FIX: user_id handling on remove user from group 2019-01-24 17:40:48 -07:00
highlight_js_controller.rb Fix all the errors to get our tests green on Rails 5.1. 2017-09-25 13:48:58 +08:00
inline_onebox_controller.rb Use hijack in inline onebox controller 2018-11-13 02:39:20 +05:30
invites_controller.rb FEATURE: remove all expired invitations by default 2019-03-07 15:28:39 +05:30
list_controller.rb FIX: remove slow platform detection from server side 2018-12-13 13:57:05 +11:00
metadata_controller.rb FEATURE: Web Share Target Support 2018-12-07 13:48:09 -02:00
notifications_controller.rb Make rubocop happy again. 2018-06-07 13:28:18 +08:00
offline_controller.rb FIX: offline controller regression 2017-10-31 15:44:50 +11:00
onebox_controller.rb FIX: include title in local onebox when linking to a different topic 2018-02-19 22:40:14 +01:00
permalinks_controller.rb FIX: if we have not target available do not redirect 2018-08-20 13:10:59 +10:00
post_action_users_controller.rb UX: cap likes 2 (#5237) 2017-11-15 11:28:54 +11:00
post_actions_controller.rb FIX: Properly display error when post action fails to create. 2018-06-20 21:20:23 +08:00
posts_controller.rb FEATURE: defer flags when deleting child replies (#7111) 2019-03-06 14:32:25 +05:30
push_notification_controller.rb Feature: Push notifications for Android (#5792) 2018-05-04 15:31:48 -07:00
queued_posts_controller.rb Update Rubocop to 0.60 2018-12-04 10:48:16 +01:00
qunit_controller.rb DEV: Don't require login for QUit test path. 2018-11-23 13:50:19 +08:00
robots_txt_controller.rb FIX: simplify so we ban all auth paths 2018-08-16 19:16:47 +10:00
safe_mode_controller.rb Allow staff members to enable safe mode, even if disabled 2018-04-25 11:49:57 -04:00
search_controller.rb FIX: do not show PM topics when moving posts to an existing public topic (#6876) 2019-01-14 15:00:45 +05:30
session_controller.rb human? helper method on a user 2019-02-08 13:34:54 -05:00
similar_topics_controller.rb display 'similar to' earlier when composing a post 2017-09-16 01:03:29 +02:00
site_controller.rb Update Rubocop to 0.60 2018-12-04 10:48:16 +01:00
static_controller.rb Fix favicon not updating on the client side when changed. 2019-03-14 15:37:43 +08:00
steps_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00
stylesheets_controller.rb FEATURE: backend support for user-selectable components 2018-08-08 14:46:34 +10:00
svg_sprite_controller.rb FEATURE: support custom icons in themes (#7155) 2019-03-15 17:16:15 +11:00
tag_groups_controller.rb FIX: tag groups page should only be visible to staff 2018-09-17 11:41:18 -04:00
tags_controller.rb FIX: Disable 'Create Topic' button if tag is staff-only. (#6984) 2019-03-12 19:23:36 +11:00
theme_javascripts_controller.rb PERF: include content-length header for CDN 2019-02-22 11:21:07 +11:00
themes_controller.rb fix theme previewing (#6245) 2018-08-08 10:58:45 +03:00
topics_controller.rb FIX: ensures tag-groups are used to allow category edit on topics (#7141) 2019-03-11 15:02:27 +01:00
uploads_controller.rb UX: Lightbox support for image uploader. (#7034) 2019-02-21 10:13:37 +08:00
user_actions_controller.rb FEATURE: Consolidate likes notifications. (#6879) 2019-01-16 10:40:16 +08:00
user_api_keys_controller.rb FEATURE: Allow wildcard in allowed_user_api_auth_redirects setting (#6779) 2019-02-26 17:03:20 +01:00
user_avatars_controller.rb REFACTOR: Proxy letter avatars in rails instead of nginx 2019-02-18 08:46:56 +11:00
user_badges_controller.rb FIX: use discourse route_for function to check url route 2019-01-11 14:58:45 +08:00
users_controller.rb FEATURE: Save ignored usernames in user preferences (#7117) 2019-03-06 11:21:58 +00:00
users_email_controller.rb FEATURE: Second factor backup 2018-06-28 10:12:32 +02:00
webhooks_controller.rb FEATURE: AWS SNS bounce notifications webhooks 2019-02-13 21:26:40 +01:00
wizard_controller.rb Refactor requires login logic, reduce duplicate code 2018-02-01 15:17:59 +11:00