<commit_before>var m = require('mithril');
var partial = require('chessground').util.partial;

function storedProp(keySuffix, initialValue) {
  var key = 'explorer.' + keySuffix;
  return function() {
    if (arguments.length) lichess.storage.set(key, JSON.stringify(arguments[0]));
    var ret = JSON.parse(lichess.storage.get(key));
    return (ret !== null) ? ret : initialValue;
  };
}

module.exports = {
  controller: function(onClose) {
    var data = {
      open: m.prop(false),
      db: {
        available: ['lichess', 'masters'], //, 'me'],
        selected: storedProp('db', 'lichess')
      },
      rating: {
        available: [1600, 1800, 2000, 2200, 2500],
        selected: storedProp('rating', [2000, 2200, 2500])
      },
      speed: {
        available: ['bullet', 'blitz', 'classical'],
        selected: storedProp('speed', ['blitz', 'classical'])
      }
    };

    var toggleMany = function(c, value) {
      if (c().indexOf(value) === -1) c(c().concat([value]));
      else if (c().length > 1) c(c().filter(function(v) {
        return v !== value;
      }));
    };

    return {
      data: data,
      toggleOpen: function() {
        data.open(!data.open());
        if (!data.open()) onClose();
      },
      toggleDb: function(db) {
        data.db.selected(db);
      },
      toggleRating: partial(toggleMany, data.rating.selected),
      toggleSpeed: partial(toggleMany, data.speed.selected)
    };
  },
  view: function(ctrl) {
    var d = ctrl.data;
    return [
      m('section.db', [
        m('label', 'Database'),
        m('div.choices',
          d.db.available.map(function(s) {
            return m('span', {
              class: d.db.selected() === s ? 'selected' : '',
              onclick: partial(ctrl.toggleDb, s)
            }, s);
          })
        )
      ]),
      m('div', {
        class: 'adv' + (d.db.selected() === 'masters' ? ' hidden' : '')
      }, [
        m('section.rating', [
          m('label', 'Players Average rating'),
          m('div.choices',
            d.rating.available.map(function(r) {
              return m('span', {
                class: d.rating.selected().indexOf(r) > -1 ? 'selected' : '',
                onclick: partial(ctrl.toggleRating, r)
              }, r);
            })
          )
        ]),
        m('section.speed', [
          m('label', 'Game speed'),
          m('div.choices',
            d.speed.available.map(function(s) {
              return m('span', {
                class: d.speed.selected().indexOf(s) > -1 ? 'selected' : '',
                onclick: partial(ctrl.toggleSpeed, s)
              }, s);
            })
          )
        ])
      ])
    ];
  }
};
<commit_msg>default explorer to master games<commit_after>var m = require('mithril');
var partial = require('chessground').util.partial;

function storedProp(keySuffix, initialValue) {
  var key = 'explorer.' + keySuffix;
  return function() {
    if (arguments.length) lichess.storage.set(key, JSON.stringify(arguments[0]));
    var ret = JSON.parse(lichess.storage.get(key));
    return (ret !== null) ? ret : initialValue;
  };
}

module.exports = {
  controller: function(onClose) {
    var data = {
      open: m.prop(false),
      db: {
        available: ['lichess', 'masters'], //, 'me'],
        selected: storedProp('db', 'masters')
      },
      rating: {
        available: [1600, 1800, 2000, 2200, 2500],
        selected: storedProp('rating', [2000, 2200, 2500])
      },
      speed: {
        available: ['bullet', 'blitz', 'classical'],
        selected: storedProp('speed', ['blitz', 'classical'])
      }
    };

    var toggleMany = function(c, value) {
      if (c().indexOf(value) === -1) c(c().concat([value]));
      else if (c().length > 1) c(c().filter(function(v) {
        return v !== value;
      }));
    };

    return {
      data: data,
      toggleOpen: function() {
        data.open(!data.open());
        if (!data.open()) onClose();
      },
      toggleDb: function(db) {
        data.db.selected(db);
      },
      toggleRating: partial(toggleMany, data.rating.selected),
      toggleSpeed: partial(toggleMany, data.speed.selected)
    };
  },
  view: function(ctrl) {
    var d = ctrl.data;
    return [
      m('section.db', [
        m('label', 'Database'),
        m('div.choices',
          d.db.available.map(function(s) {
            return m('span', {
              class: d.db.selected() === s ? 'selected' : '',
              onclick: partial(ctrl.toggleDb, s)
            }, s);
          })
        )
      ]),
      m('div', {
        class: 'adv' + (d.db.selected() === 'masters' ? ' hidden' : '')
      }, [
        m('section.rating', [
          m('label', 'Players Average rating'),
          m('div.choices',
            d.rating.available.map(function(r) {
              return m('span', {
                class: d.rating.selected().indexOf(r) > -1 ? 'selected' : '',
                onclick: partial(ctrl.toggleRating, r)
              }, r);
            })
          )
        ]),
        m('section.speed', [
          m('label', 'Game speed'),
          m('div.choices',
            d.speed.available.map(function(s) {
              return m('span', {
                class: d.speed.selected().indexOf(s) > -1 ? 'selected' : '',
                onclick: partial(ctrl.toggleSpeed, s)
              }, s);
            })
          )
        ])
      ])
    ];
  }
};

{'fraction_non_alphanumeric': 0.18151632540121748, 'fraction_numerical': 0.01365061796716473, 'mean_word_length': 1.8551869404949974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4030400', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1654, 'n_words': 318}