Commit d22eed97 authored by Yaroslav Lushnikov's avatar Yaroslav Lushnikov 🦆

Fast search 1 step

parent c6c68c88
<!DOCTYPE html>
<html>
<head><title>PM Tools settings</title></head>
<body>
API key: <input id="api_key" type="text" placeholder="Enter your api key"/>
<div id="status"></div>
<button id="save">Save</button>
<script src="settings.js">
</script>
</body>
</html>
\ No newline at end of file
function save_options() {
var apiKey = document.getElementById('api_key').value;
chrome.storage.sync.set({
apiKey: apiKey,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
function restore_options() {
// Use default value color = 'red' and likesColor = true.
chrome.storage.sync.get({
apiKey: '',
}, function(items) {
document.getElementById('api_key').value = items.apiKey;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"64": "images/logo_square.png", "64": "images/logo_square.png",
"128": "images/logo_square.png" "128": "images/logo_square.png"
}, },
"options_page": "html/settings.html",
"content_scripts": [ "content_scripts": [
{ {
"matches": [ "matches": [
...@@ -20,22 +21,13 @@ ...@@ -20,22 +21,13 @@
"scripts/pm/branch.js", "scripts/pm/branch.js",
"scripts/pm/commit_message.js", "scripts/pm/commit_message.js",
"scripts/pm/prepare_assigment.js", "scripts/pm/prepare_assigment.js",
"scripts/pm/adyax_issue.js",
"scripts/pm/workflow.js", "scripts/pm/workflow.js",
"scripts/pm/select2.js" "scripts/pm/select2.js",
"scripts/pm/search.js"
], ],
"css" : [ "css" : [
"libraries/select2/select2.css" "libraries/select2/select2.css",
] "styles/i20/search.css"
},
{
"matches": [
"https://*.adyax.com/*"
],
"js": [
"libraries/jQuery/jQuery.js",
"libraries/jScroll/jscroll.js",
"scripts/prj.adyax/commit_message.js"
] ]
}, },
{ {
...@@ -49,7 +41,8 @@ ...@@ -49,7 +41,8 @@
} }
], ],
"permissions": [ "permissions": [
"clipboardWrite" "clipboardWrite",
"storage"
], ],
"browser_action": { "browser_action": {
"default_icon": "images/logo_square.png", "default_icon": "images/logo_square.png",
......
(function($) {
var issueTitle = $('body.controller-issues.action-show').find('.subject h3');
if (issueTitle.length) {
var regex = new RegExp('^#[0-9]{1,7}');
var searchResult = issueTitle.html().match(regex);
if (searchResult) {
var issueNum = searchResult[0].replace('#', '');
var link = "<a href='https://prj.adyax.com/issues/" + issueNum + "' target='_blank'>#" + issueNum + '</a>';
var newIssueTitle = issueTitle.html().replace(searchResult[0], link);
issueTitle.html(newIssueTitle);
}
}
})(jQuery);
(function($) {
window.pmSearch = window.pmSearch || {};
let search = window.pmSearch;
search.init = function() {
// init key
search.getApiKey();
search.timers = {};
search.selected = {};
search.wrapper = $('<div class="pm-tools-search-wrapper hide-form"><div class="search-form"><input type="text" /><ul class="found"></ul></div></div>');
search.input = search.wrapper.find('input');
search.found = search.wrapper.find('.found');
$('#wrapper').append(search.wrapper);
$('body').bind('keydown', function(event) {
if (search.wrapper.hasClass('hide-form') &&
(event.altKey === true && (event.keyCode === 68 || event.keyCode === 206))) {
search.showForm();
event.preventDefault();
}
else if(!search.wrapper.hasClass('hide-form')) {
if(event.keyCode === 27 || (event.altKey === true && (event.keyCode === 68 || event.keyCode === 206))) {
search.closeForm();
event.preventDefault();
}
}
});
search.input.on('keyup', function() {
let $this = $(this);
if (search.timers.change) {
clearTimeout(search.timers.change);
}
search.timers.change = setTimeout(function () {
search.searchValue($this.val());
}, 100);
});
};
search.showForm = function() {
search.input.val('');
search.found.html('');
search.wrapper.removeClass('hide-form');
search.input.focus();
};
search.closeForm = function() {
search.wrapper.addClass('hide-form');
};
search.searchValue = function(searchText) {
if (searchText !== '') {
searchText = searchText.replace(' ', '+');
let key = search.getApiKey();
if (key) {
$.ajax({
url: "https://pm.i20.biz/issues.json?limit=10&subject=~" + searchText,
data: {"": key},
dataType: 'json',
beforeSend: function(xhr){xhr.setRequestHeader('X-Redmine-API-Key', key);},
success: function (data) {
if (data && data.total_count) {
search.found.html('');
data.issues.forEach(function(element) {
let issue = $('<li><a href="https://pm.i20.biz/issues/' + element.id + '">'
+ '<div class="found-issue">'
+ element.subject
+'</div>'
+ '</a></li>'
)
search.found.append(issue);
});
}
},
async: true
})
}
}
}
search.getApiKey = function() {
if (typeof search.apiKey == 'undefined') {
chrome.storage.sync.get('apiKey', function(value) {search.apiKey = value.apiKey });
}
return search.apiKey;
}
search.init();
})(jQuery);
(function ($) {
var subject = $('.subject h3');
var button = $("<button>Commit message</button>");
$('#sidebar').append(button);
button.on('click', function (e) {
var issueId = window.location.pathname.split('/')[2];
var commitMessage = 'refs #' + issueId + ' ' + subject.html();
var textfield = $('<input type="text" style="display: block;" value="' + commitMessage.replace(/"/g, '&quot;') + '">');
subject.after(textfield);
textfield.select();
document.execCommand('copy');
textfield.remove();
});
button.jScroll({top: 50});
$(document).trigger('scroll');
})(jQuery);
.pm-tools-search-wrapper {
width: 100%;
position: absolute;
top: 20%;
z-index: 500;
display: flex;
justify-content: center;
}
.pm-tools-search-wrapper .search-form {
background-color: #cccccc;
padding-bottom: 15px;
border-radius: 7px;
pointer-events: auto;
}
.pm-tools-search-wrapper.hide-form {
display: none;
}
.pm-tools-search-wrapper ul {
list-style: none;
width: 400px;
padding: 5px;
overflow: hidden;
}
.pm-tools-search-wrapper div.found-issue:hover {
background-color: rgb(142, 142, 142);
}
.pm-tools-search-wrapper input {
width: 400px;
height: 30px;
font-size: x-large;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment