From c5f4a558c6cfe054de3b5d624431444d2cfd2c46 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Wed, 2 Oct 2019 14:09:21 +0200 Subject: [PATCH] Bug 13881: Add desk management MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a desk and linked it to a library (branch). That's it. In the future it'll have super features like being able to link waiting reserve to a specific desk. Test plan: 1. go to the administration page and notice there isn't any mention of desk whatsoever 2. apply patches 3. ./installer/data/mysql/updatedatabase.pl 4. prove t/db_dependent/Koha/Desks.t 5. you now have desks links in admin-home and admin-menu 6. click the link 7. add a desk 8. add another one 9. delete one 10. you should have a fair list of all current desks defined 11. Done Signed-off-by: Séverine QUEUNE Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- Koha/Desk.pm | 45 +++++ Koha/Desks.pm | 56 ++++++ admin/desks.pl | 114 +++++++++++ .../prog/en/includes/admin-menu.inc | 1 + .../prog/en/includes/desks-admin-search.inc | 31 +++ .../prog/en/modules/admin/admin-home.tt | 2 + .../prog/en/modules/admin/desks.tt | 190 ++++++++++++++++++ t/db_dependent/Koha/Desks.t | 60 ++++++ 8 files changed, 499 insertions(+) create mode 100644 Koha/Desk.pm create mode 100644 Koha/Desks.pm create mode 100755 admin/desks.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/desks-admin-search.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt create mode 100644 t/db_dependent/Koha/Desks.t diff --git a/Koha/Desk.pm b/Koha/Desk.pm new file mode 100644 index 0000000000..cd4379d958 --- /dev/null +++ b/Koha/Desk.pm @@ -0,0 +1,45 @@ +package Koha::Desk; + +# Copyright (C) 2020 BULAC +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Desk - Koha Desk Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'Desk'; +} + +1; diff --git a/Koha/Desks.pm b/Koha/Desks.pm new file mode 100644 index 0000000000..a8b452cc7e --- /dev/null +++ b/Koha/Desks.pm @@ -0,0 +1,56 @@ +package Koha::Desks; + +# Copyright (C) 2020 BULAC +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Desk; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Desks - Koha Desk Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'Desk'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Desk'; +} + +1; diff --git a/admin/desks.pl b/admin/desks.pl new file mode 100755 index 0000000000..fb654e9ab1 --- /dev/null +++ b/admin/desks.pl @@ -0,0 +1,114 @@ +#! /usr/bin/perl + +# Copyright (C) 2020 BULAC +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + + +use Modern::Perl; +use CGI qw ( -utf8 ); +use C4::Context; +use C4::Auth; +use C4::Output; + +use Koha::Desks; + +my $input = new CGI; +my $searchfield = $input->param('desk_name') // q||; +my $desk_id = $input->param('desk_id') || ''; +my $op = $input->param('op') || 'list'; +my @messages; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "admin/desks.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => 'manage_desks' }, + debug => 1, + } +); + +my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; + +if ( $op eq 'add_form' ) { + my $desk; + if ($desk_id) { + $desk = Koha::Desks->find($desk_id); + } + + $template->param( desk => $desk, ); +} elsif ( $op eq 'add_validate' ) { + my $desk_id = $input->param('desk_id'); + my $desk_name = $input->param('desk_name'); + my $branchcode = $input->param('branchcode'); + + if (Koha::Desks->find($desk_id)) { + my $desk = Koha::Desks->find($desk_id); + $desk->desk_name($desk_name); + $desk->branchcode($branchcode); + eval { $desk->store; }; + if ($@) { + push @messages, { type => 'error', code => 'error_on_update' }; + } else { + push @messages, { type => 'message', code => 'success_on_update' }; + } + } else { + my $desk = Koha::Desk->new( + { + desk_id => $desk_id, + desk_name => $desk_name, + branchcode => $branchcode, + } + ); + eval { $desk->store; }; + if ($@) { + push @messages, { type => 'error', code => 'error_on_insert' }; + } else { + push @messages, { type => 'message', code => 'success_on_insert' }; + } + } + $searchfield = q||; + $op = 'list'; +} elsif ( $op eq 'delete_confirm' ) { + my $desk = Koha::Desks->find($desk_id); + $template->param( desk => $desk, ); +} elsif ( $op eq 'delete_confirmed' ) { + my $desk = Koha::Desks->find($desk_id); + my $deleted = eval { $desk->delete; }; + + if ( $@ or not $deleted ) { + push @messages, { type => 'error', code => 'error_on_delete' }; + } else { + push @messages, { type => 'message', code => 'success_on_delete' }; + } + $op = 'list'; +} + +if ( $op eq 'list' || ! $op) { + my $desks = Koha::Desks->search( { desk_name => { -like => "%$searchfield%" } } ); + $template->param( desks => $desks, ); +} + +$template->param( + desk_id => $desk_id, + searchfield => $searchfield, + messages => \@messages, + op => $op, + branches => $branches, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index cb98dfe9c0..fd5d5953a6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -16,6 +16,7 @@ [% IF ( CAN_user_parameters_manage_libraries ) %]
  • Libraries
  • Library groups
  • +
  • Desks
  • [% END %] [% IF ( CAN_user_parameters_manage_itemtypes ) %]
  • Item types
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/desks-admin-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/desks-admin-search.inc new file mode 100644 index 0000000000..cde4c70f9a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/desks-admin-search.inc @@ -0,0 +1,31 @@ +[% USE Koha %] +
    +

    [% LibraryName|html %]

    + +
    + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 87522295b9..e23251629f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -63,6 +63,8 @@
    Define libraries.
    Library groups
    Define hierarchical library groups.
    +
    Desks
    +
    Define desks.
    [% END %] [% IF ( CAN_user_parameters_manage_itemtypes ) %]
    Item types
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt new file mode 100644 index 0000000000..6d356212b2 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt @@ -0,0 +1,190 @@ +[% USE raw %] +[% USE Branches %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › [% IF op =='add_form' %]Desks › [% IF desk.desk_id %] Modify desk[% ELSE %] New desk[% END %][% ELSE %][% IF op == 'delete_confirm' %]Desks › Confirm deletion of desk[% ELSE %] Desks[% END %][% END %] +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'desks-admin-search.inc' %] + + + +
    +
    +
    +
    + +[% FOR m IN messages %] +
    + [% SWITCH m.code %] + [% CASE 'error_on_update' %] + An error occurred when updating this desk. Perhaps it already exists. + [% CASE 'error_on_insert' %] + An error occurred when adding this desk. The desk id might already exist. + [% CASE 'error_on_delete' %] + An error occurred when deleting this desk. Check the logs. + [% CASE 'success_on_update' %] + Desk updated successfully. + [% CASE 'success_on_insert' %] + Desk added successfully. + [% CASE 'success_on_delete' %] + Desk deleted successfully. + [% CASE 'already_exists' %] + This desk already exists. + [% CASE %] + [% m.code | html %] + [% END %] +
    +[% END %] + +[% IF op == 'add_form' %] + [% IF desk %] +

    Modify a desk

    + [% ELSE %] +

    New desk

    + [% END %] + +
    + + + +
    +
      + [% IF desk %] +
    1. Desk ID: [% desk.desk_id | html %]
    2. + [% END %] +
    3. + + Required +
    4. +
    5. + + +
    6. + +
    +
    + +
    + + Cancel +
    +
    +[% END %] + +[% IF op == 'delete_confirm' %] +
    +

    Delete desk "[% desk.desk_name | html %]?"

    + + + + + + + + + + +
    Desk id[% desk.desk_id | html %]
    Desk[% desk.desk_name | html %]
    Branchcode[% desk.branchcode | html %]
    +
    + + + +
    +
    + +
    +
    +[% END %] + +[% IF op == 'list' %] + + + +

    Desks

    + [% IF searchfield %] + Searching: [% searchfield | html %] + [% END %] + + [% IF desks.count %] + + + + + + + + + + + [% FOREACH desk IN desks %] + + + + + + + [% END %] + +
    Desk IDDeskLibraryAction
    [% desk.desk_id | html %][% desk.desk_name | html %][% desk.branchcode | html %] + Edit + Delete +
    + [% ELSE %] +
    + There are no desks defined. Create a new desk. +
    + [% END %] +[% END %] + +
    +
    + +
    + +
    +
    + +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] + +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/t/db_dependent/Koha/Desks.t b/t/db_dependent/Koha/Desks.t new file mode 100644 index 0000000000..89814456ff --- /dev/null +++ b/t/db_dependent/Koha/Desks.t @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development team +# Copyright 2020 BULAC +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Desk; +use Koha::Desks; +use Koha::Database; +use Koha::Libraries; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +# Add CPL if missing. +if (not defined Koha::Libraries->find('CPL')) { + Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store; +} + +my $builder = t::lib::TestBuilder->new; +my $nb_of_desks = Koha::Desks->search->count; +my $new_desk_1 = Koha::Desk->new({ + desk_name => 'my_desk_name_for_test_1', + branchcode => 'CPL', +})->store; +my $new_desk_2 = Koha::Desk->new({ + desk_name => 'my_desk_name_for_test_2', + branchcode => 'CPL', +})->store; + +like( $new_desk_1->desk_id, qr|^\d+$|, 'Adding a new desk should have set the desk_id'); +is( Koha::Desks->search->count, $nb_of_desks + 2, 'The 2 desks should have been added' ); + +my $retrieved_desk_1 = Koha::Desks->find( $new_desk_1->desk_id ); +is( $retrieved_desk_1->desk_name, $new_desk_1->desk_name, 'Find a desk by id should return the correct desk' ); + +$retrieved_desk_1->delete; +is( Koha::Desks->search->count, $nb_of_desks + 1, 'Delete should have deleted the desk' ); + +$schema->storage->txn_rollback; -- 2.39.5