From d2ebc9b931d12cb2cb120d6f7c940744bc1be39c Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Thu, 19 Oct 2017 17:47:11 +0300 Subject: Prevent schema.rb reverting from datetime_with_timezone to datetime --- config/initializers/active_record_data_types.rb | 5 +++++ .../20171019141859_fix_dev_timezone_schema.rb | 25 ++++++++++++++++++++++ db/schema.rb | 8 +++---- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20171019141859_fix_dev_timezone_schema.rb diff --git a/config/initializers/active_record_data_types.rb b/config/initializers/active_record_data_types.rb index fef591c397d..0359e14b232 100644 --- a/config/initializers/active_record_data_types.rb +++ b/config/initializers/active_record_data_types.rb @@ -79,3 +79,8 @@ elsif Gitlab::Database.mysql? NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamp' } end end + +# Ensure `datetime_with_timezone` columns are correctly written to schema.rb +if (ActiveRecord::Base.connection.active? rescue false) + ActiveRecord::Base.connection.send :reload_type_map +end diff --git a/db/migrate/20171019141859_fix_dev_timezone_schema.rb b/db/migrate/20171019141859_fix_dev_timezone_schema.rb new file mode 100644 index 00000000000..fb7c17dd747 --- /dev/null +++ b/db/migrate/20171019141859_fix_dev_timezone_schema.rb @@ -0,0 +1,25 @@ +class FixDevTimezoneSchema < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # The this migrations tries to help solve unwanted changes to `schema.rb` + # while developing GitLab. Installations created before we started using + # `datetime_with_timezone` are likely to face this problem. Updating those + # columns to the new type should help fix this. + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + TIMEZONE_TABLES = %i(appearances ci_group_variables ci_pipeline_schedule_variables events gpg_keys gpg_signatures project_auto_devops) + + def up + return unless Rails.env.development? || Rails.env.test? + + TIMEZONE_TABLES.each do |table| + change_column table, :created_at, :datetime_with_timezone + change_column table, :updated_at, :datetime_with_timezone + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 0984ca6487f..990456648b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -649,8 +649,8 @@ ActiveRecord::Schema.define(version: 20171124150326) do t.datetime "created_at" t.datetime "updated_at" t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" + t.datetime_with_timezone "confirmed_at" + t.datetime_with_timezone "confirmation_sent_at" end add_index "emails", ["confirmation_token"], name: "index_emails_on_confirmation_token", unique: true, using: :btree @@ -1762,8 +1762,8 @@ ActiveRecord::Schema.define(version: 20171124150326) do add_index "user_agent_details", ["subject_id", "subject_type"], name: "index_user_agent_details_on_subject_id_and_subject_type", using: :btree create_table "user_custom_attributes", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime_with_timezone "created_at", null: false + t.datetime_with_timezone "updated_at", null: false t.integer "user_id", null: false t.string "key", null: false t.string "value", null: false -- cgit v1.2.1 From e391fe1d6d39837d6aebb14f90e200fc6ff42d81 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 12 Dec 2017 15:11:34 +0100 Subject: Reduce cardinality of gitlab_cache_operation_duration_seconds histogram --- lib/gitlab/metrics/subscribers/rails_cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb index efd3c9daf79..250897a79c2 100644 --- a/lib/gitlab/metrics/subscribers/rails_cache.rb +++ b/lib/gitlab/metrics/subscribers/rails_cache.rb @@ -66,7 +66,7 @@ module Gitlab :gitlab_cache_operation_duration_seconds, 'Cache access time', Transaction::BASE_LABELS.merge({ action: nil }), - [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0] + [0.001, 0.01, 0.1, 1, 10] ) end -- cgit v1.2.1 From b02db1f4931060d9e28bd0d651dbea34c79340e2 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 12 Dec 2017 16:54:11 +0100 Subject: Fix gitaly_call_histogram to observe times in seconds correctly --- lib/gitlab/gitaly_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index b753ac46291..7aa2eafbb73 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -132,7 +132,7 @@ module Gitlab self.query_time += duration gitaly_call_histogram.observe( current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s), - duration) + duration / 1000.0) end def self.current_transaction_labels -- cgit v1.2.1 From a8ebed6016726722a2283458e4176fc9177558af Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 12 Dec 2017 18:12:49 +0100 Subject: Make `System.monotonic_time` retun seconds represented by float with microsecond precision --- lib/gitlab/gitaly_client.rb | 2 +- lib/gitlab/metrics/method_call.rb | 18 +++++++++++------- lib/gitlab/metrics/samplers/ruby_sampler.rb | 2 +- lib/gitlab/metrics/system.rb | 9 +++++---- lib/gitlab/metrics/transaction.rb | 8 ++++++-- spec/lib/gitlab/metrics/system_spec.rb | 4 ++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 7aa2eafbb73..b753ac46291 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -132,7 +132,7 @@ module Gitlab self.query_time += duration gitaly_call_histogram.observe( current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s), - duration / 1000.0) + duration) end def self.current_transaction_labels diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 65d55576ac2..6fb8f564237 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -4,7 +4,7 @@ module Gitlab class MethodCall MUTEX = Mutex.new BASE_LABELS = { module: nil, method: nil }.freeze - attr_reader :real_time, :cpu_time, :call_count, :labels + attr_reader :real_time_seconds, :cpu_time, :call_count, :labels def self.call_duration_histogram return @call_duration_histogram if @call_duration_histogram @@ -27,37 +27,41 @@ module Gitlab @transaction = transaction @name = name @labels = { module: @module_name, method: @method_name } - @real_time = 0 + @real_time_seconds = 0 @cpu_time = 0 @call_count = 0 end # Measures the real and CPU execution time of the supplied block. def measure - start_real = System.monotonic_time + start_real_seconds = System.monotonic_time start_cpu = System.cpu_time retval = yield - real_time = System.monotonic_time - start_real + real_time_seconds = System.monotonic_time - start_real_seconds cpu_time = System.cpu_time - start_cpu - @real_time += real_time + @real_time_seconds += real_time_seconds @cpu_time += cpu_time @call_count += 1 if call_measurement_enabled? && above_threshold? - self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0) + self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time_seconds) end retval end + def real_time_milliseconds + (real_time_seconds * 1000.0).to_i + end + # Returns a Metric instance of the current method call. def to_metric Metric.new( Instrumentation.series, { - duration: real_time, + duration: real_time_milliseconds, cpu_duration: cpu_time, call_count: call_count }, diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb index b68800417a2..4e1ea62351f 100644 --- a/lib/gitlab/metrics/samplers/ruby_sampler.rb +++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb @@ -52,7 +52,7 @@ module Gitlab metrics[:memory_usage].set(labels, System.memory_usage) metrics[:file_descriptors].set(labels, System.file_descriptor_count) - metrics[:sampler_duration].observe(labels.merge(worker_label), (System.monotonic_time - start_time) / 1000.0) + metrics[:sampler_duration].observe(labels.merge(worker_label), System.monotonic_time - start_time) ensure GC::Profiler.clear end diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index c2cbd3c16a1..b31cc6236d1 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -51,11 +51,12 @@ module Gitlab Process.clock_gettime(Process::CLOCK_REALTIME, precision) end - # Returns the current monotonic clock time in a given precision. + # Returns the current monotonic clock time as seconds with microseconds precision. # - # Returns the time as a Fixnum. - def self.monotonic_time(precision = :millisecond) - Process.clock_gettime(Process::CLOCK_MONOTONIC, precision) + # Returns the time as a Float. + def self.monotonic_time + + Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) end end end diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb index ee3afc5ffdb..16f0969ab74 100644 --- a/lib/gitlab/metrics/transaction.rb +++ b/lib/gitlab/metrics/transaction.rb @@ -35,6 +35,10 @@ module Gitlab @finished_at ? (@finished_at - @started_at) : 0.0 end + def duration_milliseconds + (duration * 1000).to_i + end + def allocated_memory @memory_after - @memory_before end @@ -50,7 +54,7 @@ module Gitlab @memory_after = System.memory_usage @finished_at = System.monotonic_time - self.class.metric_transaction_duration_seconds.observe(labels, duration * 1000) + self.class.metric_transaction_duration_seconds.observe(labels, duration) self.class.metric_transaction_allocated_memory_bytes.observe(labels, allocated_memory * 1024.0) Thread.current[THREAD_KEY] = nil @@ -97,7 +101,7 @@ module Gitlab end def track_self - values = { duration: duration, allocated_memory: allocated_memory } + values = { duration: duration_milliseconds, allocated_memory: allocated_memory } @values.each do |name, value| values[name] = value diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index 4d94d8705fb..ea3bd00970e 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -40,8 +40,8 @@ describe Gitlab::Metrics::System do end describe '.monotonic_time' do - it 'returns a Fixnum' do - expect(described_class.monotonic_time).to be_an(Integer) + it 'returns a Float' do + expect(described_class.monotonic_time).to be_an(Float) end end end -- cgit v1.2.1 From df4fe43d73c10db447fb08317bf4bf20878a2bfc Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 15 Dec 2017 20:08:21 +0000 Subject: Fixed diff_worker not compiling correctly Closes #41182 --- app/assets/javascripts/repo/lib/diff/diff_worker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/repo/lib/diff/diff_worker.js b/app/assets/javascripts/repo/lib/diff/diff_worker.js index e74c4046330..105431442af 100644 --- a/app/assets/javascripts/repo/lib/diff/diff_worker.js +++ b/app/assets/javascripts/repo/lib/diff/diff_worker.js @@ -1,6 +1,7 @@ import { computeDiff } from './diff'; -self.addEventListener('message', (e) => { +// eslint-disable-next-line prefer-arrow-callback +self.addEventListener('message', function diffWorker(e) { const data = e.data; self.postMessage({ -- cgit v1.2.1 From a69e7affbca9bbfe8fb9a51ab1646f81d8ade339 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Sat, 16 Dec 2017 00:24:18 +0000 Subject: changed webpack config --- app/assets/javascripts/repo/lib/diff/diff_worker.js | 3 +-- config/webpack.config.js | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/repo/lib/diff/diff_worker.js b/app/assets/javascripts/repo/lib/diff/diff_worker.js index 105431442af..e74c4046330 100644 --- a/app/assets/javascripts/repo/lib/diff/diff_worker.js +++ b/app/assets/javascripts/repo/lib/diff/diff_worker.js @@ -1,7 +1,6 @@ import { computeDiff } from './diff'; -// eslint-disable-next-line prefer-arrow-callback -self.addEventListener('message', function diffWorker(e) { +self.addEventListener('message', (e) => { const data = e.data; self.postMessage({ diff --git a/config/webpack.config.js b/config/webpack.config.js index 78ced4c3e8c..e850f6174b1 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -118,7 +118,10 @@ var config = { }, { test: /\_worker\.js$/, - loader: 'worker-loader', + use: [ + { loader: 'worker-loader' }, + { loader: 'babel-loader' }, + ], }, { test: /\.(worker(\.min)?\.js|pdf|bmpr)$/, -- cgit v1.2.1 From b7f59772b16b39baca7dbe2cb5dd830b7382c038 Mon Sep 17 00:00:00 2001 From: Christiaan Van den Poel Date: Sun, 17 Dec 2017 21:07:29 +0100 Subject: remove the label --- app/assets/javascripts/boards/boards_bundle.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/boards/boards_bundle.js b/app/assets/javascripts/boards/boards_bundle.js index 20d23162940..0c1cff1da7a 100644 --- a/app/assets/javascripts/boards/boards_bundle.js +++ b/app/assets/javascripts/boards/boards_bundle.js @@ -102,7 +102,6 @@ $(() => { if (list.type === 'closed') { list.position = Infinity; - list.label = { description: 'Shows all closed issues. Moving an issue to this list closes it' }; } else if (list.type === 'backlog') { list.position = -1; } -- cgit v1.2.1 From 148c7533d701490eb5cd8aebc4fa033e0f0f6ec4 Mon Sep 17 00:00:00 2001 From: Christiaan Van den Poel Date: Sun, 17 Dec 2017 21:09:57 +0100 Subject: added changelog --- ...how_proper_labels_in_board_issue_sidebar_when_issue_is_closed.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/show_proper_labels_in_board_issue_sidebar_when_issue_is_closed.yml diff --git a/changelogs/unreleased/show_proper_labels_in_board_issue_sidebar_when_issue_is_closed.yml b/changelogs/unreleased/show_proper_labels_in_board_issue_sidebar_when_issue_is_closed.yml new file mode 100644 index 00000000000..c2ab34b20a5 --- /dev/null +++ b/changelogs/unreleased/show_proper_labels_in_board_issue_sidebar_when_issue_is_closed.yml @@ -0,0 +1,5 @@ +--- +title: show None when issue is in closed list and no labels assigned +merge_request: 15976 +author: Christiaan Van den Poel +type: fixed -- cgit v1.2.1 From 3c545133e8f23b57698046bae8be23e2bc457aca Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 19 Dec 2017 17:45:25 +0100 Subject: Fix tests and formatting --- lib/gitlab/metrics/influx_db.rb | 1 + lib/gitlab/metrics/method_call.rb | 2 +- lib/gitlab/metrics/system.rb | 1 - spec/lib/gitlab/metrics/method_call_spec.rb | 11 ++++++----- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/metrics/influx_db.rb b/lib/gitlab/metrics/influx_db.rb index bdf7910b7c7..153e236d018 100644 --- a/lib/gitlab/metrics/influx_db.rb +++ b/lib/gitlab/metrics/influx_db.rb @@ -38,6 +38,7 @@ module Gitlab # This is memoized since this method is called for every instrumented # method. Loading data from an external cache on every method call slows # things down too much. + # in milliseconds @method_call_threshold ||= settings[:method_call_threshold] end diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 6fb8f564237..a030092df37 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -72,7 +72,7 @@ module Gitlab # Returns true if the total runtime of this method exceeds the method call # threshold. def above_threshold? - real_time >= Metrics.method_call_threshold + real_time_milliseconds >= Metrics.method_call_threshold end def call_measurement_enabled? diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index b31cc6236d1..4852017bf38 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -55,7 +55,6 @@ module Gitlab # # Returns the time as a Float. def self.monotonic_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) end end diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index 5341addf911..91a70ba01a0 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -8,7 +8,8 @@ describe Gitlab::Metrics::MethodCall do it 'measures the performance of the supplied block' do method_call.measure { 'foo' } - expect(method_call.real_time).to be_a_kind_of(Numeric) + expect(method_call.real_time_seconds).to be_a_kind_of(Numeric) + expect(method_call.real_time_milliseconds).to be_a_kind_of(Numeric) expect(method_call.cpu_time).to be_a_kind_of(Numeric) expect(method_call.call_count).to eq(1) end @@ -84,13 +85,13 @@ describe Gitlab::Metrics::MethodCall do end it 'returns false when the total call time is not above the threshold' do - expect(method_call).to receive(:real_time).and_return(9) + expect(method_call).to receive(:real_time_seconds).and_return(0.009) expect(method_call.above_threshold?).to eq(false) end it 'returns true when the total call time is above the threshold' do - expect(method_call).to receive(:real_time).and_return(9000) + expect(method_call).to receive(:real_time_seconds).and_return(9) expect(method_call.above_threshold?).to eq(true) end @@ -131,7 +132,7 @@ describe Gitlab::Metrics::MethodCall do describe '#real_time' do context 'without timings' do it 'returns 0.0' do - expect(method_call.real_time).to eq(0.0) + expect(method_call.real_time_seconds).to eq(0.0) end end @@ -139,7 +140,7 @@ describe Gitlab::Metrics::MethodCall do it 'returns the total real time' do method_call.measure { 'foo' } - expect(method_call.real_time >= 0.0).to be(true) + expect(method_call.real_time_seconds >= 0.0).to be(true) end end end -- cgit v1.2.1 From a623ddb0dcdc42b0bd4f9d20c79e82387d9b5547 Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Thu, 16 Nov 2017 13:34:15 -0600 Subject: replaced download icon for the sprite based one --- .../javascripts/pipelines/components/pipelines_artifacts.vue | 11 +++++++---- .../vue_merge_request_widget/components/mr_widget_header.js | 7 +++++-- app/helpers/blob_helper.rb | 2 +- app/views/projects/artifacts/browse.html.haml | 2 +- app/views/projects/blob/viewers/_download.html.haml | 2 +- app/views/projects/buttons/_download.html.haml | 2 +- app/views/projects/ci/builds/_build.html.haml | 2 +- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue b/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue index 751a20991af..fada8fd90df 100644 --- a/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue +++ b/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue @@ -1,5 +1,6 @@ diff --git a/app/assets/javascripts/cycle_analytics/components/stage_staging_component.vue b/app/assets/javascripts/cycle_analytics/components/stage_staging_component.vue index 5d95ddcd90e..508a411e599 100644 --- a/app/assets/javascripts/cycle_analytics/components/stage_staging_component.vue +++ b/app/assets/javascripts/cycle_analytics/components/stage_staging_component.vue @@ -3,6 +3,7 @@ import iconBranch from '../svg/icon_branch.svg'; import limitWarning from './limit_warning_component.vue'; import totalTime from './total_time_component.vue'; + import icon from '../../vue_shared/components/icon.vue'; export default { props: { @@ -13,6 +14,7 @@ userAvatarImage, totalTime, limitWarning, + icon, }, computed: { iconBranch() { @@ -37,7 +39,10 @@
#{{ build.id }} - + + {{ build.branch.name }} {{ build.shortSha }} diff --git a/app/assets/javascripts/cycle_analytics/components/stage_test_component.vue b/app/assets/javascripts/cycle_analytics/components/stage_test_component.vue index 04d5440b77b..88fa6b073ca 100644 --- a/app/assets/javascripts/cycle_analytics/components/stage_test_component.vue +++ b/app/assets/javascripts/cycle_analytics/components/stage_test_component.vue @@ -3,6 +3,7 @@ import iconBranch from '../svg/icon_branch.svg'; import limitWarning from './limit_warning_component.vue'; import totalTime from './total_time_component.vue'; + import icon from '../../vue_shared/components/icon.vue'; export default { props: { @@ -12,6 +13,7 @@ components: { totalTime, limitWarning, + icon, }, computed: { iconBuildStatus() { @@ -40,7 +42,10 @@ {{ build.name }} · #{{ build.id }} - + + {{ build.branch.name }} {{ build.shortSha }} diff --git a/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue b/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue index fada8fd90df..831aa92ac4f 100644 --- a/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue +++ b/app/assets/javascripts/pipelines/components/pipelines_artifacts.vue @@ -1,6 +1,6 @@ diff --git a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.js b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.js index 38c3ec874c6..85bfd03a3cf 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.js +++ b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.js @@ -1,6 +1,6 @@ import tooltip from '../../vue_shared/directives/tooltip'; import { pluralize } from '../../lib/utils/text_utility'; -import Icon from '../../vue_shared/components/icon.vue'; +import icon from '../../vue_shared/components/icon.vue'; export default { name: 'MRWidgetHeader', @@ -11,7 +11,7 @@ export default { tooltip, }, components: { - Icon, + icon, }, computed: { shouldShowCommitsBehindText() { diff --git a/app/assets/stylesheets/framework/wells.scss b/app/assets/stylesheets/framework/wells.scss index 735fc4babd7..2f3a80daa90 100644 --- a/app/assets/stylesheets/framework/wells.scss +++ b/app/assets/stylesheets/framework/wells.scss @@ -16,6 +16,10 @@ .commit-sha, .commit-info { margin-left: 4px; + + .fork-svg { + margin-right: 4px; + } } .ref-name { @@ -79,7 +83,7 @@ } .limit-icon { - margin: 0 8px; + margin: 0 4px; } .limit-message { diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 373e01931ad..f887a11004f 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -725,7 +725,5 @@ } .fork-sprite { - width: 12px; - height: 12px; margin-right: -5px; } diff --git a/app/assets/stylesheets/pages/pipeline_schedules.scss b/app/assets/stylesheets/pages/pipeline_schedules.scss index 7e2297c283f..b698a4f9afa 100644 --- a/app/assets/stylesheets/pages/pipeline_schedules.scss +++ b/app/assets/stylesheets/pages/pipeline_schedules.scss @@ -39,6 +39,10 @@ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + + svg { + vertical-align: middle; + } } .next-run-cell { diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 2d304f7eb91..0333c29e2fd 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -63,7 +63,7 @@ module CommitsHelper # Returns a link formatted as a commit branch link def commit_branch_link(url, text) link_to(url, class: 'label label-gray ref-name branch-link') do - icon('code-fork', class: 'append-right-5') + "#{text}" + sprite_icon('fork', size: 16, css_class: 'fork-svg') + "#{text}" end end diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 8a8011c27b4..acf67b83890 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -8,7 +8,7 @@ %li{ class: "js-branch-#{branch.name}" } %div = link_to project_tree_path(@project, branch.name), class: 'item-title str-truncated ref-name' do - = sprite_icon('fork', size: 8) + = sprite_icon('fork', size: 12) = branch.name   - if branch.name == @repository.root_ref diff --git a/app/views/projects/commit/_limit_exceeded_message.html.haml b/app/views/projects/commit/_limit_exceeded_message.html.haml index 84a52d49487..a264f3517c4 100644 --- a/app/views/projects/commit/_limit_exceeded_message.html.haml +++ b/app/views/projects/commit/_limit_exceeded_message.html.haml @@ -1,7 +1,7 @@ .has-tooltip{ class: "limit-box limit-box-#{objects} prepend-left-5", data: { title: "Project has too many #{label_for_message} to search"} } .limit-icon - if objects == :branch - = icon('code-fork') + = sprite_icon('fork', size: 12) - else = icon('tag') .limit-message diff --git a/app/views/projects/deployments/_commit.html.haml b/app/views/projects/deployments/_commit.html.haml index 014486be868..c7ac687e4a6 100644 --- a/app/views/projects/deployments/_commit.html.haml +++ b/app/views/projects/deployments/_commit.html.haml @@ -2,7 +2,7 @@ .branch-commit - if deployment.ref %span.icon-container - = deployment.tag? ? icon('tag') : icon('code-fork') + = deployment.tag? ? icon('tag') : sprite_icon('fork', css_class: 'sprite') = link_to deployment.ref, project_ref_path(@project, deployment.ref), class: "ref-name" .icon-container.commit-icon = custom_icon("icon_commit") diff --git a/app/views/projects/forks/error.html.haml b/app/views/projects/forks/error.html.haml index d365bcd4ecc..e8a89b8c6fc 100644 --- a/app/views/projects/forks/error.html.haml +++ b/app/views/projects/forks/error.html.haml @@ -2,7 +2,7 @@ - if @forked_project && !@forked_project.saved? .alert.alert-danger.alert-block %h4 - %i.fa.fa-code-fork + = sprite_icon('fork', size: 16) Fork Error! %p You tried to fork @@ -21,5 +21,4 @@ %p = link_to new_project_fork_path(@project), title: "Fork", class: "btn" do - %i.fa.fa-code-fork Try to fork again diff --git a/app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml b/app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml index b98dc09534f..2599ce5c4b8 100644 --- a/app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml +++ b/app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml @@ -19,7 +19,7 @@ - if ref - if generic_commit_status.ref .icon-container - = generic_commit_status.tags.any? ? icon('tag') : icon('code-fork') + = generic_commit_status.tags.any? ? icon('tag') : sprite_icon('fork', size: 10) = link_to generic_commit_status.ref, project_commits_path(generic_commit_status.project, generic_commit_status.ref) - else .light none diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml index 591da3b6638..f45a000833b 100644 --- a/app/views/projects/merge_requests/_merge_request.html.haml +++ b/app/views/projects/merge_requests/_merge_request.html.haml @@ -30,7 +30,7 @@ %span.project-ref-path   = link_to project_ref_path(merge_request.project, merge_request.target_branch), class: 'ref-name' do - = sprite_icon('fork', css_class: 'fork-sprite') + = sprite_icon('fork', size: 12, css_class: 'fork-sprite') = merge_request.target_branch - if merge_request.labels.any?   diff --git a/app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml b/app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml index f8c4005a9e0..800e234275c 100644 --- a/app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml +++ b/app/views/projects/pipeline_schedules/_pipeline_schedule.html.haml @@ -3,7 +3,7 @@ %td = pipeline_schedule.description %td.branch-name-cell - = icon('code-fork') + = sprite_icon('fork', size: 12) - if pipeline_schedule.ref.present? = link_to pipeline_schedule.ref, project_ref_path(@project, pipeline_schedule.ref), class: "ref-name" %td diff --git a/spec/javascripts/vue_shared/components/commit_spec.js b/spec/javascripts/vue_shared/components/commit_spec.js index d5754aaa9e7..fdead874209 100644 --- a/spec/javascripts/vue_shared/components/commit_spec.js +++ b/spec/javascripts/vue_shared/components/commit_spec.js @@ -10,7 +10,7 @@ describe('Commit component', () => { CommitComponent = Vue.extend(commitComp); }); - it('should render a code-fork icon if it does not represent a tag', () => { + it('should render a fork icon if it does not represent a tag', () => { component = new CommitComponent({ propsData: { tag: false, @@ -30,7 +30,7 @@ describe('Commit component', () => { }, }).$mount(); - expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-code-fork'); + expect(component.$el.querySelector('.icon-container').children).toContain('svg'); }); describe('Given all the props', () => { -- cgit v1.2.1 From ce8b53ea89b40e16c8da2e3b90c7ef3f1b148920 Mon Sep 17 00:00:00 2001 From: asaparov Date: Tue, 19 Dec 2017 19:10:14 -0500 Subject: Bumped mysql2 gem version from 0.4.5 to 0.4.10. --- Gemfile | 2 +- Gemfile.lock | 4 ++-- changelogs/unreleased/bump_mysql_gem.yml | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/bump_mysql_gem.yml diff --git a/Gemfile b/Gemfile index b6ffaf80f24..cc39714295e 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'sprockets', '~> 3.7.0' gem 'default_value_for', '~> 3.0.0' # Supported DBs -gem 'mysql2', '~> 0.4.5', group: :mysql +gem 'mysql2', '~> 0.4.10', group: :mysql gem 'pg', '~> 0.18.2', group: :postgres gem 'rugged', '~> 0.26.0' diff --git a/Gemfile.lock b/Gemfile.lock index a6e3c9e27cc..d11cadeec30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -501,7 +501,7 @@ GEM mustermann (1.0.0) mustermann-grape (1.0.0) mustermann (~> 1.0.0) - mysql2 (0.4.5) + mysql2 (0.4.10) net-ldap (0.16.0) net-ssh (4.1.0) netrc (0.11.0) @@ -1082,7 +1082,7 @@ DEPENDENCIES method_source (~> 0.8) minitest (~> 5.7.0) mousetrap-rails (~> 1.4.6) - mysql2 (~> 0.4.5) + mysql2 (~> 0.4.10) net-ldap net-ssh (~> 4.1.0) nokogiri (~> 1.8.1) diff --git a/changelogs/unreleased/bump_mysql_gem.yml b/changelogs/unreleased/bump_mysql_gem.yml new file mode 100644 index 00000000000..58166949d72 --- /dev/null +++ b/changelogs/unreleased/bump_mysql_gem.yml @@ -0,0 +1,5 @@ +--- +title: Bump mysql2 gem version from 0.4.5 to 0.4.10 +merge_request: +author: asaparov +type: other -- cgit v1.2.1 From a331a06aa8da542afa985d61370b9518cc44b1e9 Mon Sep 17 00:00:00 2001 From: julien MILLAU Date: Wed, 20 Dec 2017 08:11:13 +0000 Subject: Ignore "lost+found" folder during backup on a volume --- lib/backup/files.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/backup/files.rb b/lib/backup/files.rb index 30a91647b77..287d591e88d 100644 --- a/lib/backup/files.rb +++ b/lib/backup/files.rb @@ -18,7 +18,7 @@ module Backup FileUtils.rm_f(backup_tarball) if ENV['STRATEGY'] == 'copy' - cmd = %W(cp -a #{app_files_dir} #{Gitlab.config.backup.path}) + cmd = %W(rsync -a --exclude=lost+found #{app_files_dir} #{Gitlab.config.backup.path}) output, status = Gitlab::Popen.popen(cmd) unless status.zero? @@ -26,10 +26,10 @@ module Backup abort 'Backup failed' end - run_pipeline!([%W(tar -C #{@backup_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600]) + run_pipeline!([%W(tar --exclude=lost+found -C #{@backup_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600]) FileUtils.rm_rf(@backup_files_dir) else - run_pipeline!([%W(tar -C #{app_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600]) + run_pipeline!([%W(tar --exclude=lost+found -C #{app_files_dir} -cf - .), %w(gzip -c -1)], out: [backup_tarball, 'w', 0600]) end end -- cgit v1.2.1 From 091c4989b3c1e18723aef2b28475866b1a89e282 Mon Sep 17 00:00:00 2001 From: julien MILLAU Date: Wed, 20 Dec 2017 08:55:15 +0000 Subject: Add changelog --- .../16036-ignore-lost-found-folder-during-backup-on-a-volume.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/16036-ignore-lost-found-folder-during-backup-on-a-volume.yml diff --git a/changelogs/unreleased/16036-ignore-lost-found-folder-during-backup-on-a-volume.yml b/changelogs/unreleased/16036-ignore-lost-found-folder-during-backup-on-a-volume.yml new file mode 100644 index 00000000000..833650559a3 --- /dev/null +++ b/changelogs/unreleased/16036-ignore-lost-found-folder-during-backup-on-a-volume.yml @@ -0,0 +1,5 @@ +--- +title: "Ignore lost+found folder during backup on a volume" +merge_request: 16036 +author: Julien Millau +type: fixed \ No newline at end of file -- cgit v1.2.1 From e7b0fe36d78a4462baf623bda5d34089a19e6c23 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 20 Dec 2017 17:26:21 +0800 Subject: It should escape spaces to %20 rather than + `CGI.escape` would escape spaces to +, which is fine in some cases, but doesn't work for git clone. --- qa/qa/git/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 59cd147e055..8f999511d58 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -23,7 +23,7 @@ module QA def password=(pass) @password = pass - @uri.password = CGI.escape(pass) + @uri.password = CGI.escape(pass).gsub('+', '%20') end def use_default_credentials -- cgit v1.2.1 From cfe3c238f5d9b7f91e01a549ee365a04158541a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 20 Dec 2017 10:58:34 +0100 Subject: Update installation and upgrade guides to use Ruby 2.3.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- doc/install/installation.md | 8 +- doc/update/10.1-to-10.2.md | 4 +- doc/update/10.2-to-10.3.md | 4 +- doc/update/10.3-to-10.4.md | 360 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 368 insertions(+), 8 deletions(-) create mode 100644 doc/update/10.3-to-10.4.md diff --git a/doc/install/installation.md b/doc/install/installation.md index 56888b05609..67b89d608cc 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -133,9 +133,9 @@ Remove the old Ruby 1.8 if present: Download Ruby and compile it: mkdir /tmp/ruby && cd /tmp/ruby - curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.gz - echo '3247e217d6745c27ef23bdc77b6abdb4b57a118f ruby-2.3.5.tar.gz' | shasum -c - && tar xzf ruby-2.3.5.tar.gz - cd ruby-2.3.5 + curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.6.tar.gz + echo '4e6a0f828819e15d274ae58485585fc8b7caace0 ruby-2.3.6.tar.gz' | shasum -c - && tar xzf ruby-2.3.6.tar.gz + cd ruby-2.3.6 ./configure --disable-install-rdoc make sudo make install @@ -367,7 +367,7 @@ sudo usermod -aG redis git # Enable packfile bitmaps sudo -u git -H git config --global repack.writeBitmaps true - + # Enable push options sudo -u git -H git config --global receive.advertisePushOptions true diff --git a/doc/update/10.1-to-10.2.md b/doc/update/10.1-to-10.2.md index 9e0d8f79522..632e8befa74 100644 --- a/doc/update/10.1-to-10.2.md +++ b/doc/update/10.1-to-10.2.md @@ -339,11 +339,11 @@ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production If all items are green, then congratulations, the upgrade is complete! -## Things went south? Revert to previous version (10.0) +## Things went south? Revert to previous version (10.1) ### 1. Revert the code to the previous version -Follow the [upgrade guide from 9.5 to 10.0](9.5-to-10.0.md), except for the +Follow the [upgrade guide from 10.0 to 10.1](10.0-to-10.1.md), except for the database migration (the backup is already migrated to the previous version). ### 2. Restore from the backup diff --git a/doc/update/10.2-to-10.3.md b/doc/update/10.2-to-10.3.md index 07f9ee965f0..d6e2db8a353 100644 --- a/doc/update/10.2-to-10.3.md +++ b/doc/update/10.2-to-10.3.md @@ -339,11 +339,11 @@ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production If all items are green, then congratulations, the upgrade is complete! -## Things went south? Revert to previous version (10.0) +## Things went south? Revert to previous version (10.2) ### 1. Revert the code to the previous version -Follow the [upgrade guide from 9.5 to 10.0](9.5-to-10.0.md), except for the +Follow the [upgrade guide from 10.1 to 10.2](10.1-to-10.2.md), except for the database migration (the backup is already migrated to the previous version). ### 2. Restore from the backup diff --git a/doc/update/10.3-to-10.4.md b/doc/update/10.3-to-10.4.md new file mode 100644 index 00000000000..850cb3103f4 --- /dev/null +++ b/doc/update/10.3-to-10.4.md @@ -0,0 +1,360 @@ +--- +comments: false +--- + +# From 10.3 to 10.4 + +Make sure you view this update guide from the tag (version) of GitLab you would +like to install. In most cases this should be the highest numbered production +tag (without rc in it). You can select the tag in the version dropdown at the +top left corner of GitLab (below the menu bar). + +If the highest number stable branch is unclear please check the +[GitLab Blog](https://about.gitlab.com/blog/archives.html) for installation +guide links by version. + +### 1. Stop server + +```bash +sudo service gitlab stop +``` + +### 2. Backup + +```bash +cd /home/git/gitlab + +sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production +``` + +### 3. Update Ruby + +NOTE: GitLab 9.0 and higher only support Ruby 2.3.x and dropped support for Ruby 2.1.x. Be +sure to upgrade your interpreter if necessary. + +You can check which version you are running with `ruby -v`. + +Download and compile Ruby: + +```bash +mkdir /tmp/ruby && cd /tmp/ruby +curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.6.tar.gz +echo '4e6a0f828819e15d274ae58485585fc8b7caace0 ruby-2.3.6.tar.gz' | shasum -c - && tar xzf ruby-2.3.6.tar.gz +cd ruby-2.3.6 +./configure --disable-install-rdoc +make +sudo make install +``` + +Install Bundler: + +```bash +sudo gem install bundler --no-ri --no-rdoc +``` + +### 4. Update Node + +GitLab now runs [webpack](http://webpack.js.org) to compile frontend assets and +it has a minimum requirement of node v4.3.0. + +You can check which version you are running with `node -v`. If you are running +a version older than `v4.3.0` you will need to update to a newer version. You +can find instructions to install from community maintained packages or compile +from source at the nodejs.org website. + + + + +Since 8.17, GitLab requires the use of yarn `>= v0.17.0` to manage +JavaScript dependencies. + +```bash +curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - +echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list +sudo apt-get update +sudo apt-get install yarn +``` + +More information can be found on the [yarn website](https://yarnpkg.com/en/docs/install). + +### 5. Update Go + +NOTE: GitLab 9.2 and higher only supports Go 1.8.3 and dropped support for Go +1.5.x through 1.7.x. Be sure to upgrade your installation if necessary. + +You can check which version you are running with `go version`. + +Download and install Go: + +```bash +# Remove former Go installation folder +sudo rm -rf /usr/local/go + +curl --remote-name --progress https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz +echo '1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772 go1.8.3.linux-amd64.tar.gz' | shasum -a256 -c - && \ + sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz +sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/ +rm go1.8.3.linux-amd64.tar.gz +``` + +### 6. Get latest code + +```bash +cd /home/git/gitlab + +sudo -u git -H git fetch --all +sudo -u git -H git checkout -- db/schema.rb # local changes will be restored automatically +sudo -u git -H git checkout -- locale +``` + +For GitLab Community Edition: + +```bash +cd /home/git/gitlab + +sudo -u git -H git checkout 10-4-stable +``` + +OR + +For GitLab Enterprise Edition: + +```bash +cd /home/git/gitlab + +sudo -u git -H git checkout 10-4-stable-ee +``` + +### 7. Update gitlab-shell + +```bash +cd /home/git/gitlab-shell + +sudo -u git -H git fetch --all --tags +sudo -u git -H git checkout v$( Date: Tue, 19 Dec 2017 19:40:43 +0100 Subject: use in_milliseconds rails helper --- lib/gitlab/metrics/method_call.rb | 4 ++-- lib/gitlab/metrics/transaction.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index a030092df37..bb39b1d5462 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -27,7 +27,7 @@ module Gitlab @transaction = transaction @name = name @labels = { module: @module_name, method: @method_name } - @real_time_seconds = 0 + @real_time_seconds = 0.0 @cpu_time = 0 @call_count = 0 end @@ -53,7 +53,7 @@ module Gitlab end def real_time_milliseconds - (real_time_seconds * 1000.0).to_i + real_time_seconds.in_milliseconds.to_i end # Returns a Metric instance of the current method call. diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb index 16f0969ab74..e7975c023a9 100644 --- a/lib/gitlab/metrics/transaction.rb +++ b/lib/gitlab/metrics/transaction.rb @@ -36,7 +36,7 @@ module Gitlab end def duration_milliseconds - (duration * 1000).to_i + duration.in_milliseconds.to_i end def allocated_memory -- cgit v1.2.1 From 58b8b80787c47185bbca59bbb2039c2ba9022d27 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Wed, 20 Dec 2017 17:16:37 -0600 Subject: properly handle naming for dispatcher route chunks --- config/webpack.config.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index 78ced4c3e8c..0cb69141a73 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -176,8 +176,13 @@ var config = { return chunk.name; } return chunk.mapModules((m) => { - var chunkPath = m.request.split('!').pop(); - return path.relative(m.context, chunkPath); + const pagesBase = path.join(ROOT_PATH, 'app/assets/javascripts/pages'); + if (m.resource.indexOf(pagesBase) === 0) { + return path.relative(pagesBase, m.resource) + .replace(/\/index\.[a-z]+$/, '') + .replace(/\//g, '__'); + } + return path.relative(m.context, m.resource); }).join('_'); }), -- cgit v1.2.1 From 0e50e9d9d48752a58b640064075f7786f86e7433 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Wed, 20 Dec 2017 17:20:51 -0600 Subject: update dispatcher to allow for dynamic imports until webpack plugin is updated --- app/assets/javascripts/dispatcher.js | 4 +++- app/assets/javascripts/pages/users/show/index.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/pages/users/show/index.js diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 62867c56214..13fa553047a 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -111,6 +111,8 @@ import Activities from './activities'; return false; } + const fail = () => Flash('Error loading dynamic module'); + path = page.split(':'); shortcut_handler = null; @@ -545,7 +547,7 @@ import Activities from './activities'; new CILintEditor(); break; case 'users:show': - new UserCallout(); + import('./pages/users/show').then(m => m.default()).catch(fail); break; case 'admin:conversational_development_index:show': new UserCallout(); diff --git a/app/assets/javascripts/pages/users/show/index.js b/app/assets/javascripts/pages/users/show/index.js new file mode 100644 index 00000000000..f18f98b4e9a --- /dev/null +++ b/app/assets/javascripts/pages/users/show/index.js @@ -0,0 +1,3 @@ +import UserCallout from '~/user_callout'; + +export default () => new UserCallout(); -- cgit v1.2.1 From 040167f0724027020f2d63b6e43481fb3e29dbfc Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Wed, 20 Dec 2017 19:30:58 +0100 Subject: Use seconds where possible, and convert to milliseconds for Influxdb consumption --- ...el-reduce_cardinality_of_prometheus_metrics.yml | 5 +++++ lib/gitlab/metrics/method_call.rb | 24 +++++++++------------- lib/gitlab/metrics/system.rb | 8 ++++---- spec/lib/gitlab/metrics/method_call_spec.rb | 18 ++++++++-------- spec/lib/gitlab/metrics/system_spec.rb | 4 ++-- 5 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml diff --git a/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml b/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml new file mode 100644 index 00000000000..8213b493903 --- /dev/null +++ b/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml @@ -0,0 +1,5 @@ +--- +title: Reduce the number of buckets in gitlab_cache_operation_duration_seconds +merge_request: 15881 +author: +type: changed diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index bb39b1d5462..f4a916f154d 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -4,7 +4,7 @@ module Gitlab class MethodCall MUTEX = Mutex.new BASE_LABELS = { module: nil, method: nil }.freeze - attr_reader :real_time_seconds, :cpu_time, :call_count, :labels + attr_reader :real_time, :cpu_time, :call_count, :labels def self.call_duration_histogram return @call_duration_histogram if @call_duration_histogram @@ -27,42 +27,38 @@ module Gitlab @transaction = transaction @name = name @labels = { module: @module_name, method: @method_name } - @real_time_seconds = 0.0 - @cpu_time = 0 + @real_time = 0.0 + @cpu_time = 0.0 @call_count = 0 end # Measures the real and CPU execution time of the supplied block. def measure - start_real_seconds = System.monotonic_time + start_real = System.monotonic_time start_cpu = System.cpu_time retval = yield - real_time_seconds = System.monotonic_time - start_real_seconds + real_time = System.monotonic_time - start_real cpu_time = System.cpu_time - start_cpu - @real_time_seconds += real_time_seconds + @real_time += real_time @cpu_time += cpu_time @call_count += 1 if call_measurement_enabled? && above_threshold? - self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time_seconds) + self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time) end retval end - def real_time_milliseconds - real_time_seconds.in_milliseconds.to_i - end - # Returns a Metric instance of the current method call. def to_metric Metric.new( Instrumentation.series, { - duration: real_time_milliseconds, - cpu_duration: cpu_time, + duration: real_time.in_milliseconds.to_i, + cpu_duration: cpu_time.in_milliseconds.to_i, call_count: call_count }, method: @name @@ -72,7 +68,7 @@ module Gitlab # Returns true if the total runtime of this method exceeds the method call # threshold. def above_threshold? - real_time_milliseconds >= Metrics.method_call_threshold + real_time.in_milliseconds >= Metrics.method_call_threshold end def call_measurement_enabled? diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index 4852017bf38..e60e245cf89 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -35,19 +35,19 @@ module Gitlab if Process.const_defined?(:CLOCK_THREAD_CPUTIME_ID) def self.cpu_time Process - .clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond) + .clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_second) end else def self.cpu_time Process - .clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :millisecond) + .clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :float_second) end end # Returns the current real time in a given precision. # - # Returns the time as a Fixnum. - def self.real_time(precision = :millisecond) + # Returns the time as a Float for precision = :float_second. + def self.real_time(precision = :float_second) Process.clock_gettime(Process::CLOCK_REALTIME, precision) end diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index 91a70ba01a0..448246ff513 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -8,8 +8,7 @@ describe Gitlab::Metrics::MethodCall do it 'measures the performance of the supplied block' do method_call.measure { 'foo' } - expect(method_call.real_time_seconds).to be_a_kind_of(Numeric) - expect(method_call.real_time_milliseconds).to be_a_kind_of(Numeric) + expect(method_call.real_time).to be_a_kind_of(Numeric) expect(method_call.cpu_time).to be_a_kind_of(Numeric) expect(method_call.call_count).to eq(1) end @@ -65,14 +64,17 @@ describe Gitlab::Metrics::MethodCall do describe '#to_metric' do it 'returns a Metric instance' do + expect(method_call).to receive(:real_time).and_return(4.0001) + expect(method_call).to receive(:cpu_time).and_return(3.0001) + method_call.measure { 'foo' } metric = method_call.to_metric expect(metric).to be_an_instance_of(Gitlab::Metrics::Metric) expect(metric.series).to eq('rails_method_calls') - expect(metric.values[:duration]).to be_a_kind_of(Numeric) - expect(metric.values[:cpu_duration]).to be_a_kind_of(Numeric) + expect(metric.values[:duration]).to eq(4000) + expect(metric.values[:cpu_duration]).to eq(3000) expect(metric.values[:call_count]).to be_an(Integer) expect(metric.tags).to eq({ method: 'Foo#bar' }) @@ -85,13 +87,13 @@ describe Gitlab::Metrics::MethodCall do end it 'returns false when the total call time is not above the threshold' do - expect(method_call).to receive(:real_time_seconds).and_return(0.009) + expect(method_call).to receive(:real_time).and_return(0.009) expect(method_call.above_threshold?).to eq(false) end it 'returns true when the total call time is above the threshold' do - expect(method_call).to receive(:real_time_seconds).and_return(9) + expect(method_call).to receive(:real_time).and_return(9) expect(method_call.above_threshold?).to eq(true) end @@ -132,7 +134,7 @@ describe Gitlab::Metrics::MethodCall do describe '#real_time' do context 'without timings' do it 'returns 0.0' do - expect(method_call.real_time_seconds).to eq(0.0) + expect(method_call.real_time).to eq(0.0) end end @@ -140,7 +142,7 @@ describe Gitlab::Metrics::MethodCall do it 'returns the total real time' do method_call.measure { 'foo' } - expect(method_call.real_time_seconds >= 0.0).to be(true) + expect(method_call.real_time >= 0.0).to be(true) end end end diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index ea3bd00970e..14afcdf5daa 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -29,13 +29,13 @@ describe Gitlab::Metrics::System do describe '.cpu_time' do it 'returns a Fixnum' do - expect(described_class.cpu_time).to be_an(Integer) + expect(described_class.cpu_time).to be_an(Float) end end describe '.real_time' do it 'returns a Fixnum' do - expect(described_class.real_time).to be_an(Integer) + expect(described_class.real_time).to be_an(Float) end end -- cgit v1.2.1 From 10af36f0e8dff3629c404adac0e5553086e72481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chojnacki?= Date: Wed, 20 Dec 2017 23:42:37 +0000 Subject: add missing word to pawel-reduce_cardinality_of_prometheus_metrics.yml --- .../unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml b/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml index 8213b493903..0cee0b634d6 100644 --- a/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml +++ b/changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml @@ -1,5 +1,5 @@ --- -title: Reduce the number of buckets in gitlab_cache_operation_duration_seconds +title: Reduce the number of buckets in gitlab_cache_operation_duration_seconds metric merge_request: 15881 author: type: changed -- cgit v1.2.1 From 51b416338a2ee9e287787850d11a3474e16f1474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 20 Dec 2017 17:08:28 +0100 Subject: Backport a change made in EE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- lib/api/members.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/api/members.rb b/lib/api/members.rb index 22e4bdead41..5446f6b54b1 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -59,7 +59,9 @@ module API member = source.add_user(params[:user_id], params[:access_level], current_user: current_user, expires_at: params[:expires_at]) - if member.persisted? && member.valid? + if !member + not_allowed! # This currently can only be reached in EE + elsif member.persisted? && member.valid? present member.user, with: Entities::Member, member: member else render_validation_error!(member) -- cgit v1.2.1 From 2ef5741b18d9e580025b1f93b3bb5c5488e1cc9e Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Thu, 21 Dec 2017 12:58:39 +0000 Subject: Update Dependencies --- app/assets/images/icons.json | 2 +- app/assets/images/icons.svg | 2 +- app/assets/images/illustrations/job_not_triggered.svg | 1 + app/assets/images/illustrations/manual_action.svg | 1 + app/assets/images/illustrations/merge_request_changes_empty.svg | 2 +- app/assets/images/illustrations/service_desk_callout.svg | 1 + app/assets/images/illustrations/service_desk_empty.svg | 1 + package.json | 2 +- yarn.lock | 6 +++--- 9 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 app/assets/images/illustrations/job_not_triggered.svg create mode 100644 app/assets/images/illustrations/manual_action.svg create mode 100644 app/assets/images/illustrations/service_desk_callout.svg create mode 100644 app/assets/images/illustrations/service_desk_empty.svg diff --git a/app/assets/images/icons.json b/app/assets/images/icons.json index 68d6528758b..38c1faccbf1 100644 --- a/app/assets/images/icons.json +++ b/app/assets/images/icons.json @@ -1 +1 @@ -{"iconCount":181,"spriteSize":81482,"icons":["abuse","account","admin","angle-double-left","angle-double-right","angle-down","angle-left","angle-right","angle-up","appearance","applications","approval","arrow-down","arrow-right","assignee","bold","book","branch","bullhorn","calendar","cancel","chart","chevron-down","chevron-left","chevron-right","chevron-up","clock","close","code","collapse","comment-dots","comment-next","comment","comments","commit","credit-card","cut","dashboard","disk","doc_code","doc_image","doc_text","double-headed-arrow","download","duplicate","earth","ellipsis_v","emoji_slightly_smiling_face","emoji_smile","emoji_smiley","epic","external-link","eye-slash","eye","file-addition","file-deletion","file-modified","filter","folder","fork","geo-nodes","git-merge","group","history","home","hook","hourglass","image-comment-dark","image-comment-light","import","issue-block","issue-child","issue-close","issue-duplicate","issue-new","issue-open-m","issue-open","issue-parent","issues","italic","key-2","key","label","labels","leave","level-up","license","link","list-bulleted","list-numbered","location-dot","location","lock-open","lock","log","mail","menu","merge-request-close","messages","mobile-issue-close","monitor","more","notifications-off","notifications","overview","pencil-square","pencil","pipeline","play","plus-square-o","plus-square","plus","preferences","profile","project","push-rules","question-o","question","quote","redo","remove","repeat","retry","scale","screen-full","screen-normal","scroll_down","scroll_up","search","settings","shield","slight-frown","slight-smile","smile","smiley","snippet","spam","spinner","star-o","star","status_canceled_borderless","status_canceled","status_closed","status_created_borderless","status_created","status_failed_borderless","status_failed","status_manual_borderless","status_manual","status_notfound_borderless","status_open","status_pending_borderless","status_pending","status_running_borderless","status_running","status_skipped_borderless","status_skipped","status_success_borderless","status_success_solid","status_success","status_warning_borderless","status_warning","stop","task-done","template","terminal","thumb-down","thumb-up","thumbtack","timer","todo-add","todo-done","token","unapproval","unassignee","unlink","user","users","volume-up","warning","work"]} \ No newline at end of file +{"iconCount":186,"spriteSize":84748,"icons":["abuse","account","admin","angle-double-left","angle-double-right","angle-down","angle-left","angle-right","angle-up","appearance","applications","approval","arrow-down","arrow-right","assignee","bold","book","bookmark","branch","bullhorn","calendar","cancel","chart","chevron-down","chevron-left","chevron-right","chevron-up","clock","close","code","collapse","comment-dots","comment-next","comment","comments","commit","credit-card","cut","dashboard","disk","doc_code","doc_image","doc_text","double-headed-arrow","download","duplicate","earth","ellipsis_v","emoji_slightly_smiling_face","emoji_smile","emoji_smiley","epic","external-link","eye-slash","eye","file-addition","file-deletion","file-modified","filter","folder-o","folder-open","folder","fork","geo-nodes","git-merge","group","history","home","hook","hourglass","image-comment-dark","image-comment-light","import","issue-block","issue-child","issue-close","issue-duplicate","issue-external","issue-new","issue-open-m","issue-open","issue-parent","issues","italic","key-2","key","label","labels","leave","level-up","license","link","list-bulleted","list-numbered","location-dot","location","lock-open","lock","log","mail","menu","merge-request-close","messages","mobile-issue-close","monitor","more","notifications-off","notifications","overview","pencil-square","pencil","pipeline","play","plus-square-o","plus-square","plus","podcast","preferences","profile","project","push-rules","question-o","question","quote","redo","remove","repeat","retry","scale","screen-full","screen-normal","scroll_down","scroll_up","search","settings","shield","slight-frown","slight-smile","smile","smiley","snippet","spam","spinner","star-o","star","status_canceled_borderless","status_canceled","status_closed","status_created_borderless","status_created","status_failed_borderless","status_failed","status_manual_borderless","status_manual","status_notfound_borderless","status_open","status_pending_borderless","status_pending","status_running_borderless","status_running","status_skipped_borderless","status_skipped","status_success_borderless","status_success_solid","status_success","status_warning_borderless","status_warning","stop","task-done","template","terminal","thumb-down","thumb-up","thumbtack","timer","todo-add","todo-done","token","unapproval","unassignee","unlink","user","users","volume-up","warning","work"]} \ No newline at end of file diff --git a/app/assets/images/icons.svg b/app/assets/images/icons.svg index fd8f7862911..42f5377a10e 100644 --- a/app/assets/images/icons.svg +++ b/app/assets/images/icons.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/assets/images/illustrations/job_not_triggered.svg b/app/assets/images/illustrations/job_not_triggered.svg new file mode 100644 index 00000000000..e13c1cb0a7d --- /dev/null +++ b/app/assets/images/illustrations/job_not_triggered.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/illustrations/manual_action.svg b/app/assets/images/illustrations/manual_action.svg new file mode 100644 index 00000000000..85735855b46 --- /dev/null +++ b/app/assets/images/illustrations/manual_action.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/illustrations/merge_request_changes_empty.svg b/app/assets/images/illustrations/merge_request_changes_empty.svg index 707efa736e4..40efeb2de57 100644 --- a/app/assets/images/illustrations/merge_request_changes_empty.svg +++ b/app/assets/images/illustrations/merge_request_changes_empty.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/assets/images/illustrations/service_desk_callout.svg b/app/assets/images/illustrations/service_desk_callout.svg new file mode 100644 index 00000000000..2886388279e --- /dev/null +++ b/app/assets/images/illustrations/service_desk_callout.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/illustrations/service_desk_empty.svg b/app/assets/images/illustrations/service_desk_empty.svg new file mode 100644 index 00000000000..daaaeae6a17 --- /dev/null +++ b/app/assets/images/illustrations/service_desk_empty.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/package.json b/package.json index a5bf2309a0f..48d9b125fb8 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "worker-loader": "^1.1.0" }, "devDependencies": { - "@gitlab-org/gitlab-svgs": "^1.3.0", + "@gitlab-org/gitlab-svgs": "^1.4.0", "babel-plugin-istanbul": "^4.1.5", "eslint": "^3.10.1", "eslint-config-airbnb-base": "^10.0.1", diff --git a/yarn.lock b/yarn.lock index 55d0d33c9f2..438bfb46c79 100644 --- a/yarn.lock +++ b/yarn.lock @@ -54,9 +54,9 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@gitlab-org/gitlab-svgs@^1.3.0": - version "1.3.0" - resolved "https://registry.yarnpkg.com/@gitlab-org/gitlab-svgs/-/gitlab-svgs-1.3.0.tgz#07f2aa75d6e0e857eaa20c38a3bad7e6c22c420c" +"@gitlab-org/gitlab-svgs@^1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@gitlab-org/gitlab-svgs/-/gitlab-svgs-1.4.0.tgz#83c0a76485c1378babf2e83456b4d2442efa98e8" "@types/jquery@^2.0.40": version "2.0.48" -- cgit v1.2.1 From 66c03aaa4c5fd8902310740b229d9caf49d7bc25 Mon Sep 17 00:00:00 2001 From: Sam Galson Date: Thu, 21 Dec 2017 13:05:19 +0000 Subject: Fix prometheus arg in prometheus.yml --- doc/user/project/integrations/samples/prometheus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/project/integrations/samples/prometheus.yml b/doc/user/project/integrations/samples/prometheus.yml index 30b59e172a1..3a4735d282f 100644 --- a/doc/user/project/integrations/samples/prometheus.yml +++ b/doc/user/project/integrations/samples/prometheus.yml @@ -94,7 +94,7 @@ spec: - name: prometheus image: prom/prometheus:latest args: - - '-config.file=/prometheus-data/prometheus.yml' + - '--config.file=/prometheus-data/prometheus.yml' ports: - name: prometheus containerPort: 9090 -- cgit v1.2.1 From 6b23e9d923c816fd9ed903424fd909a08f3c51fe Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 21 Dec 2017 08:31:56 -0500 Subject: docs: fix a typo in LFS documentation --- doc/workflow/lfs/manage_large_binaries_with_git_lfs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/workflow/lfs/manage_large_binaries_with_git_lfs.md b/doc/workflow/lfs/manage_large_binaries_with_git_lfs.md index 195285f9157..f7b87dee8e1 100644 --- a/doc/workflow/lfs/manage_large_binaries_with_git_lfs.md +++ b/doc/workflow/lfs/manage_large_binaries_with_git_lfs.md @@ -170,4 +170,4 @@ GitLab checks files to detect LFS pointers on push. If LFS pointers are detected Verify that LFS in installed locally and consider a manual push with `git lfs push --all`. -If you are storing LFS files outside of GitLab you can disable LFS on the project by settting `lfs_enabled: false` with the [projets api](../../api/projects.md#edit-project). +If you are storing LFS files outside of GitLab you can disable LFS on the project by settting `lfs_enabled: false` with the [projects api](../../api/projects.md#edit-project). -- cgit v1.2.1 From c27c65f97ac6c02a73661ebd66e728b6fd4a6039 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 21 Dec 2017 14:03:15 +0100 Subject: Fall back to the `MergeRequestWidgetEntity` When no serializer was passed. --- app/serializers/merge_request_serializer.rb | 2 +- spec/controllers/projects/merge_requests_controller_spec.rb | 8 ++++++++ spec/serializers/merge_request_serializer_spec.rb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/serializers/merge_request_serializer.rb b/app/serializers/merge_request_serializer.rb index 52eb30d688a..caf193bdae3 100644 --- a/app/serializers/merge_request_serializer.rb +++ b/app/serializers/merge_request_serializer.rb @@ -7,7 +7,7 @@ class MergeRequestSerializer < BaseSerializer case opts[:serializer] when 'basic', 'sidebar' MergeRequestBasicEntity - when 'widget' + else # It's 'widget' MergeRequestWidgetEntity end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 58116e6e0fe..45c424af8c4 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -98,6 +98,14 @@ describe Projects::MergeRequestsController do expect(response).to match_response_schema('entities/merge_request_widget') end end + + context 'when no serialiser was passed' do + it 'renders widget MR entity as json' do + go(serializer: nil, format: :json) + + expect(response).to match_response_schema('entities/merge_request_widget') + end + end end describe "as diff" do diff --git a/spec/serializers/merge_request_serializer_spec.rb b/spec/serializers/merge_request_serializer_spec.rb index 1ad974c774b..b259cb92962 100644 --- a/spec/serializers/merge_request_serializer_spec.rb +++ b/spec/serializers/merge_request_serializer_spec.rb @@ -36,8 +36,8 @@ describe MergeRequestSerializer do context 'no serializer' do let(:serializer) { nil } - it 'raises an error' do - expect { json_entity }.to raise_error(NoMethodError) + it 'falls back to the widget entity' do + expect(json_entity).to match_schema('entities/merge_request_widget') end end end -- cgit v1.2.1 From d2f1d585e10e3e728f968ceae6b275e4d9bc59f4 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Fri, 15 Dec 2017 11:21:12 +0100 Subject: Skip projects filter on merge requests search When searching for merge requests, an additional subquery is added which by default filters only merge requests which belong to source or target project user has permission for. This filter is not needed because more restrictive filter which checks if user has permission for target project is used in the query. So unless a custom projects filter is used by user, it's possible to skip the default projects filter and speed up the final query. Related to #40540 --- app/services/search/global_service.rb | 5 ++++- app/services/search/group_service.rb | 1 + changelogs/unreleased/15955-improve-search-query.yml | 5 +++++ lib/gitlab/search_results.rb | 15 +++++++++++++-- spec/lib/gitlab/search_results_spec.rb | 11 +++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/15955-improve-search-query.yml diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index ff188102b62..92a32e703af 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -1,13 +1,16 @@ module Search class GlobalService attr_accessor :current_user, :params + attr_reader :default_project_filter def initialize(user, params) @current_user, @params = user, params.dup + @default_project_filter = true end def execute - Gitlab::SearchResults.new(current_user, projects, params[:search]) + Gitlab::SearchResults.new(current_user, projects, params[:search], + default_project_filter: default_project_filter) end def projects diff --git a/app/services/search/group_service.rb b/app/services/search/group_service.rb index 29478e3251f..b4efba68715 100644 --- a/app/services/search/group_service.rb +++ b/app/services/search/group_service.rb @@ -5,6 +5,7 @@ module Search def initialize(user, group, params) super(user, params) + @default_project_filter = false @group = group end diff --git a/changelogs/unreleased/15955-improve-search-query.yml b/changelogs/unreleased/15955-improve-search-query.yml new file mode 100644 index 00000000000..80cb8af617f --- /dev/null +++ b/changelogs/unreleased/15955-improve-search-query.yml @@ -0,0 +1,5 @@ +--- +title: Improve search query for merge requests. +merge_request: +author: +type: performance diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index fef9d3e31d4..7037e2e61cc 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -27,10 +27,17 @@ module Gitlab # It allows us to search only for projects user has access to attr_reader :limit_projects - def initialize(current_user, limit_projects, query) + # Whether a custom filter is used to restrict scope of projects. + # If the default filter (which lists all projects user has access to) + # is used, we can skip it when filtering merge requests and optimize the + # query + attr_reader :default_project_filter + + def initialize(current_user, limit_projects, query, default_project_filter: false) @current_user = current_user @limit_projects = limit_projects || Project.all @query = query + @default_project_filter = default_project_filter end def objects(scope, page = nil) @@ -94,7 +101,11 @@ module Gitlab end def merge_requests - merge_requests = MergeRequestsFinder.new(current_user).execute.in_projects(project_ids_relation) + merge_requests = MergeRequestsFinder.new(current_user).execute + unless default_project_filter + merge_requests = merge_requests.in_projects(project_ids_relation) + end + merge_requests = if query =~ /[#!](\d+)\z/ merge_requests.where(iid: $1) diff --git a/spec/lib/gitlab/search_results_spec.rb b/spec/lib/gitlab/search_results_spec.rb index e44a7c23452..a958baab44f 100644 --- a/spec/lib/gitlab/search_results_spec.rb +++ b/spec/lib/gitlab/search_results_spec.rb @@ -51,6 +51,17 @@ describe Gitlab::SearchResults do expect(results.objects('merge_requests')).to include merge_request_2 end + + it 'includes project filter by default' do + expect(results).to receive(:project_ids_relation).and_call_original + results.objects('merge_requests') + end + + it 'it skips project filter if default is used' do + allow(results).to receive(:default_project_filter).and_return(true) + expect(results).not_to receive(:project_ids_relation) + results.objects('merge_requests') + end end it 'does not list issues on private projects' do -- cgit v1.2.1 From 5cdd246bd994b09815a14d550c2c334cc48aa35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 19 Dec 2017 16:44:14 +0100 Subject: Update Ruby version to 2.3.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- .gitlab-ci.yml | 2 +- .ruby-version | 2 +- changelogs/unreleased/41268-bump-ruby-to-2-3-6.yml | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/41268-bump-ruby-to-2-3-6.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c26e7f0aeba..edb1069e54f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.3.5-golang-1.8-git-2.14-chrome-63.0-node-8.x-yarn-1.2-postgresql-9.6" +image: "dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.3.6-golang-1.9-git-2.14-chrome-63.0-node-8.x-yarn-1.2-postgresql-9.6" .dedicated-runner: &dedicated-runner retry: 1 diff --git a/.ruby-version b/.ruby-version index cc6c9a491e0..e75da3e63d6 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.5 +2.3.6 diff --git a/changelogs/unreleased/41268-bump-ruby-to-2-3-6.yml b/changelogs/unreleased/41268-bump-ruby-to-2-3-6.yml new file mode 100644 index 00000000000..188a854ebee --- /dev/null +++ b/changelogs/unreleased/41268-bump-ruby-to-2-3-6.yml @@ -0,0 +1,5 @@ +--- +title: Upgrade Ruby to 2.3.6 to include security patches +merge_request: 16016 +author: +type: security -- cgit v1.2.1 From 213e91d43926f09eb969859aa2c306eeb127deb4 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Thu, 21 Dec 2017 15:05:47 +0000 Subject: Resolve "Decouple multi-file editor from file list" --- app/assets/javascripts/api.js | 14 +- app/assets/javascripts/dispatcher.js | 5 - app/assets/javascripts/fly_out_nav.js | 17 +- .../javascripts/helpers/user_feature_helper.js | 7 - .../ide/components/commit_sidebar/list.vue | 66 +++++ .../components/commit_sidebar/list_collapsed.vue | 35 +++ .../ide/components/commit_sidebar/list_item.vue | 36 +++ app/assets/javascripts/ide/components/ide.vue | 73 +++++ .../javascripts/ide/components/ide_context_bar.vue | 75 +++++ .../ide/components/ide_project_branches_tree.vue | 47 +++ .../ide/components/ide_project_tree.vue | 47 +++ .../javascripts/ide/components/ide_repo_tree.vue | 66 +++++ .../javascripts/ide/components/ide_side_bar.vue | 62 ++++ .../javascripts/ide/components/ide_status_bar.vue | 71 +++++ .../javascripts/ide/components/new_branch_form.vue | 108 +++++++ .../ide/components/new_dropdown/index.vue | 101 +++++++ .../ide/components/new_dropdown/modal.vue | 112 +++++++ .../ide/components/new_dropdown/upload.vue | 87 ++++++ .../ide/components/repo_commit_section.vue | 171 +++++++++++ .../ide/components/repo_edit_button.vue | 57 ++++ .../javascripts/ide/components/repo_editor.vue | 127 ++++++++ .../javascripts/ide/components/repo_file.vue | 165 +++++++++++ .../ide/components/repo_file_buttons.vue | 56 ++++ .../ide/components/repo_loading_file.vue | 44 +++ .../ide/components/repo_prev_directory.vue | 32 ++ .../javascripts/ide/components/repo_preview.vue | 65 ++++ app/assets/javascripts/ide/components/repo_tab.vue | 69 +++++ .../javascripts/ide/components/repo_tabs.vue | 27 ++ app/assets/javascripts/ide/ide_router.js | 101 +++++++ app/assets/javascripts/ide/index.js | 55 ++++ .../javascripts/ide/lib/common/disposable.js | 14 + app/assets/javascripts/ide/lib/common/model.js | 64 ++++ .../javascripts/ide/lib/common/model_manager.js | 32 ++ .../javascripts/ide/lib/decorations/controller.js | 43 +++ app/assets/javascripts/ide/lib/diff/controller.js | 71 +++++ app/assets/javascripts/ide/lib/diff/diff.js | 30 ++ app/assets/javascripts/ide/lib/diff/diff_worker.js | 10 + app/assets/javascripts/ide/lib/editor.js | 109 +++++++ app/assets/javascripts/ide/lib/editor_options.js | 2 + app/assets/javascripts/ide/monaco_loader.js | 11 + app/assets/javascripts/ide/services/index.js | 47 +++ app/assets/javascripts/ide/stores/actions.js | 179 +++++++++++ .../javascripts/ide/stores/actions/branch.js | 43 +++ app/assets/javascripts/ide/stores/actions/file.js | 131 +++++++++ .../javascripts/ide/stores/actions/project.js | 25 ++ app/assets/javascripts/ide/stores/actions/tree.js | 188 ++++++++++++ app/assets/javascripts/ide/stores/getters.js | 19 ++ app/assets/javascripts/ide/stores/index.js | 15 + .../javascripts/ide/stores/mutation_types.js | 45 +++ app/assets/javascripts/ide/stores/mutations.js | 65 ++++ .../javascripts/ide/stores/mutations/branch.js | 28 ++ .../javascripts/ide/stores/mutations/file.js | 74 +++++ .../javascripts/ide/stores/mutations/project.js | 23 ++ .../javascripts/ide/stores/mutations/tree.js | 36 +++ app/assets/javascripts/ide/stores/state.js | 22 ++ app/assets/javascripts/ide/stores/utils.js | 175 +++++++++++ app/assets/javascripts/new_commit_form.js | 7 +- .../repo/components/commit_sidebar/list.vue | 89 ------ .../components/commit_sidebar/list_collapsed.vue | 35 --- .../repo/components/commit_sidebar/list_item.vue | 36 --- .../repo/components/new_branch_form.vue | 108 ------- .../repo/components/new_dropdown/index.vue | 89 ------ .../repo/components/new_dropdown/modal.vue | 98 ------- .../repo/components/new_dropdown/upload.vue | 68 ----- app/assets/javascripts/repo/components/repo.vue | 63 ---- .../repo/components/repo_commit_section.vue | 178 ----------- .../repo/components/repo_edit_button.vue | 57 ---- .../javascripts/repo/components/repo_editor.vue | 89 ------ .../javascripts/repo/components/repo_file.vue | 117 -------- .../repo/components/repo_file_buttons.vue | 56 ---- .../repo/components/repo_loading_file.vue | 44 --- .../repo/components/repo_prev_directory.vue | 34 --- .../javascripts/repo/components/repo_preview.vue | 65 ---- .../javascripts/repo/components/repo_sidebar.vue | 85 ------ .../javascripts/repo/components/repo_tab.vue | 67 ----- .../javascripts/repo/components/repo_tabs.vue | 27 -- app/assets/javascripts/repo/index.js | 106 ------- .../javascripts/repo/lib/common/disposable.js | 14 - app/assets/javascripts/repo/lib/common/model.js | 56 ---- .../javascripts/repo/lib/common/model_manager.js | 32 -- .../javascripts/repo/lib/decorations/controller.js | 43 --- app/assets/javascripts/repo/lib/diff/controller.js | 71 ----- app/assets/javascripts/repo/lib/diff/diff.js | 30 -- .../javascripts/repo/lib/diff/diff_worker.js | 10 - app/assets/javascripts/repo/lib/editor.js | 79 ----- app/assets/javascripts/repo/lib/editor_options.js | 2 - app/assets/javascripts/repo/monaco_loader.js | 11 - app/assets/javascripts/repo/services/index.js | 44 --- app/assets/javascripts/repo/stores/actions.js | 146 --------- .../javascripts/repo/stores/actions/branch.js | 20 -- app/assets/javascripts/repo/stores/actions/file.js | 110 ------- app/assets/javascripts/repo/stores/actions/tree.js | 163 ----------- app/assets/javascripts/repo/stores/getters.js | 40 --- app/assets/javascripts/repo/stores/index.js | 15 - .../javascripts/repo/stores/mutation_types.js | 30 -- app/assets/javascripts/repo/stores/mutations.js | 61 ---- .../javascripts/repo/stores/mutations/branch.js | 9 - .../javascripts/repo/stores/mutations/file.js | 54 ---- .../javascripts/repo/stores/mutations/tree.js | 27 -- app/assets/javascripts/repo/stores/state.js | 24 -- app/assets/javascripts/repo/stores/utils.js | 127 -------- .../vue_shared/components/project_avatar/image.vue | 103 +++++++ .../stylesheets/framework/contextual-sidebar.scss | 1 - app/assets/stylesheets/framework/variables.scss | 1 + app/assets/stylesheets/pages/repo.scss | 239 +++++++++++++-- app/controllers/ide_controller.rb | 6 + app/helpers/application_helper.rb | 2 +- app/helpers/blob_helper.rb | 43 ++- app/views/ide/index.html.haml | 12 + app/views/layouts/nav_only.html.haml | 13 + app/views/projects/_files.html.haml | 2 +- app/views/projects/blob/_header.html.haml | 1 + app/views/projects/blob/show.html.haml | 15 +- .../projects/tree/_old_tree_content.html.haml | 24 -- app/views/projects/tree/_old_tree_header.html.haml | 64 ---- app/views/projects/tree/_tree_content.html.haml | 29 +- app/views/projects/tree/_tree_header.html.haml | 78 ++++- app/views/projects/tree/show.html.haml | 7 +- app/views/shared/_ref_switcher.html.haml | 2 +- app/views/shared/repo/_repo.html.haml | 13 - ...0-decouple-multi-file-editor-from-file-list.yml | 5 + config/routes.rb | 2 + config/webpack.config.js | 4 +- package.json | 1 + spec/features/projects/ref_switcher_spec.rb | 78 ----- .../projects/tree/create_directory_spec.rb | 26 +- spec/features/projects/tree/create_file_spec.rb | 16 +- spec/features/projects/tree/upload_file_spec.rb | 9 +- .../commit_sidebar/list_collapsed_spec.js | 4 +- .../components/commit_sidebar/list_item_spec.js | 2 +- .../repo/components/commit_sidebar/list_spec.js | 29 +- .../repo/components/ide_context_bar_spec.js | 49 ++++ .../repo/components/ide_repo_tree_spec.js | 63 ++++ .../repo/components/ide_side_bar_spec.js | 43 +++ spec/javascripts/repo/components/ide_spec.js | 37 +++ .../repo/components/new_branch_form_spec.js | 4 +- .../repo/components/new_dropdown/index_spec.js | 17 +- .../repo/components/new_dropdown/modal_spec.js | 149 ++++++---- .../repo/components/new_dropdown/upload_spec.js | 81 ++++- .../repo/components/repo_commit_section_spec.js | 33 ++- .../repo/components/repo_edit_button_spec.js | 8 +- .../repo/components/repo_editor_spec.js | 6 +- .../repo/components/repo_file_buttons_spec.js | 4 +- spec/javascripts/repo/components/repo_file_spec.js | 13 +- .../repo/components/repo_loading_file_spec.js | 5 +- .../repo/components/repo_prev_directory_spec.js | 4 +- .../repo/components/repo_preview_spec.js | 4 +- .../repo/components/repo_sidebar_spec.js | 62 ---- spec/javascripts/repo/components/repo_spec.js | 35 --- spec/javascripts/repo/components/repo_tab_spec.js | 10 +- spec/javascripts/repo/components/repo_tabs_spec.js | 4 +- spec/javascripts/repo/helpers.js | 5 +- .../javascripts/repo/lib/common/disposable_spec.js | 2 +- .../repo/lib/common/model_manager_spec.js | 4 +- spec/javascripts/repo/lib/common/model_spec.js | 4 +- .../repo/lib/decorations/controller_spec.js | 8 +- spec/javascripts/repo/lib/diff/controller_spec.js | 12 +- spec/javascripts/repo/lib/diff/diff_spec.js | 2 +- spec/javascripts/repo/lib/editor_options_spec.js | 2 +- spec/javascripts/repo/lib/editor_spec.js | 4 +- spec/javascripts/repo/monaco_loader_spec.js | 2 +- .../javascripts/repo/stores/actions/branch_spec.js | 20 +- spec/javascripts/repo/stores/actions/file_spec.js | 75 ++--- spec/javascripts/repo/stores/actions/tree_spec.js | 326 +++++++-------------- spec/javascripts/repo/stores/actions_spec.js | 95 +++--- spec/javascripts/repo/stores/getters_spec.js | 38 +-- .../repo/stores/mutations/branch_spec.js | 6 +- .../javascripts/repo/stores/mutations/file_spec.js | 4 +- .../javascripts/repo/stores/mutations/tree_spec.js | 4 +- spec/javascripts/repo/stores/mutations_spec.js | 40 ++- spec/javascripts/repo/stores/utils_spec.js | 43 ++- yarn.lock | 4 + 172 files changed, 4765 insertions(+), 3632 deletions(-) delete mode 100644 app/assets/javascripts/helpers/user_feature_helper.js create mode 100644 app/assets/javascripts/ide/components/commit_sidebar/list.vue create mode 100644 app/assets/javascripts/ide/components/commit_sidebar/list_collapsed.vue create mode 100644 app/assets/javascripts/ide/components/commit_sidebar/list_item.vue create mode 100644 app/assets/javascripts/ide/components/ide.vue create mode 100644 app/assets/javascripts/ide/components/ide_context_bar.vue create mode 100644 app/assets/javascripts/ide/components/ide_project_branches_tree.vue create mode 100644 app/assets/javascripts/ide/components/ide_project_tree.vue create mode 100644 app/assets/javascripts/ide/components/ide_repo_tree.vue create mode 100644 app/assets/javascripts/ide/components/ide_side_bar.vue create mode 100644 app/assets/javascripts/ide/components/ide_status_bar.vue create mode 100644 app/assets/javascripts/ide/components/new_branch_form.vue create mode 100644 app/assets/javascripts/ide/components/new_dropdown/index.vue create mode 100644 app/assets/javascripts/ide/components/new_dropdown/modal.vue create mode 100644 app/assets/javascripts/ide/components/new_dropdown/upload.vue create mode 100644 app/assets/javascripts/ide/components/repo_commit_section.vue create mode 100644 app/assets/javascripts/ide/components/repo_edit_button.vue create mode 100644 app/assets/javascripts/ide/components/repo_editor.vue create mode 100644 app/assets/javascripts/ide/components/repo_file.vue create mode 100644 app/assets/javascripts/ide/components/repo_file_buttons.vue create mode 100644 app/assets/javascripts/ide/components/repo_loading_file.vue create mode 100644 app/assets/javascripts/ide/components/repo_prev_directory.vue create mode 100644 app/assets/javascripts/ide/components/repo_preview.vue create mode 100644 app/assets/javascripts/ide/components/repo_tab.vue create mode 100644 app/assets/javascripts/ide/components/repo_tabs.vue create mode 100644 app/assets/javascripts/ide/ide_router.js create mode 100644 app/assets/javascripts/ide/index.js create mode 100644 app/assets/javascripts/ide/lib/common/disposable.js create mode 100644 app/assets/javascripts/ide/lib/common/model.js create mode 100644 app/assets/javascripts/ide/lib/common/model_manager.js create mode 100644 app/assets/javascripts/ide/lib/decorations/controller.js create mode 100644 app/assets/javascripts/ide/lib/diff/controller.js create mode 100644 app/assets/javascripts/ide/lib/diff/diff.js create mode 100644 app/assets/javascripts/ide/lib/diff/diff_worker.js create mode 100644 app/assets/javascripts/ide/lib/editor.js create mode 100644 app/assets/javascripts/ide/lib/editor_options.js create mode 100644 app/assets/javascripts/ide/monaco_loader.js create mode 100644 app/assets/javascripts/ide/services/index.js create mode 100644 app/assets/javascripts/ide/stores/actions.js create mode 100644 app/assets/javascripts/ide/stores/actions/branch.js create mode 100644 app/assets/javascripts/ide/stores/actions/file.js create mode 100644 app/assets/javascripts/ide/stores/actions/project.js create mode 100644 app/assets/javascripts/ide/stores/actions/tree.js create mode 100644 app/assets/javascripts/ide/stores/getters.js create mode 100644 app/assets/javascripts/ide/stores/index.js create mode 100644 app/assets/javascripts/ide/stores/mutation_types.js create mode 100644 app/assets/javascripts/ide/stores/mutations.js create mode 100644 app/assets/javascripts/ide/stores/mutations/branch.js create mode 100644 app/assets/javascripts/ide/stores/mutations/file.js create mode 100644 app/assets/javascripts/ide/stores/mutations/project.js create mode 100644 app/assets/javascripts/ide/stores/mutations/tree.js create mode 100644 app/assets/javascripts/ide/stores/state.js create mode 100644 app/assets/javascripts/ide/stores/utils.js delete mode 100644 app/assets/javascripts/repo/components/commit_sidebar/list.vue delete mode 100644 app/assets/javascripts/repo/components/commit_sidebar/list_collapsed.vue delete mode 100644 app/assets/javascripts/repo/components/commit_sidebar/list_item.vue delete mode 100644 app/assets/javascripts/repo/components/new_branch_form.vue delete mode 100644 app/assets/javascripts/repo/components/new_dropdown/index.vue delete mode 100644 app/assets/javascripts/repo/components/new_dropdown/modal.vue delete mode 100644 app/assets/javascripts/repo/components/new_dropdown/upload.vue delete mode 100644 app/assets/javascripts/repo/components/repo.vue delete mode 100644 app/assets/javascripts/repo/components/repo_commit_section.vue delete mode 100644 app/assets/javascripts/repo/components/repo_edit_button.vue delete mode 100644 app/assets/javascripts/repo/components/repo_editor.vue delete mode 100644 app/assets/javascripts/repo/components/repo_file.vue delete mode 100644 app/assets/javascripts/repo/components/repo_file_buttons.vue delete mode 100644 app/assets/javascripts/repo/components/repo_loading_file.vue delete mode 100644 app/assets/javascripts/repo/components/repo_prev_directory.vue delete mode 100644 app/assets/javascripts/repo/components/repo_preview.vue delete mode 100644 app/assets/javascripts/repo/components/repo_sidebar.vue delete mode 100644 app/assets/javascripts/repo/components/repo_tab.vue delete mode 100644 app/assets/javascripts/repo/components/repo_tabs.vue delete mode 100644 app/assets/javascripts/repo/index.js delete mode 100644 app/assets/javascripts/repo/lib/common/disposable.js delete mode 100644 app/assets/javascripts/repo/lib/common/model.js delete mode 100644 app/assets/javascripts/repo/lib/common/model_manager.js delete mode 100644 app/assets/javascripts/repo/lib/decorations/controller.js delete mode 100644 app/assets/javascripts/repo/lib/diff/controller.js delete mode 100644 app/assets/javascripts/repo/lib/diff/diff.js delete mode 100644 app/assets/javascripts/repo/lib/diff/diff_worker.js delete mode 100644 app/assets/javascripts/repo/lib/editor.js delete mode 100644 app/assets/javascripts/repo/lib/editor_options.js delete mode 100644 app/assets/javascripts/repo/monaco_loader.js delete mode 100644 app/assets/javascripts/repo/services/index.js delete mode 100644 app/assets/javascripts/repo/stores/actions.js delete mode 100644 app/assets/javascripts/repo/stores/actions/branch.js delete mode 100644 app/assets/javascripts/repo/stores/actions/file.js delete mode 100644 app/assets/javascripts/repo/stores/actions/tree.js delete mode 100644 app/assets/javascripts/repo/stores/getters.js delete mode 100644 app/assets/javascripts/repo/stores/index.js delete mode 100644 app/assets/javascripts/repo/stores/mutation_types.js delete mode 100644 app/assets/javascripts/repo/stores/mutations.js delete mode 100644 app/assets/javascripts/repo/stores/mutations/branch.js delete mode 100644 app/assets/javascripts/repo/stores/mutations/file.js delete mode 100644 app/assets/javascripts/repo/stores/mutations/tree.js delete mode 100644 app/assets/javascripts/repo/stores/state.js delete mode 100644 app/assets/javascripts/repo/stores/utils.js create mode 100644 app/assets/javascripts/vue_shared/components/project_avatar/image.vue create mode 100644 app/controllers/ide_controller.rb create mode 100644 app/views/ide/index.html.haml create mode 100644 app/views/layouts/nav_only.html.haml delete mode 100644 app/views/projects/tree/_old_tree_content.html.haml delete mode 100644 app/views/projects/tree/_old_tree_header.html.haml delete mode 100644 app/views/shared/repo/_repo.html.haml create mode 100644 changelogs/unreleased/40040-decouple-multi-file-editor-from-file-list.yml delete mode 100644 spec/features/projects/ref_switcher_spec.rb create mode 100644 spec/javascripts/repo/components/ide_context_bar_spec.js create mode 100644 spec/javascripts/repo/components/ide_repo_tree_spec.js create mode 100644 spec/javascripts/repo/components/ide_side_bar_spec.js create mode 100644 spec/javascripts/repo/components/ide_spec.js delete mode 100644 spec/javascripts/repo/components/repo_sidebar_spec.js delete mode 100644 spec/javascripts/repo/components/repo_spec.js diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js index d963101028a..21d8c790e90 100644 --- a/app/assets/javascripts/api.js +++ b/app/assets/javascripts/api.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +import axios from './lib/utils/axios_utils'; const Api = { groupsPath: '/api/:version/groups.json', @@ -6,6 +7,7 @@ const Api = { namespacesPath: '/api/:version/namespaces.json', groupProjectsPath: '/api/:version/groups/:id/projects.json', projectsPath: '/api/:version/projects.json', + projectPath: '/api/:version/projects/:id', projectLabelsPath: '/:namespace_path/:project_path/labels', groupLabelsPath: '/groups/:namespace_path/labels', licensePath: '/api/:version/templates/licenses/:key', @@ -76,6 +78,14 @@ const Api = { .done(projects => callback(projects)); }, + // Return single project + project(projectPath) { + const url = Api.buildUrl(Api.projectPath) + .replace(':id', encodeURIComponent(projectPath)); + + return axios.get(url); + }, + newLabel(namespacePath, projectPath, data, callback) { let url; @@ -115,7 +125,7 @@ const Api = { commitMultiple(id, data) { // see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions const url = Api.buildUrl(Api.commitPath) - .replace(':id', id); + .replace(':id', encodeURIComponent(id)); return this.wrapAjaxCall({ url, type: 'POST', @@ -127,7 +137,7 @@ const Api = { branchSingle(id, branch) { const url = Api.buildUrl(Api.branchSinglePath) - .replace(':id', id) + .replace(':id', encodeURIComponent(id)) .replace(':branch', branch); return this.wrapAjaxCall({ diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 62867c56214..07df3c216b1 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -73,7 +73,6 @@ import initLegacyFilters from './init_legacy_filters'; import initIssuableSidebar from './init_issuable_sidebar'; import initProjectVisibilitySelector from './project_visibility'; import GpgBadges from './gpg_badges'; -import UserFeatureHelper from './helpers/user_feature_helper'; import initChangesDropdown from './init_changes_dropdown'; import NewGroupChild from './groups/new_group_child'; import AbuseReports from './abuse_reports'; @@ -447,9 +446,6 @@ import Activities from './activities'; break; case 'projects:tree:show': shortcut_handler = new ShortcutsNavigation(); - - if (UserFeatureHelper.isNewRepoEnabled()) break; - new TreeView(); new BlobViewer(); new NewCommitForm($('.js-create-dir-form')); @@ -468,7 +464,6 @@ import Activities from './activities'; shortcut_handler = true; break; case 'projects:blob:show': - if (UserFeatureHelper.isNewRepoEnabled()) break; new BlobViewer(); initBlob(); break; diff --git a/app/assets/javascripts/fly_out_nav.js b/app/assets/javascripts/fly_out_nav.js index 6110d961609..abb04d77f8f 100644 --- a/app/assets/javascripts/fly_out_nav.js +++ b/app/assets/javascripts/fly_out_nav.js @@ -161,13 +161,16 @@ export default () => { const items = [...sidebar.querySelectorAll('.sidebar-top-level-items > li')]; - sidebar.querySelector('.sidebar-top-level-items').addEventListener('mouseleave', () => { - clearTimeout(timeoutId); - - timeoutId = setTimeout(() => { - if (currentOpenMenu) hideMenu(currentOpenMenu); - }, getHideSubItemsInterval()); - }); + const topItems = sidebar.querySelector('.sidebar-top-level-items'); + if (topItems) { + sidebar.querySelector('.sidebar-top-level-items').addEventListener('mouseleave', () => { + clearTimeout(timeoutId); + + timeoutId = setTimeout(() => { + if (currentOpenMenu) hideMenu(currentOpenMenu); + }, getHideSubItemsInterval()); + }); + } headerHeight = document.querySelector('.nav-sidebar').offsetTop; diff --git a/app/assets/javascripts/helpers/user_feature_helper.js b/app/assets/javascripts/helpers/user_feature_helper.js deleted file mode 100644 index 638118a5204..00000000000 --- a/app/assets/javascripts/helpers/user_feature_helper.js +++ /dev/null @@ -1,7 +0,0 @@ -import Cookies from 'js-cookie'; - -export default { - isNewRepoEnabled() { - return Cookies.get('new_repo') === 'true'; - }, -}; diff --git a/app/assets/javascripts/ide/components/commit_sidebar/list.vue b/app/assets/javascripts/ide/components/commit_sidebar/list.vue new file mode 100644 index 00000000000..704dff981df --- /dev/null +++ b/app/assets/javascripts/ide/components/commit_sidebar/list.vue @@ -0,0 +1,66 @@ + + + diff --git a/app/assets/javascripts/ide/components/commit_sidebar/list_collapsed.vue b/app/assets/javascripts/ide/components/commit_sidebar/list_collapsed.vue new file mode 100644 index 00000000000..6a0262f271b --- /dev/null +++ b/app/assets/javascripts/ide/components/commit_sidebar/list_collapsed.vue @@ -0,0 +1,35 @@ + + + diff --git a/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue b/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue new file mode 100644 index 00000000000..742f746e02f --- /dev/null +++ b/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue @@ -0,0 +1,36 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide.vue b/app/assets/javascripts/ide/components/ide.vue new file mode 100644 index 00000000000..7f29a355eca --- /dev/null +++ b/app/assets/javascripts/ide/components/ide.vue @@ -0,0 +1,73 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_context_bar.vue b/app/assets/javascripts/ide/components/ide_context_bar.vue new file mode 100644 index 00000000000..5a08718e386 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_context_bar.vue @@ -0,0 +1,75 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_project_branches_tree.vue b/app/assets/javascripts/ide/components/ide_project_branches_tree.vue new file mode 100644 index 00000000000..bd3a521ff43 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_project_branches_tree.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_project_tree.vue b/app/assets/javascripts/ide/components/ide_project_tree.vue new file mode 100644 index 00000000000..61daba6d176 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_project_tree.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_repo_tree.vue b/app/assets/javascripts/ide/components/ide_repo_tree.vue new file mode 100644 index 00000000000..b6b089e6b25 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_repo_tree.vue @@ -0,0 +1,66 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_side_bar.vue b/app/assets/javascripts/ide/components/ide_side_bar.vue new file mode 100644 index 00000000000..535398d98c2 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_side_bar.vue @@ -0,0 +1,62 @@ + + + diff --git a/app/assets/javascripts/ide/components/ide_status_bar.vue b/app/assets/javascripts/ide/components/ide_status_bar.vue new file mode 100644 index 00000000000..a24abadd936 --- /dev/null +++ b/app/assets/javascripts/ide/components/ide_status_bar.vue @@ -0,0 +1,71 @@ + + + diff --git a/app/assets/javascripts/ide/components/new_branch_form.vue b/app/assets/javascripts/ide/components/new_branch_form.vue new file mode 100644 index 00000000000..2119d373d31 --- /dev/null +++ b/app/assets/javascripts/ide/components/new_branch_form.vue @@ -0,0 +1,108 @@ + + + diff --git a/app/assets/javascripts/ide/components/new_dropdown/index.vue b/app/assets/javascripts/ide/components/new_dropdown/index.vue new file mode 100644 index 00000000000..6e67e99a70f --- /dev/null +++ b/app/assets/javascripts/ide/components/new_dropdown/index.vue @@ -0,0 +1,101 @@ + + + diff --git a/app/assets/javascripts/ide/components/new_dropdown/modal.vue b/app/assets/javascripts/ide/components/new_dropdown/modal.vue new file mode 100644 index 00000000000..a0650d37690 --- /dev/null +++ b/app/assets/javascripts/ide/components/new_dropdown/modal.vue @@ -0,0 +1,112 @@ + + + diff --git a/app/assets/javascripts/ide/components/new_dropdown/upload.vue b/app/assets/javascripts/ide/components/new_dropdown/upload.vue new file mode 100644 index 00000000000..2a2f2a241fc --- /dev/null +++ b/app/assets/javascripts/ide/components/new_dropdown/upload.vue @@ -0,0 +1,87 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_commit_section.vue b/app/assets/javascripts/ide/components/repo_commit_section.vue new file mode 100644 index 00000000000..470db2c9650 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_commit_section.vue @@ -0,0 +1,171 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_edit_button.vue b/app/assets/javascripts/ide/components/repo_edit_button.vue new file mode 100644 index 00000000000..37bd9003e96 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_edit_button.vue @@ -0,0 +1,57 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_editor.vue b/app/assets/javascripts/ide/components/repo_editor.vue new file mode 100644 index 00000000000..221be4b9074 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_editor.vue @@ -0,0 +1,127 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_file.vue b/app/assets/javascripts/ide/components/repo_file.vue new file mode 100644 index 00000000000..09ca11531b1 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_file.vue @@ -0,0 +1,165 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_file_buttons.vue b/app/assets/javascripts/ide/components/repo_file_buttons.vue new file mode 100644 index 00000000000..34f0d51819a --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_file_buttons.vue @@ -0,0 +1,56 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_loading_file.vue b/app/assets/javascripts/ide/components/repo_loading_file.vue new file mode 100644 index 00000000000..7eb840c7608 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_loading_file.vue @@ -0,0 +1,44 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_prev_directory.vue b/app/assets/javascripts/ide/components/repo_prev_directory.vue new file mode 100644 index 00000000000..7cd359ea4ed --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_prev_directory.vue @@ -0,0 +1,32 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_preview.vue b/app/assets/javascripts/ide/components/repo_preview.vue new file mode 100644 index 00000000000..3d1e0297bd5 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_preview.vue @@ -0,0 +1,65 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_tab.vue b/app/assets/javascripts/ide/components/repo_tab.vue new file mode 100644 index 00000000000..5bd63ac9ec5 --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_tab.vue @@ -0,0 +1,69 @@ + + + diff --git a/app/assets/javascripts/ide/components/repo_tabs.vue b/app/assets/javascripts/ide/components/repo_tabs.vue new file mode 100644 index 00000000000..ab0bef4f0ac --- /dev/null +++ b/app/assets/javascripts/ide/components/repo_tabs.vue @@ -0,0 +1,27 @@ + + + diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js new file mode 100644 index 00000000000..a9cbf8e370f --- /dev/null +++ b/app/assets/javascripts/ide/ide_router.js @@ -0,0 +1,101 @@ +import Vue from 'vue'; +import VueRouter from 'vue-router'; +import store from './stores'; +import flash from '../flash'; +import { + getTreeEntry, +} from './stores/utils'; + +Vue.use(VueRouter); + +/** + * Routes below /-/ide/: + +/project/h5bp/html5-boilerplate/blob/master +/project/h5bp/html5-boilerplate/blob/master/app/js/test.js + +/project/h5bp/html5-boilerplate/mr/123 +/project/h5bp/html5-boilerplate/mr/123/app/js/test.js + +/workspace/123 +/workspace/project/h5bp/html5-boilerplate/blob/my-special-branch +/workspace/project/h5bp/html5-boilerplate/mr/123 + +/ = /workspace + +/settings +*/ + +// Unfortunately Vue Router doesn't work without at least a fake component +// If you do only data handling +const EmptyRouterComponent = { + render(createElement) { + return createElement('div'); + }, +}; + +const router = new VueRouter({ + mode: 'history', + base: `${gon.relative_url_root}/-/ide/`, + routes: [ + { + path: '/project/:namespace/:project', + component: EmptyRouterComponent, + children: [ + { + path: ':targetmode/:branch/*', + component: EmptyRouterComponent, + }, + { + path: 'mr/:mrid', + component: EmptyRouterComponent, + }, + ], + }, + ], +}); + +router.beforeEach((to, from, next) => { + if (to.params.namespace && to.params.project) { + store.dispatch('getProjectData', { + namespace: to.params.namespace, + projectId: to.params.project, + }) + .then(() => { + const fullProjectId = `${to.params.namespace}/${to.params.project}`; + + if (to.params.branch) { + store.dispatch('getBranchData', { + projectId: fullProjectId, + branchId: to.params.branch, + }); + + store.dispatch('getTreeData', { + projectId: fullProjectId, + branch: to.params.branch, + endpoint: `/tree/${to.params.branch}`, + }) + .then(() => { + if (to.params[0]) { + const treeEntry = getTreeEntry(store, `${to.params.namespace}/${to.params.project}/${to.params.branch}`, to.params[0]); + if (treeEntry) { + store.dispatch('handleTreeEntryAction', treeEntry); + } + } + }) + .catch((e) => { + flash('Error while loading the branch files. Please try again.'); + throw e; + }); + } + }) + .catch((e) => { + flash('Error while loading the project data. Please try again.'); + throw e; + }); + } + + next(); +}); + +export default router; diff --git a/app/assets/javascripts/ide/index.js b/app/assets/javascripts/ide/index.js new file mode 100644 index 00000000000..a96bd339f51 --- /dev/null +++ b/app/assets/javascripts/ide/index.js @@ -0,0 +1,55 @@ +import Vue from 'vue'; +import { mapActions } from 'vuex'; +import { convertPermissionToBoolean } from '../lib/utils/common_utils'; +import ide from './components/ide.vue'; + +import store from './stores'; +import router from './ide_router'; +import Translate from '../vue_shared/translate'; +import ContextualSidebar from '../contextual_sidebar'; + +function initIde(el) { + if (!el) return null; + + return new Vue({ + el, + store, + router, + components: { + ide, + }, + methods: { + ...mapActions([ + 'setInitialData', + ]), + }, + created() { + const data = el.dataset; + + this.setInitialData({ + endpoints: { + rootEndpoint: data.url, + newMergeRequestUrl: data.newMergeRequestUrl, + rootUrl: data.rootUrl, + }, + canCommit: convertPermissionToBoolean(data.canCommit), + onTopOfBranch: convertPermissionToBoolean(data.onTopOfBranch), + path: data.currentPath, + isRoot: convertPermissionToBoolean(data.root), + isInitialRoot: convertPermissionToBoolean(data.root), + }); + }, + render(createElement) { + return createElement('ide'); + }, + }); +} + +const ideElement = document.getElementById('ide'); + +Vue.use(Translate); + +initIde(ideElement); + +const contextualSidebar = new ContextualSidebar(); +contextualSidebar.bindEvents(); diff --git a/app/assets/javascripts/ide/lib/common/disposable.js b/app/assets/javascripts/ide/lib/common/disposable.js new file mode 100644 index 00000000000..84b29bdb600 --- /dev/null +++ b/app/assets/javascripts/ide/lib/common/disposable.js @@ -0,0 +1,14 @@ +export default class Disposable { + constructor() { + this.disposers = new Set(); + } + + add(...disposers) { + disposers.forEach(disposer => this.disposers.add(disposer)); + } + + dispose() { + this.disposers.forEach(disposer => disposer.dispose()); + this.disposers.clear(); + } +} diff --git a/app/assets/javascripts/ide/lib/common/model.js b/app/assets/javascripts/ide/lib/common/model.js new file mode 100644 index 00000000000..14d9fe4771e --- /dev/null +++ b/app/assets/javascripts/ide/lib/common/model.js @@ -0,0 +1,64 @@ +/* global monaco */ +import Disposable from './disposable'; + +export default class Model { + constructor(monaco, file) { + this.monaco = monaco; + this.disposable = new Disposable(); + this.file = file; + this.content = file.content !== '' ? file.content : file.raw; + + this.disposable.add( + this.originalModel = this.monaco.editor.createModel( + this.file.raw, + undefined, + new this.monaco.Uri(null, null, `original/${this.file.path}`), + ), + this.model = this.monaco.editor.createModel( + this.content, + undefined, + new this.monaco.Uri(null, null, this.file.path), + ), + ); + + this.events = new Map(); + } + + get url() { + return this.model.uri.toString(); + } + + get language() { + return this.model.getModeId(); + } + + get eol() { + return this.model.getEOL() === '\n' ? 'LF' : 'CRLF'; + } + + get path() { + return this.file.path; + } + + getModel() { + return this.model; + } + + getOriginalModel() { + return this.originalModel; + } + + onChange(cb) { + this.events.set( + this.path, + this.disposable.add( + this.model.onDidChangeContent(e => cb(this.model, e)), + ), + ); + } + + dispose() { + this.disposable.dispose(); + this.events.clear(); + } +} diff --git a/app/assets/javascripts/ide/lib/common/model_manager.js b/app/assets/javascripts/ide/lib/common/model_manager.js new file mode 100644 index 00000000000..fd462252795 --- /dev/null +++ b/app/assets/javascripts/ide/lib/common/model_manager.js @@ -0,0 +1,32 @@ +import Disposable from './disposable'; +import Model from './model'; + +export default class ModelManager { + constructor(monaco) { + this.monaco = monaco; + this.disposable = new Disposable(); + this.models = new Map(); + } + + hasCachedModel(path) { + return this.models.has(path); + } + + addModel(file) { + if (this.hasCachedModel(file.path)) { + return this.models.get(file.path); + } + + const model = new Model(this.monaco, file); + this.models.set(model.path, model); + this.disposable.add(model); + + return model; + } + + dispose() { + // dispose of all the models + this.disposable.dispose(); + this.models.clear(); + } +} diff --git a/app/assets/javascripts/ide/lib/decorations/controller.js b/app/assets/javascripts/ide/lib/decorations/controller.js new file mode 100644 index 00000000000..0954b7973c4 --- /dev/null +++ b/app/assets/javascripts/ide/lib/decorations/controller.js @@ -0,0 +1,43 @@ +export default class DecorationsController { + constructor(editor) { + this.editor = editor; + this.decorations = new Map(); + this.editorDecorations = new Map(); + } + + getAllDecorationsForModel(model) { + if (!this.decorations.has(model.url)) return []; + + const modelDecorations = this.decorations.get(model.url); + const decorations = []; + + modelDecorations.forEach(val => decorations.push(...val)); + + return decorations; + } + + addDecorations(model, decorationsKey, decorations) { + const decorationMap = this.decorations.get(model.url) || new Map(); + + decorationMap.set(decorationsKey, decorations); + + this.decorations.set(model.url, decorationMap); + + this.decorate(model); + } + + decorate(model) { + const decorations = this.getAllDecorationsForModel(model); + const oldDecorations = this.editorDecorations.get(model.url) || []; + + this.editorDecorations.set( + model.url, + this.editor.instance.deltaDecorations(oldDecorations, decorations), + ); + } + + dispose() { + this.decorations.clear(); + this.editorDecorations.clear(); + } +} diff --git a/app/assets/javascripts/ide/lib/diff/controller.js b/app/assets/javascripts/ide/lib/diff/controller.js new file mode 100644 index 00000000000..dc0b1c95e59 --- /dev/null +++ b/app/assets/javascripts/ide/lib/diff/controller.js @@ -0,0 +1,71 @@ +/* global monaco */ +import { throttle } from 'underscore'; +import DirtyDiffWorker from './diff_worker'; +import Disposable from '../common/disposable'; + +export const getDiffChangeType = (change) => { + if (change.modified) { + return 'modified'; + } else if (change.added) { + return 'added'; + } else if (change.removed) { + return 'removed'; + } + + return ''; +}; + +export const getDecorator = change => ({ + range: new monaco.Range( + change.lineNumber, + 1, + change.endLineNumber, + 1, + ), + options: { + isWholeLine: true, + linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(change)}`, + }, +}); + +export default class DirtyDiffController { + constructor(modelManager, decorationsController) { + this.disposable = new Disposable(); + this.editorSimpleWorker = null; + this.modelManager = modelManager; + this.decorationsController = decorationsController; + this.dirtyDiffWorker = new DirtyDiffWorker(); + this.throttledComputeDiff = throttle(this.computeDiff, 250); + this.decorate = this.decorate.bind(this); + + this.dirtyDiffWorker.addEventListener('message', this.decorate); + } + + attachModel(model) { + model.onChange(() => this.throttledComputeDiff(model)); + } + + computeDiff(model) { + this.dirtyDiffWorker.postMessage({ + path: model.path, + originalContent: model.getOriginalModel().getValue(), + newContent: model.getModel().getValue(), + }); + } + + reDecorate(model) { + this.decorationsController.decorate(model); + } + + decorate({ data }) { + const decorations = data.changes.map(change => getDecorator(change)); + this.decorationsController.addDecorations(data.path, 'dirtyDiff', decorations); + } + + dispose() { + this.disposable.dispose(); + + this.dirtyDiffWorker.removeEventListener('message', this.decorate); + this.dirtyDiffWorker.terminate(); + } +} diff --git a/app/assets/javascripts/ide/lib/diff/diff.js b/app/assets/javascripts/ide/lib/diff/diff.js new file mode 100644 index 00000000000..0e37f5c4704 --- /dev/null +++ b/app/assets/javascripts/ide/lib/diff/diff.js @@ -0,0 +1,30 @@ +import { diffLines } from 'diff'; + +// eslint-disable-next-line import/prefer-default-export +export const computeDiff = (originalContent, newContent) => { + const changes = diffLines(originalContent, newContent); + + let lineNumber = 1; + return changes.reduce((acc, change) => { + const findOnLine = acc.find(c => c.lineNumber === lineNumber); + + if (findOnLine) { + Object.assign(findOnLine, change, { + modified: true, + endLineNumber: (lineNumber + change.count) - 1, + }); + } else if ('added' in change || 'removed' in change) { + acc.push(Object.assign({}, change, { + lineNumber, + modified: undefined, + endLineNumber: (lineNumber + change.count) - 1, + })); + } + + if (!change.removed) { + lineNumber += change.count; + } + + return acc; + }, []); +}; diff --git a/app/assets/javascripts/ide/lib/diff/diff_worker.js b/app/assets/javascripts/ide/lib/diff/diff_worker.js new file mode 100644 index 00000000000..e74c4046330 --- /dev/null +++ b/app/assets/javascripts/ide/lib/diff/diff_worker.js @@ -0,0 +1,10 @@ +import { computeDiff } from './diff'; + +self.addEventListener('message', (e) => { + const data = e.data; + + self.postMessage({ + path: data.path, + changes: computeDiff(data.originalContent, data.newContent), + }); +}); diff --git a/app/assets/javascripts/ide/lib/editor.js b/app/assets/javascripts/ide/lib/editor.js new file mode 100644 index 00000000000..51e202b9348 --- /dev/null +++ b/app/assets/javascripts/ide/lib/editor.js @@ -0,0 +1,109 @@ +import DecorationsController from './decorations/controller'; +import DirtyDiffController from './diff/controller'; +import Disposable from './common/disposable'; +import ModelManager from './common/model_manager'; +import editorOptions from './editor_options'; + +export default class Editor { + static create(monaco) { + this.editorInstance = new Editor(monaco); + + return this.editorInstance; + } + + constructor(monaco) { + this.monaco = monaco; + this.currentModel = null; + this.instance = null; + this.dirtyDiffController = null; + this.disposable = new Disposable(); + + this.disposable.add( + this.modelManager = new ModelManager(this.monaco), + this.decorationsController = new DecorationsController(this), + ); + + this.debouncedUpdate = _.debounce(() => { + this.updateDimensions(); + }, 200); + window.addEventListener('resize', this.debouncedUpdate, false); + } + + createInstance(domElement) { + if (!this.instance) { + this.disposable.add( + this.instance = this.monaco.editor.create(domElement, { + model: null, + readOnly: false, + contextmenu: true, + scrollBeyondLastLine: false, + minimap: { + enabled: false, + }, + }), + this.dirtyDiffController = new DirtyDiffController( + this.modelManager, this.decorationsController, + ), + ); + } + } + + createModel(file) { + return this.modelManager.addModel(file); + } + + attachModel(model) { + this.instance.setModel(model.getModel()); + this.dirtyDiffController.attachModel(model); + + this.currentModel = model; + + this.instance.updateOptions(editorOptions.reduce((acc, obj) => { + Object.keys(obj).forEach((key) => { + Object.assign(acc, { + [key]: obj[key](model), + }); + }); + return acc; + }, {})); + + this.dirtyDiffController.reDecorate(model); + } + + clearEditor() { + if (this.instance) { + this.instance.setModel(null); + } + } + + dispose() { + this.disposable.dispose(); + window.removeEventListener('resize', this.debouncedUpdate); + + // dispose main monaco instance + if (this.instance) { + this.instance = null; + } + } + + updateDimensions() { + this.instance.layout(); + } + + setPosition({ lineNumber, column }) { + this.instance.revealPositionInCenter({ + lineNumber, + column, + }); + this.instance.setPosition({ + lineNumber, + column, + }); + } + + onPositionChange(cb) { + this.disposable.add( + this.instance.onDidChangeCursorPosition(e => cb(this.instance, e)), + ); + } +} diff --git a/app/assets/javascripts/ide/lib/editor_options.js b/app/assets/javascripts/ide/lib/editor_options.js new file mode 100644 index 00000000000..701affc466e --- /dev/null +++ b/app/assets/javascripts/ide/lib/editor_options.js @@ -0,0 +1,2 @@ +export default [{ +}]; diff --git a/app/assets/javascripts/ide/monaco_loader.js b/app/assets/javascripts/ide/monaco_loader.js new file mode 100644 index 00000000000..af83a1ec0b4 --- /dev/null +++ b/app/assets/javascripts/ide/monaco_loader.js @@ -0,0 +1,11 @@ +import monacoContext from 'monaco-editor/dev/vs/loader'; + +monacoContext.require.config({ + paths: { + vs: `${__webpack_public_path__}monaco-editor/vs`, // eslint-disable-line camelcase + }, +}); + +// eslint-disable-next-line no-underscore-dangle +window.__monaco_context__ = monacoContext; +export default monacoContext.require; diff --git a/app/assets/javascripts/ide/services/index.js b/app/assets/javascripts/ide/services/index.js new file mode 100644 index 00000000000..1fb24e93f2e --- /dev/null +++ b/app/assets/javascripts/ide/services/index.js @@ -0,0 +1,47 @@ +import Vue from 'vue'; +import VueResource from 'vue-resource'; +import Api from '../../api'; + +Vue.use(VueResource); + +export default { + getTreeData(endpoint) { + return Vue.http.get(endpoint, { params: { format: 'json' } }); + }, + getFileData(endpoint) { + return Vue.http.get(endpoint, { params: { format: 'json' } }); + }, + getRawFileData(file) { + if (file.tempFile) { + return Promise.resolve(file.content); + } + + if (file.raw) { + return Promise.resolve(file.raw); + } + + return Vue.http.get(file.rawPath, { params: { format: 'json' } }) + .then(res => res.text()); + }, + getProjectData(namespace, project) { + return Api.project(`${namespace}/${project}`); + }, + getBranchData(projectId, currentBranchId) { + return Api.branchSingle(projectId, currentBranchId); + }, + createBranch(projectId, payload) { + const url = Api.buildUrl(Api.createBranchPath).replace(':id', projectId); + + return Vue.http.post(url, payload); + }, + commit(projectId, payload) { + return Api.commitMultiple(projectId, payload); + }, + getTreeLastCommit(endpoint) { + return Vue.http.get(endpoint, { + params: { + format: 'json', + }, + }); + }, +}; diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js new file mode 100644 index 00000000000..c01046c8c76 --- /dev/null +++ b/app/assets/javascripts/ide/stores/actions.js @@ -0,0 +1,179 @@ +import Vue from 'vue'; +import { visitUrl } from '../../lib/utils/url_utility'; +import flash from '../../flash'; +import service from '../services'; +import * as types from './mutation_types'; + +export const redirectToUrl = (_, url) => visitUrl(url); + +export const setInitialData = ({ commit }, data) => + commit(types.SET_INITIAL_DATA, data); + +export const closeDiscardPopup = ({ commit }) => + commit(types.TOGGLE_DISCARD_POPUP, false); + +export const discardAllChanges = ({ commit, getters, dispatch }) => { + const changedFiles = getters.changedFiles; + + changedFiles.forEach((file) => { + commit(types.DISCARD_FILE_CHANGES, file); + + if (file.tempFile) { + dispatch('closeFile', { file, force: true }); + } + }); +}; + +export const closeAllFiles = ({ state, dispatch }) => { + state.openFiles.forEach(file => dispatch('closeFile', { file })); +}; + +export const toggleEditMode = ( + { state, commit, getters, dispatch }, + force = false, +) => { + const changedFiles = getters.changedFiles; + + if (changedFiles.length && !force) { + commit(types.TOGGLE_DISCARD_POPUP, true); + } else { + commit(types.TOGGLE_EDIT_MODE); + commit(types.TOGGLE_DISCARD_POPUP, false); + dispatch('toggleBlobView'); + + if (!state.editMode) { + dispatch('discardAllChanges'); + } + } +}; + +export const toggleBlobView = ({ commit, state }) => { + if (state.editMode) { + commit(types.SET_EDIT_MODE); + } else { + commit(types.SET_PREVIEW_MODE); + } +}; + +export const setPanelCollapsedStatus = ({ commit }, { side, collapsed }) => { + if (side === 'left') { + commit(types.SET_LEFT_PANEL_COLLAPSED, collapsed); + } else { + commit(types.SET_RIGHT_PANEL_COLLAPSED, collapsed); + } +}; + +export const checkCommitStatus = ({ state }) => + service + .getBranchData(state.currentProjectId, state.currentBranchId) + .then((data) => { + const { id } = data.commit; + const selectedBranch = + state.projects[state.currentProjectId].branches[state.currentBranchId]; + + if (selectedBranch.workingReference !== id) { + return true; + } + + return false; + }) + .catch(() => flash('Error checking branch data. Please try again.')); + +export const commitChanges = ( + { commit, state, dispatch, getters }, + { payload, newMr }, +) => + service + .commit(state.currentProjectId, payload) + .then((data) => { + const { branch } = payload; + if (!data.short_id) { + flash(data.message); + return; + } + + const selectedProject = state.projects[state.currentProjectId]; + const lastCommit = { + commit_path: `${selectedProject.web_url}/commit/${data.id}`, + commit: { + message: data.message, + authored_date: data.committed_date, + }, + }; + + flash( + `Your changes have been committed. Commit ${data.short_id} with ${ + data.stats.additions + } additions, ${data.stats.deletions} deletions.`, + 'notice', + ); + + if (newMr) { + dispatch( + 'redirectToUrl', + `${ + selectedProject.web_url + }/merge_requests/new?merge_request%5Bsource_branch%5D=${branch}`, + ); + } else { + commit(types.SET_BRANCH_WORKING_REFERENCE, { + projectId: state.currentProjectId, + branchId: state.currentBranchId, + reference: data.id, + }); + + getters.changedFiles.forEach((entry) => { + commit(types.SET_LAST_COMMIT_DATA, { + entry, + lastCommit, + }); + }); + + dispatch('discardAllChanges'); + dispatch('closeAllFiles'); + + window.scrollTo(0, 0); + } + }) + .catch(() => flash('Error committing changes. Please try again.')); + +export const createTempEntry = ( + { state, dispatch }, + { projectId, branchId, parent, name, type, content = '', base64 = false }, +) => { + const selectedParent = parent || state.trees[`${projectId}/${branchId}`]; + if (type === 'tree') { + dispatch('createTempTree', { + projectId, + branchId, + parent: selectedParent, + name, + }); + } else if (type === 'blob') { + dispatch('createTempFile', { + projectId, + branchId, + parent: selectedParent, + name, + base64, + content, + }); + } +}; + +export const scrollToTab = () => { + Vue.nextTick(() => { + const tabs = document.getElementById('tabs'); + + if (tabs) { + const tabEl = tabs.querySelector('.active .repo-tab'); + + tabEl.focus(); + } + }); +}; + +export * from './actions/tree'; +export * from './actions/file'; +export * from './actions/project'; +export * from './actions/branch'; diff --git a/app/assets/javascripts/ide/stores/actions/branch.js b/app/assets/javascripts/ide/stores/actions/branch.js new file mode 100644 index 00000000000..32bdf7fec22 --- /dev/null +++ b/app/assets/javascripts/ide/stores/actions/branch.js @@ -0,0 +1,43 @@ +import service from '../../services'; +import flash from '../../../flash'; +import * as types from '../mutation_types'; + +export const getBranchData = ( + { commit, state, dispatch }, + { projectId, branchId, force = false } = {}, +) => new Promise((resolve, reject) => { + if ((typeof state.projects[`${projectId}`] === 'undefined' || + !state.projects[`${projectId}`].branches[branchId]) + || force) { + service.getBranchData(`${projectId}`, branchId) + .then((data) => { + const { id } = data.commit; + commit(types.SET_BRANCH, { projectPath: `${projectId}`, branchName: branchId, branch: data }); + commit(types.SET_BRANCH_WORKING_REFERENCE, { projectId, branchId, reference: id }); + resolve(data); + }) + .catch(() => { + flash('Error loading branch data. Please try again.'); + reject(new Error(`Branch not loaded - ${projectId}/${branchId}`)); + }); + } else { + resolve(state.projects[`${projectId}`].branches[branchId]); + } +}); + +export const createNewBranch = ({ state, commit }, branch) => service.createBranch( + state.currentProjectId, + { + branch, + ref: state.currentBranchId, + }, +) +.then(res => res.json()) +.then((data) => { + const branchName = data.name; + const url = location.href.replace(state.currentBranchId, branchName); + + if (this.$router) this.$router.push(url); + + commit(types.SET_CURRENT_BRANCH, branchName); +}); diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js new file mode 100644 index 00000000000..0f27d5bf1c3 --- /dev/null +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -0,0 +1,131 @@ +import { normalizeHeaders } from '../../../lib/utils/common_utils'; +import flash from '../../../flash'; +import service from '../../services'; +import * as types from '../mutation_types'; +import router from '../../ide_router'; +import { + findEntry, + setPageTitle, + createTemp, + findIndexOfFile, +} from '../utils'; + +export const closeFile = ({ commit, state, dispatch }, { file, force = false }) => { + if ((file.changed || file.tempFile) && !force) return; + + const indexOfClosedFile = findIndexOfFile(state.openFiles, file); + const fileWasActive = file.active; + + commit(types.TOGGLE_FILE_OPEN, file); + commit(types.SET_FILE_ACTIVE, { file, active: false }); + + if (state.openFiles.length > 0 && fileWasActive) { + const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1; + const nextFileToOpen = state.openFiles[nextIndexToOpen]; + + dispatch('setFileActive', nextFileToOpen); + } else if (!state.openFiles.length) { + router.push(`/project/${file.projectId}/tree/${file.branchId}/`); + } + + dispatch('getLastCommitData'); +}; + +export const setFileActive = ({ commit, state, getters, dispatch }, file) => { + const currentActiveFile = getters.activeFile; + + if (file.active) return; + + if (currentActiveFile) { + commit(types.SET_FILE_ACTIVE, { file: currentActiveFile, active: false }); + } + + commit(types.SET_FILE_ACTIVE, { file, active: true }); + dispatch('scrollToTab'); + + // reset hash for line highlighting + location.hash = ''; + + commit(types.SET_CURRENT_PROJECT, file.projectId); + commit(types.SET_CURRENT_BRANCH, file.branchId); +}; + +export const getFileData = ({ state, commit, dispatch }, file) => { + commit(types.TOGGLE_LOADING, file); + + service.getFileData(file.url) + .then((res) => { + const pageTitle = decodeURI(normalizeHeaders(res.headers)['PAGE-TITLE']); + + setPageTitle(pageTitle); + + return res.json(); + }) + .then((data) => { + commit(types.SET_FILE_DATA, { data, file }); + commit(types.TOGGLE_FILE_OPEN, file); + dispatch('setFileActive', file); + commit(types.TOGGLE_LOADING, file); + }) + .catch(() => { + commit(types.TOGGLE_LOADING, file); + flash('Error loading file data. Please try again.'); + }); +}; + +export const getRawFileData = ({ commit, dispatch }, file) => service.getRawFileData(file) + .then((raw) => { + commit(types.SET_FILE_RAW_DATA, { file, raw }); + }) + .catch(() => flash('Error loading file content. Please try again.')); + +export const changeFileContent = ({ commit }, { file, content }) => { + commit(types.UPDATE_FILE_CONTENT, { file, content }); +}; + +export const setFileLanguage = ({ state, commit }, { fileLanguage }) => { + commit(types.SET_FILE_LANGUAGE, { file: state.selectedFile, fileLanguage }); +}; + +export const setFileEOL = ({ state, commit }, { eol }) => { + commit(types.SET_FILE_EOL, { file: state.selectedFile, eol }); +}; + +export const setEditorPosition = ({ state, commit }, { editorRow, editorColumn }) => { + commit(types.SET_FILE_POSITION, { file: state.selectedFile, editorRow, editorColumn }); +}; + +export const createTempFile = ({ state, commit, dispatch }, { projectId, branchId, parent, name, content = '', base64 = '' }) => { + const path = parent.path !== undefined ? parent.path : ''; + // We need to do the replacement otherwise the web_url + file.url duplicate + const newUrl = `/${projectId}/blob/${branchId}/${path}${path ? '/' : ''}${name}`; + const file = createTemp({ + projectId, + branchId, + name: name.replace(`${path}/`, ''), + path, + type: 'blob', + level: parent.level !== undefined ? parent.level + 1 : 0, + changed: true, + content, + base64, + url: newUrl, + }); + + if (findEntry(parent.tree, 'blob', file.name)) return flash(`The name "${file.name}" is already taken in this directory.`); + + commit(types.CREATE_TMP_FILE, { + parent, + file, + }); + commit(types.TOGGLE_FILE_OPEN, file); + dispatch('setFileActive', file); + + if (!state.editMode && !file.base64) { + dispatch('toggleEditMode', true); + } + + router.push(`/project${file.url}`); + + return Promise.resolve(file); +}; diff --git a/app/assets/javascripts/ide/stores/actions/project.js b/app/assets/javascripts/ide/stores/actions/project.js new file mode 100644 index 00000000000..75e332090cb --- /dev/null +++ b/app/assets/javascripts/ide/stores/actions/project.js @@ -0,0 +1,25 @@ +import service from '../../services'; +import flash from '../../../flash'; +import * as types from '../mutation_types'; + +// eslint-disable-next-line import/prefer-default-export +export const getProjectData = ( + { commit, state, dispatch }, + { namespace, projectId, force = false } = {}, +) => new Promise((resolve, reject) => { + if (!state.projects[`${namespace}/${projectId}`] || force) { + service.getProjectData(namespace, projectId) + .then(res => res.data) + .then((data) => { + commit(types.SET_PROJECT, { projectPath: `${namespace}/${projectId}`, project: data }); + if (!state.currentProjectId) commit(types.SET_CURRENT_PROJECT, `${namespace}/${projectId}`); + resolve(data); + }) + .catch(() => { + flash('Error loading project data. Please try again.'); + reject(new Error(`Project not loaded ${namespace}/${projectId}`)); + }); + } else { + resolve(state.projects[`${namespace}/${projectId}`]); + } +}); diff --git a/app/assets/javascripts/ide/stores/actions/tree.js b/app/assets/javascripts/ide/stores/actions/tree.js new file mode 100644 index 00000000000..25909400a75 --- /dev/null +++ b/app/assets/javascripts/ide/stores/actions/tree.js @@ -0,0 +1,188 @@ +import { visitUrl } from '../../../lib/utils/url_utility'; +import { normalizeHeaders } from '../../../lib/utils/common_utils'; +import flash from '../../../flash'; +import service from '../../services'; +import * as types from '../mutation_types'; +import router from '../../ide_router'; +import { + setPageTitle, + findEntry, + createTemp, + createOrMergeEntry, +} from '../utils'; + +export const getTreeData = ( + { commit, state, dispatch }, + { endpoint, tree = null, projectId, branch, force = false } = {}, +) => new Promise((resolve, reject) => { + // We already have the base tree so we resolve immediately + if (!tree && state.trees[`${projectId}/${branch}`] && !force) { + resolve(); + } else { + if (tree) commit(types.TOGGLE_LOADING, tree); + const selectedProject = state.projects[projectId]; + // We are merging the web_url that we got on the project info with the endpoint + // we got on the tree entry, as both contain the projectId, we replace it in the tree endpoint + const completeEndpoint = selectedProject.web_url + (endpoint).replace(projectId, ''); + if (completeEndpoint && (!tree || !tree.tempFile)) { + service.getTreeData(completeEndpoint) + .then((res) => { + const pageTitle = decodeURI(normalizeHeaders(res.headers)['PAGE-TITLE']); + + setPageTitle(pageTitle); + + return res.json(); + }) + .then((data) => { + if (!state.isInitialRoot) { + commit(types.SET_ROOT, data.path === '/'); + } + + dispatch('updateDirectoryData', { data, tree, projectId, branch }); + const selectedTree = tree || state.trees[`${projectId}/${branch}`]; + + commit(types.SET_PARENT_TREE_URL, data.parent_tree_url); + commit(types.SET_LAST_COMMIT_URL, { tree: selectedTree, url: data.last_commit_path }); + if (tree) commit(types.TOGGLE_LOADING, selectedTree); + + const prevLastCommitPath = selectedTree.lastCommitPath; + if (prevLastCommitPath !== null) { + dispatch('getLastCommitData', selectedTree); + } + resolve(data); + }) + .catch((e) => { + flash('Error loading tree data. Please try again.'); + if (tree) commit(types.TOGGLE_LOADING, tree); + reject(e); + }); + } else { + resolve(); + } + } +}); + +export const toggleTreeOpen = ({ commit, dispatch }, { endpoint, tree }) => { + if (tree.opened) { + // send empty data to clear the tree + const data = { trees: [], blobs: [], submodules: [] }; + + dispatch('updateDirectoryData', { data, tree, projectId: tree.projectId, branchId: tree.branchId }); + } else { + dispatch('getTreeData', { endpoint, tree, projectId: tree.projectId, branch: tree.branchId }); + } + + commit(types.TOGGLE_TREE_OPEN, tree); +}; + +export const handleTreeEntryAction = ({ commit, dispatch }, row) => { + if (row.type === 'tree') { + dispatch('toggleTreeOpen', { + endpoint: row.url, + tree: row, + }); + } else if (row.type === 'submodule') { + commit(types.TOGGLE_LOADING, row); + visitUrl(row.url); + } else if (row.type === 'blob' && row.opened) { + dispatch('setFileActive', row); + } else { + dispatch('getFileData', row); + } +}; + +export const createTempTree = ( + { state, commit, dispatch }, + { projectId, branchId, parent, name }, +) => { + let selectedTree = parent; + const dirNames = name.replace(new RegExp(`^${state.path}/`), '').split('/'); + + dirNames.forEach((dirName) => { + const foundEntry = findEntry(selectedTree.tree, 'tree', dirName); + + if (!foundEntry) { + const path = selectedTree.path !== undefined ? selectedTree.path : ''; + const tmpEntry = createTemp({ + projectId, + branchId, + name: dirName, + path, + type: 'tree', + level: selectedTree.level !== undefined ? selectedTree.level + 1 : 0, + tree: [], + url: `/${projectId}/blob/${branchId}/${path}${path ? '/' : ''}${dirName}`, + }); + + commit(types.CREATE_TMP_TREE, { + parent: selectedTree, + tmpEntry, + }); + commit(types.TOGGLE_TREE_OPEN, tmpEntry); + + router.push(`/project${tmpEntry.url}`); + + selectedTree = tmpEntry; + } else { + selectedTree = foundEntry; + } + }); +}; + +export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = state) => { + if (!tree || tree.lastCommitPath === null || !tree.lastCommitPath) return; + + service.getTreeLastCommit(tree.lastCommitPath) + .then((res) => { + const lastCommitPath = normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null; + + commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath }); + + return res.json(); + }) + .then((data) => { + data.forEach((lastCommit) => { + const entry = findEntry(tree.tree, lastCommit.type, lastCommit.file_name); + + if (entry) { + commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit }); + } + }); + + dispatch('getLastCommitData', tree); + }) + .catch(() => flash('Error fetching log data.')); +}; + +export const updateDirectoryData = ( + { commit, state }, + { data, tree, projectId, branch }, +) => { + if (!tree) { + const existingTree = state.trees[`${projectId}/${branch}`]; + if (!existingTree) { + commit(types.CREATE_TREE, { treePath: `${projectId}/${branch}` }); + } + } + + const selectedTree = tree || state.trees[`${projectId}/${branch}`]; + const level = selectedTree.level !== undefined ? selectedTree.level + 1 : 0; + const parentTreeUrl = data.parent_tree_url ? `${data.parent_tree_url}${data.path}` : state.endpoints.rootUrl; + const createEntry = (entry, type) => createOrMergeEntry({ + tree: selectedTree, + projectId: `${projectId}`, + branchId: branch, + entry, + level, + type, + parentTreeUrl, + }); + + const formattedData = [ + ...data.trees.map(t => createEntry(t, 'tree')), + ...data.submodules.map(m => createEntry(m, 'submodule')), + ...data.blobs.map(b => createEntry(b, 'blob')), + ]; + + commit(types.SET_DIRECTORY_DATA, { tree: selectedTree, data: formattedData }); +}; diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js new file mode 100644 index 00000000000..6b51ccff817 --- /dev/null +++ b/app/assets/javascripts/ide/stores/getters.js @@ -0,0 +1,19 @@ +export const changedFiles = state => state.openFiles.filter(file => file.changed); + +export const activeFile = state => state.openFiles.find(file => file.active) || null; + +export const activeFileExtension = (state) => { + const file = activeFile(state); + return file ? `.${file.path.split('.').pop()}` : ''; +}; + +export const canEditFile = (state) => { + const currentActiveFile = activeFile(state); + + return state.canCommit && + (currentActiveFile && !currentActiveFile.renderError && !currentActiveFile.binary); +}; + +export const addedFiles = state => changedFiles(state).filter(f => f.tempFile); + +export const modifiedFiles = state => changedFiles(state).filter(f => !f.tempFile); diff --git a/app/assets/javascripts/ide/stores/index.js b/app/assets/javascripts/ide/stores/index.js new file mode 100644 index 00000000000..6ac9bfd8189 --- /dev/null +++ b/app/assets/javascripts/ide/stores/index.js @@ -0,0 +1,15 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import state from './state'; +import * as actions from './actions'; +import * as getters from './getters'; +import mutations from './mutations'; + +Vue.use(Vuex); + +export default new Vuex.Store({ + state: state(), + actions, + mutations, + getters, +}); diff --git a/app/assets/javascripts/ide/stores/mutation_types.js b/app/assets/javascripts/ide/stores/mutation_types.js new file mode 100644 index 00000000000..4e3c10972ba --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutation_types.js @@ -0,0 +1,45 @@ +export const SET_INITIAL_DATA = 'SET_INITIAL_DATA'; +export const TOGGLE_LOADING = 'TOGGLE_LOADING'; +export const SET_PARENT_TREE_URL = 'SET_PARENT_TREE_URL'; +export const SET_ROOT = 'SET_ROOT'; +export const SET_LAST_COMMIT_DATA = 'SET_LAST_COMMIT_DATA'; +export const SET_LEFT_PANEL_COLLAPSED = 'SET_LEFT_PANEL_COLLAPSED'; +export const SET_RIGHT_PANEL_COLLAPSED = 'SET_RIGHT_PANEL_COLLAPSED'; + +// Project Mutation Types +export const SET_PROJECT = 'SET_PROJECT'; +export const SET_CURRENT_PROJECT = 'SET_CURRENT_PROJECT'; +export const TOGGLE_PROJECT_OPEN = 'TOGGLE_PROJECT_OPEN'; + +// Branch Mutation Types +export const SET_BRANCH = 'SET_BRANCH'; +export const SET_BRANCH_WORKING_REFERENCE = 'SET_BRANCH_WORKING_REFERENCE'; +export const TOGGLE_BRANCH_OPEN = 'TOGGLE_BRANCH_OPEN'; + +// Tree mutation types +export const SET_DIRECTORY_DATA = 'SET_DIRECTORY_DATA'; +export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN'; +export const CREATE_TMP_TREE = 'CREATE_TMP_TREE'; +export const SET_LAST_COMMIT_URL = 'SET_LAST_COMMIT_URL'; +export const CREATE_TREE = 'CREATE_TREE'; + +// File mutation types +export const SET_FILE_DATA = 'SET_FILE_DATA'; +export const TOGGLE_FILE_OPEN = 'TOGGLE_FILE_OPEN'; +export const SET_FILE_ACTIVE = 'SET_FILE_ACTIVE'; +export const SET_FILE_RAW_DATA = 'SET_FILE_RAW_DATA'; +export const UPDATE_FILE_CONTENT = 'UPDATE_FILE_CONTENT'; +export const SET_FILE_LANGUAGE = 'SET_FILE_LANGUAGE'; +export const SET_FILE_POSITION = 'SET_FILE_POSITION'; +export const SET_FILE_EOL = 'SET_FILE_EOL'; +export const DISCARD_FILE_CHANGES = 'DISCARD_FILE_CHANGES'; +export const CREATE_TMP_FILE = 'CREATE_TMP_FILE'; + +// Viewer mutation types +export const SET_PREVIEW_MODE = 'SET_PREVIEW_MODE'; +export const SET_EDIT_MODE = 'SET_EDIT_MODE'; +export const TOGGLE_EDIT_MODE = 'TOGGLE_EDIT_MODE'; +export const TOGGLE_DISCARD_POPUP = 'TOGGLE_DISCARD_POPUP'; + +export const SET_CURRENT_BRANCH = 'SET_CURRENT_BRANCH'; + diff --git a/app/assets/javascripts/ide/stores/mutations.js b/app/assets/javascripts/ide/stores/mutations.js new file mode 100644 index 00000000000..2fed9019cb6 --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutations.js @@ -0,0 +1,65 @@ +import * as types from './mutation_types'; +import projectMutations from './mutations/project'; +import fileMutations from './mutations/file'; +import treeMutations from './mutations/tree'; +import branchMutations from './mutations/branch'; + +export default { + [types.SET_INITIAL_DATA](state, data) { + Object.assign(state, data); + }, + [types.SET_PREVIEW_MODE](state) { + Object.assign(state, { + currentBlobView: 'repo-preview', + }); + }, + [types.SET_EDIT_MODE](state) { + Object.assign(state, { + currentBlobView: 'repo-editor', + }); + }, + [types.TOGGLE_LOADING](state, entry) { + Object.assign(entry, { + loading: !entry.loading, + }); + }, + [types.TOGGLE_EDIT_MODE](state) { + Object.assign(state, { + editMode: !state.editMode, + }); + }, + [types.TOGGLE_DISCARD_POPUP](state, discardPopupOpen) { + Object.assign(state, { + discardPopupOpen, + }); + }, + [types.SET_ROOT](state, isRoot) { + Object.assign(state, { + isRoot, + isInitialRoot: isRoot, + }); + }, + [types.SET_LEFT_PANEL_COLLAPSED](state, collapsed) { + Object.assign(state, { + leftPanelCollapsed: collapsed, + }); + }, + [types.SET_RIGHT_PANEL_COLLAPSED](state, collapsed) { + Object.assign(state, { + rightPanelCollapsed: collapsed, + }); + }, + [types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) { + Object.assign(entry.lastCommit, { + id: lastCommit.commit.id, + url: lastCommit.commit_path, + message: lastCommit.commit.message, + author: lastCommit.commit.author_name, + updatedAt: lastCommit.commit.authored_date, + }); + }, + ...projectMutations, + ...fileMutations, + ...treeMutations, + ...branchMutations, +}; diff --git a/app/assets/javascripts/ide/stores/mutations/branch.js b/app/assets/javascripts/ide/stores/mutations/branch.js new file mode 100644 index 00000000000..04b9582c5bb --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutations/branch.js @@ -0,0 +1,28 @@ +import * as types from '../mutation_types'; + +export default { + [types.SET_CURRENT_BRANCH](state, currentBranchId) { + Object.assign(state, { + currentBranchId, + }); + }, + [types.SET_BRANCH](state, { projectPath, branchName, branch }) { + // Add client side properties + Object.assign(branch, { + treeId: `${projectPath}/${branchName}`, + active: true, + workingReference: '', + }); + + Object.assign(state.projects[projectPath], { + branches: { + [branchName]: branch, + }, + }); + }, + [types.SET_BRANCH_WORKING_REFERENCE](state, { projectId, branchId, reference }) { + Object.assign(state.projects[projectId].branches[branchId], { + workingReference: reference, + }); + }, +}; diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js new file mode 100644 index 00000000000..5f3655b0092 --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutations/file.js @@ -0,0 +1,74 @@ +import * as types from '../mutation_types'; +import { findIndexOfFile } from '../utils'; + +export default { + [types.SET_FILE_ACTIVE](state, { file, active }) { + Object.assign(file, { + active, + }); + + Object.assign(state, { + selectedFile: file, + }); + }, + [types.TOGGLE_FILE_OPEN](state, file) { + Object.assign(file, { + opened: !file.opened, + }); + + if (file.opened) { + state.openFiles.push(file); + } else { + state.openFiles.splice(findIndexOfFile(state.openFiles, file), 1); + } + }, + [types.SET_FILE_DATA](state, { data, file }) { + Object.assign(file, { + blamePath: data.blame_path, + commitsPath: data.commits_path, + permalink: data.permalink, + rawPath: data.raw_path, + binary: data.binary, + html: data.html, + renderError: data.render_error, + }); + }, + [types.SET_FILE_RAW_DATA](state, { file, raw }) { + Object.assign(file, { + raw, + }); + }, + [types.UPDATE_FILE_CONTENT](state, { file, content }) { + const changed = content !== file.raw; + + Object.assign(file, { + content, + changed, + }); + }, + [types.SET_FILE_LANGUAGE](state, { file, fileLanguage }) { + Object.assign(file, { + fileLanguage, + }); + }, + [types.SET_FILE_EOL](state, { file, eol }) { + Object.assign(file, { + eol, + }); + }, + [types.SET_FILE_POSITION](state, { file, editorRow, editorColumn }) { + Object.assign(file, { + editorRow, + editorColumn, + }); + }, + [types.DISCARD_FILE_CHANGES](state, file) { + Object.assign(file, { + content: '', + changed: false, + }); + }, + [types.CREATE_TMP_FILE](state, { file, parent }) { + parent.tree.push(file); + }, +}; diff --git a/app/assets/javascripts/ide/stores/mutations/project.js b/app/assets/javascripts/ide/stores/mutations/project.js new file mode 100644 index 00000000000..2816562a919 --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutations/project.js @@ -0,0 +1,23 @@ +import * as types from '../mutation_types'; + +export default { + [types.SET_CURRENT_PROJECT](state, currentProjectId) { + Object.assign(state, { + currentProjectId, + }); + }, + [types.SET_PROJECT](state, { projectPath, project }) { + // Add client side properties + Object.assign(project, { + tree: [], + branches: {}, + active: true, + }); + + Object.assign(state, { + projects: Object.assign({}, state.projects, { + [projectPath]: project, + }), + }); + }, +}; diff --git a/app/assets/javascripts/ide/stores/mutations/tree.js b/app/assets/javascripts/ide/stores/mutations/tree.js new file mode 100644 index 00000000000..4fe438ab465 --- /dev/null +++ b/app/assets/javascripts/ide/stores/mutations/tree.js @@ -0,0 +1,36 @@ +import * as types from '../mutation_types'; + +export default { + [types.TOGGLE_TREE_OPEN](state, tree) { + Object.assign(tree, { + opened: !tree.opened, + }); + }, + [types.CREATE_TREE](state, { treePath }) { + Object.assign(state, { + trees: Object.assign({}, state.trees, { + [treePath]: { + tree: [], + }, + }), + }); + }, + [types.SET_DIRECTORY_DATA](state, { data, tree }) { + Object.assign(tree, { + tree: data, + }); + }, + [types.SET_PARENT_TREE_URL](state, url) { + Object.assign(state, { + parentTreeUrl: url, + }); + }, + [types.SET_LAST_COMMIT_URL](state, { tree = state, url }) { + Object.assign(tree, { + lastCommitPath: url, + }); + }, + [types.CREATE_TMP_TREE](state, { parent, tmpEntry }) { + parent.tree.push(tmpEntry); + }, +}; diff --git a/app/assets/javascripts/ide/stores/state.js b/app/assets/javascripts/ide/stores/state.js new file mode 100644 index 00000000000..539e382830f --- /dev/null +++ b/app/assets/javascripts/ide/stores/state.js @@ -0,0 +1,22 @@ +export default () => ({ + canCommit: false, + currentProjectId: '', + currentBranchId: '', + currentBlobView: 'repo-editor', + discardPopupOpen: false, + editMode: true, + endpoints: {}, + isRoot: false, + isInitialRoot: false, + lastCommitPath: '', + loading: false, + onTopOfBranch: false, + openFiles: [], + selectedFile: null, + path: '', + parentTreeUrl: '', + trees: {}, + projects: {}, + leftPanelCollapsed: false, + rightPanelCollapsed: true, +}); diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js new file mode 100644 index 00000000000..29e3ab5d040 --- /dev/null +++ b/app/assets/javascripts/ide/stores/utils.js @@ -0,0 +1,175 @@ +export const dataStructure = () => ({ + id: '', + key: '', + type: '', + projectId: '', + branchId: '', + name: '', + url: '', + path: '', + level: 0, + tempFile: false, + icon: '', + tree: [], + loading: false, + opened: false, + active: false, + changed: false, + lastCommitPath: '', + lastCommit: { + id: '', + url: '', + message: '', + updatedAt: '', + author: '', + }, + tree_url: '', + blamePath: '', + commitsPath: '', + permalink: '', + rawPath: '', + binary: false, + html: '', + raw: '', + content: '', + parentTreeUrl: '', + renderError: false, + base64: false, + editorRow: 1, + editorColumn: 1, + fileLanguage: '', + eol: '', +}); + +export const decorateData = (entity) => { + const { + id, + projectId, + branchId, + type, + url, + name, + icon, + tree_url, + path, + renderError, + content = '', + tempFile = false, + active = false, + opened = false, + changed = false, + parentTreeUrl = '', + level = 0, + base64 = false, + } = entity; + + return { + ...dataStructure(), + id, + projectId, + branchId, + key: `${name}-${type}-${id}`, + type, + name, + url, + tree_url, + path, + level, + tempFile, + icon: `fa-${icon}`, + opened, + active, + parentTreeUrl, + changed, + renderError, + content, + base64, + }; +}; + +/* + Takes the multi-dimensional tree and returns a flattened array. + This allows for the table to recursively render the table rows but keeps the data + structure nested to make it easier to add new files/directories. +*/ +export const treeList = (state, treeId) => { + const baseTree = state.trees[treeId]; + if (baseTree) { + const mapTree = arr => (!arr.tree || !arr.tree.length ? + [] : _.map(arr.tree, a => [a, mapTree(a)])); + + return _.chain(baseTree.tree) + .map(arr => [arr, mapTree(arr)]) + .flatten() + .value(); + } + return []; +}; + +export const getTree = state => (namespace, projectId, branch) => state.trees[`${namespace}/${projectId}/${branch}`]; + +export const getTreeEntry = (store, treeId, path) => { + const fileList = treeList(store.state, treeId); + return fileList ? fileList.find(file => file.path === path) : null; +}; + +export const findEntry = (tree, type, name) => tree.find( + f => f.type === type && f.name === name, +); + +export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path); + +export const setPageTitle = (title) => { + document.title = title; +}; + +export const createTemp = ({ + projectId, branchId, name, path, type, level, changed, content, base64, url, +}) => { + const treePath = path ? `${path}/${name}` : name; + + return decorateData({ + id: new Date().getTime().toString(), + projectId, + branchId, + name, + type, + tempFile: true, + path: treePath, + icon: type === 'tree' ? 'folder' : 'file-text-o', + changed, + content, + parentTreeUrl: '', + level, + base64, + renderError: base64, + url, + }); +}; + +export const createOrMergeEntry = ({ tree, + projectId, + branchId, + entry, + type, + parentTreeUrl, + level }) => { + const found = findEntry(tree.tree || tree, type, entry.name); + + if (found) { + return Object.assign({}, found, { + id: entry.id, + url: entry.url, + tempFile: false, + }); + } + + return decorateData({ + ...entry, + projectId, + branchId, + type, + parentTreeUrl, + level, + }); +}; diff --git a/app/assets/javascripts/new_commit_form.js b/app/assets/javascripts/new_commit_form.js index 6e152497d20..a2f0a44863f 100644 --- a/app/assets/javascripts/new_commit_form.js +++ b/app/assets/javascripts/new_commit_form.js @@ -6,11 +6,12 @@ export default class NewCommitForm { this.branchName = form.find('.js-branch-name'); this.originalBranch = form.find('.js-original-branch'); this.createMergeRequest = form.find('.js-create-merge-request'); - this.createMergeRequestContainer = form.find('.js-create-merge-request-container'); + this.createMergeRequestContainer = form.find( + '.js-create-merge-request-container', + ); this.branchName.keyup(this.renderDestination); this.renderDestination(); } - renderDestination() { var different; different = this.branchName.val() !== this.originalBranch.val(); @@ -23,6 +24,6 @@ export default class NewCommitForm { this.createMergeRequestContainer.hide(); this.createMergeRequest.prop('checked', false); } - return this.wasDifferent = different; + return (this.wasDifferent = different); } } diff --git a/app/assets/javascripts/repo/components/commit_sidebar/list.vue b/app/assets/javascripts/repo/components/commit_sidebar/list.vue deleted file mode 100644 index fb862e7bf01..00000000000 --- a/app/assets/javascripts/repo/components/commit_sidebar/list.vue +++ /dev/null @@ -1,89 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/commit_sidebar/list_collapsed.vue b/app/assets/javascripts/repo/components/commit_sidebar/list_collapsed.vue deleted file mode 100644 index 6a0262f271b..00000000000 --- a/app/assets/javascripts/repo/components/commit_sidebar/list_collapsed.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/commit_sidebar/list_item.vue b/app/assets/javascripts/repo/components/commit_sidebar/list_item.vue deleted file mode 100644 index 742f746e02f..00000000000 --- a/app/assets/javascripts/repo/components/commit_sidebar/list_item.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/new_branch_form.vue b/app/assets/javascripts/repo/components/new_branch_form.vue deleted file mode 100644 index ba7090e4a9d..00000000000 --- a/app/assets/javascripts/repo/components/new_branch_form.vue +++ /dev/null @@ -1,108 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/new_dropdown/index.vue b/app/assets/javascripts/repo/components/new_dropdown/index.vue deleted file mode 100644 index 781404cf8ca..00000000000 --- a/app/assets/javascripts/repo/components/new_dropdown/index.vue +++ /dev/null @@ -1,89 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/new_dropdown/modal.vue b/app/assets/javascripts/repo/components/new_dropdown/modal.vue deleted file mode 100644 index c191af7dec3..00000000000 --- a/app/assets/javascripts/repo/components/new_dropdown/modal.vue +++ /dev/null @@ -1,98 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/new_dropdown/upload.vue b/app/assets/javascripts/repo/components/new_dropdown/upload.vue deleted file mode 100644 index 14ad32f4ae0..00000000000 --- a/app/assets/javascripts/repo/components/new_dropdown/upload.vue +++ /dev/null @@ -1,68 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo.vue b/app/assets/javascripts/repo/components/repo.vue deleted file mode 100644 index a00e1e9d809..00000000000 --- a/app/assets/javascripts/repo/components/repo.vue +++ /dev/null @@ -1,63 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_commit_section.vue b/app/assets/javascripts/repo/components/repo_commit_section.vue deleted file mode 100644 index 4e0178072cb..00000000000 --- a/app/assets/javascripts/repo/components/repo_commit_section.vue +++ /dev/null @@ -1,178 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_edit_button.vue b/app/assets/javascripts/repo/components/repo_edit_button.vue deleted file mode 100644 index 37bd9003e96..00000000000 --- a/app/assets/javascripts/repo/components/repo_edit_button.vue +++ /dev/null @@ -1,57 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_editor.vue b/app/assets/javascripts/repo/components/repo_editor.vue deleted file mode 100644 index f37cbd1e961..00000000000 --- a/app/assets/javascripts/repo/components/repo_editor.vue +++ /dev/null @@ -1,89 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_file.vue b/app/assets/javascripts/repo/components/repo_file.vue deleted file mode 100644 index 75787ad6103..00000000000 --- a/app/assets/javascripts/repo/components/repo_file.vue +++ /dev/null @@ -1,117 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_file_buttons.vue b/app/assets/javascripts/repo/components/repo_file_buttons.vue deleted file mode 100644 index 34f0d51819a..00000000000 --- a/app/assets/javascripts/repo/components/repo_file_buttons.vue +++ /dev/null @@ -1,56 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_loading_file.vue b/app/assets/javascripts/repo/components/repo_loading_file.vue deleted file mode 100644 index 8fa637d771f..00000000000 --- a/app/assets/javascripts/repo/components/repo_loading_file.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_prev_directory.vue b/app/assets/javascripts/repo/components/repo_prev_directory.vue deleted file mode 100644 index a2b305bbd05..00000000000 --- a/app/assets/javascripts/repo/components/repo_prev_directory.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_preview.vue b/app/assets/javascripts/repo/components/repo_preview.vue deleted file mode 100644 index 3d1e0297bd5..00000000000 --- a/app/assets/javascripts/repo/components/repo_preview.vue +++ /dev/null @@ -1,65 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue deleted file mode 100644 index 4ea21913129..00000000000 --- a/app/assets/javascripts/repo/components/repo_sidebar.vue +++ /dev/null @@ -1,85 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_tab.vue b/app/assets/javascripts/repo/components/repo_tab.vue deleted file mode 100644 index fb29a60df66..00000000000 --- a/app/assets/javascripts/repo/components/repo_tab.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/components/repo_tabs.vue b/app/assets/javascripts/repo/components/repo_tabs.vue deleted file mode 100644 index ab0bef4f0ac..00000000000 --- a/app/assets/javascripts/repo/components/repo_tabs.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - diff --git a/app/assets/javascripts/repo/index.js b/app/assets/javascripts/repo/index.js deleted file mode 100644 index b6801af7fcb..00000000000 --- a/app/assets/javascripts/repo/index.js +++ /dev/null @@ -1,106 +0,0 @@ -import Vue from 'vue'; -import { mapActions } from 'vuex'; -import { convertPermissionToBoolean } from '../lib/utils/common_utils'; -import Repo from './components/repo.vue'; -import RepoEditButton from './components/repo_edit_button.vue'; -import newBranchForm from './components/new_branch_form.vue'; -import newDropdown from './components/new_dropdown/index.vue'; -import store from './stores'; -import Translate from '../vue_shared/translate'; - -function initRepo(el) { - if (!el) return null; - - return new Vue({ - el, - store, - components: { - repo: Repo, - }, - methods: { - ...mapActions([ - 'setInitialData', - ]), - }, - created() { - const data = el.dataset; - - this.setInitialData({ - project: { - id: data.projectId, - name: data.projectName, - url: data.projectUrl, - }, - endpoints: { - rootEndpoint: data.url, - newMergeRequestUrl: data.newMergeRequestUrl, - rootUrl: data.rootUrl, - }, - canCommit: convertPermissionToBoolean(data.canCommit), - onTopOfBranch: convertPermissionToBoolean(data.onTopOfBranch), - currentRef: data.ref, - path: data.currentPath, - currentBranch: data.currentBranch, - isRoot: convertPermissionToBoolean(data.root), - isInitialRoot: convertPermissionToBoolean(data.root), - }); - }, - render(createElement) { - return createElement('repo'); - }, - }); -} - -function initRepoEditButton(el) { - return new Vue({ - el, - store, - components: { - repoEditButton: RepoEditButton, - }, - render(createElement) { - return createElement('repo-edit-button'); - }, - }); -} - -function initNewDropdown(el) { - return new Vue({ - el, - store, - components: { - newDropdown, - }, - render(createElement) { - return createElement('new-dropdown'); - }, - }); -} - -function initNewBranchForm() { - const el = document.querySelector('.js-new-branch-dropdown'); - - if (!el) return null; - - return new Vue({ - el, - components: { - newBranchForm, - }, - store, - render(createElement) { - return createElement('new-branch-form'); - }, - }); -} - -const repo = document.getElementById('repo'); -const editButton = document.querySelector('.editable-mode'); -const newDropdownHolder = document.querySelector('.js-new-dropdown'); - -Vue.use(Translate); - -initRepo(repo); -initRepoEditButton(editButton); -initNewBranchForm(); -initNewDropdown(newDropdownHolder); diff --git a/app/assets/javascripts/repo/lib/common/disposable.js b/app/assets/javascripts/repo/lib/common/disposable.js deleted file mode 100644 index 84b29bdb600..00000000000 --- a/app/assets/javascripts/repo/lib/common/disposable.js +++ /dev/null @@ -1,14 +0,0 @@ -export default class Disposable { - constructor() { - this.disposers = new Set(); - } - - add(...disposers) { - disposers.forEach(disposer => this.disposers.add(disposer)); - } - - dispose() { - this.disposers.forEach(disposer => disposer.dispose()); - this.disposers.clear(); - } -} diff --git a/app/assets/javascripts/repo/lib/common/model.js b/app/assets/javascripts/repo/lib/common/model.js deleted file mode 100644 index 23c4811e6c0..00000000000 --- a/app/assets/javascripts/repo/lib/common/model.js +++ /dev/null @@ -1,56 +0,0 @@ -/* global monaco */ -import Disposable from './disposable'; - -export default class Model { - constructor(monaco, file) { - this.monaco = monaco; - this.disposable = new Disposable(); - this.file = file; - this.content = file.content !== '' ? file.content : file.raw; - - this.disposable.add( - this.originalModel = this.monaco.editor.createModel( - this.file.raw, - undefined, - new this.monaco.Uri(null, null, `original/${this.file.path}`), - ), - this.model = this.monaco.editor.createModel( - this.content, - undefined, - new this.monaco.Uri(null, null, this.file.path), - ), - ); - - this.events = new Map(); - } - - get url() { - return this.model.uri.toString(); - } - - get path() { - return this.file.path; - } - - getModel() { - return this.model; - } - - getOriginalModel() { - return this.originalModel; - } - - onChange(cb) { - this.events.set( - this.path, - this.disposable.add( - this.model.onDidChangeContent(e => cb(this.model, e)), - ), - ); - } - - dispose() { - this.disposable.dispose(); - this.events.clear(); - } -} diff --git a/app/assets/javascripts/repo/lib/common/model_manager.js b/app/assets/javascripts/repo/lib/common/model_manager.js deleted file mode 100644 index fd462252795..00000000000 --- a/app/assets/javascripts/repo/lib/common/model_manager.js +++ /dev/null @@ -1,32 +0,0 @@ -import Disposable from './disposable'; -import Model from './model'; - -export default class ModelManager { - constructor(monaco) { - this.monaco = monaco; - this.disposable = new Disposable(); - this.models = new Map(); - } - - hasCachedModel(path) { - return this.models.has(path); - } - - addModel(file) { - if (this.hasCachedModel(file.path)) { - return this.models.get(file.path); - } - - const model = new Model(this.monaco, file); - this.models.set(model.path, model); - this.disposable.add(model); - - return model; - } - - dispose() { - // dispose of all the models - this.disposable.dispose(); - this.models.clear(); - } -} diff --git a/app/assets/javascripts/repo/lib/decorations/controller.js b/app/assets/javascripts/repo/lib/decorations/controller.js deleted file mode 100644 index 0954b7973c4..00000000000 --- a/app/assets/javascripts/repo/lib/decorations/controller.js +++ /dev/null @@ -1,43 +0,0 @@ -export default class DecorationsController { - constructor(editor) { - this.editor = editor; - this.decorations = new Map(); - this.editorDecorations = new Map(); - } - - getAllDecorationsForModel(model) { - if (!this.decorations.has(model.url)) return []; - - const modelDecorations = this.decorations.get(model.url); - const decorations = []; - - modelDecorations.forEach(val => decorations.push(...val)); - - return decorations; - } - - addDecorations(model, decorationsKey, decorations) { - const decorationMap = this.decorations.get(model.url) || new Map(); - - decorationMap.set(decorationsKey, decorations); - - this.decorations.set(model.url, decorationMap); - - this.decorate(model); - } - - decorate(model) { - const decorations = this.getAllDecorationsForModel(model); - const oldDecorations = this.editorDecorations.get(model.url) || []; - - this.editorDecorations.set( - model.url, - this.editor.instance.deltaDecorations(oldDecorations, decorations), - ); - } - - dispose() { - this.decorations.clear(); - this.editorDecorations.clear(); - } -} diff --git a/app/assets/javascripts/repo/lib/diff/controller.js b/app/assets/javascripts/repo/lib/diff/controller.js deleted file mode 100644 index dc0b1c95e59..00000000000 --- a/app/assets/javascripts/repo/lib/diff/controller.js +++ /dev/null @@ -1,71 +0,0 @@ -/* global monaco */ -import { throttle } from 'underscore'; -import DirtyDiffWorker from './diff_worker'; -import Disposable from '../common/disposable'; - -export const getDiffChangeType = (change) => { - if (change.modified) { - return 'modified'; - } else if (change.added) { - return 'added'; - } else if (change.removed) { - return 'removed'; - } - - return ''; -}; - -export const getDecorator = change => ({ - range: new monaco.Range( - change.lineNumber, - 1, - change.endLineNumber, - 1, - ), - options: { - isWholeLine: true, - linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(change)}`, - }, -}); - -export default class DirtyDiffController { - constructor(modelManager, decorationsController) { - this.disposable = new Disposable(); - this.editorSimpleWorker = null; - this.modelManager = modelManager; - this.decorationsController = decorationsController; - this.dirtyDiffWorker = new DirtyDiffWorker(); - this.throttledComputeDiff = throttle(this.computeDiff, 250); - this.decorate = this.decorate.bind(this); - - this.dirtyDiffWorker.addEventListener('message', this.decorate); - } - - attachModel(model) { - model.onChange(() => this.throttledComputeDiff(model)); - } - - computeDiff(model) { - this.dirtyDiffWorker.postMessage({ - path: model.path, - originalContent: model.getOriginalModel().getValue(), - newContent: model.getModel().getValue(), - }); - } - - reDecorate(model) { - this.decorationsController.decorate(model); - } - - decorate({ data }) { - const decorations = data.changes.map(change => getDecorator(change)); - this.decorationsController.addDecorations(data.path, 'dirtyDiff', decorations); - } - - dispose() { - this.disposable.dispose(); - - this.dirtyDiffWorker.removeEventListener('message', this.decorate); - this.dirtyDiffWorker.terminate(); - } -} diff --git a/app/assets/javascripts/repo/lib/diff/diff.js b/app/assets/javascripts/repo/lib/diff/diff.js deleted file mode 100644 index 0e37f5c4704..00000000000 --- a/app/assets/javascripts/repo/lib/diff/diff.js +++ /dev/null @@ -1,30 +0,0 @@ -import { diffLines } from 'diff'; - -// eslint-disable-next-line import/prefer-default-export -export const computeDiff = (originalContent, newContent) => { - const changes = diffLines(originalContent, newContent); - - let lineNumber = 1; - return changes.reduce((acc, change) => { - const findOnLine = acc.find(c => c.lineNumber === lineNumber); - - if (findOnLine) { - Object.assign(findOnLine, change, { - modified: true, - endLineNumber: (lineNumber + change.count) - 1, - }); - } else if ('added' in change || 'removed' in change) { - acc.push(Object.assign({}, change, { - lineNumber, - modified: undefined, - endLineNumber: (lineNumber + change.count) - 1, - })); - } - - if (!change.removed) { - lineNumber += change.count; - } - - return acc; - }, []); -}; diff --git a/app/assets/javascripts/repo/lib/diff/diff_worker.js b/app/assets/javascripts/repo/lib/diff/diff_worker.js deleted file mode 100644 index e74c4046330..00000000000 --- a/app/assets/javascripts/repo/lib/diff/diff_worker.js +++ /dev/null @@ -1,10 +0,0 @@ -import { computeDiff } from './diff'; - -self.addEventListener('message', (e) => { - const data = e.data; - - self.postMessage({ - path: data.path, - changes: computeDiff(data.originalContent, data.newContent), - }); -}); diff --git a/app/assets/javascripts/repo/lib/editor.js b/app/assets/javascripts/repo/lib/editor.js deleted file mode 100644 index db499444402..00000000000 --- a/app/assets/javascripts/repo/lib/editor.js +++ /dev/null @@ -1,79 +0,0 @@ -import DecorationsController from './decorations/controller'; -import DirtyDiffController from './diff/controller'; -import Disposable from './common/disposable'; -import ModelManager from './common/model_manager'; -import editorOptions from './editor_options'; - -export default class Editor { - static create(monaco) { - this.editorInstance = new Editor(monaco); - - return this.editorInstance; - } - - constructor(monaco) { - this.monaco = monaco; - this.currentModel = null; - this.instance = null; - this.dirtyDiffController = null; - this.disposable = new Disposable(); - - this.disposable.add( - this.modelManager = new ModelManager(this.monaco), - this.decorationsController = new DecorationsController(this), - ); - } - - createInstance(domElement) { - if (!this.instance) { - this.disposable.add( - this.instance = this.monaco.editor.create(domElement, { - model: null, - readOnly: false, - contextmenu: true, - scrollBeyondLastLine: false, - }), - this.dirtyDiffController = new DirtyDiffController( - this.modelManager, this.decorationsController, - ), - ); - } - } - - createModel(file) { - return this.modelManager.addModel(file); - } - - attachModel(model) { - this.instance.setModel(model.getModel()); - this.dirtyDiffController.attachModel(model); - - this.currentModel = model; - - this.instance.updateOptions(editorOptions.reduce((acc, obj) => { - Object.keys(obj).forEach((key) => { - Object.assign(acc, { - [key]: obj[key](model), - }); - }); - return acc; - }, {})); - - this.dirtyDiffController.reDecorate(model); - } - - clearEditor() { - if (this.instance) { - this.instance.setModel(null); - } - } - - dispose() { - this.disposable.dispose(); - - // dispose main monaco instance - if (this.instance) { - this.instance = null; - } - } -} diff --git a/app/assets/javascripts/repo/lib/editor_options.js b/app/assets/javascripts/repo/lib/editor_options.js deleted file mode 100644 index 701affc466e..00000000000 --- a/app/assets/javascripts/repo/lib/editor_options.js +++ /dev/null @@ -1,2 +0,0 @@ -export default [{ -}]; diff --git a/app/assets/javascripts/repo/monaco_loader.js b/app/assets/javascripts/repo/monaco_loader.js deleted file mode 100644 index af83a1ec0b4..00000000000 --- a/app/assets/javascripts/repo/monaco_loader.js +++ /dev/null @@ -1,11 +0,0 @@ -import monacoContext from 'monaco-editor/dev/vs/loader'; - -monacoContext.require.config({ - paths: { - vs: `${__webpack_public_path__}monaco-editor/vs`, // eslint-disable-line camelcase - }, -}); - -// eslint-disable-next-line no-underscore-dangle -window.__monaco_context__ = monacoContext; -export default monacoContext.require; diff --git a/app/assets/javascripts/repo/services/index.js b/app/assets/javascripts/repo/services/index.js deleted file mode 100644 index 994d325e991..00000000000 --- a/app/assets/javascripts/repo/services/index.js +++ /dev/null @@ -1,44 +0,0 @@ -import Vue from 'vue'; -import VueResource from 'vue-resource'; -import Api from '../../api'; - -Vue.use(VueResource); - -export default { - getTreeData(endpoint) { - return Vue.http.get(endpoint, { params: { format: 'json' } }); - }, - getFileData(endpoint) { - return Vue.http.get(endpoint, { params: { format: 'json' } }); - }, - getRawFileData(file) { - if (file.tempFile) { - return Promise.resolve(file.content); - } - - if (file.raw) { - return Promise.resolve(file.raw); - } - - return Vue.http.get(file.rawPath, { params: { format: 'json' } }) - .then(res => res.text()); - }, - getBranchData(projectId, currentBranch) { - return Api.branchSingle(projectId, currentBranch); - }, - createBranch(projectId, payload) { - const url = Api.buildUrl(Api.createBranchPath).replace(':id', projectId); - - return Vue.http.post(url, payload); - }, - commit(projectId, payload) { - return Api.commitMultiple(projectId, payload); - }, - getTreeLastCommit(endpoint) { - return Vue.http.get(endpoint, { - params: { - format: 'json', - }, - }); - }, -}; diff --git a/app/assets/javascripts/repo/stores/actions.js b/app/assets/javascripts/repo/stores/actions.js deleted file mode 100644 index af5dcf054ef..00000000000 --- a/app/assets/javascripts/repo/stores/actions.js +++ /dev/null @@ -1,146 +0,0 @@ -import Vue from 'vue'; -import { visitUrl } from '../../lib/utils/url_utility'; -import flash from '../../flash'; -import service from '../services'; -import * as types from './mutation_types'; - -export const redirectToUrl = (_, url) => visitUrl(url); - -export const setInitialData = ({ commit }, data) => commit(types.SET_INITIAL_DATA, data); - -export const closeDiscardPopup = ({ commit }) => commit(types.TOGGLE_DISCARD_POPUP, false); - -export const discardAllChanges = ({ commit, getters, dispatch }) => { - const changedFiles = getters.changedFiles; - - changedFiles.forEach((file) => { - commit(types.DISCARD_FILE_CHANGES, file); - - if (file.tempFile) { - dispatch('closeFile', { file, force: true }); - } - }); -}; - -export const closeAllFiles = ({ state, dispatch }) => { - state.openFiles.forEach(file => dispatch('closeFile', { file })); -}; - -export const toggleEditMode = ({ state, commit, getters, dispatch }, force = false) => { - const changedFiles = getters.changedFiles; - - if (changedFiles.length && !force) { - commit(types.TOGGLE_DISCARD_POPUP, true); - } else { - commit(types.TOGGLE_EDIT_MODE); - commit(types.TOGGLE_DISCARD_POPUP, false); - dispatch('toggleBlobView'); - - if (!state.editMode) { - dispatch('discardAllChanges'); - } - } -}; - -export const toggleBlobView = ({ commit, state }) => { - if (state.editMode) { - commit(types.SET_EDIT_MODE); - } else { - commit(types.SET_PREVIEW_MODE); - } -}; - -export const checkCommitStatus = ({ state }) => service.getBranchData( - state.project.id, - state.currentBranch, -) - .then((data) => { - const { id } = data.commit; - - if (state.currentRef !== id) { - return true; - } - - return false; - }) - .catch(() => flash('Error checking branch data. Please try again.')); - -export const commitChanges = ({ commit, state, dispatch, getters }, { payload, newMr }) => - service.commit(state.project.id, payload) - .then((data) => { - const { branch } = payload; - if (!data.short_id) { - flash(data.message); - return; - } - - const lastCommit = { - commit_path: `${state.project.url}/commit/${data.id}`, - commit: { - message: data.message, - authored_date: data.committed_date, - }, - }; - - flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice'); - - if (newMr) { - dispatch('redirectToUrl', `${state.endpoints.newMergeRequestUrl}${branch}`); - } else { - commit(types.SET_COMMIT_REF, data.id); - - getters.changedFiles.forEach((entry) => { - commit(types.SET_LAST_COMMIT_DATA, { - entry, - lastCommit, - }); - }); - - dispatch('discardAllChanges'); - dispatch('closeAllFiles'); - dispatch('toggleEditMode'); - - window.scrollTo(0, 0); - } - }) - .catch(() => flash('Error committing changes. Please try again.')); - -export const createTempEntry = ({ state, dispatch }, { name, type, content = '', base64 = false }) => { - if (type === 'tree') { - dispatch('createTempTree', name); - } else if (type === 'blob') { - dispatch('createTempFile', { - tree: state, - name, - base64, - content, - }); - } -}; - -export const popHistoryState = ({ state, dispatch, getters }) => { - const treeList = getters.treeList; - const tree = treeList.find(file => file.url === state.previousUrl); - - if (!tree) return; - - if (tree.type === 'tree') { - dispatch('toggleTreeOpen', { endpoint: tree.url, tree }); - } -}; - -export const scrollToTab = () => { - Vue.nextTick(() => { - const tabs = document.getElementById('tabs'); - - if (tabs) { - const tabEl = tabs.querySelector('.active .repo-tab'); - - tabEl.focus(); - } - }); -}; - -export * from './actions/tree'; -export * from './actions/file'; -export * from './actions/branch'; diff --git a/app/assets/javascripts/repo/stores/actions/branch.js b/app/assets/javascripts/repo/stores/actions/branch.js deleted file mode 100644 index 61d9a5af3e3..00000000000 --- a/app/assets/javascripts/repo/stores/actions/branch.js +++ /dev/null @@ -1,20 +0,0 @@ -import service from '../../services'; -import * as types from '../mutation_types'; -import { pushState } from '../utils'; - -// eslint-disable-next-line import/prefer-default-export -export const createNewBranch = ({ state, commit }, branch) => service.createBranch( - state.project.id, - { - branch, - ref: state.currentBranch, - }, -).then(res => res.json()) -.then((data) => { - const branchName = data.name; - const url = location.href.replace(state.currentBranch, branchName); - - pushState(url); - - commit(types.SET_CURRENT_BRANCH, branchName); -}); diff --git a/app/assets/javascripts/repo/stores/actions/file.js b/app/assets/javascripts/repo/stores/actions/file.js deleted file mode 100644 index 5bae4fa826a..00000000000 --- a/app/assets/javascripts/repo/stores/actions/file.js +++ /dev/null @@ -1,110 +0,0 @@ -import { normalizeHeaders } from '../../../lib/utils/common_utils'; -import flash from '../../../flash'; -import service from '../../services'; -import * as types from '../mutation_types'; -import { - findEntry, - pushState, - setPageTitle, - createTemp, - findIndexOfFile, -} from '../utils'; - -export const closeFile = ({ commit, state, dispatch }, { file, force = false }) => { - if ((file.changed || file.tempFile) && !force) return; - - const indexOfClosedFile = findIndexOfFile(state.openFiles, file); - const fileWasActive = file.active; - - commit(types.TOGGLE_FILE_OPEN, file); - commit(types.SET_FILE_ACTIVE, { file, active: false }); - - if (state.openFiles.length > 0 && fileWasActive) { - const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1; - const nextFileToOpen = state.openFiles[nextIndexToOpen]; - - dispatch('setFileActive', nextFileToOpen); - } else if (!state.openFiles.length) { - pushState(file.parentTreeUrl); - } - - dispatch('getLastCommitData'); -}; - -export const setFileActive = ({ commit, state, getters, dispatch }, file) => { - const currentActiveFile = getters.activeFile; - - if (file.active) return; - - if (currentActiveFile) { - commit(types.SET_FILE_ACTIVE, { file: currentActiveFile, active: false }); - } - - commit(types.SET_FILE_ACTIVE, { file, active: true }); - dispatch('scrollToTab'); - - // reset hash for line highlighting - location.hash = ''; -}; - -export const getFileData = ({ state, commit, dispatch }, file) => { - commit(types.TOGGLE_LOADING, file); - - service.getFileData(file.url) - .then((res) => { - const pageTitle = decodeURI(normalizeHeaders(res.headers)['PAGE-TITLE']); - - setPageTitle(pageTitle); - - return res.json(); - }) - .then((data) => { - commit(types.SET_FILE_DATA, { data, file }); - commit(types.TOGGLE_FILE_OPEN, file); - dispatch('setFileActive', file); - commit(types.TOGGLE_LOADING, file); - - pushState(file.url); - }) - .catch(() => { - commit(types.TOGGLE_LOADING, file); - flash('Error loading file data. Please try again.'); - }); -}; - -export const getRawFileData = ({ commit, dispatch }, file) => service.getRawFileData(file) - .then((raw) => { - commit(types.SET_FILE_RAW_DATA, { file, raw }); - }) - .catch(() => flash('Error loading file content. Please try again.')); - -export const changeFileContent = ({ commit }, { file, content }) => { - commit(types.UPDATE_FILE_CONTENT, { file, content }); -}; - -export const createTempFile = ({ state, commit, dispatch }, { tree, name, content = '', base64 = '' }) => { - const file = createTemp({ - name: name.replace(`${state.path}/`, ''), - path: tree.path, - type: 'blob', - level: tree.level !== undefined ? tree.level + 1 : 0, - changed: true, - content, - base64, - }); - - if (findEntry(tree, 'blob', file.name)) return flash(`The name "${file.name}" is already taken in this directory.`); - - commit(types.CREATE_TMP_FILE, { - parent: tree, - file, - }); - commit(types.TOGGLE_FILE_OPEN, file); - dispatch('setFileActive', file); - - if (!state.editMode && !file.base64) { - dispatch('toggleEditMode', true); - } - - return Promise.resolve(file); -}; diff --git a/app/assets/javascripts/repo/stores/actions/tree.js b/app/assets/javascripts/repo/stores/actions/tree.js deleted file mode 100644 index 7c251e26bed..00000000000 --- a/app/assets/javascripts/repo/stores/actions/tree.js +++ /dev/null @@ -1,163 +0,0 @@ -import { visitUrl } from '../../../lib/utils/url_utility'; -import { normalizeHeaders } from '../../../lib/utils/common_utils'; -import flash from '../../../flash'; -import service from '../../services'; -import * as types from '../mutation_types'; -import { - pushState, - setPageTitle, - findEntry, - createTemp, - createOrMergeEntry, -} from '../utils'; - -export const getTreeData = ( - { commit, state, dispatch }, - { endpoint = state.endpoints.rootEndpoint, tree = state } = {}, -) => { - commit(types.TOGGLE_LOADING, tree); - - service.getTreeData(endpoint) - .then((res) => { - const pageTitle = decodeURI(normalizeHeaders(res.headers)['PAGE-TITLE']); - - setPageTitle(pageTitle); - - return res.json(); - }) - .then((data) => { - const prevLastCommitPath = tree.lastCommitPath; - if (!state.isInitialRoot) { - commit(types.SET_ROOT, data.path === '/'); - } - - dispatch('updateDirectoryData', { data, tree }); - commit(types.SET_PARENT_TREE_URL, data.parent_tree_url); - commit(types.SET_LAST_COMMIT_URL, { tree, url: data.last_commit_path }); - commit(types.TOGGLE_LOADING, tree); - - if (prevLastCommitPath !== null) { - dispatch('getLastCommitData', tree); - } - - pushState(endpoint); - }) - .catch(() => { - flash('Error loading tree data. Please try again.'); - commit(types.TOGGLE_LOADING, tree); - }); -}; - -export const toggleTreeOpen = ({ commit, dispatch }, { endpoint, tree }) => { - if (tree.opened) { - // send empty data to clear the tree - const data = { trees: [], blobs: [], submodules: [] }; - - pushState(tree.parentTreeUrl); - - commit(types.SET_PREVIOUS_URL, tree.parentTreeUrl); - dispatch('updateDirectoryData', { data, tree }); - } else { - commit(types.SET_PREVIOUS_URL, endpoint); - dispatch('getTreeData', { endpoint, tree }); - } - - commit(types.TOGGLE_TREE_OPEN, tree); -}; - -export const clickedTreeRow = ({ commit, dispatch }, row) => { - if (row.type === 'tree') { - dispatch('toggleTreeOpen', { - endpoint: row.url, - tree: row, - }); - } else if (row.type === 'submodule') { - commit(types.TOGGLE_LOADING, row); - - visitUrl(row.url); - } else if (row.type === 'blob' && row.opened) { - dispatch('setFileActive', row); - } else { - dispatch('getFileData', row); - } -}; - -export const createTempTree = ({ state, commit, dispatch }, name) => { - let tree = state; - const dirNames = name.replace(new RegExp(`^${state.path}/`), '').split('/'); - - dirNames.forEach((dirName) => { - const foundEntry = findEntry(tree, 'tree', dirName); - - if (!foundEntry) { - const tmpEntry = createTemp({ - name: dirName, - path: tree.path, - type: 'tree', - level: tree.level !== undefined ? tree.level + 1 : 0, - }); - - commit(types.CREATE_TMP_TREE, { - parent: tree, - tmpEntry, - }); - commit(types.TOGGLE_TREE_OPEN, tmpEntry); - - tree = tmpEntry; - } else { - tree = foundEntry; - } - }); - - if (tree.tempFile) { - dispatch('createTempFile', { - tree, - name: '.gitkeep', - }); - } -}; - -export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = state) => { - if (tree.lastCommitPath === null || getters.isCollapsed) return; - - service.getTreeLastCommit(tree.lastCommitPath) - .then((res) => { - const lastCommitPath = normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null; - - commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath }); - - return res.json(); - }) - .then((data) => { - data.forEach((lastCommit) => { - const entry = findEntry(tree, lastCommit.type, lastCommit.file_name); - - if (entry) { - commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit }); - } - }); - - dispatch('getLastCommitData', tree); - }) - .catch(() => flash('Error fetching log data.')); -}; - -export const updateDirectoryData = ({ commit, state }, { data, tree }) => { - const level = tree.level !== undefined ? tree.level + 1 : 0; - const parentTreeUrl = data.parent_tree_url ? `${data.parent_tree_url}${data.path}` : state.endpoints.rootUrl; - const createEntry = (entry, type) => createOrMergeEntry({ - tree, - entry, - level, - type, - parentTreeUrl, - }); - - const formattedData = [ - ...data.trees.map(t => createEntry(t, 'tree')), - ...data.submodules.map(m => createEntry(m, 'submodule')), - ...data.blobs.map(b => createEntry(b, 'blob')), - ]; - - commit(types.SET_DIRECTORY_DATA, { tree, data: formattedData }); -}; diff --git a/app/assets/javascripts/repo/stores/getters.js b/app/assets/javascripts/repo/stores/getters.js deleted file mode 100644 index 5ce9f449905..00000000000 --- a/app/assets/javascripts/repo/stores/getters.js +++ /dev/null @@ -1,40 +0,0 @@ -import _ from 'underscore'; - -/* - Takes the multi-dimensional tree and returns a flattened array. - This allows for the table to recursively render the table rows but keeps the data - structure nested to make it easier to add new files/directories. -*/ -export const treeList = (state) => { - const mapTree = arr => (!arr.tree.length ? [] : _.map(arr.tree, a => [a, mapTree(a)])); - - return _.chain(state.tree) - .map(arr => [arr, mapTree(arr)]) - .flatten() - .value(); -}; - -export const changedFiles = state => state.openFiles.filter(file => file.changed); - -export const activeFile = state => state.openFiles.find(file => file.active); - -export const activeFileExtension = (state) => { - const file = activeFile(state); - return file ? `.${file.path.split('.').pop()}` : ''; -}; - -export const isCollapsed = state => !!state.openFiles.length; - -export const canEditFile = (state) => { - const currentActiveFile = activeFile(state); - const openedFiles = state.openFiles; - - return state.canCommit && - state.onTopOfBranch && - openedFiles.length && - (currentActiveFile && !currentActiveFile.renderError && !currentActiveFile.binary); -}; - -export const addedFiles = state => changedFiles(state).filter(f => f.tempFile); - -export const modifiedFiles = state => changedFiles(state).filter(f => !f.tempFile); diff --git a/app/assets/javascripts/repo/stores/index.js b/app/assets/javascripts/repo/stores/index.js deleted file mode 100644 index 6ac9bfd8189..00000000000 --- a/app/assets/javascripts/repo/stores/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import state from './state'; -import * as actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; - -Vue.use(Vuex); - -export default new Vuex.Store({ - state: state(), - actions, - mutations, - getters, -}); diff --git a/app/assets/javascripts/repo/stores/mutation_types.js b/app/assets/javascripts/repo/stores/mutation_types.js deleted file mode 100644 index bc3390f1506..00000000000 --- a/app/assets/javascripts/repo/stores/mutation_types.js +++ /dev/null @@ -1,30 +0,0 @@ -export const SET_INITIAL_DATA = 'SET_INITIAL_DATA'; -export const TOGGLE_LOADING = 'TOGGLE_LOADING'; -export const SET_COMMIT_REF = 'SET_COMMIT_REF'; -export const SET_PARENT_TREE_URL = 'SET_PARENT_TREE_URL'; -export const SET_ROOT = 'SET_ROOT'; -export const SET_PREVIOUS_URL = 'SET_PREVIOUS_URL'; -export const SET_LAST_COMMIT_DATA = 'SET_LAST_COMMIT_DATA'; - -// Tree mutation types -export const SET_DIRECTORY_DATA = 'SET_DIRECTORY_DATA'; -export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN'; -export const CREATE_TMP_TREE = 'CREATE_TMP_TREE'; -export const SET_LAST_COMMIT_URL = 'SET_LAST_COMMIT_URL'; - -// File mutation types -export const SET_FILE_DATA = 'SET_FILE_DATA'; -export const TOGGLE_FILE_OPEN = 'TOGGLE_FILE_OPEN'; -export const SET_FILE_ACTIVE = 'SET_FILE_ACTIVE'; -export const SET_FILE_RAW_DATA = 'SET_FILE_RAW_DATA'; -export const UPDATE_FILE_CONTENT = 'UPDATE_FILE_CONTENT'; -export const DISCARD_FILE_CHANGES = 'DISCARD_FILE_CHANGES'; -export const CREATE_TMP_FILE = 'CREATE_TMP_FILE'; - -// Viewer mutation types -export const SET_PREVIEW_MODE = 'SET_PREVIEW_MODE'; -export const SET_EDIT_MODE = 'SET_EDIT_MODE'; -export const TOGGLE_EDIT_MODE = 'TOGGLE_EDIT_MODE'; -export const TOGGLE_DISCARD_POPUP = 'TOGGLE_DISCARD_POPUP'; - -export const SET_CURRENT_BRANCH = 'SET_CURRENT_BRANCH'; diff --git a/app/assets/javascripts/repo/stores/mutations.js b/app/assets/javascripts/repo/stores/mutations.js deleted file mode 100644 index ae2ba5bedf7..00000000000 --- a/app/assets/javascripts/repo/stores/mutations.js +++ /dev/null @@ -1,61 +0,0 @@ -import * as types from './mutation_types'; -import fileMutations from './mutations/file'; -import treeMutations from './mutations/tree'; -import branchMutations from './mutations/branch'; - -export default { - [types.SET_INITIAL_DATA](state, data) { - Object.assign(state, data); - }, - [types.SET_PREVIEW_MODE](state) { - Object.assign(state, { - currentBlobView: 'repo-preview', - }); - }, - [types.SET_EDIT_MODE](state) { - Object.assign(state, { - currentBlobView: 'repo-editor', - }); - }, - [types.TOGGLE_LOADING](state, entry) { - Object.assign(entry, { - loading: !entry.loading, - }); - }, - [types.TOGGLE_EDIT_MODE](state) { - Object.assign(state, { - editMode: !state.editMode, - }); - }, - [types.TOGGLE_DISCARD_POPUP](state, discardPopupOpen) { - Object.assign(state, { - discardPopupOpen, - }); - }, - [types.SET_COMMIT_REF](state, ref) { - Object.assign(state, { - currentRef: ref, - }); - }, - [types.SET_ROOT](state, isRoot) { - Object.assign(state, { - isRoot, - isInitialRoot: isRoot, - }); - }, - [types.SET_PREVIOUS_URL](state, previousUrl) { - Object.assign(state, { - previousUrl, - }); - }, - [types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) { - Object.assign(entry.lastCommit, { - url: lastCommit.commit_path, - message: lastCommit.commit.message, - updatedAt: lastCommit.commit.authored_date, - }); - }, - ...fileMutations, - ...treeMutations, - ...branchMutations, -}; diff --git a/app/assets/javascripts/repo/stores/mutations/branch.js b/app/assets/javascripts/repo/stores/mutations/branch.js deleted file mode 100644 index d8229e8a620..00000000000 --- a/app/assets/javascripts/repo/stores/mutations/branch.js +++ /dev/null @@ -1,9 +0,0 @@ -import * as types from '../mutation_types'; - -export default { - [types.SET_CURRENT_BRANCH](state, currentBranch) { - Object.assign(state, { - currentBranch, - }); - }, -}; diff --git a/app/assets/javascripts/repo/stores/mutations/file.js b/app/assets/javascripts/repo/stores/mutations/file.js deleted file mode 100644 index f9ba80b9dc2..00000000000 --- a/app/assets/javascripts/repo/stores/mutations/file.js +++ /dev/null @@ -1,54 +0,0 @@ -import * as types from '../mutation_types'; -import { findIndexOfFile } from '../utils'; - -export default { - [types.SET_FILE_ACTIVE](state, { file, active }) { - Object.assign(file, { - active, - }); - }, - [types.TOGGLE_FILE_OPEN](state, file) { - Object.assign(file, { - opened: !file.opened, - }); - - if (file.opened) { - state.openFiles.push(file); - } else { - state.openFiles.splice(findIndexOfFile(state.openFiles, file), 1); - } - }, - [types.SET_FILE_DATA](state, { data, file }) { - Object.assign(file, { - blamePath: data.blame_path, - commitsPath: data.commits_path, - permalink: data.permalink, - rawPath: data.raw_path, - binary: data.binary, - html: data.html, - renderError: data.render_error, - }); - }, - [types.SET_FILE_RAW_DATA](state, { file, raw }) { - Object.assign(file, { - raw, - }); - }, - [types.UPDATE_FILE_CONTENT](state, { file, content }) { - const changed = content !== file.raw; - - Object.assign(file, { - content, - changed, - }); - }, - [types.DISCARD_FILE_CHANGES](state, file) { - Object.assign(file, { - content: '', - changed: false, - }); - }, - [types.CREATE_TMP_FILE](state, { file, parent }) { - parent.tree.push(file); - }, -}; diff --git a/app/assets/javascripts/repo/stores/mutations/tree.js b/app/assets/javascripts/repo/stores/mutations/tree.js deleted file mode 100644 index 130221c9fda..00000000000 --- a/app/assets/javascripts/repo/stores/mutations/tree.js +++ /dev/null @@ -1,27 +0,0 @@ -import * as types from '../mutation_types'; - -export default { - [types.TOGGLE_TREE_OPEN](state, tree) { - Object.assign(tree, { - opened: !tree.opened, - }); - }, - [types.SET_DIRECTORY_DATA](state, { data, tree }) { - Object.assign(tree, { - tree: data, - }); - }, - [types.SET_PARENT_TREE_URL](state, url) { - Object.assign(state, { - parentTreeUrl: url, - }); - }, - [types.SET_LAST_COMMIT_URL](state, { tree = state, url }) { - Object.assign(tree, { - lastCommitPath: url, - }); - }, - [types.CREATE_TMP_TREE](state, { parent, tmpEntry }) { - parent.tree.push(tmpEntry); - }, -}; diff --git a/app/assets/javascripts/repo/stores/state.js b/app/assets/javascripts/repo/stores/state.js deleted file mode 100644 index 0068834831e..00000000000 --- a/app/assets/javascripts/repo/stores/state.js +++ /dev/null @@ -1,24 +0,0 @@ -export default () => ({ - canCommit: false, - currentBranch: '', - currentBlobView: 'repo-preview', - currentRef: '', - discardPopupOpen: false, - editMode: false, - endpoints: {}, - isRoot: false, - isInitialRoot: false, - lastCommitPath: '', - loading: false, - onTopOfBranch: false, - openFiles: [], - path: '', - project: { - id: 0, - name: '', - url: '', - }, - parentTreeUrl: '', - previousUrl: '', - tree: [], -}); diff --git a/app/assets/javascripts/repo/stores/utils.js b/app/assets/javascripts/repo/stores/utils.js deleted file mode 100644 index fae1f4439a9..00000000000 --- a/app/assets/javascripts/repo/stores/utils.js +++ /dev/null @@ -1,127 +0,0 @@ -export const dataStructure = () => ({ - id: '', - key: '', - type: '', - name: '', - url: '', - path: '', - level: 0, - tempFile: false, - icon: '', - tree: [], - loading: false, - opened: false, - active: false, - changed: false, - lastCommitPath: '', - lastCommit: { - url: '', - message: '', - updatedAt: '', - }, - tree_url: '', - blamePath: '', - commitsPath: '', - permalink: '', - rawPath: '', - binary: false, - html: '', - raw: '', - content: '', - parentTreeUrl: '', - renderError: false, - base64: false, -}); - -export const decorateData = (entity) => { - const { - id, - type, - url, - name, - icon, - tree_url, - path, - renderError, - content = '', - tempFile = false, - active = false, - opened = false, - changed = false, - parentTreeUrl = '', - level = 0, - base64 = false, - } = entity; - - return { - ...dataStructure(), - id, - key: `${name}-${type}-${id}`, - type, - name, - url, - tree_url, - path, - level, - tempFile, - icon: `fa-${icon}`, - opened, - active, - parentTreeUrl, - changed, - renderError, - content, - base64, - }; -}; - -export const findEntry = (state, type, name) => state.tree.find( - f => f.type === type && f.name === name, -); -export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path); - -export const setPageTitle = (title) => { - document.title = title; -}; - -export const pushState = (url) => { - history.pushState({ url }, '', url); -}; - -export const createTemp = ({ name, path, type, level, changed, content, base64 }) => { - const treePath = path ? `${path}/${name}` : name; - - return decorateData({ - id: new Date().getTime().toString(), - name, - type, - tempFile: true, - path: treePath, - icon: type === 'tree' ? 'folder' : 'file-text-o', - changed, - content, - parentTreeUrl: '', - level, - base64, - renderError: base64, - }); -}; - -export const createOrMergeEntry = ({ tree, entry, type, parentTreeUrl, level }) => { - const found = findEntry(tree, type, entry.name); - - if (found) { - return Object.assign({}, found, { - id: entry.id, - url: entry.url, - tempFile: false, - }); - } - - return decorateData({ - ...entry, - type, - parentTreeUrl, - level, - }); -}; diff --git a/app/assets/javascripts/vue_shared/components/project_avatar/image.vue b/app/assets/javascripts/vue_shared/components/project_avatar/image.vue new file mode 100644 index 00000000000..dce23bd65f6 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/project_avatar/image.vue @@ -0,0 +1,103 @@ + + + diff --git a/app/assets/stylesheets/framework/contextual-sidebar.scss b/app/assets/stylesheets/framework/contextual-sidebar.scss index 2e417315ed7..5da06b90113 100644 --- a/app/assets/stylesheets/framework/contextual-sidebar.scss +++ b/app/assets/stylesheets/framework/contextual-sidebar.scss @@ -23,7 +23,6 @@ .context-header { position: relative; margin-right: 2px; - width: $contextual-sidebar-width; a { transition: padding $sidebar-transition-duration; diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index b84d6c140be..1d6c7a5c472 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -219,6 +219,7 @@ $gl-input-padding: 10px; $gl-vert-padding: 6px; $gl-padding-top: 10px; $gl-sidebar-padding: 22px; +$gl-bar-padding: 3px; /* * Misc diff --git a/app/assets/stylesheets/pages/repo.scss b/app/assets/stylesheets/pages/repo.scss index 6eb92c7baee..da3c2d7fa5d 100644 --- a/app/assets/stylesheets/pages/repo.scss +++ b/app/assets/stylesheets/pages/repo.scss @@ -22,9 +22,10 @@ } } -.multi-file { +.ide-view { display: flex; - height: calc(100vh - 145px); + height: calc(100vh - #{$header-height}); + color: $almost-black; border-top: 1px solid $white-dark; border-bottom: 1px solid $white-dark; @@ -35,12 +36,47 @@ } } +.with-performance-bar .ide-view { + height: calc(100vh - #{$header-height}); +} + .ide-file-list { flex: 1; - overflow: scroll; .file { cursor: pointer; + + &.file-open { + background: $white-normal; + } + + .repo-file-name { + white-space: nowrap; + text-overflow: ellipsis; + } + + .unsaved-icon { + color: $indigo-700; + float: right; + font-size: smaller; + line-height: 20px; + } + + .repo-new-btn { + display: none; + margin-top: -4px; + margin-bottom: -4px; + } + + &:hover { + .repo-new-btn { + display: block; + } + + .unsaved-icon { + display: none; + } + } } a { @@ -55,10 +91,9 @@ .multi-file-table-name, .multi-file-table-col-commit-message { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + overflow: visible; max-width: 0; + padding: 6px 12px; } .multi-file-table-name { @@ -66,6 +101,7 @@ } .multi-file-table-col-commit-message { + white-space: nowrap; width: 50%; } @@ -79,7 +115,7 @@ .multi-file-tabs { display: flex; - overflow: scroll; + overflow-x: auto; background-color: $white-normal; box-shadow: inset 0 -1px $white-dark; @@ -128,9 +164,38 @@ height: 0; } +.blob-editor-container { + flex: 1; + height: 0; + display: flex; + flex-direction: column; + justify-content: center; + + .vertical-center { + min-height: auto; + } +} + +.multi-file-editor-holder { + height: 100%; +} + .multi-file-editor-btn-group { - padding: $grid-size; + padding: $gl-bar-padding $gl-padding; border-top: 1px solid $white-dark; + border-bottom: 1px solid $white-dark; + background: $white-light; +} + +.ide-status-bar { + padding: $gl-bar-padding $gl-padding; + background: $white-light; + display: flex; + justify-content: space-between; + + svg { + vertical-align: middle; + } } // Not great, but this is to deal with our current output @@ -138,10 +203,6 @@ height: 100%; overflow: scroll; - .blob-viewer { - height: 100%; - } - .file-content.code { display: flex; @@ -162,18 +223,101 @@ } } +.file-content.blob-no-preview { + a { + margin-left: auto; + margin-right: auto; + } +} + .multi-file-commit-panel { display: flex; flex-direction: column; height: 100%; width: 290px; - padding: $gl-padding; + padding: 0; background-color: $gray-light; border-left: 1px solid $white-dark; + .projects-sidebar { + display: flex; + flex-direction: column; + } + + .multi-file-commit-panel-inner { + display: flex; + flex: 1; + flex-direction: column; + } + + .multi-file-commit-panel-inner-scroll { + display: flex; + flex: 1; + flex-direction: column; + overflow: auto; + } + &.is-collapsed { width: 60px; - padding: 0; + + .multi-file-commit-list { + padding-top: $gl-padding; + overflow: hidden; + } + + .multi-file-context-bar-icon { + align-items: center; + + svg { + float: none; + margin: 0; + } + } + } + + .branch-container { + border-left: 4px solid $indigo-700; + margin-bottom: $gl-bar-padding; + } + + .branch-header { + background: $white-dark; + display: flex; + } + + .branch-header-title { + flex: 1; + padding: $grid-size $gl-padding; + color: $indigo-700; + font-weight: $gl-font-weight-bold; + + svg { + vertical-align: middle; + } + } + + .branch-header-btns { + padding: $gl-vert-padding $gl-padding; + } + + .left-collapse-btn { + display: none; + background: $gray-light; + text-align: left; + border-top: 1px solid $white-dark; + + svg { + vertical-align: middle; + } + } +} + +.multi-file-context-bar-icon { + padding: 10px; + + svg { + margin-right: 10px; + float: left; } } @@ -186,9 +330,9 @@ .multi-file-commit-panel-header { display: flex; align-items: center; - padding: 0 0 12px; margin-bottom: 12px; border-bottom: 1px solid $white-dark; + padding: $gl-btn-padding 0; &.is-collapsed { border-bottom: 1px solid $white-dark; @@ -197,23 +341,33 @@ margin-left: auto; margin-right: auto; } + + .multi-file-commit-panel-collapse-btn { + margin-right: auto; + margin-left: auto; + border-left: 0; + } } } -.multi-file-commit-panel-collapse-btn { - padding-top: 0; - padding-bottom: 0; - margin-left: auto; - font-size: 20px; +.multi-file-commit-panel-header-title { + display: flex; + flex: 1; + padding: $gl-btn-padding; - &.is-collapsed { - margin-right: auto; + svg { + margin-right: $gl-btn-padding; } } +.multi-file-commit-panel-collapse-btn { + border-left: 1px solid $white-dark; +} + .multi-file-commit-list { flex: 1; - overflow: scroll; + overflow: auto; + padding: $gl-padding; } .multi-file-commit-list-item { @@ -244,7 +398,7 @@ } .multi-file-commit-form { - padding-top: 12px; + padding: $gl-padding; border-top: 1px solid $white-dark; } @@ -295,3 +449,40 @@ } } } + +.ide-loading { + display: flex; + height: 100vh; + align-items: center; + justify-content: center; +} + +.ide-empty-state { + display: flex; + height: 100vh; + align-items: center; + justify-content: center; +} + +.repo-new-btn { + .dropdown-toggle svg { + margin-top: -2px; + margin-bottom: 2px; + } + + .dropdown-menu { + left: auto; + right: 0; + + label { + font-weight: $gl-font-weight-normal; + padding: 5px 8px; + margin-bottom: 0; + } + } +} + +.ide-flash-container.flash-container { + margin-top: $header-height; + margin-bottom: 0; +} diff --git a/app/controllers/ide_controller.rb b/app/controllers/ide_controller.rb new file mode 100644 index 00000000000..1ff25a45398 --- /dev/null +++ b/app/controllers/ide_controller.rb @@ -0,0 +1,6 @@ +class IdeController < ApplicationController + layout 'nav_only' + + def index + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4754a67450f..d13407a06c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -306,7 +306,7 @@ module ApplicationHelper cookies["sidebar_collapsed"] == "true" end - def show_new_repo? + def show_new_ide? cookies["new_repo"] == "true" && body_data_page != 'projects:show' end diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 556ed233ccf..3c2ee2cb5bc 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -8,7 +8,7 @@ module BlobHelper %w(credits changelog news copying copyright license authors) end - def edit_path(project = @project, ref = @ref, path = @path, options = {}) + def edit_blob_path(project = @project, ref = @ref, path = @path, options = {}) project_edit_blob_path(project, tree_join(ref, path), options[:link_opts]) @@ -26,10 +26,10 @@ module BlobHelper button_tag 'Edit', class: "#{common_classes} disabled has-tooltip", title: "You can only edit files when you are on a branch", data: { container: 'body' } # This condition applies to anonymous or users who can edit directly elsif !current_user || (current_user && can_modify_blob?(blob, project, ref)) - link_to 'Edit', edit_path(project, ref, path, options), class: "#{common_classes} btn-sm" + link_to 'Edit', edit_blob_path(project, ref, path, options), class: "#{common_classes} btn-sm" elsif current_user && can?(current_user, :fork_project, project) continue_params = { - to: edit_path(project, ref, path, options), + to: edit_blob_path(project, ref, path, options), notice: edit_in_new_fork_notice, notice_now: edit_in_new_fork_notice_now } @@ -41,6 +41,43 @@ module BlobHelper end end + def ide_edit_path(project = @project, ref = @ref, path = @path, options = {}) + "#{ide_path}/project#{edit_blob_path(project, ref, path, options)}" + end + + def ide_edit_text + "#{_('Multi Edit')} #{_('Beta')}".html_safe + end + + def ide_blob_link(project = @project, ref = @ref, path = @path, options = {}) + return unless show_new_ide? + + blob = options.delete(:blob) + blob ||= project.repository.blob_at(ref, path) rescue nil + + return unless blob && blob.readable_text? + + common_classes = "btn js-edit-ide #{options[:extra_class]}" + + if !on_top_of_branch?(project, ref) + button_tag ide_edit_text, class: "#{common_classes} disabled has-tooltip", title: _('You can only edit files when you are on a branch'), data: { container: 'body' } + # This condition applies to anonymous or users who can edit directly + elsif current_user && can_modify_blob?(blob, project, ref) + link_to ide_edit_text, ide_edit_path(project, ref, path, options), class: "#{common_classes} btn-sm" + elsif current_user && can?(current_user, :fork_project, project) + continue_params = { + to: ide_edit_path(project, ref, path, options), + notice: edit_in_new_fork_notice, + notice_now: edit_in_new_fork_notice_now + } + fork_path = project_forks_path(project, namespace_key: current_user.namespace.id, continue: continue_params) + + button_tag ide_edit_text, + class: common_classes, + data: { fork_path: fork_path } + end + end + def modify_file_link(project = @project, ref = @ref, path = @path, label:, action:, btn_class:, modal_type:) return unless current_user diff --git a/app/views/ide/index.html.haml b/app/views/ide/index.html.haml new file mode 100644 index 00000000000..8368e7a4563 --- /dev/null +++ b/app/views/ide/index.html.haml @@ -0,0 +1,12 @@ +- page_title 'IDE' + +- content_for :page_specific_javascripts do + = webpack_bundle_tag 'common_vue' + = webpack_bundle_tag 'ide' + +.ide-flash-container.flash-container + +#ide.ide-loading + .text-center + = icon('spinner spin 2x') + %h2.clgray= _('IDE Loading ...') diff --git a/app/views/layouts/nav_only.html.haml b/app/views/layouts/nav_only.html.haml new file mode 100644 index 00000000000..6fa4b39dc10 --- /dev/null +++ b/app/views/layouts/nav_only.html.haml @@ -0,0 +1,13 @@ +!!! 5 +%html{ lang: I18n.locale, class: page_class } + = render "layouts/head" + %body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page } } + = render 'peek/bar' + = render "layouts/header/default" + = render 'shared/outdated_browser' + .mobile-overlay + .alert-wrapper + = render "layouts/broadcast" + = yield :flash_message + = render "layouts/flash" + = yield diff --git a/app/views/projects/_files.html.haml b/app/views/projects/_files.html.haml index 3a7a99462a6..79530e78154 100644 --- a/app/views/projects/_files.html.haml +++ b/app/views/projects/_files.html.haml @@ -7,7 +7,7 @@ .nav-block = render 'projects/tree/tree_header', tree: @tree - - if !show_new_repo? && commit + - if commit = render 'shared/commit_well', commit: commit, ref: ref, project: project = render 'projects/tree/tree_content', tree: @tree, content_url: content_url diff --git a/app/views/projects/blob/_header.html.haml b/app/views/projects/blob/_header.html.haml index 281363d2e01..2a77dedd9a2 100644 --- a/app/views/projects/blob/_header.html.haml +++ b/app/views/projects/blob/_header.html.haml @@ -12,6 +12,7 @@ .btn-group{ role: "group" }< = edit_blob_link + = ide_blob_link - if current_user = replace_blob_link = delete_blob_link diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml index c4712bf3736..4d358052d43 100644 --- a/app/views/projects/blob/show.html.haml +++ b/app/views/projects/blob/show.html.haml @@ -6,21 +6,14 @@ - content_for :page_specific_javascripts do = webpack_bundle_tag 'blob' - - if show_new_repo? - = webpack_bundle_tag 'common_vue' - = webpack_bundle_tag 'repo' - = render 'projects/last_push' %div{ class: container_class } - - if show_new_repo? - = render 'projects/files', commit: @last_commit, project: @project, ref: @ref, content_url: project_blob_path(@project, @id) - - else - #tree-holder.tree-holder - = render 'blob', blob: @blob + #tree-holder.tree-holder + = render 'blob', blob: @blob - if can_modify_blob?(@blob) = render 'projects/blob/remove' - - title = "Replace #{@blob.name}" - = render 'projects/blob/upload', title: title, placeholder: title, button_title: 'Replace file', form_path: project_update_blob_path(@project, @id), method: :put + - title = "Replace #{@blob.name}" + = render 'projects/blob/upload', title: title, placeholder: title, button_title: 'Replace file', form_path: project_update_blob_path(@project, @id), method: :put diff --git a/app/views/projects/tree/_old_tree_content.html.haml b/app/views/projects/tree/_old_tree_content.html.haml deleted file mode 100644 index 6ea78851b8d..00000000000 --- a/app/views/projects/tree/_old_tree_content.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -.tree-content-holder.js-tree-content{ 'data-logs-path': @logs_path } - .table-holder - %table.table#tree-slider{ class: "table_#{@hex_path} tree-table" } - %thead - %tr - %th= s_('ProjectFileTree|Name') - %th.hidden-xs - .pull-left= _('Last commit') - %th.text-right= _('Last update') - - if @path.present? - %tr.tree-item - %td.tree-item-file-name - = link_to "..", project_tree_path(@project, up_dir_path), class: 'prepend-left-10' - %td - %td.hidden-xs - - = render_tree(tree) - - - if tree.readme - = render "projects/tree/readme", readme: tree.readme - -- if can_edit_tree? - = render 'projects/blob/upload', title: _('Upload New File'), placeholder: _('Upload New File'), button_title: _('Upload file'), form_path: project_create_blob_path(@project, @id), method: :post - = render 'projects/blob/new_dir' diff --git a/app/views/projects/tree/_old_tree_header.html.haml b/app/views/projects/tree/_old_tree_header.html.haml deleted file mode 100644 index 7f636b7e0e8..00000000000 --- a/app/views/projects/tree/_old_tree_header.html.haml +++ /dev/null @@ -1,64 +0,0 @@ -- if on_top_of_branch? - - addtotree_toggle_attributes = { href: '#', 'data-toggle': 'dropdown', 'data-target': '.add-to-tree-dropdown' } -- else - - addtotree_toggle_attributes = { title: _("You can only add files when you are on a branch"), data: { container: 'body' }, class: 'disabled has-tooltip' } - -%ul.breadcrumb.repo-breadcrumb - %li - = link_to project_tree_path(@project, @ref) do - = @project.path - - path_breadcrumbs do |title, path| - %li - = link_to truncate(title, length: 40), project_tree_path(@project, tree_join(@ref, path)) - - - if current_user - %li - %a.btn.add-to-tree{ addtotree_toggle_attributes } - = sprite_icon('plus', size: 16, css_class: 'pull-left') - = sprite_icon('arrow-down', size: 16, css_class: 'pull-left') - - if on_top_of_branch? - .add-to-tree-dropdown - %ul.dropdown-menu - - if can_edit_tree? - %li - = link_to project_new_blob_path(@project, @id) do - #{ _('New file') } - %li - = link_to '#modal-upload-blob', { 'data-target' => '#modal-upload-blob', 'data-toggle' => 'modal' } do - #{ _('Upload file') } - %li - = link_to '#modal-create-new-dir', { 'data-target' => '#modal-create-new-dir', 'data-toggle' => 'modal' } do - #{ _('New directory') } - - elsif can?(current_user, :fork_project, @project) - %li - - continue_params = { to: project_new_blob_path(@project, @id), - notice: edit_in_new_fork_notice, - notice_now: edit_in_new_fork_notice_now } - - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, - continue: continue_params) - = link_to fork_path, method: :post do - #{ _('New file') } - %li - - continue_params = { to: request.fullpath, - notice: edit_in_new_fork_notice + " Try to upload a file again.", - notice_now: edit_in_new_fork_notice_now } - - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, - continue: continue_params) - = link_to fork_path, method: :post do - #{ _('Upload file') } - %li - - continue_params = { to: request.fullpath, - notice: edit_in_new_fork_notice + " Try to create a new directory again.", - notice_now: edit_in_new_fork_notice_now } - - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, - continue: continue_params) - = link_to fork_path, method: :post do - #{ _('New directory') } - - %li.divider - %li - = link_to new_project_branch_path(@project) do - #{ _('New branch') } - %li - = link_to new_project_tag_path(@project) do - #{ _('New tag') } diff --git a/app/views/projects/tree/_tree_content.html.haml b/app/views/projects/tree/_tree_content.html.haml index a4bdd67209d..6ea78851b8d 100644 --- a/app/views/projects/tree/_tree_content.html.haml +++ b/app/views/projects/tree/_tree_content.html.haml @@ -1,5 +1,24 @@ -- content_url = local_assigns.fetch(:content_url, nil) -- if show_new_repo? - = render 'shared/repo/repo', project: @project, content_url: content_url -- else - = render 'projects/tree/old_tree_content', tree: tree +.tree-content-holder.js-tree-content{ 'data-logs-path': @logs_path } + .table-holder + %table.table#tree-slider{ class: "table_#{@hex_path} tree-table" } + %thead + %tr + %th= s_('ProjectFileTree|Name') + %th.hidden-xs + .pull-left= _('Last commit') + %th.text-right= _('Last update') + - if @path.present? + %tr.tree-item + %td.tree-item-file-name + = link_to "..", project_tree_path(@project, up_dir_path), class: 'prepend-left-10' + %td + %td.hidden-xs + + = render_tree(tree) + + - if tree.readme + = render "projects/tree/readme", readme: tree.readme + +- if can_edit_tree? + = render 'projects/blob/upload', title: _('Upload New File'), placeholder: _('Upload New File'), button_title: _('Upload file'), form_path: project_create_blob_path(@project, @id), method: :post + = render 'projects/blob/new_dir' diff --git a/app/views/projects/tree/_tree_header.html.haml b/app/views/projects/tree/_tree_header.html.haml index c02f7ee37ed..d1ecef39475 100644 --- a/app/views/projects/tree/_tree_header.html.haml +++ b/app/views/projects/tree/_tree_header.html.haml @@ -2,16 +2,78 @@ .tree-ref-holder = render 'shared/ref_switcher', destination: 'tree', path: @path, show_create: true - - if show_new_repo? && can_push_branch?(@project, @ref) - .js-new-dropdown - - else - = render 'projects/tree/old_tree_header' + - if on_top_of_branch? + - addtotree_toggle_attributes = { href: '#', 'data-toggle': 'dropdown', 'data-target': '.add-to-tree-dropdown' } + - else + - addtotree_toggle_attributes = { title: _("You can only add files when you are on a branch"), data: { container: 'body' }, class: 'disabled has-tooltip' } + + %ul.breadcrumb.repo-breadcrumb + %li + = link_to project_tree_path(@project, @ref) do + = @project.path + - path_breadcrumbs do |title, path| + %li + = link_to truncate(title, length: 40), project_tree_path(@project, tree_join(@ref, path)) + + - if current_user + %li + %a.btn.add-to-tree{ addtotree_toggle_attributes } + = sprite_icon('plus', size: 16, css_class: 'pull-left') + = sprite_icon('arrow-down', size: 16, css_class: 'pull-left') + - if on_top_of_branch? + .add-to-tree-dropdown + %ul.dropdown-menu + - if can_edit_tree? + %li + = link_to project_new_blob_path(@project, @id) do + #{ _('New file') } + %li + = link_to '#modal-upload-blob', { 'data-target' => '#modal-upload-blob', 'data-toggle' => 'modal' } do + #{ _('Upload file') } + %li + = link_to '#modal-create-new-dir', { 'data-target' => '#modal-create-new-dir', 'data-toggle' => 'modal' } do + #{ _('New directory') } + - elsif can?(current_user, :fork_project, @project) + %li + - continue_params = { to: project_new_blob_path(@project, @id), + notice: edit_in_new_fork_notice, + notice_now: edit_in_new_fork_notice_now } + - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, + continue: continue_params) + = link_to fork_path, method: :post do + #{ _('New file') } + %li + - continue_params = { to: request.fullpath, + notice: edit_in_new_fork_notice + " Try to upload a file again.", + notice_now: edit_in_new_fork_notice_now } + - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, + continue: continue_params) + = link_to fork_path, method: :post do + #{ _('Upload file') } + %li + - continue_params = { to: request.fullpath, + notice: edit_in_new_fork_notice + " Try to create a new directory again.", + notice_now: edit_in_new_fork_notice_now } + - fork_path = project_forks_path(@project, namespace_key: current_user.namespace.id, + continue: continue_params) + = link_to fork_path, method: :post do + #{ _('New directory') } + + %li.divider + %li + = link_to new_project_branch_path(@project) do + #{ _('New branch') } + %li + = link_to new_project_tag_path(@project) do + #{ _('New tag') } .tree-controls - - if show_new_repo? - .editable-mode - - else - = link_to s_('Commits|History'), project_commits_path(@project, @id), class: 'btn' + - if show_new_ide? + = succeed " " do + = link_to ide_edit_path(@project, @id), class: 'btn btn-default' do + = ide_edit_text + + = link_to s_('Commits|History'), project_commits_path(@project, @id), class: 'btn' = render 'projects/find_file_link' diff --git a/app/views/projects/tree/show.html.haml b/app/views/projects/tree/show.html.haml index 64cc70053ef..3b4057e56d0 100644 --- a/app/views/projects/tree/show.html.haml +++ b/app/views/projects/tree/show.html.haml @@ -6,11 +6,6 @@ = content_for :meta_tags do = auto_discovery_link_tag(:atom, project_commits_url(@project, @ref, rss_url_options), title: "#{@project.name}:#{@ref} commits") -- if show_new_repo? - - content_for :page_specific_javascripts do - = webpack_bundle_tag 'common_vue' - = webpack_bundle_tag 'repo' - -%div{ class: [(container_class unless show_new_repo?), ("limit-container-width" unless fluid_layout)] } +%div{ class: [(container_class), ("limit-container-width" unless fluid_layout)] } = render 'projects/last_push' = render 'projects/files', commit: @last_commit, project: @project, ref: @ref, content_url: project_tree_path(@project, @id) diff --git a/app/views/shared/_ref_switcher.html.haml b/app/views/shared/_ref_switcher.html.haml index f4a4bfaec54..479bd2cdb38 100644 --- a/app/views/shared/_ref_switcher.html.haml +++ b/app/views/shared/_ref_switcher.html.haml @@ -1,6 +1,6 @@ - show_create = local_assigns.fetch(:show_create, false) -- show_new_branch_form = show_new_repo? && show_create && can?(current_user, :push_code, @project) +- show_new_branch_form = show_new_ide? && show_create && can?(current_user, :push_code, @project) - dropdown_toggle_text = @ref || @project.default_branch = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do = hidden_field_tag :destination, destination diff --git a/app/views/shared/repo/_repo.html.haml b/app/views/shared/repo/_repo.html.haml deleted file mode 100644 index 87e8c416194..00000000000 --- a/app/views/shared/repo/_repo.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -- @no_container = true; -#repo{ data: { root: @path.empty?.to_s, - root_url: project_tree_path(project), - url: content_url, - current_branch: @ref, - ref: @commit.id, - project_name: project.name, - project_url: project_path(project), - project_id: project.id, - new_merge_request_url: namespace_project_new_merge_request_path(project.namespace, project, merge_request: { source_branch: '' }), - can_commit: (!!can_push_branch?(project, @ref)).to_s, - on_top_of_branch: (!!on_top_of_branch?(project, @ref)).to_s, - current_path: @path } } diff --git a/changelogs/unreleased/40040-decouple-multi-file-editor-from-file-list.yml b/changelogs/unreleased/40040-decouple-multi-file-editor-from-file-list.yml new file mode 100644 index 00000000000..e2fade2bfd9 --- /dev/null +++ b/changelogs/unreleased/40040-decouple-multi-file-editor-from-file-list.yml @@ -0,0 +1,5 @@ +--- +title: Adds the multi file editor as a new beta feature +merge_request: 15430 +author: +type: feature diff --git a/config/routes.rb b/config/routes.rb index 016140e0ede..f162043dd5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,8 @@ Rails.application.routes.draw do get 'liveness' => 'health#liveness' get 'readiness' => 'health#readiness' post 'storage_check' => 'health#storage_check' + get 'ide' => 'ide#index' + get 'ide/*vueroute' => 'ide#index', format: false resources :metrics, only: [:index] mount Peek::Railtie => '/peek' diff --git a/config/webpack.config.js b/config/webpack.config.js index d8797bbf4d3..6daef243991 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -70,7 +70,7 @@ var config = { protected_branches: './protected_branches', protected_tags: './protected_tags', registry_list: './registry/index.js', - repo: './repo/index.js', + ide: './ide/index.js', sidebar: './sidebar/sidebar_bundle.js', schedule_form: './pipeline_schedules/pipeline_schedule_form_bundle.js', schedules_index: './pipeline_schedules/pipeline_schedules_index_bundle.js', @@ -204,7 +204,7 @@ var config = { 'pipelines', 'pipelines_details', 'registry_list', - 'repo', + 'ide', 'schedule_form', 'schedules_index', 'sidebar', diff --git a/package.json b/package.json index a5bf2309a0f..aa4e4e79f49 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "vue": "^2.5.8", "vue-loader": "^13.5.0", "vue-resource": "^1.3.4", + "vue-router": "^3.0.1", "vue-template-compiler": "^2.5.8", "vuex": "^3.0.1", "webpack": "^3.5.5", diff --git a/spec/features/projects/ref_switcher_spec.rb b/spec/features/projects/ref_switcher_spec.rb deleted file mode 100644 index 33ccbc1a29f..00000000000 --- a/spec/features/projects/ref_switcher_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'rails_helper' - -feature 'Ref switcher', :js do - let(:user) { create(:user) } - let(:project) { create(:project, :public, :repository) } - - before do - project.team << [user, :master] - set_cookie('new_repo', 'true') - sign_in(user) - visit project_tree_path(project, 'master') - end - - it 'allow user to change ref by enter key' do - click_button 'master' - wait_for_requests - - page.within '.project-refs-form' do - input = find('input[type="search"]') - input.set 'binary' - wait_for_requests - - expect(find('.dropdown-content ul')).to have_selector('li', count: 7) - - page.within '.dropdown-content ul' do - input.native.send_keys :enter - end - end - - expect(page).to have_title 'add-pdf-text-binary' - end - - it "user selects ref with special characters" do - click_button 'master' - wait_for_requests - - page.within '.project-refs-form' do - page.fill_in 'Search branches and tags', with: "'test'" - click_link "'test'" - end - - expect(page).to have_title "'test'" - end - - context "create branch" do - let(:input) { find('.js-new-branch-name') } - - before do - click_button 'master' - wait_for_requests - - page.within '.project-refs-form' do - find(".dropdown-footer-list a").click - end - end - - it "shows error message for the invalid branch name" do - input.set 'foo bar' - click_button('Create') - wait_for_requests - expect(page).to have_content 'Branch name is invalid' - end - - it "should create new branch properly" do - input.set 'new-branch-name' - click_button('Create') - wait_for_requests - expect(find('.js-project-refs-dropdown')).to have_content 'new-branch-name' - end - - it "should create new branch by Enter key" do - input.set 'new-branch-name-2' - input.native.send_keys :enter - wait_for_requests - expect(find('.js-project-refs-dropdown')).to have_content 'new-branch-name-2' - end - end -end diff --git a/spec/features/projects/tree/create_directory_spec.rb b/spec/features/projects/tree/create_directory_spec.rb index 8f06328962e..3f6d16c8acf 100644 --- a/spec/features/projects/tree/create_directory_spec.rb +++ b/spec/features/projects/tree/create_directory_spec.rb @@ -13,6 +13,14 @@ feature 'Multi-file editor new directory', :js do visit project_tree_path(project, :master) wait_for_requests + + click_link('Multi Edit') + + wait_for_requests + end + + after do + set_cookie('new_repo', 'false') end it 'creates directory in current directory' do @@ -21,17 +29,29 @@ feature 'Multi-file editor new directory', :js do click_link('New directory') page.within('.modal') do - find('.form-control').set('foldername') + find('.form-control').set('folder name') click_button('Create directory') end + find('.add-to-tree').click + + click_link('New file') + + page.within('.modal-dialog') do + find('.form-control').set('file name') + + click_button('Create file') + end + + wait_for_requests + find('.multi-file-commit-panel-collapse-btn').click - fill_in('commit-message', with: 'commit message') + fill_in('commit-message', with: 'commit message ide') click_button('Commit') - expect(page).to have_selector('td', text: 'commit message') + expect(page).to have_content('folder name') end end diff --git a/spec/features/projects/tree/create_file_spec.rb b/spec/features/projects/tree/create_file_spec.rb index bdebc12ef47..ba71eef07f4 100644 --- a/spec/features/projects/tree/create_file_spec.rb +++ b/spec/features/projects/tree/create_file_spec.rb @@ -13,6 +13,14 @@ feature 'Multi-file editor new file', :js do visit project_tree_path(project, :master) wait_for_requests + + click_link('Multi Edit') + + wait_for_requests + end + + after do + set_cookie('new_repo', 'false') end it 'creates file in current directory' do @@ -21,17 +29,19 @@ feature 'Multi-file editor new file', :js do click_link('New file') page.within('.modal') do - find('.form-control').set('filename') + find('.form-control').set('file name') click_button('Create file') end + wait_for_requests + find('.multi-file-commit-panel-collapse-btn').click - fill_in('commit-message', with: 'commit message') + fill_in('commit-message', with: 'commit message ide') click_button('Commit') - expect(page).to have_selector('td', text: 'commit message') + expect(page).to have_content('file name') end end diff --git a/spec/features/projects/tree/upload_file_spec.rb b/spec/features/projects/tree/upload_file_spec.rb index d4e57d1ecfa..9fbb1dbd0e8 100644 --- a/spec/features/projects/tree/upload_file_spec.rb +++ b/spec/features/projects/tree/upload_file_spec.rb @@ -15,6 +15,14 @@ feature 'Multi-file editor upload file', :js do visit project_tree_path(project, :master) wait_for_requests + + click_link('Multi Edit') + + wait_for_requests + end + + after do + set_cookie('new_repo', 'false') end it 'uploads text file' do @@ -41,6 +49,5 @@ feature 'Multi-file editor upload file', :js do expect(page).to have_selector('.multi-file-tab', text: 'dk.png') expect(page).not_to have_selector('.monaco-editor') - expect(page).to have_content('The source could not be displayed for this temporary file.') end end diff --git a/spec/javascripts/repo/components/commit_sidebar/list_collapsed_spec.js b/spec/javascripts/repo/components/commit_sidebar/list_collapsed_spec.js index f750061a6a1..c4d3866c922 100644 --- a/spec/javascripts/repo/components/commit_sidebar/list_collapsed_spec.js +++ b/spec/javascripts/repo/components/commit_sidebar/list_collapsed_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import listCollapsed from '~/repo/components/commit_sidebar/list_collapsed.vue'; +import store from '~/ide/stores'; +import listCollapsed from '~/ide/components/commit_sidebar/list_collapsed.vue'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { file } from '../../helpers'; diff --git a/spec/javascripts/repo/components/commit_sidebar/list_item_spec.js b/spec/javascripts/repo/components/commit_sidebar/list_item_spec.js index 18c9b46fcd9..fc7c9ae9dd7 100644 --- a/spec/javascripts/repo/components/commit_sidebar/list_item_spec.js +++ b/spec/javascripts/repo/components/commit_sidebar/list_item_spec.js @@ -1,5 +1,5 @@ import Vue from 'vue'; -import listItem from '~/repo/components/commit_sidebar/list_item.vue'; +import listItem from '~/ide/components/commit_sidebar/list_item.vue'; import mountComponent from '../../../helpers/vue_mount_component_helper'; import { file } from '../../helpers'; diff --git a/spec/javascripts/repo/components/commit_sidebar/list_spec.js b/spec/javascripts/repo/components/commit_sidebar/list_spec.js index df7e3c5de21..cb5240ad118 100644 --- a/spec/javascripts/repo/components/commit_sidebar/list_spec.js +++ b/spec/javascripts/repo/components/commit_sidebar/list_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import commitSidebarList from '~/repo/components/commit_sidebar/list.vue'; +import store from '~/ide/stores'; +import commitSidebarList from '~/ide/components/commit_sidebar/list.vue'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { file } from '../../helpers'; @@ -13,8 +13,11 @@ describe('Multi-file editor commit sidebar list', () => { vm = createComponentWithStore(Component, store, { title: 'Staged', fileList: [], - collapsed: false, - }).$mount(); + }); + + vm.$store.state.rightPanelCollapsed = false; + + vm.$mount(); }); afterEach(() => { @@ -43,30 +46,14 @@ describe('Multi-file editor commit sidebar list', () => { describe('collapsed', () => { beforeEach((done) => { - vm.collapsed = true; + vm.$store.state.rightPanelCollapsed = true; Vue.nextTick(done); }); - it('adds collapsed class', () => { - expect(vm.$el.querySelector('.is-collapsed')).not.toBeNull(); - }); - it('hides list', () => { expect(vm.$el.querySelector('.list-unstyled')).toBeNull(); expect(vm.$el.querySelector('.help-block')).toBeNull(); }); - - it('hides collapse button', () => { - expect(vm.$el.querySelector('.multi-file-commit-panel-collapse-btn')).toBeNull(); - }); - }); - - it('clicking toggle collapse button emits toggle event', () => { - spyOn(vm, '$emit'); - - vm.$el.querySelector('.multi-file-commit-panel-collapse-btn').click(); - - expect(vm.$emit).toHaveBeenCalledWith('toggleCollapsed'); }); }); diff --git a/spec/javascripts/repo/components/ide_context_bar_spec.js b/spec/javascripts/repo/components/ide_context_bar_spec.js new file mode 100644 index 00000000000..3f8f37d2343 --- /dev/null +++ b/spec/javascripts/repo/components/ide_context_bar_spec.js @@ -0,0 +1,49 @@ +import Vue from 'vue'; +import store from '~/ide/stores'; +import ideContextBar from '~/ide/components/ide_context_bar.vue'; +import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; + +describe('Multi-file editor right context bar', () => { + let vm; + + beforeEach(() => { + const Component = Vue.extend(ideContextBar); + + vm = createComponentWithStore(Component, store); + + vm.$store.state.rightPanelCollapsed = false; + + vm.$mount(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + describe('collapsed', () => { + beforeEach((done) => { + vm.$store.state.rightPanelCollapsed = true; + + Vue.nextTick(done); + }); + + it('adds collapsed class', () => { + expect(vm.$el.querySelector('.is-collapsed')).not.toBeNull(); + }); + + it('shows correct icon', () => { + expect(vm.currentIcon).toBe('angle-double-left'); + }); + }); + + it('clicking toggle collapse button collapses the bar', () => { + spyOn(vm, 'setPanelCollapsedStatus').and.returnValue(Promise.resolve()); + + vm.$el.querySelector('.multi-file-commit-panel-collapse-btn').click(); + + expect(vm.setPanelCollapsedStatus).toHaveBeenCalledWith({ + side: 'right', + collapsed: true, + }); + }); +}); diff --git a/spec/javascripts/repo/components/ide_repo_tree_spec.js b/spec/javascripts/repo/components/ide_repo_tree_spec.js new file mode 100644 index 00000000000..b6f70f585cd --- /dev/null +++ b/spec/javascripts/repo/components/ide_repo_tree_spec.js @@ -0,0 +1,63 @@ +import Vue from 'vue'; +import store from '~/ide/stores'; +import ideRepoTree from '~/ide/components/ide_repo_tree.vue'; +import { file, resetStore } from '../helpers'; + +describe('IdeRepoTree', () => { + let vm; + + beforeEach(() => { + const IdeRepoTree = Vue.extend(ideRepoTree); + + vm = new IdeRepoTree({ + store, + propsData: { + treeId: 'abcproject/mybranch', + }, + }); + + vm.$store.state.currentBranch = 'master'; + vm.$store.state.isRoot = true; + vm.$store.state.trees['abcproject/mybranch'] = { + tree: [file()], + }; + + vm.$mount(); + }); + + afterEach(() => { + vm.$destroy(); + + resetStore(vm.$store); + }); + + it('renders a sidebar', () => { + const tbody = vm.$el.querySelector('tbody'); + + expect(vm.$el.classList.contains('sidebar-mini')).toBeFalsy(); + expect(tbody.querySelector('.repo-file-options')).toBeFalsy(); + expect(tbody.querySelector('.prev-directory')).toBeFalsy(); + expect(tbody.querySelector('.loading-file')).toBeFalsy(); + expect(tbody.querySelector('.file')).toBeTruthy(); + }); + + it('renders 5 loading files if tree is loading', (done) => { + vm.$store.state.loading = true; + + Vue.nextTick(() => { + expect(vm.$el.querySelectorAll('tbody .loading-file').length).toEqual(5); + + done(); + }); + }); + + it('renders a prev directory if is not root', (done) => { + vm.$store.state.isRoot = false; + + Vue.nextTick(() => { + expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy(); + + done(); + }); + }); +}); diff --git a/spec/javascripts/repo/components/ide_side_bar_spec.js b/spec/javascripts/repo/components/ide_side_bar_spec.js new file mode 100644 index 00000000000..30e45169205 --- /dev/null +++ b/spec/javascripts/repo/components/ide_side_bar_spec.js @@ -0,0 +1,43 @@ +import Vue from 'vue'; +import store from '~/ide/stores'; +import ideSidebar from '~/ide/components/ide_side_bar.vue'; +import { resetStore } from '../helpers'; +import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; + +describe('IdeSidebar', () => { + let vm; + + beforeEach(() => { + const Component = Vue.extend(ideSidebar); + + vm = createComponentWithStore(Component, store).$mount(); + + vm.$store.state.leftPanelCollapsed = false; + }); + + afterEach(() => { + vm.$destroy(); + + resetStore(vm.$store); + }); + + it('renders a sidebar', () => { + expect(vm.$el.querySelector('.multi-file-commit-panel-inner')).not.toBeNull(); + }); + + describe('collapsed', () => { + beforeEach((done) => { + vm.$store.state.leftPanelCollapsed = true; + + Vue.nextTick(done); + }); + + it('adds collapsed class', () => { + expect(vm.$el.classList).toContain('is-collapsed'); + }); + + it('shows correct icon', () => { + expect(vm.currentIcon).toBe('angle-double-right'); + }); + }); +}); diff --git a/spec/javascripts/repo/components/ide_spec.js b/spec/javascripts/repo/components/ide_spec.js new file mode 100644 index 00000000000..20b8dc25dcb --- /dev/null +++ b/spec/javascripts/repo/components/ide_spec.js @@ -0,0 +1,37 @@ +import Vue from 'vue'; +import store from '~/ide/stores'; +import ide from '~/ide/components/ide.vue'; +import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; +import { file, resetStore } from '../helpers'; + +describe('ide component', () => { + let vm; + + beforeEach(() => { + const Component = Vue.extend(ide); + + vm = createComponentWithStore(Component, store).$mount(); + }); + + afterEach(() => { + vm.$destroy(); + + resetStore(vm.$store); + }); + + it('does not render panel right when no files open', () => { + expect(vm.$el.querySelector('.panel-right')).toBeNull(); + }); + + it('renders panel right when files are open', (done) => { + vm.$store.state.trees['abcproject/mybranch'] = { + tree: [file()], + }; + + Vue.nextTick(() => { + expect(vm.$el.querySelector('.panel-right')).toBeNull(); + + done(); + }); + }); +}); diff --git a/spec/javascripts/repo/components/new_branch_form_spec.js b/spec/javascripts/repo/components/new_branch_form_spec.js index 9a705a1f0ed..cd1d073ec18 100644 --- a/spec/javascripts/repo/components/new_branch_form_spec.js +++ b/spec/javascripts/repo/components/new_branch_form_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import newBranchForm from '~/repo/components/new_branch_form.vue'; +import store from '~/ide/stores'; +import newBranchForm from '~/ide/components/new_branch_form.vue'; import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; import { resetStore } from '../helpers'; diff --git a/spec/javascripts/repo/components/new_dropdown/index_spec.js b/spec/javascripts/repo/components/new_dropdown/index_spec.js index 93b10fc1fee..b001c1655b4 100644 --- a/spec/javascripts/repo/components/new_dropdown/index_spec.js +++ b/spec/javascripts/repo/components/new_dropdown/index_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import newDropdown from '~/repo/components/new_dropdown/index.vue'; +import store from '~/ide/stores'; +import newDropdown from '~/ide/components/new_dropdown/index.vue'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { resetStore } from '../../helpers'; @@ -10,8 +10,12 @@ describe('new dropdown component', () => { beforeEach(() => { const component = Vue.extend(newDropdown); - vm = createComponentWithStore(component, store); + vm = createComponentWithStore(component, store, { + branch: 'master', + path: '', + }); + vm.$store.state.currentProjectId = 'abcproject'; vm.$store.state.path = ''; vm.$mount(); @@ -23,9 +27,10 @@ describe('new dropdown component', () => { resetStore(vm.$store); }); - it('renders new file and new directory links', () => { + it('renders new file, upload and new directory links', () => { expect(vm.$el.querySelectorAll('a')[0].textContent.trim()).toBe('New file'); - expect(vm.$el.querySelectorAll('a')[1].textContent.trim()).toBe('New directory'); + expect(vm.$el.querySelectorAll('a')[1].textContent.trim()).toBe('Upload file'); + expect(vm.$el.querySelectorAll('a')[2].textContent.trim()).toBe('New directory'); }); describe('createNewItem', () => { @@ -36,7 +41,7 @@ describe('new dropdown component', () => { }); it('sets modalType to tree when new directory is clicked', () => { - vm.$el.querySelectorAll('a')[1].click(); + vm.$el.querySelectorAll('a')[2].click(); expect(vm.modalType).toBe('tree'); }); diff --git a/spec/javascripts/repo/components/new_dropdown/modal_spec.js b/spec/javascripts/repo/components/new_dropdown/modal_spec.js index 1ff7590ec79..233cca06ed0 100644 --- a/spec/javascripts/repo/components/new_dropdown/modal_spec.js +++ b/spec/javascripts/repo/components/new_dropdown/modal_spec.js @@ -1,12 +1,42 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import modal from '~/repo/components/new_dropdown/modal.vue'; +import store from '~/ide/stores'; +import service from '~/ide/services'; +import modal from '~/ide/components/new_dropdown/modal.vue'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { file, resetStore } from '../../helpers'; describe('new file modal component', () => { const Component = Vue.extend(modal); let vm; + let projectTree; + + beforeEach(() => { + spyOn(service, 'getProjectData').and.returnValue(Promise.resolve({ + data: { + id: '123', + }, + })); + + spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({ + commit: { + id: '123branch', + }, + })); + + spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({ + headers: { + 'page-title': 'test', + }, + json: () => Promise.resolve({ + last_commit_path: 'last_commit_path', + parent_tree_url: 'parent_tree_url', + path: '/', + trees: [{ name: 'tree' }], + blobs: [{ name: 'blob' }], + submodules: [{ name: 'submodule' }], + }), + })); + }); afterEach(() => { vm.$destroy(); @@ -17,12 +47,26 @@ describe('new file modal component', () => { ['tree', 'blob'].forEach((type) => { describe(type, () => { beforeEach(() => { + store.state.projects.abcproject = { + web_url: '', + }; + store.state.trees = []; + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + projectTree = store.state.trees['abcproject/mybranch']; + store.state.currentProjectId = 'abcproject'; + vm = createComponentWithStore(Component, store, { type, + branchId: 'master', path: '', - }).$mount(); + parent: projectTree, + }); vm.entryName = 'testing'; + + vm.$mount(); }); it(`sets modal title as ${type}`, () => { @@ -50,6 +94,9 @@ describe('new file modal component', () => { vm.createEntryInStore(); expect(vm.createTempEntry).toHaveBeenCalledWith({ + projectId: 'abcproject', + branchId: 'master', + parent: projectTree, name: 'testing', type, }); @@ -76,31 +123,18 @@ describe('new file modal component', () => { }); it('opens newly created file', (done) => { - vm.createEntryInStore(); - - setTimeout(() => { - expect(vm.$store.state.openFiles.length).toBe(1); - expect(vm.$store.state.openFiles[0].name).toBe(type === 'blob' ? 'testing' : '.gitkeep'); - - done(); - }); - }); - - it(`creates ${type} in the current stores path`, (done) => { - vm.$store.state.path = 'app'; - - vm.createEntryInStore(); - - setTimeout(() => { - expect(vm.$store.state.tree[0].path).toBe('app/testing'); - expect(vm.$store.state.tree[0].name).toBe('testing'); + if (type === 'blob') { + vm.createEntryInStore(); - if (type === 'tree') { - expect(vm.$store.state.tree[0].tree.length).toBe(1); - } + setTimeout(() => { + expect(vm.$store.state.openFiles.length).toBe(1); + expect(vm.$store.state.openFiles[0].name).toBe(type === 'blob' ? 'testing' : '.gitkeep'); + done(); + }); + } else { done(); - }); + } }); if (type === 'blob') { @@ -108,25 +142,27 @@ describe('new file modal component', () => { vm.createEntryInStore(); setTimeout(() => { - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('testing'); - expect(vm.$store.state.tree[0].type).toBe('blob'); - expect(vm.$store.state.tree[0].tempFile).toBeTruthy(); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('testing'); + expect(baseTree[0].type).toBe('blob'); + expect(baseTree[0].tempFile).toBeTruthy(); done(); }); }); it('does not create temp file when file already exists', (done) => { - vm.$store.state.tree.push(file('testing', '1', type)); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + baseTree.push(file('testing', '1', type)); vm.createEntryInStore(); setTimeout(() => { - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('testing'); - expect(vm.$store.state.tree[0].type).toBe('blob'); - expect(vm.$store.state.tree[0].tempFile).toBeFalsy(); + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('testing'); + expect(baseTree[0].type).toBe('blob'); + expect(baseTree[0].tempFile).toBeFalsy(); done(); }); @@ -135,48 +171,47 @@ describe('new file modal component', () => { it('creates new tree', () => { vm.createEntryInStore(); - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('testing'); - expect(vm.$store.state.tree[0].type).toBe('tree'); - expect(vm.$store.state.tree[0].tempFile).toBeTruthy(); - expect(vm.$store.state.tree[0].tree.length).toBe(1); - expect(vm.$store.state.tree[0].tree[0].name).toBe('.gitkeep'); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('testing'); + expect(baseTree[0].type).toBe('tree'); + expect(baseTree[0].tempFile).toBeTruthy(); }); it('creates multiple trees when entryName has slashes', () => { vm.entryName = 'app/test'; vm.createEntryInStore(); - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('app'); - expect(vm.$store.state.tree[0].tree[0].name).toBe('test'); - expect(vm.$store.state.tree[0].tree[0].tree[0].name).toBe('.gitkeep'); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('app'); }); it('creates tree in existing tree', () => { - vm.$store.state.tree.push(file('app', '1', 'tree')); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + baseTree.push(file('app', '1', 'tree')); vm.entryName = 'app/test'; vm.createEntryInStore(); - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('app'); - expect(vm.$store.state.tree[0].tempFile).toBeFalsy(); - expect(vm.$store.state.tree[0].tree[0].tempFile).toBeTruthy(); - expect(vm.$store.state.tree[0].tree[0].name).toBe('test'); - expect(vm.$store.state.tree[0].tree[0].tree[0].name).toBe('.gitkeep'); + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('app'); + expect(baseTree[0].tempFile).toBeFalsy(); + expect(baseTree[0].tree[0].tempFile).toBeTruthy(); + expect(baseTree[0].tree[0].name).toBe('test'); }); it('does not create new tree when already exists', () => { - vm.$store.state.tree.push(file('app', '1', 'tree')); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + baseTree.push(file('app', '1', 'tree')); vm.entryName = 'app'; vm.createEntryInStore(); - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe('app'); - expect(vm.$store.state.tree[0].tempFile).toBeFalsy(); - expect(vm.$store.state.tree[0].tree.length).toBe(0); + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe('app'); + expect(baseTree[0].tempFile).toBeFalsy(); + expect(baseTree[0].tree.length).toBe(0); }); } }); @@ -188,6 +223,8 @@ describe('new file modal component', () => { vm = createComponentWithStore(Component, store, { type: 'tree', + projectId: 'abcproject', + branchId: 'master', path: '', }).$mount('.js-test'); diff --git a/spec/javascripts/repo/components/new_dropdown/upload_spec.js b/spec/javascripts/repo/components/new_dropdown/upload_spec.js index bf7893029b1..788c08e5279 100644 --- a/spec/javascripts/repo/components/new_dropdown/upload_spec.js +++ b/spec/javascripts/repo/components/new_dropdown/upload_spec.js @@ -1,19 +1,61 @@ import Vue from 'vue'; -import upload from '~/repo/components/new_dropdown/upload.vue'; -import store from '~/repo/stores'; +import upload from '~/ide/components/new_dropdown/upload.vue'; +import store from '~/ide/stores'; +import service from '~/ide/services'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { resetStore } from '../../helpers'; describe('new dropdown upload', () => { let vm; + let projectTree; beforeEach(() => { + spyOn(service, 'getProjectData').and.returnValue(Promise.resolve({ + data: { + id: '123', + }, + })); + + spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({ + commit: { + id: '123branch', + }, + })); + + spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({ + headers: { + 'page-title': 'test', + }, + json: () => Promise.resolve({ + last_commit_path: 'last_commit_path', + parent_tree_url: 'parent_tree_url', + path: '/', + trees: [{ name: 'tree' }], + blobs: [{ name: 'blob' }], + submodules: [{ name: 'submodule' }], + }), + })); + const Component = Vue.extend(upload); + store.state.projects.abcproject = { + web_url: '', + }; + store.state.currentProjectId = 'abcproject'; + store.state.trees = []; + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + projectTree = store.state.trees['abcproject/mybranch']; + vm = createComponentWithStore(Component, store, { + branchId: 'master', path: '', + parent: projectTree, }); + vm.entryName = 'testing'; + vm.$mount(); }); @@ -65,23 +107,33 @@ describe('new dropdown upload', () => { vm.createFile(target, file, true); vm.$nextTick(() => { - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe(file.name); - expect(vm.$store.state.tree[0].content).toBe(target.result); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe(file.name); + expect(baseTree[0].content).toBe(target.result); done(); }); }); it('creates new file in path', (done) => { - vm.$store.state.path = 'testing'; + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + const tree = { + type: 'tree', + name: 'testing', + path: 'testing', + tree: [], + }; + baseTree.push(tree); + + vm.parent = tree; vm.createFile(target, file, true); vm.$nextTick(() => { - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe(file.name); - expect(vm.$store.state.tree[0].content).toBe(target.result); - expect(vm.$store.state.tree[0].path).toBe(`testing/${file.name}`); + expect(baseTree.length).toBe(1); + expect(baseTree[0].tree[0].name).toBe(file.name); + expect(baseTree[0].tree[0].content).toBe(target.result); + expect(baseTree[0].tree[0].path).toBe(`testing/${file.name}`); done(); }); @@ -91,10 +143,11 @@ describe('new dropdown upload', () => { vm.createFile(binaryTarget, file, false); vm.$nextTick(() => { - expect(vm.$store.state.tree.length).toBe(1); - expect(vm.$store.state.tree[0].name).toBe(file.name); - expect(vm.$store.state.tree[0].content).toBe(binaryTarget.result.split('base64,')[1]); - expect(vm.$store.state.tree[0].base64).toBe(true); + const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].name).toBe(file.name); + expect(baseTree[0].content).toBe(binaryTarget.result.split('base64,')[1]); + expect(baseTree[0].base64).toBe(true); done(); }); diff --git a/spec/javascripts/repo/components/repo_commit_section_spec.js b/spec/javascripts/repo/components/repo_commit_section_spec.js index 72712e058e5..cd93fb3ccbf 100644 --- a/spec/javascripts/repo/components/repo_commit_section_spec.js +++ b/spec/javascripts/repo/components/repo_commit_section_spec.js @@ -1,8 +1,8 @@ import Vue from 'vue'; import * as urlUtils from '~/lib/utils/url_utility'; -import store from '~/repo/stores'; -import service from '~/repo/services'; -import repoCommitSection from '~/repo/components/repo_commit_section.vue'; +import store from '~/ide/stores'; +import service from '~/ide/services'; +import repoCommitSection from '~/ide/components/repo_commit_section.vue'; import getSetTimeoutPromise from '../../helpers/set_timeout_promise_helper'; import { file, resetStore } from '../helpers'; @@ -16,6 +16,18 @@ describe('RepoCommitSection', () => { store, }).$mount(); + comp.$store.state.currentProjectId = 'abcproject'; + comp.$store.state.currentBranchId = 'master'; + comp.$store.state.projects.abcproject = { + web_url: '', + branches: { + master: { + workingReference: '1', + }, + }, + }; + + comp.$store.state.rightPanelCollapsed = false; comp.$store.state.currentBranch = 'master'; comp.$store.state.openFiles = [file(), file()]; comp.$store.state.openFiles.forEach(f => Object.assign(f, { @@ -29,7 +41,19 @@ describe('RepoCommitSection', () => { beforeEach((done) => { vm = createComponent(); - vm.collapsed = false; + spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({ + headers: { + 'page-title': 'test', + }, + json: () => Promise.resolve({ + last_commit_path: 'last_commit_path', + parent_tree_url: 'parent_tree_url', + path: '/', + trees: [{ name: 'tree' }], + blobs: [{ name: 'blob' }], + submodules: [{ name: 'submodule' }], + }), + })); Vue.nextTick(done); }); @@ -45,7 +69,6 @@ describe('RepoCommitSection', () => { const submitCommit = vm.$el.querySelector('form .btn'); expect(vm.$el.querySelector('.multi-file-commit-form')).not.toBeNull(); - expect(vm.$el.querySelector('.multi-file-commit-panel-section header').textContent.trim()).toEqual('Staged'); expect(changedFileElements.length).toEqual(2); changedFileElements.forEach((changedFile, i) => { diff --git a/spec/javascripts/repo/components/repo_edit_button_spec.js b/spec/javascripts/repo/components/repo_edit_button_spec.js index 44018464b35..2895b794506 100644 --- a/spec/javascripts/repo/components/repo_edit_button_spec.js +++ b/spec/javascripts/repo/components/repo_edit_button_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoEditButton from '~/repo/components/repo_edit_button.vue'; +import store from '~/ide/stores'; +import repoEditButton from '~/ide/components/repo_edit_button.vue'; import { file, resetStore } from '../helpers'; describe('RepoEditButton', () => { @@ -32,7 +32,7 @@ describe('RepoEditButton', () => { vm.$mount(); expect(vm.$el.querySelector('.btn')).not.toBeNull(); - expect(vm.$el.querySelector('.btn').textContent.trim()).toBe('Edit'); + expect(vm.$el.querySelector('.btn').textContent.trim()).toBe('Cancel edit'); }); it('renders edit button with cancel text', () => { @@ -50,7 +50,7 @@ describe('RepoEditButton', () => { vm.$el.querySelector('.btn').click(); vm.$nextTick(() => { - expect(vm.$el.querySelector('.btn').textContent.trim()).toBe('Cancel edit'); + expect(vm.$el.querySelector('.btn').textContent.trim()).toBe('Edit'); done(); }); diff --git a/spec/javascripts/repo/components/repo_editor_spec.js b/spec/javascripts/repo/components/repo_editor_spec.js index 81158cad639..e7b2ed08acd 100644 --- a/spec/javascripts/repo/components/repo_editor_spec.js +++ b/spec/javascripts/repo/components/repo_editor_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoEditor from '~/repo/components/repo_editor.vue'; -import monacoLoader from '~/repo/monaco_loader'; +import store from '~/ide/stores'; +import repoEditor from '~/ide/components/repo_editor.vue'; +import monacoLoader from '~/ide/monaco_loader'; import { file, resetStore } from '../helpers'; describe('RepoEditor', () => { diff --git a/spec/javascripts/repo/components/repo_file_buttons_spec.js b/spec/javascripts/repo/components/repo_file_buttons_spec.js index d6e255e4810..115569a9117 100644 --- a/spec/javascripts/repo/components/repo_file_buttons_spec.js +++ b/spec/javascripts/repo/components/repo_file_buttons_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoFileButtons from '~/repo/components/repo_file_buttons.vue'; +import store from '~/ide/stores'; +import repoFileButtons from '~/ide/components/repo_file_buttons.vue'; import { file, resetStore } from '../helpers'; describe('RepoFileButtons', () => { diff --git a/spec/javascripts/repo/components/repo_file_spec.js b/spec/javascripts/repo/components/repo_file_spec.js index bf9181fb09c..e8b370f97b4 100644 --- a/spec/javascripts/repo/components/repo_file_spec.js +++ b/spec/javascripts/repo/components/repo_file_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoFile from '~/repo/components/repo_file.vue'; +import store from '~/ide/stores'; +import repoFile from '~/ide/components/repo_file.vue'; import { file, resetStore } from '../helpers'; describe('RepoFile', () => { @@ -35,11 +35,10 @@ describe('RepoFile', () => { const fileIcon = vm.$el.querySelector('.file-icon'); expect(vm.$el.querySelector(`.${vm.file.icon}`).style.marginLeft).toEqual('0px'); - expect(name.href).toMatch(`/${vm.file.url}`); + expect(name.href).toMatch(''); expect(name.textContent.trim()).toEqual(vm.file.name); expect(fileIcon.classList.contains(vm.file.icon)).toBeTruthy(); expect(fileIcon.style.marginLeft).toEqual(`${vm.file.level * 10}px`); - expect(vm.$el.querySelectorAll('.animation-container').length).toBe(2); }); it('does render if hasFiles is true and is loading tree', () => { @@ -75,16 +74,16 @@ describe('RepoFile', () => { }); }); - it('fires clickedTreeRow when the link is clicked', () => { + it('fires clickFile when the link is clicked', () => { vm = createComponent({ file: file(), }); - spyOn(vm, 'clickedTreeRow'); + spyOn(vm, 'clickFile'); vm.$el.click(); - expect(vm.clickedTreeRow).toHaveBeenCalledWith(vm.file); + expect(vm.clickFile).toHaveBeenCalledWith(vm.file); }); describe('submodule', () => { diff --git a/spec/javascripts/repo/components/repo_loading_file_spec.js b/spec/javascripts/repo/components/repo_loading_file_spec.js index 031f2a9c0b2..18366fb89bc 100644 --- a/spec/javascripts/repo/components/repo_loading_file_spec.js +++ b/spec/javascripts/repo/components/repo_loading_file_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoLoadingFile from '~/repo/components/repo_loading_file.vue'; +import store from '~/ide/stores'; +import repoLoadingFile from '~/ide/components/repo_loading_file.vue'; import { resetStore } from '../helpers'; describe('RepoLoadingFile', () => { @@ -48,6 +48,7 @@ describe('RepoLoadingFile', () => { it('renders 1 column of animated LoC if isMini', (done) => { vm = createComponent(); + vm.$store.state.leftPanelCollapsed = true; vm.$store.state.openFiles.push('test'); vm.$nextTick(() => { diff --git a/spec/javascripts/repo/components/repo_prev_directory_spec.js b/spec/javascripts/repo/components/repo_prev_directory_spec.js index 7f82ae36a64..ff26cab2262 100644 --- a/spec/javascripts/repo/components/repo_prev_directory_spec.js +++ b/spec/javascripts/repo/components/repo_prev_directory_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoPrevDirectory from '~/repo/components/repo_prev_directory.vue'; +import store from '~/ide/stores'; +import repoPrevDirectory from '~/ide/components/repo_prev_directory.vue'; import { resetStore } from '../helpers'; describe('RepoPrevDirectory', () => { diff --git a/spec/javascripts/repo/components/repo_preview_spec.js b/spec/javascripts/repo/components/repo_preview_spec.js index 8d1a87494cf..e90837e4cb2 100644 --- a/spec/javascripts/repo/components/repo_preview_spec.js +++ b/spec/javascripts/repo/components/repo_preview_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoPreview from '~/repo/components/repo_preview.vue'; +import store from '~/ide/stores'; +import repoPreview from '~/ide/components/repo_preview.vue'; import { file, resetStore } from '../helpers'; describe('RepoPreview', () => { diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js deleted file mode 100644 index df7cf8aabbb..00000000000 --- a/spec/javascripts/repo/components/repo_sidebar_spec.js +++ /dev/null @@ -1,62 +0,0 @@ -import Vue from 'vue'; -import store from '~/repo/stores'; -import repoSidebar from '~/repo/components/repo_sidebar.vue'; -import { file, resetStore } from '../helpers'; - -describe('RepoSidebar', () => { - let vm; - - beforeEach(() => { - const RepoSidebar = Vue.extend(repoSidebar); - - vm = new RepoSidebar({ - store, - }); - - vm.$store.state.isRoot = true; - vm.$store.state.tree.push(file()); - - vm.$mount(); - }); - - afterEach(() => { - vm.$destroy(); - - resetStore(vm.$store); - }); - - it('renders a sidebar', () => { - const thead = vm.$el.querySelector('thead'); - const tbody = vm.$el.querySelector('tbody'); - - expect(vm.$el.classList.contains('sidebar-mini')).toBeFalsy(); - expect(thead.querySelector('.name').textContent.trim()).toEqual('Name'); - expect(thead.querySelector('.last-commit').textContent.trim()).toEqual('Last commit'); - expect(thead.querySelector('.last-update').textContent.trim()).toEqual('Last update'); - expect(tbody.querySelector('.repo-file-options')).toBeFalsy(); - expect(tbody.querySelector('.prev-directory')).toBeFalsy(); - expect(tbody.querySelector('.loading-file')).toBeFalsy(); - expect(tbody.querySelector('.file')).toBeTruthy(); - }); - - it('renders 5 loading files if tree is loading', (done) => { - vm.$store.state.tree = []; - vm.$store.state.loading = true; - - Vue.nextTick(() => { - expect(vm.$el.querySelectorAll('tbody .loading-file').length).toEqual(5); - - done(); - }); - }); - - it('renders a prev directory if is not root', (done) => { - vm.$store.state.isRoot = false; - - Vue.nextTick(() => { - expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy(); - - done(); - }); - }); -}); diff --git a/spec/javascripts/repo/components/repo_spec.js b/spec/javascripts/repo/components/repo_spec.js deleted file mode 100644 index b32d2c13af8..00000000000 --- a/spec/javascripts/repo/components/repo_spec.js +++ /dev/null @@ -1,35 +0,0 @@ -import Vue from 'vue'; -import store from '~/repo/stores'; -import repo from '~/repo/components/repo.vue'; -import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; -import { file, resetStore } from '../helpers'; - -describe('repo component', () => { - let vm; - - beforeEach(() => { - const Component = Vue.extend(repo); - - vm = createComponentWithStore(Component, store).$mount(); - }); - - afterEach(() => { - vm.$destroy(); - - resetStore(vm.$store); - }); - - it('does not render panel right when no files open', () => { - expect(vm.$el.querySelector('.panel-right')).toBeNull(); - }); - - it('renders panel right when files are open', (done) => { - vm.$store.state.tree.push(file()); - - Vue.nextTick(() => { - expect(vm.$el.querySelector('.panel-right')).toBeNull(); - - done(); - }); - }); -}); diff --git a/spec/javascripts/repo/components/repo_tab_spec.js b/spec/javascripts/repo/components/repo_tab_spec.js index 7d2174196c9..507bca983df 100644 --- a/spec/javascripts/repo/components/repo_tab_spec.js +++ b/spec/javascripts/repo/components/repo_tab_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoTab from '~/repo/components/repo_tab.vue'; +import store from '~/ide/stores'; +import repoTab from '~/ide/components/repo_tab.vue'; import { file, resetStore } from '../helpers'; describe('RepoTab', () => { @@ -31,16 +31,16 @@ describe('RepoTab', () => { expect(name.textContent.trim()).toEqual(vm.tab.name); }); - it('calls setFileActive when clicking tab', () => { + it('fires clickFile when the link is clicked', () => { vm = createComponent({ tab: file(), }); - spyOn(vm, 'setFileActive'); + spyOn(vm, 'clickFile'); vm.$el.click(); - expect(vm.setFileActive).toHaveBeenCalledWith(vm.tab); + expect(vm.clickFile).toHaveBeenCalledWith(vm.tab); }); it('calls closeFile when clicking close button', () => { diff --git a/spec/javascripts/repo/components/repo_tabs_spec.js b/spec/javascripts/repo/components/repo_tabs_spec.js index 1fb2242c051..0beaf643793 100644 --- a/spec/javascripts/repo/components/repo_tabs_spec.js +++ b/spec/javascripts/repo/components/repo_tabs_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import repoTabs from '~/repo/components/repo_tabs.vue'; +import store from '~/ide/stores'; +import repoTabs from '~/ide/components/repo_tabs.vue'; import { file, resetStore } from '../helpers'; describe('RepoTabs', () => { diff --git a/spec/javascripts/repo/helpers.js b/spec/javascripts/repo/helpers.js index 820a44992b4..ac43d221198 100644 --- a/spec/javascripts/repo/helpers.js +++ b/spec/javascripts/repo/helpers.js @@ -1,5 +1,5 @@ -import { decorateData } from '~/repo/stores/utils'; -import state from '~/repo/stores/state'; +import { decorateData } from '~/ide/stores/utils'; +import state from '~/ide/stores/state'; export const resetStore = (store) => { store.replaceState(state()); @@ -12,4 +12,5 @@ export const file = (name = 'name', id = name, type = '') => decorateData({ url: 'url', name, path: name, + lastCommit: {}, }); diff --git a/spec/javascripts/repo/lib/common/disposable_spec.js b/spec/javascripts/repo/lib/common/disposable_spec.js index 62c3913bf4d..af12ca15369 100644 --- a/spec/javascripts/repo/lib/common/disposable_spec.js +++ b/spec/javascripts/repo/lib/common/disposable_spec.js @@ -1,4 +1,4 @@ -import Disposable from '~/repo/lib/common/disposable'; +import Disposable from '~/ide/lib/common/disposable'; describe('Multi-file editor library disposable class', () => { let instance; diff --git a/spec/javascripts/repo/lib/common/model_manager_spec.js b/spec/javascripts/repo/lib/common/model_manager_spec.js index 8c134f178c0..563c2e33834 100644 --- a/spec/javascripts/repo/lib/common/model_manager_spec.js +++ b/spec/javascripts/repo/lib/common/model_manager_spec.js @@ -1,6 +1,6 @@ /* global monaco */ -import monacoLoader from '~/repo/monaco_loader'; -import ModelManager from '~/repo/lib/common/model_manager'; +import monacoLoader from '~/ide/monaco_loader'; +import ModelManager from '~/ide/lib/common/model_manager'; import { file } from '../../helpers'; describe('Multi-file editor library model manager', () => { diff --git a/spec/javascripts/repo/lib/common/model_spec.js b/spec/javascripts/repo/lib/common/model_spec.js index d41ade237ca..878a4a3f3fe 100644 --- a/spec/javascripts/repo/lib/common/model_spec.js +++ b/spec/javascripts/repo/lib/common/model_spec.js @@ -1,6 +1,6 @@ /* global monaco */ -import monacoLoader from '~/repo/monaco_loader'; -import Model from '~/repo/lib/common/model'; +import monacoLoader from '~/ide/monaco_loader'; +import Model from '~/ide/lib/common/model'; import { file } from '../../helpers'; describe('Multi-file editor library model', () => { diff --git a/spec/javascripts/repo/lib/decorations/controller_spec.js b/spec/javascripts/repo/lib/decorations/controller_spec.js index 2e32e8fa0bd..fea12d74dca 100644 --- a/spec/javascripts/repo/lib/decorations/controller_spec.js +++ b/spec/javascripts/repo/lib/decorations/controller_spec.js @@ -1,8 +1,8 @@ /* global monaco */ -import monacoLoader from '~/repo/monaco_loader'; -import editor from '~/repo/lib/editor'; -import DecorationsController from '~/repo/lib/decorations/controller'; -import Model from '~/repo/lib/common/model'; +import monacoLoader from '~/ide/monaco_loader'; +import editor from '~/ide/lib/editor'; +import DecorationsController from '~/ide/lib/decorations/controller'; +import Model from '~/ide/lib/common/model'; import { file } from '../../helpers'; describe('Multi-file editor library decorations controller', () => { diff --git a/spec/javascripts/repo/lib/diff/controller_spec.js b/spec/javascripts/repo/lib/diff/controller_spec.js index ed62e28d3a3..1d55c165260 100644 --- a/spec/javascripts/repo/lib/diff/controller_spec.js +++ b/spec/javascripts/repo/lib/diff/controller_spec.js @@ -1,10 +1,10 @@ /* global monaco */ -import monacoLoader from '~/repo/monaco_loader'; -import editor from '~/repo/lib/editor'; -import ModelManager from '~/repo/lib/common/model_manager'; -import DecorationsController from '~/repo/lib/decorations/controller'; -import DirtyDiffController, { getDiffChangeType, getDecorator } from '~/repo/lib/diff/controller'; -import { computeDiff } from '~/repo/lib/diff/diff'; +import monacoLoader from '~/ide/monaco_loader'; +import editor from '~/ide/lib/editor'; +import ModelManager from '~/ide/lib/common/model_manager'; +import DecorationsController from '~/ide/lib/decorations/controller'; +import DirtyDiffController, { getDiffChangeType, getDecorator } from '~/ide/lib/diff/controller'; +import { computeDiff } from '~/ide/lib/diff/diff'; import { file } from '../../helpers'; describe('Multi-file editor library dirty diff controller', () => { diff --git a/spec/javascripts/repo/lib/diff/diff_spec.js b/spec/javascripts/repo/lib/diff/diff_spec.js index 3269ec5d2c9..57f3ac3d365 100644 --- a/spec/javascripts/repo/lib/diff/diff_spec.js +++ b/spec/javascripts/repo/lib/diff/diff_spec.js @@ -1,4 +1,4 @@ -import { computeDiff } from '~/repo/lib/diff/diff'; +import { computeDiff } from '~/ide/lib/diff/diff'; describe('Multi-file editor library diff calculator', () => { describe('computeDiff', () => { diff --git a/spec/javascripts/repo/lib/editor_options_spec.js b/spec/javascripts/repo/lib/editor_options_spec.js index b4887d063ed..edbf5450dce 100644 --- a/spec/javascripts/repo/lib/editor_options_spec.js +++ b/spec/javascripts/repo/lib/editor_options_spec.js @@ -1,4 +1,4 @@ -import editorOptions from '~/repo/lib/editor_options'; +import editorOptions from '~/ide/lib/editor_options'; describe('Multi-file editor library editor options', () => { it('returns an array', () => { diff --git a/spec/javascripts/repo/lib/editor_spec.js b/spec/javascripts/repo/lib/editor_spec.js index cd32832a232..8d51d48a782 100644 --- a/spec/javascripts/repo/lib/editor_spec.js +++ b/spec/javascripts/repo/lib/editor_spec.js @@ -1,6 +1,6 @@ /* global monaco */ -import monacoLoader from '~/repo/monaco_loader'; -import editor from '~/repo/lib/editor'; +import monacoLoader from '~/ide/monaco_loader'; +import editor from '~/ide/lib/editor'; import { file } from '../helpers'; describe('Multi-file editor library', () => { diff --git a/spec/javascripts/repo/monaco_loader_spec.js b/spec/javascripts/repo/monaco_loader_spec.js index 887a80160fc..b8ac36972aa 100644 --- a/spec/javascripts/repo/monaco_loader_spec.js +++ b/spec/javascripts/repo/monaco_loader_spec.js @@ -1,5 +1,5 @@ import monacoContext from 'monaco-editor/dev/vs/loader'; -import monacoLoader from '~/repo/monaco_loader'; +import monacoLoader from '~/ide/monaco_loader'; describe('MonacoLoader', () => { it('calls require.config and exports require', () => { diff --git a/spec/javascripts/repo/stores/actions/branch_spec.js b/spec/javascripts/repo/stores/actions/branch_spec.js index af9d6835a67..00d16fd790d 100644 --- a/spec/javascripts/repo/stores/actions/branch_spec.js +++ b/spec/javascripts/repo/stores/actions/branch_spec.js @@ -1,5 +1,5 @@ -import store from '~/repo/stores'; -import service from '~/repo/services'; +import store from '~/ide/stores'; +import service from '~/ide/services'; import { resetStore } from '../../helpers'; describe('Multi-file store branch actions', () => { @@ -16,19 +16,25 @@ describe('Multi-file store branch actions', () => { })); spyOn(history, 'pushState'); - store.state.project.id = 2; - store.state.currentBranch = 'testing'; + store.state.currentProjectId = 'abcproject'; + store.state.currentBranchId = 'testing'; + store.state.projects.abcproject = { + branches: { + master: { + workingReference: '1', + }, + }, + }; }); it('creates new branch', (done) => { store.dispatch('createNewBranch', 'master') .then(() => { - expect(store.state.currentBranch).toBe('testing'); - expect(service.createBranch).toHaveBeenCalledWith(2, { + expect(store.state.currentBranchId).toBe('testing'); + expect(service.createBranch).toHaveBeenCalledWith('abcproject', { branch: 'master', ref: 'testing', }); - expect(history.pushState).toHaveBeenCalled(); done(); }) diff --git a/spec/javascripts/repo/stores/actions/file_spec.js b/spec/javascripts/repo/stores/actions/file_spec.js index 099c0556e71..8ce01d3bf12 100644 --- a/spec/javascripts/repo/stores/actions/file_spec.js +++ b/spec/javascripts/repo/stores/actions/file_spec.js @@ -1,6 +1,6 @@ import Vue from 'vue'; -import store from '~/repo/stores'; -import service from '~/repo/services'; +import store from '~/ide/stores'; +import service from '~/ide/services'; import { file, resetStore } from '../../helpers'; describe('Multi-file store file actions', () => { @@ -24,8 +24,6 @@ describe('Multi-file store file actions', () => { localFile.parentTreeUrl = 'parentTreeUrl'; store.state.openFiles.push(localFile); - - spyOn(history, 'pushState'); }); afterEach(() => { @@ -82,15 +80,6 @@ describe('Multi-file store file actions', () => { }).catch(done.fail); }); - it('calls pushState when no open files are left', (done) => { - store.dispatch('closeFile', { file: localFile }) - .then(() => { - expect(history.pushState).toHaveBeenCalledWith(jasmine.anything(), '', 'parentTreeUrl'); - - done(); - }).catch(done.fail); - }); - it('sets next file as active', (done) => { const f = file(); store.state.openFiles.push(f); @@ -322,8 +311,26 @@ describe('Multi-file store file actions', () => { }); describe('createTempFile', () => { + let projectTree; + beforeEach(() => { document.body.innerHTML += '
'; + + store.state.currentProjectId = 'abcproject'; + store.state.currentBranchId = 'master'; + store.state.projects.abcproject = { + branches: { + master: { + workingReference: '1', + }, + }, + }; + + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + + projectTree = store.state.trees['abcproject/mybranch']; }); afterEach(() => { @@ -332,11 +339,13 @@ describe('Multi-file store file actions', () => { it('creates temp file', (done) => { store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then((f) => { expect(f.tempFile).toBeTruthy(); - expect(store.state.tree.length).toBe(1); + expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1); done(); }).catch(done.fail); @@ -344,8 +353,10 @@ describe('Multi-file store file actions', () => { it('adds tmp file to open files', (done) => { store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then((f) => { expect(store.state.openFiles.length).toBe(1); expect(store.state.openFiles[0].name).toBe(f.name); @@ -356,8 +367,10 @@ describe('Multi-file store file actions', () => { it('sets tmp file as active', (done) => { store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then((f) => { expect(f.active).toBeTruthy(); @@ -367,8 +380,10 @@ describe('Multi-file store file actions', () => { it('enters edit mode if file is not base64', (done) => { store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then(() => { expect(store.state.editMode).toBeTruthy(); @@ -376,24 +391,14 @@ describe('Multi-file store file actions', () => { }).catch(done.fail); }); - it('does not enter edit mode if file is base64', (done) => { - store.dispatch('createTempFile', { - tree: store.state, - name: 'test', - base64: true, - }).then(() => { - expect(store.state.editMode).toBeFalsy(); - - done(); - }).catch(done.fail); - }); - it('creates flash message is file already exists', (done) => { - store.state.tree.push(file('test', '1', 'blob')); + store.state.trees['abcproject/mybranch'].tree.push(file('test', '1', 'blob')); store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then(() => { expect(document.querySelector('.flash-alert')).not.toBeNull(); @@ -402,11 +407,13 @@ describe('Multi-file store file actions', () => { }); it('increases level of file', (done) => { - store.state.level = 1; + store.state.trees['abcproject/mybranch'].level = 1; store.dispatch('createTempFile', { - tree: store.state, name: 'test', + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, }).then((f) => { expect(f.level).toBe(2); diff --git a/spec/javascripts/repo/stores/actions/tree_spec.js b/spec/javascripts/repo/stores/actions/tree_spec.js index 2bbc49d5a9f..65351dbb7d9 100644 --- a/spec/javascripts/repo/stores/actions/tree_spec.js +++ b/spec/javascripts/repo/stores/actions/tree_spec.js @@ -1,10 +1,30 @@ import Vue from 'vue'; -import * as urlUtils from '~/lib/utils/url_utility'; -import store from '~/repo/stores'; -import service from '~/repo/services'; +import store from '~/ide/stores'; +import service from '~/ide/services'; import { file, resetStore } from '../../helpers'; describe('Multi-file store tree actions', () => { + let projectTree; + + const basicCallParameters = { + endpoint: 'rootEndpoint', + projectId: 'abcproject', + branch: 'master', + }; + + beforeEach(() => { + store.state.currentProjectId = 'abcproject'; + store.state.currentBranchId = 'master'; + store.state.projects.abcproject = { + web_url: '', + branches: { + master: { + workingReference: '1', + }, + }, + }; + }); + afterEach(() => { resetStore(store); }); @@ -24,38 +44,32 @@ describe('Multi-file store tree actions', () => { submodules: [{ name: 'submodule' }], }), })); - spyOn(history, 'pushState'); - - Object.assign(store.state.endpoints, { - rootEndpoint: 'rootEndpoint', - }); }); it('calls service getTreeData', (done) => { - store.dispatch('getTreeData') - .then(() => { - expect(service.getTreeData).toHaveBeenCalledWith('rootEndpoint'); + store.dispatch('getTreeData', basicCallParameters) + .then(() => { + expect(service.getTreeData).toHaveBeenCalledWith('rootEndpoint'); - done(); - }).catch(done.fail); + done(); + }).catch(done.fail); }); it('adds data into tree', (done) => { - store.dispatch('getTreeData') - .then(Vue.nextTick) + store.dispatch('getTreeData', basicCallParameters) .then(() => { - expect(store.state.tree.length).toBe(3); - expect(store.state.tree[0].type).toBe('tree'); - expect(store.state.tree[1].type).toBe('submodule'); - expect(store.state.tree[2].type).toBe('blob'); + projectTree = store.state.trees['abcproject/master']; + expect(projectTree.tree.length).toBe(3); + expect(projectTree.tree[0].type).toBe('tree'); + expect(projectTree.tree[1].type).toBe('submodule'); + expect(projectTree.tree[2].type).toBe('blob'); done(); }).catch(done.fail); }); it('sets parent tree URL', (done) => { - store.dispatch('getTreeData') - .then(Vue.nextTick) + store.dispatch('getTreeData', basicCallParameters) .then(() => { expect(store.state.parentTreeUrl).toBe('parent_tree_url'); @@ -64,10 +78,9 @@ describe('Multi-file store tree actions', () => { }); it('sets last commit path', (done) => { - store.dispatch('getTreeData') - .then(Vue.nextTick) + store.dispatch('getTreeData', basicCallParameters) .then(() => { - expect(store.state.lastCommitPath).toBe('last_commit_path'); + expect(store.state.trees['abcproject/master'].lastCommitPath).toBe('last_commit_path'); done(); }).catch(done.fail); @@ -76,8 +89,7 @@ describe('Multi-file store tree actions', () => { it('sets root if not currently at root', (done) => { store.state.isInitialRoot = false; - store.dispatch('getTreeData') - .then(Vue.nextTick) + store.dispatch('getTreeData', basicCallParameters) .then(() => { expect(store.state.isInitialRoot).toBeTruthy(); expect(store.state.isRoot).toBeTruthy(); @@ -87,7 +99,7 @@ describe('Multi-file store tree actions', () => { }); it('sets page title', (done) => { - store.dispatch('getTreeData') + store.dispatch('getTreeData', basicCallParameters) .then(() => { expect(document.title).toBe('test'); @@ -95,40 +107,15 @@ describe('Multi-file store tree actions', () => { }).catch(done.fail); }); - it('toggles loading', (done) => { - store.dispatch('getTreeData') - .then(() => { - expect(store.state.loading).toBeTruthy(); - - return Vue.nextTick(); - }) - .then(() => { - expect(store.state.loading).toBeFalsy(); - - done(); - }).catch(done.fail); - }); - - it('calls pushState with endpoint', (done) => { - store.dispatch('getTreeData') - .then(Vue.nextTick) - .then(() => { - expect(history.pushState).toHaveBeenCalledWith(jasmine.anything(), '', 'rootEndpoint'); - - done(); - }).catch(done.fail); - }); - it('calls getLastCommitData if prevLastCommitPath is not null', (done) => { const getLastCommitDataSpy = jasmine.createSpy('getLastCommitData'); const oldGetLastCommitData = store._actions.getLastCommitData; // eslint-disable-line store._actions.getLastCommitData = [getLastCommitDataSpy]; // eslint-disable-line store.state.prevLastCommitPath = 'test'; - store.dispatch('getTreeData') - .then(Vue.nextTick) + store.dispatch('getTreeData', basicCallParameters) .then(() => { - expect(getLastCommitDataSpy).toHaveBeenCalledWith(store.state); + expect(getLastCommitDataSpy).toHaveBeenCalledWith(projectTree); store._actions.getLastCommitData = oldGetLastCommitData; // eslint-disable-line @@ -149,6 +136,8 @@ describe('Multi-file store tree actions', () => { store._actions.getTreeData = [getTreeDataSpy]; // eslint-disable-line tree = { + projectId: 'abcproject', + branchId: 'master', opened: false, tree: [], }; @@ -175,10 +164,11 @@ describe('Multi-file store tree actions', () => { tree, }).then(() => { expect(getTreeDataSpy).toHaveBeenCalledWith({ + projectId: 'abcproject', + branch: 'master', endpoint: 'test', tree, }); - expect(store.state.previousUrl).toBe('test'); done(); }).catch(done.fail); @@ -199,155 +189,29 @@ describe('Multi-file store tree actions', () => { done(); }).catch(done.fail); }); - - it('pushes new state', (done) => { - spyOn(history, 'pushState'); - Object.assign(tree, { - opened: true, - parentTreeUrl: 'testing', - }); - - store.dispatch('toggleTreeOpen', { - endpoint: 'test', - tree, - }).then(() => { - expect(history.pushState).toHaveBeenCalledWith(jasmine.anything(), '', 'testing'); - - done(); - }).catch(done.fail); - }); - }); - - describe('clickedTreeRow', () => { - describe('tree', () => { - let toggleTreeOpenSpy; - let oldToggleTreeOpen; - - beforeEach(() => { - toggleTreeOpenSpy = jasmine.createSpy('toggleTreeOpen'); - - oldToggleTreeOpen = store._actions.toggleTreeOpen; // eslint-disable-line - store._actions.toggleTreeOpen = [toggleTreeOpenSpy]; // eslint-disable-line - }); - - afterEach(() => { - store._actions.toggleTreeOpen = oldToggleTreeOpen; // eslint-disable-line - }); - - it('opens tree', (done) => { - const tree = { - url: 'a', - type: 'tree', - }; - - store.dispatch('clickedTreeRow', tree) - .then(() => { - expect(toggleTreeOpenSpy).toHaveBeenCalledWith({ - endpoint: tree.url, - tree, - }); - - done(); - }).catch(done.fail); - }); - }); - - describe('submodule', () => { - let row; - - beforeEach(() => { - spyOn(urlUtils, 'visitUrl'); - - row = { - url: 'submoduleurl', - type: 'submodule', - loading: false, - }; - }); - - it('toggles loading for row', (done) => { - store.dispatch('clickedTreeRow', row) - .then(() => { - expect(row.loading).toBeTruthy(); - - done(); - }).catch(done.fail); - }); - - it('opens submodule URL', (done) => { - store.dispatch('clickedTreeRow', row) - .then(() => { - expect(urlUtils.visitUrl).toHaveBeenCalledWith('submoduleurl'); - - done(); - }).catch(done.fail); - }); - }); - - describe('blob', () => { - let row; - - beforeEach(() => { - row = { - type: 'blob', - opened: false, - }; - }); - - it('calls getFileData', (done) => { - const getFileDataSpy = jasmine.createSpy('getFileData'); - const oldGetFileData = store._actions.getFileData; // eslint-disable-line - store._actions.getFileData = [getFileDataSpy]; // eslint-disable-line - - store.dispatch('clickedTreeRow', row) - .then(() => { - expect(getFileDataSpy).toHaveBeenCalledWith(row); - - store._actions.getFileData = oldGetFileData; // eslint-disable-line - - done(); - }).catch(done.fail); - }); - - it('calls setFileActive when file is opened', (done) => { - const setFileActiveSpy = jasmine.createSpy('setFileActive'); - const oldSetFileActive = store._actions.setFileActive; // eslint-disable-line - store._actions.setFileActive = [setFileActiveSpy]; // eslint-disable-line - - row.opened = true; - - store.dispatch('clickedTreeRow', row) - .then(() => { - expect(setFileActiveSpy).toHaveBeenCalledWith(row); - - store._actions.setFileActive = oldSetFileActive; // eslint-disable-line - - done(); - }).catch(done.fail); - }); - }); }); describe('createTempTree', () => { - it('creates temp tree', (done) => { - store.dispatch('createTempTree', 'test') - .then(() => { - expect(store.state.tree[0].tempFile).toBeTruthy(); - expect(store.state.tree[0].name).toBe('test'); - expect(store.state.tree[0].type).toBe('tree'); - - done(); - }).catch(done.fail); + beforeEach(() => { + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + projectTree = store.state.trees['abcproject/mybranch']; }); - it('creates .gitkeep file in temp tree', (done) => { - store.dispatch('createTempTree', 'test') - .then(() => { - expect(store.state.tree[0].tree[0].tempFile).toBeTruthy(); - expect(store.state.tree[0].tree[0].name).toBe('.gitkeep'); + it('creates temp tree', (done) => { + store.dispatch('createTempTree', { + projectId: store.state.currentProjectId, + branchId: store.state.currentBranchId, + name: 'test', + parent: projectTree, + }) + .then(() => { + expect(projectTree.tree[0].name).toBe('test'); + expect(projectTree.tree[0].type).toBe('tree'); - done(); - }).catch(done.fail); + done(); + }).catch(done.fail); }); it('creates new folder inside another tree', (done) => { @@ -357,35 +221,46 @@ describe('Multi-file store tree actions', () => { tree: [], }; - store.state.tree.push(tree); + projectTree.tree.push(tree); - store.dispatch('createTempTree', 'testing/test') - .then(() => { - expect(store.state.tree[0].name).toBe('testing'); - expect(store.state.tree[0].tree[0].tempFile).toBeTruthy(); - expect(store.state.tree[0].tree[0].name).toBe('test'); - expect(store.state.tree[0].tree[0].type).toBe('tree'); + store.dispatch('createTempTree', { + projectId: store.state.currentProjectId, + branchId: store.state.currentBranchId, + name: 'testing/test', + parent: projectTree, + }) + .then(() => { + expect(projectTree.tree[0].name).toBe('testing'); + expect(projectTree.tree[0].tree[0].tempFile).toBeTruthy(); + expect(projectTree.tree[0].tree[0].name).toBe('test'); + expect(projectTree.tree[0].tree[0].type).toBe('tree'); - done(); - }).catch(done.fail); + done(); + }).catch(done.fail); }); it('does not create new tree if already exists', (done) => { const tree = { type: 'tree', name: 'testing', + endpoint: 'test', tree: [], }; - store.state.tree.push(tree); + projectTree.tree.push(tree); - store.dispatch('createTempTree', 'testing/test') - .then(() => { - expect(store.state.tree[0].name).toBe('testing'); - expect(store.state.tree[0].tempFile).toBeUndefined(); + store.dispatch('createTempTree', { + projectId: store.state.currentProjectId, + branchId: store.state.currentBranchId, + name: 'testing/test', + parent: projectTree, + }) + .then(() => { + expect(projectTree.tree[0].name).toBe('testing'); + expect(projectTree.tree[0].tempFile).toBeUndefined(); - done(); - }).catch(done.fail); + done(); + }).catch(done.fail); }); }); @@ -405,12 +280,17 @@ describe('Multi-file store tree actions', () => { }]), })); - store.state.tree.push(file('testing', '1', 'tree')); - store.state.lastCommitPath = 'lastcommitpath'; + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + + projectTree = store.state.trees['abcproject/mybranch']; + projectTree.tree.push(file('testing', '1', 'tree')); + projectTree.lastCommitPath = 'lastcommitpath'; }); it('calls service with lastCommitPath', (done) => { - store.dispatch('getLastCommitData') + store.dispatch('getLastCommitData', projectTree) .then(() => { expect(service.getTreeLastCommit).toHaveBeenCalledWith('lastcommitpath'); @@ -419,22 +299,22 @@ describe('Multi-file store tree actions', () => { }); it('updates trees last commit data', (done) => { - store.dispatch('getLastCommitData') - .then(Vue.nextTick) + store.dispatch('getLastCommitData', projectTree) + .then(Vue.nextTick) .then(() => { - expect(store.state.tree[0].lastCommit.message).toBe('commit message'); + expect(projectTree.tree[0].lastCommit.message).toBe('commit message'); done(); }).catch(done.fail); }); it('does not update entry if not found', (done) => { - store.state.tree[0].name = 'a'; + projectTree.tree[0].name = 'a'; - store.dispatch('getLastCommitData') + store.dispatch('getLastCommitData', projectTree) .then(Vue.nextTick) .then(() => { - expect(store.state.tree[0].lastCommit.message).not.toBe('commit message'); + expect(projectTree.tree[0].lastCommit.message).not.toBe('commit message'); done(); }).catch(done.fail); diff --git a/spec/javascripts/repo/stores/actions_spec.js b/spec/javascripts/repo/stores/actions_spec.js index 21d87e46216..0b0d34f072a 100644 --- a/spec/javascripts/repo/stores/actions_spec.js +++ b/spec/javascripts/repo/stores/actions_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import * as urlUtils from '~/lib/utils/url_utility'; -import store from '~/repo/stores'; -import service from '~/repo/services'; +import store from '~/ide/stores'; +import service from '~/ide/services'; import { resetStore, file } from '../helpers'; describe('Multi-file store actions', () => { @@ -110,6 +110,7 @@ describe('Multi-file store actions', () => { it('can force closed if there are changed files', (done) => { store.state.editMode = true; + store.state.openFiles.push(file()); store.state.openFiles[0].changed = true; @@ -125,7 +126,6 @@ describe('Multi-file store actions', () => { it('discards file changes', (done) => { const f = file(); store.state.editMode = true; - store.state.tree.push(f); store.state.openFiles.push(f); f.changed = true; @@ -141,8 +141,6 @@ describe('Multi-file store actions', () => { describe('toggleBlobView', () => { it('sets edit mode view if in edit mode', (done) => { - store.state.editMode = true; - store.dispatch('toggleBlobView') .then(() => { expect(store.state.currentBlobView).toBe('repo-editor'); @@ -153,6 +151,8 @@ describe('Multi-file store actions', () => { }); it('sets preview mode view if not in edit mode', (done) => { + store.state.editMode = false; + store.dispatch('toggleBlobView') .then(() => { expect(store.state.currentBlobView).toBe('repo-preview'); @@ -165,9 +165,15 @@ describe('Multi-file store actions', () => { describe('checkCommitStatus', () => { beforeEach(() => { - store.state.project.id = 2; - store.state.currentBranch = 'master'; - store.state.currentRef = '1'; + store.state.currentProjectId = 'abcproject'; + store.state.currentBranchId = 'master'; + store.state.projects.abcproject = { + branches: { + master: { + workingReference: '1', + }, + }, + }; }); it('calls service', (done) => { @@ -177,7 +183,7 @@ describe('Multi-file store actions', () => { store.dispatch('checkCommitStatus') .then(() => { - expect(service.getBranchData).toHaveBeenCalledWith(2, 'master'); + expect(service.getBranchData).toHaveBeenCalledWith('abcproject', 'master'); done(); }) @@ -221,7 +227,17 @@ describe('Multi-file store actions', () => { document.body.innerHTML += '
'; - store.state.project.id = 123; + store.state.currentProjectId = 'abcproject'; + store.state.currentBranchId = 'master'; + store.state.projects.abcproject = { + web_url: 'webUrl', + branches: { + master: { + workingReference: '1', + }, + }, + }; + payload = { branch: 'master', }; @@ -248,7 +264,7 @@ describe('Multi-file store actions', () => { it('calls service', (done) => { store.dispatch('commitChanges', { payload, newMr: false }) .then(() => { - expect(service.commit).toHaveBeenCalledWith(123, payload); + expect(service.commit).toHaveBeenCalledWith('abcproject', payload); done(); }).catch(done.fail); @@ -284,17 +300,6 @@ describe('Multi-file store actions', () => { }).catch(done.fail); }); - it('toggles edit mode', (done) => { - store.state.editMode = true; - - store.dispatch('commitChanges', { payload, newMr: false }) - .then(() => { - expect(store.state.editMode).toBeFalsy(); - - done(); - }).catch(done.fail); - }); - it('closes all files', (done) => { store.state.openFiles.push(file()); store.state.openFiles[0].opened = true; @@ -317,23 +322,12 @@ describe('Multi-file store actions', () => { }).catch(done.fail); }); - it('updates commit ref', (done) => { - store.dispatch('commitChanges', { payload, newMr: false }) - .then(() => { - expect(store.state.currentRef).toBe('123456'); - - done(); - }).catch(done.fail); - }); - it('redirects to new merge request page', (done) => { spyOn(urlUtils, 'visitUrl'); - store.state.endpoints.newMergeRequestUrl = 'newMergeRequestUrl?branch='; - store.dispatch('commitChanges', { payload, newMr: true }) .then(() => { - expect(urlUtils.visitUrl).toHaveBeenCalledWith('newMergeRequestUrl?branch=master'); + expect(urlUtils.visitUrl).toHaveBeenCalledWith('webUrl/merge_requests/new?merge_request%5Bsource_branch%5D=master'); done(); }).catch(done.fail); @@ -363,15 +357,30 @@ describe('Multi-file store actions', () => { }); describe('createTempEntry', () => { + beforeEach(() => { + store.state.trees['abcproject/mybranch'] = { + tree: [], + }; + store.state.projects.abcproject = { + web_url: '', + }; + }); + it('creates a temp tree', (done) => { + const projectTree = store.state.trees['abcproject/mybranch']; + store.dispatch('createTempEntry', { + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, name: 'test', type: 'tree', }) .then(() => { - expect(store.state.tree.length).toBe(1); - expect(store.state.tree[0].tempFile).toBeTruthy(); - expect(store.state.tree[0].type).toBe('tree'); + const baseTree = projectTree.tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].tempFile).toBeTruthy(); + expect(baseTree[0].type).toBe('tree'); done(); }) @@ -379,14 +388,20 @@ describe('Multi-file store actions', () => { }); it('creates temp file', (done) => { + const projectTree = store.state.trees['abcproject/mybranch']; + store.dispatch('createTempEntry', { + projectId: 'abcproject', + branchId: 'mybranch', + parent: projectTree, name: 'test', type: 'blob', }) .then(() => { - expect(store.state.tree.length).toBe(1); - expect(store.state.tree[0].tempFile).toBeTruthy(); - expect(store.state.tree[0].type).toBe('blob'); + const baseTree = projectTree.tree; + expect(baseTree.length).toBe(1); + expect(baseTree[0].tempFile).toBeTruthy(); + expect(baseTree[0].type).toBe('blob'); done(); }) diff --git a/spec/javascripts/repo/stores/getters_spec.js b/spec/javascripts/repo/stores/getters_spec.js index 952b8ec3a59..d0d5934f29a 100644 --- a/spec/javascripts/repo/stores/getters_spec.js +++ b/spec/javascripts/repo/stores/getters_spec.js @@ -1,5 +1,5 @@ -import * as getters from '~/repo/stores/getters'; -import state from '~/repo/stores/state'; +import * as getters from '~/ide/stores/getters'; +import state from '~/ide/stores/state'; import { file } from '../helpers'; describe('Multi-file store getters', () => { @@ -9,20 +9,6 @@ describe('Multi-file store getters', () => { localState = state(); }); - describe('treeList', () => { - it('returns flat tree list', () => { - localState.tree.push(file('1')); - localState.tree[0].tree.push(file('2')); - localState.tree[0].tree[0].tree.push(file('3')); - - const treeList = getters.treeList(localState); - - expect(treeList.length).toBe(3); - expect(treeList[1].name).toBe(localState.tree[0].tree[0].name); - expect(treeList[2].name).toBe(localState.tree[0].tree[0].tree[0].name); - }); - }); - describe('changedFiles', () => { it('returns a list of changed opened files', () => { localState.openFiles.push(file()); @@ -49,7 +35,7 @@ describe('Multi-file store getters', () => { localState.openFiles.push(file()); localState.openFiles.push(file('active')); - expect(getters.activeFile(localState)).toBeUndefined(); + expect(getters.activeFile(localState)).toBeNull(); }); }); @@ -67,18 +53,6 @@ describe('Multi-file store getters', () => { }); }); - describe('isCollapsed', () => { - it('returns true if state has open files', () => { - localState.openFiles.push(file()); - - expect(getters.isCollapsed(localState)).toBeTruthy(); - }); - - it('returns false if state has no open files', () => { - expect(getters.isCollapsed(localState)).toBeFalsy(); - }); - }); - describe('canEditFile', () => { beforeEach(() => { localState.onTopOfBranch = true; @@ -109,12 +83,6 @@ describe('Multi-file store getters', () => { expect(getters.canEditFile(localState)).toBeFalsy(); }); - - it('returns false if user can commit but on a branch', () => { - localState.onTopOfBranch = false; - - expect(getters.canEditFile(localState)).toBeFalsy(); - }); }); describe('modifiedFiles', () => { diff --git a/spec/javascripts/repo/stores/mutations/branch_spec.js b/spec/javascripts/repo/stores/mutations/branch_spec.js index 3c06794d5e3..a7167537ef2 100644 --- a/spec/javascripts/repo/stores/mutations/branch_spec.js +++ b/spec/javascripts/repo/stores/mutations/branch_spec.js @@ -1,5 +1,5 @@ -import mutations from '~/repo/stores/mutations/branch'; -import state from '~/repo/stores/state'; +import mutations from '~/ide/stores/mutations/branch'; +import state from '~/ide/stores/state'; describe('Multi-file store branch mutations', () => { let localState; @@ -12,7 +12,7 @@ describe('Multi-file store branch mutations', () => { it('sets currentBranch', () => { mutations.SET_CURRENT_BRANCH(localState, 'master'); - expect(localState.currentBranch).toBe('master'); + expect(localState.currentBranchId).toBe('master'); }); }); }); diff --git a/spec/javascripts/repo/stores/mutations/file_spec.js b/spec/javascripts/repo/stores/mutations/file_spec.js index 2f2835dde1f..947a60587df 100644 --- a/spec/javascripts/repo/stores/mutations/file_spec.js +++ b/spec/javascripts/repo/stores/mutations/file_spec.js @@ -1,5 +1,5 @@ -import mutations from '~/repo/stores/mutations/file'; -import state from '~/repo/stores/state'; +import mutations from '~/ide/stores/mutations/file'; +import state from '~/ide/stores/state'; import { file } from '../../helpers'; describe('Multi-file store file mutations', () => { diff --git a/spec/javascripts/repo/stores/mutations/tree_spec.js b/spec/javascripts/repo/stores/mutations/tree_spec.js index 1c76cfed9c8..cf1248ba28b 100644 --- a/spec/javascripts/repo/stores/mutations/tree_spec.js +++ b/spec/javascripts/repo/stores/mutations/tree_spec.js @@ -1,5 +1,5 @@ -import mutations from '~/repo/stores/mutations/tree'; -import state from '~/repo/stores/state'; +import mutations from '~/ide/stores/mutations/tree'; +import state from '~/ide/stores/state'; import { file } from '../../helpers'; describe('Multi-file store tree mutations', () => { diff --git a/spec/javascripts/repo/stores/mutations_spec.js b/spec/javascripts/repo/stores/mutations_spec.js index d1c9885e01d..5fd8ad94972 100644 --- a/spec/javascripts/repo/stores/mutations_spec.js +++ b/spec/javascripts/repo/stores/mutations_spec.js @@ -1,5 +1,5 @@ -import mutations from '~/repo/stores/mutations'; -import state from '~/repo/stores/state'; +import mutations from '~/ide/stores/mutations'; +import state from '~/ide/stores/state'; import { file } from '../helpers'; describe('Multi-file store mutations', () => { @@ -65,11 +65,11 @@ describe('Multi-file store mutations', () => { it('toggles editMode', () => { mutations.TOGGLE_EDIT_MODE(localState); - expect(localState.editMode).toBeTruthy(); + expect(localState.editMode).toBeFalsy(); mutations.TOGGLE_EDIT_MODE(localState); - expect(localState.editMode).toBeFalsy(); + expect(localState.editMode).toBeTruthy(); }); }); @@ -85,14 +85,6 @@ describe('Multi-file store mutations', () => { }); }); - describe('SET_COMMIT_REF', () => { - it('sets currentRef', () => { - mutations.SET_COMMIT_REF(localState, '123'); - - expect(localState.currentRef).toBe('123'); - }); - }); - describe('SET_ROOT', () => { it('sets isRoot & initialRoot', () => { mutations.SET_ROOT(localState, true); @@ -107,11 +99,27 @@ describe('Multi-file store mutations', () => { }); }); - describe('SET_PREVIOUS_URL', () => { - it('sets previousUrl', () => { - mutations.SET_PREVIOUS_URL(localState, 'testing'); + describe('SET_LEFT_PANEL_COLLAPSED', () => { + it('sets left panel collapsed', () => { + mutations.SET_LEFT_PANEL_COLLAPSED(localState, true); + + expect(localState.leftPanelCollapsed).toBeTruthy(); + + mutations.SET_LEFT_PANEL_COLLAPSED(localState, false); + + expect(localState.leftPanelCollapsed).toBeFalsy(); + }); + }); + + describe('SET_RIGHT_PANEL_COLLAPSED', () => { + it('sets right panel collapsed', () => { + mutations.SET_RIGHT_PANEL_COLLAPSED(localState, true); + + expect(localState.rightPanelCollapsed).toBeTruthy(); + + mutations.SET_RIGHT_PANEL_COLLAPSED(localState, false); - expect(localState.previousUrl).toBe('testing'); + expect(localState.rightPanelCollapsed).toBeFalsy(); }); }); }); diff --git a/spec/javascripts/repo/stores/utils_spec.js b/spec/javascripts/repo/stores/utils_spec.js index 37287c587d7..89745a2029e 100644 --- a/spec/javascripts/repo/stores/utils_spec.js +++ b/spec/javascripts/repo/stores/utils_spec.js @@ -1,4 +1,6 @@ -import * as utils from '~/repo/stores/utils'; +import * as utils from '~/ide/stores/utils'; +import state from '~/ide/stores/state'; +import { file } from '../helpers'; describe('Multi-file store utils', () => { describe('setPageTitle', () => { @@ -9,13 +11,28 @@ describe('Multi-file store utils', () => { }); }); - describe('pushState', () => { - it('calls history.pushState', () => { - spyOn(history, 'pushState'); + describe('treeList', () => { + let localState; - utils.pushState('test'); + beforeEach(() => { + localState = state(); + }); + + it('returns flat tree list', () => { + localState.trees = []; + localState.trees['abcproject/mybranch'] = { + tree: [], + }; + const baseTree = localState.trees['abcproject/mybranch'].tree; + baseTree.push(file('1')); + baseTree[0].tree.push(file('2')); + baseTree[0].tree[0].tree.push(file('3')); + + const treeList = utils.treeList(localState, 'abcproject/mybranch'); - expect(history.pushState).toHaveBeenCalledWith({ url: 'test' }, '', 'test'); + expect(treeList.length).toBe(3); + expect(treeList[1].name).toBe(baseTree[0].tree[0].name); + expect(treeList[2].name).toBe(baseTree[0].tree[0].tree[0].name); }); }); @@ -52,10 +69,10 @@ describe('Multi-file store utils', () => { }); describe('findIndexOfFile', () => { - let state; + let localState; beforeEach(() => { - state = [{ + localState = [{ path: '1', }, { path: '2', @@ -63,7 +80,7 @@ describe('Multi-file store utils', () => { }); it('finds in the index of an entry by path', () => { - const index = utils.findIndexOfFile(state, { + const index = utils.findIndexOfFile(localState, { path: '2', }); @@ -72,10 +89,10 @@ describe('Multi-file store utils', () => { }); describe('findEntry', () => { - let state; + let localState; beforeEach(() => { - state = { + localState = { tree: [{ type: 'tree', name: 'test', @@ -87,14 +104,14 @@ describe('Multi-file store utils', () => { }); it('returns an entry found by name', () => { - const foundEntry = utils.findEntry(state, 'tree', 'test'); + const foundEntry = utils.findEntry(localState.tree, 'tree', 'test'); expect(foundEntry.type).toBe('tree'); expect(foundEntry.name).toBe('test'); }); it('returns undefined when no entry found', () => { - const foundEntry = utils.findEntry(state, 'blob', 'test'); + const foundEntry = utils.findEntry(localState.tree, 'blob', 'test'); expect(foundEntry).toBeUndefined(); }); diff --git a/yarn.lock b/yarn.lock index 55d0d33c9f2..26e2b790f98 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6528,6 +6528,10 @@ vue-resource@^1.3.4: dependencies: got "^7.0.0" +vue-router@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" + vue-style-loader@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7" -- cgit v1.2.1 From e1f5c2b194fa8ee898446517f1802c6e28312b0b Mon Sep 17 00:00:00 2001 From: Mario de la Ossa Date: Mon, 18 Dec 2017 17:08:28 -0600 Subject: Do not show Vue pagination if only one page --- .../vue_shared/components/table_pagination.vue | 8 +++++++- changelogs/unreleased/33609-hide-pagination.yml | 5 +++++ .../vue_shared/components/table_pagination_spec.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/33609-hide-pagination.yml diff --git a/app/assets/javascripts/vue_shared/components/table_pagination.vue b/app/assets/javascripts/vue_shared/components/table_pagination.vue index 710452bb3d3..33096b53cf8 100644 --- a/app/assets/javascripts/vue_shared/components/table_pagination.vue +++ b/app/assets/javascripts/vue_shared/components/table_pagination.vue @@ -122,11 +122,17 @@ export default { return items; }, + showPagination() { + return this.pageInfo.totalPages > 1; + }, }, };