Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 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 () { |
| 18 | 'use strict'; |
| 19 | |
Bri Prebilic Cole | d189e28 | 2015-06-05 10:00:22 -0700 | [diff] [blame] | 20 | var urlSuffix = '/rs/dashboard'; |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 21 | |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 22 | function randomDate(start, end) { |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 23 | return new Date( |
| 24 | start.getTime() + Math.random() * (end.getTime() - start.getTime()) |
| 25 | ); |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 28 | angular.module('cordHome', []) |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 29 | .controller('CordHomeCtrl', ['$log', '$scope', '$resource', '$filter', |
| 30 | function ($log, $scope, $resource, $filter) { |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 31 | var DashboardData, resource; |
Bri Prebilic Cole | 60553c8 | 2015-06-05 08:50:17 -0700 | [diff] [blame] | 32 | $scope.page.curr = 'dashboard'; |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 33 | |
Bri Prebilic Cole | d189e28 | 2015-06-05 10:00:22 -0700 | [diff] [blame] | 34 | DashboardData = $resource($scope.shared.url + urlSuffix); |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 35 | resource = DashboardData.get({}, |
| 36 | // success |
| 37 | function () { |
Bri Prebilic Cole | 8b66a85 | 2015-06-10 17:15:10 -0700 | [diff] [blame] | 38 | $scope.bundle_name = resource.bundle_name; |
| 39 | $scope.bundle_desc = resource.bundle_desc; |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 40 | $scope.users = resource.users; |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 41 | |
| 42 | if ($.isEmptyObject($scope.shared.userActivity)) { |
| 43 | $scope.users.forEach(function (user) { |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 44 | var date = randomDate(new Date(2015, 0, 1), |
| 45 | new Date()); |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 46 | |
Bri Prebilic Cole | 7a5431e | 2015-06-08 12:53:02 -0700 | [diff] [blame] | 47 | $scope.shared.userActivity[user.id] = |
| 48 | $filter('date')(date, 'mediumTime'); |
Bri Prebilic Cole | f34c989 | 2015-06-08 11:51:01 -0700 | [diff] [blame] | 49 | }); |
| 50 | } |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 51 | }, |
| 52 | // error |
| 53 | function () { |
| 54 | $log.error('Problem with resource', resource); |
| 55 | }); |
| 56 | $log.debug('Resource received:', resource); |
| 57 | |
| 58 | $log.debug('Cord Home Ctrl has been created.'); |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 59 | }]); |
| 60 | }()); |