added new endpoint to retrieve user information and Updated tenant view

Change-Id: I93d00eb203bf7626221dc6e107fefa9f097d8011
diff --git a/views/ngXosLib/xosHelpers/spec/services/helpers/user-prefs.test.js b/views/ngXosLib/xosHelpers/spec/services/helpers/user-prefs.test.js
index 4c76484..7a00cc7 100644
--- a/views/ngXosLib/xosHelpers/spec/services/helpers/user-prefs.test.js
+++ b/views/ngXosLib/xosHelpers/spec/services/helpers/user-prefs.test.js
@@ -23,6 +23,7 @@
   describe('The xos.helper module', function(){
 
     describe('The XosUserPrefs service', () => {
+      let service, toscaBase, deffered, SiteSpy, rootScope;
 
       // load the application module
       beforeEach(module('xos.helpers', ($provide) => {
@@ -36,12 +37,19 @@
         spyOn(cookieMock, 'put').and.callThrough();
       }));
 
+      beforeEach(inject(($q, $rootScope) => {
+        rootScope = $rootScope;
+      }));
       it('should exists and have methods', () => {
         expect(service).toBeDefined();
         expect(service.getAll).toBeDefined();
         expect(service.setAll).toBeDefined();
         expect(service.getSynchronizerNotificationStatus).toBeDefined();
         expect(service.setSynchronizerNotificationStatus).toBeDefined();
+        expect(service.setUserDetailsCookie).toBeDefined();
+        expect(service.getUserDetailsCookie).toBeDefined();
+        expect(service.setDataUser).toBeDefined()
+
       });
 
       describe('the getAll method', () => {
@@ -67,6 +75,9 @@
                 first: true,
                 second: false
               }
+            },
+            userData: {
+              userId:1
             }
           }
           cookies.xosUserPrefs = JSON.stringify(syncNotification);
@@ -83,6 +94,15 @@
           });
         });
 
+        describe('the getUserDetailsCookie method', () => {
+          it('should return current user id', (done) => {
+            service.getUserDetailsCookie().$promise.then((res) => {
+              expect(res.userId).toEqual(syncNotification.userData.userId);
+              done();
+            });
+            rootScope.$apply();
+          });
+        });
         describe('the setSynchronizerNotificationStatus', () => {
           
           it('should throw an error if called without synchronizer name', () => {
@@ -98,7 +118,7 @@
             expect(service.getSynchronizerNotificationStatus('first')).toEqual(true);
 
             // should persist the change
-            expect(cookieMock.put).toHaveBeenCalledWith('xosUserPrefs', '{"synchronizers":{"notification":{"first":true,"second":true}}}');
+            expect(cookieMock.put).toHaveBeenCalledWith('xosUserPrefs', '{"synchronizers":{"notification":{"first":true,"second":true}},"userData":{"userId":1}}');
           });
 
           it('should handle empty cookies', () => {
@@ -108,6 +128,39 @@
           });
         });
       });
+      describe('the userdetails status', () => {
+        let syncNotification;
+        beforeEach(() => {
+          syncNotification = {
+            synchronizers: {
+              notification: {
+                first: true,
+                second: false
+              }
+            }
+          }
+          cookies.xosUserPrefs = JSON.stringify(syncNotification);
+        });
+        const userData = {
+          userId: 1
+        };
+        beforeEach(inject(($q,Me) => {
+          deffered= $q.defer();
+          spyOn(Me, 'get').and.callFake(function(){
+            return {$promise: deffered.promise};
+          });
+        }));
+        describe('the getUserDetailsCookie method', () => {
+          it('should return current user id', (done) => {
+            service.getUserDetailsCookie().$promise.then((res) => {
+              expect(res.userId).toEqual(userData.userId);
+              done();
+            });
+            deffered.resolve(userData);
+            rootScope.$apply();
+          });
+        });
+      });
     });
   });
 })();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/helpers/user-prefs.service.js b/views/ngXosLib/xosHelpers/src/services/helpers/user-prefs.service.js
