From 27f7771ae1a4b5f9d973a55ccbbbe30b0e05f100 Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Tue, 6 Nov 2018 22:16:49 +0100 Subject: Add setting for first day of the week --- app/assets/javascripts/due_date_select.js | 2 ++ app/assets/javascripts/issuable_form.js | 1 + app/assets/javascripts/member_expiration_date.js | 1 + .../javascripts/pages/projects/graphs/charts/index.js | 18 +++++++++++++++++- .../javascripts/pages/users/activity_calendar.js | 10 +++++++++- app/assets/javascripts/pages/users/user_tabs.js | 2 +- .../javascripts/vue_shared/components/pikaday.vue | 1 + app/controllers/profiles/preferences_controller.rb | 2 +- app/helpers/application_settings_helper.rb | 1 + app/helpers/preferences_helper.rb | 7 +++++++ app/models/application_setting.rb | 1 + app/models/user.rb | 3 +++ .../admin/application_settings/_localization.html.haml | 11 +++++++++++ .../admin/application_settings/preferences.html.haml | 11 +++++++++++ app/views/profiles/preferences/show.html.haml | 18 ++++++++++++++++++ .../2105-add-setting-for-first-day-of-the-week.yml | 5 +++++ ...114222_add_first_day_of_week_to_user_preferences.rb | 9 +++++++++ ...efault_first_day_of_week_to_application_settings.rb | 16 ++++++++++++++++ db/schema.rb | 2 ++ doc/user/profile/preferences.md | 8 ++++++++ lib/gitlab/gon_helper.rb | 2 ++ locale/gitlab.pot | 15 +++++++++++++++ .../profiles/preferences_controller_spec.rb | 3 ++- 23 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 app/views/admin/application_settings/_localization.html.haml create mode 100644 changelogs/unreleased/2105-add-setting-for-first-day-of-the-week.yml create mode 100644 db/migrate/20181027114222_add_first_day_of_week_to_user_preferences.rb create mode 100644 db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb diff --git a/app/assets/javascripts/due_date_select.js b/app/assets/javascripts/due_date_select.js index dbfcf8cc921..cb1b1173190 100644 --- a/app/assets/javascripts/due_date_select.js +++ b/app/assets/javascripts/due_date_select.js @@ -64,6 +64,7 @@ class DueDateSelect { this.saveDueDate(true); } }, + firstDay: gon.first_day_of_week, }); calendar.setDate(parsePikadayDate($dueDateInput.val())); @@ -183,6 +184,7 @@ export default class DueDateSelectors { onSelect(dateText) { $datePicker.val(calendar.toString(dateText)); }, + firstDay: gon.first_day_of_week, }); calendar.setDate(parsePikadayDate(datePickerVal)); diff --git a/app/assets/javascripts/issuable_form.js b/app/assets/javascripts/issuable_form.js index 4d2533d01f1..9336b71cfd7 100644 --- a/app/assets/javascripts/issuable_form.js +++ b/app/assets/javascripts/issuable_form.js @@ -44,6 +44,7 @@ export default class IssuableForm { parse: dateString => parsePikadayDate(dateString), toString: date => pikadayToString(date), onSelect: dateText => $issuableDueDate.val(calendar.toString(dateText)), + firstDay: gon.first_day_of_week, }); calendar.setDate(parsePikadayDate($issuableDueDate.val())); } diff --git a/app/assets/javascripts/member_expiration_date.js b/app/assets/javascripts/member_expiration_date.js index 0beedcacf33..0dabb28ea66 100644 --- a/app/assets/javascripts/member_expiration_date.js +++ b/app/assets/javascripts/member_expiration_date.js @@ -33,6 +33,7 @@ export default function memberExpirationDate(selector = '.js-access-expiration-d toggleClearInput.call($input); }, + firstDay: gon.first_day_of_week, }); calendar.setDate(parsePikadayDate($input.val())); diff --git a/app/assets/javascripts/pages/projects/graphs/charts/index.js b/app/assets/javascripts/pages/projects/graphs/charts/index.js index 3ccad513c05..26d7fa7371d 100644 --- a/app/assets/javascripts/pages/projects/graphs/charts/index.js +++ b/app/assets/javascripts/pages/projects/graphs/charts/index.js @@ -43,10 +43,26 @@ document.addEventListener('DOMContentLoaded', () => { ], }); + const reorderWeekDays = (weekDays, firstDayOfWeek = 0) => { + if (firstDayOfWeek === 0) { + return weekDays; + } + + return Object.keys(weekDays).reduce((acc, dayName, idx, arr) => { + const reorderedDayName = arr[(idx + firstDayOfWeek) % arr.length]; + + return { + ...acc, + [reorderedDayName]: weekDays[reorderedDayName], + }; + }, {}); + }; + const hourData = chartData(projectChartData.hour); responsiveChart($('#hour-chart'), hourData); - const dayData = chartData(projectChartData.weekDays); + const weekDays = reorderWeekDays(projectChartData.weekDays, gon.first_day_of_week); + const dayData = chartData(weekDays); responsiveChart($('#weekday-chart'), dayData); const monthData = chartData(projectChartData.month); diff --git a/app/assets/javascripts/pages/users/activity_calendar.js b/app/assets/javascripts/pages/users/activity_calendar.js index 8a84ac37dab..afa099d0e0b 100644 --- a/app/assets/javascripts/pages/users/activity_calendar.js +++ b/app/assets/javascripts/pages/users/activity_calendar.js @@ -159,7 +159,7 @@ export default class ActivityCalendar { .append('g') .attr('transform', (group, i) => { _.each(group, (stamp, a) => { - if (a === 0 && stamp.day === 0) { + if (a === 0 && stamp.day === this.firstDayOfWeek) { const month = stamp.date.getMonth(); const x = this.daySizeWithSpace * i + 1 + this.daySizeWithSpace; const lastMonth = _.last(this.months); @@ -205,6 +205,14 @@ export default class ActivityCalendar { y: 29 + this.dayYPos(5), }, ]; + + if (this.firstDayOfWeek === 1) { + days.push({ + text: 'S', + y: 29 + this.dayYPos(7), + }); + } + this.svg .append('g') .selectAll('text') diff --git a/app/assets/javascripts/pages/users/user_tabs.js b/app/assets/javascripts/pages/users/user_tabs.js index 1c3fd58ca74..39cd891c111 100644 --- a/app/assets/javascripts/pages/users/user_tabs.js +++ b/app/assets/javascripts/pages/users/user_tabs.js @@ -234,7 +234,7 @@ export default class UserTabs { data, calendarActivitiesPath, utcOffset, - 0, + gon.first_day_of_week, monthsAgo, ); } diff --git a/app/assets/javascripts/vue_shared/components/pikaday.vue b/app/assets/javascripts/vue_shared/components/pikaday.vue index 8bdb5bf22c2..13eb46437dd 100644 --- a/app/assets/javascripts/vue_shared/components/pikaday.vue +++ b/app/assets/javascripts/vue_shared/components/pikaday.vue @@ -40,6 +40,7 @@ export default { toString: date => pikadayToString(date), onSelect: this.selected.bind(this), onClose: this.toggled.bind(this), + firstDay: gon.first_day_of_week, }); this.$el.append(this.calendar.el); diff --git a/app/controllers/profiles/preferences_controller.rb b/app/controllers/profiles/preferences_controller.rb index a27e3cceaeb..94002095739 100644 --- a/app/controllers/profiles/preferences_controller.rb +++ b/app/controllers/profiles/preferences_controller.rb @@ -37,6 +37,6 @@ class Profiles::PreferencesController < Profiles::ApplicationController end def preferences_param_names - [:color_scheme_id, :layout, :dashboard, :project_view, :theme_id] + [:color_scheme_id, :layout, :dashboard, :project_view, :theme_id, :first_day_of_week] end end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index c8e4e2e3df9..667c5097d91 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -136,6 +136,7 @@ module ApplicationSettingsHelper :container_registry_token_expire_delay, :default_artifacts_expire_in, :default_branch_protection, + :default_first_day_of_week, :default_group_visibility, :default_project_visibility, :default_projects_limit, diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index f4f46b0fe96..301608175b2 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -43,6 +43,13 @@ module PreferencesHelper ] end + def first_day_of_week_choices + [ + ['Sunday', 0], + ['Monday', 1] + ] + end + def user_application_theme @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class end diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 88746375c67..4f9dee1720c 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -237,6 +237,7 @@ class ApplicationSetting < ActiveRecord::Base container_registry_token_expire_delay: 5, default_artifacts_expire_in: '30 days', default_branch_protection: Settings.gitlab['default_branch_protection'], + default_first_day_of_week: 0, default_group_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_projects_limit: Settings.gitlab['default_projects_limit'], diff --git a/app/models/user.rb b/app/models/user.rb index 9c091ac366c..24101eda0b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -228,6 +228,9 @@ class User < ApplicationRecord delegate :path, to: :namespace, allow_nil: true, prefix: true delegate :notes_filter_for, to: :user_preference delegate :set_notes_filter, to: :user_preference + delegate :first_day_of_week, :first_day_of_week=, to: :user_preference + + accepts_nested_attributes_for :user_preference, update_only: true state_machine :state, initial: :active do event :block do diff --git a/app/views/admin/application_settings/_localization.html.haml b/app/views/admin/application_settings/_localization.html.haml new file mode 100644 index 00000000000..87209da75fd --- /dev/null +++ b/app/views/admin/application_settings/_localization.html.haml @@ -0,0 +1,11 @@ += form_for @application_setting, url: admin_application_settings_path(anchor: 'js-localization-settings'), html: { class: 'fieldset-form' } do |f| + = form_errors(@application_setting) + + %fieldset + .form-group + = f.label :default_first_day_of_week, _('Default first day of the week'), class: 'label-bold' + = f.select :default_first_day_of_week, options_for_select({_('Sunday') => 0, _('Monday') => 1}, @application_setting.default_first_day_of_week), {}, class: 'form-control' + .form-text.text-muted + Default first day of the week in calendars and date pickers. + + = f.submit 'Save changes', class: "btn btn-success" diff --git a/app/views/admin/application_settings/preferences.html.haml b/app/views/admin/application_settings/preferences.html.haml index 00000b86ab7..c468d69d7b8 100644 --- a/app/views/admin/application_settings/preferences.html.haml +++ b/app/views/admin/application_settings/preferences.html.haml @@ -56,3 +56,14 @@ = _('Configure Gitaly timeouts.') .settings-content = render 'gitaly' + +%section.settings.as-localization.no-animate#js-localization-settings{ class: ('expanded' if expanded_by_default?) } + .settings-header + %h4 + = _('Localization') + %button.btn.btn-default.js-settings-toggle{ type: 'button' } + = expanded_by_default? ? _('Collapse') : _('Expand') + %p + = _('Various localization settings.') + .settings-content + = render 'localization' diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index c1616810185..5e1c1f30ca4 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -60,5 +60,23 @@ = f.select :project_view, project_view_choices, {}, class: 'form-control' .form-text.text-muted Choose what content you want to see on a project’s overview page. + + .col-sm-12 + %hr + + .col-lg-4.profile-settings-sidebar + %h4.prepend-top-0 + Localization + %p + Customize language and region related settings. + = succeed '.' do + = link_to 'Learn more', help_page_path('user/profile/preferences', anchor: 'localization'), target: '_blank' + .col-lg-8 + .form-group + = f.label :first_day_of_week, class: 'label-bold' do + First day of the week + = f.select :first_day_of_week, options_for_select(first_day_of_week_choices, @user.first_day_of_week || Gitlab::CurrentSettings.default_first_day_of_week), {}, class: 'form-control' + .form-text.text-muted + Choose on what day the week should start. .form-group = f.submit 'Save changes', class: 'btn btn-success' diff --git a/changelogs/unreleased/2105-add-setting-for-first-day-of-the-week.yml b/changelogs/unreleased/2105-add-setting-for-first-day-of-the-week.yml new file mode 100644 index 00000000000..f4a52b1aacd --- /dev/null +++ b/changelogs/unreleased/2105-add-setting-for-first-day-of-the-week.yml @@ -0,0 +1,5 @@ +--- +title: Add setting for first day of the week +merge_request: 22755 +author: Fabian Schneider @fabsrc +type: added diff --git a/db/migrate/20181027114222_add_first_day_of_week_to_user_preferences.rb b/db/migrate/20181027114222_add_first_day_of_week_to_user_preferences.rb new file mode 100644 index 00000000000..a0e76c2186e --- /dev/null +++ b/db/migrate/20181027114222_add_first_day_of_week_to_user_preferences.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddFirstDayOfWeekToUserPreferences < ActiveRecord::Migration + DOWNTIME = false + + def change + add_column :user_preferences, :first_day_of_week, :integer + end +end diff --git a/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb b/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb new file mode 100644 index 00000000000..110a48d4d35 --- /dev/null +++ b/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddDefaultFirstDayOfWeekToApplicationSettings < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default(:application_settings, :default_first_day_of_week, :integer, default: 0) + end + + def down + remove_column(:application_settings, :default_first_day_of_week) + end +end diff --git a/db/schema.rb b/db/schema.rb index 20c8dab4c3e..aef0f234a72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -168,6 +168,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do t.string "commit_email_hostname" t.boolean "protected_ci_variables", default: false, null: false t.string "runners_registration_token_encrypted" + t.integer "default_first_day_of_week", default: 0, null: false t.index ["usage_stats_set_by_user_id"], name: "index_application_settings_on_usage_stats_set_by_user_id", using: :btree end @@ -2153,6 +2154,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do t.integer "merge_request_notes_filter", limit: 2, default: 0, null: false t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "updated_at", null: false + t.integer "first_day_of_week" t.string "issues_sort" t.string "merge_requests_sort" t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index eb2d731343e..c14dbe586c4 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -87,3 +87,11 @@ You can choose between 3 options: - Files and Readme (default) - Readme - Activity + +## Localization + +This following setting allows you to customize calendar layouts. + +### First day of the week + +You can choose between **Sunday** and **Monday** for the first day of the week. This will be used for all calendar views and datepickers. diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index 9b1794eec91..f0af5329d76 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -24,12 +24,14 @@ module Gitlab gon.emoji_sprites_css_path = ActionController::Base.helpers.stylesheet_path('emoji_sprites') gon.test_env = Rails.env.test? gon.suggested_label_colors = LabelsHelper.suggested_colors + gon.first_day_of_week = Gitlab::CurrentSettings.default_first_day_of_week if current_user gon.current_user_id = current_user.id gon.current_username = current_user.username gon.current_user_fullname = current_user.name gon.current_user_avatar_url = current_user.avatar_url + gon.first_day_of_week = current_user.first_day_of_week if current_user.first_day_of_week end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 9ec590f90d8..f9ce6ebb79e 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -2507,6 +2507,9 @@ msgstr "" msgid "Default Branch" msgstr "" +msgid "Default first day of the week" +msgstr "" + msgid "Default: Directly import the Google Code email address or username" msgstr "" @@ -4297,6 +4300,9 @@ msgstr "" msgid "Loading…" msgstr "" +msgid "Localization" +msgstr "" + msgid "Lock" msgstr "" @@ -4615,6 +4621,9 @@ msgstr "" msgid "Modal|Close" msgstr "" +msgid "Monday" +msgstr "" + msgid "Monitor your errors by integrating with Sentry" msgstr "" @@ -6926,6 +6935,9 @@ msgstr "" msgid "Suggested change" msgstr "" +msgid "Sunday" +msgstr "" + msgid "Support for custom certificates is disabled. Ask your system's administrator to enable it." msgstr "" @@ -7977,6 +7989,9 @@ msgstr "" msgid "Various email settings." msgstr "" +msgid "Various localization settings." +msgstr "" + msgid "Various settings that affect GitLab performance." msgstr "" diff --git a/spec/controllers/profiles/preferences_controller_spec.rb b/spec/controllers/profiles/preferences_controller_spec.rb index 012f016b091..760c0fab130 100644 --- a/spec/controllers/profiles/preferences_controller_spec.rb +++ b/spec/controllers/profiles/preferences_controller_spec.rb @@ -42,7 +42,8 @@ describe Profiles::PreferencesController do prefs = { color_scheme_id: '1', dashboard: 'stars', - theme_id: '2' + theme_id: '2', + first_day_of_week: '1' }.with_indifferent_access expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!) -- cgit v1.2.1 From 5402f3c360eaa668782d53cdf04fcc1cb0a400ec Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Thu, 8 Nov 2018 17:49:54 +0100 Subject: Add default setting for first day of the week preference --- app/helpers/preferences_helper.rb | 5 +++++ app/views/profiles/preferences/show.html.haml | 2 +- doc/user/profile/preferences.md | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 301608175b2..3371592a36a 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -43,8 +43,13 @@ module PreferencesHelper ] end + def default_first_day_of_week + Date::DAYNAMES[Gitlab::CurrentSettings.default_first_day_of_week] + end + def first_day_of_week_choices [ + ["System Default (#{default_first_day_of_week})", nil], ['Sunday', 0], ['Monday', 1] ] diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index 5e1c1f30ca4..bed9aa05224 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -75,7 +75,7 @@ .form-group = f.label :first_day_of_week, class: 'label-bold' do First day of the week - = f.select :first_day_of_week, options_for_select(first_day_of_week_choices, @user.first_day_of_week || Gitlab::CurrentSettings.default_first_day_of_week), {}, class: 'form-control' + = f.select :first_day_of_week, first_day_of_week_choices, {}, class: 'form-control' .form-text.text-muted Choose on what day the week should start. .form-group diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index c14dbe586c4..925bbc84d85 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -94,4 +94,5 @@ This following setting allows you to customize calendar layouts. ### First day of the week -You can choose between **Sunday** and **Monday** for the first day of the week. This will be used for all calendar views and datepickers. +You can choose between **Default**, **Sunday** and **Monday** for the first day of the week. If you select **Default**, the system-wide default setting will be used. +This preference will be used for all calendar views and datepickers. -- cgit v1.2.1 From 8fabc92e8b4779030c4fa09d8e1c72f213814787 Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Tue, 13 Nov 2018 19:38:26 +0100 Subject: Add helpers for first day of the week --- app/helpers/preferences_helper.rb | 17 ++++++++++------- .../admin/application_settings/_localization.html.haml | 6 +++--- app/views/profiles/preferences/show.html.haml | 14 +++++++------- doc/user/profile/preferences.md | 2 +- locale/gitlab.pot | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 3371592a36a..0faa28581cc 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -43,18 +43,21 @@ module PreferencesHelper ] end - def default_first_day_of_week - Date::DAYNAMES[Gitlab::CurrentSettings.default_first_day_of_week] - end - def first_day_of_week_choices [ - ["System Default (#{default_first_day_of_week})", nil], - ['Sunday', 0], - ['Monday', 1] + [_('Sunday'), 0], + [_('Monday'), 1] ] end + def default_first_day_of_week + first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.default_first_day_of_week).first + end + + def first_day_of_week_choices_with_default + first_day_of_week_choices.unshift([_('System Default (%{default})') % { default: default_first_day_of_week }, nil]) + end + def user_application_theme @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class end diff --git a/app/views/admin/application_settings/_localization.html.haml b/app/views/admin/application_settings/_localization.html.haml index 87209da75fd..7392b32ee89 100644 --- a/app/views/admin/application_settings/_localization.html.haml +++ b/app/views/admin/application_settings/_localization.html.haml @@ -4,8 +4,8 @@ %fieldset .form-group = f.label :default_first_day_of_week, _('Default first day of the week'), class: 'label-bold' - = f.select :default_first_day_of_week, options_for_select({_('Sunday') => 0, _('Monday') => 1}, @application_setting.default_first_day_of_week), {}, class: 'form-control' + = f.select :default_first_day_of_week, first_day_of_week_choices, {}, class: 'form-control' .form-text.text-muted - Default first day of the week in calendars and date pickers. + = _('Default first day of the week in calendars and date pickers.') - = f.submit 'Save changes', class: "btn btn-success" + = f.submit _('Save changes'), class: "btn btn-success" diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index bed9aa05224..e290ba89684 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -66,17 +66,17 @@ .col-lg-4.profile-settings-sidebar %h4.prepend-top-0 - Localization + = _('Localization') %p - Customize language and region related settings. + = _('Customize language and region related settings.') = succeed '.' do - = link_to 'Learn more', help_page_path('user/profile/preferences', anchor: 'localization'), target: '_blank' + = link_to _('Learn more'), help_page_path('user/profile/preferences', anchor: 'localization'), target: '_blank' .col-lg-8 .form-group = f.label :first_day_of_week, class: 'label-bold' do - First day of the week - = f.select :first_day_of_week, first_day_of_week_choices, {}, class: 'form-control' + = _('First day of the week') + = f.select :first_day_of_week, first_day_of_week_choices_with_default, {}, class: 'form-control' .form-text.text-muted - Choose on what day the week should start. + = _('Choose on what day the week should start.') .form-group - = f.submit 'Save changes', class: 'btn btn-success' + = f.submit _('Save changes'), class: 'btn btn-success' diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index 925bbc84d85..6b8b5cf4d5e 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -94,5 +94,5 @@ This following setting allows you to customize calendar layouts. ### First day of the week -You can choose between **Default**, **Sunday** and **Monday** for the first day of the week. If you select **Default**, the system-wide default setting will be used. +You can choose between **System Default**, **Sunday** and **Monday** for the first day of the week. If you select **System Default**, the system-wide default setting will be used. This preference will be used for all calendar views and datepickers. diff --git a/locale/gitlab.pot b/locale/gitlab.pot index f9ce6ebb79e..26d64e908b7 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -1413,6 +1413,9 @@ msgstr "" msgid "Choose file..." msgstr "" +msgid "Choose on what day the week should start." +msgstr "" + msgid "Choose the top-level group for your repository imports." msgstr "" @@ -2444,6 +2447,9 @@ msgstr "" msgid "Customize how Google Code email addresses and usernames are imported into GitLab. In the next step, you'll be able to select the projects you want to import." msgstr "" +msgid "Customize language and region related settings." +msgstr "" + msgid "Customize your pipeline configuration, view your pipeline status and coverage report." msgstr "" @@ -2510,6 +2516,9 @@ msgstr "" msgid "Default first day of the week" msgstr "" +msgid "Default first day of the week in calendars and date pickers." +msgstr "" + msgid "Default: Directly import the Google Code email address or username" msgstr "" @@ -3358,6 +3367,9 @@ msgstr "" msgid "Finished" msgstr "" +msgid "First day of the week" +msgstr "" + msgid "FirstPushedBy|First" msgstr "" @@ -6944,6 +6956,9 @@ msgstr "" msgid "Switch branch/tag" msgstr "" +msgid "System Default (%{default})" +msgstr "" + msgid "System Hooks" msgstr "" -- cgit v1.2.1 From 864ce6b87ad610ac0bace900bb7e9ebcc0d63983 Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Thu, 10 Jan 2019 22:06:42 +0100 Subject: Rename setting, fix wordings --- app/helpers/application_settings_helper.rb | 2 +- app/helpers/preferences_helper.rb | 4 ++-- app/models/application_setting.rb | 2 +- .../admin/application_settings/_localization.html.haml | 4 ++-- app/views/profiles/preferences/show.html.haml | 2 -- ..._default_first_day_of_week_to_application_settings.rb | 16 ---------------- ...0717_add_first_day_of_week_to_application_settings.rb | 16 ++++++++++++++++ db/schema.rb | 2 +- doc/user/profile/preferences.md | 4 +--- lib/gitlab/gon_helper.rb | 3 +-- locale/gitlab.pot | 9 +++------ 11 files changed, 28 insertions(+), 36 deletions(-) delete mode 100644 db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb create mode 100644 db/migrate/20181028120717_add_first_day_of_week_to_application_settings.rb diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 667c5097d91..67d16306525 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -136,7 +136,6 @@ module ApplicationSettingsHelper :container_registry_token_expire_delay, :default_artifacts_expire_in, :default_branch_protection, - :default_first_day_of_week, :default_group_visibility, :default_project_visibility, :default_projects_limit, @@ -151,6 +150,7 @@ module ApplicationSettingsHelper :email_author_in_body, :enabled_git_access_protocol, :enforce_terms, + :first_day_of_week, :gitaly_timeout_default, :gitaly_timeout_medium, :gitaly_timeout_fast, diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 0faa28581cc..f1513f4f680 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -51,11 +51,11 @@ module PreferencesHelper end def default_first_day_of_week - first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.default_first_day_of_week).first + first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first end def first_day_of_week_choices_with_default - first_day_of_week_choices.unshift([_('System Default (%{default})') % { default: default_first_day_of_week }, nil]) + first_day_of_week_choices.unshift([_('System default (%{default})') % { default: default_first_day_of_week }, nil]) end def user_application_theme diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 4f9dee1720c..6d7c51c2315 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -237,7 +237,6 @@ class ApplicationSetting < ActiveRecord::Base container_registry_token_expire_delay: 5, default_artifacts_expire_in: '30 days', default_branch_protection: Settings.gitlab['default_branch_protection'], - default_first_day_of_week: 0, default_group_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_projects_limit: Settings.gitlab['default_projects_limit'], @@ -247,6 +246,7 @@ class ApplicationSetting < ActiveRecord::Base dsa_key_restriction: 0, ecdsa_key_restriction: 0, ed25519_key_restriction: 0, + first_day_of_week: 0, gitaly_timeout_default: 55, gitaly_timeout_fast: 10, gitaly_timeout_medium: 30, diff --git a/app/views/admin/application_settings/_localization.html.haml b/app/views/admin/application_settings/_localization.html.haml index 7392b32ee89..95d016a94a5 100644 --- a/app/views/admin/application_settings/_localization.html.haml +++ b/app/views/admin/application_settings/_localization.html.haml @@ -3,8 +3,8 @@ %fieldset .form-group - = f.label :default_first_day_of_week, _('Default first day of the week'), class: 'label-bold' - = f.select :default_first_day_of_week, first_day_of_week_choices, {}, class: 'form-control' + = f.label :first_day_of_week, _('Default first day of the week'), class: 'label-bold' + = f.select :first_day_of_week, first_day_of_week_choices, {}, class: 'form-control' .form-text.text-muted = _('Default first day of the week in calendars and date pickers.') diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index e290ba89684..1a9aca1f6bf 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -76,7 +76,5 @@ = f.label :first_day_of_week, class: 'label-bold' do = _('First day of the week') = f.select :first_day_of_week, first_day_of_week_choices_with_default, {}, class: 'form-control' - .form-text.text-muted - = _('Choose on what day the week should start.') .form-group = f.submit _('Save changes'), class: 'btn btn-success' diff --git a/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb b/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb deleted file mode 100644 index 110a48d4d35..00000000000 --- a/db/migrate/20181028120717_add_default_first_day_of_week_to_application_settings.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class AddDefaultFirstDayOfWeekToApplicationSettings < ActiveRecord::Migration - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - DOWNTIME = false - - def up - add_column_with_default(:application_settings, :default_first_day_of_week, :integer, default: 0) - end - - def down - remove_column(:application_settings, :default_first_day_of_week) - end -end diff --git a/db/migrate/20181028120717_add_first_day_of_week_to_application_settings.rb b/db/migrate/20181028120717_add_first_day_of_week_to_application_settings.rb new file mode 100644 index 00000000000..53cfaa289f6 --- /dev/null +++ b/db/migrate/20181028120717_add_first_day_of_week_to_application_settings.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddFirstDayOfWeekToApplicationSettings < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default(:application_settings, :first_day_of_week, :integer, default: 0) + end + + def down + remove_column(:application_settings, :first_day_of_week) + end +end diff --git a/db/schema.rb b/db/schema.rb index aef0f234a72..ffdc937ab52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -168,7 +168,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do t.string "commit_email_hostname" t.boolean "protected_ci_variables", default: false, null: false t.string "runners_registration_token_encrypted" - t.integer "default_first_day_of_week", default: 0, null: false + t.integer "first_day_of_week", default: 0, null: false t.index ["usage_stats_set_by_user_id"], name: "index_application_settings_on_usage_stats_set_by_user_id", using: :btree end diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index 6b8b5cf4d5e..c8f4e9bf1f3 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -90,9 +90,7 @@ You can choose between 3 options: ## Localization -This following setting allows you to customize calendar layouts. - ### First day of the week You can choose between **System Default**, **Sunday** and **Monday** for the first day of the week. If you select **System Default**, the system-wide default setting will be used. -This preference will be used for all calendar views and datepickers. +This preference will be used for all calendar views and date pickers. diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index f0af5329d76..3235d3ccc4e 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -24,14 +24,13 @@ module Gitlab gon.emoji_sprites_css_path = ActionController::Base.helpers.stylesheet_path('emoji_sprites') gon.test_env = Rails.env.test? gon.suggested_label_colors = LabelsHelper.suggested_colors - gon.first_day_of_week = Gitlab::CurrentSettings.default_first_day_of_week + gon.first_day_of_week = current_user&.first_day_of_week || Gitlab::CurrentSettings.first_day_of_week if current_user gon.current_user_id = current_user.id gon.current_username = current_user.username gon.current_user_fullname = current_user.name gon.current_user_avatar_url = current_user.avatar_url - gon.first_day_of_week = current_user.first_day_of_week if current_user.first_day_of_week end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 26d64e908b7..9e7cc8900c8 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -1413,9 +1413,6 @@ msgstr "" msgid "Choose file..." msgstr "" -msgid "Choose on what day the week should start." -msgstr "" - msgid "Choose the top-level group for your repository imports." msgstr "" @@ -6956,15 +6953,15 @@ msgstr "" msgid "Switch branch/tag" msgstr "" -msgid "System Default (%{default})" -msgstr "" - msgid "System Hooks" msgstr "" msgid "System Info" msgstr "" +msgid "System default (%{default})" +msgstr "" + msgid "System metrics (Custom)" msgstr "" -- cgit v1.2.1 From 15da40db553a6e7fd20d76d68bb07d895dfbfb85 Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Wed, 6 Feb 2019 17:44:46 +0100 Subject: Add 'first_day_of_week' to API settings docs --- doc/api/settings.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/settings.md b/doc/api/settings.md index c329e3cdf24..0f5371b5244 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -57,6 +57,7 @@ Example response: "dsa_key_restriction": 0, "ecdsa_key_restriction": 0, "ed25519_key_restriction": 0, + "first_day_of_week": 0, "enforce_terms": true, "terms": "Hello world!", "performance_bar_allowed_group_id": 42, @@ -113,6 +114,7 @@ Example response: "dsa_key_restriction": 0, "ecdsa_key_restriction": 0, "ed25519_key_restriction": 0, + "first_day_of_week": 0, "enforce_terms": true, "terms": "Hello world!", "performance_bar_allowed_group_id": 42, @@ -157,6 +159,7 @@ are listed in the descriptions of the relevant settings. | `email_author_in_body` | boolean | no | Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead. | | `enabled_git_access_protocol` | string | no | Enabled protocols for Git access. Allowed values are: `ssh`, `http`, and `nil` to allow both protocols. | | `enforce_terms` | boolean | no | (**If enabled, requires:** `terms`) Enforce application ToS to all users. | +| `first_day_of_week` | integer | no | The day a week starts on in calendars and date pickers. Valid values are `0` (default) for Sunday and `1` for Monday. | | `gitaly_timeout_default` | integer | no | Default Gitaly timeout, in seconds. This timeout is not enforced for git fetch/push operations or Sidekiq jobs. Set to `0` to disable timeouts. | | `gitaly_timeout_fast` | integer | no | Gitaly fast operation timeout, in seconds. Some Gitaly operations are expected to be fast. If they exceed this threshold, there may be a problem with a storage shard and 'failing fast' can help maintain the stability of the GitLab instance. Set to `0` to disable timeouts. | | `gitaly_timeout_medium` | integer | no | Medium Gitaly timeout, in seconds. This should be a value between the Fast and the Default timeout. Set to `0` to disable timeouts. | -- cgit v1.2.1 From 8ff943c280e67077662bbce524baf132b3d1919e Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Wed, 6 Feb 2019 17:49:39 +0100 Subject: Add tests for preferences_helper --- app/helpers/preferences_helper.rb | 8 ++++---- spec/helpers/preferences_helper_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index f1513f4f680..bc1742e8167 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -50,10 +50,6 @@ module PreferencesHelper ] end - def default_first_day_of_week - first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first - end - def first_day_of_week_choices_with_default first_day_of_week_choices.unshift([_('System default (%{default})') % { default: default_first_day_of_week }, nil]) end @@ -81,4 +77,8 @@ module PreferencesHelper def excluded_dashboard_choices ['operations'] end + + def default_first_day_of_week + first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first + end end diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index c112c8ed633..4c395248644 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -35,6 +35,30 @@ describe PreferencesHelper do end end + describe '#first_day_of_week_choices' do + it 'returns Sunday and Monday as choices' do + expect(helper.first_day_of_week_choices).to eq [ + ['Sunday', 0], + ['Monday', 1] + ] + end + end + + describe '#first_day_of_week_choices_with_default' do + it 'returns choices including system default' do + expect(helper.first_day_of_week_choices_with_default).to eq [ + ['System default (Sunday)', nil], ['Sunday', 0], ['Monday', 1] + ] + end + + it 'returns choices including system default set to Monday' do + stub_application_setting(first_day_of_week: 1) + expect(helper.first_day_of_week_choices_with_default).to eq [ + ['System default (Monday)', nil], ['Sunday', 0], ['Monday', 1] + ] + end + end + describe '#user_application_theme' do context 'with a user' do it "returns user's theme's css_class" do -- cgit v1.2.1 From 1a0bab0ab2896f021a5d3a80e84b5e9d6678f6c0 Mon Sep 17 00:00:00 2001 From: Fabian Schneider Date: Thu, 7 Feb 2019 09:50:22 +0100 Subject: Improve docs --- doc/api/settings.md | 2 +- doc/user/profile/preferences.md | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/api/settings.md b/doc/api/settings.md index 0f5371b5244..2ad6a46fa4b 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -159,7 +159,7 @@ are listed in the descriptions of the relevant settings. | `email_author_in_body` | boolean | no | Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead. | | `enabled_git_access_protocol` | string | no | Enabled protocols for Git access. Allowed values are: `ssh`, `http`, and `nil` to allow both protocols. | | `enforce_terms` | boolean | no | (**If enabled, requires:** `terms`) Enforce application ToS to all users. | -| `first_day_of_week` | integer | no | The day a week starts on in calendars and date pickers. Valid values are `0` (default) for Sunday and `1` for Monday. | +| `first_day_of_week` | integer | no | Start day of the week for calendar views and date pickers. Valid values are `0` (default) for Sunday and `1` for Monday. | | `gitaly_timeout_default` | integer | no | Default Gitaly timeout, in seconds. This timeout is not enforced for git fetch/push operations or Sidekiq jobs. Set to `0` to disable timeouts. | | `gitaly_timeout_fast` | integer | no | Gitaly fast operation timeout, in seconds. Some Gitaly operations are expected to be fast. If they exceed this threshold, there may be a problem with a storage shard and 'failing fast' can help maintain the stability of the GitLab instance. Set to `0` to disable timeouts. | | `gitaly_timeout_medium` | integer | no | Medium Gitaly timeout, in seconds. This should be a value between the Fast and the Default timeout. Set to `0` to disable timeouts. | diff --git a/doc/user/profile/preferences.md b/doc/user/profile/preferences.md index c8f4e9bf1f3..363d3db8db1 100644 --- a/doc/user/profile/preferences.md +++ b/doc/user/profile/preferences.md @@ -92,5 +92,6 @@ You can choose between 3 options: ### First day of the week -You can choose between **System Default**, **Sunday** and **Monday** for the first day of the week. If you select **System Default**, the system-wide default setting will be used. -This preference will be used for all calendar views and date pickers. +The first day of the week can be customised for calendar views and date pickers. + +You can choose **Sunday** or **Monday** as the first day of the week. If you select **System Default**, the system-wide default setting will be used. -- cgit v1.2.1