<commit_before>(function ($, window, undefined) {

/**
 * @module Assets-tools
 */

/**
 * Implements an input field that send search string to Amazon Product store and retrieve top ten relevant products
 * @class Assets Amazon tool
 * @constructor
 * @param {Object} [options] options to pass to this tool, so far nothing
 * @return {Q.Tool}
 */

Q.Tool.define("Assets/amazon", function(options) {

/*  
  if (!options.publisherId || !options.streamName) {
    throw "Assets/amazon tool missing something";
  }
*/

  if (!Q.Users.loggedInUser) {
      tool.element.style.display = 'none';
      console.warn("Assets/amazon: Don't render tool when user is not logged in");
      return;
  }

  // proceed to construct the tool
  var tool = this;
  var state = tool.state;
  var $te = $(tool.element);

  // draw the tool
  tool.refresh();

  console.log(state);

  $te.on(Q.Pointer.fastclick, '.Assets_amazon_results_item', tool, function () {

      Q.Streams.get(state.publisherId, state.streamName, function () {
        console.log(this.fields);
      });

      tool.filter = Q.Tool.from(tool.$('.Q_filter_tool'), 'Q/filter');
      return tool.filter.end();
  });
},

{ // DEFAULT OPTIONS

  publisherId: null,
  streamName: null,

  onChoose: new Q.Event(),  
  onSelect: new Q.Event(),
  onFilter: new Q.Event(),  
  onCreate: new Q.Event(),
  onUpdate: new Q.Event(),
  onRefresh: new Q.Event()
},

{ // YOUR TOOL'S METHODS

  refresh: function (callback) {
    var tool = this;
    var state = tool.state;
    var $te = $(tool.element);

    $items = tool.$('[data-assets-amazon], .Assets_amazon_tool');

    Q.Template.render(
        'Assets/amazon/response/wishlist',
        $items,
        function (err, html) {

            if (err) {
                return;
            }

            var options = {};

            var filterAmazon = Q.Tool.setUpElement(
                'div',
                'Q/filter',
                options,
                tool.prefix + 'filter'
            );

            tool.$(filterAmazon)
                .appendTo($te)
                .activate(
                    function () {

                        var tool = this;
                        var state = tool.state;

                        state.onFilter.set(
                          function (query, element) {

                              var latest = Q.latest(tool);

                              Q.req("Assets/amazon", 'results', 
                                function (err, response) {

                                  var msg = Q.firstErrorMessage(err, response && response.errors);
                                  if (msg) {
                                      return console.warn(msg);
                                  }

                                  var results = response.slots.results;
                                  var fields = {results: ''};
                                  if (results) {
                                      fields = {results: results};
                                  }

                                  Q.Template.render(
                                      'Assets/amazon/response/results',
                                      fields,
                                      function (err, html) {
                                          $(element).html(html);
                                      }
                                  );
                                },
                                {
                                  fields: {
                                      input: query
                                  }
                              });

                          }, tool);
                });

            $te.append(html);
            });
  },

  // optional methods for your tool
  // that would be called by Qbix
  Q: {
    onInit: function () {
      // occurs after onInit
      // of all child tools
    },
    beforeRemove: function () {
      // clean up anything you've attached
      // to the elements, such as
      // jQuery event handlers, data, etc.
    },
    onRetain: function (newOptions) {
      // compare newOptions to this.state
      // and update the tool's appearance.
      // after this event, the tool's
      // state will be extended with
      // the new options.
    },
    onLayout: function (elem, container) {
      // Occurs if the layout is being
      // updated for this tool's element.
      // If you want more fine-grained control
      // then use Q.onLayout(element) instead.
    }
  }
});

Q.Template.set('Assets/amazon/response/wishlist', 
    '<div class="Assets_amazon_image">'
    + '</div>'    
    + '<div class="Assets_amazon_price">Price:'
    + '</div>'
);

Q.Template.set('Assets/amazon/response/results',
    '{{#if results}}'
    + '<ul>'
    + '{{#each results}}'
    + '<li class="Assets_amazon_results_item" data-index={{@index}} data-asin={{ASIN}}>'
    + '<img class="Assets_amazon_results_image" src="{{pic}}" alt="{{alt}}">'
    + '<div>'
    + '<span class="Assets_amazon_results_title"><h3>{{title}}</h3></span>'
    + '<span class="Assets_amazon_results_price">{{price}}</span>'
    + '</div>'
    + '<br>'
    + '</li>'
    + '{{/each}}'
    + '</ul>'
    + '{{/if}}'
);


})(window.jQuery, window);<commit_msg>fix for Q.latest ordinal setting<commit_after>(function ($, window, undefined) {

/**
 * @module Assets-tools
 */

/**
 * Implements an input field that send search string to Amazon Product store and retrieve top ten relevant products
 * @class Assets Amazon tool
 * @constructor
 * @param {Object} [options] options to pass to this tool, so far nothing
 * @return {Q.Tool}
 */

Q.Tool.define("Assets/amazon", function(options) {

/*  
  if (!options.publisherId || !options.streamName) {
    throw "Assets/amazon tool missing something";
  }
*/

  if (!Q.Users.loggedInUser) {
      tool.element.style.display = 'none';
      console.warn("Assets/amazon: Don't render tool when user is not logged in");
      return;
  }

  // proceed to construct the tool
  var tool = this;
  var state = tool.state;
  var $te = $(tool.element);

  // draw the tool
  tool.refresh();

  console.log(state);

  $te.on(Q.Pointer.fastclick, '.Assets_amazon_results_item', tool, function () {

      Q.Streams.get(state.publisherId, state.streamName, function () {
        console.log(this.fields);
      });

      tool.filter = Q.Tool.from(tool.$('.Q_filter_tool'), 'Q/filter');
      return tool.filter.end();
  });
},

{ // DEFAULT OPTIONS

  publisherId: null,
  streamName: null,

  onChoose: new Q.Event(),  
  onSelect: new Q.Event(),
  onFilter: new Q.Event(),  
  onCreate: new Q.Event(),
  onUpdate: new Q.Event(),
  onRefresh: new Q.Event()
},

{ // YOUR TOOL'S METHODS

  refresh: function (callback) {
    var tool = this;
    var state = tool.state;
    var $te = $(tool.element);

    $items = tool.$('[data-assets-amazon], .Assets_amazon_tool');

    Q.Template.render(
        'Assets/amazon/response/wishlist',
        $items,
        function (err, html) {

            if (err) {
                return;
            }

            var options = {};

            var filterAmazon = Q.Tool.setUpElement(
                'div',
                'Q/filter',
                options,
                tool.prefix + 'filter'
            );

            tool.$(filterAmazon)
                .appendTo($te)
                .activate(
                    function () {

                        var tool = this;
                        var state = tool.state;

                        state.onFilter.set(
                          function (query, element) {

                              var latest = Q.latest(tool);

                              Q.req("Assets/amazon", 'results', 
                                function (err, response) {

                                  if (Q.latest(tool, latest)) {                                  

                                    var msg = Q.firstErrorMessage(err, response && response.errors);
                                    if (msg) {
                                        return console.warn(msg);
                                    }

                                    var results = response.slots.results;
                                    var fields = {results: ''};
                                    if (results) {
                                        fields = {results: results};
                                    }

                                    Q.Template.render(
                                        'Assets/amazon/response/results',
                                        fields,
                                        function (err, html) {
                                            $(element).html(html);
                                        }
                                    );
                                  }
                                },
                                {
                                  fields: {
                                      input: query
                                  }
                              });

                          }, tool);
                });

            $te.append(html);
            });
  },

  // optional methods for your tool
  // that would be called by Qbix
  Q: {
    onInit: function () {
      // occurs after onInit
      // of all child tools
    },
    beforeRemove: function () {
      // clean up anything you've attached
      // to the elements, such as
      // jQuery event handlers, data, etc.
    },
    onRetain: function (newOptions) {
      // compare newOptions to this.state
      // and update the tool's appearance.
      // after this event, the tool's
      // state will be extended with
      // the new options.
    },
    onLayout: function (elem, container) {
      // Occurs if the layout is being
      // updated for this tool's element.
      // If you want more fine-grained control
      // then use Q.onLayout(element) instead.
    }
  }
});

Q.Template.set('Assets/amazon/response/wishlist', 
    '<div class="Assets_amazon_image">'
    + '</div>'    
    + '<div class="Assets_amazon_price">Price:'
    + '</div>'
);

Q.Template.set('Assets/amazon/response/results',
    '{{#if results}}'
    + '<ul>'
    + '{{#each results}}'
    + '<li class="Assets_amazon_results_item" data-index={{@index}} data-asin={{ASIN}}>'
    + '<img class="Assets_amazon_results_image" src="{{pic}}" alt="{{alt}}">'
    + '<div>'
    + '<span class="Assets_amazon_results_title"><h3>{{title}}</h3></span>'
    + '<span class="Assets_amazon_results_price">{{price}}</span>'
    + '</div>'
    + '<br>'
    + '</li>'
    + '{{/each}}'
    + '</ul>'
    + '{{/if}}'
);


})(window.jQuery, window);
{'fraction_non_alphanumeric': 0.13108509847640282, 'fraction_numerical': 0.0003716090672612412, 'mean_word_length': 1.3155517315551732, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '406024', 'n_tokens_mistral': 2966, 'n_tokens_neox': 2808, 'n_words': 678}