Adding profiles to EnodeB and IMSI
diff --git a/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.html b/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.html
new file mode 100644
index 0000000..dec2045
--- /dev/null
+++ b/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.html
@@ -0,0 +1,6 @@
+<div class="modal-header">
+    <h3 class="modal-title">Add Profile</h3>
+</div>
+<div class="modal-body">
+    <xos-table data="vm.profiles" config="vm.config"></xos-table>
+</div>
\ No newline at end of file
diff --git a/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.js b/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.js
new file mode 100644
index 0000000..17f0504
--- /dev/null
+++ b/mCordPortal/src/app/components/add-profile-to-item/add-profile-to-item.js
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+angular.module('mCord')
+  .directive('addProfileToItem', function () {
+    return {
+      restrict: 'E',
+      templateUrl: 'app/components/add-profile-to-item/add-profile-to-item.html',
+      scope: {
+        modal: '=',
+        cb: '=',
+        item: '='
+      },
+      bindToController: true,
+      controllerAs: 'vm',
+      controller: function(Profile){
+
+        Profile.query().$promise
+        .then((profiles) => {
+          // TODO diff all profile from item.getProfiles
+          this.profiles = profiles;
+          return this.item.getProfiles();
+        })
+        .then((itemProfiles) => {
+          this.profiles = _.differenceBy(this.profiles, itemProfiles, 'Name');
+        });
+
+        this.config = {
+          columns: [
+            {
+              label: 'Name',
+              prop: 'Name'
+            },
+            {
+              label: 'DlAllocRBRate',
+              prop: 'DlAllocRBRate'
+            },
+            {
+              label: 'UlAllocRBRate',
+              prop: 'UlAllocRBRate'
+            },
+            {
+              label: 'Start',
+              prop: 'Start'
+            },
+            {
+              label: 'End',
+              prop: 'End'
+            }
+          ],
+          actions: [
+            {
+              label: 'Add',
+              icon: 'plus',
+              cb: (profile) => {
+                _.remove(this.profiles, p => p.Name === profile.Name);
+                this.cb(profile);
+              },
+            }
+          ],
+          filter: 'field',
+          order: true
+        }
+      }
+    };
+  });
diff --git a/mCordPortal/src/app/components/related-profiles/related-profiles.js b/mCordPortal/src/app/components/related-profiles/related-profiles.js
index 44314ef..5a889d3 100644
--- a/mCordPortal/src/app/components/related-profiles/related-profiles.js
+++ b/mCordPortal/src/app/components/related-profiles/related-profiles.js
@@ -26,8 +26,8 @@
       bindToController: true,
       controllerAs: 'vm',
       controller: function($scope, _){
-        $scope.$watch(() => this.model, enode => {
-          if(enode){
+        $scope.$watch(() => this.model, model => {
+          if(model){
             loadProfiles();
           }
         });
@@ -44,7 +44,13 @@
           .then(() => {
             _.remove(this.profiles, p => p.Name === id);
           });
-        }
+        };
+
+        $scope.$on('profile.add', (evt, data) => {
+          if(this.model.IMSI === data.targetId || this.model.eNBId === data.targetId){
+            this.profiles.push(data.profile);
+          }
+        });
       }
     };
   });
diff --git a/mCordPortal/src/app/view/enode-details/e-node-details.tpl.html b/mCordPortal/src/app/view/enode-details/e-node-details.tpl.html
index 60232f7..55abba9 100644
--- a/mCordPortal/src/app/view/enode-details/e-node-details.tpl.html
+++ b/mCordPortal/src/app/view/enode-details/e-node-details.tpl.html
@@ -19,6 +19,12 @@
             </div>
             <div class="col-xs-9">
               <related-profiles model="vm.enode" config="{showHeader: false, colors: vm.colors}"></related-profiles>
+              <div class="row">
+                <div class="col-xs-12 text-right">
+                  <a ng-click="vm.addProfile()" class="btn btn-primary-border">Add Profile</a>
+                  <a href="" class="btn btn-primary-border">Create Profile</a>
+                </div>
+              </div>
             </div>
           </div>
         </uib-tab>
@@ -47,4 +53,7 @@
       </uib-tabset>
     </div>
   </div>
