Skip to content

Commit 38785c3

Browse files
committed
Comment-task: edit, delete, create
1 parent 5050263 commit 38785c3

30 files changed

+370
-92
lines changed

app/assets/stylesheets/custom.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ a.btn.btn-primary {
3434
.fixed-right {
3535
.icon {
3636
font-size: 30px;
37-
left: -10px;
37+
left: 0px;
38+
top: 16px;
3839
position: absolute;
3940
}
4041
}
@@ -59,4 +60,8 @@ a.btn.btn-primary {
5960
grid-template-columns: repeat(8, 1fr);
6061
overflow-x: auto;
6162
overflow-y: hidden;
63+
}
64+
65+
#toast-success, #toast-warning, #toast-danger {
66+
z-index: 10000;
6267
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class CommentsController < ApplicationController
2+
before_action :set_comment, only: %i[show edit destroy update]
3+
before_action :set_task, only: %i[create show edit destroy update]
4+
5+
def show
6+
7+
end
8+
9+
def create
10+
@comment = Comment.new(comment_params)
11+
@comment.user = current_user
12+
@comment.task_id = params[:task_id].to_i
13+
if @comment.save
14+
# redirect_to root_path
15+
else
16+
render_danger(@comment.errors.full_messages.join(", "))
17+
end
18+
end
19+
20+
def update
21+
if @comment.update(comment_params)
22+
else
23+
end
24+
end
25+
26+
def destroy
27+
@comment.destroy
28+
end
29+
30+
private
31+
32+
def set_comment
33+
@comment = Comment.find(params[:id])
34+
end
35+
36+
def set_task
37+
@task = Task.find(params[:task_id])
38+
end
39+
40+
def comment_params
41+
params.require(:comment).permit(:description)
42+
end
43+
end

app/controllers/tasks_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ def index
66
end
77

88
def show
9-
9+
@comment = Comment.new
1010
end
11+
1112
def new
1213
@task = Task.new
1314
end
@@ -60,7 +61,9 @@ def assign_member
6061
if @task.update(assign_id: params[:assign_id])
6162
if current_user.id != params[:assign_id].to_i
6263
activity = tracking_activity("ActivityType::AssignMember", {task_id: @task.id, assign_id: params[:assign_id], text: "Assign Task"})
63-
tracking_notification([params[:assign_id]], activity.id)
64+
if params[:assign_id].present?
65+
tracking_notification([params[:assign_id]], activity.id)
66+
end
6467
end
6568
end
6669
end

app/controllers/users_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class UsersController < ApplicationController
2+
before_action :set_user, only: %i[show update]
23
def list_users
34
member_user_ids = Member.where(project: @current_project).pluck(:user_id) rescue []
45
@users = User.search(params[:name]).where.not(id: member_user_ids) rescue []
@@ -10,4 +11,9 @@ def list_users
1011
}
1112
)
1213
end
14+
15+
def show
16+
17+
end
18+
1319
end

app/helpers/comments_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CommentsHelper
2+
end

app/javascript/controllers/assign_member_controller.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import RequestController from "./request_controller";
44
// Connects to data-controller="assign-member"
55
export default class extends RequestController {
66
connect() {
7-
console.log("assign-member")
87
}
98

109
assignMember(event) {
@@ -21,4 +20,19 @@ export default class extends RequestController {
2120
}
2221
this.sendPostOrPut(params)
2322
}
23+
24+
noneMember(event) {
25+
if (event.preventDefault) {
26+
event.preventDefault();
27+
}
28+
let id = event.target.dataset.task;
29+
const params = {
30+
url: `/assign_member/${id}`,
31+
method: "POST",
32+
body: {
33+
assign_id: null
34+
}
35+
}
36+
this.sendPostOrPut(params)
37+
}
2438
}

app/javascript/controllers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import ProjectController from "./project_controller";
1717
import InviteFormController from "./invite_form_controller";
1818
import ToastController from "./toast_controller";
1919
import AssignMemberController from "./assign_member_controller";
20+
import ModalTurboController from "./modal_turbo_controller";
2021

2122
application.register("request", RequestController)
2223
application.register("move-task", MoveTaskController)
2324
application.register("nav", NavController)
2425
application.register("project", ProjectController)
2526
application.register("invite-form", InviteFormController)
2627
application.register("toast", ToastController)
27-
application.register("assign-member", AssignMemberController)
28+
application.register("assign-member", AssignMemberController)
29+
application.register("modal-turbo", ModalTurboController)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
import RequestController from "./request_controller";
3+
4+
// Connects to data-controller="modal-turbo"
5+
export default class extends RequestController {
6+
connect() {
7+
}
8+
9+
open(event) {
10+
let id = event.target.dataset.id;
11+
this._openComment(id)
12+
}
13+
14+
deleteComment(event) {
15+
if (event.preventDefault) {
16+
event.preventDefault();
17+
}
18+
let id = event.target.dataset.id;
19+
let task_id = event.target.dataset.task;
20+
const params = {
21+
url: `/tasks/${task_id}/comments/${id}`,
22+
method: 'Delete',
23+
}
24+
this.sendGetorDelete(params)
25+
if (!$(`.comment-form-${task_id}`).hasClass("hidden")) {
26+
this._openComment(task_id)
27+
}
28+
}
29+
30+
editComment(event) {
31+
if (event.preventDefault) {
32+
event.preventDefault();
33+
}
34+
let id = event.target.dataset.id;
35+
let task_id = event.target.dataset.task;
36+
this._openComment(task_id)
37+
const params = {
38+
url: `/tasks/${task_id}/comments/${id}`,
39+
method: 'GET',
40+
}
41+
this.sendGetorDelete(params)
42+
}
43+
44+
_openComment(task_id) {
45+
if ($(`.comment-form-${task_id}`).hasClass("hidden")) {
46+
$(`.comment-form-${task_id}`).removeClass("hidden");
47+
$(`.des-${task_id}`).removeClass("vh-80").addClass("vh-70");
48+
$(`.input-${task_id}`).removeClass("form-control").addClass("hidden");
49+
} else {
50+
$(`.comment-form-${task_id}`).addClass("hidden");
51+
$(`.des-${task_id}`).removeClass("vh-70").addClass("vh-80");
52+
$(`.input-${task_id}`).addClass("form-control").removeClass("hidden");
53+
}
54+
}
55+
}

app/javascript/controllers/move_task_controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export default class extends RequestController {
123123
}
124124

125125
detail(event) {
126+
if (event.preventDefault) {
127+
event.preventDefault();
128+
}
126129
let project_id = event.target.dataset.project;
127130
let label_id = event.target.dataset.label;
128131
let task_id = event.target.dataset.task;

app/models/comment.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Comment < ApplicationRecord
2+
belongs_to :user
3+
belongs_to :task
4+
has_rich_text :description
5+
6+
validates :description, presence: true, length: { minimum: 10 }
7+
end

0 commit comments

Comments
 (0)