<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed 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
 */

CLASS({
  package: 'foam.apps.builder',
  name: 'AppLoader',
  extendsModel: 'foam.ui.View',
  traits: [
    'foam.apps.builder.TrackLaunchCloseTrait',
  ],

  documentation: function() {/*
    Used by exported App Builder apps to load the desired model and view.
  */},

  requires: [
    'com.google.analytics.AnalyticsDAO',
    'foam.core.dao.SplitDAO',
    'foam.dao.NullDAO',
    'foam.dao.ProxyDAO',
    'foam.metrics.Metric',
    'foam.ui.md.FlatButton',
    'foam.ui.md.SharedStyles',
  ],
  imports: [
    'appConfig as data',
    'document',
  ],
  exports: [
    'metricsDAO',
  ],

  constants: {
    CONFIG_PATH: 'config.json',
  },

  properties: [
    {
      name: 'data',
      postSet: function(old, nu) {
        if ( old === nu ) return;
        this.configure(nu);
        this.updateView(nu);
      },
    },
    {
      model_: 'ViewFactoryProperty',
      name: 'delegate',
    },
    {
      model_: 'foam.core.types.DAOProperty',
      name: 'metricsDAO',
      factory: function() { return this.ProxyDAO.create({}, this.Y); },
    },
    {
      model_: 'foam.core.types.DAOProperty',
      type: 'com.google.analytics.AnalyticsDAO',
      name: 'appMetricsDAO',
    },
    {
      model_: 'foam.core.types.DAOProperty',
      type: 'com.google.analytics.AnalyticsDAO',
      name: 'appBuilderMetricsDAO',
    },
    {
      name: 'hasAppBuilderMetricsDAO',
      getter: function() {
        return this.data && this.data.appBuilderAnalyticsEnabled;
      },
    },
    {
      name: 'hasAppMetricsDAO',
      getter: function() {
        return this.data && this.data.analyticsId;
      },
    },
    {
      model_: 'FunctionProperty',
      name: 'appMetricsDAOFactory',
      defaultValue: function(data) {
        if ( ! data ) return this.NullDAO.create({}, this.Y);
        return this.AnalyticsDAO.create({
          storageName: 'App-' + data.appId + '-operations',
          daoType: 'XHR',
          propertyId: data.analyticsId,
          appName: data.appName,
          appVersion: data.version,
          endpoint: 'https://www.google-analytics.com/collect',
        }, this.Y);
      },
    },
    {
      model_: 'FunctionProperty',
      name: 'appBuilderMetricsDAOFactory',
      defaultValue: function(data) {
        if ( ! data ) return this.NullDAO.create({}, this.Y);
        return this.AnalyticsDAO.create({
          storageName: 'AppBuilder-' + data.appId + '-operations',
          daoType: 'XHR',
          debug: true,
          propertyId: 'UA-47217230-7',
          appName: data.appName,
          appVersion: data.version,
          endpoint: 'https://www.google-analytics.com/collect',
          debugEndpoint: 'https://www.google-analytics.com/debug/collect',
        }, this.Y);
      },
    },
  ],

  methods: [
    function init() {
      this.SUPER();

      this.SharedStyles.create({}, this.Y);

      // Mimic behaviour of foam.browser.BrowserView.
      this.Y.registerModel(this.FlatButton.xbind({
        displayMode: 'ICON_ONLY',
        height: 24,
        width: 24,
      }), 'foam.ui.ActionButton');
    },
    function initHTML() {
      this.SUPER();
      if ( ! this.parent ) this.document.title = this.data.appName;
    },
    function configure(data) {
      if ( ! data ) return;

      // Report analytics under category: [App ID].<commit_msg>App Builder: Remove debug analytics backend from App Builder tracking of built apps. For some reason this is introducing a problem with real time reporting (but, no problem, it is just for debugging anyway). Towards #356 and #357<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed 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
 */

CLASS({
  package: 'foam.apps.builder',
  name: 'AppLoader',
  extendsModel: 'foam.ui.View',
  traits: [
    'foam.apps.builder.TrackLaunchCloseTrait',
  ],

  documentation: function() {/*
    Used by exported App Builder apps to load the desired model and view.
  */},

  requires: [
    'com.google.analytics.AnalyticsDAO',
    'foam.core.dao.SplitDAO',
    'foam.dao.NullDAO',
    'foam.dao.ProxyDAO',
    'foam.metrics.Metric',
    'foam.ui.md.FlatButton',
    'foam.ui.md.SharedStyles',
  ],
  imports: [
    'appConfig as data',
    'document',
  ],
  exports: [
    'metricsDAO',
  ],

  constants: {
    CONFIG_PATH: 'config.json',
  },

  properties: [
    {
      name: 'data',
      postSet: function(old, nu) {
        if ( old === nu ) return;
        this.configure(nu);
        this.updateView(nu);
      },
    },
    {
      model_: 'ViewFactoryProperty',
      name: 'delegate',
    },
    {
      model_: 'foam.core.types.DAOProperty',
      name: 'metricsDAO',
      factory: function() { return this.ProxyDAO.create({}, this.Y); },
    },
    {
      model_: 'foam.core.types.DAOProperty',
      type: 'com.google.analytics.AnalyticsDAO',
      name: 'appMetricsDAO',
    },
    {
      model_: 'foam.core.types.DAOProperty',
      type: 'com.google.analytics.AnalyticsDAO',
      name: 'appBuilderMetricsDAO',
    },
    {
      name: 'hasAppBuilderMetricsDAO',
      getter: function() {
        return this.data && this.data.appBuilderAnalyticsEnabled;
      },
    },
    {
      name: 'hasAppMetricsDAO',
      getter: function() {
        return this.data && this.data.analyticsId;
      },
    },
    {
      model_: 'FunctionProperty',
      name: 'appMetricsDAOFactory',
      defaultValue: function(data) {
        if ( ! data ) return this.NullDAO.create({}, this.Y);
        return this.AnalyticsDAO.create({
          storageName: 'App-' + data.appId + '-operations',
          daoType: 'XHR',
          propertyId: data.analyticsId,
          appName: data.appName,
          appVersion: data.version,
          endpoint: 'https://www.google-analytics.com/collect',
        }, this.Y);
      },
    },
    {
      model_: 'FunctionProperty',
      name: 'appBuilderMetricsDAOFactory',
      defaultValue: function(data) {
        if ( ! data ) return this.NullDAO.create({}, this.Y);
        return this.AnalyticsDAO.create({
          storageName: 'AppBuilder-' + data.appId + '-operations',
          daoType: 'XHR',
          propertyId: 'UA-47217230-7',
          appName: data.appName,
          appVersion: data.version,
          endpoint: 'https://www.google-analytics.com/collect',
        }, this.Y);
      },
    },
  ],

  methods: [
    function init() {
      this.SUPER();

      this.SharedStyles.create({}, this.Y);

      // Mimic behaviour of foam.browser.BrowserView.
      this.Y.registerModel(this.FlatButton.xbind({
        displayMode: 'ICON_ONLY',
        height: 24,
        width: 24,
      }), 'foam.ui.ActionButton');
    },
    function initHTML() {
      this.SUPER();
      if ( ! this.parent ) this.document.title = this.data.appName;
    },
    function configure(data) {
      if ( ! data ) return;

      // Report analytics under category: [App ID].
{'fraction_non_alphanumeric': 0.14480064655172414, 'fraction_numerical': 0.00646551724137931, 'mean_word_length': 2.28104286345559, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 7, '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': '2116070', 'n_tokens_mistral': 2423, 'n_tokens_neox': 2373, 'n_words': 490}