Ignore:
Timestamp:
03/11/15 11:09:37 (9 years ago)
Author:
emanuel.dima@uni-tuebingen.de
Message:
  1. beta-29: better language detection for weblicht
File:
1 edited

Legend:

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

    r6093 r6097  
    297297        },
    298298
    299         getExportParams: function(corpusId, format) {
     299        getExportParams: function(corpusId, format, filterLanguage) {
    300300                var params = corpusId ? {corpusId:corpusId}:{};
    301301                if (format) params.format = format;
    302                 if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
     302                if (filterLanguage) {
     303                        params.filterLanguage = filterLanguage;
     304                } else if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
    303305                        params.filterLanguage = this.state.language[0];
    304306                }
     
    307309
    308310        getDownloadLink: function(corpusId, format) {
    309                 return 'rest/search/'+this.state.searchId+'/download?' + this.getExportParams(corpusId, format);
    310         },
    311 
    312         getToWeblichtLink: function(corpusId) {
    313                 var params = corpusId ? {corpusId:corpusId}:{};
    314                 return 'rest/search/'+this.state.searchId+'/toWeblicht?' + this.getExportParams(corpusId);
     311                return 'rest/search/'+this.state.searchId+'/download?' +
     312                        this.getExportParams(corpusId, format);
     313        },
     314
     315        getToWeblichtLink: function(corpusId, forceLanguage) {
     316                return 'rest/search/'+this.state.searchId+'/toWeblicht?' +
     317                        this.getExportParams(corpusId, null, forceLanguage);
    315318        },
    316319
     
    469472                                                                                        layers.map(function(l) {
    470473                                                                                                var cls = l.disabled ? 'disabled':'';
    471                                                                                                 var handler = function() { if (!l.disabled) this.setLayer(l.id); };
     474                                                                                                var handler = function() { if (!l.disabled) this.setLayer(l.id); }.bind(this);
    472475                                                                                                return React.createElement("li", {key: l.id, className: cls}, " ", React.createElement("a", {tabIndex: "-1", href: "#",
    473476                                                                                                        onClick: handler}, " ", l.name, " "));
     
    753756        },
    754757
    755         renderToWeblichtLinks: function(corpusId, error) {
     758        renderToWeblichtLinks: function(corpusId, forceLanguage, error) {
    756759                return (
    757760                        React.createElement("div", {className: "dropdown"},
     
    765768                                                error ?
    766769                                                        React.createElement("div", {className: "alert alert-danger", style: {margin:10, width:200}}, error) :
    767                                                         React.createElement("a", {href: this.props.getToWeblichtLink(corpusId), target: "_blank"}, " ",
     770                                                        React.createElement("a", {href: this.props.getToWeblichtLink(corpusId, forceLanguage), target: "_blank"}, " ",
    768771                                                                "Send to Weblicht")
    769772                                               
     
    834837                        return false;
    835838                }
    836                 var wlerror = null;
     839
     840                var forceLanguage = null, wlerror = null;
    837841                if (this.props.weblichtLanguages.indexOf(this.props.searchedLanguage[0]) < 0) {
    838                         wlerror = "Cannot use WebLicht: unsupported language";
     842                        // the search language is either AnyLanguage or unsupported
     843                        if (this.props.searchedLanguage[0] === multipleLanguageCode) {
     844                                if (corpusHit.corpus.languages && corpusHit.corpus.languages.length === 1) {
     845                                        forceLanguage = corpusHit.corpus.languages[0];
     846                                } else {
     847                                        var langs = corpusHit.kwics.map(function(kwic) {return kwic.language;});
     848                                        langs = _.uniq(langs.filter(function(l){ return l !== null; }));
     849                                        console.log("languages:", langs);
     850                                        if (langs.length === 1) {
     851                                                forceLanguage = langs[0];
     852                                        }
     853                                }
     854                        }
     855                        if (!forceLanguage) {
     856                                wlerror = "Cannot use WebLicht: unsupported language ("+this.props.searchedLanguage[1]+")";
     857                        }
    839858                }
    840859                var corpus = corpusHit.corpus;
     
    852871                                                                         this.renderDisplayKWIC(),
    853872                                                                        React.createElement("div", {className: "inline"}, " ", this.renderDownloadLinks(corpusHit.corpus.id), " "),
    854                                                                         React.createElement("div", {className: "inline"}, " ", this.renderToWeblichtLinks(corpus.id, wlerror), " ")
     873                                                                        React.createElement("div", {className: "inline"}, " ", this.renderToWeblichtLinks(corpus.id, forceLanguage, wlerror), " ")
    855874                                                                )
    856875                                                        ),
     
    9911010                return ret;
    9921011        },
     1012
     1013        uniq: function(a) {
     1014                var r = [];
     1015                for (var i = 0; i < a.length; i++) {
     1016                        if (r.indexOf(a[i]) < 0) {
     1017                                r.push(a[i]);
     1018                        }
     1019                }
     1020                return r;
     1021        },
    9931022};
    9941023
Note: See TracChangeset for help on using the changeset viewer.