Matteo Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 1 | /* |
| 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 Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 18 | 'use strict'; |
Matteo Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 19 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 20 | var urlSuffix = '/rs/dashboard'; |
Matteo Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 21 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 22 | function randomDate(start, end) { |
| 23 | return new Date( |
| 24 | start.getTime() + Math.random() * (end.getTime() - start.getTime()) |
| 25 | ); |
| 26 | } |
Matteo Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 27 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 28 | 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 Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 34 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 35 | // 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 Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 40 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 41 | // 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 Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 42 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 43 | // add an icon to the user |
| 44 | res.users.map(function(user){ |
| 45 | user['icon_id'] = 'mom'; |
| 46 | return user; |
| 47 | }); |
Matteo Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 48 | |
Matteo Scandolo | 680cd92 | 2016-01-26 17:21:39 -0800 | [diff] [blame] | 49 | // 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 Scandolo | 5d56861 | 2016-01-26 11:02:16 -0800 | [diff] [blame] | 64 | }()); |