adding controller for portal mode.

handles the refresh of the page and loading of the job widgets
This commit is contained in:
Jared Tabor 2014-10-15 17:05:43 -04:00
parent f855b508dc
commit 33ad0c7612

View File

@ -1,191 +1,140 @@
// /************************************
// * Copyright (c) 2014 AnsibleWorks, Inc.
// *
// *
// * Portal.js
// *
// * Controller functions for portal mode
// *
// */
/************************************
* Copyright (c) 2014 AnsibleWorks, Inc.
*
*
* Portal.js
*
* Controller functions for portal mode
*
*/
// /**
// * @ngdoc function
// * @name controllers.function:Portal
// * @description This controller's for portal mode
// */
// 'use strict';
/**
* @ngdoc function
* @name controllers.function:Portal
* @description This controller's for portal mode
*/
'use strict';
// /**
// * @ngdoc method
// * @name controllers.function:Portal#Portal
// * @methodOf controllers.function:Portal
// * @description portal mode woohoo
// *
// *
// */
// function Portal($scope, $compile, $routeParams, $rootScope, $location, $log, Wait,
// ClearScope, Stream, Rest, GetBasePath, ProcessErrors, Button){
/**
* @ngdoc method
* @name controllers.function:Portal#Portal
* @methodOf controllers.function:Portal
* @description portal mode woohoo
*
*
*/
function PortalController($scope, $compile, $routeParams, $rootScope, $location, $log, Wait, ClearScope, Stream, Rest, GetBasePath, ProcessErrors,
Button, PortalJobTemplate, GenerateList, JobTemplateList, SearchInit, PaginateInit, PlaybookRun){
// ClearScope('portal');
ClearScope('portal');
// // var buttons, html, e, waitCount, loadedCount,borderStyles, jobs_scope, schedule_scope;
var html,
e,
winHeight,
available_height,
list = JobTemplateList,
view= GenerateList,
defaultUrl = GetBasePath('job_templates'),
buttons = {
refresh: {
mode: 'all',
awToolTip: "Refresh the page",
ngClick: "refresh()",
ngShow:"socketStatus == 'error'"
}
// ,
// stream: {
// ngClick: "showActivity()",
// awToolTip: "View Activity Stream",
// mode: 'all'
// }
};
// // // Add buttons to the top of the Home page. We're using lib/ansible/generator_helpers.js-> Buttons()
// // // to build buttons dynamically and insure all styling and icons match the rest of the application.
// // buttons = {
// // refresh: {
// // mode: 'all',
// // awToolTip: "Refresh the page",
// // ngClick: "refresh()",
// // ngShow:"socketStatus == 'error'"
// // },
// // stream: {
// // ngClick: "showActivity()",
// // awToolTip: "View Activity Stream",
// // mode: 'all'
// // }
// // };
html = Button({
btn: buttons.refresh,
action: 'refresh',
toolbar: true
});
// // html = Button({
// // btn: buttons.refresh,
// // action: 'refresh',
// // toolbar: true
// // });
// html += Button({
// btn: buttons.stream,
// action: 'stream',
// toolbar: true
// });
// // html += Button({
// // btn: buttons.stream,
// // action: 'stream',
// // toolbar: true
// // });
e = angular.element(document.getElementById('portal-list-actions'));
e.html(html);
$compile(e)($scope);
// // e = angular.element(document.getElementById('home-list-actions'));
// // e.html(html);
// // $compile(e)($scope);
if ($scope.removeLoadPortal) {
$scope.removeLoadPortal();
}
$scope.removeLoadPortal = $scope.$on('LoadPortal', function () {
winHeight = $(window).height();
available_height = Math.floor(winHeight - $('#main-menu-container .navbar').outerHeight() - $('#refresh-row').outerHeight() - 45);
$('.portal-container').height(available_height);
// // waitCount = 4;
// // loadedCount = 0;
view.inject( list, {
id : 'portal-job-template',
mode: 'edit',
scope: $scope,
breadCrumbs: false,
searchSize: 'col-lg-6 col-md-6'
});
// // if (!$routeParams.login) {
// // // If we're not logging in, start the Wait widget. Otherwise, it's already running.
// // //Wait('start');
// // }
$rootScope.flashMessage = null;
// // if ($scope.removeWidgetLoaded) {
// // $scope.removeWidgetLoaded();
// // }
// // $scope.removeWidgetLoaded = $scope.$on('WidgetLoaded', function (e, label, jobscope, schedulescope) {
// // // Once all the widgets report back 'loaded', turn off Wait widget
// // if(label==="dashboard_jobs"){
// // jobs_scope = jobscope;
// // schedule_scope = schedulescope;
// // }
// // loadedCount++;
// // if (loadedCount === waitCount) {
// // $(window).resize(_.debounce(function() {
// // $scope.$emit('ResizeJobGraph');
// // $scope.$emit('ResizeHostGraph');
// // $scope.$emit('ResizeHostPieGraph');
// // Wait('stop');
// // }, 500));
// // $(window).resize();
// // }
// // });
SearchInit({
scope: $scope,
set: 'job_templates',
list: list,
url: defaultUrl
});
PaginateInit({
scope: $scope,
list: list,
url: defaultUrl
});
// // if ($scope.removeDashboardReady) {
// // $scope.removeDashboardReady();
// // }
// // $scope.removeDashboardReady = $scope.$on('dashboardReady', function (e, data) {
// // nv.dev=false;
// Called from Inventories tab, host failed events link:
if ($routeParams.name) {
$scope[list.iterator + 'SearchField'] = 'name';
$scope[list.iterator + 'SearchValue'] = $routeParams.name;
$scope[list.iterator + 'SearchFieldLabel'] = list.fields.name.label;
}
$scope.search(list.iterator);
// // borderStyles = {"border": "1px solid #A9A9A9",
// // "border-radius": "4px",
// // "padding": "5px",
// // "margin-bottom": "15px"};
// // $('.graph-container').css(borderStyles);
PortalJobTemplate({
scope: $scope,
target: 'portal-jobs',
// dashboard: data
});
// // var winHeight = $(window).height(),
// // available_height = winHeight - $('#main-menu-container .navbar').outerHeight() - $('#count-container').outerHeight() - 120;
// // $('.graph-container').height(available_height/2);
// // // // chart.update();
});
$scope.submitJob = function (id) {
PlaybookRun({ scope: $scope, id: id });
};
// // DashboardCounts({
// // scope: $scope,
// // target: 'dash-counts',
// // dashboard: data
// // });
$scope.refresh = function () {
$scope.$emit('LoadPortal');
// Wait('start');
// loadedCount = 0;
// Rest.setUrl(GetBasePath('dashboard'));
// Rest.get()
// .success(function (data) {
// $scope.$emit('dashboardReady', data);
// })
// .error(function (data, status) {
// ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard: ' + status });
// });
};
// // JobStatusGraph({
// // scope: $scope,
// // target: 'dash-job-status-graph',
// // dashboard: data
// // });
$scope.refresh();
// // if ($rootScope.user_is_superuser === true) {
// // waitCount = 5;
// // HostGraph({
// // scope: $scope,
// // target: 'dash-host-count-graph',
// // dashboard: data
// // });
// // }
// // else{
// // $('#dash-host-count-graph').remove(); //replaceWith("<div id='dash-host-count-graph' class='left-side col-sm-12 col-xs-12'></div>");
// // }
// // DashboardJobs({
// // scope: $scope,
// // target: 'dash-jobs-list',
// // dashboard: data
// // });
// // HostPieChart({
// // scope: $scope,
// // target: 'dash-host-status-graph',
// // dashboard: data
// // });
}
// // });
// // if ($rootScope.removeJobStatusChange) {
// // $rootScope.removeJobStatusChange();
// // }
// // $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function() {
// // jobs_scope.refreshJobs();
// // $scope.$emit('ReloadJobStatusGraph');
// // });
// // if ($rootScope.removeScheduleChange) {
// // $rootScope.removeScheduleChange();
// // }
// // $rootScope.removeScheduleChange = $rootScope.$on('ScheduleChange', function() {
// // schedule_scope.refreshSchedules();
// // $scope.$emit('ReloadJobStatusGraph');
// // });
// // $scope.showActivity = function () {
// // Stream({
// // scope: $scope
// // });
// // };
// // $scope.refresh = function () {
// // Wait('start');
// // loadedCount = 0;
// // Rest.setUrl(GetBasePath('dashboard'));
// // Rest.get()
// // .success(function (data) {
// // $scope.$emit('dashboardReady', data);
// // })
// // .error(function (data, status) {
// // ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard: ' + status });
// // });
// // };
// // $scope.refresh();
// }
// Home.$inject = ['$scope', '$compile', '$routeParams', '$rootScope', '$location', '$log','Wait',
// 'ClearScope', 'Stream', 'Rest', 'GetBasePath', 'ProcessErrors', 'Button'
// ];
PortalController.$inject = ['$scope', '$compile', '$routeParams', '$rootScope', '$location', '$log','Wait', 'ClearScope', 'Stream', 'Rest', 'GetBasePath', 'ProcessErrors',
'Button', 'PortalJobTemplate', 'GenerateList' , 'JobTemplateList', 'SearchInit', 'PaginateInit', 'PlaybookRun'
];