Commit 860265ab authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 687ccb43 712a63a7
...@@ -57,6 +57,8 @@ export default { ...@@ -57,6 +57,8 @@ export default {
type: 'blob', type: 'blob',
content: result, content: result,
base64: !isText, base64: !isText,
binary: !isText,
rawPath: !isText ? target.result : '',
}); });
}, },
readFile(file) { readFile(file) {
......
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import flash from '~/flash'; import flash from '~/flash';
import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
...@@ -56,6 +57,10 @@ export default { ...@@ -56,6 +57,10 @@ export default {
active: this.file.viewMode === 'preview', active: this.file.viewMode === 'preview',
}; };
}, },
fileType() {
const info = viewerInformationForPath(this.file.path);
return (info && info.id) || '';
},
}, },
watch: { watch: {
file(newVal, oldVal) { file(newVal, oldVal) {
...@@ -258,6 +263,7 @@ export default { ...@@ -258,6 +263,7 @@ export default {
:path="file.rawPath || file.path" :path="file.rawPath || file.path"
:file-size="file.size" :file-size="file.size"
:project-path="file.projectId" :project-path="file.projectId"
:type="fileType"
/> />
<diff-viewer <diff-viewer
v-if="showDiffViewer" v-if="showDiffViewer"
......
...@@ -22,6 +22,8 @@ export const decorateFiles = ({ ...@@ -22,6 +22,8 @@ export const decorateFiles = ({
tempFile = false, tempFile = false,
content = '', content = '',
base64 = false, base64 = false,
binary = false,
rawPath = '',
}) => { }) => {
const treeList = []; const treeList = [];
const entries = {}; const entries = {};
...@@ -90,6 +92,8 @@ export const decorateFiles = ({ ...@@ -90,6 +92,8 @@ export const decorateFiles = ({
changed: tempFile, changed: tempFile,
content, content,
base64, base64,
binary,
rawPath,
previewMode: viewerInformationForPath(name), previewMode: viewerInformationForPath(name),
parentPath, parentPath,
}); });
......
...@@ -53,7 +53,7 @@ export const setResizingStatus = ({ commit }, resizing) => { ...@@ -53,7 +53,7 @@ export const setResizingStatus = ({ commit }, resizing) => {
export const createTempEntry = ( export const createTempEntry = (
{ state, commit, dispatch }, { state, commit, dispatch },
{ name, type, content = '', base64 = false }, { name, type, content = '', base64 = false, binary = false, rawPath = '' },
) => ) =>
new Promise(resolve => { new Promise(resolve => {
const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name; const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name;
...@@ -79,8 +79,10 @@ export const createTempEntry = ( ...@@ -79,8 +79,10 @@ export const createTempEntry = (
branchId: state.currentBranchId, branchId: state.currentBranchId,
type, type,
tempFile: true, tempFile: true,
base64,
content, content,
base64,
binary,
rawPath,
}); });
const { file, parentPath } = data; const { file, parentPath } = data;
......
...@@ -69,6 +69,8 @@ export const decorateData = entity => { ...@@ -69,6 +69,8 @@ export const decorateData = entity => {
changed = false, changed = false,
parentTreeUrl = '', parentTreeUrl = '',
base64 = false, base64 = false,
binary = false,
rawPath = '',
previewMode, previewMode,
file_lock, file_lock,
html, html,
...@@ -92,6 +94,8 @@ export const decorateData = entity => { ...@@ -92,6 +94,8 @@ export const decorateData = entity => {
renderError, renderError,
content, content,
base64, base64,
binary,
rawPath,
previewMode, previewMode,
file_lock, file_lock,
html, html,
......
<script> <script>
import { viewerInformationForPath } from './lib/viewer_utils';
import MarkdownViewer from './viewers/markdown_viewer.vue'; import MarkdownViewer from './viewers/markdown_viewer.vue';
import ImageViewer from './viewers/image_viewer.vue'; import ImageViewer from './viewers/image_viewer.vue';
import DownloadViewer from './viewers/download_viewer.vue'; import DownloadViewer from './viewers/download_viewer.vue';
...@@ -24,15 +23,18 @@ export default { ...@@ -24,15 +23,18 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
type: {
type: String,
required: false,
default: '',
},
}, },
computed: { computed: {
viewer() { viewer() {
if (!this.path) return null; if (!this.path) return null;
if (!this.type) return DownloadViewer;
const previewInfo = viewerInformationForPath(this.path); switch (this.type) {
if (!previewInfo) return DownloadViewer;
switch (previewInfo.id) {
case 'markdown': case 'markdown':
return MarkdownViewer; return MarkdownViewer;
case 'image': case 'image':
......
...@@ -58,12 +58,11 @@ export default { ...@@ -58,12 +58,11 @@ export default {
const moveX = e.pageX || e.touches[0].pageX; const moveX = e.pageX || e.touches[0].pageX;
let leftValue = moveX - this.$refs.swipeFrame.getBoundingClientRect().left; let leftValue = moveX - this.$refs.swipeFrame.getBoundingClientRect().left;
const spaceLeft = 20;
const { clientWidth } = this.$refs.swipeFrame; const { clientWidth } = this.$refs.swipeFrame;
if (leftValue <= 0) { if (leftValue <= 0) {
leftValue = 0; leftValue = 0;
} else if (leftValue > clientWidth - spaceLeft) { } else if (leftValue > clientWidth) {
leftValue = clientWidth - spaceLeft; leftValue = clientWidth;
} }
this.swipeWrapWidth = (leftValue / clientWidth) * 100; this.swipeWrapWidth = (leftValue / clientWidth) * 100;
...@@ -80,7 +79,7 @@ export default { ...@@ -80,7 +79,7 @@ export default {
document.body.removeEventListener('touchmove', this.dragMove); document.body.removeEventListener('touchmove', this.dragMove);
}, },
prepareSwipe() { prepareSwipe() {
if (this.swipeOldImgInfo && this.swipeNewImgInfo) { if (this.swipeOldImgInfo && this.swipeNewImgInfo && this.swipeOldImgInfo.renderedWidth > 0) {
// Add 2 for border width // Add 2 for border width
this.swipeMaxWidth = this.swipeMaxWidth =
Math.max(this.swipeOldImgInfo.renderedWidth, this.swipeNewImgInfo.renderedWidth) + 2; Math.max(this.swipeOldImgInfo.renderedWidth, this.swipeNewImgInfo.renderedWidth) + 2;
...@@ -101,6 +100,8 @@ export default { ...@@ -101,6 +100,8 @@ export default {
}, },
resize: _.throttle(function throttledResize() { resize: _.throttle(function throttledResize() {
this.swipeBarPos = 0; this.swipeBarPos = 0;
this.swipeWrapWidth = 0;
this.prepareSwipe();
}, 400), }, 400),
}, },
}; };
...@@ -111,6 +112,8 @@ export default { ...@@ -111,6 +112,8 @@ export default {
<div <div
ref="swipeFrame" ref="swipeFrame"
:style="{ :style="{
width: swipeMaxPixelWidth,
height: swipeMaxPixelHeight,
'user-select': dragging ? 'none' : null, 'user-select': dragging ? 'none' : null,
}" }"
class="swipe-frame" class="swipe-frame"
......
---
title: "Fix misaligned image diff swipe view"
merge_request: 26969
author: ftab
type: fixed
---
title: Show proper preview for uploaded images in Web IDE
merge_request: 27471
author:
type: fixed
...@@ -191,29 +191,119 @@ describe 'Merge request > User creates image diff notes', :js do ...@@ -191,29 +191,119 @@ describe 'Merge request > User creates image diff notes', :js do
end end
end end
describe 'image view modes' do shared_examples 'swipe view' do
before do it 'moves the swipe handle' do
visit project_commit_path(project, '2f63565e7aac07bcdadb654e253078b727143ec4') # Simulate dragging swipe view slider
expect { drag_and_drop_by(find('.swipe-bar'), 20, 0) }
.to change { find('.swipe-bar')['style'] }
.from(a_string_matching('left: 1px'))
end end
it 'resizes image in onion skin view mode' do it 'shows both images at the same position' do
find('.view-modes-menu .onion-skin').click drag_and_drop_by(find('.swipe-bar'), 40, 0)
expect(find('.onion-skin-frame')['style']).to match('width: 228px; height: 240px;') expect(left_position('.frame.added img'))
.to eq(left_position('.frame.deleted img'))
end end
end
it 'resets onion skin view mode opacity when toggling between view modes' do shared_examples 'onion skin' do
find('.view-modes-menu .onion-skin').click it 'resets opacity when toggling between view modes' do
# Simulate dragging onion-skin slider # Simulate dragging onion-skin slider
drag_and_drop_by(find('.dragger'), -30, 0) drag_and_drop_by(find('.dragger'), -30, 0)
expect(find('.onion-skin-frame .frame.added', visible: false)['style']).not_to match('opacity: 1;') expect(find('.onion-skin-frame .frame.added', visible: false)['style']).not_to match('opacity: 1;')
switch_to_swipe_view
switch_to_onion_skin
expect(find('.onion-skin-frame .frame.added', visible: false)['style']).to match('opacity: 1;')
end
end
describe 'changes tab image diff' do
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, target_branch: 'master', source_branch: 'deleted-image-test', author: user) }
before do
visit diffs_project_merge_request_path(project, merge_request)
click_link "Changes"
end
def set_image_diff_sources
# set path of added and deleted images to something the spec can view
page.execute_script("document.querySelector('.frame.added img').src = '/apple-touch-icon.png';")
page.execute_script("document.querySelector('.frame.deleted img').src = '/favicon.png';")
wait_for_requests
expect(find('.frame.added img', visible: false)['src']).to match('/apple-touch-icon.png')
expect(find('.frame.deleted img', visible: false)['src']).to match('/favicon.png')
end
def switch_to_swipe_view
# it isn't given the .swipe class in the merge request diff
find('.view-modes-menu li:nth-child(2)').click
expect(find('.view-modes-menu li.active')).to have_content('Swipe')
set_image_diff_sources
end
def switch_to_onion_skin
# it isn't given the .onion-skin class in the merge request diff
find('.view-modes-menu li:nth-child(3)').click
expect(find('.view-modes-menu li.active')).to have_content('Onion skin')
set_image_diff_sources
end
describe 'onion skin' do
before do
switch_to_onion_skin
end
it_behaves_like 'onion skin'
end
describe 'swipe view' do
before do
switch_to_swipe_view
end
it_behaves_like 'swipe view'
end
end
describe 'image view modes' do
before do
visit project_commit_path(project, '2f63565e7aac07bcdadb654e253078b727143ec4')
end
def switch_to_swipe_view
find('.view-modes-menu .swipe').click find('.view-modes-menu .swipe').click
end
def switch_to_onion_skin
find('.view-modes-menu .onion-skin').click find('.view-modes-menu .onion-skin').click
end
expect(find('.onion-skin-frame .frame.added', visible: false)['style']).to match('opacity: 1;') describe 'onion skin' do
before do
switch_to_onion_skin
end
it 'resizes image' do
expect(find('.onion-skin-frame')['style']).to match('width: 228px; height: 240px;')
end
it_behaves_like 'onion skin'
end
describe 'swipe view' do
before do
switch_to_swipe_view
end
it_behaves_like 'swipe view'
end end
end end
...@@ -232,4 +322,8 @@ describe 'Merge request > User creates image diff notes', :js do ...@@ -232,4 +322,8 @@ describe 'Merge request > User creates image diff notes', :js do
click_button 'Comment' click_button 'Comment'
wait_for_requests wait_for_requests
end end
def left_position(element)
page.evaluate_script("document.querySelectorAll('#{element}')[0].getBoundingClientRect().left;")
end
end end
...@@ -78,6 +78,8 @@ describe('new dropdown upload', () => { ...@@ -78,6 +78,8 @@ describe('new dropdown upload', () => {
type: 'blob', type: 'blob',
content: 'plain text', content: 'plain text',
base64: false, base64: false,
binary: false,
rawPath: '',
}); });
}); });
...@@ -89,6 +91,8 @@ describe('new dropdown upload', () => { ...@@ -89,6 +91,8 @@ describe('new dropdown upload', () => {
type: 'blob', type: 'blob',
content: binaryTarget.result.split('base64,')[1], content: binaryTarget.result.split('base64,')[1],
base64: true, base64: true,
binary: true,
rawPath: binaryTarget.result,
}); });
}); });
}); });
......
...@@ -4,6 +4,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -4,6 +4,7 @@ import axios from '~/lib/utils/axios_utils';
import contentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import contentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants'; import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants';
import '~/behaviors/markdown/render_gfm';
describe('ContentViewer', () => { describe('ContentViewer', () => {
let vm; let vm;
...@@ -29,6 +30,7 @@ describe('ContentViewer', () => { ...@@ -29,6 +30,7 @@ describe('ContentViewer', () => {
path: 'test.md', path: 'test.md',
content: '* Test', content: '* Test',
projectPath: 'testproject', projectPath: 'testproject',
type: 'markdown',
}); });
const previewContainer = vm.$el.querySelector('.md-previewer'); const previewContainer = vm.$el.querySelector('.md-previewer');
...@@ -44,6 +46,7 @@ describe('ContentViewer', () => { ...@@ -44,6 +46,7 @@ describe('ContentViewer', () => {
createComponent({ createComponent({
path: GREEN_BOX_IMAGE_URL, path: GREEN_BOX_IMAGE_URL,
fileSize: 1024, fileSize: 1024,
type: 'image',
}); });
setTimeout(() => { setTimeout(() => {
......
...@@ -138,22 +138,6 @@ describe('ImageDiffViewer', () => { ...@@ -138,22 +138,6 @@ describe('ImageDiffViewer', () => {
done(); done();
}); });
}); });
it('drag handler is working', done => {
vm.$el.querySelector('.view-modes-menu li:nth-child(2)').click();
vm.$nextTick(() => {
expect(vm.$el.querySelector('.swipe-bar').style.left).toBe('1px');
expect(vm.$el.querySelector('.top-handle')).not.toBeNull();
dragSlider(vm.$el.querySelector('.swipe-bar'), 40);
vm.$nextTick(() => {
expect(vm.$el.querySelector('.swipe-bar').style.left).toBe('-20px');
done();
});
});
});
}); });
describe('onionSkin', () => { describe('onionSkin', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment