##// END OF EJS Templates
files: fixed lost pjax timeout
marcink -
r3656:949d861d new-ui
parent child Browse files
Show More
@@ -1,350 +1,350 b''
1 1 <%inherit file="/base/base.mako"/>
2 2
3 3 <%def name="title(*args)">
4 4 ${_('{} Files').format(c.repo_name)}
5 5 %if hasattr(c,'file'):
6 6 &middot; ${(h.safe_unicode(c.file.path) or '\\')}
7 7 %endif
8 8
9 9 %if c.rhodecode_name:
10 10 &middot; ${h.branding(c.rhodecode_name)}
11 11 %endif
12 12 </%def>
13 13
14 14 <%def name="breadcrumbs_links()">
15 15 ${_('Files')}
16 16 %if c.file:
17 17 @ ${h.show_id(c.commit)}
18 18 %endif
19 19 </%def>
20 20
21 21 <%def name="menu_bar_nav()">
22 22 ${self.menu_items(active='repositories')}
23 23 </%def>
24 24
25 25 <%def name="menu_bar_subnav()">
26 26 ${self.repo_menu(active='files')}
27 27 </%def>
28 28
29 29 <%def name="main()">
30 30 <div>
31 31 <div id="files_data">
32 32 <%include file='files_pjax.mako'/>
33 33 </div>
34 34 </div>
35 35 <script>
36 36
37 37 var metadataRequest = null;
38 38 var fileSourcePage = ${c.file_source_page};
39 39 var atRef = '${request.GET.get('at', '')}';
40 40
41 41 var getState = function(context) {
42 42 var url = $(location).attr('href');
43 43 var _base_url = '${h.route_path("repo_files",repo_name=c.repo_name,commit_id='',f_path='')}';
44 44 var _annotate_url = '${h.route_path("repo_files:annotated",repo_name=c.repo_name,commit_id='',f_path='')}';
45 45 _base_url = _base_url.replace('//', '/');
46 46 _annotate_url = _annotate_url.replace('//', '/');
47 47
48 48 //extract f_path from url.
49 49 var parts = url.split(_base_url);
50 50 if (parts.length != 2) {
51 51 parts = url.split(_annotate_url);
52 52 if (parts.length != 2) {
53 53 var rev = "tip";
54 54 var f_path = "";
55 55 } else {
56 56 var parts2 = parts[1].split('/');
57 57 var rev = parts2.shift(); // pop the first element which is the revision
58 58 var f_path = parts2.join('/');
59 59 }
60 60
61 61 } else {
62 62 var parts2 = parts[1].split('/');
63 63 var rev = parts2.shift(); // pop the first element which is the revision
64 64 var f_path = parts2.join('/');
65 65 }
66 66
67 67 var url_params = {
68 68 repo_name: templateContext.repo_name,
69 69 commit_id: rev,
70 70 f_path:'__FPATH__'
71 71 };
72 72 if (atRef !== '') {
73 73 url_params['at'] = atRef
74 74 }
75 75
76 76 var _url_base = pyroutes.url('repo_files', url_params);
77 77 var _node_list_url = pyroutes.url('repo_files_nodelist',
78 78 {repo_name: templateContext.repo_name,
79 79 commit_id: rev, f_path: f_path});
80 80
81 81 return {
82 82 url: url,
83 83 f_path: f_path,
84 84 rev: rev,
85 85 commit_id: "${c.commit.raw_id}",
86 86 node_list_url: _node_list_url,
87 87 url_base: _url_base
88 88 };
89 89 };
90 90
91 91 var getFilesMetadata = function() {
92 92 if (metadataRequest && metadataRequest.readyState != 4) {
93 93 metadataRequest.abort();
94 94 }
95 95 if (fileSourcePage) {
96 96 return false;
97 97 }
98 98
99 99 if ($('#file-tree-wrapper').hasClass('full-load')) {
100 100 // in case our HTML wrapper has full-load class we don't
101 101 // trigger the async load of metadata
102 102 return false;
103 103 }
104 104
105 105 var state = getState('metadata');
106 106 var url_data = {
107 107 'repo_name': templateContext.repo_name,
108 108 'commit_id': state.commit_id,
109 109 'f_path': state.f_path
110 110 };
111 111
112 112 var url = pyroutes.url('repo_nodetree_full', url_data);
113 113
114 114 metadataRequest = $.ajax({url: url});
115 115
116 116 metadataRequest.done(function(data) {
117 117 $('#file-tree').html(data);
118 118 timeagoActivate();
119 119 });
120 120 metadataRequest.fail(function (data, textStatus, errorThrown) {
121 121 console.log(data);
122 122 if (data.status != 0) {
123 123 alert("Error while fetching metadata.\nError code {0} ({1}).Please consider reloading the page".format(data.status,data.statusText));
124 124 }
125 125 });
126 126 };
127 127
128 128 var callbacks = function() {
129 129 timeagoActivate();
130 130
131 131 if ($('#trimmed_message_box').height() < 50) {
132 132 $('#message_expand').hide();
133 133 }
134 134
135 135 $('#message_expand').on('click', function(e) {
136 136 $('#trimmed_message_box').css('max-height', 'none');
137 137 $(this).hide();
138 138 });
139 139
140 140 var state = getState('callbacks');
141 141
142 142 // VIEW FOR FILE SOURCE
143 143 if (fileSourcePage) {
144 144 // variants for with source code, not tree view
145 145
146 146 // select code link event
147 147 $("#hlcode").mouseup(getSelectionLink);
148 148
149 149 // file history select2 used for history, and switch to
150 150 var initialCommitData = {
151 151 id: null,
152 152 text: '${_("Pick Commit")}',
153 153 type: 'sha',
154 154 raw_id: null,
155 155 files_url: null
156 156 };
157 157
158 158 select2FileHistorySwitcher('#diff1', initialCommitData, state);
159 159
160 160 // show at, diff to actions handlers
161 161 $('#diff1').on('change', function(e) {
162 162 $('#diff_to_commit').removeClass('disabled').removeAttr("disabled");
163 163 $('#diff_to_commit').val(_gettext('Diff to Commit ') + e.val.truncateAfter(8, '...'));
164 164
165 165 $('#show_at_commit').removeClass('disabled').removeAttr("disabled");
166 166 $('#show_at_commit').val(_gettext('Show at Commit ') + e.val.truncateAfter(8, '...'));
167 167 });
168 168
169 169 $('#diff_to_commit').on('click', function(e) {
170 170 var diff1 = $('#diff1').val();
171 171 var diff2 = $('#diff2').val();
172 172
173 173 var url_data = {
174 174 repo_name: templateContext.repo_name,
175 175 source_ref: diff1,
176 176 source_ref_type: 'rev',
177 177 target_ref: diff2,
178 178 target_ref_type: 'rev',
179 179 merge: 1,
180 180 f_path: state.f_path
181 181 };
182 182 window.location = pyroutes.url('repo_compare', url_data);
183 183 });
184 184
185 185 $('#show_at_commit').on('click', function(e) {
186 186 var diff1 = $('#diff1').val();
187 187
188 188 var annotate = $('#annotate').val();
189 189 if (annotate === "True") {
190 190 var url = pyroutes.url('repo_files:annotated',
191 191 {'repo_name': templateContext.repo_name,
192 192 'commit_id': diff1, 'f_path': state.f_path});
193 193 } else {
194 194 var url = pyroutes.url('repo_files',
195 195 {'repo_name': templateContext.repo_name,
196 196 'commit_id': diff1, 'f_path': state.f_path});
197 197 }
198 198 window.location = url;
199 199
200 200 });
201 201
202 202 // show more authors
203 203 $('#show_authors').on('click', function(e) {
204 204 e.preventDefault();
205 205 var url = pyroutes.url('repo_file_authors',
206 206 {'repo_name': templateContext.repo_name,
207 207 'commit_id': state.rev, 'f_path': state.f_path});
208 208
209 209 $.pjax({
210 210 url: url,
211 211 data: 'annotate=${("1" if c.annotate else "0")}',
212 212 container: '#file_authors',
213 213 push: false,
214 timeout: pjaxTimeout
214 timeout: 5000
215 215 }).complete(function(){
216 216 $('#show_authors').hide();
217 217 $('#file_authors_title').html(_gettext('All Authors'))
218 218 })
219 219 });
220 220
221 221 // load file short history
222 222 $('#file_history_overview').on('click', function(e) {
223 223 e.preventDefault();
224 224 path = state.f_path;
225 225 if (path.indexOf("#") >= 0) {
226 226 path = path.slice(0, path.indexOf("#"));
227 227 }
228 228 var url = pyroutes.url('repo_changelog_file',
229 229 {'repo_name': templateContext.repo_name,
230 230 'commit_id': state.rev, 'f_path': path, 'limit': 6});
231 231 $('#file_history_container').show();
232 232 $('#file_history_container').html('<div class="file-history-inner">{0}</div>'.format(_gettext('Loading ...')));
233 233
234 234 $.pjax({
235 235 url: url,
236 236 container: '#file_history_container',
237 237 push: false,
238 timeout: pjaxTimeout
238 timeout: 5000
239 239 })
240 240 });
241 241
242 242 }
243 243 // VIEW FOR FILE TREE BROWSER
244 244 else {
245 245 getFilesMetadata();
246 246
247 247 // fuzzy file filter
248 248 fileBrowserListeners(state.node_list_url, state.url_base);
249 249
250 250 // switch to widget
251 251 var initialCommitData = {
252 252 at_ref: atRef,
253 253 id: null,
254 254 text: '${c.commit.raw_id}',
255 255 type: 'sha',
256 256 raw_id: '${c.commit.raw_id}',
257 257 idx: ${c.commit.idx},
258 258 files_url: null,
259 259 };
260 260
261 261 // check if we have ref info.
262 262 var selectedRef = fileTreeRefs[atRef];
263 263 if (selectedRef !== undefined) {
264 264 $.extend(initialCommitData, selectedRef)
265 265 }
266 266
267 267 var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name});
268 268
269 269 var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
270 270 var formatResult = function (result, container, query) {
271 271 return formatSelect2SelectionRefs(result);
272 272 };
273 273
274 274 var formatSelection = function (data, container) {
275 275 var commit_ref = data;
276 276
277 277 var tmpl = '';
278 278 if (commit_ref.type === 'sha') {
279 279 tmpl = commit_ref.raw_id.substr(0,8);
280 280 } else if (commit_ref.type === 'branch') {
281 281 tmpl = tmpl.concat('<i class="icon-branch"></i> ');
282 282 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
283 283 } else if (commit_ref.type === 'tag') {
284 284 tmpl = tmpl.concat('<i class="icon-tag"></i> ');
285 285 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
286 286 } else if (commit_ref.type === 'book') {
287 287 tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
288 288 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
289 289 }
290 290
291 291 tmpl = tmpl.concat('<span class="select-index-number">{0}</span>'.format(commit_ref.idx));
292 292 return tmpl
293 293 };
294 294
295 295 $(targetElement).select2({
296 296 cachedDataSource: {},
297 297 dropdownAutoWidth: true,
298 298 width: "resolve",
299 299 containerCssClass: "drop-menu",
300 300 dropdownCssClass: "drop-menu-dropdown",
301 301 query: function(query) {
302 302 var self = this;
303 303 var cacheKey = '__ALL_FILE_REFS__';
304 304 var cachedData = self.cachedDataSource[cacheKey];
305 305 if (cachedData) {
306 306 var data = select2RefFilterResults(query.term, cachedData);
307 307 query.callback({results: data.results});
308 308 } else {
309 309 $.ajax({
310 310 url: loadUrl,
311 311 data: {},
312 312 dataType: 'json',
313 313 type: 'GET',
314 314 success: function(data) {
315 315 self.cachedDataSource[cacheKey] = data;
316 316 query.callback({results: data.results});
317 317 }
318 318 });
319 319 }
320 320 },
321 321 initSelection: function(element, callback) {
322 322 callback(initialData);
323 323 },
324 324 formatResult: formatResult,
325 325 formatSelection: formatSelection
326 326 });
327 327
328 328 };
329 329
330 330 select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData);
331 331
332 332 $('#refs_filter').on('change', function(e) {
333 333 var data = $('#refs_filter').select2('data');
334 334 window.location = data.files_url
335 335 });
336 336
337 337 }
338 338 };
339 339
340 340 $(document).ready(function() {
341 341 callbacks();
342 342 var search_GET = "${request.GET.get('search','')}";
343 343 if (search_GET === "1") {
344 344 _NODEFILTER.initFilter();
345 345 }
346 346 });
347 347
348 348 </script>
349 349
350 350 </%def> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now