mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-11-01 13:38:33 +00:00
Little refactoring of all assets. JS code better identing.
This commit is contained in:
@@ -1,221 +1,221 @@
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* BuildsCtrl responsible for rendering the repo's
|
||||
* recent build history.
|
||||
*/
|
||||
function BuildsCtrl($scope, $stateParams, builds, repos, users, logs) {
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner+'/'+name;
|
||||
/**
|
||||
* BuildsCtrl responsible for rendering the repo's
|
||||
* recent build history.
|
||||
*/
|
||||
function BuildsCtrl($scope, $stateParams, builds, repos, users, logs) {
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner + '/' + name;
|
||||
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function(payload){
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
// Gets a list of builds
|
||||
builds.list(fullName).then(function(payload){
|
||||
$scope.builds = angular.isArray(payload.data) ? payload.data : [];
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets a list of builds
|
||||
builds.list(fullName).then(function (payload) {
|
||||
$scope.builds = angular.isArray(payload.data) ? payload.data : [];
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
$scope.watch = function(repo) {
|
||||
repos.watch(repo.full_name).then(function(payload) {
|
||||
$scope.repo.starred = true;
|
||||
});
|
||||
}
|
||||
$scope.watch = function (repo) {
|
||||
repos.watch(repo.full_name).then(function (payload) {
|
||||
$scope.repo.starred = true;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.unwatch = function(repo) {
|
||||
repos.unwatch(repo.full_name).then(function() {
|
||||
$scope.repo.starred = false;
|
||||
});
|
||||
}
|
||||
$scope.unwatch = function (repo) {
|
||||
repos.unwatch(repo.full_name).then(function () {
|
||||
$scope.repo.starred = false;
|
||||
});
|
||||
};
|
||||
|
||||
repos.subscribe(fullName, function(event) {
|
||||
var added = false;
|
||||
for (var i=0;i<$scope.builds.length;i++) {
|
||||
var build = $scope.builds[i];
|
||||
if (event.number !== build.number) {
|
||||
continue; // ignore
|
||||
}
|
||||
// update the build status
|
||||
$scope.builds[i] = event;
|
||||
$scope.$apply();
|
||||
added = true;
|
||||
}
|
||||
repos.subscribe(fullName, function (event) {
|
||||
var added = false;
|
||||
for (var i = 0; i < $scope.builds.length; i++) {
|
||||
var build = $scope.builds[i];
|
||||
if (event.number !== build.number) {
|
||||
continue; // ignore
|
||||
}
|
||||
// update the build status
|
||||
$scope.builds[i] = event;
|
||||
$scope.$apply();
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
$scope.builds.push(event);
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!added) {
|
||||
$scope.builds.push(event);
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* BuildCtrl responsible for rendering a build.
|
||||
*/
|
||||
function BuildCtrl($scope, $stateParams, $window, logs, builds, repos, users) {
|
||||
/**
|
||||
* BuildCtrl responsible for rendering a build.
|
||||
*/
|
||||
function BuildCtrl($scope, $stateParams, $window, logs, builds, repos, users) {
|
||||
|
||||
var number = $stateParams.number;
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner+'/'+name;
|
||||
var number = $stateParams.number;
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner + '/' + name;
|
||||
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function(payload){
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
// Gets the build
|
||||
builds.get(fullName, number).then(function(payload){
|
||||
$scope.build = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets the build
|
||||
builds.get(fullName, number).then(function (payload) {
|
||||
$scope.build = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
repos.subscribe(fullName, function(event) {
|
||||
if (event.number !== parseInt(number)) {
|
||||
return; // ignore
|
||||
}
|
||||
// update the build
|
||||
$scope.build = event;
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
repos.subscribe(fullName, function (event) {
|
||||
if (event.number !== parseInt(number)) {
|
||||
return; // ignore
|
||||
}
|
||||
// update the build
|
||||
$scope.build = event;
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BuildOutCtrl responsible for rendering a build output.
|
||||
*/
|
||||
function BuildOutCtrl($scope, $stateParams, $window, logs, builds, repos, users) {
|
||||
/**
|
||||
* BuildOutCtrl responsible for rendering a build output.
|
||||
*/
|
||||
function BuildOutCtrl($scope, $stateParams, $window, logs, builds, repos, users) {
|
||||
|
||||
var step = parseInt($stateParams.step) || 1;
|
||||
var number = $stateParams.number;
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner+'/'+name;
|
||||
var streaming = false;
|
||||
var tail = false;
|
||||
var step = parseInt($stateParams.step) || 1;
|
||||
var number = $stateParams.number;
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner + '/' + name;
|
||||
var streaming = false;
|
||||
var tail = false;
|
||||
|
||||
// Initiates streaming a build.
|
||||
var stream = function() {
|
||||
if (streaming) {
|
||||
return;
|
||||
}
|
||||
streaming = true;
|
||||
// Initiates streaming a build.
|
||||
var stream = function () {
|
||||
if (streaming) {
|
||||
return;
|
||||
}
|
||||
streaming = true;
|
||||
|
||||
var convert = new Filter({stream:true,newline:false});
|
||||
var term = document.getElementById("term");
|
||||
term.innerHTML = "";
|
||||
var convert = new Filter({stream: true, newline: false});
|
||||
var term = document.getElementById("term");
|
||||
term.innerHTML = "";
|
||||
|
||||
// subscribes to the build otuput.
|
||||
logs.subscribe(fullName, number, step, function(data){
|
||||
term.innerHTML += convert.toHtml(data.replace("\\n","\n"));
|
||||
if (tail) {
|
||||
// scrolls to the bottom of the page if enabled
|
||||
$window.scrollTo(0, $window.document.body.scrollHeight);
|
||||
}
|
||||
});
|
||||
}
|
||||
// subscribes to the build otuput.
|
||||
logs.subscribe(fullName, number, step, function (data) {
|
||||
term.innerHTML += convert.toHtml(data.replace("\\n", "\n"));
|
||||
if (tail) {
|
||||
// scrolls to the bottom of the page if enabled
|
||||
$window.scrollTo(0, $window.document.body.scrollHeight);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function(payload){
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
// Gets the build
|
||||
builds.get(fullName, number).then(function(payload){
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.jobs[step-1];
|
||||
// Gets the build
|
||||
builds.get(fullName, number).then(function (payload) {
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.jobs[step - 1];
|
||||
|
||||
if (['pending', 'killed'].indexOf($scope.task.status) !== -1) {
|
||||
// do nothing
|
||||
} else if ($scope.task.status === 'running') {
|
||||
// stream the build
|
||||
stream();
|
||||
} else {
|
||||
if (['pending', 'killed'].indexOf($scope.task.status) !== -1) {
|
||||
// do nothing
|
||||
} else if ($scope.task.status === 'running') {
|
||||
// stream the build
|
||||
stream();
|
||||
} else {
|
||||
|
||||
// fetch the logs for the finished build.
|
||||
logs.get(fullName, number, step).then(function(payload){
|
||||
var convert = new Filter({stream:false,newline:false});
|
||||
var term = document.getElementById("term")
|
||||
term.innerHTML = convert.toHtml(payload.data);
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// fetch the logs for the finished build.
|
||||
logs.get(fullName, number, step).then(function (payload) {
|
||||
var convert = new Filter({stream: false, newline: false});
|
||||
var term = document.getElementById("term")
|
||||
term.innerHTML = convert.toHtml(payload.data);
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
$scope.restart = function() {
|
||||
builds.restart(fullName, number).then(function(payload){
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.builds[step-1];
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
$scope.restart = function () {
|
||||
builds.restart(fullName, number).then(function (payload) {
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.builds[step - 1];
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cancel = function() {
|
||||
builds.cancel(fullName, number).then(function(payload){
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.builds[step-1];
|
||||
}).catch(function(err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
$scope.cancel = function () {
|
||||
builds.cancel(fullName, number).then(function (payload) {
|
||||
$scope.build = payload.data;
|
||||
$scope.task = payload.data.builds[step - 1];
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.tail = function() {
|
||||
tail = !tail;
|
||||
};
|
||||
$scope.tail = function () {
|
||||
tail = !tail;
|
||||
};
|
||||
|
||||
repos.subscribe(fullName, function(event) {
|
||||
if (event.number !== parseInt(number)) {
|
||||
return; // ignore
|
||||
}
|
||||
// update the build
|
||||
$scope.build = event;
|
||||
$scope.task = event.builds[step-1];
|
||||
$scope.$apply();
|
||||
repos.subscribe(fullName, function (event) {
|
||||
if (event.number !== parseInt(number)) {
|
||||
return; // ignore
|
||||
}
|
||||
// update the build
|
||||
$scope.build = event;
|
||||
$scope.task = event.builds[step - 1];
|
||||
$scope.$apply();
|
||||
|
||||
// start streaming the current build
|
||||
if ($scope.task.status === 'running') {
|
||||
stream();
|
||||
} else {
|
||||
// resets our streaming state
|
||||
streaming = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
// start streaming the current build
|
||||
if ($scope.task.status === 'running') {
|
||||
stream();
|
||||
} else {
|
||||
// resets our streaming state
|
||||
streaming = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
angular
|
||||
.module('drone')
|
||||
.controller('BuildOutCtrl', BuildOutCtrl)
|
||||
.controller('BuildCtrl', BuildCtrl)
|
||||
.controller('BuildsCtrl', BuildsCtrl);
|
||||
angular
|
||||
.module('drone')
|
||||
.controller('BuildOutCtrl', BuildOutCtrl)
|
||||
.controller('BuildCtrl', BuildCtrl)
|
||||
.controller('BuildsCtrl', BuildsCtrl);
|
||||
})();
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* ReposCtrl responsible for rendering the user's
|
||||
* repository home screen.
|
||||
*/
|
||||
function ReposCtrl($scope, $stateParams, repos, users) {
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
/**
|
||||
* ReposCtrl responsible for rendering the user's
|
||||
* repository home screen.
|
||||
*/
|
||||
function ReposCtrl($scope, $stateParams, repos, users) {
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
// Gets a list of repos to display in the
|
||||
// dropdown.
|
||||
repos.list().then(function(payload){
|
||||
$scope.repos = angular.isArray(payload.data) ? payload.data : [];
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
// Gets a list of repos to display in the
|
||||
// dropdown.
|
||||
repos.list().then(function (payload) {
|
||||
$scope.repos = angular.isArray(payload.data) ? payload.data : [];
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* RepoAddCtrl responsible for activaing a new
|
||||
* repository.
|
||||
*/
|
||||
function RepoAddCtrl($scope, $location, repos, users) {
|
||||
/**
|
||||
* RepoAddCtrl responsible for activaing a new
|
||||
* repository.
|
||||
*/
|
||||
function RepoAddCtrl($scope, $location, repos, users) {
|
||||
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
$scope.add = function(slug) {
|
||||
repos.post(slug).then(function(payload) {
|
||||
$location.path('/'+slug);
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}
|
||||
$scope.add = function (slug) {
|
||||
repos.post(slug).then(function (payload) {
|
||||
$location.path('/' + slug);
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RepoEditCtrl responsible for editing a repository.
|
||||
*/
|
||||
function RepoEditCtrl($scope, $window, $location, $stateParams, repos, users) {
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner+'/'+name;
|
||||
/**
|
||||
* RepoEditCtrl responsible for editing a repository.
|
||||
*/
|
||||
function RepoEditCtrl($scope, $window, $location, $stateParams, repos, users) {
|
||||
var owner = $stateParams.owner;
|
||||
var name = $stateParams.name;
|
||||
var fullName = owner + '/' + name;
|
||||
|
||||
// Inject window for composing url
|
||||
$scope.window = $window;
|
||||
// Inject window for composing url
|
||||
$scope.window = $window;
|
||||
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function(payload){
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
// Gets the currently authenticated user
|
||||
users.getCached().then(function (payload) {
|
||||
$scope.user = payload.data;
|
||||
});
|
||||
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function(payload){
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
// Gets a repository
|
||||
repos.get(fullName).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
$scope.save = function(repo) {
|
||||
repo.timeout = parseInt(repo.timeout);
|
||||
repos.update(repo).then(function(payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
$scope.save = function (repo) {
|
||||
repo.timeout = parseInt(repo.timeout);
|
||||
repos.update(repo).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.delete = function(repo) {
|
||||
repos.delete(repo).then(function(payload) {
|
||||
$location.path('/');
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
$scope.delete = function (repo) {
|
||||
repos.delete(repo).then(function (payload) {
|
||||
$location.path('/');
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.param={}
|
||||
$scope.addParam = function(param) {
|
||||
if (!$scope.repo.params) {
|
||||
$scope.repo.params = {}
|
||||
}
|
||||
$scope.repo.params[param.key]=param.value;
|
||||
$scope.param={}
|
||||
$scope.param = {};
|
||||
$scope.addParam = function (param) {
|
||||
if (!$scope.repo.params) {
|
||||
$scope.repo.params = {}
|
||||
}
|
||||
$scope.repo.params[param.key] = param.value;
|
||||
$scope.param = {};
|
||||
|
||||
// auto-update
|
||||
repos.update($scope.repo).then(function(payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
// auto-update
|
||||
repos.update($scope.repo).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteParam = function(key) {
|
||||
delete $scope.repo.params[key];
|
||||
$scope.deleteParam = function (key) {
|
||||
delete $scope.repo.params[key];
|
||||
|
||||
// auto-update
|
||||
repos.update($scope.repo).then(function(payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}
|
||||
// auto-update
|
||||
repos.update($scope.repo).then(function (payload) {
|
||||
$scope.repo = payload.data;
|
||||
}).catch(function (err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
angular
|
||||
.module('drone')
|
||||
.controller('ReposCtrl', ReposCtrl)
|
||||
.controller('RepoAddCtrl', RepoAddCtrl)
|
||||
.controller('RepoEditCtrl', RepoEditCtrl);
|
||||
angular
|
||||
.module('drone')
|
||||
.controller('ReposCtrl', ReposCtrl)
|
||||
.controller('RepoAddCtrl', RepoAddCtrl)
|
||||
.controller('RepoEditCtrl', RepoEditCtrl);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user