added group_timelines

This commit is contained in:
nilsding 2015-01-13 13:23:12 +01:00
parent eaa4096af5
commit a8ed21942e
9 changed files with 83 additions and 81 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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 %>

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'}