migrating most of angular app to new data structure

This commit is contained in:
Brad Rydzewski 2015-06-22 22:36:50 -07:00
parent e6cb22f190
commit 5ec17e9172
7 changed files with 46 additions and 43 deletions

View file

@ -45,7 +45,7 @@
var added = false; var added = false;
for (var i=0;i<$scope.builds.length;i++) { for (var i=0;i<$scope.builds.length;i++) {
var build = $scope.builds[i]; var build = $scope.builds[i];
if (event.sequence !== build.sequence) { if (event.number !== build.number) {
continue; // ignore continue; // ignore
} }
// update the build status // update the build status
@ -91,7 +91,7 @@
}); });
repos.subscribe(fullName, function(event) { repos.subscribe(fullName, function(event) {
if (event.sequence !== parseInt(number)) { if (event.number !== parseInt(number)) {
return; // ignore return; // ignore
} }
// update the build // update the build
@ -150,11 +150,11 @@
// Gets the build // Gets the build
builds.get(fullName, number).then(function(payload){ builds.get(fullName, number).then(function(payload){
$scope.build = payload.data; $scope.build = payload.data;
$scope.task = payload.data.builds[step-1]; $scope.task = payload.data.jobs[step-1];
if (['pending', 'killed'].indexOf($scope.task.state) !== -1) { if (['pending', 'killed'].indexOf($scope.task.status) !== -1) {
// do nothing // do nothing
} else if ($scope.task.state === 'running') { } else if ($scope.task.status === 'running') {
// stream the build // stream the build
stream(); stream();
} else { } else {
@ -195,7 +195,7 @@
}; };
repos.subscribe(fullName, function(event) { repos.subscribe(fullName, function(event) {
if (event.sequence !== parseInt(number)) { if (event.number !== parseInt(number)) {
return; // ignore return; // ignore
} }
// update the build // update the build
@ -204,7 +204,7 @@
$scope.$apply(); $scope.$apply();
// start streaming the current build // start streaming the current build
if ($scope.task.state === 'running') { if ($scope.task.status === 'running') {
stream(); stream();
} else { } else {
// resets our streaming state // resets our streaming state

View file

@ -45,7 +45,7 @@
var added = false; var added = false;
for (var i=0;i<$scope.builds.length;i++) { for (var i=0;i<$scope.builds.length;i++) {
var build = $scope.builds[i]; var build = $scope.builds[i];
if (event.sequence !== build.sequence) { if (event.number !== build.number) {
continue; // ignore continue; // ignore
} }
// update the build status // update the build status

View file

@ -12,7 +12,7 @@
<a ng-href="/{{ repo.full_name }}" class="icon icon-home"></a> <a ng-href="/{{ repo.full_name }}" class="icon icon-home"></a>
<a ng-href="/{{ repo.full_name }}">{{ repo.owner }} / {{ repo.name }}</a> <a ng-href="/{{ repo.full_name }}">{{ repo.owner }} / {{ repo.name }}</a>
<span class="spacer"></span> <span class="spacer"></span>
<a ng-href="#">{{ build.sequence }}</a> <a ng-href="#">{{ build.number }}</a>
</div> </div>
<div class="menu"> <div class="menu">
@ -31,28 +31,28 @@
<section class="commit-section"> <section class="commit-section">
<div class="row build-row"> <div class="row build-row">
<div> <div>
<div ng-class="[ 'build-num', build.state ]"></div> <div ng-class="[ 'build-num', build.status ]"></div>
</div> </div>
<div> <div>
<h3>{{ build.message }}</h3> <h3>{{ build.head_commit.message }}</h3>
<p><strong>{{ build.author }}</strong> pushed to <strong>{{ build.branch }}</strong> {{ build.started_at | fromNow }}</p> <p><strong>{{ build.head_commit.author.login }}</strong> pushed to <strong>{{ build.head_commit.branch }}</strong> {{ build.started_at | fromNow }}</p>
<div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{build.sequence}}</div> <div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{build.number}}</div>
</div> </div>
</div> </div>
</section> </section>
<section> <section>
<a class="row build-row sub-build-row" ng-repeat="task in build.builds" ng-href="{{ repo.full_name }}/{{ build.sequence }}/{{ task.sequence }}"> <a class="row build-row sub-build-row" ng-repeat="job in build.jobs" ng-href="{{ repo.full_name }}/{{ build.number }}/{{ job.number }}">
<div> <div>
<div ng-class="[ 'build-num', build.state ]"></div> <div ng-class="[ 'build-num', build.status ]"></div>
</div> </div>
<div> <div>
<h3> <h3>
<div ng-repeat="(key, value) in task.environment"> <div ng-repeat="(key, value) in job.environment">
{{ key.toUpperCase() }}={{ value }} {{ key.toUpperCase() }}={{ value }}
</div> </div>
</h3> </h3>
<div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{task.sequence}}</div> <div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{job.number}}</div>
</div> </div>
</a> </a>
</section> </section>
@ -60,5 +60,5 @@
<button ng-if="build.state !== 'pending' && build.state !== 'running'" ng-click="restart()">Restart</button> <button ng-if="build.status !== 'pending' && build.status !== 'running'" ng-click="restart()">Restart</button>
<button ng-if="build.state === 'pending' || build.state === 'running'" ng-click="cancel()">Cancel</button> <button ng-if="build.status === 'pending' || build.status === 'running'" ng-click="cancel()">Cancel</button>

View file

@ -32,16 +32,16 @@
<section class="commit-section"> <section class="commit-section">
<div class="row build-row"> <div class="row build-row">
<div> <div>
<div ng-class="[ 'build-num', task.state ]" ng-if="task"></div> <div ng-class="[ 'build-num', task.status ]" ng-if="task"></div>
<div ng-class="[ 'build-num', build.state ]" ng-if="!task"></div> <div ng-class="[ 'build-num', build.status ]" ng-if="!task"></div>
</div> </div>
<div> <div>
<h3>{{ build.message }}</h3> <h3>{{ build.head_commit.message }}</h3>
<p><strong>{{ build.author }}</strong> pushed to <strong>{{ build.branch }}</strong> {{ build.started_at | fromNow }}</p> <p><strong>{{ build.head_commit.author.login }}</strong> pushed to <strong>{{ build.head_commit.branch }}</strong> {{ build.started_at | fromNow }}</p>
</div> </div>
</div> </div>
<div class="row build-row sub-build-row" ng-if="build.builds.length > 1"> <div class="row build-row sub-build-row" ng-if="build.jobs.length > 1">
<div> <div>
</div> </div>
@ -58,11 +58,11 @@
<pre id="term" ng-if="task && task.state !== 'pending'"></pre> <pre id="term" ng-if="task && task.status !== 'pending'"></pre>
<button class="fab" ng-if="build.state === 'running'" ng-click="tail()"></button> <button class="fab" ng-if="build.status === 'running'" ng-click="tail()"></button>
</article> </article>
<button ng-if="build.state !== 'pending' && build.state !== 'running'" ng-click="restart()">Restart</button> <button ng-if="build.status !== 'pending' && build.status !== 'running'" ng-click="restart()">Restart</button>
<button ng-if="build.state === 'pending' || build.state === 'running'" ng-click="cancel()">Cancel</button> <button ng-if="build.status === 'pending' || build.status === 'running'" ng-click="cancel()">Cancel</button>

View file

@ -25,14 +25,14 @@
<article> <article>
<section> <section>
<a class="row build-row" ng-repeat="build in builds | orderBy:'-sequence'" ng-href="/{{ repo.full_name }}/{{ build.sequence }}"> <a class="row build-row" ng-repeat="build in builds | orderBy:'-number'" ng-href="/{{ repo.full_name }}/{{ build.number }}">
<div> <div>
<div ng-class="[ 'build-num', build.state ]"></div> <div ng-class="[ 'build-num', build.status ]"></div>
</div> </div>
<div> <div>
<h3>{{ build.message }}</h3> <h3>{{ build.head_commit.message }}</h3>
<p><strong>{{ build.author }}</strong> pushed to <strong>{{ build.branch }}</strong> {{ build.started_at | fromNow }}</p> <p><strong>{{ build.head_commit.author.login }}</strong> pushed to <strong>{{ build.head_commit.branch }}</strong> {{ build.started_at | fromNow }}</p>
<div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{build.sequence}}</div> <div style="position:absolute;top:30px;right:30px;color:#CCC;"># {{build.number}}</div>
</div> </div>
</a> </a>
</section> </section>

View file

@ -29,14 +29,14 @@
<div class="row"> <div class="row">
<div>Post Commit Hooks</div> <div>Post Commit Hooks</div>
<div> <div>
<input id="post_commits" type="checkbox" hidden="hidden" ng-model="repo.post_commits" ng-change="save(repo)" /> <input id="post_commits" type="checkbox" hidden="hidden" ng-model="repo.hooks.push" ng-change="save(repo)" />
<label for="post_commits" class="switch"></label> <label for="post_commits" class="switch"></label>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div>Pull Request Hooks</div> <div>Pull Request Hooks</div>
<div> <div>
<input id="pull_requests" type="checkbox" hidden="hidden" ng-model="repo.pull_requests" ng-change="save(repo)" /> <input id="pull_requests" type="checkbox" hidden="hidden" ng-model="repo.hooks.pull_request" ng-change="save(repo)" />
<label for="pull_requests" class="switch"></label> <label for="pull_requests" class="switch"></label>
</div> </div>
</div> </div>

View file

@ -31,11 +31,14 @@ type repoResp struct {
// accept null values, effectively patching an existing // accept null values, effectively patching an existing
// repository object with only the supplied fields. // repository object with only the supplied fields.
type repoReq struct { type repoReq struct {
PostCommit *bool `json:"post_commits"`
PullRequest *bool `json:"pull_requests"`
Trusted *bool `json:"trusted"` Trusted *bool `json:"trusted"`
Timeout *int64 `json:"timeout"` Timeout *int64 `json:"timeout"`
Hooks struct {
PullReqeust *bool `json:"pull_request"`
Push *bool `json:"push"`
}
// optional private parameters can only be // optional private parameters can only be
// supplied by the repository admin. // supplied by the repository admin.
Params *map[string]string `json:"params"` Params *map[string]string `json:"params"`
@ -95,11 +98,11 @@ func PutRepo(c *gin.Context) {
repo.Params = *in.Params repo.Params = *in.Params
} }
if in.PostCommit != nil { if in.Hooks.Push != nil {
repo.Hooks.Push = *in.PostCommit repo.Hooks.Push = *in.Hooks.Push
} }
if in.PullRequest != nil { if in.Hooks.PullReqeust != nil {
repo.Hooks.PullRequest = *in.PullRequest repo.Hooks.PullRequest = *in.Hooks.PullReqeust
} }
if in.Trusted != nil && user.Admin { if in.Trusted != nil && user.Admin {
repo.Trusted = *in.Trusted repo.Trusted = *in.Trusted