{% extends "repo_master.html" %}
{% from "_formhelper.html" import render_field_in_row, show_comment %}
{% block title %}Pull request #{{ requestid }} - {{ repo.name }}{% endblock %}
{%block tag %}home{% endblock %}
{% block repo %}
<h2>Request pull
<a href="{{ url_for('view_repo', username=username, repo=repo.name)}}">
{{ repo.name }}
</a>
(<a href="{{ url_for('view_tree', username=username,
repo=repo.name, identifier=commitid) }}"
>tree</a>)
</h2>
{% if pull_request %}
<div class="header">
<h3>Title: {{ pull_request.title }}</h3>
<ul class="buttons">
{% if pull_request.status and repo_admin %}
<li>
<form action="{{ url_for('merge_request_pull', username=username,
repo=repo.name, requestid=requestid) }}" method="POST">
{{ mergeform.csrf_token }}
<input class="button" type="submit" value="Merge"/>
</form>
</li>
<li>
<form action="{{ url_for('cancel_request_pull', username=username,
repo=repo.name, requestid=requestid) }}" method="POST">
{{ mergeform.csrf_token }}
<input type="submit" value="Close" id="cancel_pr" class="button"/>
</form>
</li>
{% elif pull_request and pull_request.status == False %}
<li>
<span class="error">Merged</span>
</li>
{% endif %}
<li>
<a class="button patch" href="{{ url_for('request_pull_patch', username=username,
repo=repo.name, requestid=requestid) }}">Patch</a>
</li>
</ul>
</div>
{% endif %}
{% if form %}
<section class="new_project">
<form action="{{ url_for('.new_request_pull', username=username,
repo=repo.name, commitid=commitid, branch_from=branch_from,
branch_to=branch_to) }}" method="post">
<table>
{{ render_field_in_row(form.title) }}
<tr>
<td>To branch</td>
<td>
<select id="branch_select" name="branch_to">
<option>{{ branch_to }}</option>
{% for branch in branches |reverse %}
{% if branch != branch_to %}
<option>{{ branch }}</option>
{% endif %}
{% endfor %}
</select>
</td>
</tr>
</table>
<p class="buttons indent">
<input type="submit" class="submit positive button" value="Create">
{{ form.csrf_token }}
<a href="{{ url_for('view_repo', username=username, repo=repo.name)}}">
<input type="button" value="Cancel" />
</a>
</p>
</form>
</section>
{% endif %}
{% if pull_request %}
<section class="pr_info">
<table>
<tr>
<th>By</th>
<td>
<a href="{{ url_for('view_user', username=pull_request.user.user) }}">
{{ pull_request.user.user | avatar(16) | safe }}
{{ pull_request.user.fullname }} ({{ pull_request.user.user }})
</a>
</td>
</tr>
<tr>
<th>From</th>
<td>
<a href="{{ url_for('view_repo_branch',
username=pull_request.repo_from.user.user if pull_request.repo_from.is_fork,
repo=pull_request.repo_from.name,
branchname=pull_request.branch_from)
}}">
{{ pull_request.repo_from.fullname }} ({{ pull_request.branch_from }})
</td>
</tr>
<tr>
<th>Created</th>
<td title="{{ pull_request.date_created.strftime('%b %d %Y %H:%M:%S') }}">
{{ pull_request.date_created |humanize }}
</td>
</tr>
</table>
</section>
{% endif %}
<section class="commit_list">
<ul>
{% for commit in diff_commits %}
<li>
{% if pull_request and pull_request.status and pull_request.repo_from.is_fork %}
<a href="{{ url_for('view_commit', username=pull_request.repo_from.user.user,
repo=pull_request.repo_from.name, commitid=commit.oid.hex)}}">
{% else %}
<a href="{{ url_for('view_commit', username=username,
repo=repo.name, commitid=commit.oid.hex)}}">
{% endif %}
<span class="commitid">{{ commit.oid.hex|short }}</span>
{{ commit.message.split('\n')[0] }}
<span class="commitdate" title="{{ commit.commit_time|format_ts }}">
{{ commit.commit_time|humanize }}
</span>
</a>
</li>
{% else %}
<p class="error"> No commits found </p>
{% endfor %}
</ul>
</section>
<section class="request_diff">
{% if diff %}
{% for patch in diff %}
<section class="commit_diff">
<header>
<h3>{{ patch.new_file_path }}</h3>
<ul class="buttons">
<li class="addrem_bar">
{% if (patch.additions + patch.deletions) %}
<span style="width: {{ (100.0 * patch.additions / (patch.additions + patch.deletions))|round|int }}%">
{% if patch.additions > 0 %}+{{ patch.additions }}{% endif %}
{% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %}
</span>
{% endif %}
</li>
<li>
{% if pull_request %}
<a class="button view" href="{{
url_for(
'view_file',
username=pull_request.repo_from.user.username,
repo=pull_request.repo_from.name,
identifier=pull_request.branch_from,
filename=patch.new_file_path) }}"
{% else %}
<a class="button view" href="{{
url_for(
'view_file',
username=username,
repo=repo.name,
identifier=branch_from,
filename=patch.new_file_path) }}"
{% endif %}
{% if patch |hasattr('new_id') %}
title="View file as of {{ patch.new_id|short }}">View</a>
{% else %}
title="View file as of {{ patch.new_oid|short }}">View</a>
{% endif %}
</li>
</ul>
</header>
{% autoescape false %}
{{ patch | patch_to_diff | html_diff | format_loc(
filename=patch.new_file_path,
commit=patch.new_id or patch.new_oid,
prequest=pull_request,
index=loop.index)}}
{% endautoescape %}
{% endfor %}
{% endif %}
</section>
{% if pull_request and pull_request.comments%}
<section class="request_comment">
{% for comment in pull_request.discussion %}
{% if not comment.commit_id %}
{{ show_comment(comment.user, comment.date_created, comment.comment,
loop.index) }}
{% endif %}
{% endfor %}
</section>
{% endif %}
<section class="request_comment add_comment">
{% if authenticated and mergeform and pull_request %}
<form action="{{ url_for(
'pull_request_add_comment', username=username, repo=repo.name,
requestid=requestid) }}"
method="post">
{{ mergeform.csrf_token }}
<header>
<label for="comment">Add new comment</label>
(supports the <a href="http://daringfireball.net/projects/markdown/syntax"
target="_blank">Markdown syntax</a>)
</header>
<div id="tabs">
<ul>
<li><a href="#edit">Comment</a></li>
<li><a href="#preview">Preview</a></li>
</ul>
<div id="edit">
<div>
<textarea id="comment" name="comment" placeholder="Enter your comment here"></textarea>
</div>
</div>
<div id="preview">
</div>
<div>
<input type="submit" class="submit positive button" value="Comment">
<input type="button" value="Clear" id="clear_comment" />
</div>
</div>
</form>
{% elif pull_request %}
<p><a href="{{ url_for('auth_login', next=request.url) }}">Login</a> to comment.</p>
{% endif %}
</section>
{% endblock %}
{% block jscripts %}
{{ super() }}
<script type="text/javascript">
$(function(){
$( "#branch_select" ).change(
function() {
var sel = $('#branch_select');
var final_url = "{{ url_for('.new_request_pull', username=username,
repo=repo.name, commitid=commitid, branch_from=branch_from,
branch_to='--') }}";
final_url = final_url.replace('--', sel.val());
window.location.href = final_url;
}
);
{% if pull_request %}
{# These lines are only for existing pull-requests, not new ones #}
$('#cancel_pr').click(function(){
return window.confirm("Are you sure you want to close this requested pull?");
});
});
function comment() {
$( ".cancel" ).click(
function() {
$(this).parent().parent().parent().parent().remove();
}
);
};
$(function(){
$( ".code_table tr" ).hover(
function() {
$( this ).find( "img" ).show().width(13);
}, function() {
$( this ).find( "img" ).hide();
}
);
$( ".prc" ).click(
function() {
var row = $( this ).attr('data-row');
var commit = $( this ).attr('data-commit');
var filename = $( this ).attr('data-filename');
var url = "{{ url_for(
'pull_request_add_comment', username=username, repo=repo.name,
requestid=requestid, commit='', filename='', row='') }}".slice(0, -2);
url = url + commit + '/' + filename + '/' + row;
var rowid = $(this).prev().find('a').attr('id');
var table = $( this ).parent().parent();
var nextid = rowid.replace('_' + row, '_' + (Number(row) + 1));
var next_row = table.find('#' + nextid).parent().parent();
if (next_row.prev().find('.pr_comment_form').length == 0){
$.get( url , function( data ) {
next_row.before(
'<tr><td></td><td colspan="2" class="pr_comment_form">' + data + '</td></tr>' );
comment();
});
} else {
next_row.prev().find('.pr_comment_form').parent().remove();
}
}
);
$( "#tabs" ).tabs();
$( "#tabs" ).on('tabsactivate',
function(event, ui) {
if (ui.newPanel.selector == '#preview') {
var _text = $( "#comment" ).val();
var _url = "{{ url_for('markdown_preview') }}";
$.ajax({
url: _url ,
type: 'POST',
data: {
content: _text,
csrf_token: "{{ mergeform.csrf_token.current_token }}",
},
dataType: 'html',
success: function(res) {
$( "#preview" ).html(res);
},
error: function() {
alert('Unable to generate preview!');
}
});
return false;
}
}
);
$( ".reply" ).click(
function() {
var _section = $(this).parent().parent().parent();
var _comment = _section.find('.comment_body');
var _text = _comment.text().split("\n");
var _output = new Array();
for (cnt = 0; cnt < _text.length - 1; cnt ++) {
_output[cnt] = '> ' + jQuery.trim(_text[cnt + 1]);
}
$( "#comment" ).val(_output.join("\n"));
}
);
var cur_hash = null;
highlight_comment = function() {
var _hash = window.location.hash;
if (_hash != cur_hash) {
$( cur_hash ).css(
"background", "linear-gradient(to bottom, #ededed 0%, #fff 100%)"
);
};
cur_hash = _hash;
if ( _hash ) {
$( _hash ).css(
"background", "linear-gradient(to bottom, #eded98 0%, #fff 100%)"
);
};
return false;
};
$(window.onload=highlight_comment());
$(window).on('hashchange', highlight_comment);
{% endif %}
});
</script>
{% endblock %}