Interceptor to fake non XOS data
diff --git a/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js b/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
index 9e6596e..314be5f 100644
--- a/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
+++ b/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
@@ -35,13 +35,49 @@
.service('Subscribers', function($resource, cordConfig){
return $resource(cordConfig.url + '/xoslib/rs/subscriber');
})
- .service('SubscriberUsers', function($resource, cordConfig){
+ .service('SubscriberUsers', function($resource, $filter, cordConfig, Helpers){
// TODO define an interceptor as res.users should be resources
// NOTE SubscriberId should ne retrieved from login information
return $resource(cordConfig.url + '/xoslib/rs/subscriber/:subscriberId/users/:id', {}, {
query: {
method: 'GET',
- isArray: false
+ isArray: false,
+ interceptor: {
+ response: function(res){
+ // this is used to fake some data that are not XOS related,
+ // but can be provided by any external services
+
+ // add an icon to the user
+ res.data.users.map(function(user){
+ console.log(user)
+ switch (user.name){
+ case 'Mom\'s PC':
+ user['icon_id'] = 'mom';
+ break
+ case 'Jack\'s Laptop':
+ user['icon_id'] = 'boy2';
+ break
+ case 'Jill\'s Laptop':
+ user['icon_id'] = 'girl1';
+ break
+ case 'Dad\'s PC':
+ user['icon_id'] = 'dad';
+ break
+ }
+
+ return user;
+ });
+
+ // add a random login date to the user
+ res.data.users.forEach(function(user){
+ if(!angular.isDefined(cordConfig.userActivity[user.id])){
+ var date = Helpers.randomDate(new Date(2015, 0, 1), new Date());
+ cordConfig.userActivity[user.id] = $filter('date')(date, 'mediumTime');
+ }
+ });
+ return res.data;
+ }
+ }
}
});
//return $resource(cordConfig.url + '/xoslib/corduser/:id')
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js b/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
index 60dea84..054c703 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
@@ -15,64 +15,59 @@
*/
(function () {
- 'use strict';
+ 'use strict';
- var urlSuffix = '/rs/bundle';
+ var urlSuffix = '/rs/bundle';
- var basic = 'basic',
- family = 'family';
+ var basic = 'basic',
+ family = 'family';
- angular.module('cordBundle', [])
- .controller('CordBundleCtrl', ['$log', '$scope', '$resource',
- function ($log, $scope, $resource) {
- var BundleData, resource,
- getData;
- $scope.page.curr = 'bundle';
- $scope.show = false;
+ angular.module('cordBundle', [])
+ .controller('CordBundleCtrl', function ($log, $scope, $resource, cordConfig) {
+ var BundleData, resource,
+ getData;
+ $scope.page.curr = 'bundle';
+ $scope.show = false;
- getData = function (id) {
- if (!id) { id = ''; }
+ // set the current bundle
+ $scope.name = cordConfig.bundles[cordConfig.activeBundle].name;
+ $scope.desc = cordConfig.bundles[cordConfig.activeBundle].desc;
+ $scope.funcs = cordConfig.bundles[cordConfig.activeBundle].functions;
- BundleData = $resource($scope.shared.url + urlSuffix + '/' + id);
- resource = BundleData.get({},
- // success
- function () {
- var current, availId;
- current = resource.bundle.id;
- $scope.name = resource.bundle.name;
- $scope.desc = resource.bundle.desc;
- $scope.funcs = resource.bundle.functions;
+ // set the available bundle
+ if(cordConfig.activeBundle === 0) {
+ $scope.available = cordConfig.bundles[1];
+ }
+ else{
+ $scope.available = cordConfig.bundles[0];
+ }
- availId = (current === basic) ? family : basic;
- resource.bundles.forEach(function (bundle) {
- if (bundle.id === availId) {
- // NOTE available should be an array
- $scope.available = bundle;
- }
- });
- },
- // error
- function () {
- $log.error('Problem with resource', resource);
- });
- };
+ // switching the bundles
+ $scope.changeBundle = function (id) {
+ if(cordConfig.activeBundle === 0){
+ cordConfig.activeBundle = 1;
+ $scope.available = cordConfig.bundles[0];
+ }
+ else{
+ cordConfig.activeBundle = 0;
+ $scope.available = cordConfig.bundles[1];
+ }
+ $scope.name = cordConfig.bundles[cordConfig.activeBundle].name;
+ $scope.desc = cordConfig.bundles[cordConfig.activeBundle].desc;
+ $scope.funcs = cordConfig.bundles[cordConfig.activeBundle].functions;
+ };
- getData();
+ // hiding and showing bundles
+ $scope.showBundles = function () {
+ $scope.show = !$scope.show;
+ };
- $scope.changeBundle = function (id) {
- getData(id);
- };
+ $log.debug('Cord Bundle Ctrl has been created.');
+ })
- $scope.showBundles = function () {
- $scope.show = !$scope.show;
- };
-
- $log.debug('Cord Bundle Ctrl has been created.');
- }])
-
- .directive('bundleAvailable', [function () {
- return {
- templateUrl: 'app/view/bundle/available.html'
- };
- }]);
+ .directive('bundleAvailable', [function () {
+ return {
+ templateUrl: 'app/view/bundle/available.html'
+ };
+ }]);
}());
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/home/home.js b/views/ngXosViews/subscriberPortal/src/app/view/home/home.js
index 60c3a94..454972c 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/home/home.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/home/home.js
@@ -19,12 +19,6 @@
var urlSuffix = '/rs/dashboard';
- function randomDate(start, end) {
- return new Date(
- start.getTime() + Math.random() * (end.getTime() - start.getTime())
- );
- }
-
angular.module('cordHome', [])
.controller('CordHomeCtrl', [
'$log', '$scope', '$resource', '$filter', 'cordConfig', 'SubscriberUsers', 'Helpers',
@@ -35,24 +29,8 @@
// NOTE subscriberId should be retrieved by login
SubscriberUsers.query({subscriberId: 1}).$promise
.then(function(res){
- $scope.bundle_name = cordConfig.bundles[0].name;
- $scope.bundle_desc = cordConfig.bundles[0].desc;
-
- // NOTE the loops creates data that are not available in xos should we move them in a service? Should we define a small backend to store this infos?
-
- // add an icon to the user
- res.users.map(function(user){
- user['icon_id'] = 'mom';
- return user;
- });
-
- // add a random login date to the user
- res.users.forEach(function(user){
- if(!angular.isDefined(cordConfig.userActivity[user.id])){
- var date = randomDate(new Date(2015, 0, 1), new Date());
- cordConfig.userActivity[user.id] = $filter('date')(date, 'mediumTime');
- }
- });
+ $scope.bundle_name = cordConfig.bundles[cordConfig.activeBundle].name;
+ $scope.bundle_desc = cordConfig.bundles[cordConfig.activeBundle].desc;
$scope.users = res.users;
})
.catch(function(){
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/user/user.js b/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
index f7450cb..bc75afd 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
@@ -22,16 +22,10 @@
family = 'family',
url_filter = 'url_filter';
- function randomDate(start, end) {
- return new Date(
- start.getTime() + Math.random() * (end.getTime() - start.getTime())
- );
- }
-
angular.module('cordUser', [])
.controller('CordUserCtrl', ['$log', '$scope', '$resource', '$timeout', '$filter', 'SubscriberUsers', 'cordConfig',
function ($log, $scope, $resource, $timeout, $filter, SubscriberUsers, cordConfig) {
- var BundleData, bundleResource;
+
$scope.page.curr = 'user';
$scope.isFamily = false;
$scope.newLevels = {};
@@ -43,35 +37,20 @@
// NOTE subscriberId should be retrieved by login
SubscriberUsers.query({subscriberId: 1}).$promise
.then(function(res){
- $scope.isFamily = cordConfig.bundles[0].id === 'family';
+ $scope.isFamily = cordConfig.bundles[cordConfig.activeBundle].id === 'family';
// if bundle is family search for url_filter level
if ($scope.isFamily) {
- angular.forEach(cordConfig.bundles[0].functions, function(fn){
+ angular.forEach(cordConfig.bundles[cordConfig.activeBundle].functions, function(fn){
if(fn.id === 'url_filter'){
$scope.levels = fn.params.levels;
}
});
}
- // NOTE the loops creates data that are not available in xos should we move them in a service? Should we define a small backend to store this infos?
-
- // add an icon to the user
- res.users.map(function(user){
- user['icon_id'] = 'mom';
- return user;
- });
-
- // add a random login date to the user
- res.users.forEach(function(user){
- if(!angular.isDefined(cordConfig.userActivity[user.id])){
- var date = randomDate(new Date(2015, 0, 1), new Date());
- cordConfig.userActivity[user.id] = $filter('date')(date, 'mediumTime');
- }
- });
$scope.users = res.users;
})
.catch(function () {
- $log.error('Problem with resource', bundleResource);
+ $log.error('Problem with resource', SubscriberUsers);
});
$scope.updateLevel = function(user){
diff --git a/views/ngXosViews/subscriberPortal/src/cord.js b/views/ngXosViews/subscriberPortal/src/cord.js
index f646be0..5406bd2 100644
--- a/views/ngXosViews/subscriberPortal/src/cord.js
+++ b/views/ngXosViews/subscriberPortal/src/cord.js
@@ -70,6 +70,7 @@
.constant('cordConfig', {
url: '',
userActivity: {}, //check if really needed
+ activeBundle: 0,
bundles: [
{
"id": "family",