Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
search issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sap committed Jan 30, 2017
1 parent 48a32eb commit fe8ccbc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 24 deletions.
59 changes: 38 additions & 21 deletions app/addressbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,47 @@ const Config = require('electron-config');
const config = new Config();
const starsDB = require('../db/stars');

let isReady = false, el, starBox, lastShortUrl = '', lastFullUrl = '', lastIssue = '';
let isReady = false, el, starBox, lastShortUrl = '', lastFullUrl = '', lastIssue = '',
searchTerm = null;

const baseUrl = $.rtrim(config.get('baseUrl'), '/');
const repoToSearch = config.get('repoToSearch');


function getUnfocusedText () {
if (searchTerm) return searchTerm;
if (!lastIssue || !lastIssue.name) return lastShortUrl || '';
const mod = lastIssue.repo.split('/').pop();
return `${mod} / ${lastIssue.name}`;
}

function getFocusedText () {
if (searchTerm) return searchTerm;
return lastFullUrl;
}


// BaseURL/Group/RepoName/issues?q=is:open is:issue...
function getSearchUrl (q) {
const query = 'issues?q=is:open is:issue ' + q;
return [baseUrl, repoToSearch, query].join('/');
}


function gotoUrl (url) {
searchTerm = null;

if (url) el[0].value = url;
url = el[0].value.trim();

const validUrl = isValidUrl(url);
if (!validUrl) url = config.get('baseUrl') + parseAnyAddress(url);
starBox.addClass('disabled');

// $.trigger('hide-connection-error');
if (!validUrl) { // not a URL - do search
searchTerm = url;
url = getSearchUrl(url);
}

starBox.addClass('disabled');
if (url) $.trigger('frame/goto', url);
$.trigger('address-input-end');
}
Expand All @@ -33,22 +56,9 @@ function isValidUrl (url) {
}


function parseAnyAddress (url) {
url = shortenUrl(url);
const parts = url.split('/');
let id;
url = '';
if (parts.length > 2) id = parts.pop();
if (parts.length > 1) {
url = parts.join('/');
if (id === 'issues') id = '/';
if (id) url += `/issues/${id}`;
}
return $.rtrim(url, '/');
}


function onUrlChanged (webview, issue) {
if (issue) searchTerm = null;

lastFullUrl = config.get('state.url');
lastShortUrl = shortenUrl(lastFullUrl);
lastIssue = issue || {};
Expand All @@ -65,6 +75,13 @@ function onUrlChanged (webview, issue) {


function shortenUrl (url = '') {
if (url.indexOf('?q=') > -1) { // it's search url
return searchTerm = url
.split('?q=').pop()
.replace(/is(:|%3A)(issue|open|closed)/g, '')
.replace(/(%20|\+)/g, ' ')
.trim();
}
return url
.replace(config.get('baseUrl'), '')
.replace('pull/', '')
Expand All @@ -80,7 +97,7 @@ function focusAddressbar () {


function onFocus () {
el[0].value = lastFullUrl;
el[0].value = getFocusedText();
el[0].select();
}

Expand All @@ -95,7 +112,7 @@ function onKeyPress (e) {
function onKeyDown (e) {
if (e.key === 'ArrowDown') return $.trigger('focus-address-results');
if (e.key === 'Escape') {
e.target.value = lastFullUrl;
e.target.value = getFocusedText();
e.target.select();
$.trigger('address-input-end');
}
Expand Down
9 changes: 8 additions & 1 deletion app/db/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ function getById (_id) {


function find (txt) {
const ltxt = txt.toLowerCase();
return get().then(items => {
return items.filter(item => $.fuzzy(item.name, txt));
return items
.filter(item => $.fuzzy(item.name, txt))
.sort((a, b) => {
const bv = b.name.toLowerCase().indexOf(ltxt);
const av = a.name.toLowerCase().indexOf(ltxt);
return bv - av;
});
});
}

Expand Down
4 changes: 3 additions & 1 deletion app/settings/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
.settings-buttons { margin: 20px 0 0 0; text-align: right; }
.settings-buttons .btn { font-size: 13px; }
.settings-buttons .btn-left { float: left; }
.settings-buttons .btn-save { font-weight: bold; }
.settings-buttons .btn-save { font-weight: bold; }

.settings-info-text { font-size: 11px; color: #999; margin-left: 146px; }
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ <h1>Notifications

<section id="frame"></section>




<section class="settings">
<h1>Preferences</h1>
<form class="settings-form">

<label>Base URL: <input name="baseUrl" required></label>

<label>Home button URL: <input name="homeUrl" placeholder="Defaults to Base URL"></label>

<label>Repo to search: <input name="repoToSearch" placeholder="Just Group/RepoName"></label>
<span class="settings-info-text">BaseURL/<b>Group/RepoName</b>/issues?q=is:open is:issue...</span>
<span class="settings-info-text">e.g. https://github.com/<b>angular/angular</b>/issues?q=is:open is:issue...</span>

<div class="settings-buttons">
<a href="#" class="btn btn-left btn-folder" data-go="folder">Open settings folder</a>
<button class="btn btn-cancel" data-go="cancel" type="button">Cancel</button>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "github-browser",
"productName": "Github Browser",
"description": "Github browser.",
"version": "0.5.0",
"version": "0.6.0",
"main": "index.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit fe8ccbc

Please sign in to comment.