Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standup comments 1 #446

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
666ef94
Add StandupMeetingComment model
GALTdea Nov 27, 2023
8fffecc
Add enum for standup_meeting_comment sections
GALTdea Nov 27, 2023
2abc9b1
WIP: still need to organize views and controllers
GALTdea Nov 28, 2023
1a73ed7
refactor yesterday_work_description to sections controller and added …
GALTdea Nov 29, 2023
bc0599f
remove unneded code and files
GALTdea Nov 29, 2023
f8748ae
removes unneded code
GALTdea Nov 29, 2023
d30f07c
rubocop fixes
GALTdea Nov 29, 2023
36e8431
Style Standup comment section
GALTdea Dec 1, 2023
0cc40e0
Adds user reference to standup meeting comments
GALTdea Dec 1, 2023
1015180
resize comment container
GALTdea Dec 1, 2023
47052d9
Add comment font-awesome icon to link_to
GALTdea Dec 1, 2023
a0cafb6
refactor standup_meeting creation to persist standup_meeting to be ab…
GALTdea Dec 1, 2023
a6ba1ca
remove unneded actions and add destroy action
GALTdea Dec 1, 2023
d275920
Adds a delete comment link
GALTdea Dec 1, 2023
15b42f3
modify routes
GALTdea Dec 1, 2023
82ff3b1
WIP: Adding request spec for standup_meeting_comments destroy action
GALTdea Dec 1, 2023
01e3471
create action request test working
GALTdea Dec 1, 2023
363fb0b
Fix standup_meeting_comment facotory bot
GALTdea Dec 2, 2023
eab9d4c
Add standup_meeting_comment_policy
GALTdea Dec 2, 2023
4060e57
Rubocop
GALTdea Dec 2, 2023
f9b21ee
Add policy test specs for standup_meeting_comment destroy?
GALTdea Dec 2, 2023
fdc424c
.
GALTdea Dec 2, 2023
f54b765
Fix delete link style
GALTdea Dec 2, 2023
09bdb6b
Update section index view style
GALTdea Dec 2, 2023
ec90999
remove create action
GALTdea Dec 4, 2023
56ca3f5
Add comments spec for comments method)
GALTdea Dec 4, 2023
e6f5907
rubocop
GALTdea Dec 5, 2023
03f7438
Add spec for section_content method
GALTdea Dec 5, 2023
f178b4f
Complete section_content specs for all sections
GALTdea Dec 5, 2023
b6519f1
Add policy to comment links
GALTdea Jan 8, 2024
bb8e968
Add StandupMeetingCommentPolicy edit? spec
GALTdea Jan 9, 2024
df52161
Re set migratioin
GALTdea Jan 16, 2024
3ab668e
update standup_meeting_comments attribute name to sesction_name
GALTdea Jan 16, 2024
fe4d9c5
Update specs to reflect latest migration
GALTdea Jan 16, 2024
4f928a0
Address PR feedback
GALTdea Jan 16, 2024
de4903d
update branch
GALTdea Jan 19, 2024
652316e
resolved merging conflicts
GALTdea Jan 19, 2024
86ce397
fixed content_type into an instance variable to fix failed tests in l…
GALTdea Jan 19, 2024
93e6165
fixed bug caused by section_name variable changes
GALTdea Jan 19, 2024
dca22a9
Added spec for the allowed_section method
GALTdea Jan 20, 2024
12c8a34
remove uneeded scope
GALTdea Jan 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
</span>
<div class="divider my-1 "></div>
<%= tag.span(standup_content, class: "grow whitespace-pre-line") %>

<%= link_to standup_meeting_sections_path(standup_meeting_id: @standup_meeting.id, section: content_type), class: '' do %>
<i class="fas fa-comments"></i> Comments
<% end %>
</div>
39 changes: 39 additions & 0 deletions app/controllers/standup_meeting_comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class StandupMeetingCommentsController < ApplicationController
before_action :set_standup_meeting, only: %i[create]

def edit; end

