<commit_before>import {Common} from '../common';
import {Node} from './node';
import {Utility} from '../utility';

export class TreeNode extends Node{
  static inject() { return [Common, Element, Utility]; }
  constructor(common, element, utility){
    super();
    this.common = common;
    this.element = element;
    this.utility = utility;

    this.node =  null;
    this.node_id = null;
    this.url = "";
    this.title = null
    this.collapsed = null;
    this.children = null;
    this.metaRef = null;
    this.meta = null;
  }

  activate(model){
    // console.log("activate, model.node_id:"+model.node_id)
    this.node_id = model.node_id;
    this.parentVM = model.parentVM;
    this.treeVM = model.parentVM.treeVM;
    this.parentVM.addChildVM(this, this.node_id);

    var that = this;
    this.nodeRef = this.treeVM.dirNodesRef.child(this.node_id);
    this.nodeRef.on('value', function(dataSnapshot) {
      if (that.treeVM.editing) return;
      console.log("this.nodeRef.on('value', model.node_id:"+model.node_id)
      var data = dataSnapshot.val();
      console.log(data)
      if (!data) return;
      that.node = data;
      if (!that.node.children) that.node.children = [];
    });

    this.metaRef = this.treeVM.filesRef.child(this.node_id).child("meta");
    this.metaRef.on('value', function(dataSnapshot) {
      if (that.treeVM.editing) return;
      var data = dataSnapshot.val();
      if (!data) return;
      that.meta = data;
      console.log(that.meta)
      if ("directory" != that.meta.type) {
        that.url = "./#" + that.meta.type + "/online/" + that.meta.id + "/root";
      }
    });
  }

  cut() {
    this.treeVM.selectedVMList.push(this);
    this.treeVM.cut();
  }
}<commit_msg>[Feature] Collapse directory.<commit_after>import {Common} from '../common';
import {Node} from './node';
import {Utility} from '../utility';

export class TreeNode extends Node{
  static inject() { return [Common, Element, Utility]; }
  constructor(common, element, utility){
    super();
    this.common = common;
    this.element = element;
    this.utility = utility;

    this.node =  null;
    this.node_id = null;
    this.url = "";
    this.title = null
    this.collapsed = null;
    this.children = null;
    this.metaRef = null;
    this.meta = null;
  }

  activate(model){
    // console.log("activate, model.node_id:"+model.node_id)
    this.node_id = model.node_id;
    this.parentVM = model.parentVM;
    this.treeVM = model.parentVM.treeVM;
    this.parentVM.addChildVM(this, this.node_id);

    var that = this;
    this.nodeRef = this.treeVM.dirNodesRef.child(this.node_id);
    this.nodeRef.on('value', function(dataSnapshot) {
      if (that.treeVM.editing) return;
      console.log("this.nodeRef.on('value', model.node_id:"+model.node_id)
      var data = dataSnapshot.val();
      console.log(data)
      if (!data) return;
      that.node = data;
      if (!that.node.children) that.node.children = [];
    });

    this.metaRef = this.treeVM.filesRef.child(this.node_id).child("meta");
    this.metaRef.on('value', function(dataSnapshot) {
      if (that.treeVM.editing) return;
      var data = dataSnapshot.val();
      if (!data) return;
      that.meta = data;
      console.log(that.meta)
      if ("directory" != that.meta.type) {
        that.url = "./#" + that.meta.type + "/online/" + that.meta.id + "/root";
      }
    });
  }

  cut() {
    this.treeVM.selectedVMList.push(this);
    this.treeVM.cut();
  }

  toggle() {
    if ("directory" != this.meta.type) return;
    this.meta.collapsed = !this.meta.collapsed;
    this.treeVM.filesRef.child(this.node.id).child("/meta/collapsed").set(this.meta.collapsed);
  }
}
{'fraction_non_alphanumeric': 0.16363636363636364, 'fraction_numerical': 0.0, 'mean_word_length': 2.823651452282158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6789415', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1239, 'n_words': 230}