<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
 *
 * 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.
 */

CLASS({
  package: 'foam.u2',
  name: 'DAOListView',
  extends: 'foam.u2.View',

  requires: [
    'foam.u2.DetailView',
    'foam.u2.md.CitationView',
  ],
  imports: [
    'selection$',
  ],

  constants: {
    ROW_CLICK: ['row-click'],
  },

  properties: [
    {
      model_: 'foam.core.types.DAOProperty',
      name: 'data',
      postSet: function(old, nu) {
        this.dao = nu;
      },
    },
    {
      // Separate from data so it can be a DAOProperty.
      model_: 'foam.core.types.DAOProperty',
      name: 'dao',
    },
    {
      name: 'daoListener_',
      lazyFactory: function() {
        return {
          put: this.onDAOPut,
          remove: this.onDAORemove,
          reset: this.onDAOReset
        };
      }
    },
    {
      type: 'ViewFactory',
      name: 'rowView',
    },
    {
      name: 'rows',
      factory: function() {
        return {};
      }
    },
    ['nodeName', 'div']
  ],
  templates: [
    function CSS() {/*
      .foam-u2-DAOListView {
      }
    */}
  ],
  methods: [
    function initE() {
      this.dao$Proxy.pipe(this.daoListener_);
      this.cls('foam-u2-DAOListView');
    },
  ],
  listeners: [
    {
      name: 'onDAOPut',
      code: function(obj) {
        if ( this.rows[obj.id] ) {
          this.rows[obj.id].data = obj;
          return;
        }

        var Y = this.Y.sub({ data: obj });

        var child = this.rowView ?
            this.rowView({ data: obj }, Y) :
            obj.toRowE ? obj.toRowE(Y) :
            obj.toE ? obj.toE(Y) :
            this.DetailView.create({ data: obj }, Y);

        child.on('click', function() {
          this.publish(this.ROW_CLICK);
          this.selection = obj;
        }.bind(this));

        this.rows[obj.id] = child;
        this.add(child);
      }
    },
    {
      name: 'onDAORemove',
      code: function(obj) {
        if ( this.rows[obj.id] ) {<commit_msg>foam.u2.DAOListView: Include the object in ROW_CLICK events.  Default to CitationView instead of DetailView.<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
 *
 * 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.
 */

CLASS({
  package: 'foam.u2',
  name: 'DAOListView',
  extends: 'foam.u2.View',

  requires: [
    'foam.u2.DetailView',
    'foam.u2.md.CitationView',
  ],
  imports: [
    'selection$',
  ],

  constants: {
    ROW_CLICK: ['row-click'],
  },

  properties: [
    {
      model_: 'foam.core.types.DAOProperty',
      name: 'data',
      postSet: function(old, nu) {
        this.dao = nu;
      },
    },
    {
      // Separate from data so it can be a DAOProperty.
      model_: 'foam.core.types.DAOProperty',
      name: 'dao',
    },
    {
      name: 'daoListener_',
      lazyFactory: function() {
        return {
          put: this.onDAOPut,
          remove: this.onDAORemove,
          reset: this.onDAOReset
        };
      }
    },
    {
      type: 'ViewFactory',
      name: 'rowView',
    },
    {
      name: 'rows',
      factory: function() {
        return {};
      }
    },
    ['nodeName', 'div']
  ],
  templates: [
    function CSS() {/*
      .foam-u2-DAOListView {
      }
    */}
  ],
  methods: [
    function initE() {
      this.dao$Proxy.pipe(this.daoListener_);
      this.cls('foam-u2-DAOListView');
    },
  ],
  listeners: [
    {
      name: 'onDAOPut',
      code: function(obj) {
        if ( this.rows[obj.id] ) {
          this.rows[obj.id].data = obj;
          return;
        }

        var Y = this.Y.sub({ data: obj });

        var child = this.rowView ?
            this.rowView({ data: obj }, Y) :
            obj.toRowE ? obj.toRowE(Y) :
            obj.toE ? obj.toE(Y) :
            this.CitationView.create({ data: obj }, Y);

        child.on('click', function() {
          this.publish(this.ROW_CLICK, obj);
          this.selection = obj;
        }.bind(this));

        this.rows[obj.id] = child;
        this.add(child);
      }
    },
    {
      name: 'onDAORemove',
      code: function(obj) {
        if ( this.rows[obj.id] ) {
{'fraction_non_alphanumeric': 0.1403779406093328, 'fraction_numerical': 0.0055919784033937525, 'mean_word_length': 1.9488345650938033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5077379', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1707, 'n_words': 415}