index 7bf8ae1..bb8a810 100644
--- a/views/ngXosLib/xosHelpers/src/services/helpers/user-prefs.service.js
+++ b/views/ngXosLib/xosHelpers/src/services/helpers/user-prefs.service.js
@@ -1,95 +1,164 @@
-(function () {
-  
-  angular.module('xos.helpers')
-
-  /**
-  * @ngdoc service
-  * @name xos.helpers.XosUserPrefs
-  * @description
-  * This service is used to store the user preferences in cookies, so that they survive to page changes.
-  * The structure of the user preference is:
-  * ```
-  * {
-  *   synchronizers: {
-  *     notification: {
-  *       'volt': boolean,
-  *       'openstack': boolean,
-  *       ...
-  *     }
-  *   }
-  * }
-  * ```
-  **/
-
-  .service('XosUserPrefs', function($cookies){
-
-    let userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {};
-
-    /**
-    * @ngdoc method
-    * @name xos.helpers.XosUserPrefs#getAll
-    * @methodOf xos.helpers.XosUserPrefs
-    * @description
-    * Return all the user preferences stored in cookies
-    * @returns {object} The user preferences
-    **/
-    this.getAll = () => {
-      userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {};
-      return userPrefs;
-    };
-
-    /**
-    * @ngdoc method
-    * @name xos.helpers.XosUserPrefs#setAll
-    * @methodOf xos.helpers.XosUserPrefs
-    * @description
-    * Override all user preferences
-    * @param {object} prefs The user preferences
-    **/
-    this.setAll = (prefs) => {
-      $cookies.put('xosUserPrefs', angular.toJson(prefs));
-    };
-
-    /**
-    * @ngdoc method
-    * @name xos.helpers.XosUserPrefs#getSynchronizerNotificationStatus
-    * @methodOf xos.helpers.XosUserPrefs
-    * @description
-    * Return the synchronizer notification status, if name is not provided return the status for all synchronizers
-    * @param {string=} prefs The synchronizer name
-    * @returns {object | string} The synchronizer status
-    **/
-    this.getSynchronizerNotificationStatus = (name = false) => {
-      if(name){
-        return this.getAll().synchronizers.notification[name];
-      }
-      return this.getAll().synchronizers.notification;
-    };
-
-    /**
-    * @ngdoc method
-    * @name xos.helpers.XosUserPrefs#setSynchronizerNotificationStatus
-    * @methodOf xos.helpers.XosUserPrefs
-    * @description
-    * Update the notification status for a single synchronizer
-    * @param {string} name The synchronizer name
-    * @param {boolean} value The notification status (true means that it has been sent)
-    **/
-    this.setSynchronizerNotificationStatus = (name = false, value) => {
-      if(!name){
-        throw new Error('[XosUserPrefs] When updating a synchronizer is mandatory to provide a name.')
-      }
-
-      let cookies = this.getAll();
-
-      if(!cookies.synchronizers){
-        cookies.synchronizers = {
-          notification: {}
-        }
-      }
-
-      cookies.synchronizers.notification[name] = value;
-      this.setAll(cookies);
-    }
-  });
+(function () {

+  

+  angular.module('xos.helpers')

+

+  /**

+  * @ngdoc service

+  * @name xos.helpers.XosUserPrefs

+  * @description

+  * This service is used to store the user preferences in cookies, so that they survive to page changes.

+  * The structure of the user preference is:

+  * ```

+  * {

+  *   synchronizers: {

+  *     notification: {

+  *       'volt': boolean,

+  *       'openstack': boolean,

+  *       ...

+  *     }

+  *   }

+  *   userData: {

+  *     current_user_site_id: Number,

+  *     current_user_site_user_names: Array[1],

+  *     ...

+  *     }

+  * }

+  * ```

+  **/

+

+  .service('XosUserPrefs', function($cookies, Me, $q){

+

+    let userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {};

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#getAll

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Return all the user preferences stored in cookies

+    * @returns {object} The user preferences

+    **/

+    this.getAll = () => {

+      userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {};

+      return userPrefs;

+    };

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#setAll

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Override all user preferences

+    * @param {object} prefs The user preferences

+    **/

+    this.setAll = (prefs) => {

+      $cookies.put('xosUserPrefs', angular.toJson(prefs));

+    };

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#getSynchronizerNotificationStatus

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Return the synchronizer notification status, if name is not provided return the status for all synchronizers

+    * @param {string=} prefs The synchronizer name

+    * @returns {object | string} The synchronizer status

+    **/

+    this.getSynchronizerNotificationStatus = (name = false) => {

+      if(name){

+        return this.getAll().synchronizers.notification[name];

+      }

+      return this.getAll().synchronizers.notification;

+    };

+

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#getUserDetailsCookie

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Return all the user details stored in cookies or call the service

+    * @returns {object} The user details

+    **/

+    this.getUserDetailsCookie = () => {

+      var defer = $q.defer();

+      let localPref  = this.getAll();

+      if(!localPref.userData){

+        this.setUserDetailsCookie(localPref).$promise.then((data)=>{

+          defer.resolve(data);

+        });

+      }

+      else{

+        defer.resolve(localPref.userData);

+      }

+      return {$promise: defer.promise};

+    };

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#setDataUser

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Return all the user details from the endpoint (api/utility/me)

+    * @returns {object} The user details

+    **/

+

+    this.setDataUser = ()=>{

+      //var deff = $q.defer();

+      return Me.get().$promise;

+

+    };

+

+    /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#setUserDetailsCookie

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Save the user details in the cookie

+    * @param {object} details stored in cookie

+    * @param {objects} returns the user details as a promise

+    **/

+    this.setUserDetailsCookie = (localPref = localPref)=> {

+

+      var defer = $q.defer();

+      this.setDataUser().then((user)=>{

+        this.model = user;

+        defer.resolve(this.model);

+      }).then(() => {

+        localPref.userData = this.model.data;

+        this.setAll(localPref);

+      })

+      .catch ((e) => {

+        defer.reject(e);

+        throw new Error(e);

+      });

+      return {$promise: defer.promise};

+    }

+

+     /**

+    * @ngdoc method

+    * @name xos.helpers.XosUserPrefs#setSynchronizerNotificationStatus

+    * @methodOf xos.helpers.XosUserPrefs

+    * @description

+    * Update the notification status for a single synchronizer

+    * @param {string} name The synchronizer name

+    * @param {boolean} value The notification status (true means that it has been sent)

+    **/

+

+    this.setSynchronizerNotificationStatus = (name = false, value) => {

+      if(!name){

+        throw new Error('[XosUserPrefs] When updating a synchronizer is mandatory to provide a name.')

+      }

+

+      let cookies = this.getAll();

+

+      if(!cookies.synchronizers){

+        cookies.synchronizers = {

+          notification: {}

+        }

+      }

+      cookies.synchronizers.notification[name] = value;

+      this.setAll(cookies);

+    }

+  });

 })();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Me.js b/views/ngXosLib/xosHelpers/src/services/rest/Me.js
new file mode 100644
index 0000000..ff77060
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Me.js
@@ -0,0 +1,26 @@
+(function() {

+  'use strict';

+

+  angular.module('xos.helpers')

+  /**

+  * @ngdoc service

+  * @name xos.helpers.Me

+  * @description Http read-only api to fetch /api/utility/me/

+  **/

+  .service('Me', function($q,$http){

+

+    this.get = () => {

+      let deferred = $q.defer();

+

+      $http.get('/api/utility/me/')

+      .then(res => {

+        deferred.resolve(res);

+      })

+      .catch(e => {

+        deferred.reject(e);

+      });

+      return deferred.promise;

+

+    };

+  })

+})();
\ No newline at end of file
diff --git a/views/ngXosViews/tenant/spec/sample.test.js b/views/ngXosViews/tenant/spec/sample.test.js
index 3bd610b..ba28499 100644
--- a/views/ngXosViews/tenant/spec/sample.test.js
+++ b/views/ngXosViews/tenant/spec/sample.test.js
@@ -13,7 +13,7 @@
     httpBackend.whenGET('/api/core/sites/?no_hyperlinks=1').respond(200, []);
     // Setting up mock request
     scope = $rootScope.$new();
-    element = angular.element('<users-list></users-list>');
+    element = angular.element('<site-list></site-list>');
     $compile(element)(scope);
     scope.$digest();
     isolatedScope = element.isolateScope().vm;
diff --git a/views/ngXosViews/tenant/src/index.html b/views/ngXosViews/tenant/src/index.html
index e1a83d4..d647aa5 100644
--- a/views/ngXosViews/tenant/src/index.html
+++ b/views/ngXosViews/tenant/src/index.html
@@ -33,4 +33,6 @@
 <!-- inject:js -->
 <script src="/../../../xos/core/xoslib/static/js/vendor/ngXosHelpers.js"></script>
 <script src="/.tmp/main.js"></script>
+<script src="/.tmp/sitedetail.js"></script>
+<script src="/.tmp/createslice.js"></script>
 <!-- endinject -->
\ No newline at end of file
diff --git a/views/ngXosViews/tenant/src/js/createslice.js b/views/ngXosViews/tenant/src/js/createslice.js
new file mode 100644
index 0000000..933542e
--- /dev/null
+++ b/views/ngXosViews/tenant/src/js/createslice.js
@@ -0,0 +1,278 @@
+/**

+ * Created by arpit on 7/7/2016.

+ */

+'use strict';

+

+angular.module('xos.tenant')

+.directive('createSlice', function(){

+  return {

+    //sites : {},

+    restrict: 'E',

+    scope: {},

+    bindToController: true,

+    controllerAs: 'cs',

+    templateUrl: 'templates/createslice.html',

+    controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state, $q, XosUserPrefs){

+      this.config = {

+        exclude: ['site', 'password', 'last_login', 'mount_data_sets', 'default_flavor', 'creator', 'exposed_ports', 'networks', 'omf_friendly', 'omf_friendly', 'no_sync', 'no_policy', 'lazy_blocked', 'write_protect', 'deleted', 'backend_status', 'backend_register', 'policed', 'enacted', 'updated', 'created', 'validators', 'humanReadableName'],

+        formName: 'SliceDetails',

+        feedback: {

+          show: false,

+          message: 'Form submitted successfully !!!',

+          type: 'success'

+        },

+        actions: [

+          {

+            label: 'Save',

+            icon: 'ok', // refers to bootstraps glyphicon

+            cb: (model, form) => { // receive the model

+              saveform(model, form).then(()=> {

+                $state.go('site', {id: this.model.site});

+              });

+            },

+            class: 'success'

+          },  {

+            label: 'Save and continue editing',

+            icon: 'ok', // refers to bootstraps glyphicon

+            cb: (model, form) => { // receive the model

+              saveform(model,form);

+            },

+            class: 'primary'

+          },

+          {

+            label: 'Save and add another',

+            icon: 'ok', // refers to bootstraps glyphicon

+            cb: (model, form) => {

+              saveform(model,form).then(()=> {

+                $state.go('createslice',{site : this.model.site,id : ''});

+              });

+            },

+            class: 'primary'

+          }

+        ],

+        fields:

+        {

+          site: {

+            label: 'Site',

+            type: 'select',

+            validators: { required: true},

+            hint: 'The Site this Slice belongs to',

+            options: []

+

+          },

+          name: {

+            label: 'Name',

+            type: 'string',

+            hint: 'The Name of the Slice',

+            validators: {

+              required: true

+            }

+          },

+          serviceClass: {

+            label: 'ServiceClass',

+            type: 'select',

+            validators: {required: true},

+            hint: 'The Site this Slice belongs to',

+            options: [

+              {

+                id: 1,

+                label: 'Best effort'

+              }

+            ]

+          },

+          enabled: {

+            label: 'Enabled',

+            type: 'boolean',

+            hint: 'Status for this Slice'

+          },

+          description: {

+            label: 'Description',

+            type: 'string',

+            hint: 'High level description of the slice and expected activities',

+            validators: {

+              required: false,

+              minlength: 10

+            }

+          },

+          service: {

+            label: 'Service',

+            type: 'select',

+            validators: { required: false},

+            options: [

+              {

+                id: 0,

+                label: '--------'

+              }

+            ]

+          },

+          slice_url: {

+            label: 'Slice url',

+            type: 'string',

+            validators: {

+              required: false,

+              minlength: 10

+            }

+          },

+          max_instances: {

+            label: 'Max Instances',

+            type: 'number',

+            validators: {

+              required: false,

+              min: 0

+            }

+          },

+          default_isolation: {

+            label: 'Default Isolation',

+            type: 'select',

+            validators: { required: false},

+            options: [

+              {

+                id: 'vm',

+                label: 'Virtual Machine'

+              },

+              {

+                id: 'container',

+                label: 'Container'

+              },

+              {

+                id: 'container_vm',

+                label: 'Container in VM'

+              }

+            ]

+          },

+          default_image: {

+            label: 'Default image',

+            type: 'select',

+            validators: { required: false},

+            options: []

+          },

+          network: {

+            label: 'Network',

+            type: 'select',

+            validators: { required: false},

+            options: [

+              {

+                id: 'default',

+                label: 'Default'

+              },

+              {

+                id: 'host',

+                label: 'Host'

+              },

+              {

+                id: 'bridged',

+                label: 'Bridged'

+              },

+              {

+                id: 'noauto',

+                label: 'No Automatic Networks'

+              }

+            ]

+          }

+

+        }

+      };

+      var data;

+      Images.query().$promise

+          .then((users) => {

+            this.users = users;

+            data = this.users;

+            this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});

+            this.config.fields['default_image'].options = this.optionValImg;

+          })

+          .catch((e) => {

+            throw new Error(e);

+          });

+

+      // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}

+      this.setData = (data, fields) => {

+        var i;

+        var retObj=[];

+        for(i = 0; i<data.length; i++){

+          var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};

+          retObj.push(optVal);

+

+        }

+        return retObj;

+      };

+

+      // retrieving user list

+

+      if ($stateParams.id)

+      {

+        delete this.config.fields['site'];

+        this.config.exclude.push('site');

+

+        Slices.get({id: $stateParams.id}).$promise

+          .then((users) => {

+            this.users = users;

+            data = users;

+

+            this.model = data;

+          })

+          .catch((e) => {

+            throw new Error(e);

+          });

+      }

+      else

+      {

+

+

+        this.model = {};

+        XosUserPrefs.getUserDetailsCookie().$promise

+        .then((userdata)=>{

+          this.model['creator'] =userdata.current_user_id;

+        })

+        .catch ((e) => {

+          throw new Error(e);

+        });

+

+        Sites.query().$promise

+        .then((users) => {

+          this.users_site = users;

+          this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});

+          this.config.fields['site'].options = this.optionVal;

+        })

+        .catch((e) => {

+          throw new Error(e);

+        });

+      }

+

+      var  saveform = (model,form) =>

+      { // receive the model

+        var deferred = $q.defer();

+        delete model.networks;

+        if (form.$valid )

+        {

+          if(model.id){

+            var pr = Slices.update(model).$promise;

+          }

+          else{

+            var pr = Slices.save(model).$promise;

+          }

+          pr.then((users) => {

+            this.model = users;

+            //data = users;

+            //this.model = this.users;

+            this.config.feedback.show = true;

+            deferred.resolve(this.model);

+          })

+          .catch((e) => {

+            this.config.feedback.show = true;

+            this.config.feedback.type='danger';

+            if(e.data && e.data.detail )

+            {

+              this.config.feedback.message = e.data.detail;

+            }

+            else {

+              this.config.feedback.message=e.statusText;

+            }

+            deferred.reject(e);

+          });

+        }

+

+        return  deferred.promise;

+      }

+    }

+  };

+});
\ No newline at end of file
diff --git a/views/ngXosViews/tenant/src/js/main.js b/views/ngXosViews/tenant/src/js/main.js
index 7ed4af6..e3dd54a 100644
--- a/views/ngXosViews/tenant/src/js/main.js
+++ b/views/ngXosViews/tenant/src/js/main.js
@@ -1,418 +1,99 @@
-'use strict';
-
-angular.module('xos.tenant', [
-  'ngResource',
-  'ngCookies',
-  'ui.router',
-  'xos.helpers'
-])
-.config(($stateProvider) => {
-  $stateProvider
-  .state('user-list', {
-    url: '/',
-    template: '<users-list></users-list>'
-  })
-    .state('site', {
-      url: '/site/:id',
-      template: '<site-detail></site-detail>'
-
-    })
-    .state('createslice', {
-      url: '/site/:site/slice/:id?',
-      template: '<create-slice></create-slice>'
-
-    });
-})
-.config(function($httpProvider){
-  $httpProvider.interceptors.push('NoHyperlinks');
-})
-.directive('usersList', function(){
-  return {
-    //sites : {},
-    restrict: 'E',
-    scope: {},
-    bindToController: true,
-    controllerAs: 'vm',
-    templateUrl: 'templates/users-list.tpl.html',
-    controller: function(Sites, SlicesPlus){
-
-
-
-      this.tableConfig = {
-        columns: [
-          {
-            label: 'Site1',
-            prop: 'name',
-            link: item => `#/site/${item.id}`
-          },
-          {
-            label: 'Allocated',
-            prop: 'instance_total'
-          },
-          {
-            label: 'Ready',
-            prop: 'instance_total_ready'
-          }
-        ]
-      };
-
-      // retrieving user list
-      Sites.query().$promise
-      .then((users) => {
-        this.sites = users;
-        return  SlicesPlus.query().$promise
-      })
-      .then((users) => {
-        this.slices = users;
-        this.site_list = this.returnData(this.sites, this.slices);
-      })
-      .catch((e) => {
-        throw new Error(e);
-      });
-
-
-      this.returnData = (sites, slices) => {
-        var i, j=0;
-        var site_list=[];
-
-        for(i = 0; i<sites.length; i++){
-          var instance_t = 0;
-          var instance_t_r = 0;
-          for(j=0;j<slices.length;j++){
-            if (sites[i].id != null && slices[j].site !=null && sites[i].id === slices[j].site){
-              instance_t = instance_t + slices[j].instance_total;
-              instance_t_r = instance_t_r + slices[j].instance_total_ready;
-            }
-          }
-          var data_sites = {
-            'id': sites[i].id,
-            'name': sites[i].name,
-            'instance_total': instance_t,
-            'instance_total_ready': instance_t_r
-          };
-          site_list.push(data_sites);
-        }
-        return site_list;
-      }
-    }
-  };
-})
-.directive('siteDetail', function(){
-  return {
-    restrict: 'E',
-    scope: {},
-    bindToController: true,
-    controllerAs: 'sl',
-    templateUrl: 'templates/slicelist.html',
-    controller: function(SlicesPlus, $stateParams){
-      this.siteId  = $stateParams.id;
-      this.tableConfig = {
-        columns: [
-          {
-            label: 'Slice List',
-            prop: 'name',
-            link: item => `#/site/${item.site}/slice/${item.id}`
-          },
-          {
-            label: 'Allocated',
-            prop: 'instance_total'
-          },
-          {
-            label: 'Ready',
-            prop: 'instance_total_ready'
-          }
-        ]
-      };
-
-      // retrieving user list
-      SlicesPlus.query({
-        site: $stateParams.id
-      }).$promise
-      .then((users) => {
-        this.sliceList = users;
-      })
-      .catch((e) => {
-        throw new Error(e);
-      });
-    }
-  };
-})
-.directive('createSlice', function(){
-  return {
-    //sites : {},
-    restrict: 'E',
-    scope: {},
-    bindToController: true,
-    controllerAs: 'cs',
-    templateUrl: 'templates/createslice.html',
-    controller: function(Slices, SlicesPlus, Sites, Images, $stateParams, $http, $state, $q){
-      this.config = {
-        exclude: ['site', 'password', 'last_login', 'mount_data_sets', 'default_flavor', 'creator', 'exposed_ports', 'networks', 'omf_friendly', 'omf_friendly', 'no_sync', 'no_policy', 'lazy_blocked', 'write_protect', 'deleted', 'backend_status', 'backend_register', 'policed', 'enacted', 'updated', 'created', 'validators', 'humanReadableName'],
-        formName: 'SliceDetails',
-        feedback: {
-          show: false,
-          message: 'Form submitted successfully !!!',
-          type: 'success'
-        },
-        actions: [
-          {
-            label: 'Save',
-            icon: 'ok', // refers to bootstraps glyphicon
-            cb: (model, form) => { // receive the model
-              saveform(model, form).then(()=> {
-                $state.go('site', {id: this.model.site});
-              });
-            },
-            class: 'success'
-          },  {
-            label: 'Save and continue editing',
-            icon: 'ok', // refers to bootstraps glyphicon
-            cb: (model, form) => { // receive the model
-              saveform(model,form);
-            },
-            class: 'primary'
-          },
-          {
-            label: 'Save and add another',
-            icon: 'ok', // refers to bootstraps glyphicon
-            cb: (model, form) => {
-              saveform(model,form).then(()=> {
-                $state.go('createslice',{site : this.model.site,id : ''});
-              });
-            },
-            class: 'primary'
-          }
-        ],
-        fields:
-        {
-          site: {
-            label: 'Site',
-            type: 'select',
-            validators: { required: true},
-            hint: 'The Site this Slice belongs to',
-            options: []
-
-          },
-          name: {
-            label: 'Name',
-            type: 'string',
-            hint: 'The Name of the Slice',
-            validators: {
-              required: true
-            }
-          },
-          serviceClass: {
-            label: 'ServiceClass',
-            type: 'select',
-            validators: {required: true},
-            hint: 'The Site this Slice belongs to',
-            options: [
-              {
-                id: 1,
-                label: 'Best effort'
-              }
-            ]
-          },
-          enabled: {
-            label: 'Enabled',
-            type: 'boolean',
-            hint: 'Status for this Slice'
-          },
-          description: {
-            label: 'Description',
-            type: 'string',
-            hint: 'High level description of the slice and expected activities',
-            validators: {
-              required: false,
-              minlength: 10
-            }
-          },
-          service: {
-            label: 'Service',
-            type: 'select',
-            validators: { required: false},
-            options: [
-              {
-                id: 0,
-                label: '--------'
-              }
-            ]
-          },
-          slice_url: {
-            label: 'Slice url',
-            type: 'string',
-            validators: {
-              required: false,
-              minlength: 10
-            }
-          },
-          max_instances: {
-            label: 'Max Instances',
-            type: 'number',
-            validators: {
-              required: false,
-              min: 0
-            }
-          },
-          default_isolation: {
-            label: 'Default Isolation',
-            type: 'select',
-            validators: { required: false},
-            options: [
-              {
-                id: 'vm',
-                label: 'Virtual Machine'
-              },
-              {
-                id: 'container',
-                label: 'Container'
-              },
-              {
-                id: 'container_vm',
-                label: 'Container in VM'
-              }
-            ]
-          },
-          default_image: {
-            label: 'Default image',
-            type: 'select',
-            validators: { required: false},
-            options: []
-          },
-          network: {
-            label: 'Network',
-            type: 'select',
-            validators: { required: false},
-            options: [
-              {
-                id: 'default',
-                label: 'Default'
-              },
-              {
-                id: 'host',
-                label: 'Host'
-              },
-              {
-                id: 'bridged',
-                label: 'Bridged'
-              },
-              {
-                id: 'noauto',
-                label: 'No Automatic Networks'
-              }
-            ]
-          }
-
-        }
-      };
-      var data;
-      Images.query().$promise
-          .then((users) => {
-            this.users = users;
-            data = this.users;
-            this.optionValImg = this.setData(data, {field1: 'id', field2: 'name'});
-            this.config.fields['default_image'].options = this.optionValImg;
-          })
-          .catch((e) => {
-            throw new Error(e);
-          });
-
-      // Use this method for select by seting object in fields variable of format { field1 : "val1", field2 : "val2"}
-      this.setData = (data, fields) => {
-        var i;
-        var retObj=[];
-        for(i = 0; i<data.length; i++){
-          var optVal = {id: data[i][fields.field1], label: data[i][fields.field2]};
-          retObj.push(optVal);
-
-        }
-        return retObj;
-      };
-
-      // retrieving user list
-
-      if ($stateParams.id)
-      {
-        delete this.config.fields['site'];
-        this.config.exclude.push('site');
-
-        Slices.get({id: $stateParams.id}).$promise
-          .then((users) => {
-            this.users = users;
-            data = users;
-
-            this.model = data;
-          })
-          .catch((e) => {
-            throw new Error(e);
-          });
-      }
-      else
-      {
-
-
-        this.model = {};
-        $http.get('/xoslib/tenantview/').
-        success((data) => {
-          this.userList = data;
-          this.model['creator'] = this.userList.current_user_id;
-
-        });
-
-
-
-
-
-
-        Sites.query().$promise
-      .then((users) => {
-        this.users_site = users;
-        this.optionVal = this.setData(this.users_site, {field1: 'id', field2: 'name'});
-        this.config.fields['site'].options = this.optionVal;
-        //= this.optionVal;
-
-      })
-      .catch((e) => {
-        throw new Error(e);
-      });
-
-      }
-
-      var  saveform = (model,form) =>
-      { // receive the model
-        var deferred = $q.defer();
-        delete model.networks;
-        if (form.$valid )
-        {
-          if(model.id){
-            var pr = Slices.update(model).$promise;
-          }
-          else{
-            var pr = Slices.save(model).$promise;
-          }
-          pr.then((users) => {
-            this.model = users;
-            //data = users;
-            //this.model = this.users;
-            this.config.feedback.show = true;
-            deferred.resolve(this.model);
-          })
-          .catch((e) => {
-            this.config.feedback.show = true;
-            this.config.feedback.type='danger';
-            if(e.data && e.data.detail )
-            {
-              this.config.feedback.message = e.data.detail;
-            }
-            else {
-              this.config.feedback.message=e.statusText;
-            }
-            deferred.reject(e);
-          });
-        }
-
-        return  deferred.promise;
-      }
-    }
-  };
-});
\ No newline at end of file
+'use strict';

+

+angular.module('xos.tenant', [

+  'ngResource',

+  'ngCookies',

+  'ui.router',

+  'xos.helpers'

+])

+.config(($stateProvider) => {

+  $stateProvider

+  .state('site-list', {

+    url: '/',

+    template: '<site-list></site-list>'

+  })

+    .state('site', {

+      url: '/site/:id',

+      template: '<site-detail></site-detail>'

+

+    })

+    .state('createslice', {

+      url: '/site/:site/slice/:id?',

+      template: '<create-slice></create-slice>'

+

+    });

+})

+.config(function($httpProvider){

+  $httpProvider.interceptors.push('NoHyperlinks');

+})

+.directive('siteList', function(){

+  return {

+    //sites : {},

+    restrict: 'E',

+    scope: {},

+    bindToController: true,

+    controllerAs: 'vm',

+    templateUrl: 'templates/users-list.tpl.html',

+    controller: function(Sites, SlicesPlus){

+

+

+

+      this.tableConfig = {

+        columns: [

+          {

+            label: 'Site',

+            prop: 'name',

+            link: item => `#/site/${item.id}`

+          },

+          {

+            label: 'Allocated',

+            prop: 'instance_total'

+          },

+          {

+            label: 'Ready',

+            prop: 'instance_total_ready'

+          }

+        ]

+      };

+

+      // retrieving user list

+      Sites.query().$promise

+      .then((users) => {

+        this.sites = users;

+        return  SlicesPlus.query().$promise

+      })

+      .then((users) => {

+        this.slices = users;

+        this.site_list = this.returnData(this.sites, this.slices);

+      })

+      .catch((e) => {

+        throw new Error(e);

+      });

+

+

+      this.returnData = (sites, slices) => {

+        var i, j=0;

+        var site_list=[];

+

+        for(i = 0; i<sites.length; i++){

+          var instance_t = 0;

+          var instance_t_r = 0;

+          for(j=0;j<slices.length;j++){

+            if (sites[i].id != null && slices[j].site !=null && sites[i].id === slices[j].site){

+              instance_t = instance_t + slices[j].instance_total;

+              instance_t_r = instance_t_r + slices[j].instance_total_ready;

+            }

+          }

+          var data_sites = {

+            'id': sites[i].id,

+            'name': sites[i].name,

+            'instance_total': instance_t,

+            'instance_total_ready': instance_t_r

+          };

+          site_list.push(data_sites);

+        }

+        return site_list;

+      }

+    }

+  };

+});

