Skip to content

Commit

Permalink
Merge pull request #27 from fr3nch13/1.x-dev
Browse files Browse the repository at this point in the history
Added the ability to track the refferring url when submitting an issue.
  • Loading branch information
fr3nch13 authored Feb 25, 2020
2 parents 3f54d28 + 8e6f2be commit d4d35fb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ public function add(): ?\Cake\Http\Response
{
$errors = [];
if ($this->getRequest()->is('post')) {
if ($this->JiraForm->execute($this->getRequest()->getData())) {
$data = $this->getRequest()->getData();
if ($this->getRequest()->getQuery()) {
$query = $this->getRequest()->getQuery();
if (isset($query['referer'])) {
$data['referer'] = $query['referer'];
}
}
if ($this->JiraForm->execute($data)) {
$this->Flash->success(__('The {0} has been saved.', [$this->humanName]));

return $this->redirect(['action' => 'thankyou', '?' => ['type' => $this->humanName]]);
Expand Down
10 changes: 6 additions & 4 deletions src/Lib/JiraProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class JiraProject
'type' => 'text',
'required' => true,
],
'details' => [
'description' => [
'type' => 'textarea',
'required' => true,
],
Expand All @@ -119,7 +119,7 @@ class JiraProject
'type' => 'text',
'required' => true,
],
'details' => [
'description' => [
'type' => 'textarea',
'required' => true,
],
Expand All @@ -136,7 +136,7 @@ class JiraProject
'type' => 'text',
'required' => true,
],
'details' => [
'description' => [
'type' => 'textarea',
'required' => true,
],
Expand Down Expand Up @@ -548,7 +548,6 @@ public function submitIssue(string $type, array $data = []): bool
public function buildSubmittedIssue(string $type, array $data = []): \JiraRestApi\Issue\IssueField
{
$typeInfo = $this->getAllowedTypes($type);

// make sure we can get the project info first.
// getInfo will throw an exception if it can't find the project.
// putting a try/catch around it so scrutinizer stops complaining.
Expand All @@ -567,6 +566,9 @@ public function buildSubmittedIssue(string $type, array $data = []): \JiraRestAp
$issueField->setSummary($data['summary']);
}
if (isset($data['description'])) {
if (isset($data['referer'])) {
$data['description'] = __("{0}\n\n-----------\n\nReferer: {1}", [$data['description'], $data['referer']]);
}
$issueField->setDescription($data['description']);
}
if (isset($data['priority'])) {
Expand Down
41 changes: 39 additions & 2 deletions src/Template/Element/nav-links.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* @var \App\View\AppView $this
*/

use Cake\Routing\Router;
?>
<li class="dropdown jira jira-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Expand All @@ -16,14 +18,49 @@
</li>
<li class="jira-body">
<div class="pull-left">
<a href="<?= $this->Url->build(['action' => 'add', 'controller' => 'Bugs', 'plugin' => 'Fr3nch13/Jira', 'prefix' => false]); ?>" class="btn btn-default btn-flat">Bug</a>
<a href="<?= $this->Url->build([
'action' => 'add',
'controller' => 'Bugs',
'plugin' => 'Fr3nch13/Jira',
'prefix' => false,
'?' => [
'referer' => 1,
],
]); ?>" class="jira-link btn btn-default btn-flat">Bug</a>
</div>
<div class="pull-right">
<a href="<?= $this->Url->build(['action' => 'add', 'controller' => 'FeatureRequests', 'plugin' => 'Fr3nch13/Jira', 'prefix' => false]); ?>" class="btn btn-default btn-flat">Feature</a>
<a href="<?= $this->Url->build([
'action' => 'add',
'controller' => 'FeatureRequests',
'plugin' => 'Fr3nch13/Jira',
'prefix' => false,
'?' => [
'referer' => 1,
],
]); ?>" class="jira-link btn btn-default btn-flat">Feature</a>
</div>
<div style="clear: both;"></div>
</li>
<li class="jira-footer">
</li>
</ul>
</li>
<script type="text/javascript">
$(document).ready(function()
{
/**
* This updates the urls for the jira links so the
* submitted issue has an accurate url being reported.
*/
$(window).bind('locationchange', function()
{
$('.jira-menu .jira-body a.jira-link').each(function(e)
{
var $href = $(this).attr('href');
console.log($href);
$href = $href.replace(/\?referer\=.*/, '?referer=' + encodeURI(window.location.href));
$(this).attr('href', $href);
});
});
});
</script>
8 changes: 4 additions & 4 deletions tests/TestCase/Form/AppFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testGetFormData(): void
'type' => 'text',
'required' => true,
],
'details' => [
'description' => [
'type' => 'textarea',
'required' => true,
],
Expand All @@ -112,7 +112,7 @@ public function testSetFormData(): void
'type' => 'text',
'required' => true,
],
'details' => [
'description' => [
'type' => 'textarea',
'required' => true,
],
Expand Down Expand Up @@ -161,7 +161,7 @@ public function testValidate()
$this->assertCount(2, $this->JiraForm->getErrors());
$requestData = [
'summary' => 'TEST SUMMARY',
'details' => 'test details',
'description' => 'test details',
];
$this->assertTrue($this->JiraForm->validate($requestData));
$this->assertCount(0, $this->JiraForm->getErrors());
Expand All @@ -176,7 +176,7 @@ public function testExecute(): void
{
$requestData = [
'summary' => 'TEST SUMMARY',
'details' => 'test details',
'description' => 'test details',
];

$result = $this->JiraForm->execute($requestData);
Expand Down

0 comments on commit d4d35fb

Please sign in to comment.