From fe8ccbc02a843d61f137cfea140655411b6c5656 Mon Sep 17 00:00:00 2001 From: Tomasz Borychowski Date: Mon, 30 Jan 2017 14:16:04 +0000 Subject: [PATCH] search issues --- app/addressbar/index.js | 59 ++++++++++++++++++++++++++--------------- app/db/history.js | 9 ++++++- app/settings/index.css | 4 ++- index.html | 10 +++++++ package.json | 2 +- 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/app/addressbar/index.js b/app/addressbar/index.js index b704942..cd1e985 100644 --- a/app/addressbar/index.js +++ b/app/addressbar/index.js @@ -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'); } @@ -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 || {}; @@ -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/', '') @@ -80,7 +97,7 @@ function focusAddressbar () { function onFocus () { - el[0].value = lastFullUrl; + el[0].value = getFocusedText(); el[0].select(); } @@ -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'); } diff --git a/app/db/history.js b/app/db/history.js index c1391ff..93bcbf8 100644 --- a/app/db/history.js +++ b/app/db/history.js @@ -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; + }); }); } diff --git a/app/settings/index.css b/app/settings/index.css index f05ef2c..e5ca2d4 100644 --- a/app/settings/index.css +++ b/app/settings/index.css @@ -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; } \ No newline at end of file +.settings-buttons .btn-save { font-weight: bold; } + +.settings-info-text { font-size: 11px; color: #999; margin-left: 146px; } \ No newline at end of file diff --git a/index.html b/index.html index 67ebe5f..7eacb9e 100755 --- a/index.html +++ b/index.html @@ -65,11 +65,21 @@

Notifications
+ + +

Preferences

+ + + + + BaseURL/Group/RepoName/issues?q=is:open is:issue... + e.g. https://github.com/angular/angular/issues?q=is:open is:issue... +
Open settings folder diff --git a/package.json b/package.json index eb4a654..70ed4c3 100644 --- a/package.json +++ b/package.json @@ -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",