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