Add DHCP Dialog 30/52830/1
authorElisha Oren <elisha.oren@hpe.com>
Thu, 26 Jan 2017 16:27:10 +0000 (18:27 +0200)
committerElisha Oren <elisha.oren@hpe.com>
Sun, 5 Mar 2017 12:23:37 +0000 (14:23 +0200)
Change-Id: Ifc359bfb2ba719133d8119e5d40b91b79e027dda
Signed-off-by: Elisha Oren <elisha.oren@hpe.com>
dlux/cpeui/cpeui-module/src/main/resources/cpeui/admin.tpl.html
dlux/cpeui/cpeui-module/src/main/resources/cpeui/cpeui.controller.js
dlux/cpeui/cpeui-module/src/main/resources/cpeui/dialogs/DHCP.tpl.html [new file with mode: 0644]
dlux/cpeui/cpeui-module/src/main/resources/cpeui/dialogs/LinkIpvcUni.tpl.html
dlux/cpeui/cpeui-module/src/main/resources/cpeui/services/cpeui.dialogs.js
dlux/cpeui/cpeui-module/src/main/resources/cpeui/services/cpeui.services.js
dlux/cpeui/cpeui-module/src/main/resources/cpeui/services/utils.js
dlux/cpeui/cpeui-module/src/main/resources/cpeui/static/cpeui-custom.css
dlux/cpeui/cpeui-module/src/main/resources/cpeui/tenant.controller.js
dlux/cpeui/cpeui-module/src/main/resources/cpeui/tenant.tpl.html

index e4d30226c63170b0420de71caa673def497585c0..925695e88c37b32bbe8659ec0dbe3b429ada766d 100644 (file)
                                ng-click="setTab('admin',3);updateView()"><a href="#/cpeui/admin/unis">
                                 <i class="icon-exchange"></i> UNIs</a>
                         </li>
-                        <li ng-class="{ active: isTabSet('admin',4)}"
-                               ng-click="setTab('admin',4);updateNetworksView()"><a href="#/cpeui/admin/networks">
-                               <i class="icon-signal"></i> Networks</a>
-                        </li>
                         <li ng-class="{ active: isTabSet('admin',5)}" ng-click="setTab('admin',5);updateProfilesView()">
                                <a href="#/cpeui/admin/profiles"><i class="icon-book"></i> Bandwidth Profiles</a>
                         </li>
                        </tbody>
                </table>
        </div>
-       <div ng-show="isTabSet('admin',4)">
-               <div class="table-header">Networks</div>
-               <table class="footable table table-striped">
-                       <thead>
-                               <tr>
-                                       <th>Network ID</th>
-                                       <th>Network name</th>
-                                       <th>Tenant</th>
-                               </tr>
-                       </thead>
-                       <tbody>
-                               <tr ng-repeat="svc in services ">                                       
-                                       <td class="minimal-width">{{ svc['svc-id'] }}</td>
-                                       <td class="minimal-width">{{ networkNames[svc['svc-id']] }}</td>                                        
-                                       <td ng-if="svc['tenant-id']" class="minimal-width">{{ svc['tenant-id'] }}</td>
-                                       <td ng-if="!(svc['tenant-id'])" class="minimal-width">
-                                       <md-input-container class="md-block">
-                                                       <label>Assign Tenant</label>
-                                               <md-select ng-change="assignNetworkToTenant(svc)" ng-model="selectedTenant[svc['svc-id']]" name="selectedTenant">
-                                                       <md-option ng-repeat="tenant in tenantArray" value="{{ tenant.name }}">{{ tenant.name }}</md-option>
-                                               </md-select>
-                                       </md-input-container>
-                                       </td>
-                               </tr>
-                       </tbody>
-               </table>                
-       </div>
        <div ng-show="isTabSet('admin',5)">
                <div class="table-header">Bandwidth Profiles</div>
                <table class="footable table table-striped">