def create
@standup_meeting_comment = @standup_meeting.standup_meeting_comments.new(standup_meeting_comment_params)
@standup_meeting_comment.user = current_user
if @standup_meeting_comment.save
redirect_to @standup_meeting_comment, notice: 'Comment was successfully created.'
else
render :new
end
end

def destroy
@standup_meeting_comment = StandupMeetingComment.find(params[:id])
authorize @standup_meeting_comment
respond_to do |format|
if @standup_meeting_comment.destroy
format.html do
redirect_back(fallback_location: root_path, notice: 'Comment was successfully deleted.')
end
else
format.html { render :show, status: :unprocessable_entity }
end
end
end

private

def set_standup_meeting
@standup_meeting = StandupMeeting.find(params[:standup_meeting_id])
end

def standup_meeting_comment_params
params.require(:standup_meeting_comment).permit(:content, :name, :standup_meeting_id)
end
end
7 changes: 7 additions & 0 deletions app/controllers/standup_meetings/sections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class StandupMeetings::SectionsController < ApplicationController
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This controller (along with its view) creates a dynamic view corresponding to the appropriate question/section in the standup meeting groups. e.g:
when params:
http://localhost:3000/standup_meetings/597/sections?section=yesterday_work_description

Screenshot 2024-01-09 at 10 59 42 AM

def index
@standup_meeting = StandupMeeting.find(params[:standup_meeting_id])
@section = params[:section]
@question = @standup_meeting.send(@section)
GALTdea marked this conversation as resolved.
Show resolved Hide resolved
end
end
1 change: 1 addition & 0 deletions app/controllers/standup_meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def index
)
@completed_meetings = @standup_meetings.filter(&:completed?)
end

# rubocop:enable Metrics/AbcSize

def edit
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/standup_meeting_comments_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module StandupMeetingCommentsHelper
end
17 changes: 17 additions & 0 deletions app/models/standup_meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
class StandupMeeting < ApplicationRecord
has_noticed_notifications

has_many :standup_meeting_comments, dependent: :destroy

belongs_to :standup_meeting_group, inverse_of: :standup_meetings
belongs_to :user

Expand All @@ -42,4 +44,19 @@ class StandupMeeting < ApplicationRecord
}

scope :for_member, ->(user, group) { where(user:, standup_meeting_group: group) }

def comments(section)
standup_meeting_comments.where(name: section)
end

def section_content(section)
case section
when 'yesterday_work_description'
yesterday_work_description
when 'today_work_description'
today_work_description
when 'blockers_description'
blockers_description
end
end
JoshDevHub marked this conversation as resolved.
Show resolved Hide resolved
end
27 changes: 27 additions & 0 deletions app/models/standup_meeting_comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: standup_meeting_comments
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# standup_meeting_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_standup_meeting_comments_on_standup_meeting_id (standup_meeting_id)
# index_standup_meeting_comments_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (standup_meeting_id => standup_meetings.id)
# fk_rails_... (user_id => users.id)
#
class StandupMeetingComment < ApplicationRecord
belongs_to :standup_meeting
belongs_to :user

has_rich_text :content
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class User < ApplicationRecord
has_one :current_resume, -> { where(current: true) }, class_name: 'Resume', dependent: nil
# rubocop:enable Rails/InverseOf

has_many :standup_meeting_comments, dependent: :destroy

validates :first_name, presence: true
validates :last_name, presence: true

Expand Down
17 changes: 17 additions & 0 deletions app/policies/standup_meeting_comment_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class StandupMeetingCommentPolicy < ApplicationPolicy
alias_method :standup_meeting_comment, :record

def destroy?
user == standup_meeting_comment.user
end

def edit?
user == standup_meeting_comment.user
end

class Scope < Scope
def resolve
scope.all
end
end
end
43 changes: 43 additions & 0 deletions app/views/standup_meetings/sections/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<h1 class="text-2xl font-bold mb-4 text-center "><%= @section.humanize.titleize %></h1>
<div class="max-w-6xl mx-auto border rounded-lg p-4">
<h1 class="text-1xl font-bold mb-4"><%= @standup_meeting.section_content(@section) %> </h1>
</div>

<div class="max-w-6xl mx-auto mt-4">
<% @standup_meeting.comments(@section).each do |comment| %>
<div class="flex-1 border rounded-lg leading-relaxed mb-3">
<div class="bg-gray-100 px-3 py-1 rounded-t-lg">
<strong class="text-sm font-semibold"><%= comment.user.first_name %></strong> <span class="text-xs text-gray-500"><%= time_ago_in_words(comment.created_at) %></span>
</div>

<div class="mt-2 mx-2">
<p class="text-sm">
<%= comment.content %>
</p>
</div>

<div class="mt-4 flex justify-end m-2 text-xs text-gray-500">
<% if policy(comment).edit? %>
<div class="text-sm hover:text-blue-600 cursor-pointer mr-2">Edit</div>
<% end %>
<% if policy(comment).destroy? %>
<div class="text-sm hover:text-blue-600 cursor-pointer"> <%= link_to 'Delete', standup_meeting_standup_meeting_comment_path(@standup_meeting, comment), method: :delete, data: { turbo_method: :delete } %></div>
<% end %>
</div>
</div>
<% end %>

<div class="border-t-4 border-gray-300 mt-4">
<div>Add a comment</div>
<%= form_with model:[@standup_meeting, StandupMeetingComment.new], html: { class: 'border rounded-lg mt-4 p-2' } do |f| %>
<%= f.hidden_field :name, value: @section %>

<div class="flex flex-col justify-between space-y-2 mb-4">
<%= f.rich_text_area :content, class:"textarea textarea-bordered" %>
</div>
<div class="form-control">
<%= f.submit class:"btn btn-primary btn-sm mx-auto"%>
</div>
<% end %>
</div>
</div>
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'admin_constraint'

Rails.application.routes.draw do
resources :standup_meeting_comments, only: %i[index show new create edit update]
constraints(AdminConstraint) do
mount Sidekiq::Web => '/sidekiq'
end
Expand Down Expand Up @@ -69,4 +70,11 @@
scope controller: :static do
get :faq
end

resources :standup_meetings do
resources :standup_meeting_comments, only: %i[create update destroy]
scope module: :standup_meetings do
resources :sections, only: %i[create show index]
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20231127185636_create_standup_meeting_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateStandupMeetingComments < ActiveRecord::Migration[7.0]
def change
create_table :standup_meeting_comments do |t|
t.string :name
GALTdea marked this conversation as resolved.
Show resolved Hide resolved
t.references :standup_meeting, null: false, foreign_key: true

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserToStandupMeetingComments < ActiveRecord::Migration[7.0]
def change
add_reference :standup_meeting_comments, :user, null: false, foreign_key: true
end
end
23 changes: 22 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified erd.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:yesterday_work_description) { 'Lorem ipsum' }
let(:today_work_description) { 'Sit amet' }
let(:standup_meeting) do
build(:standup_meeting, yesterday_work_description:, today_work_description:)
create(:standup_meeting, yesterday_work_description:, today_work_description:)
end

it "renders yesterday's content when passed the yesterday content type" do
Expand Down
28 changes: 28 additions & 0 deletions spec/factories/standup_meeting_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# == Schema Information
#
# Table name: standup_meeting_comments
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# standup_meeting_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_standup_meeting_comments_on_standup_meeting_id (standup_meeting_id)
# index_standup_meeting_comments_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (standup_meeting_id => standup_meetings.id)
# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
factory :standup_meeting_comment do
name { 'MyString' }
standup_meeting
user
end
end
15 changes: 15 additions & 0 deletions spec/helpers/standup_meeting_comments_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the StandupMeetingCommentsHelper. For example:
#
# describe StandupMeetingCommentsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe StandupMeetingCommentsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
26 changes: 26 additions & 0 deletions spec/models/standup_meeting_comment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# == Schema Information
#
# Table name: standup_meeting_comments
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# standup_meeting_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_standup_meeting_comments_on_standup_meeting_id (standup_meeting_id)
# index_standup_meeting_comments_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (standup_meeting_id => standup_meetings.id)
# fk_rails_... (user_id => users.id)
#
require 'rails_helper'

RSpec.describe StandupMeetingComment do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading