2014-06-22 00:22:38 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var app = angular.module('app', [
|
|
|
|
'ngRoute',
|
|
|
|
'ui.filters'
|
|
|
|
]);
|
|
|
|
|
|
|
|
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
|
|
|
|
$routeProvider.when('/', {
|
2014-07-10 04:11:28 +03:00
|
|
|
templateUrl: '/views/home.html',
|
2014-06-22 00:22:38 +03:00
|
|
|
controller: 'HomeController',
|
|
|
|
title: 'Dashboard',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-07-10 08:24:06 +03:00
|
|
|
.when('/sync', {
|
|
|
|
templateUrl: '/views/sync.html',
|
|
|
|
controller: 'SyncController',
|
|
|
|
title: 'Sync'
|
|
|
|
})
|
2014-06-22 00:22:38 +03:00
|
|
|
.when('/login', {
|
|
|
|
templateUrl: '/views/login.html',
|
|
|
|
title: 'Login',
|
|
|
|
})
|
|
|
|
.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-10 00:25:11 +03: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-22 00:22:38 +03:00
|
|
|
.when('/admin/users', {
|
2014-07-10 00:25:11 +03:00
|
|
|
templateUrl: '/views/users.html',
|
2014-06-22 00:22:38 +03:00
|
|
|
controller: 'UsersController',
|
|
|
|
title: 'System Users',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/admin/settings', {
|
|
|
|
templateUrl: '/views/sys_config.html',
|
|
|
|
controller: 'ConfigController',
|
|
|
|
title: 'System Settings',
|
|
|
|
resolve: {
|
|
|
|
user: function(authService) {
|
|
|
|
return authService.getUser();
|
|
|
|
},
|
|
|
|
conf: function(confService) {
|
|
|
|
return confService.getConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.when('/:remote/:owner/:name/settings', {
|
2014-07-10 08:24:06 +03:00
|
|
|
templateUrl: '/views/repo_edit.html',
|
2014-06-22 00:22:38 +03: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 23:46:04 +03:00
|
|
|
repo: function($route, repos) {
|
2014-06-22 00:22:38 +03:00
|
|
|
var remote = $route.current.params.remote;
|
|
|
|
var owner = $route.current.params.owner;
|
|
|
|
var name = $route.current.params.name;
|
2014-07-11 23:46:04 +03:00
|
|
|
return repos.getRepo(remote, owner, name);
|
2014-06-22 00:22:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// use the HTML5 History API
|
|
|
|
$locationProvider.html5Mode(true);
|
|
|
|
}]);
|
|
|
|
|
|
|
|
/* Directives */
|
|
|
|
|
|
|
|
/* also see https://coderwall.com/p/vcfo4q */
|
|
|
|
app.run(['$location', '$rootScope', '$routeParams', function($location, $rootScope, $routeParams) {
|
|
|
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
|
|
|
document.title = current.$$route.title + ' · drone.io';
|
|
|
|
});
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.controller("ConfigController", function($scope, $http, user) {
|
|
|
|
|
|
|
|
$scope.user = user;
|
|
|
|
|
|
|
|
$http({method: 'GET', url: '/v1/config'}).
|
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.config = data;
|
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-22 13:02:22 +03:00
|
|
|
app.controller("CommitController", function($scope, $http, $routeParams, stdout, feed, notify) {
|
2014-06-22 00:22:38 +03:00
|
|
|
|
|
|
|
var remote = $routeParams.remote;
|
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var branch = $routeParams.branch;
|
|
|
|
var commit = $routeParams.commit;
|
|
|
|
|
2014-06-22 13:02:22 +03:00
|
|
|
feed.subscribe(function(item) {
|
|
|
|
// if the
|
|
|
|
if (item.commit.sha == commit
|
|
|
|
&& item.commit.branch == branch) {
|
|
|
|
$scope.commit = item.commit;
|
|
|
|
$scope.$apply();
|
|
|
|
} else {
|
|
|
|
// we trigger an html5 notification so the
|
|
|
|
// user is aware another build started
|
|
|
|
notify.sendCommit(
|
|
|
|
item.repo,
|
|
|
|
item.commit
|
|
|
|
);
|
2014-06-22 12:04:07 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-22 00:22:38 +03: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 12:04:07 +03:00
|
|
|
|
|
|
|
if (data.status!='Started' && data.status!='Pending') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stdout.subscribe(data.id, function(out){
|
|
|
|
console.log(out);
|
|
|
|
});
|
2014-06-22 00:22:38 +03:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
// load the repo build stdout
|
2014-07-09 10:46:15 +03:00
|
|
|
$http({method: 'GET', url: '/v1/repos/'+remote+'/'+owner+"/"+name+"/branches/"+branch+"/commits/"+commit+"/console"}).
|
2014-06-22 00:22:38 +03:00
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.console = data;
|
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
2014-06-22 12:04:07 +03:00
|
|
|
});
|