diff --git a/views/ngXosViews/tenant/src/js/sitedetail.js b/views/ngXosViews/tenant/src/js/sitedetail.js
new file mode 100644
index 0000000..c29a904
--- /dev/null
+++ b/views/ngXosViews/tenant/src/js/sitedetail.js
@@ -0,0 +1,46 @@
+/**

+ * Created by arpit on 7/7/2016.

+ */

+'use strict';

+

+angular.module('xos.tenant')

+.directive('siteDetail', function(){

+  return {

+    restrict: 'E',

+    scope: {},

+    bindToController: true,

+    controllerAs: 'sl',

+    templateUrl: 'templates/slicelist.html',

+    controller: function(SlicesPlus, $stateParams){

+      this.siteId  = $stateParams.id;

+      this.tableConfig = {

+        columns: [

+          {

+            label: 'Slice List',

+            prop: 'name',

+            link: item => `#/site/${item.site}/slice/${item.id}`

+          },

+          {

+            label: 'Allocated',

+            prop: 'instance_total'

+          },

+          {

+            label: 'Ready',

+            prop: 'instance_total_ready'

+          }

+        ]

+      };

+

+      // retrieving user list

+      SlicesPlus.query({

+        site: $stateParams.id

+      }).$promise

+      .then((users) => {

+        this.sliceList = users;

+      })

+      .catch((e) => {

+        throw new Error(e);

+      });

+    }

+  };

+});
\ No newline at end of file