Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple jiras #602

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ li {

input[type='text'].quiji-options-jira-url {
margin-top: 3px;
margin-bottom: 5px;
min-height: 2em;
padding-left: 6px;
width: 100%;
Expand Down
13 changes: 12 additions & 1 deletion html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ <h3 data-i18n="baseURL"></h3>
>
</span>
</p>
<input type="text" class="quiji-options-jira-url" required />
<input type="text" class="company-id" required placeholder="ID"/>
<input type="text" class="quiji-options-jira-url" required placeholder="https://"/>

<input type="text" class="company-id" placeholder="ID"/>
<input type="text" class="quiji-options-jira-url" placeholder="https://"/>

<input type="text" class="company-id" placeholder="ID"/>
<input type="text" class="quiji-options-jira-url" placeholder="https://"/>

<input type="text" class="company-id" placeholder="ID"/>
<input type="text" class="quiji-options-jira-url" placeholder="https://"/>

<h3 data-i18n="defaultAction"></h3>
<p data-i18n="defaultActionDescription"></p>
<select name="default option">
Expand Down
6 changes: 6 additions & 0 deletions html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<p>
<label>
<strong>Ticket ID</strong>
<select name="company" class="company-selector">
<option class="company-options" value="0"></option>
<option class="company-options" value="1"></option>
<option class="company-options" value="2"></option>
<option class="company-options" value="3"></option>
</select>
<input type="text" size="50" class="quiji-ticket-id" id="quiji-ticket-id" autofocus required />
</label>
</p>
Expand Down
6 changes: 4 additions & 2 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
const _browser = this.browser || this.chrome;
const storage = _browser.storage.sync || _browser.storage.local;

var openTicket = (ticket, newTab) => {
var openTicket = (ticket, newTab, company) => {
storage.get(
{
jiraURL: '',
trimSpaces: 0,
},
(options) => {
const jiraURL = options && options.jiraURL;
const jiraUrlArray = parseInt(company)
const jiraURL = options && options.jiraURL[jiraUrlArray];

const trimSpaces = options && options.trimSpaces !== 0;
let newURL;

Expand Down
33 changes: 29 additions & 4 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ const storage = _browser.storage.sync || _browser.storage.local;
const saveOptions = (event) => {
event.preventDefault();
const status = document.querySelector('.quiji-options-status');
const jira = document.querySelector('.quiji-options-jira-url').value;
if (!urlPattern.test(jira)) {
const jira = document.querySelectorAll('.quiji-options-jira-url');
const jiraCompanies = document.querySelectorAll('.company-id');

let invalidUrl = false
for (const urls of jira) {
if (urls.value) {
invalidUrl = !urlPattern.test(urls.value) ? true : invalidUrl
}
}

if (invalidUrl) {
status.textContent = _browser.i18n.getMessage('validURL');
} else {
let defaultOption = document.querySelector('select').value;
Expand All @@ -20,9 +29,17 @@ const saveOptions = (event) => {

const trimSpaces = document.querySelector('#trim-spaces').checked ? 1 : 0;

let allJira = []
let allJiraCompanies = []
for (let i = 0; i < jira.length; i++) {
allJira.push(jira[i].value)
allJiraCompanies.push(jiraCompanies[i].value)
}

storage.set(
{
jiraURL: jira,
jiraURL: allJira,
jiraCompanyIds: allJiraCompanies,
defaultOption,
trimSpaces,
},
Expand All @@ -41,11 +58,19 @@ const restoreOptions = () => {
storage.get(
{
jiraURL: '',
jiraCompanyIds: '',
defaultOption: 0,
trimSpaces: 0,
},
(options) => {
document.querySelector('.quiji-options-jira-url').value = (options && options.jiraURL) || '';
//for each load options here.
let allJiraLinks = options.jiraURL
let allLinkNodes = document.querySelectorAll('.quiji-options-jira-url')
let allCompanyNodes = document.querySelectorAll('.company-id')
for (let i = 0; i < allJiraLinks.length; i++) {
allLinkNodes[i].value = allJiraLinks[i] || ''
allCompanyNodes[i].value = options.jiraCompanyIds[i] || ''
}
// Map 0 to currentTab and 1 to newTab
let defaultOption = _browser.i18n.getMessage('currentTab');
if (options && options.defaultOption === 1) {
Expand Down
30 changes: 26 additions & 4 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ const handleSubmit = (event) => {
event.preventDefault();
}
const ticket = encodeURIComponent(document.querySelector('.quiji-ticket-id').value);
if (ticket) {
window.setTimeout(() => window.close(), 1000);
_browser.extension.getBackgroundPage().openTicket(ticket, event.target.newTab);
}
const company = document.querySelector('.company-selector').value
storage.set(
{
jiraLastUsed: company,
},
() => {
if (ticket) {
window.setTimeout(() => window.close(), 1000);
_browser.extension.getBackgroundPage().openTicket(ticket, event.target.newTab, company);
}
//? maybe storing last option should be an option
}
);
};

const handleLastTicket = (event, defaultOption, lastTicket) => {
Expand All @@ -25,6 +34,8 @@ const renderDialog = () => {
storage.get(
{
defaultOption: 0,
jiraCompanyIds: '',
jiraLastUsed: '',
lastTicket: '',
},
(options) => {
Expand All @@ -34,6 +45,17 @@ const renderDialog = () => {
const currentButton = document.querySelector('.quiji-current-tab');
currentButton.newTab = false;

//render company options
let allCompanyOptions = document.querySelectorAll('.company-options')
for (let i = 0; i < allCompanyOptions.length; i++) {
allCompanyOptions[i].innerHTML = options.jiraCompanyIds[i] || `Jira ${i+1}`
}

//on first run, options.jiraLastUsed may be null
if (options.jiraLastUsed){
const jiraCompany = parseInt(options.jiraLastUsed)
document.querySelectorAll('.company-options')[jiraCompany].setAttribute('selected', '')
}
const lastTicketButton = createLastTicketButton(options);

form.addEventListener('submit', handleSubmit);
Expand Down