Commit 74b7efba authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'set-default-whitespace-diff' into 'master'

Set default whitespace diff

Closes #18761

See merge request !16570
parents 31ed2898 14cca608
Pipeline #82350518 passed with stages
in 99 minutes and 23 seconds
......@@ -74,6 +74,7 @@ export default function initDiffsApp(store) {
isFluidLayout: parseBoolean(dataset.isFluidLayout),
dismissEndpoint: dataset.dismissEndpoint,
showSuggestPopover: parseBoolean(dataset.showSuggestPopover),
showWhitespaceDefault: parseBoolean(dataset.showWhitespaceDefault),
};
},
computed: {
......@@ -82,11 +83,15 @@ export default function initDiffsApp(store) {
}),
},
created() {
let hideWhitespace = getParameterValues('w')[0];
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
this.setRenderTreeList(renderTreeList);
this.setShowWhitespace({ showWhitespace: getParameterValues('w')[0] !== '1' });
if (!hideWhitespace) {
hideWhitespace = this.showWhitespaceDefault ? '0' : '1';
}
this.setShowWhitespace({ showWhitespace: hideWhitespace !== '1' });
},
methods: {
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
......@@ -103,6 +108,7 @@ export default function initDiffsApp(store) {
isFluidLayout: this.isFluidLayout,
dismissEndpoint: this.dismissEndpoint,
showSuggestPopover: this.showSuggestPopover,
showWhitespaceDefault: this.showWhitespaceDefault,
},
});
},
......
......@@ -46,7 +46,8 @@ class Profiles::PreferencesController < Profiles::ApplicationController
:first_day_of_week,
:preferred_language,
:time_display_relative,
:time_format_in_24h
:time_format_in_24h,
:show_whitespace_in_diffs
]
end
end
......
......@@ -48,6 +48,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
@commits_count = @merge_request.commits_count
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
@current_user_data = UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestUserEntity).to_json
@show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
set_pipeline_variables
......
......@@ -235,6 +235,7 @@ class User < ApplicationRecord
delegate :timezone, :timezone=, to: :user_preference
delegate :time_display_relative, :time_display_relative=, to: :user_preference
delegate :time_format_in_24h, :time_format_in_24h=, to: :user_preference
delegate :show_whitespace_in_diffs, :show_whitespace_in_diffs=, to: :user_preference
accepts_nested_attributes_for :user_preference, update_only: true
......
......@@ -61,6 +61,10 @@
= f.select :project_view, project_view_choices, {}, class: 'select2'
.form-text.text-muted
= s_('Preferences|Choose what content you want to see on a project’s overview page.')
.form-group.form-check
= f.check_box :show_whitespace_in_diffs, class: 'form-check-input'
= f.label :show_whitespace_in_diffs, class: 'form-check-label' do
= s_('Preferences|Show whitespace in diffs')
.col-sm-12
%hr
......
......@@ -83,7 +83,8 @@
changes_empty_state_illustration: image_path('illustrations/merge_request_changes_empty.svg'),
is_fluid_layout: fluid_layout.to_s,
dismiss_endpoint: user_callouts_path,
show_suggest_popover: show_suggest_popover?.to_s } }
show_suggest_popover: show_suggest_popover?.to_s,
show_whitespace_default: @show_whitespace_default.to_s } }
.mr-loading-status
= spinner
......
# 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 AddShowWhitespaceInDiffsToUserPreferences < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :user_preferences, :show_whitespace_in_diffs, :boolean, default: true, allow_null: false
end
def down
remove_column :user_preferences, :show_whitespace_in_diffs
end
end
......@@ -3478,6 +3478,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
t.boolean "time_display_relative"
t.boolean "time_format_in_24h"
t.string "projects_sort", limit: 64
t.boolean "show_whitespace_in_diffs", default: true, null: false
t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true
end
......
---
title: Set default whitespace diff behaviour
merge_request: 16570
author: Lee Tickett
type: added
......@@ -11329,6 +11329,9 @@ msgstr ""
msgid "Preferences|Project overview content"
msgstr ""
msgid "Preferences|Show whitespace in diffs"
msgstr ""
msgid "Preferences|Syntax highlighting theme"
msgstr ""
......
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