<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

/**
 * @fileoverview This library provides functions for navigating to and dealing
 *     with views of the current gadget.
 */

var gadgets = gadgets || {};

/**
 * Implements the gadgets.views API spec. See
 * http://code.google.com/apis/gadgets/docs/reference/gadgets.views.html
 */
gadgets.views = function() {

  /**
   * Reference to the current view object.
   */
  var currentView = null;

  /**
   * Map of all supported views for this container.
   */
  var supportedViews = {};

  /**
   * Map of parameters passed to the current request.
   */
  var params = {};

  return {
    requestNavigateTo : function(view, opt_params) {
      // TODO: Actually implementing this is going to require gadgets.rpc or
      // ifpc or something.
      var prefs = new gadgets.Prefs();
      var ifpcRelay = gadgets.util.getUrlParameters().parent || '';
      gadgets.ifpc_.call("remote_iframe_" + prefs.getModuleId(),
                         "requestNavigateTo",
                         [view.getName(), opt_params],
                         ifpcRelay,
                         null,
                         '');
    },

    getCurrentView : function() {
      return currentView;
    },

    getSupportedViews : function() {
      return supportedViews;
    },

    getParams : function() {
      return params;
    },

    /**
     * Initializes views. Assumes that the current view is the "view"
     * url parameter (or default if "view" isn't supported), and that
     * all view parameters are in the form view-<name>
     * TODO: Use unified configuration when it becomes available.
     * @param {Map&lt;String, Boolean&gt;} supported The views you support,
     *   where keys = name of the view and values = isOnlyVisible
     */
    init : function(supported) {
      if (typeof supported["default"] === "undefined") {
        throw new Error("default view required!");
      }

      for (var s in supported) if (supported.hasOwnProperty(s)) {
        supportedViews[s] = new gadgets.views.View(s, supported[s]);
      }

      var urlParams = gadgets.util.getUrlParameters();
      // View parameters are passed as a single parameter.
      if (urlParams["view-params"]) {
        var tmpParams = gadgets.json.parse(urlParams["view-params"]);
        if (tmpParams) {
          params = tmpParams;
        }
      }
      currentView = supportedViews[urlParams.view] || supportedViews["default"];
    }
  };
}();

gadgets.views.View = function(name, opt_isOnlyVisible) {
  this.name_ = name;
  this.isOnlyVisible_ = !!opt_isOnlyVisible;
};

gadgets.views.View.prototype.getName = function() {
  return this.name_;
};

gadgets.views.View.prototype.isOnlyVisibleGadget = function() {
  return this.isOnlyVisible_;
};

gadgets.views.ViewType = gadgets.util.makeEnum([
  "FULL_PAGE", "DASHBOARD", "POPUP"
]);<commit_msg>Fixes for gadgets.views and requestNavigateTo<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

/**
 * @fileoverview This library provides functions for navigating to and dealing
 *     with views of the current gadget.
 */

var gadgets = gadgets || {};

/**
 * Implements the gadgets.views API spec. See
 * http://code.google.com/apis/gadgets/docs/reference/gadgets.views.html
 */
gadgets.views = function() {

  /**
   * Reference to the current view object.
   */
  var currentView = null;

  /**
   * Map of all supported views for this container.
   */
  var supportedViews = {};

  /**
   * Map of parameters passed to the current request.
   */
  var params = {};

  return {
    requestNavigateTo : function(view, opt_params) {
      // TODO: Actually implementing this is going to require gadgets.rpc or
      // ifpc or something.
      var prefs = new gadgets.Prefs();
      var ifpcRelay = gadgets.util.getUrlParameters().parent || '';
      gadgets.ifpc_.call("remote_iframe_" + prefs.getModuleId(),
                         "requestNavigateTo",
                        ["remote_iframe_" + prefs.getModuleId(),
                          view.getName(),
                         opt_params],
                         ifpcRelay,
                         null,
                         '');
    },

    getCurrentView : function() {
      return currentView;
    },

    getSupportedViews : function() {
      return supportedViews;
    },

    getParams : function() {
      return params;
    },

    /**
     * Initializes views. Assumes that the current view is the "view"
     * url parameter (or default if "view" isn't supported), and that
     * all view parameters are in the form view-<name>
     * TODO: Use unified configuration when it becomes available.
     * @param {Map&lt;String, Boolean&gt;} supported The views you support,
     *   where keys = name of the view and values = isOnlyVisible
     */
    init : function(supported) {
      if (typeof supported["default"] === "undefined") {
        throw new Error("default view required!");
      }

      for (var s in supported) if (supported.hasOwnProperty(s)) {
        supportedViews[s] = new gadgets.views.View(s, supported[s]);
      }

      var urlParams = gadgets.util.getUrlParameters();
      // View parameters are passed as a single parameter.
      if (urlParams["view-params"]) {
        var tmpParams = gadgets.json.parse(
            decodeURIComponent(urlParams["view-params"]));
        if (tmpParams) {
          params = tmpParams;
        }
      }
      currentView = supportedViews[urlParams.view] || supportedViews["default"];
    }
  };
}();

gadgets.views.View = function(name, opt_isOnlyVisible) {
  this.name_ = name;
  this.isOnlyVisible_ = !!opt_isOnlyVisible;
};

gadgets.views.View.prototype.getName = function() {
  return this.name_;
};

gadgets.views.View.prototype.isOnlyVisibleGadget = function() {
  return this.isOnlyVisible_;
};

gadgets.views.ViewType = gadgets.util.makeEnum([
  "FULL_PAGE", "DASHBOARD", "POPUP"
]);
{'fraction_non_alphanumeric': 0.10635155096011817, 'fraction_numerical': 0.001074258090506244, 'mean_word_length': 2.6743956586087814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3479036', 'n_tokens_mistral': 2079, 'n_tokens_neox': 2016, 'n_words': 669}