- Timestamp:
- 03/10/15 14:16:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUAggregator/trunk/src/main/resources/assets/js/search.js
r6081 r6092 2 2 (function() { 3 3 "use strict"; 4 5 var NO_MORE_RECORDS_DIAGNOSTIC_URI = "info:srw/diagnostic/1/61"; 4 6 5 7 window.MyAggregator = window.MyAggregator || {}; … … 65 67 corpus.priority = 1; // used for ordering search results in corpus view 66 68 corpus.index = index; // original order, used for stable sort 67 });68 this.recurse(function(corpus, index) {69 if (corpus.institution.link > 1) {70 corpus.selected = false;71 }72 69 }); 73 70 } … … 180 177 181 178 nohits: { 182 requests: [], 183 results: [], 179 results: null, 184 180 }, 185 181 anyLanguage: [multipleLanguageCode, "Any Language"], … … 249 245 }); 250 246 }, 247 nextResults: function(corpusId) { 248 // console.log("searching next results in corpus:", corpusId); 249 this.props.ajax({ 250 url: 'rest/search/'+this.state.searchId, 251 type: "POST", 252 data: { 253 corpusId: corpusId, 254 numberOfResults: this.state.numberOfResults, 255 }, 256 success: function(searchId, textStatus, jqXHR) { 257 // console.log("search ["+query+"] ok: ", searchId, jqXHR); 258 var timeout = 250; 259 setTimeout(this.refreshSearchResults, timeout); 260 this.setState({ searchId: searchId, timeout: timeout }); 261 }.bind(this), 262 }); 263 }, 251 264 252 265 refreshSearchResults: function() { … … 258 271 success: function(json, textStatus, jqXHR) { 259 272 var timeout = this.state.timeout; 260 if (json. requests.length > 0) {273 if (json.inProgress) { 261 274 if (timeout < 10000) { 262 275 timeout = 1.5 * timeout; … … 267 280 console.log("search ended; hits:", json); 268 281 } 269 this.setState({ hits: json, timeout: timeout }); 282 var corpusHit = this.state.zoomedCorpusHit; 283 if (corpusHit) { 284 for (var resi = 0; resi < json.results.length; resi++) { 285 var res = json.results[resi]; 286 if (res.corpus.id === corpusHit.corpus.id) { 287 corpusHit = res; 288 break; 289 } 290 } 291 } 292 this.setState({ hits: json, timeout: timeout, zoomedCorpusHit: corpusHit}); 270 293 }.bind(this), 271 294 }); … … 293 316 this.state.corpora.setVisibility(this.state.searchLayerId, 294 317 languageFilter === 'byGuess' ? multipleLanguageCode : languageObj[0]); 295 this.setState({language: languageObj, languageFilter: languageFilter}); 296 this.state.corpora.update(); 318 this.setState({ 319 language: languageObj, 320 languageFilter: languageFilter, 321 corpora: this.state.corpora, // === this.state.corpora.update(); 322 }); 297 323 }, 298 324 299 325 setLayer: function(layerId) { 300 326 this.state.corpora.setVisibility(layerId, this.state.language[0]); 301 this.state.corpora.update(); 302 this.setState({searchLayerId: layerId}); 327 this.setState({ 328 searchLayerId: layerId, 329 hits: this.nohits, 330 searchId: null, 331 corpora: this.state.corpora, // === this.state.corpora.update(); 332 }); 303 333 }, 304 334 … … 319 349 var noLangFiltering = this.state.languageFilter === 'byMeta'; 320 350 var langCode = this.state.language[0]; 321 return this.state.hits.results.map(function(corpusHit) { 322 return { 323 corpus: corpusHit.corpus, 324 startRecord: corpusHit.startRecord, 325 endRecord: corpusHit.endRecord, 326 exception: corpusHit.exception, 327 diagnostics: corpusHit.diagnostics, 328 searchString: corpusHit.searchString, 329 kwics: noLangFiltering ? corpusHit.kwics : 330 corpusHit.kwics.filter(function(kwic) { 331 return kwic.language === langCode || langCode === multipleLanguageCode || langCode === null; 332 }), 333 }; 334 }); 351 var results = null, inProgress = 0, hits = 0; 352 if (this.state.hits.results) { 353 results = this.state.hits.results.map(function(corpusHit) { 354 return { 355 corpus: corpusHit.corpus, 356 inProgress: corpusHit.inProgress, 357 exception: corpusHit.exception, 358 diagnostics: corpusHit.diagnostics, 359 kwics: noLangFiltering ? corpusHit.kwics : 360 corpusHit.kwics.filter(function(kwic) { 361 return kwic.language === langCode || 362 langCode === multipleLanguageCode || 363 langCode === null; 364 }), 365 }; 366 }); 367 for (var i = 0; i < results.length; i++) { 368 var result = results[i]; 369 if (result.inProgress) { 370 inProgress++; 371 } 372 if (result.kwics.length > 0) { 373 hits ++; 374 } 375 } 376 } 377 return { 378 results: results, 379 hits: hits, 380 inProgress: inProgress, 381 }; 335 382 }, 336 383 … … 354 401 }, 355 402 356 handleChange: function(event) {403 onQuery: function(event) { 357 404 this.setState({query: event.target.value}); 358 405 }, … … 377 424 }, 378 425 379 render Aggregator: function() {426 render: function() { 380 427 var layer = layerMap[this.state.searchLayerId]; 381 428 return ( … … 390 437 React.createElement("input", {className: "form-control input-lg search", name: "query", type: "text", 391 438 value: this.state.query, placeholder: this.props.placeholder, 392 tabIndex: "1", onChange: this. handleChange, onKeyDown: this.handleKey}),439 tabIndex: "1", onChange: this.onQuery, onKeyDown: this.handleKey}), 393 440 React.createElement("div", {className: "input-group-btn"}, 394 441 React.createElement("button", {className: "btn btn-default input-lg", type: "button", onClick: this.search}, … … 467 514 React.createElement(Modal, {ref: "resultModal", title: this.renderZoomedResultTitle(this.state.zoomedCorpusHit)}, 468 515 React.createElement(ZoomedResult, {corpusHit: this.state.zoomedCorpusHit, 516 nextResults: this.nextResults, 469 517 getDownloadLink: this.getDownloadLink, 470 518 getToWeblichtLink: this.getToWeblichtLink, … … 475 523 476 524 React.createElement("div", {className: "top-gap"}, 477 React.createElement(Results, {requests: this.state.hits.requests, 478 results: this.filterResults(), 525 React.createElement(Results, {collhits: this.filterResults(), 479 526 toggleResultModal: this.toggleResultModal, 480 527 getDownloadLink: this.getDownloadLink, … … 485 532 ); 486 533 }, 487 render: function() {488 return this.renderAggregator();489 }490 534 }); 491 535 … … 622 666 }, 623 667 624 renderDiagnostic: function(d) { 625 return React.createElement("div", {className: "alert alert-warning", key: d.uri}, 668 renderDiagnostic: function(d, key) { 669 if (d.uri === NO_MORE_RECORDS_DIAGNOSTIC_URI) { 670 return false; 671 } 672 return React.createElement("div", {className: "alert alert-warning", key: key}, 626 673 React.createElement("div", null, "Diagnostic: ", d.message) 627 674 ); … … 632 679 return false; 633 680 } 634 635 681 return corpusHit.diagnostics.map(this.renderDiagnostic); 636 682 }, … … 714 760 React.createElement("li", null, 715 761 error ? 716 React.createElement("div", {className: "alert alert-danger", style: {margin:10 }}, error) :762 React.createElement("div", {className: "alert alert-danger", style: {margin:10, width:200}}, error) : 717 763 React.createElement("a", {href: this.props.getToWeblichtLink(corpusId), target: "_blank"}, " ", 718 764 "Send to Weblicht") … … 729 775 propTypes: { 730 776 corpusHit: PT.object, 777 nextResults: PT.func.isRequired, 731 778 languageMap: PT.object.isRequired, 732 779 weblichtLanguages: PT.array.isRequired, … … 737 784 mixins: [ResultMixin], 738 785 786 getInitialState: function() { 787 return { 788 inProgress: false, 789 }; 790 }, 791 792 componentWillReceiveProps: function() { 793 this.setState({inProgress: false}); 794 }, 795 796 nextResults: function(e) { 797 this.setState({inProgress: true}); 798 this.props.nextResults(this.props.corpusHit.corpus.id); 799 }, 800 739 801 renderLanguages: function(languages) { 740 802 return languages … … 742 804 .sort() 743 805 .join(", "); 806 }, 807 808 renderMoreResults:function(){ 809 if (this.state.inProgress || this.props.corpusHit.inProgress) 810 return React.createElement("span", {style: {fontStyle:'italic'}}, "Retrieving results, please wait..."); 811 812 var moreResults = true; 813 for (var i = 0; i < this.props.corpusHit.diagnostics.length; i++) { 814 var d = this.props.corpusHit.diagnostics[i]; 815 if (d.uri === NO_MORE_RECORDS_DIAGNOSTIC_URI) { 816 moreResults = false; 817 break; 818 } 819 } 820 if (!moreResults) 821 return React.createElement("span", {style: {fontStyle:'italic'}}, "No other results available for this query"); 822 return React.createElement("button", {className: "btn btn-default", onClick: this.nextResults}, 823 React.createElement("span", {className: "glyphicon glyphicon-option-horizontal", 'aria-hidden': "true"}), " More Results" 824 ); 744 825 }, 745 826 … … 777 858 778 859 React.createElement("div", {style: {textAlign:'center', marginTop:10}}, 779 React.createElement("button", {className: "btn btn-default"}, 780 React.createElement("span", {className: "glyphicon glyphicon-option-horizontal", 'aria-hidden': "true"}), " More Results" 781 ) 860 this.renderMoreResults() 782 861 ) 783 862 … … 789 868 var Results = React.createClass({displayName: 'Results', 790 869 propTypes: { 791 requests: PT.array.isRequired, 792 results: PT.array.isRequired, 870 collhits: PT.object.isRequired, 793 871 searchedLanguage: PT.array.isRequired, 794 872 toggleResultModal: PT.func.isRequired, … … 825 903 }, 826 904 827 renderProgressMessage: function(hits) { 828 var total = this.props.requests.length + this.props.results.length; 829 var msg = hits + " matching collections found in " + this.props.results.length + " searched collections"; 830 var percents = Math.round(100 * this.props.results.length / total); 905 renderProgressMessage: function() { 906 var collhits = this.props.collhits; 907 var done = collhits.results.length - collhits.inProgress; 908 var msg = collhits.hits + " matching collections found in " + done + " searched collections"; 909 var percents = Math.round(100 * collhits.hits / collhits.results.length); 831 910 var styleperc = {width: percents+"%"}; 832 911 return React.createElement("div", {style: {marginTop:10}}, 833 912 React.createElement("div", null, msg), 834 this.props.requests.length> 0 ?913 collhits.inProgress > 0 ? 835 914 React.createElement("div", {className: "progress", style: {marginBottom:10}}, 836 915 React.createElement("div", {className: "progress-bar progress-bar-striped active", role: "progressbar", … … 847 926 848 927 render: function() { 849 if (this.props.results.length + this.props.requests.length === 0) { 928 var collhits = this.props.collhits; 929 if (!collhits.results) { 850 930 return false; 851 931 } 852 var hits = this.props.results.filter(function(corpusHit) { return corpusHit.kwics.length > 0; }).length; 853 var showprogress = this.props.requests.length > 0; 932 var showprogress = collhits.inProgress > 0; 854 933 return React.createElement("div", null, 855 934 React.createElement(ReactCSSTransitionGroup, {transitionName: "fade"}, 856 showprogress ? this.renderProgressMessage( hits) : React.createElement("div", {style: {height:20}}),935 showprogress ? this.renderProgressMessage() : React.createElement("div", {style: {height:20}}), 857 936 React.createElement("div", {style: {marginBottom:2}}, 858 937 showprogress ? false : 859 React.createElement("div", {className: "float-left"}, " ", hits + " matching collections found", " "),938 React.createElement("div", {className: "float-left"}, " ", collhits.hits + " matching collections found", " "), 860 939 861 hits === 0 ? false :940 collhits.hits === 0 ? false : 862 941 React.createElement("div", {className: "float-right"}, 863 942 React.createElement("div", null, 864 943 this.renderDisplayKWIC(), 865 this.props.requests.length=== 0 ?944 collhits.inProgress === 0 ? 866 945 React.createElement("div", {className: "inline"}, " ", this.renderDownloadLinks(), " ") 867 946 :false … … 872 951 React.createElement("div", {style: {clear:'both'}}) 873 952 ), 874 this.props.results.map(this.renderResultPanel)953 collhits.results.map(this.renderResultPanel) 875 954 ) 876 955 );
Note: See TracChangeset
for help on using the changeset viewer.