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