blob: 60c3a940a0b438acc511baf41bd04e03114f0501 [file] [log] [blame]
Matteo Scandolo5d568612016-01-26 11:02:16 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function () {
Matteo Scandolo680cd922016-01-26 17:21:39 -080018 'use strict';
Matteo Scandolo5d568612016-01-26 11:02:16 -080019
Matteo Scandolo680cd922016-01-26 17:21:39 -080020 var urlSuffix = '/rs/dashboard';
Matteo Scandolo5d568612016-01-26 11:02:16 -080021
Matteo Scandolo680cd922016-01-26 17:21:39 -080022 function randomDate(start, end) {
23 return new Date(
24 start.getTime() + Math.random() * (end.getTime() - start.getTime())
25 );
26 }
Matteo Scandolo5d568612016-01-26 11:02:16 -080027
Matteo Scandolo680cd922016-01-26 17:21:39 -080028 angular.module('cordHome', [])
29 .controller('CordHomeCtrl', [
30 '$log', '$scope', '$resource', '$filter', 'cordConfig', 'SubscriberUsers', 'Helpers',
31 function ($log, $scope, $resource, $filter, cordConfig, SubscriberUsers, Helpers) {
32 var DashboardData, resource;
33 $scope.page.curr = 'dashboard';
Matteo Scandolo5d568612016-01-26 11:02:16 -080034
Matteo Scandolo680cd922016-01-26 17:21:39 -080035 // NOTE subscriberId should be retrieved by login
36 SubscriberUsers.query({subscriberId: 1}).$promise
37 .then(function(res){
38 $scope.bundle_name = cordConfig.bundles[0].name;
39 $scope.bundle_desc = cordConfig.bundles[0].desc;
Matteo Scandolo5d568612016-01-26 11:02:16 -080040
Matteo Scandolo680cd922016-01-26 17:21:39 -080041 // 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?
Matteo Scandolo5d568612016-01-26 11:02:16 -080042
Matteo Scandolo680cd922016-01-26 17:21:39 -080043 // add an icon to the user
44 res.users.map(function(user){
45 user['icon_id'] = 'mom';
46 return user;
47 });
Matteo Scandolo5d568612016-01-26 11:02:16 -080048
Matteo Scandolo680cd922016-01-26 17:21:39 -080049 // add a random login date to the user
50 res.users.forEach(function(user){
51 if(!angular.isDefined(cordConfig.userActivity[user.id])){
52 var date = randomDate(new Date(2015, 0, 1), new Date());
53 cordConfig.userActivity[user.id] = $filter('date')(date, 'mediumTime');
54 }
55 });
56 $scope.users = res.users;
57 })
58 .catch(function(){
59 $log.error('Problem with resource', resource);
60 });
61
62 $log.debug('Cord Home Ctrl has been created.');
63 }]);
Matteo Scandolo5d568612016-01-26 11:02:16 -080064}());