Skip to content

Commit 36861f2

Browse files
committed
Initial commit
0 parents  commit 36861f2

10 files changed

Lines changed: 295 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nbproject/

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# MantisBT SearchRelatedIssue Plugin
2+
3+
[![Join the chat at https://gitter.im/mantisbt-plugins/SearchRelatedIssue](https://badges.gitter.im/mantisbt-plugins/SearchRelatedIssue.svg)](https://gitter.im/mantisbt-plugins/SearchRelatedIssue?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
5+
Overview
6+
--------
7+
The plugin implements a live search for related issues during the creation of a new issue.
8+
9+
Screenshots
10+
-----------
11+
12+
![alt text](doc/SearchRelatedIssue.png)
13+
14+
Download
15+
--------
16+
Please download the stable version.
17+
(https://github.com/mantisbt-plugins/SearchRelatedIssue/releases/latest)
18+
19+
20+
How to install
21+
--------------
22+
23+
1. Copy SearchRelatedIssue folder into plugins folder.
24+
2. Open Mantis with browser.
25+
3. Log in as administrator.
26+
4. Go to Manage -> Manage Plugins.
27+
5. Find SearchRelatedIssue in the list.
28+
6. Click Install.
29+
30+
Supported Versions
31+
------------------
32+
33+
- MantisBT 2.0 and higher - supported
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
# Copyright (c) 2019 brlumen (igflocal@gmail.com)
4+
# SearchRelatedIssue for MantisBT is free software:
5+
# you can redistribute it and/or modify it under the terms of the GNU
6+
# General Public License as published by the Free Software Foundation,
7+
# either version 2 of the License, or (at your option) any later version.
8+
#
9+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
10+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
11+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
# See the GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with SearchRelatedIssue plugin for MantisBT.
16+
# If not, see <http://www.gnu.org/licenses/>.
17+
18+
class SearchRelatedIssuePlugin extends MantisPlugin {
19+
20+
public function register() {
21+
$this->name = 'SearchRelatedIssue';
22+
$this->description = plugin_lang_get( 'description' );
23+
24+
$this->version = '1.0.0';
25+
$this->requires = array(
26+
'MantisCore' => '2.0.0',
27+
);
28+
29+
$this->author = 'brlumen';
30+
$this->contact = 'igflocal@gmail.com';
31+
$this->url = 'http://github.com/mantisbt-plugins/SearchRelatedIssue';
32+
// $this->page = 'config_page';
33+
}
34+
35+
function hooks() {
36+
return array(
37+
'EVENT_LAYOUT_RESOURCES' => 'resources',
38+
);
39+
}
40+
41+
function resources() {
42+
43+
$t_page = array_key_exists( 'REQUEST_URI', $_SERVER ) ? basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) : basename( __FILE__ );
44+
if( $t_page == 'bug_report_page.php' ) {
45+
return '<link rel="stylesheet" type="text/css" href="' . plugin_file( 'related_search_240520191349.css' ) . '"></link>' .
46+
'<script type="text/javascript" src="' . plugin_file( 'related_search.js' ) . '"></script>';
47+
}
48+
}
49+
50+
}
673 Bytes
Loading
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
# Copyright (c) 2018 brlumen (igflocal@gmail.com)
3+
# SearchRelatedIssue for MantisBT is free software:
4+
# you can redistribute it and/or modify it under the terms of the GNU
5+
# General Public License as published by the Free Software Foundation,
6+
# either version 2 of the License, or (at your option) any later version.
7+
#
8+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
9+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with SearchRelatedIssue plugin for MantisBT.
15+
# If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
var display_request = 0;
18+
var current_request = 0;
19+
var loading_img;
20+
var summary_input;
21+
22+
$(document).ready(function () {
23+
24+
$('[name=summary]').after('<li id="loader_area" style="list-style-type: none;" hidden=""><img id="loading_img" src="/plugin_file.php?file=SearchRelatedIssue/ajax-loader.gif"></li>');
25+
loading_img = document.getElementById('loader_area');
26+
27+
summary_input = document.getElementsByName('summary')[0];
28+
var bug_report_token = document.getElementsByName('bug_report_token')[0];
29+
30+
if (summary_input.value.length > 0) {
31+
search_request(summary_input.value, bug_report_token.value);
32+
}
33+
var current_timer = 0;
34+
$('[name=summary]').bind("input", function () {
35+
if (this.value.length > 0 && this.value.trim() != 0) {
36+
37+
loading_img.removeAttribute('hidden');
38+
clearTimeout(current_timer);
39+
var search_string = this.value;
40+
var token = $('[name=bug_report_token]').val();
41+
current_timer = setTimeout(function () {
42+
search_request(search_string, token);
43+
}, 700);
44+
}
45+
46+
if (summary_input.value.length < 1) {
47+
$(".search_result").remove();
48+
}
49+
})
50+
});
51+
52+
function search_request(search_string, token) {
53+
current_request++;
54+
$.ajax({
55+
type: 'post',
56+
url: '/plugin.php?page=SearchRelatedIssue/search',
57+
data: {
58+
'referal': search_string,
59+
'bug_report_token': token,
60+
'request_id': current_request,
61+
},
62+
response: 'text',
63+
success: function (data, textStatus, jqXHR) {
64+
try {
65+
var response = JSON.parse(data);
66+
if (response['request_id'] > display_request) {
67+
$(".search_result").remove();
68+
$('[id=loader_area]').after(response['data']);
69+
display_request = response['request_id'];
70+
}
71+
} catch (err) {
72+
console.log(err);
73+
}
74+
if (summary_input.value.length < 1) {
75+
$(".search_result").remove();
76+
}
77+
loading_img.setAttribute('hidden', '');
78+
}
79+
})
80+
}
81+
82+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
# Copyright (c) 2019 brlumen (igflocal@gmail.com)
3+
# SearchRelatedIssue for MantisBT is free software:
4+
# you can redistribute it and/or modify it under the terms of the GNU
5+
# General Public License as published by the Free Software Foundation,
6+
# either version 2 of the License, or (at your option) any later version.
7+
#
8+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
9+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with SearchRelatedIssue plugin for MantisBT.
15+
# If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
.search_result{
19+
background: #FFF;
20+
border: 1px #ccc solid;
21+
max-height:400px;
22+
overflow-y:auto;
23+
margin: 0 0 0 0;
24+
margin-top: 2px;
25+
}
26+
27+
.search_result a{
28+
display: block;
29+
margin: 3px 3px;
30+
padding: 7px;
31+
font-size: 12px;
32+
text-decoration: none;
33+
color: inherit;
34+
cursor: pointer;
35+
border-radius: 3px;
36+
overflow-y: hidden;
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
# Copyright (c) 2019 brlumen (igflocal@gmail.com)
3+
# SearchRelatedIssue for MantisBT is free software:
4+
# you can redistribute it and/or modify it under the terms of the GNU
5+
# General Public License as published by the Free Software Foundation,
6+
# either version 2 of the License, or (at your option) any later version.
7+
#
8+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
9+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with SearchRelatedIssue plugin for MantisBT.
15+
# If not, see <http://www.gnu.org/licenses/>.
16+
17+
$s_plugin_SearchRelatedIssue_header_related_issue_list = 'The following %1$s might be related.';
18+
$s_plugin_SearchRelatedIssue_description = 'The plugin implements a live search for related issues during the creation of a new issue.';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
# Copyright (c) 2019 brlumen (igflocal@gmail.com)
3+
# SearchRelatedIssue for MantisBT is free software:
4+
# you can redistribute it and/or modify it under the terms of the GNU
5+
# General Public License as published by the Free Software Foundation,
6+
# either version 2 of the License, or (at your option) any later version.
7+
#
8+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
9+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
# See the GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with SearchRelatedIssue plugin for MantisBT.
15+
# If not, see <http://www.gnu.org/licenses/>.
16+
17+
$s_plugin_SearchRelatedIssue_header_related_issue_list = 'Найдены похожие %1$s.';
18+
$s_plugin_SearchRelatedIssue_description = 'Плагин реализует живой поиск похожих задач во время создания новой задачи.';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
# Copyright (c) 2019 brlumen (igflocal@gmail.com)
4+
# SearchRelatedIssue for MantisBT is free software:
5+
# you can redistribute it and/or modify it under the terms of the GNU
6+
# General Public License as published by the Free Software Foundation,
7+
# either version 2 of the License, or (at your option) any later version.
8+
#
9+
# SearchRelatedIssue plugin for for MantisBT is distributed in the hope
10+
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
11+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
# See the GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with SearchRelatedIssue plugin for MantisBT.
16+
# If not, see <http://www.gnu.org/licenses/>.
17+
18+
19+
form_security_validate( 'bug_report' );
20+
21+
$t_filter = filter_create_any();
22+
23+
$t_filter['search'] = gpc_get_string( 'referal' );
24+
25+
$t_request_id = gpc_get_int( 'request_id' );
26+
27+
$t_current_project = helper_get_current_project();
28+
29+
$t_filter['project_id'][0] = $t_current_project;
30+
31+
$t_per_page = null;
32+
$t_bug_count = null;
33+
$t_page_count = null;
34+
35+
$t_rows = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true );
36+
37+
$t_response['request_id'] = $t_request_id;
38+
$t_response['data'] = '';
39+
40+
if( count( $t_rows ) > 0 ) {
41+
42+
$t_response['data'] = '<ul class="search_result">';
43+
$t_response['data'] .= '<li style="margin-left: 5px; margin-top: 5px; margin-bottom: 5px;">' . sprintf( plugin_lang_get( 'header_related_issue_list' ), lang_get( 'issues' ) ) . '</li>';
44+
45+
foreach( $t_rows as $t_issue ) {
46+
$t_response['data'] .= '<li>' .
47+
'<a class=search_result style="background-color:' . get_status_color( $t_issue->status ) . ';" href="' . string_get_bug_view_url( $t_issue->id ) . '";>' . $t_issue->id . ": " . $t_issue->summary . '</a></li>';
48+
}
49+
50+
$t_response['data'] .= '</ul>';
51+
}
52+
53+
$t_response_json = json_encode( $t_response );
54+
55+
echo $t_response_json;
56+

doc/SearchRelatedIssue.png

24.4 KB
Loading

0 commit comments

Comments
 (0)