forked from ifournight/tower_homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
993e3c4
commit 34ed341
Showing
14 changed files
with
159 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
class ActivitiesController < ApplicationController | ||
def index | ||
if Team.exists?(session[:team_id]) | ||
team = Team.find session[:team_id] | ||
projects = current_user.anticipated_projects_in_team(team) | ||
@team = Team.find session[:team_id] | ||
projects = current_user.anticipated_projects_in_team(@team) | ||
project_ids = projects.map(&:id) | ||
@activities = Activity.where(project_id: project_ids).order('created_at DESC').to_a | ||
else | ||
@activities = Activity.order('created_at DESC').to_a | ||
end | ||
by_day = @activities.group_by_day(&:created_at) | ||
@activities_by_day = {} | ||
by_day.each do |day, group| | ||
@activities_by_day[day] = {} | ||
by_project = group.group_by(&:project_id) | ||
by_project.each do |id, subgroup| | ||
@activities_by_day[day][id] = subgroup | ||
|
||
by_day = @activities.group_by_day(&:created_at) | ||
@activities_by_day = {} | ||
by_day.each do |day, group| | ||
@activities_by_day[day] = {} | ||
by_project = group.group_by(&:project_id) | ||
by_project.each do |id, subgroup| | ||
@activities_by_day[day][id] = subgroup | ||
end | ||
end | ||
end | ||
|
||
@by_day_groups = [] | ||
@activities_by_day.each do |day, group| | ||
@by_day_groups << { day: day, group: group } | ||
end | ||
@by_day_groups = [] | ||
@activities_by_day.each do |day, group| | ||
@by_day_groups << { day: day, group: group } | ||
end | ||
|
||
@by_day_groups.sort do |a, b| | ||
(a[:day] <=> b[:day]) | ||
@by_day_groups.sort do |a, b| | ||
(a[:day] <=> b[:day]) | ||
end | ||
@by_day_groups.reverse! | ||
end | ||
@by_day_groups.reverse! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ def completed | |
end | ||
end | ||
|
||
has_many :activities | ||
|
||
def collaborators | ||
Access | ||
.where( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
<section class='section' id="todo-list-section"> | ||
<%= content_tag :section, class: 'section', id: "activities-team_#{@team.id}" do %> | ||
<% if @activities.any? %> | ||
|
||
<% @by_day_groups.each do |by_day_group| %> | ||
<section class='section'> | ||
|
||
<%= content_tag :section, id: "by-day_#{by_day_group[:day]}", class: 'section' do %> | ||
|
||
<h2 class='title is-h2'><%= by_day_group[:day] %></h2> | ||
<% by_day_group[:group].each do |project_id, by_project_group| %> | ||
<% project = Project.find(project_id) %> | ||
<h3 class='title is-h3'><%= link_to project.name, project %></h3> | ||
<ul> | ||
<% by_project_group.each do |activity| %> | ||
<%= render activity %> | ||
|
||
<%= content_tag :section, id: "by-d_#{by_day_group[:day]}-p_#{project.id}", class: 'section' do %> | ||
<h3 class='title is-h3'><%= link_to project.name, project %></h3> | ||
<ul> | ||
<% by_project_group.each do |activity| %> | ||
<%= render activity %> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
</ul> | ||
<br> | ||
|
||
<% end %> | ||
</section> | ||
|
||
<% end %> | ||
|
||
<% end %> | ||
|
||
<% end %> | ||
</section> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,62 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'User view activities page' do | ||
scenario 'they see exsiting activities' do | ||
user = create(:user) | ||
activity = create(:activity) | ||
sign_in(user) | ||
before :each do | ||
@user = create(:user, name: 'ifournight') | ||
@momo = create(:user, name: 'momo') | ||
|
||
@team_citizen_4 = create_logic_team(owner: @user, team_name: 'Citizen 4') | ||
@team_private = create_logic_team(owner: @user, team_name: 'ifournight private') | ||
|
||
add_team_member(team: @team_citizen_4, member: @momo, authority: 'member') | ||
add_team_member(team: @team_private, member: @momo, authority: 'member') | ||
|
||
@journey = create_logic_project_from_team(team: @team_citizen_4, project_name: 'journey', creator: @user) | ||
@make_momo_star = create_logic_project_from_team(team: @team_citizen_4, project_name: 'make_momo_star', creator: @user) | ||
|
||
@v_coming = create_logic_project_from_team(team: @team_private, project_name: 'v_coming', creator: @user) | ||
@homework = create_logic_project_from_team(team: @team_private, project_name: 'tower_homework', creator: @user) | ||
|
||
make_user_project_collaborator(@momo, @make_momo_star) | ||
make_user_project_collaborator(@momo, @v_coming) | ||
make_user_project_collaborator(@momo, @homework) | ||
|
||
10.times do |i| | ||
create_logic_todo(creator: @user, project: @journey, title: "Todo #{i * 4 + 1}") | ||
create_logic_todo(creator: @user, project: @make_momo_star, title: "Todo #{i * 4 + 2}") | ||
create_logic_todo(creator: @user, project: @v_coming, title: "Todo #{i * 4 + 3}") | ||
create_logic_todo(creator: @user, project: @homework, title: "Todo #{i * 4 + 4}") | ||
end | ||
end | ||
|
||
scenario 'he/she only see exsiting activities belongs_to current working team' do | ||
visit sign_in_url | ||
visit activities_url | ||
sign_in(@momo) | ||
|
||
# let rails know user is working on this project | ||
visit project_path(@journey) | ||
visit activities_path | ||
|
||
expect(page).to have_current_path(activities_path) | ||
expect(page).to have_css "#activities-team_#{@journey.team.id}" | ||
expect(page).to have_no_css "#activities-team_#{@team_private.id}" | ||
end | ||
|
||
scenario 'he/she see activities belongs to projects only he/she anticipated' do | ||
sign_in(@momo) | ||
|
||
# let rails know user is working on this project | ||
visit project_path(@journey) | ||
visit activities_path | ||
|
||
expect(page).to have_css "#activities-team_#{@journey.team.id}" | ||
|
||
@make_momo_star.activities.each do |activity| | ||
expect(page).to have_css "#activity_#{activity.id}" | ||
end | ||
|
||
a = activity | ||
expect(page).to have_css "#activity_#{a.id}" | ||
@journey.activities.each do |activity| | ||
expect(page).to have_no_css "#activity_#{activity.id}" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters