Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. 'use strict';
  2.  
  3. angular
  4. .module('hawk.pipelinesManagement')
  5. .controller('PipelinesController', function ($log, pipeStats, pipeConfig) {
  6. var vm = this;
  7. vm.toggleLogo = 1;
  8.  
  9. vm.formData = {};
  10. vm.allPipelines = [];
  11. vm.allPipesDefWithRuns = [];
  12. vm.notExecPipe = [];
  13. vm.index = 0;
  14.  
  15. vm.getGroupName = function (input) {
  16. vm.groupName = input;
  17. };
  18.  
  19. vm.getAll = function () {
  20. pipeConfig.getAllPipelines()
  21. .then(function (res) {
  22. vm.allPipesDefWithRuns = [];
  23. for (var i in res) {
  24. vm.index = i;
  25.  
  26. pipeStats.getAllRunsByName(res[i].OriginalName)
  27. .then(function (res) {
  28. var sortedRuns = res;
  29.  
  30. sortedRuns = _.sortBy(sortedRuns, 'ExecutionID');
  31.  
  32. vm.allPipesDefWithRuns.push(sortedRuns[sortedRuns.length-1]);
  33.  
  34. console.log(vm.allPipesDefWithRuns);
  35. }, function (err) {
  36. vm.notExecPipe = {
  37. "OriginalName": res[vm.index].OriginalName,
  38. "Started": '',
  39. "End": '',
  40. "Reason": "Not Executed"
  41. };
  42.  
  43. vm.allPipesDefWithRuns.push(vm.notExecPipe);
  44. console.log(vm.allPipesDefWithRuns);
  45. });
  46. }
  47.  
  48.  
  49. }, function (err) {
  50.  
  51. })
  52. };
  53.  
  54. vm.addPipeline = function(formData){
  55. var materials = [];
  56. if (formData.materials.git) {
  57. var git = {
  58. "PipelineName": formData.pipeline.name,
  59. "Name": formData.materials.git.name,
  60. "Type": 'GIT',
  61. "Url": formData.materials.git.url,
  62. "AutoTriggerOnChange": formData.materials.git.poll,
  63. "Destination": formData.materials.git.name,
  64. "MaterialSpecificDetails": {
  65. "branch": 'master'
  66. //"username": formData.materials.git.username || '',
  67. //"password": formData.materials.git.password || ''
  68. }
  69. };
  70. materials.push(git);
  71. }
  72. if (formData.materials.tfs) {
  73. var tfs = {
  74. "PipelineName": formData.pipeline.name,
  75. "Name": formData.materials.tfs.name,
  76. "Type": 'TFS',
  77. "AutoTriggerOnChange": formData.materials.tfs.poll,
  78. "Destination": formData.materials.tfs.name,
  79. "MaterialSpecificDetails": {
  80. "domain": formData.materials.tfs.domain,
  81. "projectPath": formData.materials.tfs.projectPath,
  82. "username": formData.materials.tfs.username,
  83. "password": formData.materials.tfs.password
  84. }
  85. };
  86. materials.push(tfs);
  87. }
  88.  
  89. var pipeline = {
  90. "OriginalName": formData.pipeline.name,
  91. "Name": formData.pipeline.name,
  92. "GroupName": vm.groupName,
  93. "Materials": materials,
  94. "EnvironmentVariables": [],
  95. "Parameters": [],
  96. "Environment": {},
  97. "Stages": [
  98. {
  99. "Name": formData.stage.name,
  100. "Jobs": [
  101. {
  102. "Name": "defaultJob",
  103. "Tasks": [
  104. {
  105. "Command": "cmd",
  106. "Arguments": ["/c"],
  107. "RunIfCondition": 'Passed',
  108. "Type": 'Exec'
  109. }
  110. ],
  111. "EnvironmentVariables": []
  112. }
  113. ],
  114. "EnvironmentVariables": [],
  115. "Security": null,
  116. "FetchMaterials": true,
  117. "NeverCleanArtifacts": false,
  118. "CleanWorkingDirectory": false,
  119. "StageType": formData.stage.trigger
  120. }
  121. ],
  122. "AutoScheduling": formData.pipeline.autoSchedule
  123. };
  124.  
  125. console.log(pipeline);
  126.  
  127. pipeConfig.createPipeline(pipeline)
  128. .then(function (success) {
  129. vm.getAll();
  130. //console.log(vm.allPipelines);
  131. }, function (err) {
  132. vm.getAll();
  133. console.log(err);
  134. })
  135. };
  136.  
  137. function groupPipelinesByGroup(groups) {
  138. groups = _.groupBy(groups, 'GroupName');
  139. for (var pipeline in groups) {
  140. groups[pipeline] = _.groupBy(groups[pipeline], 'Name');
  141. for (var run in groups[pipeline]) {
  142. groups[pipeline][run] = _.sortBy(groups[pipeline][run], 'ExecutionID');
  143. }
  144. }
  145. return groups;
  146. }
  147.  
  148. //Start the form wizard script on page load
  149. FormWizard.init();
  150.  
  151. vm.wizardInfo = {
  152. steps: {
  153. first: 'Setup',
  154. second: 'Materials',
  155. third: 'Review'
  156. },
  157. buttons: {
  158. back: 'Back',
  159. continue: 'Continue',
  160. submit: 'Submit'
  161. },
  162. labels: {
  163. autoSchedule: 'Auto Scheduling',
  164. name: 'Name',
  165. pipelineName: 'Pipeline Name',
  166. gitUrl: 'Git URL',
  167. branch: 'Branch',
  168. username: 'Username',
  169. password: 'Password',
  170. tfsDomain: 'Domain',
  171. projectPath: 'Project Path',
  172. stageName: 'Stage Name',
  173. trigger: 'Trigger option'
  174. },
  175. validationMsg: {
  176. error: "You have some form errors. Please check below.",
  177. success: "Your form validation is successful!"
  178. },
  179. placeholders: {
  180. pipelineName: 'Enter your pipeline name',
  181. gitUrl: 'Enter your git url',
  182. username: 'Enter TFS username',
  183. password: 'Enter TFS password',
  184. tfsDomain: 'Enter TFS domain',
  185. projectPath: 'Enter TFS project path',
  186. stageName: 'Enter stage name',
  187. materialName: 'Enter material name',
  188. gitUsername: 'Enter GIT username',
  189. gitPassword: 'Enter GIT password'
  190. }
  191. };
  192.  
  193. //Changes class of logos if name is entered by user
  194. vm.gitInputChange = function (gitName) {
  195. if (gitName == undefined || gitName.length == 0) {
  196. $('#logoGit').removeClass('l-active2');
  197. }
  198. else {
  199. $('#logoGit').addClass('l-active2');
  200. }
  201. };
  202.  
  203. vm.tfsInputChange = function (tfsName) {
  204. if (tfsName == undefined || tfsName.length == 0) {
  205. $('#logoTfs').removeClass('l-active2');
  206. }
  207. else {
  208. $('#logoTfs').addClass('l-active2');
  209. }
  210. };
  211. //End of logos functions
  212.  
  213. vm.getAll();
  214. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement