Skip to content

Commit

Permalink
Merge branch 'main' into bug/218-clipboard-button-shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
rishijain authored Oct 10, 2023
2 parents fbc56fb + 21d7457 commit 2159e8d
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem "bootstrap-sass", "3.4.1"
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use Puma as the app server
gem "puma", "~> 6.2"
gem "puma", "~> 6.3"
# Use SCSS for stylesheets
gem "sass-rails", "~> 5.0"
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -54,7 +54,7 @@ gem "jquery-rails"

gem "pg"

gem "jquery-ui-rails", "~> 5.0", ">= 5.0.5"
gem "jquery-ui-rails", "~> 6.0"
gem "acts_as_list"

gem "mimemagic", "~> 0.3.8"
Expand Down
54 changes: 28 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ GEM
tzinfo (~> 2.0)
acts_as_list (1.1.0)
activerecord (>= 4.2)
addressable (2.8.1)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
autoprefixer-rails (10.4.13.0)
Expand Down Expand Up @@ -146,7 +146,7 @@ GEM
globalid (1.1.0)
activesupport (>= 5.0)
hashie (5.0.0)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
Expand All @@ -155,7 +155,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.6.3)
jwt (2.7.0)
Expand All @@ -165,9 +165,9 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.19.1)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
nokogiri (>= 1.12.0)
madmin (1.2.7)
pagy (>= 3.5, < 6.0)
rails (>= 6.0.3)
Expand All @@ -182,8 +182,8 @@ GEM
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.1.2)
minitest (5.18.0)
mini_mime (1.1.5)
minitest (5.20.0)
multi_xml (0.6.0)
net-imap (0.3.4)
date
Expand All @@ -197,12 +197,12 @@ GEM
newrelic_rpm (9.1.0)
next_rails (1.2.2)
colorize (>= 0.8.1)
nio4r (2.5.8)
nokogiri (1.14.3-arm64-darwin)
nio4r (2.5.9)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-darwin)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.14.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand Down Expand Up @@ -237,13 +237,13 @@ GEM
parser (3.2.1.1)
ast (~> 2.4.1)
pg (1.4.6)
public_suffix (5.0.1)
puma (6.2.1)
public_suffix (5.0.3)
puma (6.3.1)
nio4r (~> 2.0)
pundit (2.3.0)
activesupport (>= 3.0.0)
racc (1.6.2)
rack (2.2.6.4)
racc (1.7.1)
rack (2.2.8)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-protection (3.0.5)
Expand All @@ -268,11 +268,13 @@ GEM
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
Expand All @@ -287,7 +289,7 @@ GEM
ffi (~> 1.0)
recursive-open-struct (1.1.3)
redcarpet (3.5.1)
regexp_parser (2.7.0)
regexp_parser (2.8.1)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
Expand Down Expand Up @@ -369,7 +371,7 @@ GEM
rubocop-performance (~> 1.16.0)
standardrb (1.0.1)
standard
thor (1.2.1)
thor (1.2.2)
tilt (2.1.0)
timeout (0.3.2)
turbolinks (5.2.1)
Expand All @@ -393,15 +395,15 @@ GEM
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.7)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-21
x86_64-linux

Expand All @@ -420,7 +422,7 @@ DEPENDENCIES
faker
jbuilder (~> 2.5)
jquery-rails
jquery-ui-rails (~> 5.0, >= 5.0.5)
jquery-ui-rails (~> 6.0)
listen (~> 3.7)
madmin (~> 1.2)
matrix
Expand All @@ -429,7 +431,7 @@ DEPENDENCIES
next_rails
ombu_labs-auth
pg
puma (~> 6.2)
puma (~> 6.3)
pundit (~> 2.2)
rack-mini-profiler
rails (~> 7.0.2)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//= require jquery
//= require bootstrap-sprockets
//= require jquery-ui/widget
//= require jquery-ui/sortable
//= require jquery-ui/widgets/sortable
//= require turbolinks
//= require clipboard.min
//= require sortable_list
Expand Down
33 changes: 33 additions & 0 deletions app/assets/stylesheets/stories.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,36 @@
border: 1px solid #9b054d;
padding: 5px;
}

.comments-section {
margin: 16px 0;

.comment-card {
margin: 8px 0;

.bold {
font-weight: bold;
}

.link-blue {
color: blue;
}
}
}

.comment-form-container {
margin: 8px 0;
width: 50%;

.bold {
font-weight: bold;
}
}

#comment_body {
margin: 10px 0;
}

input.button.green {
width: auto;
}
59 changes: 59 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class CommentsController < ApplicationController
before_action :authenticate_user!
before_action :load_story_and_project
before_action :find_comment, only: [:edit, :update, :destroy]

def edit
end

def create
@comment = current_user.comments.build(story: @story)
@comment.attributes = comment_params
saved = @comment.save
if saved
flash[:success] = "Comment created!"
else
flash[:error] = @comment.errors.full_messages
end

redirect_to project_story_path(@comment.story.project_id, @comment.story_id)
end

def update
updated = @comment.update(comment_params)
if updated
flash[:success] = "Comment updated!"
redirect_to project_story_path(@comment.story.project_id, @comment.story_id)
else
flash[:error] = @comment.errors.full_messages
render :edit
end
end

def destroy
@comment.destroy
flash[:success] = "Comment deleted!"
redirect_to project_story_path(@comment.story.project_id, @comment.story_id)
end

private

def find_comment
@comment = current_user.comments.where(story_id: params[:story_id]).find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:error] = "Comment not found"
redirect_to project_story_path(params[:project_id], params[:story_id])
end

def load_story_and_project
@project = Project.find(params[:project_id])
@story = Story.find(params[:story_id])
rescue ActiveRecord::RecordNotFound
flash[:error] = "Project or Story not found"
redirect_to projects_path
end

def comment_params
params.require(:comment).permit(:body)
end
end
25 changes: 20 additions & 5 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def bulk_destroy

def show
@estimate = Estimate.find_by(story: @story, user: current_user)
@comments = @story.comments.includes(:user).order(:created_at)
@comment = Comment.new
end

def update
Expand Down Expand Up @@ -85,12 +87,25 @@ def import
end

def export
csv = CSV.generate(headers: true) { |csv|
csv << CSV_HEADERS
@project.stories.by_position.each do |story|
csv << story.attributes.slice(*CSV_HEADERS)
csv = if params[:export_with_comments] == "1"
CSV.generate(headers: true) do |csv|
csv << CSV_HEADERS + ["comment"]
@project.stories.includes(:comments).by_position.each do |story|
comments = []
story.comments.each do |comment|
comments << "#{comment.user.name}: #{comment.body}"
end
csv << [story.id, story.title, story.description, story.position] + comments
end
end
}
else
CSV.generate(headers: true) do |csv|
csv << CSV_HEADERS
@project.stories.by_position.each do |story|
csv << story.attributes.slice(*CSV_HEADERS)
end
end
end
filename = "#{@project.title.gsub(/[^\w]/, "_")}-#{Time.now.to_formatted_s(:short).tr(" ", "_")}.csv"
send_data csv, filename: filename
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Comment < ApplicationRecord
belongs_to :story
belongs_to :user
validates :body, presence: true
end
1 change: 1 addition & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Story < ApplicationRecord
belongs_to :project
has_many :estimates
has_many :users, through: :estimates
has_many :comments

before_create :add_position

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class User < ApplicationRecord
include OmbuLabsAuthenticable

has_many :estimates
has_many :comments
end
7 changes: 7 additions & 0 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="comment-card">
<p class="bold"><%= comment.user.name %>: <%= markdown(comment.body) %> <%= comment.created_at %><p>
<% if current_user == comment.user %>
<%= link_to "Edit Comment", edit_project_story_comment_path(project, story, comment), class: "link-blue" %> |
<%= link_to "Delete", project_story_comment_path(project, story, comment), method: :delete, data: { confirm: "Are you sure?" }, title: "Delete" %>
<% end %>
</div>
5 changes: 5 additions & 0 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= form_with model: [project, story, comment] do |form| %>
<%= form.text_area :body, rows: 6 %>
<%= form.submit class: "button green"%>
<%= link_to "Back", project_story_path(project, story), id: "back", class: "button" if ["edit", "update"].include?(action_name) %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/comments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="container">
<h2 class="new-edit-title">Edit Comment</h2>
<%= render partial: "form", locals: {story: @story, comment: @comment, project: @project} %>
</div>
9 changes: 8 additions & 1 deletion app/views/projects/_import_export.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
<h4 class="my-0 font-weight-normal">Export CSV</h4>
</div>
<div class="card-body">
<%= link_to 'Export', export_project_stories_path(@project), class: "button green" %>
<%= form_with url: export_project_stories_path(@project), method: :get do |f| %>
<%= f.submit "Export", class: "button green", data: { disable_with: false } %>
<br/>
<%= f.label :export_with_comments do %>
<%= f.check_box :export_with_comments %>
Export with comments
<% end %>
<% end %>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 2159e8d

Please sign in to comment.