re-added code to read/write websocket data. added to amber templates
This commit is contained in:
parent
b0255af7a9
commit
4d4defc416
11 changed files with 64 additions and 41 deletions
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/server/channel"
|
||||
"github.com/drone/drone/server/render"
|
||||
"github.com/drone/drone/server/resource/commit"
|
||||
"github.com/drone/drone/server/resource/perm"
|
||||
|
@ -94,12 +95,17 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error {
|
|||
User *user.User
|
||||
Repo *repo.Repo
|
||||
Branch string
|
||||
Token string
|
||||
Channel string
|
||||
Stream string
|
||||
Branches []*commit.Commit
|
||||
Commits []*commit.Commit
|
||||
Commit *commit.Commit
|
||||
}{User: usr, Repo: arepo}
|
||||
|
||||
// generate a token for connecting to the streaming server
|
||||
// to get notified of feed items.
|
||||
data.Channel = channel.Create(host + "/" + owner + "/" + name + "/")
|
||||
|
||||
// if commit details are provided we should retrieve the build details
|
||||
// and serve the build page.
|
||||
if len(sha) != 0 {
|
||||
|
@ -107,6 +113,11 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error {
|
|||
if err != nil {
|
||||
return s.render(w, "404.html", nil)
|
||||
}
|
||||
|
||||
// generate a token for connecting to the streaming server
|
||||
// to get notified of feed items.
|
||||
data.Stream = channel.Create(host + "/" + owner + "/" + name + "/" + branch + "/" + sha)
|
||||
|
||||
return s.render(w, "repo_commit.html", &data)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"github.com/drone/drone/server/channel"
|
||||
"github.com/drone/drone/server/database"
|
||||
"github.com/drone/drone/server/handler"
|
||||
"github.com/drone/drone/server/render"
|
||||
|
@ -93,6 +95,9 @@ func main() {
|
|||
// TODO we need to replace this with go.rice
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
||||
// server websocket data
|
||||
http.Handle("/feed", websocket.Handler(channel.Read))
|
||||
|
||||
// register the router
|
||||
// TODO we disabled nosurf because it was impacting API calls.
|
||||
// we need to disable nosurf for api calls (ie not coming from website).
|
||||
|
|
|
@ -85,15 +85,15 @@ func (w *worker) execute(task *BuildTask) error {
|
|||
// make sure a channel exists for the repository,
|
||||
// the commit, and the commit output (TODO)
|
||||
reposlug := fmt.Sprintf("%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name)
|
||||
commitslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
|
||||
consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s/console", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
|
||||
//commitslug := fmt.Sprintf("%s/%s/%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
|
||||
consoleslug := fmt.Sprintf("%s/%s/%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
|
||||
channel.Create(reposlug)
|
||||
channel.Create(commitslug)
|
||||
//channel.Create(commitslug)
|
||||
channel.CreateStream(consoleslug)
|
||||
|
||||
// notify the channels that the commit and build started
|
||||
channel.SendJSON(reposlug, task.Commit)
|
||||
channel.SendJSON(commitslug, task.Commit)
|
||||
//channel.SendJSON(commitslug, task.Commit)
|
||||
|
||||
var buf = &bufferWrapper{channel: consoleslug}
|
||||
|
||||
|
@ -145,7 +145,7 @@ func (w *worker) execute(task *BuildTask) error {
|
|||
|
||||
// notify the channels that the commit and build finished
|
||||
channel.SendJSON(reposlug, task.Commit)
|
||||
channel.SendJSON(commitslug, task.Commit)
|
||||
//channel.SendJSON(commitslug, task.Commit)
|
||||
channel.Close(consoleslug)
|
||||
|
||||
// send all "finished" notifications
|
||||
|
|
|
@ -32,10 +32,10 @@ func NewSession(users user.UserManager) Session {
|
|||
|
||||
// User gets the currently authenticated user from the secure cookie session.
|
||||
func (s *session) User(r *http.Request) *user.User {
|
||||
if true {
|
||||
user, _ := s.users.Find(1)
|
||||
return user
|
||||
}
|
||||
//if true {
|
||||
// user, _ := s.users.Find(1)
|
||||
// return user
|
||||
//}
|
||||
|
||||
switch {
|
||||
case r.FormValue("access_token") == "":
|
||||
|
|
|
@ -76,7 +76,6 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
|
|||
|
||||
onClose: function(e) {
|
||||
console.log('output websocket closed: ' + JSON.stringify(e));
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -73,5 +73,11 @@
|
|||
$(".timeago").timeago();
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token='+{{.Channel}});
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -80,23 +80,18 @@
|
|||
$(".timeago").timeago();
|
||||
});
|
||||
</script>{{$__amber_38 := .Build.Status}}{{$__amber_39 := __amber_eql $__amber_38 "Pending"}}{{$__amber_40 := .Build.Status}}{{$__amber_41 := __amber_eql $__amber_40 "Started"}}{{$__amber_42 := or $__amber_41 $__amber_39}}{{if $__amber_42}}
|
||||
<script>
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token={{.Channel}}');
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var commitUpdates = new Drone.CommitUpdates('/feed?token='+ {{.Token}});
|
||||
var commitUpdates = new Drone.CommitUpdates('/feed?token={{.Stream}}');
|
||||
var outputBox = document.getElementById('stdout');
|
||||
commitUpdates.startOutput(outputBox);
|
||||
|
||||
$("#follow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if(commitUpdates.autoFollow) {
|
||||
commitUpdates.autoFollow = false;
|
||||
$(this).text("Follow");
|
||||
} else {
|
||||
commitUpdates.autoFollow = true;
|
||||
$(this).text("Stop following");
|
||||
}
|
||||
});
|
||||
commitUpdates.startOutput(outputBox);
|
||||
});
|
||||
</script>{{else}}
|
||||
<script>
|
||||
|
|
|
@ -82,9 +82,13 @@
|
|||
$(document).ready(function() {
|
||||
$(".timeago").timeago();
|
||||
});
|
||||
|
||||
</script>{{$__amber_50 := .Repo.Active}}{{if $__amber_50}}
|
||||
<script></script>{{else}}
|
||||
<script>
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token={{.Channel}}');
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
||||
</script>{{else}}
|
||||
<script>
|
||||
document.forms[0].onsubmit = function(event) {
|
||||
var form = event.target;
|
||||
|
|
|
@ -46,3 +46,9 @@ block append scripts
|
|||
$(document).ready(function() {
|
||||
$(".timeago").timeago();
|
||||
});
|
||||
|
||||
script
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token='+#{Channel});
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
|
@ -51,23 +51,17 @@ block append scripts
|
|||
});
|
||||
|
||||
if Build.Status == "Started" || Build.Status == "Pending"
|
||||
script
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token=#{Channel}');
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
||||
script
|
||||
$(document).ready(function() {
|
||||
var commitUpdates = new Drone.CommitUpdates('/feed?token='+ #{Token});
|
||||
var commitUpdates = new Drone.CommitUpdates('/feed?token=#{Stream}');
|
||||
var outputBox = document.getElementById('stdout');
|
||||
commitUpdates.startOutput(outputBox);
|
||||
|
||||
$("#follow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if(commitUpdates.autoFollow) {
|
||||
commitUpdates.autoFollow = false;
|
||||
$(this).text("Follow");
|
||||
} else {
|
||||
commitUpdates.autoFollow = true;
|
||||
$(this).text("Stop following");
|
||||
}
|
||||
});
|
||||
commitUpdates.startOutput(outputBox);
|
||||
});
|
||||
else
|
||||
script
|
||||
|
|
|
@ -58,9 +58,12 @@ block append scripts
|
|||
$(".timeago").timeago();
|
||||
});
|
||||
|
||||
|
||||
if Repo.Active
|
||||
script
|
||||
var ws = new WebSocket((window.location.protocol=='http:'?'ws':'wss')+'://'+window.location.host+'/feed?token=#{Channel}');
|
||||
ws.onmessage = function (e) {
|
||||
console.log(e);
|
||||
};
|
||||
else
|
||||
script
|
||||
document.forms[0].onsubmit = function(event) {
|
||||
|
|
Loading…
Reference in a new issue