From 3de4031de1b002207963018f2f2142622a571cc9 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. From the bibliographic detail page, in the holdings table, choose Edit -> Upload image. This process should be the same as above but should provide item information on the screen. Confirm that images are uploaded correctly to the specific item. Test with AllowMultipleCovers enabled and disabled to confirm that the "Existing covers will be replaced" checkbox is enabled only when multiple covers are possible. Signed-off-by: Solène Desvaux Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- .../prog/en/modules/tools/upload-images.tt | 574 +++++++++++++----- tools/upload-cover-image.pl | 66 +- 2 files changed, 487 insertions(+), 153 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..14bba1240b 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,47 @@
    - [% IF ( uploadimage ) %] -

    Image upload results :

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

    Upload local cover image

    + [% ELSIF biblio %] +

    + Upload local cover image for [% INCLUDE 'biblio-title.inc' %] + [% IF ( itemnumber ) %], Item number: [% itemnumber | html %][% END %] +

    [% ELSIF itemnumber %] -

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

    - [% ELSIF biblionumber %] -

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

    +

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

    [% 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 +178,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 +305,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..cf82352abb 100755 --- a/tools/upload-cover-image.pl +++ b/tools/upload-cover-image.pl @@ -75,13 +75,30 @@ my $sessionID = $cookies{'CGISESSID'}->value; my $error; +my $biblio; +my $cover_images; +my $item; + +if ( $itemnumber ) { + $item = Koha::Items->find($itemnumber); + $biblionumber = $item->biblionumber; + $biblio = Koha::Biblios->find( $biblionumber ); + $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,17 +192,37 @@ if ($fileID) { logaction('CATALOGUING', 'MODIFY', $biblionumber, "biblio cover image: $filename"); } my $srcimage = GD::Image->new("$dir/$filename"); + my $biblio; + my $item; if ( defined $srcimage ) { $total++; eval { if ( $replace ) { if ( $biblionumber ) { - Koha::Biblios->find($biblionumber)->cover_images->delete; + $biblio = Koha::Biblios->find( $biblionumber ); + $biblio->cover_images->delete; } elsif ( $itemnumber ) { - Koha::Items->find($itemnumber)->cover_images->delete; + $item = Koha::Items->find($itemnumber); + $item->cover_images->delete; + $biblio = Koha::Biblios->find( $item->{biblionumber} ); + } + } else { + if( $biblionumber ){ + $biblio = Koha::Biblios->find( $biblionumber ); + } elsif ( $itemnumber ){ + $item = Koha::Items->find($itemnumber); + $biblio = Koha::Biblios->find( $item->{biblionumber} ); + } else { + warn "Problem."; } } + push @results, { + biblionumber => $biblionumber, + itemnumber => $itemnumber, + title => $biblio->title + }; + Koha::CoverImage->new( { biblionumber => $biblionumber, @@ -213,14 +250,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&itemnumber=$itemnumber"); + } } output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5