Changeset 7042 for SRUAggregator


Ignore:
Timestamp:
07/27/16 12:43:50 (8 years ago)
Author:
Leif-Jöran
Message:

Some cleanup of queryType and queryTypeId and clearer distinction in relation to layers.

File:
1 edited

Legend:

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

    r7041 r7042  
    2121var multipleLanguageCode = "mul"; // see ISO-693-3
    2222
    23 //var queryTypes = [
    24 var layers = [
     23var queryTypes = [
    2524        {
    2625                id: "cql",
     
    4140];
    4241
    43 var layerMap = {
    44         cql: layers[0],
    45         fcs: layers[1],
     42var queryTypeMap = {
     43        cql: queryTypes[0],
     44        fcs: queryTypes[1],
    4645};
     46
    4747// var layers = [
    4848//      {
    4949//              id: "text",
    50 //              name: "Text Resources",
     50//              name: "Text",
    5151//              searchPlaceholder: "Elephant",
    5252//              searchLabel: "Search text",
     
    177177};
    178178
    179 Corpora.prototype.isCorpusVisible = function(corpus, layerId, languageCode) {
    180         //if (layerId !== "text") {
     179Corpora.prototype.isCorpusVisible = function(corpus, queryTypeId, languageCode) {
     180        //if (queryTypeId !== "text") {
    181181        //      return false;
    182182        //}
     
    202202};
    203203
    204 Corpora.prototype.setVisibility = function(layerId, languageCode) {
     204Corpora.prototype.setVisibility = function(queryTypeId, languageCode) {
    205205        // top level
    206206        this.corpora.forEach(function(corpus) {
    207                 corpus.visible = this.isCorpusVisible(corpus, layerId, languageCode);
     207                corpus.visible = this.isCorpusVisible(corpus, queryTypeId, languageCode);
    208208                this.recurseCorpora(corpus.subCorpora, function(c) { c.visible = corpus.visible; });
    209209        }.bind(this));
     
    285285                        languageMap: {},
    286286                        weblichtLanguages: [],
    287                         queryType: getQueryVariable('queryType') || 'cql',
     287                        queryTypeId: getQueryVariable('queryType') || 'cql',
    288288                        query: getQueryVariable('query') || '',
    289289                        language: this.anyLanguage,
    290290                        languageFilter: 'byMeta',
    291                         //fixme!
    292                         searchLayerId: getQueryVariable('queryType') || 'cql',
    293291                        numberOfResults: 10,
    294292
     
    346344        search: function() {
    347345                var query = this.state.query;
    348                 var queryType = this.state.searchLayerId;
     346                var queryType = this.state.queryTypeId;
    349347                if (!query || this.props.embedded) {
    350348                        this.setState({ hits: this.nohits, searchId: null });
     
    363361                        type: "POST",
    364362                        data: {
    365                                 layer: this.state.searchLayerId,
     363                                query: query,
     364                                queryType: queryType,
    366365                                language: this.state.language[0],
    367                                 queryType: queryType,
    368                                 query: query,
    369366                                numberOfResults: this.state.numberOfResults,
    370367                                corporaIds: selectedIds,
     
    452449
    453450        setLanguageAndFilter: function(languageObj, languageFilter) {
    454                 this.state.corpora.setVisibility(this.state.searchLayerId,
     451                this.state.corpora.setVisibility(this.state.queryTypeId,
    455452                        languageFilter === 'byGuess' ? multipleLanguageCode : languageObj[0]);
    456453                this.setState({
     
    461458        },
    462459
    463         setLayer: function(layerId) {
    464                 this.state.corpora.setVisibility(layerId, this.state.language[0]);
     460        setQueryType: function(queryTypeId) {
     461                this.state.corpora.setVisibility(queryTypeId, this.state.language[0]);
    465462                this.setState({
    466                         searchLayerId: layerId,
    467                         queryType: layerId,
     463                        queryTypeId: queryTypeId,
    468464                        hits: this.nohits,
    469465                        searchId: null,
    470                         displayADV: layerId == "fcs" ? true : false,
     466                        displayADV: queryTypeId == "fcs" ? true : false,
    471467                        corpora: this.state.corpora, // === this.state.corpora.update();
    472468                });
     
    573569                if (this.props.embedded) {
    574570                        var query = this.state.query;
    575                         var queryType = this.state.queryType;
     571                        var queryType = this.state.queryTypeId;
    576572                        var newurl = !query ? "#" :
    577573                                (window.MyAggregator.URLROOT + "?" + encodeQueryData({queryType:queryType, query:query, mode:'search'}));
     
    591587
    592588        render: function() {
    593                 var layer = layerMap[this.state.searchLayerId];
     589                var queryType = queryTypeMap[this.state.queryTypeId];
    594590                return  (
    595591                        <div className="top-gap">
     
    597593                                        <div className="aligncenter" style={{marginLeft:16, marginRight:16}}>
    598594                                                <div className="input-group">
    599                                                         <span className="input-group-addon" style={{backgroundColor:layer.searchLabelBkColor}}>
    600                                                                 {layer.searchLabel}
     595                                                        <span className="input-group-addon" style={{backgroundColor:queryType.searchLabelBkColor}}>
     596                                                                {queryType.searchLabel}
    601597                                                        </span>
    602598
     
    627623                                                                </div>
    628624                                                                <div className="input-group-btn hidden-xxs">
    629                                                                         <ul ref="layerDropdownMenu" className="dropdown-menu">
    630                                                                                 {       layers.map(function(l) {
     625                                                                        <ul ref="queryTypeDropdownMenu" className="dropdown-menu">
     626                                                                                {       queryTypes.map(function(l) {
    631627                                                                                                var cls = l.disabled ? 'disabled':'';
    632                                                                                                 var handler = function() { if (!l.disabled) this.setLayer(l.id); }.bind(this);
     628                                                                                                var handler = function() { if (!l.disabled) this.setQueryType(l.id); }.bind(this);
    633629                                                                                                return <li key={l.id} className={cls}> <a tabIndex="-1" href="#"
    634630                                                                                                        onClick={handler}> {l.name} </a></li>;
     
    638634                                                                        <button className="form-control btn btn-default"
    639635                                                                                        aria-expanded="false" data-toggle="dropdown" >
    640                                                                                 {layer.name} <span className="caret"/>
     636                                                                                {queryType.name} <span className="caret"/>
    641637                                                                        </button>
    642638                                                                </div>
     
    686682                                                                  weblichtLanguages={this.state.weblichtLanguages}
    687683                                                                  languageMap={this.state.languageMap}
    688                                                                   queryType={this.state.queryType} />
     684                                                                  queryTypeId={this.state.queryTypeId} />
    689685                                </Modal>
    690686
     
    695691                                                         getToWeblichtLink={this.getToWeblichtLink}
    696692                                                         searchedLanguage={this.state.language}
    697                                                          queryType={this.state.queryType}/>
     693                                                         queryTypeId={this.state.queryTypeId}/>
    698694                                </div>
    699695                        </div>
     
    994990                getDownloadLink: PT.func.isRequired,
    995991                getToWeblichtLink: PT.func.isRequired,
    996                 queryType: PT.string.isRequired,
     992                queryTypeId: PT.string.isRequired,
    997993        },
    998994        mixins: [ResultMixin],
     
    10731069                                                                <div>
    10741070                                                                        {this.renderDisplayKWIC()}
    1075                                                                     {this.props.queryType !== "fcs" ? "" : this.renderDisplayADV()}
     1071                                                                    {this.props.queryTypeId !== "fcs" ? "" : this.renderDisplayADV()}
    10761072                                                                        <div className="inline"> {this.renderDownloadLinks(corpusHit.corpus.id)} </div>
    10771073                                                                        <div className="inline"> {this.renderToWeblichtLinks(corpus.id, forceLanguage, wlerror)} </div>
     
    11001096                getDownloadLink: PT.func.isRequired,
    11011097                getToWeblichtLink: PT.func.isRequired,
    1102                 queryType: PT.string.isRequired,
     1098                queryTypeId: PT.string.isRequired,
    11031099        },
    11041100        mixins: [ResultMixin],
     
    11701166                                                                        <div>
    11711167                                                                                {this.renderDisplayKWIC()}
    1172                                                                             {this.props.queryType !== "fcs" ? "" : this.renderDisplayADV()}
     1168                                                                            {this.props.queryTypeId !== "fcs" ? "" : this.renderDisplayADV()}
    11731169                                                                                { collhits.inProgress === 0 ?
    11741170                                                                                        <div className="inline"> {this.renderDownloadLinks()} </div>
Note: See TracChangeset for help on using the changeset viewer.