From 9738703424786f5105e5539a198e36af16ed18e0 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 4 May 2016 09:32:59 +0100 Subject: [PATCH] If image preview fails to load, just show the "no preview" message --- services/web/app/views/project/editor/binary-file.jade | 8 +++++++- .../binary-files/controllers/BinaryFileController.coffee | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/services/web/app/views/project/editor/binary-file.jade b/services/web/app/views/project/editor/binary-file.jade index ca25a6d806..6e81c7a107 100644 --- a/services/web/app/views/project/editor/binary-file.jade +++ b/services/web/app/views/project/editor/binary-file.jade @@ -4,15 +4,21 @@ div.binary-file.full-size( ng-if="openFile" ) img( + ng-show="!failedLoad" ng-src="/project/{{ project_id }}/file/{{ openFile.id }}" ng-if="['png', 'jpg', 'jpeg', 'gif'].indexOf(extension(openFile)) > -1" + onerror="sl_binaryFilePreviewError()" + onabort="sl_binaryFilePreviewError()" ) img( + ng-show="!failedLoad" ng-src="/project/{{ project_id }}/file/{{ openFile.id }}?format=png" ng-if="['pdf', 'eps'].indexOf(extension(openFile)) > -1" + onerror="sl_binaryFilePreviewError()" + onabort="sl_binaryFilePreviewError()" ) p.no-preview( - ng-if="['png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1" + ng-if="failedLoad || ['png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1" ) #{translate("no_preview_available")} a.btn.btn-info( ng-href="/project/{{ project_id }}/file/{{ openFile.id }}" diff --git a/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee b/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee index 5dcabe8000..29da05259c 100644 --- a/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee +++ b/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee @@ -2,6 +2,13 @@ define [ "base" ], (App) -> App.controller "BinaryFileController", ["$scope", ($scope) -> + + $scope.failedLoad = false + + window.sl_binaryFilePreviewError = () => + $scope.failedLoad = true + $scope.$apply() + $scope.extension = (file) -> return file.name.split(".").pop()?.toLowerCase() - ] \ No newline at end of file + ]