From a8ed21942ee285dbd7df10d81ff6ff41524d8948 Mon Sep 17 00:00:00 2001 From: nilsding Date: Tue, 13 Jan 2015 13:23:12 +0100 Subject: [PATCH] added group_timelines --- app/controllers/group_controller.rb | 7 +++++ app/models/group.rb | 5 +++ app/validators/screen_name_validator.rb | 3 +- app/views/group/index.html.haml | 16 ++++++++++ app/views/group/index.js.erb | 8 +++++ app/views/public/index.html.haml | 41 +----------------------- app/views/shared/_sidebar.html.haml | 42 +++++++++++++++++++++++++ app/views/static/index.html.haml | 41 +----------------------- config/routes.rb | 1 + 9 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 app/controllers/group_controller.rb create mode 100644 app/views/group/index.html.haml create mode 100644 app/views/group/index.js.erb create mode 100644 app/views/shared/_sidebar.html.haml diff --git a/app/controllers/group_controller.rb b/app/controllers/group_controller.rb new file mode 100644 index 00000000..c39c69c1 --- /dev/null +++ b/app/controllers/group_controller.rb @@ -0,0 +1,7 @@ +class GroupController < ApplicationController + before_filter :index + + def index + @timeline = Group.find_by_name(params[:group_name]).timeline.paginate(page: params[:page]) + end +end \ No newline at end of file diff --git a/app/models/group.rb b/app/models/group.rb index 55af9077..367a2821 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -15,4 +15,9 @@ class Group < ActiveRecord::Base def remove_member(user) GroupMember.where(group: self, user: user).first!.destroy end + + # @return [Array] the groups' timeline + def timeline + Answer.where("user_id in (?)", members.pluck(:user_id)).order(:created_at).reverse_order + end end diff --git a/app/validators/screen_name_validator.rb b/app/validators/screen_name_validator.rb index e0158662..3633c4b1 100644 --- a/app/validators/screen_name_validator.rb +++ b/app/validators/screen_name_validator.rb @@ -1,7 +1,8 @@ class ScreenNameValidator < ActiveModel::EachValidator FORBIDDEN_SCREEN_NAMES = %w(justask_admin retrospring_admin admin justask retrospring support about public notifications inbox sign_in sign_up sidekiq moderation moderator mod administrator - siteadmin site_admin help retro_spring retroospring retrosprlng niisding nllsding) + siteadmin site_admin help retro_spring retroospring retrosprlng niisding nllsding + group settings) def validate_each(record, attribute, value) if FORBIDDEN_SCREEN_NAMES.include? value.downcase diff --git a/app/views/group/index.html.haml b/app/views/group/index.html.haml new file mode 100644 index 00000000..d9f363bf --- /dev/null +++ b/app/views/group/index.html.haml @@ -0,0 +1,16 @@ +.container.j2-page + .col-md-3.col-sm-3 + = render 'shared/sidebar' + .col-md-9.col-xs-12.col-sm-9 + = render 'layouts/messages' + + #timeline + - @timeline.each do |answer| + = render 'shared/answerbox', a: answer + + #pagination= will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false + + - if @timeline.next_page + %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @timeline.current_page }} + Load more +.visible-xs= render 'shared/links' diff --git a/app/views/group/index.js.erb b/app/views/group/index.js.erb new file mode 100644 index 00000000..9ce16da7 --- /dev/null +++ b/app/views/group/index.js.erb @@ -0,0 +1,8 @@ +$('#timeline').append('<% @timeline.each do |answer| + %><%= j render 'shared/answerbox', a: answer +%><% end %>'); +<% if @timeline.next_page %> + $('#pagination').html('<%= j will_paginate @timeline, renderer: BootstrapPagination::Rails, page_links: false %>'); +<% else %> + $('#pagination, #load-more-btn').remove(); +<% end %> \ No newline at end of file diff --git a/app/views/public/index.html.haml b/app/views/public/index.html.haml index bc4d115c..d9f363bf 100644 --- a/app/views/public/index.html.haml +++ b/app/views/public/index.html.haml @@ -1,45 +1,6 @@ .container.j2-page .col-md-3.col-sm-3 - .panel.panel-default.hidden-xs - .panel-body - %p - Welcome, - = current_user.screen_name - - unless inbox_count.nil? - %p - %strong - You have - = pluralize(inbox_count, 'new question') - in your inbox! - .row - %a{href: show_user_followers_path(current_user.screen_name)} - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#follower-count= current_user.follower_count - %h6.entry-subtext Followers - %a{href: show_user_friends_path(current_user.screen_name)} - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#friend-count= current_user.friend_count - %h6.entry-subtext Following - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= current_user.asked_count - %h6.entry-subtext Questions - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= current_user.answered_count - %h6.entry-subtext Answers - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= current_user.commented_count - %h6.entry-subtext Comments - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= current_user.smiled_count - %h6.entry-subtext Smiles - .panel.panel-default - .panel-body - %ul.nav.nav-pills.nav-stacked - = nav_entry "Timeline", root_path - = nav_entry "Public", public_timeline_path - .hidden-xs= render 'shared/links' + = render 'shared/sidebar' .col-md-9.col-xs-12.col-sm-9 = render 'layouts/messages' diff --git a/app/views/shared/_sidebar.html.haml b/app/views/shared/_sidebar.html.haml new file mode 100644 index 00000000..58002c6c --- /dev/null +++ b/app/views/shared/_sidebar.html.haml @@ -0,0 +1,42 @@ +.panel.panel-default.hidden-xs + .panel-body + %p + Welcome, + = current_user.screen_name + - unless inbox_count.nil? + %p + %strong + You have + = pluralize(inbox_count, 'new question') + in your inbox! + .row + %a{href: show_user_followers_path(current_user.screen_name)} + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#follower-count= current_user.follower_count + %h6.entry-subtext Followers + %a{href: show_user_friends_path(current_user.screen_name)} + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#friend-count= current_user.friend_count + %h6.entry-subtext Following + .row + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#asked-count= current_user.asked_count + %h6.entry-subtext Questions + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#answered-count= current_user.answered_count + %h6.entry-subtext Answers + .row + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#asked-count= current_user.commented_count + %h6.entry-subtext Comments + .col-md-6.col-sm-6.col-xs-6 + %h4.entry-text#answered-count= current_user.smiled_count + %h6.entry-subtext Smiles +.panel.panel-default + .panel-body + %ul.nav.nav-pills.nav-stacked + = nav_entry "Timeline", root_path + = nav_entry "Public", public_timeline_path + - current_user.groups.each do |group| + = nav_entry group.display_name, group_timeline_path(group.name) +.hidden-xs= render 'shared/links' \ No newline at end of file diff --git a/app/views/static/index.html.haml b/app/views/static/index.html.haml index 037e1e57..14d88172 100644 --- a/app/views/static/index.html.haml +++ b/app/views/static/index.html.haml @@ -1,46 +1,7 @@ - if user_signed_in? .container.j2-page .col-md-3.col-sm-3 - .panel.panel-default.hidden-xs - .panel-body - %p - Welcome, - = current_user.screen_name - - unless inbox_count.nil? - %p - %strong - You have - = pluralize(inbox_count, 'new question') - in your inbox! - .row - %a{href: show_user_followers_path(current_user.screen_name)} - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#follower-count= current_user.follower_count - %h6.entry-subtext Followers - %a{href: show_user_friends_path(current_user.screen_name)} - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#friend-count= current_user.friend_count - %h6.entry-subtext Following - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= current_user.asked_count - %h6.entry-subtext Questions - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= current_user.answered_count - %h6.entry-subtext Answers - .row - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#asked-count= current_user.commented_count - %h6.entry-subtext Comments - .col-md-6.col-sm-6.col-xs-6 - %h4.entry-text#answered-count= current_user.smiled_count - %h6.entry-subtext Smiles - .panel.panel-default - .panel-body - %ul.nav.nav-pills.nav-stacked - = nav_entry "Timeline", root_path - = nav_entry "Public", public_timeline_path - .hidden-xs= render 'shared/links' + = render 'shared/sidebar' .col-md-9.col-xs-12.col-sm-9 = render 'layouts/messages' diff --git a/config/routes.rb b/config/routes.rb index 7c07be4e..6ad14e74 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,7 @@ Rails.application.routes.draw do end match '/public', to: 'public#index', via: :get, as: :public_timeline + match '/group/:group_name', to: 'group#index', via: :get, as: :group_timeline match '/notifications(/:type)', to: 'notifications#index', via: :get, as: :notifications, defaults: {type: 'all'}