blob: fc0fa38340ea840215e73cc27333e9b9869ec1fa [file] [log] [blame]
Bri Prebilic Colee0311892015-05-15 11:27:15 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Colee0311892015-05-15 11:27:15 -07003 *
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 Coled189e282015-06-05 10:00:22 -070020 var urlSuffix = '/rs/dashboard';
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070021
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070022 function randomDate(start, end) {
Bri Prebilic Cole7a5431e2015-06-08 12:53:02 -070023 return new Date(
24 start.getTime() + Math.random() * (end.getTime() - start.getTime())
25 );
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070026 }
27
Bri Prebilic Colee0311892015-05-15 11:27:15 -070028 angular.module('cordHome', [])
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070029 .controller('CordHomeCtrl', ['$log', '$scope', '$resource', '$filter',
30 function ($log, $scope, $resource, $filter) {
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070031 var DashboardData, resource;
Bri Prebilic Cole60553c82015-06-05 08:50:17 -070032 $scope.page.curr = 'dashboard';
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070033
Bri Prebilic Coled189e282015-06-05 10:00:22 -070034 DashboardData = $resource($scope.shared.url + urlSuffix);
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070035 resource = DashboardData.get({},
36 // success
37 function () {
Bri Prebilic Cole8b66a852015-06-10 17:15:10 -070038 $scope.bundle_name = resource.bundle_name;
39 $scope.bundle_desc = resource.bundle_desc;
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070040 $scope.users = resource.users;
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070041
42 if ($.isEmptyObject($scope.shared.userActivity)) {
43 $scope.users.forEach(function (user) {
Bri Prebilic Cole7a5431e2015-06-08 12:53:02 -070044 var date = randomDate(new Date(2015, 0, 1),
45 new Date());
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070046
Bri Prebilic Cole7a5431e2015-06-08 12:53:02 -070047 $scope.shared.userActivity[user.id] =
48 $filter('date')(date, 'mediumTime');
Bri Prebilic Colef34c9892015-06-08 11:51:01 -070049 });
50 }
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070051 },
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 Colee0311892015-05-15 11:27:15 -070059 }]);
60}());