-</div>
\ No newline at end of file
+</div>
+<script type="text/ng-template" id="addProfileToImsi">
+  <add-profile-to-item modal="vm.modal" cb="vm.callback" item="vm.eNodeB"></add-profile-to-item>
+</script>
\ No newline at end of file
diff --git a/mCordPortal/src/app/view/enode-details/enode-details.js b/mCordPortal/src/app/view/enode-details/enode-details.js
index 4c93fe7..a187893 100644
--- a/mCordPortal/src/app/view/enode-details/enode-details.js
+++ b/mCordPortal/src/app/view/enode-details/enode-details.js
@@ -8,7 +8,7 @@
         scope: {},
         controllerAs: 'vm',
         templateUrl: 'app/view/enode-details/e-node-details.tpl.html',
-        controller: function($stateParams, _, Enodeb){
+        controller: function($scope, $stateParams, $uibModal, _, Enodeb){
 
           const secondsToHms = d => {
             d = Number(d);
@@ -30,12 +30,16 @@
             return this.enode.getProfiles()
           })
           .then(profiles => {
-            console.log(profiles);
+            this.profiles = profiles;
+            createChartData(profiles);
+          });
+
+          const createChartData = (profiles) => {
             this.data = _.reduce(profiles, (list, p) => {
               list.push([p.DlAllocRBRate, p.UlAllocRBRate]);
               return list;
-            }, [])
-          });
+            }, []);
+          }
 
           this.labels = ['Download', 'Upload'];
 
@@ -55,6 +59,24 @@
               }
             ]
           };
+
+          this.addProfile = () => {
+            const _this = this;
+            this.modalInstance = $uibModal.open({
+              animation: true,
+              templateUrl: 'addProfileToImsi',
+              controllerAs: 'vm',
+              controller: function ($uibModalInstance) {
+                this.modal    = $uibModalInstance;
+                this.callback = (profile) => {
+                  $scope.$broadcast('profile.add', {targetId: _this.enode.eNBId, profile: profile});
+                  _this.profiles.push(profile);
+                  createChartData(_this.profiles);
+                };
+                this.eNodeB = _this.enode;
+              }
+            });
+          };
           
         }
       }
diff --git a/mCordPortal/src/app/view/home/e-node-map-panel.js b/mCordPortal/src/app/view/home/e-node-map-panel.js
index 37ca7a9..51bae53 100644
--- a/mCordPortal/src/app/view/home/e-node-map-panel.js
+++ b/mCordPortal/src/app/view/home/e-node-map-panel.js
@@ -11,10 +11,26 @@
         bindToController: true,
         controllerAs: 'vm',
         templateUrl: 'app/view/home/e-node-map-panel.tpl.html',
-        controller: function(){
+        controller: function($scope, $uibModal){
           this.close = () => {
             delete this.eNodeB;
           };
+
+          this.addProfile = () => {
+            const _this = this;
+            this.modalInstance = $uibModal.open({
+              animation: true,
+              templateUrl: 'addProfileToImsi',
+              controllerAs: 'vm',
+              controller: function ($uibModalInstance) {
+                this.modal    = $uibModalInstance;
+                this.callback = (profile) => {
+                  $scope.$broadcast('profile.add', {targetId: _this.eNodeB.eNBId, profile: profile});
+                };
+                this.eNodeB = _this.eNodeB;
+              }
+            });
+          };
         }
       }
     });
diff --git a/mCordPortal/src/app/view/home/e-node-map-panel.tpl.html b/mCordPortal/src/app/view/home/e-node-map-panel.tpl.html
index 1f85893..b74dd0b 100644
--- a/mCordPortal/src/app/view/home/e-node-map-panel.tpl.html
+++ b/mCordPortal/src/app/view/home/e-node-map-panel.tpl.html
@@ -25,7 +25,7 @@
         <div class="panel-body">
           <div class="row text-center">
             <div class="col-xs-6">
-              <a class="btn btn-primary-border">Add Profile</a>
+              <a ng-click="vm.addProfile()" class="btn btn-primary-border">Add Profile</a>
             </div>
             <div class="col-xs-6">
               <a class="btn btn-primary-border">Create Profile</a>
