Show More
@@ -2,6 +2,17 | |||||
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # changelog controller for pylons |
|
3 | # changelog controller for pylons | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
|
5 | from json import dumps | |||
|
6 | from mercurial.graphmod import colored, CHANGESET | |||
|
7 | from mercurial.node import short | |||
|
8 | from mercurial.templatefilters import person | |||
|
9 | from pylons import request, session, tmpl_context as c | |||
|
10 | from pylons_app.lib.auth import LoginRequired | |||
|
11 | from pylons_app.lib.base import BaseController, render | |||
|
12 | from pylons_app.model.hg_model import HgModel | |||
|
13 | from webhelpers.paginate import Page | |||
|
14 | import logging | |||
|
15 | from mercurial.graphmod import revisions as graph_rev | |||
5 |
|
16 | |||
6 | # This program is free software; you can redistribute it and/or |
|
17 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
18 | # modify it under the terms of the GNU General Public License | |
@@ -22,12 +33,6 Created on April 21, 2010 | |||||
22 | changelog controller for pylons |
|
33 | changelog controller for pylons | |
23 | @author: marcink |
|
34 | @author: marcink | |
24 | """ |
|
35 | """ | |
25 | from pylons import request, session, tmpl_context as c |
|
|||
26 | from pylons_app.lib.auth import LoginRequired |
|
|||
27 | from pylons_app.lib.base import BaseController, render |
|
|||
28 | from pylons_app.model.hg_model import HgModel |
|
|||
29 | from webhelpers.paginate import Page |
|
|||
30 | import logging |
|
|||
31 | log = logging.getLogger(__name__) |
|
36 | log = logging.getLogger(__name__) | |
32 |
|
37 | |||
33 | class ChangelogController(BaseController): |
|
38 | class ChangelogController(BaseController): | |
@@ -58,39 +63,35 class ChangelogController(BaseController | |||||
58 | c.pagination = Page(changesets, page=p, item_count=c.total_cs, |
|
63 | c.pagination = Page(changesets, page=p, item_count=c.total_cs, | |
59 | items_per_page=c.size) |
|
64 | items_per_page=c.size) | |
60 |
|
65 | |||
61 |
|
|
66 | self._graph(changesets, c.size, p) | |
62 |
|
67 | |||
63 | return render('changelog/changelog.html') |
|
68 | return render('changelog/changelog.html') | |
64 |
|
69 | |||
65 |
|
70 | |||
66 | def _graph(self, repo, size, p): |
|
71 | def _graph(self, repo, size, p): | |
67 | pass |
|
72 | revcount = size | |
68 | # revcount = size |
|
73 | if not repo.revisions:return dumps([]), 0 | |
69 | # if not repo.revisions:return dumps([]), 0 |
|
74 | ||
70 | # |
|
75 | max_rev = repo.revisions[-1] | |
71 | # max_rev = repo.revisions[-1] |
|
76 | offset = 1 if p == 1 else ((p - 1) * revcount) | |
72 | # offset = 1 if p == 1 else ((p - 1) * revcount) |
|
77 | rev_start = repo.revisions[(-1 * offset)] | |
73 | # rev_start = repo.revisions[(-1 * offset)] |
|
78 | ||
74 | # c.bg_height = 120 |
|
79 | revcount = min(max_rev, revcount) | |
75 | # |
|
80 | rev_end = max(0, rev_start - revcount) | |
76 | # revcount = min(max_rev, revcount) |
|
81 | dag = graph_rev(repo.repo, rev_start, rev_end) | |
77 | # rev_end = max(0, rev_start - revcount) |
|
82 | ||
78 | # dag = graph_rev(repo.repo, rev_start, rev_end) |
|
83 | c.dag = tree = list(colored(dag)) | |
79 |
|
|
84 | data = [] | |
80 | # c.dag = tree = list(colored(dag)) |
|
85 | for (id, type, ctx, vtx, edges) in tree: | |
81 | # canvasheight = (len(tree) + 1) * c.bg_height - 27 |
|
86 | if type != CHANGESET: | |
82 | # data = [] |
|
87 | continue | |
83 | # for (id, type, ctx, vtx, edges) in tree: |
|
88 | node = short(ctx.node()) | |
84 | # if type != CHANGESET: |
|
89 | age = ctx.date() | |
85 | # continue |
|
90 | desc = ctx.description() | |
86 |
|
|
91 | user = person(ctx.user()) | |
87 |
|
|
92 | branch = ctx.branch() | |
88 | # desc = ctx.description() |
|
93 | branch = branch, repo.repo.branchtags().get(branch) == ctx.node() | |
89 | # user = person(ctx.user()) |
|
94 | data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) | |
90 | # branch = ctx.branch() |
|
95 | ||
91 | # branch = branch, repo.repo.branchtags().get(branch) == ctx.node() |
|
96 | c.jsdata = dumps(data) | |
92 | # data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
|
|||
93 | # |
|
|||
94 | # c.jsdata = dumps(data) |
|
|||
95 | # c.canvasheight = canvasheight |
|
|||
96 |
|
97 |
@@ -645,10 +645,8 p.files { | |||||
645 | /** end of changeset **/ |
|
645 | /** end of changeset **/ | |
646 |
|
646 | |||
647 | /** canvas **/ |
|
647 | /** canvas **/ | |
648 | canvas { |
|
648 | #graph_nodes{ | |
649 | position: absolute; |
|
649 | margin-top:8px; | |
650 | z-index: 5; |
|
|||
651 | top: -0.7em; |
|
|||
652 | } |
|
650 | } | |
653 | #graph{ |
|
651 | #graph{ | |
654 | overflow: hidden; |
|
652 | overflow: hidden; |
@@ -1,5 +1,6 | |||||
1 | // branch_renderer.js - Rendering of branch DAGs on the client side |
|
1 | // branch_renderer.js - Rendering of branch DAGs on the client side | |
2 | // |
|
2 | // | |
|
3 | // Copyright 2008 Jesper Noehr <jesper AT noehr DOT org> | |||
3 | // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> |
|
4 | // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> | |
4 | // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> |
|
5 | // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> | |
5 | // |
|
6 | // | |
@@ -15,50 +16,34 var colors = [ | |||||
15 | [ 0.0, 1.0, 0.0 ], |
|
16 | [ 0.0, 1.0, 0.0 ], | |
16 | [ 0.0, 1.0, 1.0 ], |
|
17 | [ 0.0, 1.0, 1.0 ], | |
17 | [ 0.0, 0.0, 1.0 ], |
|
18 | [ 0.0, 0.0, 1.0 ], | |
18 | [ 1.0, 0.0, 1.0 ] |
|
19 | [ 1.0, 0.0, 1.0 ], | |
|
20 | [ 1.0, 1.0, 0.0 ], | |||
|
21 | [ 0.0, 0.0, 0.0 ] | |||
19 | ]; |
|
22 | ]; | |
20 |
|
23 | |||
21 |
function |
|
24 | function BranchRenderer() { | |
22 |
|
25 | |||
23 |
this.canvas = document.getElementById( |
|
26 | this.canvas = document.getElementById("graph_canvas"); | |
24 | if (navigator.userAgent.indexOf('MSIE') >= 0) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); |
|
27 | ||
|
28 | //if ($.browser.msie) | |||
|
29 | // this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); | |||
25 | this.ctx = this.canvas.getContext('2d'); |
|
30 | this.ctx = this.canvas.getContext('2d'); | |
26 | this.ctx.strokeStyle = 'rgb(0, 0, 0)'; |
|
31 | this.ctx.strokeStyle = 'rgb(0, 0, 0)'; | |
27 | this.ctx.fillStyle = 'rgb(0, 0, 0)'; |
|
32 | this.ctx.fillStyle = 'rgb(0, 0, 0)'; | |
28 | this.cur = [0, 0]; |
|
33 | this.cur = [0, 0]; | |
|
34 | this.max_column = 1; | |||
29 | this.line_width = 3; |
|
35 | this.line_width = 3; | |
30 | this.bg = [0, 4]; |
|
36 | this.bg = [0, 4]; | |
31 | this.cell = [2, 0]; |
|
37 | this.cell = [2, 0]; | |
32 | this.columns = 0; |
|
|||
33 | this.revlink = ''; |
|
38 | this.revlink = ''; | |
34 |
|
39 | |||
35 | this.scale = function(height) { |
|
40 | this.scale = function(height) { | |
|
41 | this.box_size = Math.floor(height/1.2); | |||
|
42 | this.cell_height = this.box_size; | |||
36 | this.bg_height = height; |
|
43 | this.bg_height = height; | |
37 | this.box_size = Math.floor(this.bg_height / 1.2); |
|
|||
38 | this.cell_height = this.box_size; |
|
|||
39 | } |
|
44 | } | |
40 |
|
45 | |||
41 | function colorPart(num) { |
|
|||
42 | num *= 255 |
|
|||
43 | num = num < 0 ? 0 : num; |
|
|||
44 | num = num > 255 ? 255 : num; |
|
|||
45 | var digits = Math.round(num).toString(16); |
|
|||
46 | if (num < 16) { |
|
|||
47 | return '0' + digits; |
|
|||
48 | } else { |
|
|||
49 | return digits; |
|
|||
50 | } |
|
|||
51 | } |
|
|||
52 |
|
||||
53 | this.setColor = function(color, bg, fg) { |
|
46 | this.setColor = function(color, bg, fg) { | |
54 |
|
||||
55 | // Set the colour. |
|
|||
56 | // |
|
|||
57 | // Picks a distinct colour based on an internal wheel; the bg |
|
|||
58 | // parameter provides the value that should be assigned to the 'zero' |
|
|||
59 | // colours and the fg parameter provides the multiplier that should be |
|
|||
60 | // applied to the foreground colours. |
|
|||
61 |
|
||||
62 | color %= colors.length; |
|
47 | color %= colors.length; | |
63 | var red = (colors[color][0] * fg) || bg; |
|
48 | var red = (colors[color][0] * fg) || bg; | |
64 | var green = (colors[color][1] * fg) || bg; |
|
49 | var green = (colors[color][1] * fg) || bg; | |
@@ -69,69 +54,78 function Graph() { | |||||
69 | var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; |
|
54 | var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; | |
70 | this.ctx.strokeStyle = s; |
|
55 | this.ctx.strokeStyle = s; | |
71 | this.ctx.fillStyle = s; |
|
56 | this.ctx.fillStyle = s; | |
72 | return s; |
|
|||
73 |
|
||||
74 | } |
|
57 | } | |
75 |
|
58 | |||
76 | this.render = function(data) { |
|
59 | this.render = function(data) { | |
77 |
|
60 | var idx = 1; | ||
78 | var backgrounds = ''; |
|
61 | var rela = document.getElementById('graph'); | |
79 |
var |
|
62 | var pad = 160; | |
|
63 | var scale = 20; | |||
80 |
|
64 | |||
81 | for (var i in data) { |
|
65 | for (var i in data) { | |
|
66 | this.scale(scale); | |||
|
67 | var row = document.getElementById("chg_"+idx); | |||
|
68 | var next = document.getElementById("chg_"+idx+1); | |||
|
69 | var extra = 0; | |||
82 |
|
70 | |||
83 | var parity = i % 2; |
|
71 | //skip this since i don't have DATE in my app | |
84 | this.cell[1] += this.bg_height; |
|
72 | //if (next.is('.changesets-date')) { | |
|
73 | // extra = next.outerHeight(); | |||
|
74 | //} | |||
|
75 | ||||
|
76 | ||||
|
77 | this.cell[1] += row.clientWidth; | |||
85 | this.bg[1] += this.bg_height; |
|
78 | this.bg[1] += this.bg_height; | |
86 |
|
79 | |||
87 |
|
|
80 | cur = data[i]; | |
88 |
|
|
81 | nodeid = cur[0]; | |
89 |
|
|
82 | node = cur[1]; | |
90 | var fold = false; |
|
83 | in_l = cur[2]; | |
91 |
|
84 | |||
92 |
for (var j in |
|
85 | for (var j in in_l) { | |
93 |
|
86 | |||
94 |
line = |
|
87 | line = in_l[j]; | |
95 | start = line[0]; |
|
88 | start = line[0]; | |
96 | end = line[1]; |
|
89 | end = line[1]; | |
97 | color = line[2]; |
|
90 | color = line[2]; | |
98 |
|
91 | |||
99 |
if ( |
|
92 | if (start > this.max_column) { | |
100 |
this.column |
|
93 | this.max_column = start; | |
101 | } |
|
94 | } | |
102 |
|
95 | |||
103 |
if ( |
|
96 | if (end > this.max_column) { | |
104 | var fold = true; |
|
97 | this.max_column = end; | |
105 | } |
|
98 | } | |
106 |
|
99 | |||
107 | x0 = this.cell[0] + this.box_size * start + this.box_size / 2; |
|
100 | this.setColor(color, 0.0, 0.65); | |
108 | y0 = this.bg[1] - this.bg_height / 2; |
|
101 | ||
109 | x1 = this.cell[0] + this.box_size * end + this.box_size / 2; |
|
|||
110 | y1 = this.bg[1] + this.bg_height / 2; |
|
|||
111 |
|
102 | |||
112 | this.edge(x0, y0, x1, y1, color); |
|
103 | y = row.offsetTop-rela.offsetTop+4; | |
|
104 | x = pad-((this.cell[0] + this.box_size * start - 1) + this.bg_height-2); | |||
|
105 | this.ctx.beginPath(); | |||
|
106 | this.ctx.moveTo(x, y); | |||
113 |
|
107 | |||
|
108 | y += row.clientHeight; | |||
|
109 | x = pad-((1 + this.box_size * end) + this.bg_height-2); | |||
|
110 | this.ctx.lineTo(x,y+extra); | |||
|
111 | this.ctx.stroke(); | |||
114 | } |
|
112 | } | |
115 |
|
113 | |||
116 | // Draw the revision node in the right column |
|
|||
117 |
|
||||
118 | column = node[0] |
|
114 | column = node[0] | |
119 | color = node[1] |
|
115 | color = node[1] | |
120 |
|
116 | |||
121 | radius = this.box_size / 8; |
|
117 | radius = 4; | |
122 | x = this.cell[0] + this.box_size * column + this.box_size / 2; |
|
118 | y = row.offsetTop-rela.offsetTop+4; | |
123 | y = this.bg[1] - this.bg_height / 2; |
|
119 | x = pad-(Math.round(this.cell[0] * scale/2 * column + radius) + 15 - (column*4)); | |
124 | var add = this.vertex(x, y, color, parity, cur); |
|
120 | ||
125 | backgrounds += add[0]; |
|
121 | this.ctx.beginPath(); | |
126 | nodedata += add[1]; |
|
122 | this.setColor(color, 0.25, 0.75); | |
|
123 | this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); | |||
|
124 | this.ctx.fill(); | |||
127 |
|
125 | |||
128 | if (fold) this.columns -= 1; |
|
126 | idx++; | |
129 |
|
||||
130 | } |
|
127 | } | |
131 |
|
128 | |||
132 | document.getElementById('nodebgs').innerHTML += backgrounds; |
|
|||
133 | document.getElementById('graphnodes').innerHTML += nodedata; |
|
|||
134 |
|
||||
135 | } |
|
129 | } | |
136 |
|
130 | |||
137 | } |
|
131 | } |
@@ -24,9 +24,9 | |||||
24 | % if c.pagination: |
|
24 | % if c.pagination: | |
25 |
|
25 | |||
26 | <div id="graph"> |
|
26 | <div id="graph"> | |
27 |
|
|
27 | <div id="graph_nodes"> | |
28 |
|
|
28 | <canvas id="graph_canvas"></canvas> | |
29 |
|
|
29 | </div> | |
30 | <div id="graph_content"> |
|
30 | <div id="graph_content"> | |
31 | <div class="container_header"> |
|
31 | <div class="container_header"> | |
32 | ${h.form(h.url.current(),method='get')} |
|
32 | ${h.form(h.url.current(),method='get')} | |
@@ -35,7 +35,7 | |||||
35 | ${h.end_form()} |
|
35 | ${h.end_form()} | |
36 | </div> |
|
36 | </div> | |
37 | %for cnt,cs in enumerate(c.pagination): |
|
37 | %for cnt,cs in enumerate(c.pagination): | |
38 | <div class="container"> |
|
38 | <div id="chg_${cnt+1}" class="container"> | |
39 | <div class="left"> |
|
39 | <div class="left"> | |
40 | <div class="date">${_('commit')} ${cs.revision}: ${cs.raw_id}@${cs.date}</div> |
|
40 | <div class="date">${_('commit')} ${cs.revision}: ${cs.raw_id}@${cs.date}</div> | |
41 | <div class="author">${cs.author}</div> |
|
41 | <div class="author">${cs.author}</div> | |
@@ -72,19 +72,28 | |||||
72 | %endfor |
|
72 | %endfor | |
73 | </div> |
|
73 | </div> | |
74 | </div> |
|
74 | </div> | |
|
75 | <script type="text/javascript" src="/js/graph.js"></script> | |||
75 |
|
76 | |||
76 |
|
|
77 | <script type="text/javascript"> | |
77 | ##<script type="text/javascript" src="http://bitbucket-assets.s3.amazonaws.com/js/lib/bundle.160310Mar.js"></script> |
|
78 | YAHOO.util.Event.onDOMReady(function(){ | |
78 | ## |
|
79 | function set_canvas() { | |
79 | ##<script> |
|
80 | var c = document.getElementById('graph_nodes'); | |
80 | ##<!-- hide script content |
|
81 | var t = document.getElementById('graph_content'); | |
81 | ## |
|
82 | canvas = document.getElementById('graph_canvas'); | |
82 | ##var jsdata = ${c.jsdata|n}; |
|
83 | var div_h = t.clientHeight; | |
83 | ##var r = new BranchRenderer(); |
|
84 | c.style.height=div_h+'px'; | |
84 | ##r.render(jsdata); |
|
85 | canvas.setAttribute('height',div_h); | |
|
86 | canvas.setAttribute('width',160); | |||
|
87 | }; | |||
85 |
|
88 | |||
86 | ##// stop hiding script --> |
|
89 | set_canvas(); | |
87 | ##</script> |
|
90 | ||
|
91 | var jsdata = ${c.jsdata|n}; | |||
|
92 | var r = new BranchRenderer(); | |||
|
93 | r.render(jsdata); | |||
|
94 | ||||
|
95 | }); | |||
|
96 | </script> | |||
88 |
|
97 | |||
89 | <div> |
|
98 | <div> | |
90 | <h2>${c.pagination.pager('$link_previous ~2~ $link_next')}</h2> |
|
99 | <h2>${c.pagination.pager('$link_previous ~2~ $link_next')}</h2> |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now