From d59aed94e7ec441f44301a55e0529a9c34a01fd2 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 10 Aug 2017 13:05:04 -0500 Subject: Move syntax highlighting into a method Fix https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37142936 --- app/assets/javascripts/repo/components/repo_preview.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/repo/components/repo_preview.vue b/app/assets/javascripts/repo/components/repo_preview.vue index d8de022335b..0caa3a4551a 100644 --- a/app/assets/javascripts/repo/components/repo_preview.vue +++ b/app/assets/javascripts/repo/components/repo_preview.vue @@ -4,7 +4,7 @@ import Store from '../stores/repo_store'; export default { data: () => Store, mounted() { - $(this.$el).find('.file-content').syntaxHighlight(); + this.highlightFile(); }, computed: { html() { @@ -12,10 +12,16 @@ export default { }, }, + methods: { + highlightFile() { + $(this.$el).find('.file-content').syntaxHighlight(); + }, + }, + watch: { html() { this.$nextTick(() => { - $(this.$el).find('.file-content').syntaxHighlight(); + this.highlightFile(); }); }, }, -- cgit v1.2.1 From 06c330954e030e30e9e8284110907c53b206e447 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 10 Aug 2017 13:09:01 -0500 Subject: Use v-else instead of duplicating logic Fix http://192.168.1.135:3000/gitlab-org/gitlab-ce/blob/master/app/assets/javascripts/broadcast_message.js --- .../javascripts/repo/components/repo_preview.vue | 20 +++++++++++++++++--- app/assets/javascripts/repo/helpers/repo_helper.js | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/repo/components/repo_preview.vue b/app/assets/javascripts/repo/components/repo_preview.vue index 0caa3a4551a..2200754cbef 100644 --- a/app/assets/javascripts/repo/components/repo_preview.vue +++ b/app/assets/javascripts/repo/components/repo_preview.vue @@ -30,9 +30,23 @@ export default { diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js index fee98c12592..b12ea92c17a 100644 --- a/app/assets/javascripts/repo/helpers/repo_helper.js +++ b/app/assets/javascripts/repo/helpers/repo_helper.js @@ -190,7 +190,7 @@ const RepoHelper = { newFile.url = file.url || location.pathname; newFile.url = file.url; - if (newFile.render_error === 'too_large') { + if (newFile.render_error === 'too_large' || newFile.render_error === 'collapsed') { newFile.tooLarge = true; } newFile.newContent = ''; -- cgit v1.2.1 From f1e1113bf4d107c0ecf3f989f6110b00a83cef2d Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 10 Aug 2017 13:50:59 -0500 Subject: Split out linkClicked and add tests Fix https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37143174 --- .../javascripts/repo/components/repo_sidebar.vue | 45 ++++++++++---------- .../repo/components/repo_sidebar_spec.js | 48 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue index d6d832efc49..ccc84c4ed7c 100644 --- a/app/assets/javascripts/repo/components/repo_sidebar.vue +++ b/app/assets/javascripts/repo/components/repo_sidebar.vue @@ -33,32 +33,29 @@ const RepoSidebar = { }); }, - linkClicked(clickedFile) { - let url = ''; + fileClicked(clickedFile) { let file = clickedFile; - if (typeof file === 'object') { - file.loading = true; - if (file.type === 'tree' && file.opened) { - file = Store.removeChildFilesOfTree(file); + + file.loading = true; + if (file.type === 'tree' && file.opened) { + file = Store.removeChildFilesOfTree(file); + file.loading = false; + } else { + Service.url = file.url; + // I need to refactor this to do the `then` here. + // Not a callback. For now this is good enough. + // it works. + Helper.getContent(file, () => { file.loading = false; - } else { - url = file.url; - Service.url = url; - // I need to refactor this to do the `then` here. - // Not a callback. For now this is good enough. - // it works. - Helper.getContent(file, () => { - file.loading = false; - Helper.scrollTabsRight(); - }); - } - } else if (typeof file === 'string') { - // go back - url = file; - Service.url = url; - Helper.getContent(null, () => Helper.scrollTabsRight()); + Helper.scrollTabsRight(); + }); } }, + + goToPreviousDirectoryClicked(prevURL) { + Service.url = prevURL; + Helper.getContent(null, () => Helper.scrollTabsRight()); + }, }, }; @@ -82,7 +79,7 @@ export default RepoSidebar; + @linkclicked="goToPreviousDirectoryClicked(prevURL)"/> diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js index 0d216c9c026..e8bc8a62240 100644 --- a/spec/javascripts/repo/components/repo_sidebar_spec.js +++ b/spec/javascripts/repo/components/repo_sidebar_spec.js @@ -1,4 +1,6 @@ import Vue from 'vue'; +import Helper from '~/repo/helpers/repo_helper'; +import RepoService from '~/repo/services/repo_service'; import RepoStore from '~/repo/stores/repo_store'; import repoSidebar from '~/repo/components/repo_sidebar.vue'; @@ -58,4 +60,50 @@ describe('RepoSidebar', () => { expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy(); }); + + describe('methods', () => { + describe('fileClicked', () => { + it('should fetch data for new file', () => { + spyOn(Helper, 'getContent'); + const file1 = { + id: 0, + }; + RepoStore.files = [file1]; + RepoStore.isRoot = true; + const vm = createComponent(); + + vm.fileClicked(file1); + + expect(Helper.getContent).toHaveBeenCalledWith(file1, jasmine.any(Function)); + }); + + it('should hide files in directory if already open', () => { + spyOn(RepoStore, 'removeChildFilesOfTree').and.callThrough(); + const file1 = { + id: 0, + type: 'tree', + url: '', + opened: true, + }; + RepoStore.files = [file1]; + RepoStore.isRoot = true; + const vm = createComponent(); + + vm.fileClicked(file1); + + expect(RepoStore.removeChildFilesOfTree).toHaveBeenCalledWith(file1); + }); + }); + + describe('goToPreviousDirectoryClicked', () => { + it('should hide files in directory if already open', () => { + const prevUrl = 'foo/bar'; + const vm = createComponent(); + + vm.goToPreviousDirectoryClicked(prevUrl); + + expect(RepoService.url).toEqual(prevUrl); + }); + }); + }); }); -- cgit v1.2.1 From ecb7c534f60f89a57468148f543a6895692b6081 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 10 Aug 2017 14:01:32 -0500 Subject: Use promise syntax with Helper.getContent Fix https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37143217 --- app/assets/javascripts/repo/components/repo_sidebar.vue | 17 +++++++++-------- app/assets/javascripts/repo/helpers/repo_helper.js | 3 +-- spec/javascripts/repo/components/repo_sidebar_spec.js | 5 +++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue index ccc84c4ed7c..0d4f8c6635e 100644 --- a/app/assets/javascripts/repo/components/repo_sidebar.vue +++ b/app/assets/javascripts/repo/components/repo_sidebar.vue @@ -42,19 +42,20 @@ const RepoSidebar = { file.loading = false; } else { Service.url = file.url; - // I need to refactor this to do the `then` here. - // Not a callback. For now this is good enough. - // it works. - Helper.getContent(file, () => { - file.loading = false; - Helper.scrollTabsRight(); - }); + Helper.getContent(file) + .then(() => { + file.loading = false; + Helper.scrollTabsRight(); + }) + .catch(Helper.loadingError); } }, goToPreviousDirectoryClicked(prevURL) { Service.url = prevURL; - Helper.getContent(null, () => Helper.scrollTabsRight()); + Helper.getContent(null) + .then(() => Helper.scrollTabsRight()) + .catch(Helper.loadingError); }, }, }; diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js index b12ea92c17a..308ede5fba0 100644 --- a/app/assets/javascripts/repo/helpers/repo_helper.js +++ b/app/assets/javascripts/repo/helpers/repo_helper.js @@ -135,14 +135,13 @@ const RepoHelper = { return isRoot; }, - getContent(treeOrFile, cb) { + getContent(treeOrFile) { let file = treeOrFile; // const loadingData = RepoHelper.setLoading(true); return Service.getContent() .then((response) => { const data = response.data; // RepoHelper.setLoading(false, loadingData); - if (cb) cb(); Store.isTree = RepoHelper.isTree(data); if (!Store.isTree) { if (!file) file = data; diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js index e8bc8a62240..edd27d3afb8 100644 --- a/spec/javascripts/repo/components/repo_sidebar_spec.js +++ b/spec/javascripts/repo/components/repo_sidebar_spec.js @@ -64,9 +64,10 @@ describe('RepoSidebar', () => { describe('methods', () => { describe('fileClicked', () => { it('should fetch data for new file', () => { - spyOn(Helper, 'getContent'); + spyOn(Helper, 'getContent').and.callThrough(); const file1 = { id: 0, + url: '', }; RepoStore.files = [file1]; RepoStore.isRoot = true; @@ -74,7 +75,7 @@ describe('RepoSidebar', () => { vm.fileClicked(file1); - expect(Helper.getContent).toHaveBeenCalledWith(file1, jasmine.any(Function)); + expect(Helper.getContent).toHaveBeenCalledWith(file1); }); it('should hide files in directory if already open', () => { -- cgit v1.2.1 From a081a60d89af1f05a8f6f243e073a96e35b2b349 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 10 Aug 2017 14:17:38 -0500 Subject: Make close/changed icon more accessible Fix https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37143527 --- app/assets/javascripts/repo/components/repo_tab.vue | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/repo/components/repo_tab.vue b/app/assets/javascripts/repo/components/repo_tab.vue index 712d64c236f..b6a9948f487 100644 --- a/app/assets/javascripts/repo/components/repo_tab.vue +++ b/app/assets/javascripts/repo/components/repo_tab.vue @@ -10,6 +10,12 @@ const RepoTab = { }, computed: { + closeLabel() { + if (this.tab.changed) { + return `${this.tab.name} changed`; + } + return `Close ${this.tab.name}`; + }, changedClass() { const tabChangedObj = { 'fa-times': !this.tab.changed, @@ -34,8 +40,17 @@ export default RepoTab;