From 2d15c3fd7591a9cba94fadb6c49be03a4b9f9f31 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 6 Aug 2021 16:31:15 +0000 Subject: [PATCH] Bug 25025: Drag-and-drop cover image upload This patch updates the Upload local cover image page so that the user has the option of dragging a file from a folder on their computer instead of using a file upload button. The patch also adds a preview of uploaded single images and display of existing images on the record you're adding to. To test, apply the patch and make sure the LocalCoverImages system preference is enabled. - Go to Tools -> Upload local cover image and test the following processes: - Upload single cover image, specifying a biblionumber - Test dragging an image from a file on your computer - Test clicking the "Drop files here or click..." link. - You should see a preview of the image file on the screen, with information about the file: file name, image type, file size. - Click "Process images" - with "Existing covers will be replaced" checked - with "Existing covers will be replaced" unchecked When the upload process completes you should see information about the title in the page heading and a thumbnail of the cover in the sidebar. - Test that the image can be deleted from this page. You should be redirected back to this page with the same title still selected. - Upload a zip file of images - Test dragging an image from a file on your computer - Test clicking the "Drop files here or click..." link. - A zip file can't be previewed onscreen but you should see the same file information and a Font Awesome "zip file" icon. - Click "Process images" From the bibliographic detail page, click the "Images" tab, and click "Upload." With this workflow the field asking for a biblionumber should not appear. Test with AllowMultipleCovers enabled and disabled to confirm that the "Existing covers will be replaced" checkbox is enabled only when multiple covers are possible. --- .../prog/en/modules/tools/upload-images.tt | 571 +++++++++++++----- tools/upload-cover-image.pl | 45 +- 2 files changed, 466 insertions(+), 150 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt index 506187271b..08a718a268 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt @@ -2,11 +2,77 @@ [% USE Asset %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] -Upload images › Tools › Koha + + Koha › + Tools › + Upload local cover image + [% IF ( biblio ) %] + › [% INCLUDE 'biblio-title-head.inc' %] + [% END %] + [% INCLUDE 'doc-head-close.inc' %] - +[% FILTER collapse %] + +[% END %] @@ -21,29 +87,28 @@
  • Tools
  • +
  • + Upload local cover image +
  • [% IF ( uploadimage ) %] -
  • - Upload local cover image -
  • Upload results
  • + [% IF ( biblionumber ) %] +
  • + [% INCLUDE 'biblio-title.inc' %] +
  • + [% END %] [% ELSIF itemnumber %] -
  • - Upload local cover image -
  • Upload cover for itemnumber: [% itemnumber | html %]
  • [% ELSIF biblionumber %] -
  • - Upload local cover image -
  • Upload cover for biblionumber: [% biblionumber | html %] @@ -64,43 +129,46 @@
    - [% IF ( uploadimage ) %] -

    Image upload results :

    -
    -
    - [% END # /IF uploadimage %] - [% UNLESS itemnumber || biblionumber %]

    Upload local cover image

    [% ELSIF itemnumber %]

    Upload local cover image for itemnumber: [% itemnumber | html %]

    - [% ELSIF biblionumber %] -

    Upload local cover image for biblionumber: [% biblionumber | html %]

    + [% ELSIF biblio %] +

    + Upload local cover image for [% INCLUDE 'biblio-title.inc' %] +

    [% END %] + [% IF ( uploadimage ) %] +

    Image upload results :

    +
    + [% IF ( error ) %] +
    + [% IF ( error == 'UZIPFAIL' ) %] +

    Failed to unzip archive.
    Please ensure you are uploading a valid zip file and try again.

    + [% ELSIF ( error == 'OPNLINK' ) %] +

    Cannot open folder index (idlink.txt or datalink.txt) to read.
    Please verify that it exists.

    + [% ELSIF ( error == 'OPNIMG' ) %] +

    Cannot process file as an image.
    Please ensure you only upload GIF, JPEG, PNG, or XPM images.

    + [% ELSIF ( error == 'DELERR' ) %] +

    Unrecognized or missing field delimiter.
    Please verify that you are using either a single quote or a tab.

    + [% ELSIF ( error == 'DBERR' ) %] +

    Unable to save image to database.

    + [% ELSE %] +

    An unknown error has occurred.
    Please review the error log for more details.

    + [% END %] +
    + [% END # /IF error %] +

    [% total | html %] images found

    + +
    +
    + [% END # /IF uploadimage %] +
      [% UNLESS itemnumber || biblionumber %]
    • Select an image file or ZIP file to upload. The tool will accept images in GIF, JPEG, PNG, and XPM formats.
    • @@ -109,91 +177,121 @@ [% END %]
    -
    -
    - Upload images -
      -
    1. +
      + [% IF ( cover_images ) %] +
      + [% ELSE %] +
      + [% END %] + + +
      - - - Required + +
      -
    2. -
    -
    -
    - -
    -
    Upload progress: - - - 0% -
    -
    -
    -
    - -
    - - - - [% UNLESS itemnumber || biblionumber %] -
    - File type -
      -
    1. - [% IF (filetype != 'image' ) %] - - [% ELSE %] - - [% END %] - -
    2. -
    3. - [% IF (filetype == 'image' ) %] - - [% ELSE %] - - [% END %] - -
    4. -
    5. - [% IF ( filetype == 'image' ) %] - - [% ELSE %] -
    +
    + +
    + + + + + [% IF itemnumber %] + + + [% ELSIF biblionumber %] + + + [% END %] + + +
    +
      + [% UNLESS itemnumber || biblionumber %] +
    1. + [% IF (filetype != 'image' ) %] + + [% ELSE %] + + [% END %] + +
    2. +
    3. + [% IF (filetype == 'image' ) %] + + [% ELSE %] + + [% END %] + +
    4. +
    5. + + +
    6. [% END %] - - - -
    -
    - [% ELSIF itemnumber %] - - - [% ELSIF biblionumber %] - - - [% END %] -
    - Options -
      -
    1. - [% IF AllowMultipleCovers == 0 %] - +
    2. +
    3. +
    +
    + +
    + + [% IF ( biblionumber ) %] + Cancel [% ELSE %] - + Cancel [% END %] - -
  • - - -
    - -
    - + + + + [% IF ( cover_images.size ) %] +
    +

    Existing images

    + +
    + [% END # /IF images.size %] + + @@ -206,20 +304,115 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/tools-menu.js") | $raw %] - [% Asset.js("js/file-upload.js") | $raw %] [% END %] diff --git a/tools/upload-cover-image.pl b/tools/upload-cover-image.pl index f55d8f128d..734a54e033 100755 --- a/tools/upload-cover-image.pl +++ b/tools/upload-cover-image.pl @@ -75,13 +75,28 @@ my $sessionID = $cookies{'CGISESSID'}->value; my $error; +my $biblio; +my $cover_images; +my $item; + +if ( $itemnumber ) { + $item = Koha::Items->find($itemnumber); + $cover_images = $item->cover_images->as_list; +} elsif ( $biblionumber ){ + $biblio = Koha::Biblios->find( $biblionumber ); + $cover_images = $biblio->cover_images->as_list; +} + $template->param( filetype => $filetype, + biblio => $biblio, biblionumber => $biblionumber, itemnumber => $itemnumber, + cover_images => $cover_images, ); my $total = 0; +my @results; if ($fileID) { my $upload = Koha::UploadedFiles->find( $fileID ); @@ -175,6 +190,11 @@ if ($fileID) { logaction('CATALOGUING', 'MODIFY', $biblionumber, "biblio cover image: $filename"); } my $srcimage = GD::Image->new("$dir/$filename"); + my $biblio = Koha::Biblios->find( $biblionumber ); + push @results, { + biblionumber => $biblionumber, + title => $biblio->title + }; if ( defined $srcimage ) { $total++; eval { @@ -213,14 +233,23 @@ if ($fileID) { } } } - - $template->param( - total => $total, - uploadimage => 1, - error => $error, - biblionumber => $biblionumber || Koha::Items->find($itemnumber)->biblionumber, - itemnumber => $itemnumber, - ); + if( $error ){ + $template->param( + total => $total, + uploadimage => 1, + error => $error, + biblionumber => $biblionumber || Koha::Items->find($itemnumber)->biblionumber, + itemnumber => $itemnumber, + ); + } elsif ( @results ){ + $template->param( + total => $total, + uploadimage => 1, + results => \@results + ); + } else { + print $input->redirect("/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=$biblionumber"); + } } output_html_with_http_headers $input, $cookie, $template->output; -- 2.20.1