index 046e45786093d21c08619074ae98fd51f8897057..709cb110df790c5d21495c46540b532c50ae9c99 100644 (file)
@@ -24,7 +24,8 @@ define([].concat(modules).concat(services).concat(directives).concat(controllers
 
     $scope.tab = {
       tenantData : 1,
-      admin : 1
+      admin : 1,
+      L3subTable:0
     };
     var selectedTab = mainTabIndexs[$state.params.tabName];
     if (selectedTab != undefined) {
diff --git a/dlux/cpeui/cpeui-module/src/main/resources/cpeui/dialogs/DHCP.tpl.html b/dlux/cpeui/cpeui-module/src/main/resources/cpeui/dialogs/DHCP.tpl.html
new file mode 100644 (file)
index 0000000..ae596bd
--- /dev/null
@@ -0,0 +1,146 @@
+<md-dialog class="cpe-dialog" ng-cloak ng-init="dialogState='MAIN'">
+    <md-toolbar>
+      <div class="md-toolbar-tools">
+        <h2>Intranet {{dialogState=='MAIN' ? '- DHCP' : ''}}</h2>
+        <span flex></span>
+        <md-button class="md-icon-button" aria-label="Close dialog" ng-click="cancel()">
+        <i class="icon-remove-sign"></i>
+        </md-button>
+      </div>
+    </md-toolbar>
+    <md-dialog-content>
+    <div layout="column" ng-cloak>
+        <md-content layout-padding ng-show="dialogState=='MAIN'">
+                <form id="dnsForm" name="dnsForm" novalidate>
+                    <div layout="row" id="dnsInputs">
+                        <md-input-container class="md-block">
+                        <label>Primary DNS Server</label>
+                            <input type="text" required name="primaryDns" ng-model="obj.primaryDns" ng-pattern="/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/" />
+                            <div ng-messages="dnsForm.primaryDns.$error">
+                                  <div ng-message="required">IP is required!</div>
+                                  <div ng-message="pattern">IP is required! (ex. 127.0.0.1)</div>
+                            </div>
+                        </md-input-container>
+                        <md-input-container class="md-block">
+                        <label>Secondary DNS Server</label>
+                            <input type="text" required name="secondaryDns" ng-model="obj.secondaryDns" ng-pattern="/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/" />
+                            <div ng-messages="dnsForm.secondaryDns.$error">
+                                <div ng-message="required">IP is required!</div>
+                                <div ng-message="pattern">IP is required! (ex. 127.0.0.1)</div>
+                            </div>
+                        </md-input-container>
+                        <button class="btn btn-info" ng-click="setDNS(obj.primaryDns,obj.secondaryDns)" style="margin:8px"> Set DNS</button>
+                    </div>
+                </form>
+                       <md-input-container class="complexSelect md-block right" style="margin-top:0">
+                         <md-select md-container-class="complexSelect" ng-attr-disabled="{{getAvailableNetwork().length ? undefined : 'disabled' }}" name="networks" ng-model="selectedNetworks" md-selected-text="'Enable Networks'" multiple> <!-- md-on-close="updateEnabled()"> -->
+                             <md-checkbox style="margin: 11px" ng-checked="isAllSelected()" md-indeterminate="isPartialSelected()" ng-click="selectAll()"> Select All</md-checkbox>
+                             <div class="complexSelectOptions">
+                                 <md-option ng-repeat="u in getAvailableNetwork()" ng-value="u">{{u.mefUni['ip-address']}}</md-option>
+                             </div>
+                             <md-button class="btn btn-info" ng-click="updateEnabled()" style="background-color: orange;width: 90%;">Apply </md-button>
+                         </md-select>
+                       </md-input-container>
+                
+              <table class="footable table table-striped inner-table">
+                      <thead>
+                          <tr>
+                              <th>Network</th>
+                              <th>DNS Primary</th>
+                              <th>DNS Secondary</th>
+                              <th>Starting IP</th>
+                              <th>Ending IP</th>
+                              <th>Static Assignment</th>
+                              <th class="minimal-width"></th>
+                          </tr>
+                      </thead>
+                      <tbody>
+                          <tr ng-repeat="u in dhcps">
+                              <td> {{u.subnet}} </td>
+                              <td>{{u['dns-servers'][0]['dns-server']}}</td>
+                              <td>{{u['dns-servers'][1]['dns-server']}}</td>
+                              <td>{{u['allocate-from']}}</td>
+                              <td> {{u['allocate-to']}}</td>
+                              <td> <button type="button" class="btn btn-md btn-info" ng-click="openStaticAssigment(u)"> <i class="icon-tasks"></i> Open</button> </td>
+                              <td class="minimal-width" style="white-space: nowrap;">                              
+                              <button type="button" class="btn btn-md btn-danger" ng-click="removeDhcp(u.subnet)"> <i class="icon-trash"></i> </button>
+                              </td>
+                          </tr>
+                      </tbody>
+                  </table>
+        </md-content>
+        <md-content layout-padding ng-if="dialogState=='STATIC'">
+        <div layout="row" flex="100">
+            <div layout="column">
+                <div>DHCP - Assignment</div>
+                <div>Subnet {{focusedSubnet.subnet}}</div>
+                <div>From {{focusedSubnet['allocate-from']}}, To: {{focusedSubnet['allocate-to']}}</div>                
+            </div>                        
+        </div>
+        <form name="projectForm" novalidate ng-submit="addAllocation(projectForm, obj.mac, obj.ip)">
+              <table class="footable table table-striped inner-table">
+                      <thead>
+                          <tr>
+                              <th>Mac</th>
+                              <th>IP</th>
+                              <th class="minimal-width"><button type="button" class="btn btn-md btn-info right" ng-disabled="isAddingRow()" ng-click="setAddingRow(true)"> <i class="icon-plus"></i> </button></th>
+                          </tr>
+                      </thead>
+                      <tbody>
+                          <tr ng-if="isAddingRow()">
+                              <td style="padding-bottom: 0">
+                               <md-input-container>
+                                    <input type="text" required name="mac" ng-model="obj.mac" ng-pattern="/\b(?:[0-9a-fA-F][0-9a-fA-F]:){5}[0-9a-fA-F]{2}\b/"/>
+                                    <div ng-messages="projectForm.mac.$error">
+                                          <div ng-message="required">MAC is required!</div>
+                                          <div ng-message="pattern">MAC is required! (ex. AA:BB:CC:DD:EE:FF)</div>
+                                    </div>
+                                 </md-input-container>
+                              </td>
+                              <td style="padding-bottom: 0">
+                               <md-input-container>
+                                    <input type="text" required name="ip" ng-model="obj.ip" ng-pattern="/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/" />
+                                    <div ng-messages="projectForm.ip.$error">
+                                          <div ng-message="required">IP is required!</div>
+                                          <div ng-message="pattern">IP is required! (ex. 127.0.0.1)</div>
+                                    </div>
+                                 </md-input-container>
+                              </td>
+                              <td class="minimal-width" style="white-space: nowrap;">                              
+                                <button type="button" class="btn btn-md btn-danger" ng-click="setAddingRow(false)"> <i class="icon-trash"></i> </button>
+                                <button type="submit" class="btn btn-md btn-info"> <i class="icon-plus"></i> </button>
+                              </td>
+                          </tr>
+                          <tr ng-repeat="alloc in subnetAllocations | orderBy: 'mac'">
+                              <td ng-bind="alloc.mac"> </td>
+                              <td ng-bind="alloc['allocated-ip']"></td>
+                              <td class="minimal-width" style="white-space: nowrap;">                              
+                                <button type="button" class="btn btn-md btn-danger" ng-click="removeAllocation(focusedSubnet.subnet, alloc.mac)"> <i class="icon-trash"></i> </button>
+                              </td>
+                          </tr>
+                      </tbody>
+                  </table>
+                  </form>
+        </md-content>
+        <md-content class="confirmDialog" layout-padding ng-if="dialogState=='CONFIRM'">
+        <h2>Are You Sure?</h2>
+        <div>
+        <p ng-bind="confirmationMsg"></p>
+        </div>
+        </md-content>
+      </div>
+    </md-dialog-content>
+    <md-dialog-actions layout="row" ng-if="dialogState=='MAIN'">
+      <span flex></span>      
+      <md-button type="button" ng-click="cancel()">OK</md-button>
+    </md-dialog-actions>
+    <md-dialog-actions layout="row" ng-if="dialogState=='STATIC'">
+      <span flex></span>
+      <md-button type="button" ng-click="openMain()">Back</md-button>      
+    </md-dialog-actions>
+    <md-dialog-actions layout="row" ng-if="dialogState=='CONFIRM'">
+      <span flex></span>
+      <md-button type="button" ng-click="back()">Cancel</md-button>
+      <md-button type="button" ng-click="confirmed()">OK</md-button>
+    </md-dialog-actions>
+</md-dialog>
index b4ee2c0402d4c04dbf0f5b5d8bd4b80d05cfce48..8f7a6cf5977e1f011fae817f42d401947f1ec5d8 100644 (file)
         </md-select>
       </md-input-container>
       <md-input-container class="md-block">
-        <label>IP Uni</label>
-        <md-select ng-model="obj.ip_uni" name="ip_uni" ng-disabled="!obj.uni">
-                       <md-option ng-repeat="ipuni in obj.uni['ip-unis']['ip-uni'] " value="{{ ipuni['ip-uni-id'] }}" >{{ ipuni['ip-uni-id'] }} : {{ipuni['ip-address']}}{{ipuni.vlan ? (' (vlan: ' + ipuni.vlan+')') : ''}}</md-option>
-        </md-select>
+        <label>IP Uni Address</label>
+        <input type="text" required name="ipaddress" ng-model="obj['ip-address']" ng-pattern="/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[1-2]?[0-9]|3[0-2])\b/">
+        <div ng-messages="projectForm.ipaddress.$error">
+            <div ng-message="pattern">IP/Mask are required! (ex. 127.0.0.1/32)</div>
+        </div>
+      </md-input-container>
+      <md-input-container class="md-block">
+        <label>Vlan</label>
+        <input type="number" ng-required="hasVlans" name="vlan" ng-model="obj.vlan">
+        <div ng-messages="projectForm.vlan.$error" ng-if="hasVlans">
+            <div ng-message="required">Vlan is required when there are other ip-unis with vlans</div>
+        </div>
+      </md-input-container>
+      <md-input-container class="md-block">
+        <label>Segmentation ID</label>
+        <input type="number" name="segmentationid" ng-model="obj['segmentation-id']">
+        <div ng-messages="projectForm.segmentationid.$error">
+            <div ng-message="number">Number is required!</div>
+        </div>
       </md-input-container>
       <md-input-container class="md-block">
         <label>Bandwidth Profile</label>
index efe3bd1b8d8109ac95d5f05886dd4db605ea4647..a67f5bd0f0c3c7094e08fb010742dfa15f222bf7 100644 (file)
@@ -3,7 +3,7 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
   cpeui.factory('CpeuiDialogs', function($mdDialog, $mdMedia, CpeuiSvc) {
     var svc = {};
 
-    svc.Dialog = function(tpl, params, callback, customController) {
+    svc.Dialog = function(tpl, _params, callback, customController) {
 
       this.customFullscreen = $mdMedia('xs') || $mdMedia('sm');
 
@@ -32,6 +32,9 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
       };
 
       this.show = function(ev, params) {
+        if (_params) {
+            params = angular.merge(_params,params);
+        }
         $mdDialog.show({
           controller : this.dialogController,
           templateUrl : 'src/app/cpeui/dialogs/' + tpl + '.tpl.html',
index 5786d0bda6ce70ba62ba0d60c94261693313a687..3eb723c4d372af3732eea3d58509ac82c09584ce 100644 (file)
@@ -375,7 +375,7 @@ define(['app/cpeui/cpeui.module'],function(cpeui) {
             data:data
         }).then(function successCallback(response) {
             if (callback != undefined) {
-                callback();
+                callback(ipUniId);
             }
         });
     };
@@ -479,6 +479,149 @@ define(['app/cpeui/cpeui.module'],function(cpeui) {
       });
     };
 
+    // DHCP
+    svc.getServicesVrfId = function(svcid, callback) {
+        $http({
+            method:'GET',
+            url:"/restconf/operational/mef-services:mef-services/mef-service/"+svcid+"/ipvc"
+        }).then(function successCallback(response) {            
+            vrfId = response.data["ipvc"]["vrf-id"];            
+            if (callback != undefined) {
+                callback(vrfId);
+            }
+        }, function errorCallback(response) {
+            if (response.status == 404) {
+                callback({});
+            } else {
+                console.log(response);
+            }
+        });
+    };
+
+    svc.addDhcp = function(vrfid, subnet, fromIp, toIp, callback) {
+        var data = {"allocation-pool": {
+                        "subnet":subnet,
+                        "gateway":subnet.split('/')[0],
+                        "vrf-id":vrfid,
+                        "allocate-from": fromIp,
+                        "allocate-to":toIp
+                    }};
+        $http({
+            method:'POST',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid,
+            data:data
+        }).then(function successCallback(response) {            
+            if (callback != undefined) {
+                callback();
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+        });
+    }
+    
+    svc.removeDhcp = function(vrfid, subnet, callback) {        
+        $http({
+            method:'DELETE',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid + "/allocation-pool/" + window.encodeURIComponent(subnet)
+        }).then(function successCallback(response) {            
+            if (callback != undefined) {
+                callback();
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+        });
+    }
+    
+    svc.getDhcp = function(vrfid, callback) {        
+        $http({
+            method:'GET',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid
+        }).then(function successCallback(response) {       
+            var dhcps = {};
+            if (!response.data.vrf[0] || !response.data.vrf[0]['allocation-pool']){
+                callback({});
+                return;
+            }
+            response.data.vrf[0]['allocation-pool'].forEach(function(d){
+                dhcps[d.subnet] = d;
+            });
+            
+            if (callback != undefined) {
+                callback(dhcps);
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+        });
+    };
+    
+    svc.addDhcpStaticAllocation = function(vrfid, subnet, macAndIp, callback) {
+        
+        var data = {"allocation-instance": []};
+        
+        macAndIp.forEach(function(macIp){
+            data["allocation-instance"].push({
+                "mac":macIp[0],
+                "allocated-ip":macIp[1]
+            });
+        });
+        
+        $http({
+            method:'POST',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid + "/allocation/"+ window.encodeURIComponent(subnet),
+            data:data
+        }).then(function successCallback(response) {
+            if (callback != undefined) {
+                callback();
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+        });
+    };
+    
+    svc.getDhcpStaticAllocation = function(vrfid, subnet, callback) {
+        $http({
+            method:'GET',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid + "/allocation/"+ window.encodeURIComponent(subnet)
+        }).then(function successCallback(response) {
+            if (callback != undefined) {
+                callback(response.data["allocation"][0]["allocation-instance"]);
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+            callback([]);
+        });
+    };
+    
+    svc.removeDhcpStaticAllocation = function(vrfid, subnet, mac, callback) {
+        $http({
+            method:'DELETE',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid + "/allocation/"+ window.encodeURIComponent(subnet) +"/allocation-instance/"+window.encodeURIComponent(mac)
+        }).then(function successCallback(response) {
+            if (callback != undefined) {
+                callback();
+            }
+        }, function errorCallback(response) {
+            console.log(response);            
+        });
+    };
+    
+    svc.setDHCPDnsServers = function(vrfid, subnet, primaryDns, secondaryDns, callback){
+        var data = {"dns-servers":[
+                       {"dns-server":primaryDns},
+                       {"dns-server":secondaryDns}
+                   ]};
+        $http({
+            method:'POST',
+            url:"/restconf/config/dhcpi:dhcpi/vrf/" + vrfid + "/allocation-pool/"+ window.encodeURIComponent(subnet),
+            data:data
+        }).then(function successCallback(response) {
+            if (callback != undefined) {
+                callback();
+            }
+        }, function errorCallback(response) {
+            console.log(response);
+        });
+    };
 
     // EVCs
     function getJsonUnis(unis) {
@@ -492,7 +635,6 @@ define(['app/cpeui/cpeui.module'],function(cpeui) {
 
     svc.addEvc = function(evc, evc_type, tenant, callback) {
             var uni_json = getJsonUnis(evc.unis);
-//            preserved-vlan
             if (evc['svc-id']) {
                 var evcId = evc['svc-id'];
             } else {
index ff10fa13ea7e5eba90a0aec18550af9b1fd6cf87..5b3cd503eea71b93b1c8325fb80b56870b6aef7e 100644 (file)
@@ -15,6 +15,31 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
       svc.randomId = function () {
           return Math.floor(Math.random() * Math.pow(2, 31));
       };
+      
+      
+      svc.getSubnetEdges = function(subnet) {
+          var ip = subnet.split('/')[0];
+          var mask = subnet.split('/')[1];
+          var ipParts = ip.split('.');
+          var ipValue = Number(ipParts[0]) * Math.pow(2,24) + Number(ipParts[1]) * Math.pow(2,16) + Number(ipParts[2]) * Math.pow(2,8) + Number(ipParts[3]);
+          var minIP = (ipValue & (~(Math.pow(2,32-mask)-1))) + 1;
+          var byte1 = ( minIP >>> 24 );
+          var byte2 = ( minIP >>> 16 ) & 255;
+          var byte3 = ( minIP >>>  8 ) & 255;
+          var byte4 = minIP & 255;
+          minIP =  ( byte1 + '.' + byte2 + '.' + byte3 + '.' + byte4 );
+          
+          var maxIP = (ipValue | ((Math.pow(2,32-mask)-1))) -1;
+          byte1 = ( maxIP >>> 24 );
+          byte2 = ( maxIP >>> 16 ) & 255;
+          byte3 = ( maxIP >>>  8 ) & 255;
+          byte4 = maxIP & 255;
+          maxIP =  ( byte1 + '.' + byte2 + '.' + byte3 + '.' + byte4 );
+          
+          return [minIP, maxIP];
+          
+      }
+      
       return svc;
   });
 
index a1b945d60475273ca3246e86474cd6aa00a29ac7..ed3e7f012a577ed093562e501bee53ef5e9e1919 100644 (file)
@@ -91,6 +91,7 @@ MD-SELECT-MENU MD-OPTION div, MD-SELECT-VALUE SPAN, MD-SELECT-VALUE SPAN * {
 
 MD-DIALOG {
        min-width: 30% !important;
+       width: initial;
 }
 
 .no-error-spacer .md-errors-spacer {
@@ -173,4 +174,30 @@ I.expand-btn {
 I.expand-btn:focus {
     outline: 0;
     border: none;
+}
+#dnsInputs {
+    padding-bottom: 0;
+}
+#dnsInputs md-input-container {
+    padding-bottom: 0 !important;
+    margin-top: 0;
+    margin-bottom: 0;
+    margin-right: 16px;
+}
+#dnsForm {
+       padding-top:16px;
+       padding-bottom:0;
+}
+.confirmDialog {
+       background-color: #414040;
+}
+.confirmDialog P, .confirmDialog h2 {
+       color: white;
+}
+.complexSelect md-select-menu, .complexSelect md-content{
+       max-height:300px;
+}
+.complexSelectOptions {
+       overflow-y: scroll;
+       max-height:170px;
 }
\ No newline at end of file
index a231654ed7032953932ecc5a8e8d992d40275983..6767e308a052ba494ee7d468cda995e33c97543d 100644 (file)
@@ -1,5 +1,5 @@
 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
-  cpeui.register.controller('OpenTenantCtrl', function($scope, CpeuiSvc, CpeuiDialogs, $stateParams) {
+  cpeui.register.controller('OpenTenantCtrl', function($scope, CpeuiSvc, CpeuiDialogs, CpeUiUtils, $stateParams) {
 
     $scope.curTenant = $stateParams.tenantid;
     $scope.unisTables = {};
@@ -21,7 +21,7 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
     var tabIndexs = {
         "inventory" : 0,
         "L2" : 1,
-        "L3" : 2,
+        "L3" : 2
       }
     if ($stateParams.tenantTabName in tabIndexs) {
       $scope.tab.tenantData = tabIndexs[$stateParams.tenantTabName];
@@ -243,10 +243,12 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
 
     $scope.linkIpvcUniDialog = new CpeuiDialogs.Dialog('LinkIpvcUni', {},
         function(obj) {
-          CpeuiSvc.addIpvcUni(obj.svc_id, obj.uni['uni-id'], obj.ip_uni, obj.profile_name,
+        CpeuiSvc.addIpUni(obj.uni['uni-id'], obj['ip-address'], obj.vlan, obj['segmentation-id'], function(ipUniId) {
+          CpeuiSvc.addIpvcUni(obj.svc_id, obj.uni['uni-id'], ipUniId, obj.profile_name,
               function() {
-                $scope.updateEvcView();
+                  $scope.updateUnis($scope.updateEvcView);
               });
+            });
         });
 
     var ipUniDialogController = function($scope, $mdDialog) {
@@ -311,10 +313,6 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
         }
 
         $scope.done = function() {
-//            if (!angular.equals({},$scope.obj)){
-//                $scope.projectForm.$setSubmitted();
-//                return;
-//            }
             if (!$scope.toRemove && !$scope.toAdd) {
                 $mdDialog.hide();
                 return;
@@ -364,9 +362,155 @@ define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
                 if (mefUni.vlan) { u.vlan = mefUni.vlan };
             });
         }
-        new CpeuiDialogs.Dialog('StaticRouting', {}, function() {
+        new CpeuiDialogs.Dialog('StaticRouting', {"ipvc":ipvc, "subnets":angular.copy($scope.subnets)}, function() {
             $scope.updateEvcView();
-        }, staticRoutingController).show(undefined, {"ipvc":ipvc, "subnets":angular.copy($scope.subnets)});
+        }, staticRoutingController).show();
+    }
+    
+    
+    var dhcpDialogController = function($scope, $mdDialog, params) {
+        
+        $scope.selectedNetworks = [];
+        $scope.vrfid = params.vrfId;
+        $scope._isAddingRow = false;
+        
+        $scope.selectAll = function(){
+            if (!$scope.isAllSelected()){
+                $scope.selectedNetworks = $scope.getAvailableNetwork();                
+            } else {
+                $scope.selectedNetworks = [];                
+            }
+        };
+        $scope.isPartialSelected = function(){
+            return ($scope.selectedNetworks.length != 0) && ($scope.selectedNetworks.length != $scope.getAvailableNetwork().length);
+        };
+        $scope.isAllSelected = function(){
+            return ($scope.selectedNetworks.length ==  $scope.getAvailableNetwork().length);
+        };
+        
+        $scope.updateEnabled = function() {
+            $scope.selectedNetworks.forEach(function(u){
+                $scope.addDhcp(u.mefUni['ip-address']);
+            });
+            $scope.selectedNetworks = [];
+            $('md-backdrop').click();// close md-select dropdown
+        };
+        
+        $scope.openStaticAssigment = function(subnet) {            
+            $scope.focusedSubnet = subnet;
+            CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, subnet.subnet, function(allocations) {
+                $scope.subnetAllocations = allocations;
+                $scope.dialogState = 'STATIC';
+            });
+        };
+        $scope.openMain = function() {
+            $scope.dialogState = 'MAIN';
+        };
+        //confirmation
+        $scope.confirmationMsg = null;
+        $scope.okCallback = null;
+        $scope.previousState = null;
+
+        $scope.confirm = function(msg, okCallback) {
+            $scope.confirmationMsg = msg;
+            $scope.okCallback = okCallback;
+            $scope.previousState = $scope.dialogState;
+            $scope.dialogState = 'CONFIRM';
+        }
+        $scope.back = function() {
+            $scope.dialogState = $scope.previousState;
+        }
+        $scope.confirmed = function() {
+            $scope.okCallback()
+            $scope.dialogState = $scope.previousState;
+        }
+        
+        $scope.updateDhcpData = function() {
+            CpeuiSvc.getDhcp($scope.vrfid, function(dhcps){
+                $scope.dhcps = dhcps;
+                //$scope.params.ipvcUnis = $scope.params.ipvcUnis.filter(x => $scope.dhcps[x.mefUni['ip-address']] == undefined);
+            });
+        }
+        
+        $scope.getAvailableNetwork = function(){
+            if ($scope.dhcps !== undefined) {
+                return $scope.params.ipvcUnis.filter(x => $scope.dhcps[x.mefUni['ip-address']] == undefined);
+            } else {
+                return $scope.params.ipvcUnis;
+            }
+        }
+        
+        $scope.addDhcp = function(subnet) {
+            var edges = CpeUiUtils.getSubnetEdges(subnet);
+            CpeuiSvc.addDhcp($scope.vrfid, subnet, edges[0] ,edges[1],function(){
+                // TODO find a way to getDhcp only once, after the last add                
+                $scope.updateDhcpData();
+            });
+        }
+        
+        $scope.removeDhcp = function(subnet) {
+            $scope.confirm("This will delete this dhcp configuration",function(){
+                CpeuiSvc.removeDhcp($scope.vrfid, subnet, function(){
+                    $scope.updateDhcpData();
+                });
+            });
+        };
+        $scope.isAddingRow = function() {
+            return $scope._isAddingRow;
+        }
+        $scope.setAddingRow = function(val) {
+            $scope._isAddingRow = val;
+        }
+        $scope.addAllocation = function(form, mac, ip) {
+            if (form.$valid) {
+                CpeuiSvc.addDhcpStaticAllocation($scope.vrfid, $scope.focusedSubnet.subnet, [[mac,ip]], function(){
+                    CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, $scope.focusedSubnet.subnet, function(allocations) {
+                        $scope.subnetAllocations = allocations;
+                    });
+                });
+
+                // reset form
+                delete $scope.obj.mac;
+                delete $scope.obj.ip;
+                form.$setPristine();
+                form.$setUntouched();
+                $scope.setAddingRow(false);
+            }
+        }
+        
+        $scope.removeAllocation = function(subnet, mac) {
+            $scope.confirm("Are you sure you want to remove this allocation?",function(){
+                CpeuiSvc.removeDhcpStaticAllocation($scope.vrfid, subnet, mac, function(){
+                    CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, subnet, function(allocations) {
+                        $scope.subnetAllocations = allocations;
+                    });
+                });
+            });
+        };
+        
+        $scope.setDNS = function(primaryDns, secondaryDns) {
+            for (var i in $scope.dhcps) {
+                var allocPool = $scope.dhcps[i];
+                CpeuiSvc.setDHCPDnsServers($scope.vrfid, allocPool.subnet, primaryDns, secondaryDns, $scope.updateDhcpData);
+            };
+        }
+
+        $scope.updateDhcpData();
+    };
+    
+    $scope.openDhcpDialog = function(ipvc) {
+        CpeuiSvc.getServicesVrfId(ipvc['svc-id'],function(vrfId){            
+            params = {ipvc:ipvc,ipvcUnis:[],vrfId:vrfId};
+            if (ipvc.ipvc.unis && ipvc.ipvc.unis.uni) {            
+                params.ipvcUnis = angular.copy(ipvc.ipvc.unis.uni);
+                params.ipvcUnis.forEach(function(u){
+                    u.mefUni = $scope.getMefInterfaceIpvc(u['uni-id'],u['ip-uni-id']);
+                });
+            }
+            new CpeuiDialogs.Dialog('DHCP', params, function() {
+                $scope.updateEvcView();
+            }, dhcpDialogController).show();
+        });
     }
 
     $scope.ipUniSubnetDialog = new CpeuiDialogs.Dialog('AddIpUniSubnet', {}, function(obj) {
index 316c2f5f96732af2c561f542c2ff1fbb7bddb0ee..0ad3664701de9874b58c4058fb55c362c0607294 100644 (file)
                     <tr>
                         <th class="minimal-width">Service ID</th>
                         <th class="minimal-width">Service Name</th>
-                        <th>Service Endpoints</th>
+                        <th>Service Endpoints</th>                        
                         <th class="minimal-width">
                             <button class="btn btn-md btn-info right" ng-click="ipvcDialog.show($event,{'svcTypes':svcTypes})">
                                 <i class="icon-plus"></i>
                 </thead>
                 <tbody id="l2_table">
                     <tr ng-repeat="ipvc in ipvcs | orderBy : 'name'">
-                        <td class="minimal-width">{{ ipvc['svc-id'] }}</td>
-                        <td class="minimal-width">{{ ipvc['name'] }}</td>
+                        <td class="minimal-width">{{ ipvc.ipvc['ipvc-id'] }}</td>
+                        <td class="minimal-width">{{ ipvc['name'] }}</td>                        
                         <td>
                             <table class="footable table table-striped inner-table" ng-if="ipvc.ipvc.unis.uni" ng-init="expandFlags.L3[ipvc.ipvc['ipvc-id']] = true">
                                 <thead ng-if="!expandFlags.L3[ipvc.ipvc['ipvc-id']]">
                                                                <md-menu-item>
                                                                  <md-button ng-click="openRoutingDialog(ipvc)">Routing</md-button>
                                                                </md-menu-item>
-                                                               <!--
                                                                <md-menu-item>
-                                      <md-button>DHCP</md-button>
+                                      <md-button ng-click="openDhcpDialog(ipvc)">DHCP</md-button>
                                     </md-menu-item>
+                                                               <!--
                                     <md-menu-item>
                                       <md-button>NAT</md-button>
                                     </md-menu-item>