summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Kolb <kolbyjack@gmail.com>2019-06-11 17:48:42 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-06-25 09:31:23 +0800
commit4e283ee706b11fd3b918230976addc9a70603ce6 (patch)
tree17c39d55c76ce24380f4805c733c823b63222d85
parentdb9783f7826ed5ba58a8941dd80a1cd7dda517b0 (diff)
downloadgitlab-ce-4e283ee706b11fd3b918230976addc9a70603ce6.tar.gz
Limit time tracking values to hours
Adds an instance setting to limit display of time tracking values to hours only
-rw-r--r--app/assets/javascripts/boards/components/issue_time_estimate.vue9
-rw-r--r--app/assets/javascripts/lib/utils/datetime_utility.js9
-rw-r--r--app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.vue2
-rw-r--r--app/helpers/application_settings_helper.rb1
-rw-r--r--app/models/application_setting_implementation.rb1
-rw-r--r--app/views/admin/application_settings/_localization.html.haml6
-rw-r--r--changelogs/unreleased/30355-use-hours-only-for-time-tracking.yml5
-rw-r--r--db/migrate/20190611090827_add_time_tracking_display_hours_only_to_application_settings.rb21
-rw-r--r--db/schema.rb1
-rw-r--r--doc/api/settings.md1
-rw-r--r--lib/gitlab/gon_helper.rb2
-rw-r--r--lib/gitlab/time_tracking_formatter.rb3
12 files changed, 56 insertions, 5 deletions
diff --git a/app/assets/javascripts/boards/components/issue_time_estimate.vue b/app/assets/javascripts/boards/components/issue_time_estimate.vue
index 98c1d29db16..2545980163f 100644
--- a/app/assets/javascripts/boards/components/issue_time_estimate.vue
+++ b/app/assets/javascripts/boards/components/issue_time_estimate.vue
@@ -16,10 +16,15 @@ export default {
},
computed: {
title() {
- return stringifyTime(parseSeconds(this.estimate), true);
+ return stringifyTime(
+ parseSeconds(this.estimate, { limitToHours: gon.time_tracking_display_hours_only }),
+ true
+ );
},
timeEstimate() {
- return stringifyTime(parseSeconds(this.estimate));
+ return stringifyTime(
+ parseSeconds(this.estimate, { limitToHours: gon.time_tracking_display_hours_only })
+ );
},
},
};
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js
index d521c462ad8..f8398f2f780 100644
--- a/app/assets/javascripts/lib/utils/datetime_utility.js
+++ b/app/assets/javascripts/lib/utils/datetime_utility.js
@@ -479,7 +479,10 @@ export const pikadayToString = date => {
* Seconds can be negative or positive, zero or non-zero. Can be configured for any day
* or week length.
*/
-export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {}) => {
+export const parseSeconds = (
+ seconds,
+ { daysPerWeek = 5, hoursPerDay = 8, limitToHours = false } = {},
+) => {
const DAYS_PER_WEEK = daysPerWeek;
const HOURS_PER_DAY = hoursPerDay;
const MINUTES_PER_HOUR = 60;
@@ -496,6 +499,10 @@ export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {})
let unorderedMinutes = Math.abs(seconds / MINUTES_PER_HOUR);
return _.mapObject(timePeriodConstraints, minutesPerPeriod => {
+ if (limitToHours && minutesPerPeriod > MINUTES_PER_HOUR) {
+ return 0;
+ }
+
const periodCount = Math.floor(unorderedMinutes / minutesPerPeriod);
unorderedMinutes -= periodCount * minutesPerPeriod;
diff --git a/app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.vue b/app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.vue
index f4d926cd3ec..cd3e7ce33f7 100644
--- a/app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.vue
+++ b/app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.vue
@@ -32,7 +32,7 @@ export default {
computed: {
parsedTimeRemaining() {
const diffSeconds = this.timeEstimate - this.timeSpent;
- return parseSeconds(diffSeconds);
+ return parseSeconds(diffSeconds, { limitToHours: gon.time_tracking_display_hours_only });
},
timeRemainingHumanReadable() {
return stringifyTime(this.parsedTimeRemaining);
diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb
index 4469118f065..596ac1c4c1e 100644
--- a/app/helpers/application_settings_helper.rb
+++ b/app/helpers/application_settings_helper.rb
@@ -253,6 +253,7 @@ module ApplicationSettingsHelper
:throttle_unauthenticated_enabled,
:throttle_unauthenticated_period_in_seconds,
:throttle_unauthenticated_requests_per_period,
+ :time_tracking_display_hours_only,
:two_factor_grace_period,
:unique_ips_limit_enabled,
:unique_ips_limit_per_user,
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb
index 904d650ef96..7b5bf5ad5cf 100644
--- a/app/models/application_setting_implementation.rb
+++ b/app/models/application_setting_implementation.rb
@@ -82,6 +82,7 @@ module ApplicationSettingImplementation
throttle_unauthenticated_enabled: false,
throttle_unauthenticated_period_in_seconds: 3600,
throttle_unauthenticated_requests_per_period: 3600,
+ time_tracking_display_hours_only: false,
two_factor_grace_period: 48,
unique_ips_limit_enabled: false,
unique_ips_limit_per_user: 10,
diff --git a/app/views/admin/application_settings/_localization.html.haml b/app/views/admin/application_settings/_localization.html.haml
index bb4d1fa1241..8f09d42a053 100644
--- a/app/views/admin/application_settings/_localization.html.haml
+++ b/app/views/admin/application_settings/_localization.html.haml
@@ -8,4 +8,10 @@
.form-text.text-muted
= _('Default first day of the week in calendars and date pickers.')
+ .form-group
+ .form-check
+ = f.check_box :time_tracking_display_hours_only, class: 'form-check-input'
+ = f.label :time_tracking_display_hours_only, class: 'form-check-label' do
+ _('Limit time tracking display to hours.')
+
= f.submit _('Save changes'), class: "btn btn-success"
diff --git a/changelogs/unreleased/30355-use-hours-only-for-time-tracking.yml b/changelogs/unreleased/30355-use-hours-only-for-time-tracking.yml
new file mode 100644
index 00000000000..afc548472aa
--- /dev/null
+++ b/changelogs/unreleased/30355-use-hours-only-for-time-tracking.yml
@@ -0,0 +1,5 @@
+---
+title: Add option to show time tracking values in hours only
+merge_request: 29469
+author: Jon Kolb
+type: added
diff --git a/db/migrate/20190611090827_add_time_tracking_display_hours_only_to_application_settings.rb b/db/migrate/20190611090827_add_time_tracking_display_hours_only_to_application_settings.rb
new file mode 100644
index 00000000000..f4daf0d1863
--- /dev/null
+++ b/db/migrate/20190611090827_add_time_tracking_display_hours_only_to_application_settings.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddTimeTrackingDisplayHoursOnlyToApplicationSettings < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_column_with_default :application_settings, :time_tracking_display_hours_only, :boolean, default: false, allow_null: false
+ end
+
+ def down
+ remove_column :application_settings, :time_tracking_display_hours_only
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b81558178b9..d39833f9755 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -229,6 +229,7 @@ ActiveRecord::Schema.define(version: 20190620112608) do
t.integer "custom_project_templates_group_id"
t.boolean "elasticsearch_limit_indexing", default: false, null: false
t.string "geo_node_allowed_ips", default: "0.0.0.0/0, ::/0"
+ t.boolean "time_tracking_display_hours_only", default: false, null: false
t.index ["custom_project_templates_group_id"], name: "index_application_settings_on_custom_project_templates_group_id", using: :btree
t.index ["file_template_project_id"], name: "index_application_settings_on_file_template_project_id", using: :btree
t.index ["usage_stats_set_by_user_id"], name: "index_application_settings_on_usage_stats_set_by_user_id", using: :btree
diff --git a/doc/api/settings.md b/doc/api/settings.md
index c2a1f7feefd..7363b43393f 100644
--- a/doc/api/settings.md
+++ b/doc/api/settings.md
@@ -231,6 +231,7 @@ are listed in the descriptions of the relevant settings.
| `throttle_unauthenticated_enabled` | boolean | no | (**If enabled, requires:** `throttle_unauthenticated_period_in_seconds` and `throttle_unauthenticated_requests_per_period`) Enable unauthenticated request rate limit. Helps reduce request volume (e.g. from crawlers or abusive bots). |
| `throttle_unauthenticated_period_in_seconds` | integer | required by: `throttle_unauthenticated_enabled` | Rate limit period in seconds. |
| `throttle_unauthenticated_requests_per_period` | integer | required by: `throttle_unauthenticated_enabled` | Max requests per period per IP. |
+| `time_tracking_display_hours_only` | boolean | no | Limit time tracking values to hours only. Default is `false`. |
| `two_factor_grace_period` | integer | required by: `require_two_factor_authentication` | Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication. |
| `unique_ips_limit_enabled` | boolean | no | (**If enabled, requires:** `unique_ips_limit_per_user` and `unique_ips_limit_time_window`) Limit sign in from multiple ips. |
| `unique_ips_limit_per_user` | integer | required by: `unique_ips_limit_enabled` | Maximum number of ips per user. |
diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb
index 582c3065189..ca2e4e5f001 100644
--- a/lib/gitlab/gon_helper.rb
+++ b/lib/gitlab/gon_helper.rb
@@ -32,6 +32,8 @@ module Gitlab
gon.first_day_of_week = current_user&.first_day_of_week || Gitlab::CurrentSettings.first_day_of_week
gon.ee = Gitlab.ee?
+ gon.time_tracking_display_hours_only = Gitlab::CurrentSettings.time_tracking_display_hours_only
+
if current_user
gon.current_user_id = current_user.id
gon.current_username = current_user.username
diff --git a/lib/gitlab/time_tracking_formatter.rb b/lib/gitlab/time_tracking_formatter.rb
index cc206010e74..a63fe51eb97 100644
--- a/lib/gitlab/time_tracking_formatter.rb
+++ b/lib/gitlab/time_tracking_formatter.rb
@@ -16,7 +16,8 @@ module Gitlab
def output(seconds)
with_custom_config do
- ChronicDuration.output(seconds, format: :short, limit_to_hours: false, weeks: true) rescue nil
+ limit_to_hours = Gitlab::CurrentSettings.time_tracking_display_hours_only
+ ChronicDuration.output(seconds, format: :short, limit_to_hours: limit_to_hours, weeks: true) rescue nil
end
end