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