files.mako
378 lines
| 13.4 KiB
| application/x-mako
|
MakoHtmlLexer
r1282 | <%inherit file="/base/base.mako"/> | ||
<%def name="title(*args)"> | |||
r3655 | ${_('{} Files').format(c.repo_name)} | ||
r1282 | %if hasattr(c,'file'): | ||
r3655 | · ${(h.safe_unicode(c.file.path) or '\\')} | ||
r1282 | %endif | ||
%if c.rhodecode_name: | |||
· ${h.branding(c.rhodecode_name)} | |||
%endif | |||
</%def> | |||
<%def name="breadcrumbs_links()"> | |||
${_('Files')} | |||
%if c.file: | |||
@ ${h.show_id(c.commit)} | |||
%endif | |||
</%def> | |||
<%def name="menu_bar_nav()"> | |||
${self.menu_items(active='repositories')} | |||
</%def> | |||
<%def name="menu_bar_subnav()"> | |||
${self.repo_menu(active='files')} | |||
</%def> | |||
<%def name="main()"> | |||
r3713 | <script type="text/javascript"> | ||
var fileSourcePage = ${c.file_source_page}; | |||
var atRef = '${request.GET.get('at', '')}'; | |||
// global state for fetching metadata | |||
metadataRequest = null; | |||
// global metadata about URL | |||
r3716 | filesUrlData = ${h.files_url_data(request)|n}; | ||
r3713 | </script> | ||
r3655 | <div> | ||
r3882 | <div> | ||
r1282 | <%include file='files_pjax.mako'/> | ||
</div> | |||
</div> | |||
r3654 | |||
r3713 | <script type="text/javascript"> | ||
r1282 | |||
r3706 | var initFileJS = function () { | ||
r3713 | var state = getFileState(); | ||
r3706 | |||
// select code link event | |||
$("#hlcode").mouseup(getSelectionLink); | |||
// file history select2 used for history of file, and switch to | |||
var initialCommitData = { | |||
at_ref: atRef, | |||
id: null, | |||
text: '${c.commit.raw_id}', | |||
type: 'sha', | |||
raw_id: '${c.commit.raw_id}', | |||
idx: ${c.commit.idx}, | |||
files_url: null, | |||
}; | |||
// check if we have ref info. | |||
var selectedRef = fileTreeRefs[atRef]; | |||
if (selectedRef !== undefined) { | |||
$.extend(initialCommitData, selectedRef) | |||
} | |||
r3713 | var loadUrl = pyroutes.url('repo_file_history', {'repo_name': templateContext.repo_name, 'commit_id': state.commit_id,'f_path': state.f_path}); | ||
r3706 | var cacheKey = '__SINGLE_FILE_REFS__'; | ||
var cachedDataSource = {}; | |||
var loadRefsData = function (query) { | |||
$.ajax({ | |||
url: loadUrl, | |||
data: {}, | |||
dataType: 'json', | |||
type: 'GET', | |||
success: function (data) { | |||
cachedDataSource[cacheKey] = data; | |||
query.callback({results: data.results}); | |||
} | |||
}); | |||
}; | |||
var feedRefsData = function (query, cachedData) { | |||
var data = {results: []}; | |||
//filter results | |||
$.each(cachedData.results, function () { | |||
var section = this.text; | |||
var children = []; | |||
$.each(this.children, function () { | |||
if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) { | |||
children.push(this) | |||
} | |||
}); | |||
data.results.push({ | |||
'text': section, | |||
'children': children | |||
}) | |||
}); | |||
query.callback(data); | |||
}; | |||
var select2FileHistorySwitcher = function (targetElement, loadUrl, initialData) { | |||
var formatResult = function (result, container, query) { | |||
return formatSelect2SelectionRefs(result); | |||
}; | |||
var formatSelection = function (data, container) { | |||
var commit_ref = data; | |||
var tmpl = ''; | |||
if (commit_ref.type === 'sha') { | |||
tmpl = (commit_ref.raw_id || "").substr(0,8); | |||
} else if (commit_ref.type === 'branch') { | |||
tmpl = tmpl.concat('<i class="icon-branch"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} else if (commit_ref.type === 'tag') { | |||
tmpl = tmpl.concat('<i class="icon-tag"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} else if (commit_ref.type === 'book') { | |||
tmpl = tmpl.concat('<i class="icon-bookmark"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} | |||
var idx = commit_ref.idx || 0; | |||
r3707 | if (idx !== 0) { | ||
tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx)); | |||
} | |||
r3706 | return tmpl | ||
}; | |||
$(targetElement).select2({ | |||
dropdownAutoWidth: true, | |||
width: "resolve", | |||
containerCssClass: "drop-menu", | |||
dropdownCssClass: "drop-menu-dropdown", | |||
query: function(query) { | |||
var cachedData = cachedDataSource[cacheKey]; | |||
if (cachedData) { | |||
feedRefsData(query, cachedData) | |||
} else { | |||
loadRefsData(query) | |||
} | |||
}, | |||
initSelection: function(element, callback) { | |||
callback(initialData); | |||
}, | |||
formatResult: formatResult, | |||
formatSelection: formatSelection | |||
}); | |||
}; | |||
select2FileHistorySwitcher('#file_refs_filter', loadUrl, initialCommitData); | |||
r4294 | // switcher for files | ||
r3706 | $('#file_refs_filter').on('change', function(e) { | ||
var data = $('#file_refs_filter').select2('data'); | |||
var commit_id = data.id; | |||
r4294 | var params = { | ||
'repo_name': templateContext.repo_name, | |||
'commit_id': commit_id, | |||
'f_path': state.f_path | |||
}; | |||
if(data.at_rev !== undefined && data.at_rev !== "") { | |||
params['at'] = data.at_rev; | |||
} | |||
r3706 | |||
if ("${c.annotate}" === "True") { | |||
r4294 | var url = pyroutes.url('repo_files:annotated', params); | ||
r3706 | } else { | ||
r4294 | var url = pyroutes.url('repo_files', params); | ||
r3706 | } | ||
window.location = url; | |||
}); | |||
// load file short history | |||
$('#file_history_overview').on('click', function(e) { | |||
e.preventDefault(); | |||
path = state.f_path; | |||
if (path.indexOf("#") >= 0) { | |||
path = path.slice(0, path.indexOf("#")); | |||
} | |||
r3742 | var url = pyroutes.url('repo_commits_file', | ||
r3706 | {'repo_name': templateContext.repo_name, | ||
r3713 | 'commit_id': state.commit_id, 'f_path': path, 'limit': 6}); | ||
r3706 | $('#file_history_container').show(); | ||
$('#file_history_container').html('<div class="file-history-inner">{0}</div>'.format(_gettext('Loading ...'))); | |||
$.pjax({ | |||
url: url, | |||
container: '#file_history_container', | |||
push: false, | |||
timeout: 5000 | |||
r4026 | }).complete(function () { | ||
tooltipActivate(); | |||
r3706 | }); | ||
}); | |||
}; | |||
var initTreeJS = function () { | |||
r3713 | var state = getFileState(); | ||
r3706 | getFilesMetadata(); | ||
// fuzzy file filter | |||
fileBrowserListeners(state.node_list_url, state.url_base); | |||
// switch to widget | |||
var initialCommitData = { | |||
at_ref: atRef, | |||
id: null, | |||
text: '${c.commit.raw_id}', | |||
type: 'sha', | |||
raw_id: '${c.commit.raw_id}', | |||
idx: ${c.commit.idx}, | |||
files_url: null, | |||
}; | |||
// check if we have ref info. | |||
var selectedRef = fileTreeRefs[atRef]; | |||
if (selectedRef !== undefined) { | |||
$.extend(initialCommitData, selectedRef) | |||
} | |||
var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name}); | |||
var cacheKey = '__ALL_FILE_REFS__'; | |||
var cachedDataSource = {}; | |||
var loadRefsData = function (query) { | |||
$.ajax({ | |||
url: loadUrl, | |||
data: {}, | |||
dataType: 'json', | |||
type: 'GET', | |||
success: function (data) { | |||
cachedDataSource[cacheKey] = data; | |||
query.callback({results: data.results}); | |||
} | |||
}); | |||
}; | |||
var feedRefsData = function (query, cachedData) { | |||
var data = {results: []}; | |||
//filter results | |||
$.each(cachedData.results, function () { | |||
var section = this.text; | |||
var children = []; | |||
$.each(this.children, function () { | |||
if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) { | |||
children.push(this) | |||
} | |||
}); | |||
data.results.push({ | |||
'text': section, | |||
'children': children | |||
}) | |||
}); | |||
//push the typed in commit idx | |||
if (!isNaN(query.term)) { | |||
var files_url = pyroutes.url('repo_files', | |||
{'repo_name': templateContext.repo_name, | |||
'commit_id': query.term, 'f_path': state.f_path}); | |||
data.results.push({ | |||
'text': _gettext('go to numeric commit'), | |||
'children': [{ | |||
at_ref: null, | |||
id: null, | |||
text: 'r{0}'.format(query.term), | |||
type: 'sha', | |||
raw_id: query.term, | |||
idx: query.term, | |||
files_url: files_url, | |||
}] | |||
}); | |||
} | |||
query.callback(data); | |||
}; | |||
var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) { | |||
var formatResult = function (result, container, query) { | |||
return formatSelect2SelectionRefs(result); | |||
}; | |||
var formatSelection = function (data, container) { | |||
var commit_ref = data; | |||
var tmpl = ''; | |||
if (commit_ref.type === 'sha') { | |||
tmpl = (commit_ref.raw_id || "").substr(0,8); | |||
} else if (commit_ref.type === 'branch') { | |||
tmpl = tmpl.concat('<i class="icon-branch"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} else if (commit_ref.type === 'tag') { | |||
tmpl = tmpl.concat('<i class="icon-tag"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} else if (commit_ref.type === 'book') { | |||
tmpl = tmpl.concat('<i class="icon-bookmark"></i> '); | |||
tmpl = tmpl.concat(escapeHtml(commit_ref.text)); | |||
} | |||
var idx = commit_ref.idx || 0; | |||
r3707 | if (idx !== 0) { | ||
tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx)); | |||
} | |||
r3706 | return tmpl | ||
}; | |||
$(targetElement).select2({ | |||
dropdownAutoWidth: true, | |||
width: "resolve", | |||
containerCssClass: "drop-menu", | |||
dropdownCssClass: "drop-menu-dropdown", | |||
query: function(query) { | |||
var cachedData = cachedDataSource[cacheKey]; | |||
if (cachedData) { | |||
feedRefsData(query, cachedData) | |||
} else { | |||
loadRefsData(query) | |||
} | |||
}, | |||
initSelection: function(element, callback) { | |||
callback(initialData); | |||
}, | |||
formatResult: formatResult, | |||
formatSelection: formatSelection | |||
}); | |||
}; | |||
select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData); | |||
r4294 | // switcher for file tree | ||
r3706 | $('#refs_filter').on('change', function(e) { | ||
var data = $('#refs_filter').select2('data'); | |||
window.location = data.files_url | |||
}); | |||
}; | |||
$(document).ready(function() { | |||
r1282 | timeagoActivate(); | ||
r4026 | tooltipActivate(); | ||
r1282 | |||
if ($('#trimmed_message_box').height() < 50) { | |||
$('#message_expand').hide(); | |||
} | |||
$('#message_expand').on('click', function(e) { | |||
$('#trimmed_message_box').css('max-height', 'none'); | |||
$(this).hide(); | |||
}); | |||
if (fileSourcePage) { | |||
r3706 | initFileJS() | ||
} else { | |||
initTreeJS() | |||
r1282 | } | ||
r3654 | |||
r1282 | var search_GET = "${request.GET.get('search','')}"; | ||
r3315 | if (search_GET === "1") { | ||
r3694 | NodeFilter.initFilter(); | ||
NodeFilter.focus(); | |||
r1282 | } | ||
}); | |||
</script> | |||
r3655 | </%def> |