Commit ddcfc696 authored by Ruben Davila's avatar Ruben Davila

Address most of the feedback from last code review.

parent aebb6294
...@@ -12,7 +12,7 @@ module IssuableActions ...@@ -12,7 +12,7 @@ module IssuableActions
destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym destroy_method = "destroy_#{issuable.class.name.underscore}".to_sym
TodoService.new.public_send(destroy_method, issuable, current_user) TodoService.new.public_send(destroy_method, issuable, current_user)
name = issuable.class.name.titleize.downcase name = issuable.human_class_name
flash[:notice] = "The #{name} was successfully deleted." flash[:notice] = "The #{name} was successfully deleted."
redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class]) redirect_to polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable.class])
end end
......
...@@ -221,8 +221,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -221,8 +221,7 @@ class Projects::IssuesController < Projects::ApplicationController
def issue_params def issue_params
params.require(:issue).permit( params.require(:issue).permit(
:title, :assignee_id, :position, :description, :confidential, :weight, :title, :assignee_id, :position, :description, :confidential, :weight,
:milestone_id, :due_date, :state_event, :task_num, :lock_version, :time_estimate, :milestone_id, :due_date, :state_event, :task_num, :lock_version, label_ids: []
label_ids: [],
) )
end end
end end
...@@ -674,7 +674,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -674,7 +674,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
approvals_before_merge approvals_before_merge
approver_group_ids approver_group_ids
approver_ids approver_ids
time_estimate
] ]
end end
......
...@@ -255,6 +255,17 @@ module Issuable ...@@ -255,6 +255,17 @@ module Issuable
self.class.to_ability_name self.class.to_ability_name
end end
# Convert this Issuable class name to a format usable by notifications.
#
# Examples:
#
# issuable.class # => MergeRequest
# issuable.human_class_name # => "merge request"
def human_class_name
@human_class_name ||= self.class.name.titleize.downcase
end
# Returns a Hash of attributes to be used for Twitter card metadata # Returns a Hash of attributes to be used for Twitter card metadata
def card_attributes def card_attributes
{ {
...@@ -307,4 +318,8 @@ module Issuable ...@@ -307,4 +318,8 @@ module Issuable
def time_spent def time_spent
timelogs.sum(:time_spent) timelogs.sum(:time_spent)
end end
def spend_time(seconds)
timelogs.new(time_spent: seconds)
end
end end
class Timelog < ActiveRecord::Base class Timelog < ActiveRecord::Base
validates :time_spent, :trackable, presence: true validates :time_spent, presence: true
belongs_to :trackable, polymorphic: true belongs_to :trackable, polymorphic: true
end end
...@@ -37,8 +37,7 @@ class IssuableBaseService < BaseService ...@@ -37,8 +37,7 @@ class IssuableBaseService < BaseService
end end
def create_time_estimate_note(issuable) def create_time_estimate_note(issuable)
SystemNoteService.change_time_estimate( SystemNoteService.change_time_estimate(issuable, issuable.project, current_user)
issuable, issuable.project, current_user, issuable.time_estimate)
end end
def create_time_spent_note(issuable, time_spent) def create_time_spent_note(issuable, time_spent)
...@@ -147,6 +146,7 @@ class IssuableBaseService < BaseService ...@@ -147,6 +146,7 @@ class IssuableBaseService < BaseService
def create(issuable) def create(issuable)
merge_slash_commands_into_params!(issuable) merge_slash_commands_into_params!(issuable)
filter_params filter_params
change_spent_time(issuable)
params.delete(:state_event) params.delete(:state_event)
params[:author] ||= current_user params[:author] ||= current_user
...@@ -241,7 +241,7 @@ class IssuableBaseService < BaseService ...@@ -241,7 +241,7 @@ class IssuableBaseService < BaseService
def change_spent_time(issuable) def change_spent_time(issuable)
if time_spent if time_spent
issuable.timelogs.new(time_spent: time_spent) issuable.spend_time(time_spent)
end end
end end
......
...@@ -248,25 +248,24 @@ module SlashCommands ...@@ -248,25 +248,24 @@ module SlashCommands
params '@user' params '@user'
command :cc command :cc
desc 'Set estimate' desc 'Set time estimate'
params 'e.g: 1w 3d 2h 14m' params '<1w 3d 2h 14m>'
condition do condition do
current_user.can?(:"update_#{issuable.to_ability_name}", project) current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end end
command :estimate do |raw_duration| command :estimate do |raw_duration|
@updates[:time_estimate] = ChronicDuration.parse(raw_duration, default_unit: 'hours') @updates[:time_estimate] = ChronicDuration.parse(raw_duration, default_unit: 'hours')
end end
desc 'Enter current spent time' desc 'Enter current spent time'
params 'e.g: 3h 30m' params '<1h 30m>'
condition do condition do
issuable.persisted? && current_user.can?(:"admin_#{issuable.to_ability_name}", issuable)
current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end end
command :spend do |raw_duration| command :spend do |raw_duration|
reduce_time = raw_duration.gsub!(/\A-/, '') reduce_time = raw_duration.sub!(/\A-/, '')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours') time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours')
time_spent = time_spent * -1 if reduce_time time_spent *= -1 if reduce_time
@updates[:time_spent] = time_spent @updates[:time_spent] = time_spent
end end
......
...@@ -124,9 +124,9 @@ module SystemNoteService ...@@ -124,9 +124,9 @@ module SystemNoteService
# #
# Returns the created Note object # Returns the created Note object
def change_time_estimate(noteable, project, author, time_estimate) def change_time_estimate(noteable, project, author)
parsed_time = ChronicDuration.output(time_estimate, format: :short) parsed_time = ChronicDuration.output(noteable.time_estimate, format: :short)
body = "Changed estimate of this #{noteable.to_ability_name} to #{parsed_time}" body = "Changed time estimate of this #{noteable.human_class_name} to #{parsed_time}"
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
...@@ -145,8 +145,9 @@ module SystemNoteService ...@@ -145,8 +145,9 @@ module SystemNoteService
# Returns the created Note object # Returns the created Note object
def change_time_spent(noteable, project, author, time_spent) def change_time_spent(noteable, project, author, time_spent)
parsed_time = ChronicDuration.output(time_spent, format: :short) parsed_time = ChronicDuration.output(time_spent.abs, format: :short)
body = "Added #{parsed_time} of time spent on this #{noteable.to_ability_name}" action = time_spent > 0 ? 'Added' : 'Substracted'
body = "#{action} #{parsed_time} of time spent on this #{noteable.human_class_name}"
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
......
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
- else - else
.pull-right .pull-right
- if can?(current_user, :"destroy_#{issuable.to_ability_name}", @project) - if can?(current_user, :"destroy_#{issuable.to_ability_name}", @project)
= link_to 'Delete', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), data: { confirm: "#{issuable.class.name.titleize} will be removed! Are you sure?" }, = link_to 'Delete', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), data: { confirm: "#{issuable.human_class_name} will be removed! Are you sure?" },
method: :delete, class: 'btn btn-danger btn-grouped' method: :delete, class: 'btn btn-danger btn-grouped'
= link_to 'Cancel', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), class: 'btn btn-grouped btn-cancel' = link_to 'Cancel', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), class: 'btn btn-grouped btn-cancel'
......
...@@ -23,8 +23,13 @@ class AddEstimateToIssuables < ActiveRecord::Migration ...@@ -23,8 +23,13 @@ class AddEstimateToIssuables < ActiveRecord::Migration
# comments: # comments:
# disable_ddl_transaction! # disable_ddl_transaction!
def change def up
add_column_with_default :issues, :time_estimate, :integer, default: 0 add_column_with_default :issues, :time_estimate, :integer, default: 0
add_column_with_default :merge_requests, :time_estimate, :integer, default: 0 add_column_with_default :merge_requests, :time_estimate, :integer, default: 0
end end
def down
remove_column :issues, :time_estimate
remove_column :merge_requests, :time_estimate
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment