From f9dfb4a0c1ee52e93f007818fd7215f8e56b2dd5 Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Mon, 6 Mar 2017 15:41:50 +0100
Subject: [PATCH] FEAT init angular2

---
 apps/maarch_entreprise/index.php              | 20 +++++++++-
 .../js/angular/app/app.component.js           | 26 ++++++++++++
 .../js/angular/app/app.component.ts           |  7 ++++
 .../js/angular/app/app.module.js              | 28 +++++++++++++
 .../js/angular/app/app.module.ts              | 11 +++++
 apps/maarch_entreprise/js/angular/main.js     |  5 +++
 apps/maarch_entreprise/js/angular/main.ts     |  5 +++
 .../js/angular/systemjs.config.js             | 40 +++++++++++++++++++
 .../js/angular/tsconfig.json                  | 13 ++++++
 apps/maarch_entreprise/merged_jsAbstract.php  | 35 ++++++++++------
 core/class/class_core_tools.php               |  3 ++
 modules/basket/view_baskets.php               |  3 +-
 package.json                                  | 32 +++++++++++++++
 13 files changed, 213 insertions(+), 15 deletions(-)
 create mode 100644 apps/maarch_entreprise/js/angular/app/app.component.js
 create mode 100644 apps/maarch_entreprise/js/angular/app/app.component.ts
 create mode 100644 apps/maarch_entreprise/js/angular/app/app.module.js
 create mode 100644 apps/maarch_entreprise/js/angular/app/app.module.ts
 create mode 100644 apps/maarch_entreprise/js/angular/main.js
 create mode 100644 apps/maarch_entreprise/js/angular/main.ts
 create mode 100644 apps/maarch_entreprise/js/angular/systemjs.config.js
 create mode 100644 apps/maarch_entreprise/js/angular/tsconfig.json
 create mode 100644 package.json

diff --git a/apps/maarch_entreprise/index.php b/apps/maarch_entreprise/index.php
index b42fa22363b..4b2afae761a 100644
--- a/apps/maarch_entreprise/index.php
+++ b/apps/maarch_entreprise/index.php
@@ -226,9 +226,27 @@ if(empty($_SESSION['current_basket'])){
 
 
  ?>
-<body ng-app="AppModule" ng-controller="mainCtrl" style="background: url('static.php?filename=loading_big.gif') no-repeat fixed center;" onload="$('maarch_body').style.background='f2f2f2';$('maarch_body').style.backgroundImage='';$('maarch_body').style.backgroundUrl='';$('maarch_content').style.display='block';session_expirate(<?php echo $time;?>, '<?php
+
+<!-- Polyfill(s) for older browsers -->
+<!-- <script src="/node_modules/core-js/client/shim.js"></script>
+<script src="/node_modules/zone.js/dist/zone.js"></script>
+<script src="/node_modules/systemjs/dist/system.src.js"></script>
+<script src="js/angular/systemjs.config.js"></script> -->
+<!-- <script>
+  System.import('js/angular/main.js').catch(function(err){ console.error(err); });
+</script> -->
+
+<!--body ng-app="AppModule" ng-controller="mainCtrl" style="background: url('static.php?filename=loading_big.gif') no-repeat fixed center;" onload="$('maarch_body').style.background='f2f2f2';$('maarch_body').style.backgroundImage='';$('maarch_body').style.backgroundUrl='';$('maarch_content').style.display='block';session_expirate(<?php echo $time;?>, '<?php
+    echo $_SESSION['config']['businessappurl'];
+    ?>index.php?display=true&page=logout&logout=true');" id="maarch_body"-->
+
+<body style="background: url('static.php?filename=loading_big.gif') no-repeat fixed center;" onload="$('maarch_body').style.background='f2f2f2';$('maarch_body').style.backgroundImage='';$('maarch_body').style.backgroundUrl='';$('maarch_content').style.display='block';session_expirate(<?php echo $time;?>, '<?php
     echo $_SESSION['config']['businessappurl'];
     ?>index.php?display=true&page=logout&logout=true');" id="maarch_body">
+    
+
+<my-app>Loading AppComponent content here ...</my-app>
+
     <div id ="maarch_content" style="display:none;">
 
     <?php
diff --git a/apps/maarch_entreprise/js/angular/app/app.component.js b/apps/maarch_entreprise/js/angular/app/app.component.js
new file mode 100644
index 00000000000..583c240d1f0
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/app/app.component.js
@@ -0,0 +1,26 @@
+"use strict";
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
+var __metadata = (this && this.__metadata) || function (k, v) {
+    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
+};
+var core_1 = require('@angular/core');
+var AppComponent = (function () {
+    function AppComponent() {
+        this.name = 'Angular';
+    }
+    AppComponent = __decorate([
+        core_1.Component({
+            selector: 'my-app',
+            template: "<h1>Hello {{name}}</h1>",
+        }), 
+        __metadata('design:paramtypes', [])
+    ], AppComponent);
+    return AppComponent;
+}());
+exports.AppComponent = AppComponent;
+//# sourceMappingURL=app.component.js.map
\ No newline at end of file
diff --git a/apps/maarch_entreprise/js/angular/app/app.component.ts b/apps/maarch_entreprise/js/angular/app/app.component.ts
new file mode 100644
index 00000000000..7fb173cd011
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/app/app.component.ts
@@ -0,0 +1,7 @@
+import { Component } from '@angular/core';
+
+@Component({
+  selector: 'my-app',
+  template: `<h1>Hello {{name}}</h1>`,
+})
+export class AppComponent  { name = 'Angular'; }
diff --git a/apps/maarch_entreprise/js/angular/app/app.module.js b/apps/maarch_entreprise/js/angular/app/app.module.js
new file mode 100644
index 00000000000..1715df39d55
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/app/app.module.js
@@ -0,0 +1,28 @@
+"use strict";
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
+var __metadata = (this && this.__metadata) || function (k, v) {
+    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
+};
+var core_1 = require('@angular/core');
+var platform_browser_1 = require('@angular/platform-browser');
+var app_component_1 = require('./app.component');
+var AppModule = (function () {
+    function AppModule() {
+    }
+    AppModule = __decorate([
+        core_1.NgModule({
+            imports: [platform_browser_1.BrowserModule],
+            declarations: [app_component_1.AppComponent],
+            bootstrap: [app_component_1.AppComponent]
+        }), 
+        __metadata('design:paramtypes', [])
+    ], AppModule);
+    return AppModule;
+}());
+exports.AppModule = AppModule;
+//# sourceMappingURL=app.module.js.map
\ No newline at end of file
diff --git a/apps/maarch_entreprise/js/angular/app/app.module.ts b/apps/maarch_entreprise/js/angular/app/app.module.ts
new file mode 100644
index 00000000000..357b003a5ab
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/app/app.module.ts
@@ -0,0 +1,11 @@
+import { NgModule }      from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+
+import { AppComponent }  from './app.component';
+
+@NgModule({
+  imports:      [ BrowserModule ],
+  declarations: [ AppComponent ],
+  bootstrap:    [ AppComponent ]
+})
+export class AppModule { }
diff --git a/apps/maarch_entreprise/js/angular/main.js b/apps/maarch_entreprise/js/angular/main.js
new file mode 100644
index 00000000000..0c4c3b99e29
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/main.js
@@ -0,0 +1,5 @@
+"use strict";
+var platform_browser_dynamic_1 = require('@angular/platform-browser-dynamic');
+var app_module_1 = require('./app/app.module');
+platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(app_module_1.AppModule);
+//# sourceMappingURL=main.js.map
\ No newline at end of file
diff --git a/apps/maarch_entreprise/js/angular/main.ts b/apps/maarch_entreprise/js/angular/main.ts
new file mode 100644
index 00000000000..311c44b76de
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/main.ts
@@ -0,0 +1,5 @@
+import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
+
+import { AppModule } from './app/app.module';
+
+platformBrowserDynamic().bootstrapModule(AppModule);
diff --git a/apps/maarch_entreprise/js/angular/systemjs.config.js b/apps/maarch_entreprise/js/angular/systemjs.config.js
new file mode 100644
index 00000000000..c1ec6562023
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/systemjs.config.js
@@ -0,0 +1,40 @@
+/**
+ * System configuration for Angular samples
+ * Adjust as necessary for your application needs.
+ */
+(function (global) {
+  System.config({
+    paths: {
+      // paths serve as alias
+      'npm:': '/node_modules/'
+    },
+    // map tells the System loader where to look for things
+    map: {
+      // our app is within the app folder
+      app: 'js/angular/app',
+
+      // angular bundles
+      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
+      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
+      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
+      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
+      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
+      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
+      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
+      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
+
+      // other libraries
+      'rxjs':                      'npm:rxjs',
+      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
+    },
+    // packages tells the System loader how to load when no filename and/or no extension
+    packages: {
+      app: {
+        defaultExtension: 'js'
+      },
+      rxjs: {
+        defaultExtension: 'js'
+      }
+    }
+  });
+})(this);
diff --git a/apps/maarch_entreprise/js/angular/tsconfig.json b/apps/maarch_entreprise/js/angular/tsconfig.json
new file mode 100644
index 00000000000..f13f84d31fe
--- /dev/null
+++ b/apps/maarch_entreprise/js/angular/tsconfig.json
@@ -0,0 +1,13 @@
+{
+  "compilerOptions": {
+    "target": "es5",
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "sourceMap": false,
+    "emitDecoratorMetadata": true,
+    "experimentalDecorators": true,
+    "lib": [ "es2015", "dom" ],
+    "noImplicitAny": true,
+    "suppressImplicitAnyIndexErrors": true
+  }
+}
diff --git a/apps/maarch_entreprise/merged_jsAbstract.php b/apps/maarch_entreprise/merged_jsAbstract.php
index 99fd0135fa9..090d67d4864 100644
--- a/apps/maarch_entreprise/merged_jsAbstract.php
+++ b/apps/maarch_entreprise/merged_jsAbstract.php
@@ -44,9 +44,11 @@ class MergedJsAbstract {
 		readfile('apps/maarch_entreprise/js/prototype.js');
 		readfile('apps/maarch_entreprise/js/scriptaculous.js');
 		readfile('apps/maarch_entreprise/js/jquery.min.js');
-		readfile('apps/maarch_entreprise/js/angular.min.js');
-		readfile('apps/maarch_entreprise/js/angular-route.js');
-		readfile('apps/maarch_entreprise/js/ng-table.min.js');
+
+		// readfile('apps/maarch_entreprise/js/angular.min.js');
+		// readfile('apps/maarch_entreprise/js/angular-route.js');
+		// readfile('apps/maarch_entreprise/js/ng-table.min.js');
+
 		readfile('apps/maarch_entreprise/js/indexing.js');
 		readfile('apps/maarch_entreprise/js/scrollbox.js');
 		readfile('apps/maarch_entreprise/js/effects.js');
@@ -58,12 +60,19 @@ class MergedJsAbstract {
 		readfile('apps/maarch_entreprise/js/Chart.js');
 		readfile('apps/maarch_entreprise/js/chosen.proto.min.js');
 		readfile('apps/maarch_entreprise/js/event.simulate.js');
-		readfile('apps/maarch_entreprise/js/RSVP.js');
-        readfile('apps/maarch_entreprise/js/render.js');
-        readfile('apps/maarch_entreprise/js/jio.js');
+		
+		//for office.js
+		//readfile('apps/maarch_entreprise/js/RSVP.js');
+        //readfile('apps/maarch_entreprise/js/render.js');
+        //readfile('apps/maarch_entreprise/js/jio.js');
+
+		// readfile('apps/maarch_entreprise/js/app.module.js');
+		// readfile('apps/maarch_entreprise/js/aController.js');
 
-		readfile('apps/maarch_entreprise/js/app.module.js');
-		readfile('apps/maarch_entreprise/js/aController.js');
+		readfile('node_modules/core-js/client/shim.js');
+		readfile('node_modules/zone.js/dist/zone.js');
+		readfile('node_modules/systemjs/dist/system.src.js');
+		readfile('apps/maarch_entreprise/js/angular/systemjs.config.js');
 
         echo "\n";
 	}
@@ -77,11 +86,11 @@ class MergedJsAbstract {
 			    {
 			        include('modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/functions.js');
 			    }
-			    if(file_exists($_SESSION['config']['corepath'].'custom/'.$_SESSION['custom_override_id'].'/modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js')
-					|| file_exists($_SESSION['config']['corepath'].'/modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js'))
-			    {
-			        include('modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js');
-			    }
+			  //   if(file_exists($_SESSION['config']['corepath'].'custom/'.$_SESSION['custom_override_id'].'/modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js')
+					// || file_exists($_SESSION['config']['corepath'].'/modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js'))
+			  //   {
+			  //       include('modules/'.$_SESSION['modules_loaded'][$value]['name'].'/js/aController.js');
+			  //   }
 			}
 		}
 	}
