Ignore:
Timestamp:
02/24/15 16:58:55 (9 years ago)
Author:
emanuel.dima@uni-tuebingen.de
Message:
  1. alpha 21: downloading as text, csv, excel and tcf works
File:
1 edited

Legend:

Unmodified
Added
Removed
  • SRUAggregator/trunk/src/main/resources/assets/js/search.js

    r5971 r6043  
    6262                corpus.selected = true; // selected in the corpus view
    6363                corpus.expanded = false; // not expanded in the corpus view
    64                 corpus.priority = 1; // priority in corpus view
     64                corpus.priority = 1; // used for ordering search results in corpus view
    6565                corpus.index = index; // original order, used for stable sort
    6666        });
     
    164164        },
    165165
    166         timeout: 0,
    167166        nohits: {
    168167                requests: [],
     
    182181
    183182                        searchId: null,
    184                         hits: this.nohits,
     183                        timeout: 0,
     184                        hits: this.nohits,                     
    185185                };
    186186        },
     
    195195                        url: 'rest/corpora',
    196196                        success: function(json, textStatus, jqXHR) {
    197                                 this.setState({corpora : new Corpora(json, this.updateCorpora)});
     197                                if (this.isMounted()) {
     198                                        this.setState({corpora : new Corpora(json, this.updateCorpora)});
     199                                }
    198200                        }.bind(this),
    199201                });
     
    204206                        url: 'rest/languages',
    205207                        success: function(json, textStatus, jqXHR) {
    206                                 this.setState({languageMap : json});
     208                                if (this.isMounted()) {
     209                                        this.setState({languageMap : json});
     210                                }
    207211                        }.bind(this),
    208212                });
     
    233237                        success: function(searchId, textStatus, jqXHR) {
    234238                                // console.log("search ["+query+"] ok: ", searchId, jqXHR);
    235                                 this.setState({searchId : searchId});
    236                                 this.timeout = 250;
    237                                 setTimeout(this.refreshSearchResults, this.timeout);
     239                                var timeout = 250;
     240                                setTimeout(this.refreshSearchResults, timeout);
     241                                this.setState({ searchId: searchId, timeout: timeout });
    238242                        }.bind(this),
    239243                });
     
    241245
    242246        refreshSearchResults: function() {
    243                 if (!this.state.searchId) {
     247                if (!this.state.searchId || !this.isMounted()) {
    244248                        return;
    245249                }
     
    247251                        url: 'rest/search/'+this.state.searchId,
    248252                        success: function(json, textStatus, jqXHR) {
     253                                var timeout = this.state.timeout;
    249254                                if (json.requests.length > 0) {
    250                                         if (this.timeout < 10000) {
    251                                                 this.timeout = 1.5 * this.timeout;
     255                                        if (timeout < 10000) {
     256                                                timeout = 1.5 * timeout;
    252257                                        }
    253                                         setTimeout(this.refreshSearchResults, this.timeout);
    254                                         // console.log("new search in: " + this.timeout+ "ms");
     258                                        setTimeout(this.refreshSearchResults, timeout);
     259                                        // console.log("new search in: " + this.timeout + "ms");
    255260                                } else {
    256261                                        console.log("search ended; hits:", json);
    257262                                }
    258                                 this.setState({hits:json});
     263                                this.setState({ hits: json, timeout: timeout });
    259264                        }.bind(this),
    260265                });
     
    656661        },
    657662
    658         renderToolbox: function() {
    659                 if (this.props.requests.length > 0) {
    660                         return false;
    661                 }
    662                 return  React.createElement("div", {className: "toolbox float-left"},
    663                                         React.createElement("a", {className: "btn btn-default", href: this.props.getDownloadLink("text")},
    664                                                 React.createElement("span", {className: "glyphicon glyphicon-download-alt", 'aria-hidden': "true"}), " Download"
    665                                         )
    666                                 );
    667         },
    668 
    669663        renderProgressBar: function() {
    670664                var percents = 100 * this.props.results.length / (this.props.requests.length + this.props.results.length);
     
    693687        },
    694688
    695         renderKwicCheckbox: function() {
    696                 return  React.createElement("div", {className: "float-right", style: {marginRight:17}},
    697                                         React.createElement("div", {className: "btn-group", style: {display:"inline-block"}},
    698                                                 React.createElement("label", {forHtml: "inputKwic", className: "btn-default"},
    699                                                          this.state.displayKwic ?
    700                                                                 React.createElement("input", {id: "inputKwic", type: "checkbox", value: "kwic", checked: true, onChange: this.toggleKwic}) :
    701                                                                 React.createElement("input", {id: "inputKwic", type: "checkbox", value: "kwic", onChange: this.toggleKwic}),
    702                                                        
    703                                                         " " + ' ' +
    704                                                         "Display as Key Word In Context"
     689        renderDownloadLinks: function() {
     690                return (
     691                        React.createElement("div", {className: "dropdown"},
     692                                React.createElement("button", {className: "btn btn-default", 'aria-expanded': "false", 'data-toggle': "dropdown"},
     693                                        React.createElement("span", {className: "glyphicon glyphicon-download-alt", 'aria-hidden': "true"}),
     694                                        " ", " Download ", " ",
     695                                        React.createElement("span", {className: "caret"})
     696                                ),
     697                                React.createElement("ul", {className: "dropdown-menu"},
     698                                        React.createElement("li", null, " ", React.createElement("a", {href: this.props.getDownloadLink("csv")},
     699                                                        " ", " As CSV file")),
     700                                        React.createElement("li", null, " ", React.createElement("a", {href: this.props.getDownloadLink("excel")},
     701                                                        " ", " As Excel file")),
     702                                        React.createElement("li", null, " ", React.createElement("a", {href: this.props.getDownloadLink("tcf")},
     703                                                        " ", " As TCF file")),
     704                                        React.createElement("li", null, " ", React.createElement("a", {href: this.props.getDownloadLink("text")},
     705                                                        " ", " As Plain Text file"))
     706                                )
     707                        )
     708                );
     709        },
     710
     711        renderToolbox: function(hits) {
     712                if (hits <= 0) {
     713                        return false;
     714                }
     715                return  React.createElement("div", {key: "-toolbox-", style: {marginBottom:10}},
     716                                        React.createElement("div", {className: "toolbox float-left inline"},
     717                                                this.renderDownloadLinks()
     718                                        ),
     719                                        React.createElement("div", {className: "float-right inline", style: {marginTop:15}},
     720                                                React.createElement("div", {className: "btn-group", style: {display:"inline-block"}},
     721                                                        React.createElement("label", {forHtml: "inputKwic", className: "btn-default"},
     722                                                                 this.state.displayKwic ?
     723                                                                        React.createElement("input", {id: "inputKwic", type: "checkbox", value: "kwic", checked: true, onChange: this.toggleKwic}) :
     724                                                                        React.createElement("input", {id: "inputKwic", type: "checkbox", value: "kwic", onChange: this.toggleKwic}),
     725                                                               
     726                                                                " " + ' ' +
     727                                                                "Display as Key Word In Context"
     728                                                        )
    705729                                                )
    706730                                        )
     
    719743                                                React.createElement("div", {key: "-found-message-", style: margintop}, this.renderFoundMessage(hits), " "),
    720744                                                React.createElement("div", {key: "-progress-", style: margintop}, this.renderProgressBar()),
    721                                                 hits > 0 ?
    722                                                         React.createElement("div", {key: "-option-KWIC-", className: "row"},
    723                                                                 this.renderToolbox(),
    724                                                                 this.renderKwicCheckbox()
    725                                                         )
    726                                                         : false,
     745                                                this.renderToolbox(hits),
    727746                                                this.props.results.map(this.renderResultPanels)
    728747                                        )
Note: See TracChangeset for help on using the changeset viewer.