Skip to content

Commit

Permalink
#37 +issue links, BUG in ajax/confirm JS
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiedirkx committed Feb 4, 2015
1 parent 87da652 commit 6fe3f08
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 57 deletions.
2 changes: 1 addition & 1 deletion inc.bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
define('JIRA_USER', $account->user);
define('JIRA_AUTH', $account->auth);

define('XSRF_TOKEN', md5(date('Y-m-d') . ':' . JIRA_URL . ':' . JIRA_AUTH));
define('XSRF_TOKEN', md5(date('Y-m-d H') . ':' . JIRA_URL . ':' . JIRA_AUTH));

$url = parse_url(JIRA_URL);
define('JIRA_ORIGIN', $url['scheme'] . '://' . $url['host']);
Expand Down
43 changes: 40 additions & 3 deletions issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
exit;
}

else if ( isset($_GET['delete_link']) ) {
do_tokencheck();

$id = $_GET['delete_link'];
$response = jira_delete('issueLink/' . $id, null, $error, $info);

exit(IS_AJAX ? 'OK' : do_redirect('issue', compact('key')));
}

else if ( isset($_GET['delete_attachment']) ) {
do_tokencheck();

Expand Down Expand Up @@ -125,6 +134,7 @@
$parent = @$fields->parent;
$attachments = $fields->attachment;
$worklogs = $fields->worklog->worklogs;
$links = $fields->issuelinks;
$comments = $fields->comment->comments;

$fieldsmeta = $user->custom_field_ids;
Expand All @@ -146,6 +156,7 @@
$actions['Labels'] = 'labels.php?key=' . $key;
$actions['Log work'] = 'logwork.php?key=' . $key . '&summary=' . urlencode($fields->summary);
$actions['Upload'] = 'upload.php?key=' . $key . '&summary=' . urlencode($fields->summary);
$actions['Link'] = 'link.php?key=' . $key . '&summary=' . urlencode($fields->summary);
$actions['➔ View in Jira'] = JIRA_URL . '/browse/' . $key;

$resolution = '';
Expand Down Expand Up @@ -262,6 +273,30 @@
echo '</div>';
}

if ( $links ) {
echo '<h2 class="pre-menu">' . count($links) . ' links</h2> (<a href="' . $actions['Link'] . '">add</a>)';
echo '<div class="table links">';
echo '<table border="1">';
foreach ( $links AS $i => $link ) {
$first = $i == 0;

$linkedIssue = @$link->outwardIssue ?: $link->inwardIssue;
$xward = @$link->outwardIssue ? 'outward' : 'inward';
$linkTitle = $link->type->$xward;

echo '<tr>';
if ($first) {
echo '<td rowspan="' . count($links) . '">This issue</td>';
}
echo '<td>' . html($linkTitle) . '</td>';
echo '<td>' . html_icon($linkedIssue->fields->issuetype, 'issuetype') . ' <a href="issue.php?key=' . $linkedIssue->key . '">' . $linkedIssue->key . '</a> ' . html_icon($linkedIssue->fields->status, 'status') . ' ' . html($linkedIssue->fields->summary) . '</td>';
echo '<td><a class="ajax" data-confirm="Unlink this issue from ' . $linkedIssue->key . '? Re-linking is easy." href="?key=' . $key . '&delete_link=' . $link->id . '&token=' . XSRF_TOKEN . '">x</a></td>';
echo '</tr>';
}
echo '</table>';
echo '</div>';
}

if ( $worklogs ) {
echo '<h2 class="pre-menu">' . $fields->worklog->total . ' worklogs</h2> (<a href="' . $actions['Log work'] . '">add</a>)';

Expand All @@ -286,7 +321,7 @@
echo '<p><a href="worklogs.php?key=' . $key . '&subtasks=' . implode(',', $subkeys) . '&summary=' . urlencode($fields->summary) . '">See ALL worklogs, incl subtasks.</a></p>';
}

echo '<h2>' . count($comments) . ' comments</h2>';
echo '<h2 class="pre-menu">' . count($comments) . ' comments</h2> (<a href="#new-comment">add</a>)';
echo '<div class="comments">';
foreach ( $comments AS $i => $comment ) {
$created = strtotime($comment->created);
Expand All @@ -303,14 +338,16 @@
}
echo '</div>';

echo '<div class="post-comment">';
echo '<div id="new-comment" class="post-comment">';
echo '<h2>New comment</h2>';
echo '<form autocomplete="off" method="post">';
echo '<p><textarea name="comment" rows="8"></textarea></p>';
echo '<p><input type="submit" /></p>';
echo '</form>';
echo '</div>';

// echo '<pre>' . print_r($issue, 1) . '</pre>';
if ( isset($_GET['debug']) ) {
echo '<pre>' . print_r($issue, 1) . '</pre>';
}

include 'tpl.footer.php';
62 changes: 62 additions & 0 deletions link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

require 'inc.bootstrap.php';

do_logincheck();

$key = @$_GET['key'];

$summary = @$_GET['summary'];

// Create link
if ( isset($_POST['type'], $_POST['issue']) ) {
$type = explode(':', $_POST['type']);
$otherIssueXward = $type[1];
$thisIssueXward = $otherIssueXward == 'inward' ? 'outward' : 'inward';

$data = array(
'type' => array('name' => $type[0]),
$thisIssueXward . 'Issue' => array('key' => $key),
$otherIssueXward . 'Issue' => array('key' => $_POST['issue']),
);

$response = jira_post('issueLink', $data, $error, $info);

if ( !$error ) {
return do_redirect('issue', array('key' => $key));
}

echo '<pre>';
print_r($data);
var_dump($error);
print_r($response);
print_r($info);

exit;
}

$linkTypes = jira_get('issueLinkType');
$linkTypeOptions = array_reduce($linkTypes->issueLinkTypes, function($options, $type) {
$options[$type->name . ':inward'] = $type->inward;
if ($type->outward != $type->inward) {
$options[$type->name . ':outward'] = $type->outward;
}
return $options;
});

include 'tpl.header.php';

echo '<h1><a href="issue.php?key=' . $key . '">' . $key . '</a> ' . html($summary) . '</h1>';

?>
<h2>Create link</h2>

<form autocomplete="off" method="post">
<p>This issue <select name="type"><?= html_options($linkTypeOptions, 'Relates:inward') ?></select></p>
<p>That issue: <input name="issue" placeholder="ABC-123" /></p>
<p><input type="submit" /></p>
</form>

<?php

include 'tpl.footer.php';
Loading

0 comments on commit 6fe3f08

Please sign in to comment.