lp1863252 fix Get Coordinates button in org admin
authorJason Etheridge <jason@EquinoxInitiative.org>
Fri, 19 Feb 2021 05:29:13 +0000 (00:29 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 11 Mar 2021 21:00:53 +0000 (16:00 -0500)
The underlying method can now handle org objects or org id's, and the UI
will also alert the user with any non-catastrophic error such as the location
not being found.

Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>

Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Geo.pm

index cea8fd1..4156ba2 100644 (file)
@@ -5,6 +5,7 @@ import {PcrudService} from '@eg/core/pcrud.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
+import {ToastService} from '@eg/share/toast/toast.service';
 
 const ADDR_TYPES =
     ['billing_address', 'holds_address', 'mailing_address', 'ill_address'];
@@ -38,9 +39,10 @@ export class OrgAddressComponent {
     constructor(
         private idl: IdlService,
         private org: OrgService,
-       private pcrud: PcrudService,
-       private auth: AuthService,
-        private net: NetService
+        private pcrud: PcrudService,
+        private auth: AuthService,
+        private net: NetService,
+        private toast: ToastService
     ) {
         this.addrChange = new EventEmitter<IdlObject>();
         this.tabName = 'billing_address';
@@ -165,22 +167,26 @@ export class OrgAddressComponent {
 
     getCoordinates($event: any) {
         const addr = $event.record;
-
         this.net.request(
             'open-ils.actor',
-           'open-ils.actor.geo.retrieve_coordinates',
-           this.auth.token(),
-            addr.org_unit(),
+            'open-ils.actor.geo.retrieve_coordinates',
+            this.auth.token(),
+            typeof addr.org_unit() === 'object' ? addr.org_unit().id() : addr.org_unit(),
             addr.street1() + ' ' + addr.street2() + ', '
             + addr.city() + ', ' + addr.state() + ' ' + addr.post_code()
             + ' ' + addr.country()
         ).subscribe(
             (res) => {
-                addr.latitude( res.latitude );
-                addr.longitude( res.longitude );
+                console.log('geo',res);
+                if (typeof res.ilsevent == 'undefined') {
+                    addr.latitude( res.latitude );
+                    addr.longitude( res.longitude );
+                } else {
+                    this.toast.danger(res.desc);
+                }
             },
             (err) => {
-                console.error(err);
+                console.error('geo',err);
             }
         );
     }
index cb0d92a..3f735e5 100644 (file)
@@ -140,6 +140,8 @@ sub retrieve_coordinates { # invoke 3rd party API for latitude/longitude lookup
     #       implementing some options for limiting outgoing geo-coding API calls
     # return $e->die_event unless $e->checkauth;
 
+    $org = ref($org) ? $org->id : $org; # never trust the caller :-)
+
     my $use_geo = $e->retrieve_config_global_flag('opac.use_geolocation');
     $use_geo = ($use_geo and $U->is_true($use_geo->enabled));
     return new OpenILS::Event("GEOCODING_NOT_ENABLED") unless ($U->is_true($use_geo));