3 appDS2.controller('workflowsControllerDS2', function($scope, $http, $log, $modal) {
4 $scope.viewPerPage = 5;
5 $scope.scrollViewsPerPage = 20;
6 $scope.currentPage = 2;
8 $scope.searchCategory = "";
9 $scope.searchString = "";
15 $scope.showModal = false;
16 $scope.toggleModal = function(){
17 $scope.showModal = !$scope.showModal;
21 $scope.workflow.active = "true";
23 $scope.updateAllWorkflowStatus = function() {
24 angular.forEach($scope.workflows,function(value){
25 $scope.checkWorkflowStatus(value);
29 $scope.fetchWorkflowsList = function() {
30 $http.get('workflows/list').then(function(workflowList){
31 console.log('Got new list from server = ' + workflowList.data);
32 $scope.workflows = workflowList.data;
33 $scope.updateAllWorkflowStatus();
37 $scope.addNewWorkflow = function(newWorkflow) {
38 $http.post('workflows/addWorkflow/', JSON.stringify(newWorkflow)).success(function() {
39 $scope.fetchWorkflowsList();
42 $scope.workflow.name = '';
46 $scope.updateWorkflow = function (workflowToEdit) {
47 //workflowToEdit.active='true';
48 var modalInstance = $modal.open({
49 animation: $scope.animationsEnabled,
50 templateUrl: 'app/fusion/scripts/DS2-view-models/DS2-workflows-page/workflow-new.html',
51 sizeClass: 'modal-small',
52 controller: ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
53 $scope.workflow = workflowToEdit;
54 $scope.ok = function() {
56 $scope.workflow.name== undefined|| $scope.workflow.name == null|| $scope.workflow.name == ""
57 ||$scope.workflow.workflowKey == undefined ||$scope.workflow.workflowKey==null||$scope.workflow.workflowKey==""
58 ||$scope.workflow.runLink==undefined||$scope.workflow.runLink==null||$scope.workflow.runLink==""
62 alert("please provide valid entries !");
66 console.log('Updating existing workflow ... ' + JSON.stringify($scope.workflow));
67 $http.post('workflows/editWorkflow/', JSON.stringify($scope.workflow)).then(function(returnedWorkflow){
68 console.log('Returned Workflow = ' + JSON.stringify(returnedWorkflow));
69 $modalInstance.close($scope.workflow);
74 $scope.cancel = function() {
75 $modalInstance.dismiss();
78 //End of inner controller
80 workflow: function() {
81 console.log('Passing ' + JSON.stringify($scope.workflow));
82 return $scope.workflow;
87 modalInstance.result.then(function (editedWorkFlow) {
88 //Need to convert to proper date - later
89 delete editedWorkFlow.created;
90 delete editedWorkFlow.updated;
92 delete editedWorkFlow.createdBy;
93 delete editedWorkFlow.modifiedBy;
95 console.log('selected Item ' + JSON.stringify(editedWorkFlow));
96 $scope.$emit('workflowAdded', editedWorkFlow);
99 $log.info('Modal dismissed at: ' + new Date());
103 $scope.reset = function(){
104 console.log("Resetting ....");
107 $scope.update = function(){
108 console.log("updating ....");
111 $scope.createWorkflow = function (modalSize) {
113 var modalInstance = $modal.open({
114 animation: $scope.animationsEnabled,
115 templateUrl: 'app/fusion/scripts/DS2-view-models/DS2-workflows-page/workflow-new.html',
116 sizeClass: 'modal-small',
117 controller: ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
118 $scope.workflow = {};
119 $scope.workflow.active = 'true';
120 $scope.ok = function() {
121 if($scope.workflow.name== undefined|| $scope.workflow.name == null|| $scope.workflow.name == ""
122 ||$scope.workflow.workflowKey == undefined ||$scope.workflow.workflowKey==null||$scope.workflow.workflowKey==""
123 ||$scope.workflow.runLink==undefined||$scope.workflow.runLink==null||$scope.workflow.runLink==""
127 alert("please provide valid entries !");
130 console.log('Saving new workflow ... ' + JSON.stringify($scope.workflow));
131 $http.post('workflows/addWorkflow/', JSON.stringify($scope.workflow)).then(function(returnedWorkflow){
132 console.log('Returned Workflow = ' + JSON.stringify(returnedWorkflow));
133 $modalInstance.close($scope.workflow);
137 /* console.log(size);*/
138 $scope.cancel = function() {
139 $modalInstance.dismiss();
142 //End of inner controller
144 workflow: function() {
145 console.log('Passing ' + JSON.stringify($scope.workflow));
146 return $scope.workflow;
151 modalInstance.result.then(function (newWorkflow) {
152 console.log('selected Item ' + JSON.stringify(newWorkflow));
153 $scope.$emit('workflowAdded', newWorkflow);
156 $log.info('Modal dismissed at: ' + new Date());
158 };//End of createWorkflow function
161 $scope.removeWorkflow = function(workflowToRemove){
162 var modalInstance = $modal.open({
163 animation: $scope.animationsEnabled,
164 templateUrl: 'app/fusion/scripts/DS2-view-models/DS2-workflows-page/workflow-remove.html',
165 sizeClass: 'modal-small',
166 controller: ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
167 $scope.workflowToRemove = workflowToRemove;
168 $scope.ok = function() {
169 console.log('Removing workflow ... ' + JSON.stringify($scope.workflowToRemove) + ' on client request.');
170 $http.post('workflows/removeWorkflow/', JSON.stringify($scope.workflowToRemove.id)).then(function(){
171 console.log('Workflow successfully removed !!!');
172 $modalInstance.close();
176 $scope.cancel = function() {
177 $modalInstance.dismiss();
182 modalInstance.result.then(function () {
183 $scope.$emit('workflowRemoved');
185 $log.info('Modal dismissed at: ' + new Date());
192 $scope.scheduleWorkflow = function(workflowToSchedule){
193 var modalInstance = $modal.open({
194 animation: $scope.animationsEnabled,
195 templateUrl: 'app/fusion/scripts/DS2-view-models/DS2-workflows-page/workflow-schedule.html',
197 controller: ['$scope', '$modalInstance', '$http','dateFilter', function ($scope, $modalInstance, $http,dateFilter) {
199 $scope.workflowToSchedule = workflowToSchedule;
200 $scope.dt = new Date();
201 $scope.dt2 = new Date();
202 $scope.dateformat = 'MM/dd/yyyy',
203 $scope.datetimeformat = "hh:mm a";
205 $scope.recurrenceOptions =[{
206 index:0, value:'One-Time', title:'One-Time'
208 index:1, value: 'Hourly',title:'Hourly'
210 index:2, value: 'Daily',title:'Daily'
212 index:3, value: 'Weekly',title:'Weekly'
214 $scope.selectRecurrenceOpt = $scope.recurrenceOptions[0];
217 for (var i=0; i<24; i++){
222 $scope.hours.push(newObj);
226 for (var i=0; i<60; i++){
231 $scope.minutes.push(newObj);
234 $scope.AMPMOptions =[
236 index:0, value:'AM', title:'AM'
238 index:1, value: 'PM',title:'PM'
241 $scope.selectFirstHour =$scope.hours[0];
242 $scope.selectFirstMinute =$scope.minutes[0];
244 $scope.selectLastHour =$scope.hours[0];
245 $scope.selectLastMinute =$scope.minutes[0];
247 $scope.selectStartAMPMOption=$scope.AMPMOptions[0];
248 $scope.selectLastAMPMOption=$scope.AMPMOptions[0];
250 var GenerateCronExpression = function(trigger_dt, RecurrenceOpt) {
251 var CRON_sec = trigger_dt.getSeconds();
252 var CRON_min = trigger_dt.getMinutes();
253 var CRON_hr = trigger_dt.getHours();
254 var CRON_date= trigger_dt.getDate();
255 var CRON_month = trigger_dt.toLocaleString('en-US', {month: 'short'}).toUpperCase();
256 var CRON_day = trigger_dt.toLocaleString('en-US', {weekday: 'short'}).toUpperCase();
257 var CRON_year = trigger_dt.getFullYear();
258 if (RecurrenceOpt ==="One-Time") {
261 if (RecurrenceOpt ==="Hourly") {
267 } else if (RecurrenceOpt ==="Daily") {
272 } else if (RecurrenceOpt ==="Weekly") {
279 var CRON_Expression = [CRON_sec, CRON_min, CRON_hr, CRON_date, CRON_month, CRON_day, CRON_year];
280 return CRON_Expression.join(" ");
283 $scope.ok = function() {
285 // DateTime for the start time: it should be noted that the start time
286 // for a CRON job should be prior to the trigger time.
287 $scope.trigger_dt = new Date( $scope.dt.getFullYear() +
288 "-" + ("0"+($scope.dt.getMonth()+1)).slice(-2) +
289 "-" +("0"+ $scope.dt.getDate()).slice(-2) +
290 " " + ("0" + $scope.selectFirstHour.value).slice(-2) +
291 ":" +("0" + $scope.selectFirstMinute.value).slice(-2) +
294 $scope.startDateTime_CRON = GenerateCronExpression($scope.trigger_dt, $scope.selectRecurrenceOpt.value)
296 //roll back the the start date time by 30 seconds (start time should be 30 seconds prior to trigger time)
297 dt_st = new Date($scope.trigger_dt - 30*1000)
299 startDateTime = dt_st.getFullYear() +
300 "-" + ("0"+(dt_st.getMonth()+1)).slice(-2) +
301 "-" +("0"+ dt_st.getDate()).slice(-2) +
302 " " + ("0" + dt_st.getHours()).slice(-2) +
303 ":" +("0" + dt_st.getMinutes()).slice(-2) +
304 ":" + ("0" + dt_st.getSeconds()).slice(-2) +".0";
305 $scope.startDateTime = startDateTime;
307 $scope.endDateTime = $scope.dt2.getFullYear() +
308 "-" + ("0"+($scope.dt2.getMonth()+1)).slice(-2) +
309 "-" +("0"+ $scope.dt2.getDate()).slice(-2) +
310 " " + ("0"+ $scope.selectLastHour.value).slice(-2) +
311 ":" +("0" + $scope.selectLastMinute.value).slice(-2) +
314 $scope.WorkflowScheduleObject = {};
315 $scope.WorkflowScheduleObject['startDateTime_CRON'] = $scope.startDateTime_CRON;
316 $scope.WorkflowScheduleObject['startDateTime'] = $scope.startDateTime;
317 $scope.WorkflowScheduleObject['endDateTime'] = $scope.endDateTime;
318 $scope.WorkflowScheduleObject['workflowKey'] = $scope.workflowToSchedule.workflowKey;
319 $scope.WorkflowScheduleObject['recurrence'] = $scope.selectRecurrenceOpt.value;
320 $scope.WorkflowScheduleObject['workflow_arguments'] = "test";
321 $scope.WorkflowScheduleObject['workflow_server_url'] = $scope.workflowToSchedule.runLink;
324 TimeFromNowToStart = new Date($scope.startDateTime)-new Date()
325 TimeStartToEnd = new Date($scope.endDateTime)-new Date($scope.startDateTime)
327 if (TimeFromNowToStart<=0) {
328 console.log("invalid start time input")
329 alert("Please ensure the scheduled start date time is later than current time.")
332 if (TimeStartToEnd<=0) {
333 console.log("invalid end time input")
334 alert("Please ensure the schduled end date time is later than the start time.")
337 // if successful then save and close
338 $scope.saveCronJob($scope.WorkflowScheduleObject);
339 $modalInstance.close();
343 $scope.saveCronJob = function(cronJobData){
345 console.log('saving cron job data: ' + cronJobData);
346 var uuu = "workflows/saveCronJob.htm";
347 var postData={cronJobDataObj: cronJobData};
351 //dataType: 'json', // data type expected from server
352 contentType: 'application/json',
353 data: JSON.stringify(postData), // data type sent to server
354 success : function(data){
355 $scope.$apply(function(){
356 //$scope.availableRoleFunctions=[];$scope.$apply();
357 // new // $scope.availableFnMenuItems=data.availableFnMenuItems;
360 //alert("Update Successful.") ;
361 //$scope.editRoleFunction = null;
362 // new /// $modalInstance.close({availableFnMenuItems:$scope.availableRoleFunctions});
364 error : function(data){
365 alert("Error while saving.");
371 $scope.cancel = function() {
372 console.log("cancel triggered")
373 $modalInstance.dismiss();
378 modalInstance.result.then(function () {
379 $scope.$emit('workflowRemoved');
381 $log.info('Modal dismissed at: ' + new Date());
393 $scope.previewWorkflow = function(workflowToPreview,modalSize){
394 var modalInstance = $modal.open({
395 animation: $scope.animationsEnabled,
396 templateUrl: 'app/fusion/scripts/DS2-view-models/DS2-workflows-page/workflow-preview.html',
397 sizeClass: 'modal-medium',
398 controller: ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
399 $scope.workflowToPreview = workflowToPreview;
400 console.log('previewWorkFlow invoked');
401 console.log($scope.workflowToPreview);
403 $scope.cancel = function() {
404 $modalInstance.dismiss();
409 modalInstance.result.then(function () {
410 $scope.$emit('workflowRemoved');
412 $log.info('Modal dismissed at: ' + new Date());
418 /* change work flow status based on the boolean variable "suspendBool" which corresponds whether
419 * we would like to suspend or activate a workflow specified by key. */
420 $scope.changeWorkflowStatus = function(workflowToChangeStatus,suspendBool){
421 if (workflowToChangeStatus!==null) {
422 var statusUrl= workflowToChangeStatus.runLink+"/engine-rest/process-definition/key/"+workflowToChangeStatus.workflowKey
423 var suspendedUrl= statusUrl+"/suspended"
424 var xmlHttp = new XMLHttpRequest();
425 xmlHttp.open('PUT', suspendedUrl, false);
426 xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
427 xmlHttp.onload = function() {
429 console.log("process definition is now suspended");
430 workflowToChangeStatus.active="false"
432 console.log("process definition is now activated");
433 workflowToChangeStatus.active="true"
436 xmlHttp.send(JSON.stringify({
437 "suspended" : suspendBool,
438 "includeProcessInstances" : true,
439 "executionDate" : "2013-11-21T10:49:45"
445 $scope.activateWorkflow = function(workflowToActivate){
446 $scope.changeWorkflowStatus(workflowToActivate,false)
450 $scope.suspendWorkflow = function(workflowToActivate){
451 $scope.changeWorkflowStatus(workflowToActivate,true)
454 $scope.checkWorkflowStatus = function(workflow) {
455 if (workflow!==null) {
456 var statusUrl= workflow.runLink+"/engine-rest/process-definition/key/"+workflow.workflowKey
457 var xmlHttp3 = new XMLHttpRequest();
458 xmlHttp3.open('GET', statusUrl, true);
459 xmlHttp3.withCredentials = true;
461 xmlHttp3.onreadystatechange = function() {
462 if (xmlHttp3.readyState == 4 && xmlHttp3.status == 200) {
463 // do something with the response in the variable data
464 var temp = JSON.parse(xmlHttp3.responseText)
465 if (temp.suspended == false){
466 console.log("Activated")
467 workflow.active="true"
469 console.log("Suspended")
470 workflow.active="false"
477 $scope.StartWorkflowInstance = function(workflowToStart){
478 if (workflowToStart!==null) {
479 var statusUrl= workflowToStart.runLink+"/engine-rest/process-definition/key/"+workflowToStart.workflowKey
480 var suspendedUrl= statusUrl+"/submit-form"
481 var xmlHttp = new XMLHttpRequest();
482 xmlHttp.open('POST', suspendedUrl, false);
483 xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
484 xmlHttp.onload = function() {
486 xmlHttp.send(JSON.stringify({
488 "customerId": {"value":"asdasda","type":"String"},
489 "amount":{"value":"100","type":"String"}
497 $scope.$on('workflowAdded', function(event, newWorkflow) {
498 console.log("New Workflow to be added in list scope " + JSON.stringify(newWorkflow));
499 //$scope.workflows.push(newWorkflow);
500 $scope.fetchWorkflowsList();
501 console.log('newly added workflow = ' + JSON.stringify(newWorkflow));
504 $scope.$on('workflowRemoved', function(event) {
505 $scope.fetchWorkflowsList();
508 $scope.fetchWorkflowsList();