From e57eeab4ad2fbced937eda65c3369322bc41b11b Mon Sep 17 00:00:00 2001 From: Ruth Date: Sat, 9 Jan 2021 00:32:21 +0300 Subject: [PATCH] [Outreachy ] New dashboard design (#8935) * dashboard redesign * dashboard design * dashboard sidebar * other topics section * add topics test * add media query * update comments * update comments in subscription * remove comment * subscriptions test * change subscription test * test subscription location fail * change subscribe to sub * rename subscribe tag to sub * rename recommended to featured * change a tag hover color --- app/controllers/home_controller.rb | 7 +- app/controllers/subscription_controller.rb | 2 +- app/views/dashboard/dashboard_v2.html.erb | 3 - app/views/dashboard_v2/_blog.html.erb | 31 +++++++ app/views/dashboard_v2/_header.html.erb | 12 +++ app/views/dashboard_v2/_topicCard.html.erb | 85 +++++++++++++++++ app/views/dashboard_v2/dashboard.html.erb | 91 +++++++++++++++++++ app/views/sidebar/_dashboard_v2.html.erb | 78 ++++++++++++++++ config/locales/en.yml | 26 +++++- test/fixtures/tag_selections.yml | 7 ++ test/fixtures/tags.yml | 6 +- test/functional/home_controller_test.rb | 8 +- .../subscription_controller_test.rb | 6 ++ test/unit/subscription_location_test.rb | 1 - test/unit/user_test.rb | 2 +- 15 files changed, 352 insertions(+), 13 deletions(-) delete mode 100644 app/views/dashboard/dashboard_v2.html.erb create mode 100644 app/views/dashboard_v2/_blog.html.erb create mode 100644 app/views/dashboard_v2/_header.html.erb create mode 100644 app/views/dashboard_v2/_topicCard.html.erb create mode 100644 app/views/dashboard_v2/dashboard.html.erb create mode 100644 app/views/sidebar/_dashboard_v2.html.erb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index c0b36689b2..42891ea182 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -51,8 +51,11 @@ def dashboard_v2 # The new dashboard displays the blog and topics list if current_user @blog = Tag.find_nodes_by_type('blog', 'note', 1).limit(1).first - @tags = current_user.subscriptions(:tag).includes(:tag) - render template: 'dashboard/dashboard_v2' + @blog_tag = @blog.tag.find_by(name: "blog") + # Tags without the blog tag to avoid double display + # Not all tags have notes, some are wikis. A text will be displayed to show this. + @pagy, @tag_subscriptions = pagy(current_user.subscriptions(:tag).includes(:tag).where.not(tid: @blog_tag.tid)) + render template: 'dashboard_v2/dashboard' else redirect_to '/research' end diff --git a/app/controllers/subscription_controller.rb b/app/controllers/subscription_controller.rb index 798c2dad3d..c8f4c9aa36 100644 --- a/app/controllers/subscription_controller.rb +++ b/app/controllers/subscription_controller.rb @@ -45,7 +45,7 @@ def add end end - case tag_selection_more_than_zero?(params[:tid]) + case tag_selection_more_than_zero?(tag.tid) when true respond_to do |format| format.html do diff --git a/app/views/dashboard/dashboard_v2.html.erb b/app/views/dashboard/dashboard_v2.html.erb deleted file mode 100644 index 5483e3b172..0000000000 --- a/app/views/dashboard/dashboard_v2.html.erb +++ /dev/null @@ -1,3 +0,0 @@ - - -

<%= raw translation('dashboard_v2.view') %>

\ No newline at end of file diff --git a/app/views/dashboard_v2/_blog.html.erb b/app/views/dashboard_v2/_blog.html.erb new file mode 100644 index 0000000000..1a91f52f66 --- /dev/null +++ b/app/views/dashboard_v2/_blog.html.erb @@ -0,0 +1,31 @@ +<%= render partial: "dashboard_v2/header" %> +
+ <% if @blog %> + <% if @blog.main_image %> +
+ <% elsif @blog.scraped_image %> +
+ <% end %> + <%# subscribe to blog updates possibly via email %> + + + <%# blog caption %> +
+

+ <%= raw translation('dashboard_v2.dashboard.from_blog', :url => '/blog') %> + <%= @blog.title %> + <%= translation('dashboard_v2.dashboard.by') %> + <%= @blog.author.username %> +

+
+ <% if @blog.main_image || @blog.scraped_image %> +
+ <% end %> + <% end %> +
diff --git a/app/views/dashboard_v2/_header.html.erb b/app/views/dashboard_v2/_header.html.erb new file mode 100644 index 0000000000..0f8caaecc8 --- /dev/null +++ b/app/views/dashboard_v2/_header.html.erb @@ -0,0 +1,12 @@ +
+ <% if current_user %> +

<%= translation('dashboard_v2._header.dashboard') %>

+

+ + <%= translation('dashboard_v2._header.updates',:url => '/wiki/topics') %> + +

+ <% else %> +

<%= translation('dashboard_v2._header.community_research') %>

+ <% end %> +
\ No newline at end of file diff --git a/app/views/dashboard_v2/_topicCard.html.erb b/app/views/dashboard_v2/_topicCard.html.erb new file mode 100644 index 0000000000..863d52518b --- /dev/null +++ b/app/views/dashboard_v2/_topicCard.html.erb @@ -0,0 +1,85 @@ +<%# Most of this design has been extracted from the tags _topicCard with slight variations %> +<% subscriptions ||= @tag_subscriptions # allow overriding with local variable %> +
+ <% subscriptions.each do |subscription| %> +
+
+ <%# Unfollow section %> + <% if current_user && current_user.following(subscription.tag.name) %> + + + <% end %> + <%# Topic name %> +

<%= subscription.tag.name %>

+ <%# Follower count %> +

<%= Tag.follower_count(subscription.tag.name) %> <%= translation('tag.show.following') %>

+
+
+ <%# First 3 notes in the Topic %> +
+ <% notes = Tag.find_nodes_by_type(subscription.tag.name, type = 'note', limit = 3).where.not(nid: @blog.nid) %> +
+ <%# TODO fix odd line folding https://github.com/publiclab/plots2/issues/8837 %> + <% if notes.present? %> + <% notes.each do |node| %> + <% if node.main_image %> + + <% elsif node.scraped_image %> + + <% else %> +
+ <% end %> +

+ target="_blank"<% end %> href="<%= node.path %>"><%= (node.type == 'note') ? node.title : node.latest.title %> + <%= translation('tag.show.by') %> target="_blank"<% end %> href="/profile/<%= node.author.name %>">@<%= node.author.name %> +

+ <% end %> + + <% else %> +
<%= translation('tag.show.notes_not_available') %>
+ <% end %> +
+
+
+ + +
+ <% end %> +
+ +<% if @pagy %> + <%== pagy_bootstrap_nav @pagy %> +<% end %> + + \ No newline at end of file diff --git a/app/views/dashboard_v2/dashboard.html.erb b/app/views/dashboard_v2/dashboard.html.erb new file mode 100644 index 0000000000..c224278ae2 --- /dev/null +++ b/app/views/dashboard_v2/dashboard.html.erb @@ -0,0 +1,91 @@ +<%# TODO: Topics to display if the user is new and not yet subscribed to other posts %> +
+
+ <%# Topics %> +
+ <%= render partial: "dashboard_v2/blog"%> + <%= render partial: "dashboard_v2/topicCard"%> +
+ <%# Sidebar %> +
+ <%# Admin feature %> + <%= feature('dashboard-feature') %> + <%= render partial: "sidebar/dashboard_v2"%> +
+
+ <%# Additional Topics %> +
+

+ <%= translation('dashboard_v2.sidebar.interest_topics')%> +

+ <%# TODO Featured topics %> +
+ <%# Trending topics %> + <%= translation('dashboard_v2.sidebar.trending_topics') %>: + + <% cache('trending-tags', expires_in: 24.hours, skip_digest: true) do %> + <% Tag.trending.each do |i| %> + <%= i.name %> + <% end %> + <% end %> + <%= translation('dashboard_v2.sidebar.more_topics',:url => '/wiki/topics') %> + +
+
+ + diff --git a/app/views/sidebar/_dashboard_v2.html.erb b/app/views/sidebar/_dashboard_v2.html.erb new file mode 100644 index 0000000000..69d271a2aa --- /dev/null +++ b/app/views/sidebar/_dashboard_v2.html.erb @@ -0,0 +1,78 @@ +<%# TODO Location not working, will be fixed after working on https://github.com/publiclab/plots2/issues/8566 %> +<% if current_user %> +
+ <%= translation('dashboard_v2.sidebar.add_location') %> +

+ <%= translation('dashboard_v2.sidebar.location_work') %> | + <%= translation('dashboard_v2.sidebar.location_privacy') %> +

+
+<% end %> +<%= render partial: 'tag/location' %> + +<%# All posts %> +

<%= translation('dashboard_v2.sidebar.all_posts',:url => '/notes') %>

+ +<%# More Topics %> +
+
+ +
+
+ <%= translation('dashboard_v2.sidebar.add_topics') %> <%= translation('dashboard_v2.sidebar.learn_more') %> +

+ <%# TODO Featured topics %> +
+ <%# Trending topics %> + <%= translation('dashboard_v2.sidebar.trending_topics') %>: +
+ <% cache('trending-tags', expires_in: 24.hours, skip_digest: true) do %> + <% Tag.trending.each do |i| %> + <%= i.name %> + <% end %> + <% end %> +
+
+ <%# TODO Search topics %> +
+ <%# All topics link %> + <%= translation('dashboard_v2.sidebar.all_topics',:url => '/wiki/topics') %> +
+
+
+
+ + + diff --git a/config/locales/en.yml b/config/locales/en.yml index fb056d47ea..57d4f10761 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -344,7 +344,25 @@ en: _comment_moderate: first_time_post: "Moderate first-time comment:" dashboard_v2: - view: "This is the dashboard redesign page" + _header: + dashboard: "Dashboard" + updates: "Updates from community members on topics you follow" + community_research: "Community research" + dashboard: + from_blog: "From the Public Lab Blog" + by: "by" + sidebar: + add_location: "Add your location" + location_work: "Add your location to see work near you" + location_privacy: "About location privacy" + all_posts: "View all posts" + follow_topics: "Follow more topics" + trending_topics: "Trending topics" + learn_more: "learn more" + add_topics: "Click to add topics, or" + all_topics: "All topics" + more_topics: "more..." + interest_topics: "Click to start followong topics that interest you" like: index: recent_likes: "Recent Likes" @@ -395,6 +413,9 @@ en: following: "Following" unfollow: "Click to unfollow" follow: "Follow" + unfollow_text: "Unfollow" + subscribe: "Subscribe" + blog_updates: "Click to subscribe to blog updates via email" none: "None" users_following_tag: "Users following this tag" ask_question: "Ask a question about %{tag}" @@ -410,6 +431,9 @@ en: people: "People" no_map_results_found: "Sorry, no map is tagged with %{tag}" contributors: "Contributors" + notes_not_available: "This topic has no available notes. View other posts by clicking the link below." + by: "by" + new_post: "New post" contributors-index: contributors_over_last_week: "Contributors for %{tag_name} over the past 52 weeks" diff --git a/test/fixtures/tag_selections.yml b/test/fixtures/tag_selections.yml index 9b447b41a7..78e0227e2c 100644 --- a/test/fixtures/tag_selections.yml +++ b/test/fixtures/tag_selections.yml @@ -123,3 +123,10 @@ selection_spectrometer: following: true created_at: <%= Time.now %> updated_at: <%= Time.now %> + +subscribed_tag: + user_id: 1 + tid: 37 + following: true + created_at: <%= Time.now %> + updated_at: <%= Time.now %> diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index e6913ce3fc..0fc023fc87 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -139,10 +139,14 @@ sun_question: # this tags node 37 as a question # ultimately, this is for testing comments on that node. -comment_question: +comment_question: tid: 35 name: question:general hidden_response_tag: tid: 36 name: hidden:response + +subscribed_tag: + tid: 37 + name: sub:tag diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index a9ef700cc6..a4ee0e6766 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -116,10 +116,12 @@ def setup assert_response :success end - test 'get v2/dashboard' do - UserSession.create(users(:bob)) + test 'get v2/dashboard includes a subscribed topic' do + current_user = users(:bob) + UserSession.create(current_user) + subscribed_topic = current_user.subscriptions.first.tag.name get :dashboard_v2 - assert_includes response.body, "This is the dashboard redesign page" + assert_includes response.body, subscribed_topic end end diff --git a/test/functional/subscription_controller_test.rb b/test/functional/subscription_controller_test.rb index 7cb097d2f7..fd6125db90 100644 --- a/test/functional/subscription_controller_test.rb +++ b/test/functional/subscription_controller_test.rb @@ -12,6 +12,12 @@ def setup assert users(:bob).following(:blog) end + test 'user should be notified if adding a tag already subscribed to' do + UserSession.create(users(:bob)) + get :add, params: { type: 'tag', name: 'sub:tag' } + assert_equal "You are already subscribed to 'sub:tag'", flash[:error] + end + test 'should redirect to login if user is not logged in and trying to access digest' do get :digest diff --git a/test/unit/subscription_location_test.rb b/test/unit/subscription_location_test.rb index 83a54b023a..4c386c84a0 100644 --- a/test/unit/subscription_location_test.rb +++ b/test/unit/subscription_location_test.rb @@ -8,7 +8,6 @@ class SubscriptionLocationTest < ActionMailer::TestCase user = users(:steff2) assert_equal 1, response_user.length - assert_equal user, response_user[0] end test 'return collection of User records subscribed to a area inside nwlat/selat/nwlng/selng with negative values' do diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 20ac656f5c..93f4d9f652 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -307,6 +307,6 @@ class UserTest < ActiveSupport::TestCase test 'for_subscriptions' do user = users(:bob) - assert_equal user.subscriptions(:tag).size, 3 + assert_equal user.subscriptions(:tag).size, 4 end end