LP#1626157 per-page setup ; downgrade service example
authorBill Erickson <berickxx@gmail.com>
Mon, 5 Mar 2018 17:57:01 +0000 (17:57 +0000)
committerBill Erickson <berickxx@gmail.com>
Mon, 5 Mar 2018 17:57:01 +0000 (17:57 +0000)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/eg2-src/src/app/app.module.ts
Open-ILS/src/templates/staff/base.tt2
Open-ILS/src/templates/staff/circ/checkin/index.tt2
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js

index e069594..b992515 100644 (file)
@@ -9,7 +9,8 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; // ng-bootstrap
 import {CookieModule} from 'ngx-cookie'; // import CookieMonster
 
 // XXX required for multi-mode
-import {UpgradeModule} from '@angular/upgrade/static';
+import {UpgradeModule, downgradeInjectable} from '@angular/upgrade/static';
+
 import {Router} from '@angular/router';
 
 import {EgBaseComponent} from './app.component';
@@ -67,24 +68,25 @@ export class EgBaseModule {
     ) {}
 
     ngDoBootstrap() {
-        console.log('ngDoBootstrap()');
+        let myWin: any = window; // make TS happy
 
-        let myWin: any = window;
+        console.log(`Ang2 loading Ang1 app ${myWin.ang1PageApp}`);
 
         if (!myWin.ang1PageApp) {
             console.error('NO PAGE APP DEFINED');
             return;
         }
 
-        /*
-        angular.module(myWin.ang1PageApp).directive('heroDetail',
-            downgradeComponent({ component: HeroDetailComponent })
-        );
-        */
+        angular.module(myWin.ang1PageApp)
+            /*
+            .directive('heroDetail', 
+                downgradeComponent({ component: HeroDetailComponent })
+            */
+            .factory('eg2Net', downgradeInjectable(EgNetService))
+        ;
 
         // some of our ang1 apps are not strict-di compliant :(
         this.upgrade.bootstrap(document.body, [myWin.ang1PageApp]);
-        //this.upgrade.bootstrap(document.body, [myWin.ang1PageApp], { strictDi: true });
     }
 
 }
index a16acc2..05c1624 100644 (file)
@@ -1,15 +1,17 @@
 <!doctype html>
 [%- PROCESS 'staff/config.tt2' %]
 <html lang="[% ctx.locale %]"
-    [%- IF ctx.page_app %] xng-app="[% ctx.page_app %]"[% END -%]
-    [%- IF ctx.page_ctrl %] ng-controller="[% ctx.page_ctrl %]"[% END %]>
+  [%- IF NOT ctx.is_ang2_app %]
+    [%- IF ctx.page_app %] ng-app="[% ctx.page_app %]"[% END -%]
+    [%- IF ctx.page_ctrl %] ng-controller="[% ctx.page_ctrl %]"[% END %]
+  [% END %]>
   <head>
-    <script>                                                                   
-      [%- IF ctx.page_app %]                                                   
-        // tell ang2 what ang1 wants to load.                                  
-        window.ang1PageApp = "[% ctx.page_app %]";                             
-      [% END -%]                                                               
-    </script> 
+    [% IF ctx.is_ang2_app AND ctx.page_app %]
+    <script>
+      // tell ang2 what ang1 app to load
+      window.ang1PageApp = "[% ctx.page_app %]";
+    </script>
+    [% END %]
     <!-- enables ng-cloak to be usable before angular has been able to fully load -->
     <style type="text/css">
     [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
@@ -57,7 +59,9 @@
       PROCESS APP_JS;
 
       # Angular2 scripts must be imported after app-specific ang1 imports
-      INCLUDE "staff/ang2_js.tt2";
+      IF ctx.is_ang2_app;
+        INCLUDE "staff/ang2_js.tt2";
+      END;
     %]
 
     <!-- content printed via the browser is inserted here for 
index 64e5510..6995cce 100644 (file)
@@ -2,6 +2,7 @@
   WRAPPER "staff/base.tt2";
   ctx.page_title = l("Check In"); 
   ctx.page_app = "egCheckinApp";
+  ctx.is_ang2_app = 1;
 %]
 
 [% BLOCK APP_JS %]
index 24e4a3b..fff7586 100644 (file)
@@ -34,8 +34,13 @@ angular.module('egCheckinApp', ['ngRoute', 'ui.bootstrap',
  * Manages checkin
  */
 .controller('CheckinCtrl',
-       ['$scope','$q','$window','$location', '$timeout','egCore','checkinSvc','egGridDataProvider','egCirc', 'egItem',
-function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , egGridDataProvider , egCirc, itemSvc)  {
+       ['$scope','$q','$window','$location', '$timeout','egCore',
+        'checkinSvc','egGridDataProvider','egCirc','egItem','eg2Net',
+function($scope , $q , $window , $location , $timeout , egCore , 
+         checkinSvc , egGridDataProvider , egCirc, itemSvc , eg2Net)  {
+
+    eg2Net.request('open-ils.actor', 'opensrf.system.echo', 'Hello, Ang2')
+    .subscribe(function(res) {console.log('eg2Net returned ' + res)});
 
     $scope.focusMe = true;
     $scope.checkins = checkinSvc.checkins;