##// END OF EJS Templates
files: added option to use highlight marker to show keywords inside file source.
dan -
r3315:3f904fe0 default
parent child Browse files
Show More
@@ -1,324 +1,324 b''
1 1 <%inherit file="/base/base.mako"/>
2 2
3 3 <%def name="title(*args)">
4 4 ${_('%s Files') % 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 class="title">
31 31 ${self.repo_page_title(c.rhodecode_db_repo)}
32 32 </div>
33 33
34 34 <div id="pjax-container" class="summary">
35 35 <div id="files_data">
36 36 <%include file='files_pjax.mako'/>
37 37 </div>
38 38 </div>
39 39 <script>
40 40 var curState = {
41 41 commit_id: "${c.commit.raw_id}"
42 42 };
43 43
44 44 var getState = function(context) {
45 45 var url = $(location).attr('href');
46 46 var _base_url = '${h.route_path("repo_files",repo_name=c.repo_name,commit_id='',f_path='')}';
47 47 var _annotate_url = '${h.route_path("repo_files:annotated",repo_name=c.repo_name,commit_id='',f_path='')}';
48 48 _base_url = _base_url.replace('//', '/');
49 49 _annotate_url = _annotate_url.replace('//', '/');
50 50
51 51 //extract f_path from url.
52 52 var parts = url.split(_base_url);
53 53 if (parts.length != 2) {
54 54 parts = url.split(_annotate_url);
55 55 if (parts.length != 2) {
56 56 var rev = "tip";
57 57 var f_path = "";
58 58 } else {
59 59 var parts2 = parts[1].split('/');
60 60 var rev = parts2.shift(); // pop the first element which is the revision
61 61 var f_path = parts2.join('/');
62 62 }
63 63
64 64 } else {
65 65 var parts2 = parts[1].split('/');
66 66 var rev = parts2.shift(); // pop the first element which is the revision
67 67 var f_path = parts2.join('/');
68 68 }
69 69
70 70 var _node_list_url = pyroutes.url('repo_files_nodelist',
71 71 {repo_name: templateContext.repo_name,
72 72 commit_id: rev, f_path: f_path});
73 73 var _url_base = pyroutes.url('repo_files',
74 74 {repo_name: templateContext.repo_name,
75 75 commit_id: rev, f_path:'__FPATH__'});
76 76 return {
77 77 url: url,
78 78 f_path: f_path,
79 79 rev: rev,
80 80 commit_id: curState.commit_id,
81 81 node_list_url: _node_list_url,
82 82 url_base: _url_base
83 83 };
84 84 };
85 85
86 86 var metadataRequest = null;
87 87 var getFilesMetadata = function() {
88 88 if (metadataRequest && metadataRequest.readyState != 4) {
89 89 metadataRequest.abort();
90 90 }
91 91 if (fileSourcePage) {
92 92 return false;
93 93 }
94 94
95 95 if ($('#file-tree-wrapper').hasClass('full-load')) {
96 96 // in case our HTML wrapper has full-load class we don't
97 97 // trigger the async load of metadata
98 98 return false;
99 99 }
100 100
101 101 var state = getState('metadata');
102 102 var url_data = {
103 103 'repo_name': templateContext.repo_name,
104 104 'commit_id': state.commit_id,
105 105 'f_path': state.f_path
106 106 };
107 107
108 108 var url = pyroutes.url('repo_nodetree_full', url_data);
109 109
110 110 metadataRequest = $.ajax({url: url});
111 111
112 112 metadataRequest.done(function(data) {
113 113 $('#file-tree').html(data);
114 114 timeagoActivate();
115 115 });
116 116 metadataRequest.fail(function (data, textStatus, errorThrown) {
117 117 console.log(data);
118 118 if (data.status != 0) {
119 119 alert("Error while fetching metadata.\nError code {0} ({1}).Please consider reloading the page".format(data.status,data.statusText));
120 120 }
121 121 });
122 122 };
123 123
124 124 var callbacks = function() {
125 125 var state = getState('callbacks');
126 126 timeagoActivate();
127 127
128 128 // used for history, and switch to
129 129 var initialCommitData = {
130 130 id: null,
131 131 text: '${_("Pick Commit")}',
132 132 type: 'sha',
133 133 raw_id: null,
134 134 files_url: null
135 135 };
136 136
137 137 if ($('#trimmed_message_box').height() < 50) {
138 138 $('#message_expand').hide();
139 139 }
140 140
141 141 $('#message_expand').on('click', function(e) {
142 142 $('#trimmed_message_box').css('max-height', 'none');
143 143 $(this).hide();
144 144 });
145 145
146 146 if (fileSourcePage) {
147 147 // variants for with source code, not tree view
148 148
149 149 // select code link event
150 150 $("#hlcode").mouseup(getSelectionLink);
151 151
152 152 // file history select2
153 153 select2FileHistorySwitcher('#diff1', initialCommitData, state);
154 154
155 155 // show at, diff to actions handlers
156 156 $('#diff1').on('change', function(e) {
157 157 $('#diff_to_commit').removeClass('disabled').removeAttr("disabled");
158 158 $('#diff_to_commit').val(_gettext('Diff to Commit ') + e.val.truncateAfter(8, '...'));
159 159
160 160 $('#show_at_commit').removeClass('disabled').removeAttr("disabled");
161 161 $('#show_at_commit').val(_gettext('Show at Commit ') + e.val.truncateAfter(8, '...'));
162 162 });
163 163
164 164 $('#diff_to_commit').on('click', function(e) {
165 165 var diff1 = $('#diff1').val();
166 166 var diff2 = $('#diff2').val();
167 167
168 168 var url_data = {
169 169 repo_name: templateContext.repo_name,
170 170 source_ref: diff1,
171 171 source_ref_type: 'rev',
172 172 target_ref: diff2,
173 173 target_ref_type: 'rev',
174 174 merge: 1,
175 175 f_path: state.f_path
176 176 };
177 177 window.location = pyroutes.url('repo_compare', url_data);
178 178 });
179 179
180 180 $('#show_at_commit').on('click', function(e) {
181 181 var diff1 = $('#diff1').val();
182 182
183 183 var annotate = $('#annotate').val();
184 184 if (annotate === "True") {
185 185 var url = pyroutes.url('repo_files:annotated',
186 186 {'repo_name': templateContext.repo_name,
187 187 'commit_id': diff1, 'f_path': state.f_path});
188 188 } else {
189 189 var url = pyroutes.url('repo_files',
190 190 {'repo_name': templateContext.repo_name,
191 191 'commit_id': diff1, 'f_path': state.f_path});
192 192 }
193 193 window.location = url;
194 194
195 195 });
196 196
197 197 // show more authors
198 198 $('#show_authors').on('click', function(e) {
199 199 e.preventDefault();
200 200 var url = pyroutes.url('repo_file_authors',
201 201 {'repo_name': templateContext.repo_name,
202 202 'commit_id': state.rev, 'f_path': state.f_path});
203 203
204 204 $.pjax({
205 205 url: url,
206 206 data: 'annotate=${"1" if c.annotate else "0"}',
207 207 container: '#file_authors',
208 208 push: false,
209 209 timeout: pjaxTimeout
210 210 }).complete(function(){
211 211 $('#show_authors').hide();
212 212 })
213 213 });
214 214
215 215 // load file short history
216 216 $('#file_history_overview').on('click', function(e) {
217 217 e.preventDefault();
218 218 path = state.f_path;
219 219 if (path.indexOf("#") >= 0) {
220 220 path = path.slice(0, path.indexOf("#"));
221 221 }
222 222 var url = pyroutes.url('repo_changelog_file',
223 223 {'repo_name': templateContext.repo_name,
224 224 'commit_id': state.rev, 'f_path': path, 'limit': 6});
225 225 $('#file_history_container').show();
226 226 $('#file_history_container').html('<div class="file-history-inner">{0}</div>'.format(_gettext('Loading ...')));
227 227
228 228 $.pjax({
229 229 url: url,
230 230 container: '#file_history_container',
231 231 push: false,
232 232 timeout: pjaxTimeout
233 233 })
234 234 });
235 235
236 236 }
237 237 else {
238 238 getFilesMetadata();
239 239
240 240 // fuzzy file filter
241 241 fileBrowserListeners(state.node_list_url, state.url_base);
242 242
243 243 // switch to widget
244 244 select2RefSwitcher('#refs_filter', initialCommitData);
245 245 $('#refs_filter').on('change', function(e) {
246 246 var data = $('#refs_filter').select2('data');
247 247 curState.commit_id = data.raw_id;
248 248 $.pjax({url: data.files_url, container: '#pjax-container', timeout: pjaxTimeout});
249 249 });
250 250
251 251 $("#prev_commit_link").on('click', function(e) {
252 252 var data = $(this).data();
253 253 curState.commit_id = data.commitId;
254 254 });
255 255
256 256 $("#next_commit_link").on('click', function(e) {
257 257 var data = $(this).data();
258 258 curState.commit_id = data.commitId;
259 259 });
260 260
261 261 $('#at_rev').on("keypress", function(e) {
262 262 /* ENTER PRESSED */
263 263 if (e.keyCode === 13) {
264 264 var rev = $('#at_rev').val();
265 265 // explicit reload page here. with pjax entering bad input
266 266 // produces not so nice results
267 267 window.location = pyroutes.url('repo_files',
268 268 {'repo_name': templateContext.repo_name,
269 269 'commit_id': rev, 'f_path': state.f_path});
270 270 }
271 271 });
272 272 }
273 273 };
274 274
275 275 var pjaxTimeout = 5000;
276 276
277 277 $(document).pjax(".pjax-link", "#pjax-container", {
278 278 "fragment": "#pjax-content",
279 279 "maxCacheLength": 1000,
280 280 "timeout": pjaxTimeout
281 281 });
282 282
283 283 // define global back/forward states
284 284 var isPjaxPopState = false;
285 285 $(document).on('pjax:popstate', function() {
286 286 isPjaxPopState = true;
287 287 });
288 288
289 289 $(document).on('pjax:end', function(xhr, options) {
290 290 if (isPjaxPopState) {
291 291 isPjaxPopState = false;
292 292 callbacks();
293 293 _NODEFILTER.resetFilter();
294 294 }
295 295
296 296 // run callback for tracking if defined for google analytics etc.
297 297 // this is used to trigger tracking on pjax
298 298 if (typeof window.rhodecode_statechange_callback !== 'undefined') {
299 299 var state = getState('statechange');
300 300 rhodecode_statechange_callback(state.url, null)
301 301 }
302 302 });
303 303
304 304 $(document).on('pjax:success', function(event, xhr, options) {
305 305 if (event.target.id == "file_history_container") {
306 306 $('#file_history_overview').hide();
307 307 $('#file_history_overview_full').show();
308 308 timeagoActivate();
309 309 } else {
310 310 callbacks();
311 311 }
312 312 });
313 313
314 314 $(document).ready(function() {
315 315 callbacks();
316 316 var search_GET = "${request.GET.get('search','')}";
317 if (search_GET == "1") {
317 if (search_GET === "1") {
318 318 _NODEFILTER.initFilter();
319 319 }
320 320 });
321 321
322 322 </script>
323 323
324 324 </%def>
@@ -1,109 +1,130 b''
1 1 <%namespace name="sourceblock" file="/codeblocks/source.mako"/>
2 2
3 3 <div id="codeblock" class="codeblock">
4 4 <div class="codeblock-header">
5 5 <div class="stats">
6 6 <span class="stats-filename">
7 7 <strong>
8 8 <i class="icon-file-text"></i>
9 9 ${c.file.unicode_path_safe}
10 10 </strong>
11 11 </span>
12 12 <span class="item last"><i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${c.f_path}" title="${_('Copy the full path')}"></i></span>
13 13 <br/>
14 14
15 15 % if c.lf_node:
16 16 <span title="${_('This file is a pointer to large binary file')}"> | ${_('LargeFile')} ${h.format_byte_size_binary(c.lf_node.size)} </span>
17 17 % endif
18 18
19 19 <span class="stats-first-item">${c.file.lines()[0]} ${_ungettext('line', 'lines', c.file.lines()[0])}</span>
20 20 <span> | ${h.format_byte_size_binary(c.file.size)}</span>
21 21 <span> | ${c.file.mimetype} </span>
22 22 <span> | ${h.get_lexer_for_filenode(c.file).__class__.__name__}</span>
23 23
24 24 </div>
25 25 <div class="buttons">
26 26 <a id="file_history_overview" href="#">
27 27 ${_('History')}
28 28 </a>
29 29 <a id="file_history_overview_full" style="display: none" href="${h.route_path('repo_changelog_file',repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path)}">
30 30 ${_('Show Full History')}
31 31 </a> |
32 32 %if c.annotate:
33 33 ${h.link_to(_('Source'), h.route_path('repo_files', repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))}
34 34 %else:
35 35 ${h.link_to(_('Annotation'), h.route_path('repo_files:annotated',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))}
36 36 %endif
37 37 | ${h.link_to(_('Raw'), h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))}
38 38 |
39 39 % if c.lf_node:
40 40 <a href="${h.route_path('repo_file_download',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path, _query=dict(lf=1))}">
41 41 ${_('Download largefile')}
42 42 </a>
43 43 % else:
44 44 <a href="${h.route_path('repo_file_download',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path)}">
45 45 ${_('Download')}
46 46 </a>
47 47 % endif
48 48
49 49 %if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
50 50 |
51 51 %if c.on_branch_head and c.branch_or_raw_id and not c.file.is_binary:
52 52 <a href="${h.route_path('repo_files_edit_file',repo_name=c.repo_name,commit_id=c.branch_or_raw_id,f_path=c.f_path, _anchor='edit')}">
53 53 ${_('Edit on Branch:{}').format(c.branch_name)}
54 54 </a>
55 55 | <a class="btn-danger btn-link" href="${h.route_path('repo_files_remove_file',repo_name=c.repo_name,commit_id=c.branch_or_raw_id,f_path=c.f_path, _anchor='edit')}">${_('Delete')}
56 56 </a>
57 57 %elif c.on_branch_head and c.branch_or_raw_id and c.file.is_binary:
58 58 ${h.link_to(_('Edit'), '#', class_="btn btn-link disabled tooltip", title=_('Editing binary files not allowed'))}
59 59 | ${h.link_to(_('Delete'), h.route_path('repo_files_remove_file',repo_name=c.repo_name,commit_id=c.branch_or_raw_id,f_path=c.f_path, _anchor='edit'),class_="btn-danger btn-link")}
60 60 %else:
61 61 ${h.link_to(_('Edit'), '#', class_="btn btn-link disabled tooltip", title=_('Editing files allowed only when on branch head commit'))}
62 62 | ${h.link_to(_('Delete'), '#', class_="btn btn-danger btn-link disabled tooltip", title=_('Deleting files allowed only when on branch head commit'))}
63 63 %endif
64 64 %endif
65 65 </div>
66 66 </div>
67 67 <div id="file_history_container"></div>
68 68 <div class="code-body">
69 69 %if c.file.is_binary:
70 70 <% rendered_binary = h.render_binary(c.repo_name, c.file)%>
71 71 % if rendered_binary:
72 72 ${rendered_binary}
73 73 % else:
74 74 <div>
75 75 ${_('Binary file (%s)') % c.file.mimetype}
76 76 </div>
77 77 % endif
78 78 %else:
79 79 % if c.file.size < c.visual.cut_off_limit_file:
80 80 %if c.renderer and not c.annotate:
81 81 ## pick relative url based on renderer
82 82 <%
83 83 relative_urls = {
84 84 'raw': h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path),
85 85 'standard': h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path),
86 86 }
87 87 %>
88 88 ${h.render(c.file.content, renderer=c.renderer, relative_urls=relative_urls)}
89 89 %else:
90 90 <table class="cb codehilite">
91 91 %if c.annotate:
92 92 <% color_hasher = h.color_hasher() %>
93 93 %for annotation, lines in c.annotated_lines:
94 94 ${sourceblock.render_annotation_lines(annotation, lines, color_hasher)}
95 95 %endfor
96 96 %else:
97 97 %for line_num, tokens in enumerate(c.lines, 1):
98 98 ${sourceblock.render_line(line_num, tokens)}
99 99 %endfor
100 100 %endif
101 101 </table>
102 102 %endif
103 103 %else:
104 104 ${_('File size {} is bigger then allowed limit {}. ').format(h.format_byte_size_binary(c.file.size), h.format_byte_size_binary(c.visual.cut_off_limit_file))} ${h.link_to(_('Show as raw'),
105 105 h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))}
106 106 %endif
107 107 %endif
108 108 </div>
109 </div> No newline at end of file
109 </div>
110
111 <script type="text/javascript">
112 % if request.GET.get('mark'):
113
114 $(function(){
115 $(".codehilite").mark(
116 "${request.GET.get('mark')}",
117 {
118 "className": 'match',
119 "accuracy": "complementary",
120 "ignorePunctuation": ":._(){}[]!'+=".split(""),
121 "each": function(el) {
122 // and also highlight lines !
123 $($(el).closest('tr')).find('td.cb-lineno').addClass('cb-line-selected');
124 }
125 }
126 );
127
128 });
129 % endif
130 </script>
General Comments 0
You need to be logged in to leave comments. Login now