/lib/Socket.js removed disconnect code

Removing some code for attempting to disconnect a socket. we found a work around from this and are no longer using this
This commit is contained in:
Jared Tabor
2014-10-30 15:36:27 -04:00
parent 73e1c0236d
commit 213f6d2af1
11 changed files with 287 additions and 46 deletions

View File

@@ -19,7 +19,7 @@
tooltip_delay: {show: 500, hide: 100}, // Default number of milliseconds to delay displaying/hiding tooltips
debug_mode: false, // Enable console logging messages
debug_mode: true, // Enable console logging messages
password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong.
// This value controls progress bar colors:

View File

@@ -79,6 +79,8 @@ function JobsListController ($rootScope, $log, $scope, $compile, $routeParams, C
queued_scope.search('queued_job');
break;
case 'successful':
completed_scope.search('completed_job');
break;
case 'failed':
case 'error':
case 'canceled':

View File

@@ -31,8 +31,7 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location,
var html,
e,
// winHeight,
// available_height,
jobs_scope,
list = PortalJobTemplateList,
view= GenerateList,
defaultUrl = GetBasePath('job_templates'),
@@ -112,12 +111,60 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location,
if ($scope.removeWidgetLoaded) {
$scope.removeWidgetLoaded();
}
$scope.removeWidgetLoaded = $scope.$on('WidgetLoaded', function () {
$scope.removeWidgetLoaded = $scope.$on('WidgetLoaded', function (e, label, jobscope) {
if(label==="portal_jobs"){
jobs_scope = jobscope;
}
$('.actions-column:eq(0)').text('Launch');
$('.actions-column:eq(1)').text('Details');
$('.list-well:eq(1)').css('margin-top' , '0px');
});
// function processEvent(event) {
// switch(event.status) {
// case 'running':
// jobs_scope.search('running_job');
// jobs_scope.search('queued_job');
// break;
// case 'new':
// case 'pending':
// case 'waiting':
// jobs_scope.search('queued_job');
// break;
// case 'successful':
// jobs_scope.search('completed_job');
// case 'failed':
// case 'error':
// case 'canceled':
// jobs_scope.search('completed_job');
// jobs_scope.search('running_job');
// jobs_scope.search('queued_job');
// }
// }
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function() {
jobs_scope.refreshJobs();
// if(data.status==='pending'){
// // $scope.refresh();
// $('#portal-jobs').empty();
// // $rootScope.flashMessage = null;
// PortalJobsWidget({
// scope: $scope,
// target: 'portal-jobs',
// searchSize: 'col-lg-6 col-md-6'
// });
// }
//x`processEvent(data);
});
$scope.submitJob = function (id) {
PlaybookRun({ scope: $scope, id: id });
};

View File

@@ -760,7 +760,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
}
scope.removePlaybookLaunchFinished = scope.$on('PlaybookLaunchFinished', function(e, data) {
//var base = $location.path().replace(/^\//, '').split('/')[0];
if(scope.portalMode===false){
if(scope.portalMode===false || scope.$parent.portalMode===false){
$location.path('/jobs/' + data.job);
}

View File

@@ -19,10 +19,24 @@ angular.module('JobTemplatesHelper', ['Utilities'])
* Add bits to $scope for handling callback url help
*
*/
.factory('CallbackHelpInit', ['$location', 'GetBasePath', function($location, GetBasePath) {
.factory('CallbackHelpInit', ['$location', 'GetBasePath', 'Rest', 'JobTemplateForm', 'GenerateForm', '$routeParams', 'LoadBreadCrumbs', 'ProcessErrors', 'ParseTypeChange',
'ParseVariableString', 'Empty', 'LookUpInit', 'InventoryList', 'CredentialList','ProjectList', 'RelatedSearchInit', 'RelatedPaginateInit',
function($location, GetBasePath, Rest, JobTemplateForm, GenerateForm, $routeParams, LoadBreadCrumbs, ProcessErrors,ParseTypeChange,
ParseVariableString, Empty, LookUpInit, InventoryList, CredentialList, ProjectList, RelatedSearchInit, RelatedPaginateInit) {
return function(params) {
var scope = params.scope;
var scope = params.scope,
defaultUrl = GetBasePath('job_templates'),
// generator = GenerateForm,
form = JobTemplateForm(),
// loadingFinishedCount = 0,
// base = $location.path().replace(/^\//, '').split('/')[0],
master = {},
id = $routeParams.template_id,
relatedSets = {};
// checkSCMStatus, getPlaybooks, callback,
// choicesCount = 0;
// The form uses awPopOverWatch directive to 'watch' scope.callback_help for changes. Each time the
// popover is activated, a function checks the value of scope.callback_help before constructing the content.
@@ -56,8 +70,132 @@ angular.module('JobTemplatesHelper', ['Utilities'])
scope.example_config_key = '5a8ec154832b780b9bdef1061764ae5a';
scope.example_template_id = 'N';
scope.setCallbackHelp();
scope.fillJobTemplate = function(){
// id = id || $rootScope.copy.id;
// Retrieve detail record and prepopulate the form
Rest.setUrl(defaultUrl + id);
Rest.get()
.success(function (data) {
var fld, i;
LoadBreadCrumbs({ path: '/job_templates/' + id, title: data.name });
for (fld in form.fields) {
if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) {
if (form.fields[fld].type === 'select') {
if (scope[fld + '_options'] && scope[fld + '_options'].length > 0) {
for (i = 0; i < scope[fld + '_options'].length; i++) {
if (data[fld] === scope[fld + '_options'][i].value) {
scope[fld] = scope[fld + '_options'][i];
}
}
} else {
scope[fld] = data[fld];
}
} else {
scope[fld] = data[fld];
if(fld ==='survey_enabled'){
// $scope.$emit('EnableSurvey', fld);
$('#job_templates_survey_enabled_chbox').attr('checked', scope[fld]);
if(Empty(data.summary_fields.survey)) {
$('#job_templates_delete_survey_btn').hide();
$('#job_templates_edit_survey_btn').hide();
$('#job_templates_create_survey_btn').show();
}
else{
$('#job_templates_delete_survey_btn').show();
$('#job_templates_edit_survey_btn').show();
$('#job_templates_create_survey_btn').hide();
scope.survey_exists = true;
}
}
}
master[fld] = scope[fld];
}
if (fld === 'variables') {
// Parse extra_vars, converting to YAML.
scope.variables = ParseVariableString(data.extra_vars);
master.variables = scope.variables;
}
if (form.fields[fld].type === 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
}
}
scope.url = data.url;
scope.ask_variables_on_launch = (data.ask_variables_on_launch) ? 'true' : 'false';
master.ask_variables_on_launch = scope.ask_variables_on_launch;
relatedSets = form.relatedSets(data.related);
if (data.host_config_key) {
scope.example_config_key = data.host_config_key;
}
scope.example_template_id = id;
scope.setCallbackHelp();
scope.callback_url = scope.callback_server_path + ((data.related.callback) ? data.related.callback :
GetBasePath('job_templates') + id + '/callback/');
master.callback_url = scope.callback_url;
LookUpInit({
scope: scope,
form: form,
current_item: data.inventory,
list: InventoryList,
field: 'inventory',
input_type: "radio"
});
LookUpInit({
url: GetBasePath('credentials') + '?kind=ssh',
scope: scope,
form: form,
current_item: data.credential,
list: CredentialList,
field: 'credential',
hdr: 'Select Machine Credential',
input_type: "radio"
});
LookUpInit({
scope: scope,
form: form,
current_item: data.project,
list: ProjectList,
field: 'project',
input_type: "radio"
});
RelatedSearchInit({
scope: scope,
form: form,
relatedSets: relatedSets
});
RelatedPaginateInit({
scope: scope,
relatedSets: relatedSets
});
scope.$emit('jobTemplateLoaded', data.related.cloud_credential);
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, {
hdr: 'Error!',
msg: 'Failed to retrieve job template: ' + $routeParams.template_id + '. GET status: ' + status
});
});
};
};
}]);

View File

@@ -32,6 +32,7 @@ angular.module('VariablesHelper', ['Utilities'])
json_obj = JSON.parse(variables);
json_obj = SortVariables(json_obj);
result = jsyaml.safeDump(json_obj);
}
catch (e) {
$log.info('Attempt to parse extra_vars as JSON failed. Attempting to parse as YAML');
@@ -56,6 +57,7 @@ angular.module('VariablesHelper', ['Utilities'])
try {
json_obj = SortVariables(variables);
result = jsyaml.safeDump(json_obj);
// result = variables;
}
catch(e3) {
ProcessErrors(null, variables, e3.message, null, { hdr: 'Error!',
@@ -78,7 +80,11 @@ angular.module('VariablesHelper', ['Utilities'])
**/
.factory('ToJSON', ['$log', 'ProcessErrors', function($log, ProcessErrors) {
return function(parseType, variables, stringify, reviver) {
var json_data, result;
var json_data,
result;
// bracketVar,
// key,
// lines, i, newVars = [];
if (parseType === 'json') {
try {
//parse a JSON string
@@ -97,7 +103,30 @@ angular.module('VariablesHelper', ['Utilities'])
}
} else {
try {
// if(variables.indexOf('{{')>-1){
// lines = variables.split(/\n/);
// for(i=0; i<lines.length; i++){
// if(lines[i].indexOf('{{')>-1){
// lines[i] = lines[i].replace('{{', '"{{');
// // lines[i] = lines[i].replace(lines[i].lastIndexOf('}}'), '}}"');
// lines[i] = lines[i]+'"';
// // newVars = newVars+ lines[i];
// newVars.push(lines[i])
// }
// }
// json_data = jsyaml.load(newVars.toString());
// bracketVar = variables.substr(variables.indexOf('{{'), variables.indexOf('}}'));
// bracketVar = bracketVar.trimRight();
// key = variables.substr(0, variables.indexOf(':'));
// json_data = jsyaml.load(variables);
// json_data[key] = bracketVar;
// }
// else
json_data = jsyaml.load(variables);
}
catch(e) {
json_data = {};

View File

@@ -64,7 +64,6 @@ angular.module('JobTemplatesListDefinition', [])
ngHref: '#/job_templates/{{ job_template.id }}/schedules',
awToolTip: 'Schedule future job template runs',
dataPlacement: 'top',
ngHide: 'portalMode===true'
},
edit: {
label: 'Edit',
@@ -72,7 +71,6 @@ angular.module('JobTemplatesListDefinition', [])
awToolTip: 'Edit template',
"class": 'btn-default btn-xs',
dataPlacement: 'top',
ngHide: 'portalMode===true'
},
"delete": {
label: 'Delete',
@@ -80,7 +78,14 @@ angular.module('JobTemplatesListDefinition', [])
"class": 'btn-danger btn-xs',
awToolTip: 'Delete template',
dataPlacement: 'top',
ngHide: 'portalMode===true'
},
copy: {
label: 'Copy',
ngClick: "copyJobTemplate(job_template.id, job_template.name)",
"class": 'btn-danger btn-xs',
awToolTip: 'Copy template',
dataPlacement: 'top',
}
}
});

View File

@@ -19,6 +19,9 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities'])
choicesCount = 0,
listCount = 0,
jobs_scope = scope.$new(true),
// completed_scope = scope.$new(true),
// running_scope = scope.$new(true),
// queued_scope = scope.$new(true),
// scheduled_scope = scope.$new(true),
max_rows,
html, e;
@@ -56,7 +59,7 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities'])
listCount++;
if (listCount === 1) {
//api_complete = true;
scope.$emit('WidgetLoaded', jobs_scope);
scope.$emit('WidgetLoaded', "portal_jobs", jobs_scope);
}
});
@@ -75,16 +78,36 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities'])
id: 'active-jobs',
url: GetBasePath('unified_jobs') + '?status__in=running,completed,failed,successful,error,canceled',
pageSize: max_rows,
spinner: false
spinner: true
});
// LoadSchedulesScope({
// completed_scope.showJobType = true;
// LoadJobsScope({
// parent_scope: scope,
// scope: scheduled_scope,
// list: ScheduledJobsList,
// id: 'scheduled-jobs-tab',
// url: GetBasePath('schedules') + '?next_run__isnull=false',
// pageSize: max_rows,
// spinner: false
// scope: completed_scope,
// list: PortalJobsList,
// id: 'active-jobs',
// url: GetBasePath('unified_jobs') + '?or__status=successful&or__status=failed&or__status=error&or__status=canceled',
// // searchParams: search_params,
// pageSize: max_rows
// });
// LoadJobsScope({
// parent_scope: scope,
// scope: running_scope,
// list: PortalJobsList,
// id: 'active-jobs',
// url: GetBasePath('unified_jobs') + '?status=running',
// pageSize: max_rows
// });
// LoadJobsScope({
// parent_scope: scope,
// scope: queued_scope,
// list: PortalJobsList,
// id: 'active-jobs',
// url: GetBasePath('unified_jobs') + '?or__status=pending&or__status=waiting&or__status=new',
// pageSize: max_rows
// });
$(window).resize(_.debounce(function() {

View File

@@ -28,7 +28,8 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
endpoint = params.endpoint,
protocol = $location.protocol(),
config, socketPort,
handshakeData, url;
// handshakeData,
url;
// Since some pages are opened in a new tab, we might get here before AnsibleConfig is available.
// In that case, load from local storage.
@@ -70,19 +71,20 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
// We have a valid session token, so attempt socket connection
$log.debug('Socket connecting to: ' + url);
self.scope.socket_url = url;
handshakeData = {
headers: {
'Authorization': 'Token ' + token,
'X-Auth-Token': 'Token ' + token
}
};
// handshakeData = {
// headers: {
// 'Authorization': 'Token ' + token,
// 'X-Auth-Token': 'Token ' + token
// }
// }
self.socket = io.connect(url, {
// headers:
// {
// 'Authorization': 'Token ' + token,
// 'X-Auth-Token': 'Token ' + token
// },
headers:
{
'Authorization': 'Token ' + token,
'X-Auth-Token': 'Token ' + token
},
'connect timeout': 3000,
'try multiple transports': false,
'max reconneciton attemps': 3,
@@ -180,19 +182,6 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
});
});
},
disconnect: function(){
var self = this;
$rootScope.disconnect_timer = setInterval(function(){disconnectSocket();}, 1000);
function disconnectSocket() {
self.socket.socket.disconnect();
window.clearInterval($rootScope.disconnect_timer);
}
// self.scope.$apply(function () {
// });
},
emit: function (eventName, data, callback) {
var self = this;
self.socket.emit(eventName, data, function () {

View File

@@ -159,7 +159,7 @@ angular.module('GeneratorHelpers', [])
icon = 'fa-list-ul';
break;
case 'copy':
icon = "fa-cut";
icon = "fa-copy";
break;
}
icon += (size) ? " " + size : "";

View File

@@ -3,4 +3,12 @@
<div ng-include="'/static/partials/schedule_dialog.html'"></div>
<div ng-include="'/static/partials/logviewer.html'"></div>
<div id="survey-modal-dialog"></div>
<div id="copy-job-modal" style="display:none">
<form name="copy_form" id="copy_form">
What would you like to name the copy of job template <b><span id=job_name></span></b>?<br>
<input id="new_copy_name" name="new_copy_name" ng-model ="new_copy_name" ng-required="true" class="form-control ng-pristine ng-invalid-required ng-invalid" style="margin-top:10px;">
<div class="error survey_error ng-hide" ng-show="copy_form.new_copy_name.$dirty && copy_form.new_copy_name.$error.required">A value is required!</div></input>
</form>
</div>
</div>