diff --git a/core/class/class_core_tools.php b/core/class/class_core_tools.php
index 4380ef27c9a..d63c502c5fe 100755
--- a/core/class/class_core_tools.php
+++ b/core/class/class_core_tools.php
@@ -1580,6 +1580,9 @@ class core_tools extends functions
             var app_path = '<?php echo $_SESSION['config']['businessappurl'];?>static.php?filename=';
         </script>-->
         <script type="text/javascript" src="<?php echo $_SESSION['config']['businessappurl'];?>merged_js.php"></script>
+        <script>
+          System.import('js/angular/main.js').catch(function(err){ console.error(err); });
+        </script>
         <?php
 
     }
diff --git a/modules/basket/view_baskets.php b/modules/basket/view_baskets.php
index 8585d481171..678b2a317a5 100644
--- a/modules/basket/view_baskets.php
+++ b/modules/basket/view_baskets.php
@@ -313,7 +313,8 @@ if (count($_SESSION['user']['baskets']) > 0) {
 }
 ?>
 </h1>
-<div id="inner_content" class="clearfix" ng-controller="basketCtrl">
+<!--div id="inner_content" class="clearfix" ng-controller="basketCtrl"-->
+<div id="inner_content" class="clearfix">
 <?php
 
 
diff --git a/package.json b/package.json
new file mode 100644
index 00000000000..7de69bb497d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,32 @@
+{
+  "name": "MaarchCourrier",
+  "version": "1.0.0",
+  "description": "MaarchCourrier",
+  "scripts": {
+    "build": "tsc -p apps/maarch_entreprise/js/angular/",
+    "build:watch": "tsc -p apps/maarch_entreprise/js/angular/ -w"
+  },
+  "keywords": [],
+  "author": "Maarch",
+  "license": "GPLV3",
+  "dependencies": {
+    "@angular/common": "~2.4.0",
+    "@angular/compiler": "~2.4.0",
+    "@angular/core": "~2.4.0",
+    "@angular/forms": "~2.4.0",
+    "@angular/http": "~2.4.0",
+    "@angular/platform-browser": "~2.4.0",
+    "@angular/platform-browser-dynamic": "~2.4.0",
+    "@angular/router": "~3.4.0",
+
+    "angular-in-memory-web-api": "~0.2.4",
+    "systemjs": "0.19.40",
+    "core-js": "^2.4.1",
+    "rxjs": "5.0.1",
+    "zone.js": "^0.7.4"
+  },
+  "devDependencies": {
+    "typescript": "~2.0.10"
+  },
+  "repository": {}
+}
-- 
GitLab