From d6a64db1ced3d3577886a7aec140a5174cbceb48 Mon Sep 17 00:00:00 2001 From: alexwl Date: Wed, 6 Feb 2019 21:42:29 +0300 Subject: Add identifier search in all indexed packages --- javascript/app/controllers/packages.js | 19 ++++++++- javascript/app/controllers/search.js | 28 +++++++++++++ javascript/app/router.js | 5 ++- javascript/app/routes/packages.js | 3 ++ javascript/app/routes/search.js | 42 ++++++++++++++++++++ javascript/app/styles/app.scss | 14 +++++++ .../components/input-with-autocomplete.hbs | 2 +- javascript/app/templates/package.hbs | 3 +- javascript/app/templates/package/search.hbs | 6 +-- javascript/app/templates/packages.hbs | 24 ++++++++++- javascript/app/templates/search.hbs | 46 ++++++++++++++++++++++ javascript/app/utils/api-urls.js | 3 ++ 12 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 javascript/app/controllers/search.js create mode 100644 javascript/app/routes/search.js create mode 100644 javascript/app/templates/search.hbs (limited to 'javascript/app') diff --git a/javascript/app/controllers/packages.js b/javascript/app/controllers/packages.js index a1724dd..614ecd8 100644 --- a/javascript/app/controllers/packages.js +++ b/javascript/app/controllers/packages.js @@ -1,4 +1,6 @@ import Ember from 'ember'; +import {goToDefinition} from '../utils/go-to-definition'; + export default Ember.Controller.extend({ queryObserver : Ember.observer("query",function() { Ember.run.debounce(this, () => { @@ -8,5 +10,20 @@ export default Ember.Controller.extend({ this.set('packages',packages); }); }, 300); - }) + }), + actions: { + searchIdentifier (query) { + if(query) { + document.title = "Haskell code explorer"; + this.transitionToRoute('search',query); + } + }, + showIdentifier (identifierInfo) { + goToDefinition(this.get('store'), + identifierInfo.locationInfo, + 1,//left mouse button + null); + return false; + } + } }); diff --git a/javascript/app/controllers/search.js b/javascript/app/controllers/search.js new file mode 100644 index 0000000..5d77770 --- /dev/null +++ b/javascript/app/controllers/search.js @@ -0,0 +1,28 @@ +import Ember from 'ember'; +import {goToDefinition} from '../utils/go-to-definition'; + +export default Ember.Controller.extend({ + store : Ember.inject.service('store'), + actions : { + goToDefinition (locationInfo,event) { + goToDefinition(this.get('store'), + locationInfo, + event.which, + null); + return false; + }, + searchIdentifier (query) { + if(query) { + document.title = "Haskell code explorer"; + this.transitionToRoute('search',query); + } + }, + showIdentifier (identifierInfo) { + goToDefinition(this.get('store'), + identifierInfo.locationInfo, + 1,//left mouse button + null); + return false; + } + } +}); diff --git a/javascript/app/router.js b/javascript/app/router.js index f58e9ab..7fce17a 100644 --- a/javascript/app/router.js +++ b/javascript/app/router.js @@ -7,14 +7,15 @@ var Router = Ember.Router.extend({ Router.map(function() { this.route('packages',{path:''}); + this.route('search',{path:'/search/:query'}); this.route('package', {path:'/package/:packageId'}, function() { this.route('show',function() { this.route('file', {path:'*filePath'}, function() { }); }); this.route('search',{path:'/search/:query'}); - }); - this.route('bad-url', { path: '/*badurl' }); + }); + this.route('bad-url', { path: '/*badurl' }); }); export default Router; diff --git a/javascript/app/routes/packages.js b/javascript/app/routes/packages.js index 2bbf9bc..34a454d 100644 --- a/javascript/app/routes/packages.js +++ b/javascript/app/routes/packages.js @@ -9,6 +9,9 @@ export default Ember.Route.extend({ setupController(controller, model) { this._super(controller, model); controller.set('packages',model); + controller.set('createSearchUrlFunction',(query) => { + return urls.globalIdentifiersUrl(query); + }); }, afterModel () { document.title = config.APP.title; diff --git a/javascript/app/routes/search.js b/javascript/app/routes/search.js new file mode 100644 index 0000000..c181c2f --- /dev/null +++ b/javascript/app/routes/search.js @@ -0,0 +1,42 @@ +import Ember from 'ember'; +import {urls} from '../utils/api-urls'; +import {goToDefinition} from '../utils/go-to-definition'; + +export default Ember.Route.extend({ + store : Ember.inject.service('store'), + model (params) { + return { + query: params.query, + url: urls.globalIdentifiersUrl(params.query)+"?per_page=20" + }; + }, + setupController(controller, model) { + this._super(controller, model); + controller.set('createSearchUrlFunction',(query) => { + return urls.globalIdentifiersUrl(query); + }); + }, + afterModel () { + const onmouseup = (event) => { + // This makes links in documentation clickable + if(event.target.dataset.location) { + let location; + try { + location = JSON.parse(event.target.dataset.location); + } catch (e) { + console.log(e); + } + if(location) { + goToDefinition(this.get('store'),location,event.which); + } + } + }; + this._onmouseup = onmouseup; + document.addEventListener('mouseup',onmouseup); + }, + deactivate() { + if(this._onmouseup) { + document.removeEventListener('mouseup',this._onmouseup); + } + } +}); diff --git a/javascript/app/styles/app.scss b/javascript/app/styles/app.scss index bca1dce..a6e322e 100644 --- a/javascript/app/styles/app.scss +++ b/javascript/app/styles/app.scss @@ -135,6 +135,11 @@ li { margin-top:20px; } +.global-identifier-search-form { + max-width:500px; + margin-top:20px; +} + .package-header-filename { white-space: nowrap; } @@ -530,6 +535,14 @@ button { right:0px; } +.global-search-results-content { + position:absolute; + top:80px; + bottom:0px; + left:0px; + right:0px; +} + .search-result { padding:5px; } @@ -557,6 +570,7 @@ button { .identifier-menu-item { margin-right:10px; } + .references-packages { position:absolute; width:230px; diff --git a/javascript/app/templates/components/input-with-autocomplete.hbs b/javascript/app/templates/components/input-with-autocomplete.hbs index eb0100d..1a73c07 100644 --- a/javascript/app/templates/components/input-with-autocomplete.hbs +++ b/javascript/app/templates/components/input-with-autocomplete.hbs @@ -14,6 +14,6 @@ {{/if}}
- +
diff --git a/javascript/app/templates/package.hbs b/javascript/app/templates/package.hbs index 8c6d1a4..5f9fa68 100644 --- a/javascript/app/templates/package.hbs +++ b/javascript/app/templates/package.hbs @@ -7,6 +7,7 @@ createSearchUrlFunction=createSearchUrlFunction maxItems=10 selectItem=(action 'showIdentifier') + searchButtonText="Search" placeholder="Identifier" as |identifier|}} {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}}
@@ -31,7 +32,7 @@
{{/resizable-panel}}
-
+
{{outlet}}
{{#bottom-panel visible=bottomPanelVisible topPanelElementId="#file-container" containerElementId="#right-panel" as |section|}} diff --git a/javascript/app/templates/package/search.hbs b/javascript/app/templates/package/search.hbs index ebc4d52..37b3992 100644 --- a/javascript/app/templates/package/search.hbs +++ b/javascript/app/templates/package/search.hbs @@ -2,11 +2,11 @@ Query : {{model.query}}
- {{#paginated-list url=model.url as |identifiers|}} + {{#paginated-list url=model.url as |identifiers|}}
    {{#each identifiers as |identifier|}} -
  • - {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}} +
  • + {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}}
    {{#if identifier.locationInfo.modulePath}} diff --git a/javascript/app/templates/packages.hbs b/javascript/app/templates/packages.hbs index 6dc4b7b..80464e6 100644 --- a/javascript/app/templates/packages.hbs +++ b/javascript/app/templates/packages.hbs @@ -1,6 +1,26 @@
    -
    - +
    +
    + {{#input-with-autocomplete + onSubmit=(action 'searchIdentifier') + createSearchUrlFunction=createSearchUrlFunction + maxItems=10 + selectItem=(action 'showIdentifier') + searchButtonText="Search in all packages" + placeholder="Haskell identifier" as |identifier|}} + {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}} +
    + {{identifier.locationInfo.packageId.name}}-{{identifier.locationInfo.packageId.version}} + {{#if identifier.locationInfo.modulePath}} + {{identifier.locationInfo.modulePath}} + {{else}} + {{identifier.locationInfo.moduleName}} + {{/if}} +
    + {{/input-with-autocomplete}} +
    +
    +
    {{input class="form-control" type="text" value=query placeholder="Package name"}} Number of packages : {{packages.length}} diff --git a/javascript/app/templates/search.hbs b/javascript/app/templates/search.hbs new file mode 100644 index 0000000..343ce68 --- /dev/null +++ b/javascript/app/templates/search.hbs @@ -0,0 +1,46 @@ +
    +
    +
    +
    + {{#input-with-autocomplete + onSubmit=(action 'searchIdentifier') + createSearchUrlFunction=createSearchUrlFunction + maxItems=10 + selectItem=(action 'showIdentifier') + searchButtonText="Search in all packages" + placeholder="Haskell identifier" as |identifier|}} + {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}} +
    + {{identifier.locationInfo.packageId.name}}-{{identifier.locationInfo.packageId.version}} + {{#if identifier.locationInfo.modulePath}} + {{identifier.locationInfo.modulePath}} + {{else}} + {{identifier.locationInfo.moduleName}} + {{/if}} +
    + {{/input-with-autocomplete}} +
    +
    + Query : {{model.query}} +
    +
    + {{#paginated-list url=model.url as |identifiers|}} +
      + {{#each identifiers as |identifier|}} +
    • + {{identifier.demangledOccName}} :: {{type-signature-text components=identifier.idType.components}} + +
      + {{#if identifier.locationInfo.modulePath}} + Defined in {{identifier.locationInfo.packageId.name}}-{{identifier.locationInfo.packageId.version}} {{identifier.locationInfo.modulePath}} + {{/if}} +
      +
      {{{identifier.doc}}}
      +
    • + {{/each}} +
    + {{/paginated-list}} +
    +
    +
    +
    diff --git a/javascript/app/utils/api-urls.js b/javascript/app/utils/api-urls.js index 2eb2e7c..da8fdcb 100644 --- a/javascript/app/utils/api-urls.js +++ b/javascript/app/utils/api-urls.js @@ -28,5 +28,8 @@ export const urls = { }, globalReferencesUrl : function (externalId) { return config.APP.apiUrlPrefix + "/globalReferences/"+encodeURIComponent(externalId); + }, + globalIdentifiersUrl : function (query) { + return config.APP.apiUrlPrefix + "/globalIdentifiers/"+encodeURIComponent(query).replace(/\./g, '%2E'); } } -- cgit v1.2.3