Show More
@@ -1,208 +1,211 b'' | |||||
1 | // # Copyright (C) 2016-2019 RhodeCode GmbH |
|
1 | // # Copyright (C) 2016-2019 RhodeCode GmbH | |
2 | // # |
|
2 | // # | |
3 | // # This program is free software: you can redistribute it and/or modify |
|
3 | // # This program is free software: you can redistribute it and/or modify | |
4 | // # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | // # it under the terms of the GNU Affero General Public License, version 3 | |
5 | // # (only), as published by the Free Software Foundation. |
|
5 | // # (only), as published by the Free Software Foundation. | |
6 | // # |
|
6 | // # | |
7 | // # This program is distributed in the hope that it will be useful, |
|
7 | // # This program is distributed in the hope that it will be useful, | |
8 | // # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | // # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | // # GNU General Public License for more details. |
|
10 | // # GNU General Public License for more details. | |
11 | // # |
|
11 | // # | |
12 | // # You should have received a copy of the GNU Affero General Public License |
|
12 | // # You should have received a copy of the GNU Affero General Public License | |
13 | // # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13 | // # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | // # |
|
14 | // # | |
15 | // # This program is dual-licensed. If you wish to learn more about the |
|
15 | // # This program is dual-licensed. If you wish to learn more about the | |
16 | // # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | // # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | // # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | // # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | var CommitsController = function () { |
|
20 | var CommitsController = function () { | |
21 | var self = this; |
|
21 | var self = this; | |
22 | this.$graphCanvas = $('#graph_canvas'); |
|
22 | this.$graphCanvas = $('#graph_canvas'); | |
23 | this.$commitCounter = $('#commit-counter'); |
|
23 | this.$commitCounter = $('#commit-counter'); | |
24 |
|
24 | |||
25 | this.getCurrentGraphData = function () { |
|
25 | this.getCurrentGraphData = function () { | |
26 | // raw form |
|
26 | // raw form | |
27 | return self.$graphCanvas.data('commits'); |
|
27 | return self.$graphCanvas.data('commits'); | |
28 | }; |
|
28 | }; | |
29 |
|
29 | |||
30 | this.setLabelText = function (graphData) { |
|
30 | this.setLabelText = function (graphData) { | |
31 | var shown = $('.commit_hash').length; |
|
31 | var shown = $('.commit_hash').length; | |
32 | var total = self.$commitCounter.data('total'); |
|
32 | var total = self.$commitCounter.data('total'); | |
33 |
|
33 | |||
34 | if (shown == 1) { |
|
34 | if (shown == 1) { | |
35 | var text = _gettext('showing {0} out of {1} commit').format(shown, total); |
|
35 | var text = _gettext('showing {0} out of {1} commit').format(shown, total); | |
36 | } else { |
|
36 | } else { | |
37 | var text = _gettext('showing {0} out of {1} commits').format(shown, total); |
|
37 | var text = _gettext('showing {0} out of {1} commits').format(shown, total); | |
38 | } |
|
38 | } | |
39 | self.$commitCounter.html(text) |
|
39 | self.$commitCounter.html(text) | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | this.reloadGraph = function (chunk) { |
|
42 | this.reloadGraph = function (chunk) { | |
43 | chunk = chunk || 'next'; |
|
43 | chunk = chunk || 'next'; | |
44 |
|
44 | |||
45 | // reset state on re-render ! |
|
45 | // reset state on re-render ! | |
46 | self.$graphCanvas.html(''); |
|
46 | self.$graphCanvas.html(''); | |
47 |
|
47 | |||
48 | var edgeData = $("[data-graph]").data('graph') || this.$graphCanvas.data('graph') || []; |
|
48 | var edgeData = $("[data-graph]").data('graph') || this.$graphCanvas.data('graph') || []; | |
49 | var prev_link = $('.load-more-commits').find('.prev-commits').get(0); |
|
49 | var prev_link = $('.load-more-commits').find('.prev-commits').get(0); | |
50 | var next_link = $('.load-more-commits').find('.next-commits').get(0); |
|
50 | var next_link = $('.load-more-commits').find('.next-commits').get(0); | |
51 |
|
51 | |||
52 | // Determine max number of edges per row in graph |
|
52 | // Determine max number of edges per row in graph | |
53 | var edgeCount = 1; |
|
53 | var edgeCount = 1; | |
54 | $.each(edgeData, function (i, item) { |
|
54 | $.each(edgeData, function (i, item) { | |
55 | $.each(item[2], function (key, value) { |
|
55 | $.each(item[2], function (key, value) { | |
56 | if (value[1] > edgeCount) { |
|
56 | if (value[1] > edgeCount) { | |
57 | edgeCount = value[1]; |
|
57 | edgeCount = value[1]; | |
58 | } |
|
58 | } | |
59 | }); |
|
59 | }); | |
60 | }); |
|
60 | }); | |
61 |
|
61 | |||
62 | if (prev_link && next_link) { |
|
62 | if (prev_link && next_link) { | |
63 | var graph_padding = -64; |
|
63 | var graph_padding = -64; | |
64 | } |
|
64 | } | |
65 | else if (next_link) { |
|
65 | else if (next_link) { | |
66 | var graph_padding = -32; |
|
66 | var graph_padding = -32; | |
67 | } else { |
|
67 | } else { | |
68 | var graph_padding = 0; |
|
68 | var graph_padding = 0; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | var x_step = Math.min(10, Math.floor(86 / edgeCount)); |
|
71 | var x_step = Math.min(10, Math.floor(86 / edgeCount)); | |
72 | var height = $('#changesets').find('.commits-range').height() + graph_padding; |
|
72 | var height = $('#changesets').find('.commits-range').height() + graph_padding; | |
73 | var graph_options = { |
|
73 | var graph_options = { | |
74 | width: 100, |
|
74 | width: 100, | |
75 | height: height, |
|
75 | height: height, | |
76 | x_step: x_step, |
|
76 | x_step: x_step, | |
77 | y_step: 42, |
|
77 | y_step: 42, | |
78 | dotRadius: 3.5, |
|
78 | dotRadius: 3.5, | |
79 | lineWidth: 2.5 |
|
79 | lineWidth: 2.5 | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | var prevCommitsData = this.$graphCanvas.data('commits') || []; |
|
82 | var prevCommitsData = this.$graphCanvas.data('commits') || []; | |
83 | var nextCommitsData = $("[data-graph]").data('commits') || []; |
|
83 | var nextCommitsData = $("[data-graph]").data('commits') || []; | |
84 |
|
84 | |||
85 | if (chunk == 'next') { |
|
85 | if (chunk == 'next') { | |
86 | var commitData = $.merge(prevCommitsData, nextCommitsData); |
|
86 | var commitData = $.merge(prevCommitsData, nextCommitsData); | |
87 | } else { |
|
87 | } else { | |
88 | var commitData = $.merge(nextCommitsData, prevCommitsData); |
|
88 | var commitData = $.merge(nextCommitsData, prevCommitsData); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | this.$graphCanvas.data('graph', edgeData); |
|
91 | this.$graphCanvas.data('graph', edgeData); | |
92 | this.$graphCanvas.data('commits', commitData); |
|
92 | this.$graphCanvas.data('commits', commitData); | |
93 |
|
93 | |||
94 | // destroy dynamic loaded graph |
|
94 | // destroy dynamic loaded graph | |
95 | $("[data-graph]").remove(); |
|
95 | $("[data-graph]").remove(); | |
96 |
|
96 | |||
97 | this.$graphCanvas.commits(graph_options); |
|
97 | this.$graphCanvas.commits(graph_options); | |
98 |
|
98 | |||
99 | this.setLabelText(edgeData); |
|
99 | this.setLabelText(edgeData); | |
100 |
|
100 | |||
101 | var padding = 90; |
|
101 | var padding = 90; | |
102 | if (prev_link) { |
|
102 | if (prev_link) { | |
103 | padding += 34; |
|
103 | padding += 34; | |
104 |
|
104 | |||
105 | } |
|
105 | } | |
106 | $('#graph_nodes').css({'padding-top': padding}); |
|
106 | $('#graph_nodes').css({'padding-top': padding}); | |
107 |
|
107 | |||
108 | $.each($('.message.truncate'), function(idx, value) { |
|
108 | $.each($('.message.truncate'), function(idx, value) { | |
109 | if(!(value.offsetWidth < value.scrollWidth)){ |
|
109 | if(!(value.offsetWidth < value.scrollWidth)){ | |
110 |
$(this).closest('td').siblings('.expand_commit') |
|
110 | var expandTd = $(this).closest('td').siblings('.expand_commit'); | |
|
111 | expandTd.find('i').hide(); | |||
|
112 | expandTd.removeAttr('title'); | |||
|
113 | expandTd.removeClass('expand_commit'); | |||
111 | } |
|
114 | } | |
112 | }); |
|
115 | }); | |
113 |
|
116 | |||
114 | }; |
|
117 | }; | |
115 |
|
118 | |||
116 | this.getChunkUrl = function (page, chunk, branch, commit_id, f_path) { |
|
119 | this.getChunkUrl = function (page, chunk, branch, commit_id, f_path) { | |
117 | var urlData = { |
|
120 | var urlData = { | |
118 | 'repo_name': templateContext.repo_name, |
|
121 | 'repo_name': templateContext.repo_name, | |
119 | 'page': page, |
|
122 | 'page': page, | |
120 | 'chunk': chunk |
|
123 | 'chunk': chunk | |
121 | }; |
|
124 | }; | |
122 |
|
125 | |||
123 | if (branch !== undefined && branch !== '') { |
|
126 | if (branch !== undefined && branch !== '') { | |
124 | urlData['branch'] = branch; |
|
127 | urlData['branch'] = branch; | |
125 | } |
|
128 | } | |
126 | if (commit_id !== undefined && commit_id !== '') { |
|
129 | if (commit_id !== undefined && commit_id !== '') { | |
127 | urlData['commit_id'] = commit_id; |
|
130 | urlData['commit_id'] = commit_id; | |
128 | } |
|
131 | } | |
129 | if (f_path !== undefined && f_path !== '') { |
|
132 | if (f_path !== undefined && f_path !== '') { | |
130 | urlData['f_path'] = f_path; |
|
133 | urlData['f_path'] = f_path; | |
131 | } |
|
134 | } | |
132 |
|
135 | |||
133 | if (urlData['commit_id'] && urlData['f_path']) { |
|
136 | if (urlData['commit_id'] && urlData['f_path']) { | |
134 | return pyroutes.url('repo_commits_elements_file', urlData); |
|
137 | return pyroutes.url('repo_commits_elements_file', urlData); | |
135 | } |
|
138 | } | |
136 | else { |
|
139 | else { | |
137 | return pyroutes.url('repo_commits_elements', urlData); |
|
140 | return pyroutes.url('repo_commits_elements', urlData); | |
138 | } |
|
141 | } | |
139 |
|
142 | |||
140 | }; |
|
143 | }; | |
141 |
|
144 | |||
142 | this.loadNext = function (node, page, branch, commit_id, f_path) { |
|
145 | this.loadNext = function (node, page, branch, commit_id, f_path) { | |
143 | var loadUrl = this.getChunkUrl(page, 'next', branch, commit_id, f_path); |
|
146 | var loadUrl = this.getChunkUrl(page, 'next', branch, commit_id, f_path); | |
144 | var postData = {'graph': JSON.stringify(this.getCurrentGraphData())}; |
|
147 | var postData = {'graph': JSON.stringify(this.getCurrentGraphData())}; | |
145 |
|
148 | |||
146 | $.post(loadUrl, postData, function (data) { |
|
149 | $.post(loadUrl, postData, function (data) { | |
147 | $(node).closest('tbody').append(data); |
|
150 | $(node).closest('tbody').append(data); | |
148 | $(node).closest('td').remove(); |
|
151 | $(node).closest('td').remove(); | |
149 | self.reloadGraph('next'); |
|
152 | self.reloadGraph('next'); | |
150 | }) |
|
153 | }) | |
151 | }; |
|
154 | }; | |
152 |
|
155 | |||
153 | this.loadPrev = function (node, page, branch, commit_id, f_path) { |
|
156 | this.loadPrev = function (node, page, branch, commit_id, f_path) { | |
154 | var loadUrl = this.getChunkUrl(page, 'prev', branch, commit_id, f_path); |
|
157 | var loadUrl = this.getChunkUrl(page, 'prev', branch, commit_id, f_path); | |
155 | var postData = {'graph': JSON.stringify(this.getCurrentGraphData())}; |
|
158 | var postData = {'graph': JSON.stringify(this.getCurrentGraphData())}; | |
156 |
|
159 | |||
157 | $.post(loadUrl, postData, function (data) { |
|
160 | $.post(loadUrl, postData, function (data) { | |
158 | $(node).closest('tbody').prepend(data); |
|
161 | $(node).closest('tbody').prepend(data); | |
159 | $(node).closest('td').remove(); |
|
162 | $(node).closest('td').remove(); | |
160 | self.reloadGraph('prev'); |
|
163 | self.reloadGraph('prev'); | |
161 | }) |
|
164 | }) | |
162 | }; |
|
165 | }; | |
163 |
|
166 | |||
164 | this.expandCommit = function (node, reloadGraph) { |
|
167 | this.expandCommit = function (node, reloadGraph) { | |
165 | reloadGraph = reloadGraph || false; |
|
168 | reloadGraph = reloadGraph || false; | |
166 |
|
169 | |||
167 | var target_expand = $(node); |
|
170 | var target_expand = $(node); | |
168 | var cid = target_expand.data('commitId'); |
|
171 | var cid = target_expand.data('commitId'); | |
169 |
|
172 | |||
170 | if (target_expand.hasClass('open')) { |
|
173 | if (target_expand.hasClass('open')) { | |
171 | $('#c-' + cid).css({ |
|
174 | $('#c-' + cid).css({ | |
172 | 'height': '1.5em', |
|
175 | 'height': '1.5em', | |
173 | 'white-space': 'nowrap', |
|
176 | 'white-space': 'nowrap', | |
174 | 'text-overflow': 'ellipsis', |
|
177 | 'text-overflow': 'ellipsis', | |
175 | 'overflow': 'hidden' |
|
178 | 'overflow': 'hidden' | |
176 | }); |
|
179 | }); | |
177 | $('#t-' + cid).css({ |
|
180 | $('#t-' + cid).css({ | |
178 | 'height': 'auto', |
|
181 | 'height': 'auto', | |
179 | 'line-height': '.9em', |
|
182 | 'line-height': '.9em', | |
180 | 'text-overflow': 'ellipsis', |
|
183 | 'text-overflow': 'ellipsis', | |
181 | 'overflow': 'hidden', |
|
184 | 'overflow': 'hidden', | |
182 | 'white-space': 'nowrap' |
|
185 | 'white-space': 'nowrap' | |
183 | }); |
|
186 | }); | |
184 | target_expand.removeClass('open'); |
|
187 | target_expand.removeClass('open'); | |
185 | } |
|
188 | } | |
186 | else { |
|
189 | else { | |
187 | $('#c-' + cid).css({ |
|
190 | $('#c-' + cid).css({ | |
188 | 'height': 'auto', |
|
191 | 'height': 'auto', | |
189 | 'white-space': 'pre-line', |
|
192 | 'white-space': 'pre-line', | |
190 | 'text-overflow': 'initial', |
|
193 | 'text-overflow': 'initial', | |
191 | 'overflow': 'visible' |
|
194 | 'overflow': 'visible' | |
192 | }); |
|
195 | }); | |
193 | $('#t-' + cid).css({ |
|
196 | $('#t-' + cid).css({ | |
194 | 'height': 'auto', |
|
197 | 'height': 'auto', | |
195 | 'max-height': 'none', |
|
198 | 'max-height': 'none', | |
196 | 'text-overflow': 'initial', |
|
199 | 'text-overflow': 'initial', | |
197 | 'overflow': 'visible', |
|
200 | 'overflow': 'visible', | |
198 | 'white-space': 'normal' |
|
201 | 'white-space': 'normal' | |
199 | }); |
|
202 | }); | |
200 | target_expand.addClass('open'); |
|
203 | target_expand.addClass('open'); | |
201 | } |
|
204 | } | |
202 |
|
205 | |||
203 | if (reloadGraph) { |
|
206 | if (reloadGraph) { | |
204 | // redraw the graph |
|
207 | // redraw the graph | |
205 | self.reloadGraph(); |
|
208 | self.reloadGraph(); | |
206 | } |
|
209 | } | |
207 | } |
|
210 | } | |
208 | }; |
|
211 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now