@@ -47,5 +47,7 @@
       </div>
     </div>
   </div>
-  <!-- <pre>{{vm.eNodeB | json}}</pre> -->
-</div>
\ No newline at end of file
+</div>
+<script type="text/ng-template" id="addProfileToImsi">
+  <add-profile-to-item modal="vm.modal" cb="vm.callback" item="vm.eNodeB"></add-profile-to-item>
+</script>
\ No newline at end of file
diff --git a/mCordPortal/src/app/view/imsi-details/imsi-details.js b/mCordPortal/src/app/view/imsi-details/imsi-details.js
index 0628601..99204c4 100644
--- a/mCordPortal/src/app/view/imsi-details/imsi-details.js
+++ b/mCordPortal/src/app/view/imsi-details/imsi-details.js
@@ -8,7 +8,7 @@
         scope: {},
         controllerAs: 'vm',
         templateUrl: 'app/view/imsi-details/imsi-details.tpl.html',
-        controller: function($stateParams, _, Imsi){
+        controller: function($scope, $stateParams, $uibModal, _, Imsi){
 
           Imsi.get({id: $stateParams.id}).$promise
           .then((imsi) => {
@@ -16,10 +16,7 @@
             return imsi.getProfiles()
           })
           .then(profiles => {
-            this.data = _.reduce(profiles, (list, p) => {
-              list.push([p.DlAllocRBRate, p.UlAllocRBRate]);
-              return list;
-            }, [])
+            this.profiles = profiles;
           });
 
           this.config = {
@@ -29,14 +26,30 @@
               {
                 label: 'Update',
                 icon: 'ok',
-                cb: (enode) => {
-                  enode.$save();
+                cb: (imsi) => {
+                  imsi.$save();
                 },
                 class: 'primary-border'
               }
             ]
           };
-          
+
+          this.addProfile = () => {
+            const _this = this;
+            this.modalInstance = $uibModal.open({
+              animation: true,
+              templateUrl: 'addProfileToImsi',
+              controllerAs: 'vm',
+              controller: function ($uibModalInstance) {
+                this.modal    = $uibModalInstance;
+                this.callback = (profile) => {
+                  console.log(_this.imsi);
+                  $scope.$broadcast('profile.add', {targetId: _this.imsi.IMSI, profile: profile});
+                };
+                this.imsi = _this.imsi;
+              }
+            });
+          };
         }
       }
     });
diff --git a/mCordPortal/src/app/view/imsi-details/imsi-details.tpl.html b/mCordPortal/src/app/view/imsi-details/imsi-details.tpl.html
index 7238856..f6b0947 100644
--- a/mCordPortal/src/app/view/imsi-details/imsi-details.tpl.html
+++ b/mCordPortal/src/app/view/imsi-details/imsi-details.tpl.html
@@ -15,7 +15,7 @@
       <related-profiles model="vm.imsi" config="{showHeader: false, delete: true}"></related-profiles>
     </div>
     <div class="col-xs-12 text-right">
-      <a href="" class="btn btn-primary-border">
+      <a ng-click="vm.addProfile()" href="" class="btn btn-primary-border">
         Add Profile
       </a>
       <a href="" class="btn btn-primary-border">
@@ -23,4 +23,8 @@
       </a>
     </div>
   </div>
-</div>
\ No newline at end of file
+</div>
+
+<script type="text/ng-template" id="addProfileToImsi">
+  <add-profile-to-item modal="vm.modal" cb="vm.callback" item="vm.imsi"></add-profile-to-item>
+</script>
\ No newline at end of file
diff --git a/mCordPortal/src/index.html b/mCordPortal/src/index.html
index 171ee44..c7a789e 100644
--- a/mCordPortal/src/index.html
+++ b/mCordPortal/src/index.html
@@ -66,6 +66,7 @@
     <script src="dist/components/footer/footer.js"></script>
     <script src="dist/components/add-enodeb/add-enodeb.js"></script>
     <script src="dist/components/add-imsi/add-imsi.js"></script>
+    <script src="dist/components/add-profile-to-item/add-profile-to-item.js"></script>
     <script src="dist/components/related-profiles/related-profiles.js"></script>
     <script src="dist/components/related-stats/related-stats.js"></script>