2014-06-21 21:22:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var app = angular.module('app', [
|
|
|
|
'ngRoute',
|
|
|
|
'ui.filters'
|
|
|
|
]);
|
|
|
|
|
2014-08-16 20:52:33 +00:00
|
|
|
app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) {
|
2014-06-21 21:22:38 +00:00
|
|
|
$routeProvider.when('/', {
|
2014-07-10 01:11:28 +00:00
|
|
|
templateUrl: '/views/home.html',
|
2014-06-21 21:22:38 +00:00
|
|
|
controller: 'HomeController',
|
|
|
|
title: 'Dashboard',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-07-10 05:24:06 +00:00
|
|
|
.when('/sync', {
|
|
|
|
templateUrl: '/views/sync.html',
|
|
|
|
controller: 'SyncController',
|
|
|
|
title: 'Sync'
|
|
|
|
})
|
2014-06-21 21:22:38 +00:00
|
|
|
.when('/login', {
|
|
|
|
templateUrl: '/views/login.html',
|
2014-07-13 02:01:58 +00:00
|
|
|
controller: 'LoginController',
|
2014-06-21 21:22:38 +00:00
|
|
|
title: 'Login',
|
|
|
|
})
|
2014-09-03 07:43:36 +00:00
|
|
|
.when('/gitlab', {
|
|
|
|
templateUrl: '/views/login_gitlab.html',
|
|
|
|
title: 'GitLab Login',
|
|
|
|
})
|
2014-06-21 21:22:38 +00:00
|
|
|
.when('/setup', {
|
|
|
|
templateUrl: '/views/setup.html',
|
|
|
|
controller: 'SetupController',
|
|
|
|
title: 'Setup'
|
|
|
|
})
|
|
|
|
.when('/setup/:remote', {
|
|
|
|
templateUrl: '/views/setup.html',
|
|
|
|
controller: 'SetupController',
|
|
|
|
title: 'Setup'
|
|
|
|
})
|
|
|
|
.when('/account/profile', {
|
|
|
|
templateUrl: '/views/account.html',
|
|
|
|
controller: 'UserController',
|
|
|
|
title: 'Profile',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/account/repos', {
|
|
|
|
templateUrl: '/views/repo_list.html',
|
|
|
|
controller: 'AccountReposController',
|
|
|
|
title: 'Repositories',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-07-09 21:25:11 +00:00
|
|
|
.when('/admin/users/add', {
|
|
|
|
templateUrl: '/views/users_add.html',
|
|
|
|
controller: 'UserAddController',
|
|
|
|
title: 'Add User',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/admin/users/:host/:login', {
|
|
|
|
templateUrl: '/views/users_edit.html',
|
|
|
|
controller: 'UserEditController',
|
|
|
|
title: 'Edit User',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-06-21 21:22:38 +00:00
|
|
|
.when('/admin/users', {
|
2014-07-09 21:25:11 +00:00
|
|
|
templateUrl: '/views/users.html',
|
2014-06-21 21:22:38 +00:00
|
|
|
controller: 'UsersController',
|
|
|
|
title: 'System Users',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/admin/settings', {
|
2014-07-14 07:00:04 +00:00
|
|
|
templateUrl: '/views/config.html',
|
2014-06-21 21:22:38 +00:00
|
|
|
controller: 'ConfigController',
|
|
|
|
title: 'System Settings',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/:remote/:owner/:name/settings', {
|
2014-07-10 05:24:06 +00:00
|
|
|
templateUrl: '/views/repo_edit.html',
|
2014-06-21 21:22:38 +00:00
|
|
|
controller: 'RepoConfigController',
|
|
|
|
title: 'Repository Settings',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/:remote/:owner/:name/:branch/:commit', {
|
|
|
|
templateUrl: '/views/commit.html',
|
|
|
|
controller: 'CommitController',
|
|
|
|
title: 'Recent Commits',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/:remote/:owner/:name', {
|
|
|
|
templateUrl: '/views/repo.html',
|
|
|
|
controller: 'RepoController',
|
|
|
|
title: 'Recent Commits',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
},
|
2014-07-11 20:46:04 +00:00
|
|
|
repo: function($route, repos) {
|
2014-06-21 21:22:38 +00:00
|
|
|
var remote = $route.current.params.remote;
|
|
|
|
var owner = $route.current.params.owner;
|
|
|
|
var name = $route.current.params.name;
|
2014-07-11 20:46:04 +00:00
|
|
|
return repos.getRepo(remote, owner, name);
|
2014-06-21 21:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// use the HTML5 History API
|
|
|
|
$locationProvider.html5Mode(true);
|
2014-08-16 20:52:33 +00:00
|
|
|
|
|
|
|
$httpProvider.interceptors.push(function($q, $location) {
|
|
|
|
return {
|
|
|
|
'responseError': function(rejection) {
|
2014-08-18 06:26:29 +00:00
|
|
|
if (rejection.status == 401 && rejection.config.url != "/v1/user") {
|
2014-08-16 20:52:33 +00:00
|
|
|
$location.path('/login');
|
|
|
|
}
|
|
|
|
return $q.reject(rejection);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-06-21 21:22:38 +00:00
|
|
|
}]);
|
|
|
|
|
|
|
|
/* also see https://coderwall.com/p/vcfo4q */
|
2014-07-11 22:29:31 +00:00
|
|
|
app.run(['$location', '$rootScope', '$routeParams', 'feed', 'stdout', function($location, $rootScope, $routeParams, feed, stdout) {
|
|
|
|
|
|
|
|
$rootScope.$on('$routeChangeStart', function (event, next) {
|
|
|
|
feed.unsubscribe();
|
|
|
|
stdout.unsubscribe();
|
|
|
|
});
|
|
|
|
|
2014-06-21 21:22:38 +00:00
|
|
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
|
|
|
document.title = current.$$route.title + ' · drone.io';
|
|
|
|
});
|
2014-08-16 20:52:33 +00:00
|
|
|
|
2014-06-21 21:22:38 +00:00
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Controllers */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.controller("AccountReposController", function($scope, $http, user) {
|
|
|
|
|
|
|
|
$scope.user = user;
|
|
|
|
|
|
|
|
// get the user details
|
|
|
|
$http({method: 'GET', url: '/v1/user/repos'}).
|
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.repos = (typeof data==='string')?[]:data;
|
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.active="";
|
|
|
|
$scope.remote="";
|
|
|
|
$scope.byActive = function(entry){
|
|
|
|
switch (true) {
|
|
|
|
case $scope.active == "true" && !entry.active: return false;
|
|
|
|
case $scope.active == "false" && entry.active: return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
$scope.byRemote = function(entry){
|
|
|
|
return $scope.remote == "" || $scope.remote == entry.remote;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-13 23:46:49 +00:00
|
|
|
app.controller("CommitController", function($scope, $http, $routeParams, stdout, feed) {
|
2014-06-21 21:22:38 +00:00
|
|
|
|
|
|
|
var remote = $routeParams.remote;
|
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var branch = $routeParams.branch;
|
|
|
|
var commit = $routeParams.commit;
|
2014-07-12 02:10:18 +00:00
|
|
|
$scope.console='';
|
2014-06-21 21:22:38 +00:00
|
|
|
|
2014-06-22 10:02:22 +00:00
|
|
|
feed.subscribe(function(item) {
|
2014-07-12 02:10:18 +00:00
|
|
|
if (item.commit.sha == commit &&
|
|
|
|
item.commit.branch == branch) {
|
2014-06-22 10:02:22 +00:00
|
|
|
$scope.commit = item.commit;
|
|
|
|
$scope.$apply();
|
|
|
|
} else {
|
2014-07-13 23:46:49 +00:00
|
|
|
// we trigger an toast notification so the
|
2014-06-22 10:02:22 +00:00
|
|
|
// user is aware another build started
|
2014-07-13 23:46:49 +00:00
|
|
|
|
2014-06-22 09:04:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-21 21:22:38 +00:00
|
|
|
// load the repo meta-data
|
|
|
|
$http({method: 'GET', url: '/v1/repos/'+remote+'/'+owner+"/"+name}).
|
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.repo = data;
|
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
// load the repo commit data
|
|
|
|
$http({method: 'GET', url: '/v1/repos/'+remote+'/'+owner+"/"+name+"/branches/"+branch+"/commits/"+commit}).
|
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.commit = data;
|
2014-06-22 09:04:07 +00:00
|
|
|
|
|
|
|
if (data.status!='Started' && data.status!='Pending') {
|
2014-07-11 23:52:22 +00:00
|
|
|
$http({method: 'GET', url: '/v1/repos/'+remote+'/'+owner+"/"+name+"/branches/"+branch+"/commits/"+commit+"/console"}).
|
|
|
|
success(function(data, status, headers, config) {
|
2014-07-12 02:10:18 +00:00
|
|
|
var lineFormatter = new Drone.LineFormatter();
|
|
|
|
var el = document.querySelector('#output');
|
|
|
|
angular.element(el).append(lineFormatter.format(data));
|
2014-07-11 23:52:22 +00:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
2014-07-12 02:10:18 +00:00
|
|
|
return;
|
2014-06-22 09:04:07 +00:00
|
|
|
}
|
|
|
|
|
2014-07-12 02:10:18 +00:00
|
|
|
var lineFormatter = new Drone.LineFormatter();
|
|
|
|
var el = document.querySelector('#output');
|
2014-06-22 09:04:07 +00:00
|
|
|
stdout.subscribe(data.id, function(out){
|
2014-07-12 02:10:18 +00:00
|
|
|
angular.element(el).append(lineFormatter.format(out));
|
2014-06-22 09:04:07 +00:00
|
|
|
});
|
2014-06-21 21:22:38 +00:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
2014-07-11 23:52:22 +00:00
|
|
|
|
2014-06-21 21:22:38 +00:00
|
|
|
|
2014-06-22 09:04:07 +00:00
|
|
|
});
|