Skip to content

Commit cdca91a

Browse files
committed
html previews in new files
test plan: - the new files preview should show HTML files uploaded to course/user files (note that relative links in downloaded HTML will break; this is an expected consequence of previewing a bare HTML file) fixes CNVS-20110 Change-Id: I77725865668284f02cf72fa8e7ea12e9b69c7954 Reviewed-on: https://gerrit.instructure.com/53264 Reviewed-by: James Williams <jamesw@instructure.com> Tested-by: Jenkins QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
1 parent 63f4f22 commit cdca91a

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

app/coffeescripts/react_files/components/FilePreview.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ define [
203203
allowFullScreen: true
204204
title: I18n.t('File Preview')
205205
src: @state.displayedItem.get 'preview_url'
206-
className: 'ef-file-preview-frame'
206+
className: 'ef-file-preview-frame' + if @state.displayedItem.get('content-type') is 'text/html' then ' ef-file-preview-frame-html' else ''
207207
}
208208
else # file was not found
209209
div className: 'ef-file-not-found ef-file-preview-frame',

app/controllers/file_previews_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def show
8080
# media files
8181
elsif @file.content_type =~ %r{\A(audio|video)/}
8282
return render template: 'file_previews/media_preview', layout: false
83+
# html files
84+
elsif @file.content_type == 'text/html'
85+
return redirect_to context_url(@context, :context_file_preview_url, @file.id)
8386
# no preview available
8487
else
8588
@accessed_asset = nil # otherwise it will double-log when they download the file

app/stylesheets/pages/react_files/_FilePreview.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $preview-font-color: $ic-color-light;
88
$spacing-width: 0;
99
$preview-footer-height: 140px;
1010
$preview-header-height: 9vh;
11+
$preview-html-background: whitesmoke;
1112

1213
.ReactModal__Overlay.ReactModal__Overlay--ef-file-preview {
1314
background: rgba(black, 0.9);
@@ -248,3 +249,8 @@ a.ef-file-preview-button, button.ef-file-preview-button div {
248249
.FilePreviewInfoPanel__usageRights {
249250
vertical-align: top;
250251
}
252+
253+
// so previews of unstyled HTML will not feature black-on-black text
254+
.ef-file-preview-frame-html {
255+
background-color: $preview-html-background;
256+
}

spec/controllers/file_previews_controller_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@
7777
expect(response.location).to match %r{\A//docs.google.com/viewer}
7878
end
7979

80+
it "should redirect to file if it's html" do
81+
Attachment.any_instance.stubs(:crocodoc_url).returns(nil)
82+
Attachment.any_instance.stubs(:canvadoc_url).returns(nil)
83+
attachment_model content_type: 'text/html'
84+
get :show, course_id: @course.id, file_id: @attachment.id
85+
expect(response).to be_redirect
86+
expect(response.location).to match %r{/courses/#{@course.id}/files/#{@attachment.id}/preview}
87+
end
88+
8089
it "should render a download link if no previews are available" do
8190
Attachment.any_instance.stubs(:crocodoc_url).returns(nil)
8291
Attachment.any_instance.stubs(:canvadoc_url).returns(nil)

0 commit comments

Comments
 (0)