-
Notifications
You must be signed in to change notification settings - Fork 3
/
ctrl_dlg_submit_job.js
127 lines (117 loc) · 4.38 KB
/
ctrl_dlg_submit_job.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var graphSchemaApp = angular.module('graphSchemaApp');
graphSchemaApp.controller('Dlg_submit_job', ['$scope', '$element', '$http', 'title', 'scriptText', 'cells', 'close', 'hardware_platform',
'jobService', 'Simulation_time', 'Simulation_name', 'bbpOidcSession', 'clbUser', '$location', 'clbContext',
'python_script_string',
function($scope, $element, $http, title, scriptText, cells, close, hardware_platform,
jobService, Simulation_time, Simulation_name, bbpOidcSession, clbUser, $location, clbContext,
python_script_string) {
clbUser.getCurrentUserOnly().then(
function(response) {
console.log(response);
},
function(err) {
bbpOidcSession.login();
});
$scope.title = title;
$scope.scriptText = scriptText;
$scope.base_url = "";
var curdate = new Date();
$scope.job = {};
$scope.job.collab_id = 4293; //default value
//$scope.job.log = " ";
$scope.job.status = "submitted";
//$scope.job.timestamp_completion = curdate.toUTCString();
$scope.job.code = $scope.scriptText;
$scope.job.command = "";
$scope.job.hardware_config = {};
$scope.hardware_platform = hardware_platform;
$scope.job.tags = ["gui"];
$scope.job.input_data = [];
//$scope.job.output_data = [];
//$scope.job.resource_uri = "";
$scope.inputs = [];
$scope.Simulation_time = Simulation_time;
if(($scope.hardware_platform == "") || ($scope.hardware_platform == null)){
$scope.hardware_platform = "BrainScaleS";
}
var ctx = null;
console.log($location);
console.log($location.search());
console.log(window.location);
if( $location.search().ctx ) {
ctx = $location.search().ctx;
console.log(ctx);
clbContext.get(ctx).then(
function(context) {
console.log("Collab id = " + context.collab.id);
$scope.job.collab_id = context.collab.id;
},
function(err) {
console.log(err);
}
);
}
console.log("Context is " + ctx);
$scope.submitJob = function(job, jobService){
var job_p = JSON.stringify(job);
var job_status = document.getElementById('job_status');
job_status.textContent = JSON.parse(job_p).status;
job_status.classList.remove('badge-primary');
job_status.classList.remove('badge-danger');
job_status.classList.remove('badge-success');
job_status.classList.add('badge-info');
try {
jobService.post(job_p, function(data, status){
job_status.textContent = JSON.parse(job_p).status;
job_status.classList.remove('badge-primary');
job_status.classList.remove('badge-danger');
job_status.classList.remove('badge-success');
job_status.classList.add('badge-info');
})
} catch(error) {
// console.log("error : " + error);
// console.log("job status (failled) : " + JSON.parse(job_p).status);
job_status.textContent = JSON.parse(job_p).status;
job_status.classList.remove('badge-primary');
job_status.classList.remove('badge-success');
job_status.classList.remove('badge-info');
job_status.classList.add('badge-danger');
}
// .error(function(data, status){
// console.log("failled : +" + data + "/" + status );
// });
};
$scope.beforeClose = function(){
if(($scope.Simulation_time == null) || ($scope.Simulation_time.toString() == "")){
$scope.msgAlert = "Simulation time value is required."
} else if(($scope.Simulation_name == "") || ($scope.Simulation_name == null)){
$scope.msgAlert = "Simulation name value is required.";
} else {
$scope.close()
}
};
$scope.close = function() {
$scope.scriptText = python_script_string(cells, $scope.hardware_platform, $scope.Simulation_time, $scope.Simulation_name);
$scope.job.code = $scope.scriptText;
$scope.job.hardware_platform = $scope.hardware_platform;
$scope.job.timestamp_submission = curdate.toUTCString();
close({
hardware_platform: $scope.hardware_platform,
Simulation_time: $scope.Simulation_time,
Simulation_name: $scope.Simulation_name,
timestamp_submission: $scope.job.timestamp_submission,
}, 100);
$scope.submitJob($scope.job, jobService);
$('.modal-backdrop').remove();
};
$scope.cancel = function() {
close({
hardware_platform: $scope.hardware_platform,
Simulation_time: $scope.Simulation_time,
Simulation_name: $scope.Simulation_name,
timestamp_submission: $scope.job.timestamp_submission,
}, 100);
$('.modal-backdrop').remove();
};
}
]);