Bugzilla – Attachment 148462 Details for
Bug 33104
Add vendor interfaces
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33104: Add the ability to create vendor interfaces
Bug-33104-Add-the-ability-to-create-vendor-interfa.patch (text/plain), 10.78 KB, created by
Jonathan Druart
on 2023-03-21 13:12:17 UTC
(
hide
)
Description:
Bug 33104: Add the ability to create vendor interfaces
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-03-21 13:12:17 UTC
Size:
10.78 KB
patch
obsolete
>From db1f3885702d114b9ab12a1b618792b95ba9be4a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 1 Mar 2023 15:53:22 +0100 >Subject: [PATCH] Bug 33104: Add the ability to create vendor interfaces > >This patchset is adding the ability to create interfaces for vendors. >An interface is a website, software, or portal that you use to manage orders or >gather statistics from the vendor/organisation. > >It will help librarians to keep track of those different information >within Koha. > >* new DB table aqbookseller_interfaces(id, vendor_id, type, name, uri, >login, password, account_email, notes) >* new AV category VENDOR_INTERFACE_TYPE with 3 example values ADMIN, >ORDERS, REPORTS >* new pair of Koha classes Koha::Acquisition::Bookseller::Interface[s] >* new method to retrieve the interfaces from the vendor >Koha::Acquisition::Bookseller->interfaces >* Add/Delete interfaces when editing a vendor >* Display the interfaces on the vendor show view > >Test plan: >- Add a new vendor >=> Notice the new "Interfaces" block >- Create some interfaces >=> They are display on the vendor show view >=> The password is hashed and can displayed on the demand > >QA Note: >The "contacts" code is not very nice and I didn't want to replicate it, >so I went another way and tried to make the code reusable, for further >reutilisation. >--- > Koha/Acquisition/Bookseller.pm | 28 ++++++ > acqui/updatesupplier.pl | 16 ++++ > .../prog/css/src/staff-global.scss | 3 +- > .../prog/en/modules/acqui/supplier.tt | 87 ++++++++++++++++++- > 4 files changed, 132 insertions(+), 2 deletions(-) > >diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm >index 0ba30a3243c..a11c7656438 100644 >--- a/Koha/Acquisition/Bookseller.pm >+++ b/Koha/Acquisition/Bookseller.pm >@@ -19,6 +19,7 @@ use Modern::Perl; > > use Koha::Acquisition::Bookseller::Aliases; > use Koha::Acquisition::Bookseller::Contacts; >+use Koha::Acquisition::Bookseller::Interfaces; > use Koha::Subscriptions; > > use base qw( Koha::Object ); >@@ -104,6 +105,33 @@ sub aliases { > return Koha::Acquisition::Bookseller::Aliases->_new_from_dbic( $rs ); > } > >+=head3 interfaces >+ >+ my $interfaces = $vendor->interfaces >+ >+ $vendor->interfaces(\@interfaces); >+ >+=cut >+ >+sub interfaces { >+ my ($self, $interfaces) = @_; >+ >+ if ($interfaces) { >+ my $schema = $self->_result->result_source->schema; >+ $schema->txn_do( >+ sub { >+ $self->interfaces->delete; >+ for my $interface (@$interfaces) { >+ $self->_result->add_to_aqbookseller_interfaces($interface); >+ } >+ } >+ ); >+ } >+ >+ my $rs = $self->_result->aqbookseller_interfaces; >+ return Koha::Acquisition::Bookseller::Interfaces->_new_from_dbic( $rs ); >+} >+ > > =head3 to_api_mapping > >diff --git a/acqui/updatesupplier.pl b/acqui/updatesupplier.pl >index ac0d50ba649..642111ab4c2 100755 >--- a/acqui/updatesupplier.pl >+++ b/acqui/updatesupplier.pl >@@ -47,6 +47,7 @@ contact_serialsprimary. > =cut > > use Modern::Perl; >+use List::MoreUtils qw( any ); > use C4::Context; > use C4::Auth qw( checkauth ); > >@@ -130,8 +131,23 @@ if($data{'name'}) { > $contact->{booksellerid} = $data{id}; > Koha::Acquisition::Bookseller::Contact->new( $contact )->store > } >+ >+ # Insert aliases > $bookseller->aliases([ map { { alias => $_ } } @aliases ]); > >+ # Insert interfaces >+ my @interface_counters = $input->multi_param('interface_counter'); >+ my @interfaces; >+ for my $counter ( @interface_counters ) { >+ my $interface = {}; >+ for my $attr (qw(name type uri login password account_email notes)){ >+ my $v = $input->param("interface_${attr}_${counter}"); >+ $interface->{$attr} = $v; >+ } >+ push @interfaces, $interface if any { defined && length } values %$interface; >+ } >+ $bookseller->interfaces(\@interfaces); >+ > #redirect to booksellers.pl > print $input->redirect("booksellers.pl?booksellerid=".$data{id}); > } else { >diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >index 9b1534fdbdb..eb3e412df14 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >@@ -2584,7 +2584,8 @@ td.bundle { > margin: 0 0 8px 8px; > } > >-#contact-template { >+#contact-template, >+#interface-template { > display: none; > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt >index 8a03894351d..c68f1cfcc3a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt >@@ -186,7 +186,6 @@ > <label for="aliases">Aliases: </label> > <div id="aliases" style="padding-left: 11rem;"></div> > </li> >- > </ol> > </fieldset> > <fieldset class="rows"> >@@ -204,6 +203,11 @@ > <button id="add-contact" class="btn btn-default"><i class="fa fa-plus"></i> Add another contact</button> > </fieldset> > >+ <fieldset class="rows"> >+ <legend>Interfaces</legend> >+ <div id="interfaces"></div> >+ </fieldset> >+ > <fieldset class="rows"> > <legend>Ordering information</legend> > <ol><li><label for="activestatus">Vendor is:</label> >@@ -359,6 +363,29 @@ > <p><strong>Notes: </strong>[% notes | html %]</p> > [% END %] > </div> <!-- #supplier-ordering-information --> >+ >+ [% IF vendor.interfaces.count %] >+ <div id="supplier-interfaces" class="page-section"> >+ <h2>Interfaces</h2> >+ >+ [% FOR interface IN vendor.interfaces %] >+ <fieldset class="rows"> >+ <legend>[% interface.name | html %]</legend> >+ <ul> >+ <li> >+ <li>Type: [% interface.type | html %]</li> >+ <li>URI: [% interface.uri | html %]</li> >+ <li>Login: [% interface.login | html %]</li> >+ <li>Password: [% interface.password | html %]</li> >+ <li>Account email: [% interface.account_email | html %]</li> >+ <li>Notes : [% interface.notes | html %]</li> >+ </li> >+ </ul> >+ </fieldset> >+ [% END %] >+ </div> >+ [% END %] >+ > </div> <!-- /.col-sm-6 --> > > <div class="col-sm-6"> >@@ -511,6 +538,63 @@ > $("#aliases").html(nodes.html()); > } > >+ [% IF vendor %] >+ let interfaces = [% To.json(vendor.interfaces.unblessed) | $raw %]; >+ [% ELSE %] >+ let interfaces = []; >+ [% END %] >+ function serialize_interface_form(){ >+ interfaces = []; >+ $("#interfaces > fieldset.supplier-interface > ol.interface-form").each( (index, interface_form )=> { >+ let interface = {}; >+ $(interface_form).find('input,textarea').serializeArray().map(attr => { >+ let name = attr.name.replace(/interface_([\w_]+)_\d+/, "$1"); >+ interface[name] = attr.value >+ }) >+ interfaces.push(interface); >+ }); >+ return interfaces; >+ } >+ function remove_interface(i){ >+ interfaces = serialize_interface_form(); >+ interfaces.splice(i, 1); >+ refresh_interfaces(); >+ } >+ function add_interface(){ >+ interfaces = serialize_interface_form(); >+ interfaces.push({ >+ type: "", >+ name: "", >+ uri: "", >+ login: "", >+ password: "", >+ account_email: "", >+ notes: "", >+ }); >+ refresh_interfaces(); >+ } >+ function refresh_interfaces(){ >+ let nodes = $("<div id='interfaces'></div>"); >+ interfaces.forEach((interface, i) => { >+ let n = $("<fieldset class='supplier-interface'></fieldset>"); >+ n.append("<legend>" + _("Interface details") + "</legend>"); >+ n.append(`<input type="hidden" name="interface_counter" value="${i}" />`); >+ let ol = $('<ol class="interface-form"></ol>'); >+ ol.append(`<li><label for="interface_name_${i}">` + _("Name: ") + `</label><input type="text" size="40" id="interface_name_${i}" name="interface_name_${i}" value="${interface.name}" /></li>`); >+ ol.append(`<li><label for="interface_type_${i}">` + _("Type: ") + `</label><input type="text" size="40" id="interface_type_${i}" name="interface_type_${i}" value="${interface.type}" /></li>`); >+ ol.append(`<li><label for="interface_uri_${i}">` + _("URI: ") + `</label><input type="text" size="40" id="interface_uri_${i}" name="interface_uri_${i}" value="${interface.uri}" /></li>`); >+ ol.append(`<li><label for="interface_login_${i}">` + _("Login: ") + `</label><input type="text" size="40" id="interface_login_${i}" name="interface_login_${i}" value="${interface.login}" /></li>`); >+ ol.append(`<li><label for="interface_password_${i}">` + _("Password: ") + `</label><input type="text" size="40" id="interface_password_${i}" name="interface_password_${i}" value="${interface.password}" /></li>`); >+ ol.append(`<li><label for="interface_account_email_${i}">` + _("Account email: ") + `</label><input type="text" size="40" id="interface_account_email_${i}" name="interface_account_email_${i}" value="${interface.account_email}" /></li>`); >+ ol.append(`<li><label for="interface_notes_${i}">` + _("Notes: ") + `</label><textarea cols="40" rows="3" id="interface_notes_${i}" name="interface_notes_${i}">${interface.notes}</textarea></li>`); >+ ol.append(`<li><button class="btn btn-default" onclick="remove_interface(${i});"><i class="fa fa-trash"></i> Delete interface</li>`); >+ n.append(ol); >+ nodes.append(n); >+ }); >+ nodes.append(`<button onclick="add_interface();" class="btn btn-default"><i class="fa fa-plus"></i> ` + _("Add another interface") + '</button>') >+ $("#interfaces").replaceWith(nodes); >+ } >+ > var Sticky; > > $(document).ready(function() { >@@ -551,6 +635,7 @@ > }); > > refresh_aliases(); >+ refresh_interfaces(); > > Sticky = $("#toolbar"); > Sticky.hcSticky({ >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33104
:
147632
|
147633
|
147634
|
147635
|
147636
|
147637
|
147638
|
147639
|
148459
|
148460
|
148461
|
148462
|
148463
|
148464
|
148465
|
148466
|
148473
|
148474
|
148475
|
148476
|
148477
|
148478
|
148479
|
148480
|
149375
|
149420
|
149421
|
149422
|
149431
|
149492
|
149493
|
149494
|
149495
|
149496
|
149497
|
149498
|
149499
|
149500
|
149501
|
149502
|
149503
|
149631
|
149632