Refactored around to have same style in code
diff --git a/views/ngXosViews/subscriberPortal/src/app/fw/services/helpers.js b/views/ngXosViews/subscriberPortal/src/app/fw/services/helpers.js
index 80f30b1..6f6c4a6 100644
--- a/views/ngXosViews/subscriberPortal/src/app/fw/services/helpers.js
+++ b/views/ngXosViews/subscriberPortal/src/app/fw/services/helpers.js
@@ -1,3 +1,19 @@
+/*
+ * 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.
+ */
+
(function () {
"use strict";
diff --git a/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js b/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
index 314be5f..59c05d8 100644
--- a/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
+++ b/views/ngXosViews/subscriberPortal/src/app/fw/services/rest.js
@@ -1,6 +1,23 @@
-"use strict";
+/*
+ * 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('cordRest', [])
+(function () {
+ "use strict";
+
+ angular.module('cordRest', [])
.service('User', function($http, $q, $cookies, cordConfig){
this.login = function(username, password){
var deferred = $q.defer();
@@ -36,8 +53,6 @@
return $resource(cordConfig.url + '/xoslib/rs/subscriber');
})
.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',
@@ -49,7 +64,6 @@
// 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';
@@ -80,8 +94,8 @@
}
}
});
- //return $resource(cordConfig.url + '/xoslib/corduser/:id')
})
.service('SubscriberUsersUrlFilterLevel', function($resource, cordConfig){
return $resource(cordConfig.url + '/xoslib/rs/subscriber/:subscriberId/users/:userId/url_filter/');
- });
\ No newline at end of file
+ });
+}());
\ No newline at end of file
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js b/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
index 054c703..310118b 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/bundle/bundle.js
@@ -64,10 +64,9 @@
$log.debug('Cord Bundle Ctrl has been created.');
})
-
- .directive('bundleAvailable', [function () {
+ .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 454972c..ea35436 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/home/home.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/home/home.js
@@ -17,26 +17,22 @@
(function () {
'use strict';
- var urlSuffix = '/rs/dashboard';
-
angular.module('cordHome', [])
- .controller('CordHomeCtrl', [
- '$log', '$scope', '$resource', '$filter', 'cordConfig', 'SubscriberUsers', 'Helpers',
- function ($log, $scope, $resource, $filter, cordConfig, SubscriberUsers, Helpers) {
- var DashboardData, resource;
- $scope.page.curr = 'dashboard';
+ .controller('CordHomeCtrl', function ($log, $scope, cordConfig, SubscriberUsers) {
- // NOTE subscriberId should be retrieved by login
- SubscriberUsers.query({subscriberId: 1}).$promise
- .then(function(res){
- $scope.bundle_name = cordConfig.bundles[cordConfig.activeBundle].name;
- $scope.bundle_desc = cordConfig.bundles[cordConfig.activeBundle].desc;
- $scope.users = res.users;
- })
- .catch(function(){
- $log.error('Problem with resource', resource);
- });
+ $scope.page.curr = 'dashboard';
- $log.debug('Cord Home Ctrl has been created.');
- }]);
+ // NOTE subscriberId should be retrieved by login
+ SubscriberUsers.query({subscriberId: 1}).$promise
+ .then(function(res){
+ $scope.bundle_name = cordConfig.bundles[cordConfig.activeBundle].name;
+ $scope.bundle_desc = cordConfig.bundles[cordConfig.activeBundle].desc;
+ $scope.users = res.users;
+ })
+ .catch(function(){
+ $log.error('Problem with resource', SubscriberUsers);
+ });
+
+ $log.debug('Cord Home Ctrl has been created.');
+ });
}());
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/login/login.js b/views/ngXosViews/subscriberPortal/src/app/view/login/login.js
index 8a3f2cf..c902480 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/login/login.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/login/login.js
@@ -16,37 +16,25 @@
(function () {
'use strict';
- var urlSuffix = '/rs/login';
angular.module('cordLogin', [])
- .controller('CordLoginCtrl', [
- '$log', '$scope', '$resource', '$location', '$window', 'User',
- function ($log, $scope, $resource, $location, $window, User) {
- var LoginData, resource;
- $scope.page.curr = 'login';
+ .controller('CordLoginCtrl', function ($log, $scope, $resource, $location, $window, User) {
- function getResource(email) {
- LoginData = $resource($scope.shared.url + urlSuffix + '/' + email);
- resource = LoginData.get({},
- function () {
- $location.url('/home');
- $window.location.href = $location.absUrl();
- });
+ $scope.page.curr = 'login';
+
+ $scope.login = function () {
+ if ($scope.email && $scope.password) {
+ //getResource($scope.email);
+
+ User.login($scope.email, $scope.password)
+ .then(function(user){
+ $location.url('/home');
+ });
+
+ $scope.shared.login = $scope.email;
}
+ };
- $scope.login = function () {
- if ($scope.email && $scope.password) {
- //getResource($scope.email);
-
- User.login($scope.email, $scope.password)
- .then(function(user){
- $location.url('/home');
- });
-
- $scope.shared.login = $scope.email;
- }
- };
-
- $log.debug('Cord Login Ctrl has been created.');
- }]);
+ $log.debug('Cord Login Ctrl has been created.');
+ });
}());
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/user/user.html b/views/ngXosViews/subscriberPortal/src/app/view/user/user.html
index 9822b57..052913e 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/user/user.html
+++ b/views/ngXosViews/subscriberPortal/src/app/view/user/user.html
@@ -33,19 +33,6 @@
</select>
</td>
</tr>
- <tr>
- <td class="buttons">
- <div ng-show="showCheck">
- <icon size="20px" id="checkMark"></icon>
- </div>
- <input type="reset" value="Cancel"
- ng-click="cancelChanges(changeLevels)"
- ng-disabled="changeLevels.$pristine">
- <input type="button" value="Apply"
- ng-click="applyChanges(changeLevels)"
- ng-disabled="changeLevels.$pristine">
- </td>
- </tr>
</table>
</form>
</div>
diff --git a/views/ngXosViews/subscriberPortal/src/app/view/user/user.js b/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
index bc75afd..6eff78a 100644
--- a/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
+++ b/views/ngXosViews/subscriberPortal/src/app/view/user/user.js
@@ -17,127 +17,52 @@
(function () {
'use strict';
- var bundleUrlSuffix = '/rs/bundle',
- userUrlSuffix = '/rs/users',
- family = 'family',
- url_filter = 'url_filter';
-
angular.module('cordUser', [])
- .controller('CordUserCtrl', ['$log', '$scope', '$resource', '$timeout', '$filter', 'SubscriberUsers', 'cordConfig',
- function ($log, $scope, $resource, $timeout, $filter, SubscriberUsers, cordConfig) {
+ .controller('CordUserCtrl', function ($log, $scope, $resource, $timeout, $filter, SubscriberUsers, cordConfig) {
- $scope.page.curr = 'user';
- $scope.isFamily = false;
- $scope.newLevels = {};
- $scope.showCheck = false;
- $scope.ratingsShown = false;
+ $scope.page.curr = 'user';
+ $scope.isFamily = false;
+ $scope.newLevels = {};
+ $scope.showCheck = false;
+ $scope.ratingsShown = false;
- // === Get data functions ---
-
- // NOTE subscriberId should be retrieved by login
- SubscriberUsers.query({subscriberId: 1}).$promise
- .then(function(res){
- $scope.isFamily = cordConfig.bundles[cordConfig.activeBundle].id === 'family';
- // if bundle is family search for url_filter level
- if ($scope.isFamily) {
- angular.forEach(cordConfig.bundles[cordConfig.activeBundle].functions, function(fn){
- if(fn.id === 'url_filter'){
- $scope.levels = fn.params.levels;
- }
- });
- }
-
- $scope.users = res.users;
- })
- .catch(function () {
- $log.error('Problem with resource', SubscriberUsers);
- });
-
- $scope.updateLevel = function(user){
- user.$save()
- .then(function(){
- console.log('saved');
- })
- .catch(function(e){
- throw new Error(e);
- });
- };
-
- //function getUsers(url) {
- // var UserData, userResource;
- // UserData = $resource(url);
- // userResource = UserData.get({},
- // // success
- // function () {
- // $scope.users = userResource.users;
- // if ($.isEmptyObject($scope.shared.userActivity)) {
- // $scope.users.forEach(function (user) {
- // var date = randomDate(new Date(2015, 0, 1),
- // new Date());
- //
- // $scope.shared.userActivity[user.id] =
- // $filter('date')(date, 'mediumTime');
- // });
- // }
- // },
- // // error
- // function () {
- // $log.error('Problem with resource', userResource);
- // }
- // );
- //}
- //
- //getUsers($scope.shared.url + userUrlSuffix);
-
- // === Form functions ---
-
- function levelUrl(id, level) {
- return $scope.shared.url +
- userUrlSuffix + '/' + id + '/apply/url_filter/level/' + level;
- }
-
- // NOTE This will trigger one request for each user to update url_filter level
- $scope.applyChanges = function (changeLevels) {
- var requests = [];
-
- if ($scope.users) {
- $.each($scope.users, function (index, user) {
- var id = user.id,
- level = user.profile.url_filter.level;
- if ($scope.newLevels[id] !== level) {
- requests.push(levelUrl(id, $scope.newLevels[id]));
+ // NOTE subscriberId should be retrieved by login
+ SubscriberUsers.query({subscriberId: 1}).$promise
+ .then(function(res){
+ $scope.isFamily = cordConfig.bundles[cordConfig.activeBundle].id === 'family';
+ // if bundle is family search for url_filter level
+ if ($scope.isFamily) {
+ angular.forEach(cordConfig.bundles[cordConfig.activeBundle].functions, function(fn){
+ if(fn.id === 'url_filter'){
+ $scope.levels = fn.params.levels;
}
});
-
- $.each(requests, function (index, req) {
- getUsers(req);
- });
}
- changeLevels.$setPristine();
- $scope.showCheck = true;
- $timeout(function () {
- $scope.showCheck = false;
- }, 3000);
- };
- $scope.cancelChanges = function (changeLevels) {
- if ($scope.users) {
- $.each($scope.users, function (index, user) {
- $scope.newLevels[user.id] = user.profile.url_filter.level;
- });
- }
- changeLevels.$setPristine();
- $scope.showCheck = false;
- };
+ $scope.users = res.users;
+ })
+ .catch(function () {
+ $log.error('Problem with resource', SubscriberUsers);
+ });
- $scope.showRatings = function () {
- $scope.ratingsShown = !$scope.ratingsShown;
- };
+ $scope.updateLevel = function(user){
+ // TODO save this data and show a confirmation to the user
+ user.$save()
+ .then(function(){
+ console.log('saved');
+ })
+ .catch(function(e){
+ throw new Error(e);
+ });
+ };
- $log.debug('Cord User Ctrl has been created.');
- }])
+ $scope.showRatings = function () {
+ $scope.ratingsShown = !$scope.ratingsShown;
+ };
- .directive('ratingsPanel', ['$log', function ($log) {
+ $log.debug('Cord User Ctrl has been created.');
+ })
+ .directive('ratingsPanel', function ($log) {
return {
templateUrl: 'app/view/user/ratingPanel.html',
link: function (scope, elem, attrs) {
@@ -177,6 +102,5 @@
});
}
};
- }]);
-
+ });
}());
diff --git a/views/ngXosViews/subscriberPortal/src/cord.js b/views/ngXosViews/subscriberPortal/src/cord.js
index 5406bd2..0f3649b 100644
--- a/views/ngXosViews/subscriberPortal/src/cord.js
+++ b/views/ngXosViews/subscriberPortal/src/cord.js
@@ -59,14 +59,13 @@
redirectTo: '/login'
});
}])
- .controller('CordCtrl', ['$scope', '$location', 'cordConfig',
- function ($scope, $location, cordConfig) {
- $scope.shared = {
- url: 'http://' + $location.host() + ':' + $location.port()
- };
- $scope.shared.userActivity = cordConfig.userActivity;
- $scope.page = {};
- }])
+ .controller('CordCtrl', function ($scope, $location, cordConfig) {
+ $scope.shared = {
+ url: 'http://' + $location.host() + ':' + $location.port()
+ };
+ $scope.shared.userActivity = cordConfig.userActivity;
+ $scope.page = {};
+ })
.constant('cordConfig', {
url: '',
userActivity: {}, //check if really needed