Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular
- .module('hawk.pipelinesManagement')
- .controller('PipelinesController', function ($log, pipeStats, pipeConfig) {
- var vm = this;
- vm.toggleLogo = 1;
- vm.formData = {};
- vm.allPipelines = [];
- vm.allPipesDefWithRuns = [];
- vm.notExecPipe = [];
- vm.index = 0;
- vm.getGroupName = function (input) {
- vm.groupName = input;
- };
- vm.getAll = function () {
- pipeConfig.getAllPipelines()
- .then(function (res) {
- vm.allPipesDefWithRuns = [];
- for (var i in res) {
- vm.index = i;
- pipeStats.getAllRunsByName(res[i].OriginalName)
- .then(function (res) {
- var sortedRuns = res;
- sortedRuns = _.sortBy(sortedRuns, 'ExecutionID');
- vm.allPipesDefWithRuns.push(sortedRuns[sortedRuns.length-1]);
- console.log(vm.allPipesDefWithRuns);
- }, function (err) {
- vm.notExecPipe = {
- "OriginalName": res[vm.index].OriginalName,
- "Started": '',
- "End": '',
- "Reason": "Not Executed"
- };
- vm.allPipesDefWithRuns.push(vm.notExecPipe);
- console.log(vm.allPipesDefWithRuns);
- });
- }
- }, function (err) {
- })
- };
- vm.addPipeline = function(formData){
- var materials = [];
- if (formData.materials.git) {
- var git = {
- "PipelineName": formData.pipeline.name,
- "Name": formData.materials.git.name,
- "Type": 'GIT',
- "Url": formData.materials.git.url,
- "AutoTriggerOnChange": formData.materials.git.poll,
- "Destination": formData.materials.git.name,
- "MaterialSpecificDetails": {
- "branch": 'master'
- //"username": formData.materials.git.username || '',
- //"password": formData.materials.git.password || ''
- }
- };
- materials.push(git);
- }
- if (formData.materials.tfs) {
- var tfs = {
- "PipelineName": formData.pipeline.name,
- "Name": formData.materials.tfs.name,
- "Type": 'TFS',
- "AutoTriggerOnChange": formData.materials.tfs.poll,
- "Destination": formData.materials.tfs.name,
- "MaterialSpecificDetails": {
- "domain": formData.materials.tfs.domain,
- "projectPath": formData.materials.tfs.projectPath,
- "username": formData.materials.tfs.username,
- "password": formData.materials.tfs.password
- }
- };
- materials.push(tfs);
- }
- var pipeline = {
- "OriginalName": formData.pipeline.name,
- "Name": formData.pipeline.name,
- "GroupName": vm.groupName,
- "Materials": materials,
- "EnvironmentVariables": [],
- "Parameters": [],
- "Environment": {},
- "Stages": [
- {
- "Name": formData.stage.name,
- "Jobs": [
- {
- "Name": "defaultJob",
- "Tasks": [
- {
- "Command": "cmd",
- "Arguments": ["/c"],
- "RunIfCondition": 'Passed',
- "Type": 'Exec'
- }
- ],
- "EnvironmentVariables": []
- }
- ],
- "EnvironmentVariables": [],
- "Security": null,
- "FetchMaterials": true,
- "NeverCleanArtifacts": false,
- "CleanWorkingDirectory": false,
- "StageType": formData.stage.trigger
- }
- ],
- "AutoScheduling": formData.pipeline.autoSchedule
- };
- console.log(pipeline);
- pipeConfig.createPipeline(pipeline)
- .then(function (success) {
- vm.getAll();
- //console.log(vm.allPipelines);
- }, function (err) {
- vm.getAll();
- console.log(err);
- })
- };
- function groupPipelinesByGroup(groups) {
- groups = _.groupBy(groups, 'GroupName');
- for (var pipeline in groups) {
- groups[pipeline] = _.groupBy(groups[pipeline], 'Name');
- for (var run in groups[pipeline]) {
- groups[pipeline][run] = _.sortBy(groups[pipeline][run], 'ExecutionID');
- }
- }
- return groups;
- }
- //Start the form wizard script on page load
- FormWizard.init();
- vm.wizardInfo = {
- steps: {
- first: 'Setup',
- second: 'Materials',
- third: 'Review'
- },
- buttons: {
- back: 'Back',
- continue: 'Continue',
- submit: 'Submit'
- },
- labels: {
- autoSchedule: 'Auto Scheduling',
- name: 'Name',
- pipelineName: 'Pipeline Name',
- gitUrl: 'Git URL',
- branch: 'Branch',
- username: 'Username',
- password: 'Password',
- tfsDomain: 'Domain',
- projectPath: 'Project Path',
- stageName: 'Stage Name',
- trigger: 'Trigger option'
- },
- validationMsg: {
- error: "You have some form errors. Please check below.",
- success: "Your form validation is successful!"
- },
- placeholders: {
- pipelineName: 'Enter your pipeline name',
- gitUrl: 'Enter your git url',
- username: 'Enter TFS username',
- password: 'Enter TFS password',
- tfsDomain: 'Enter TFS domain',
- projectPath: 'Enter TFS project path',
- stageName: 'Enter stage name',
- materialName: 'Enter material name',
- gitUsername: 'Enter GIT username',
- gitPassword: 'Enter GIT password'
- }
- };
- //Changes class of logos if name is entered by user
- vm.gitInputChange = function (gitName) {
- if (gitName == undefined || gitName.length == 0) {
- $('#logoGit').removeClass('l-active2');
- }
- else {
- $('#logoGit').addClass('l-active2');
- }
- };
- vm.tfsInputChange = function (tfsName) {
- if (tfsName == undefined || tfsName.length == 0) {
- $('#logoTfs').removeClass('l-active2');
- }
- else {
- $('#logoTfs').addClass('l-active2');
- }
- };
- //End of logos functions
- vm.getAll();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement