<commit_before>(function() {
  var array = wesabe.lang.array;
  var number = wesabe.lang.number;
  var date = wesabe.lang.date;
  var shared = wesabe.views.shared;
  var preferences = wesabe.data.preferences;

  var TRANSACTIONS_PER_PAGE = 30;

  wesabe.provide('views.pages.accounts', function() {
    this.init();
  });

  wesabe.views.pages.accounts.prototype = {
    // Contains the current selection for the page.
    // @type wesabe.util.Selection
    selection: null,

    // The current search term in use, if any.
    search: null,

    // References the #accounts node wrapped in a jQuery object.
    accounts: null,

    // References the #account-transactions node wrapped in a jQuery object.
    transactions: null,

    // References the #tags node wrapped in a jQuery object.
    tags: null,

    // essentially, what page of transactions are we on?
    offset: null,
    limit: TRANSACTIONS_PER_PAGE,

    // what date range should we be showing transactions in?
    start: null,
    end: null,

    // are we showing only unedited transactions?
    unedited: false,

    // have the various page components been loaded yet?
    _hasLoadedAccounts: false,
    _hasLoadedTags: false,
    _hasLoadedTransactions: false,

    init: function() {
      var self = this;

      shared
        .setPageTitle('My Accounts')
        .setCurrentTab('accounts');

      // create a shared selection for this page
      self.selection = new wesabe.util.Selection();
      self.selection.bind('changed', function(event, newsel, oldsel) {
        self.onSelectionChanged();
      });

      $.address.change(function() {
        self.attemptToReloadState();
      });

      // load all accounts view
      $('#accounts .module-header :header a, #nav-accounts > a')
        .click(function(event) {
          self.selection.clear();
          $.address.value('/accounts');
          return false;
        });

      wesabe.ready('wesabe.views.widgets.accounts.__instance__', function() {
        self.setUpAccountsWidget();
      });

      wesabe.ready('wesabe.views.widgets.account-transactions', function() {
        self.setUpTransactionWidget();
      });

      wesabe.ready('wesabe.views.widgets.tags.__instance__', function() {
        self.setUpTagsWidget();
      });

      shared.addSearchListener(function(query) {
        self.onSearch(query);
      });

      $(function(){ self.attemptToReloadState() });
    },

    onSearch: function(query) {
      this.search = query;
      this.storeState();
    },

    setUpAccountsWidget: function() {
      var self = this;

      self.accounts = wesabe.views.widgets.accounts.__instance__;
      // use the shared selection for the accounts widget's selection
      self.accounts.setSelection(self.selection);
      // wait until the accounts have loaded to try to restore selection
      function loaded() {
        self.accounts.unbind('loaded', loaded);
        self._hasLoadedAccounts = true;
        self.attemptToReloadState();
      }

      self.accounts
        .bind('loaded', loaded)
        .bind('account-updated', function() {
          // setTimeout(..., 0) cargo-culted from GWT -- I think it's like Thread.pass,
          // and won't block other callbacks to the account-updated event
          setTimeout(function() {
            self.refresh();
          }, 0);
        });

      if (self.accounts.hasDoneInitialLoad()) loaded();
    },

    setUpTransactionWidget: function() {
      var self = this;

      self.transactions = $('#account-transactions');
      // use the shared selection for the transaction widget's selection
      self.transactions.fn('selection', self.selection);
      // set the default offset/limit
      self.transactions.fn('offset', 0);
      self.transactions.fn('limit', TRANSACTIONS_PER_PAGE);
      // try to restore the selection in case this is the last widget loaded
      self._hasLoadedTransactions = true;
      self.attemptToReloadState();

      self.transactions
        // when a transaction is added/saved, reload the list, chart, accounts, and tags
        .bind('transaction-changed', function() {
          self.refreshTransactions();
          self.redrawChart();
          wesabe.data.accounts.sharedDataSource.requestData();
          wesabe.data.tags.sharedDataSource.requestData();
        })
        // toggle between All / Unedited
        .kvobserve('unedited', function(_, unedited) {
          if (self.unedited !== unedited) {
            self.unedited = unedited;
            self.storeState();
            self.reload();
          }
        })
        // handle clicking Earlier / Later buttons
        .kvobserve('offset', function(_, offset) {
          if (self.offset !== offset) {
            self.offset = offset;
            self.storeState();
            self.reload();
          }
        })
        // if the limit changes just refresh the data with the new value
        .kvobserve('limit', function(_, limit) {
          if (self.limit !== limit) {
            self.limit = limit;
            self.refresh();
          }
        });

      self.transactions.fn('transactionDataSource').subscribe({
        change: function(data) {
          self.transactions.fn('transactions', data);
        }
      });
    },

    // refreshing just means repopulating the list with new data
    refreshTransactions: function() {
      var ds = this.transactions.fn('transactionDataSource');
      ds.setParams(this.paramsForCurrentSelection());
      ds.requestData();
    },

    // reloading means clearing the list and refreshing
    reloadTransactions: function() {
      this.transactions.fn('transactions').fn('clear');
      this.transactions.fn('loading', true);
      this.refreshTransactions();
    },

    setUpTagsWidget: function() {
      var self = this;

      function loaded() {
        self.tags.unbind('loaded', loaded);
        self._hasLoadedTags = true;
        self.attemptToReloadState();
      }

      self.tags = wesabe.views.widgets.tags.__instance__;
      // use the shared selection for the tags widget's selection<commit_msg>Don't clear the list of transactions, it just slows things down.<commit_after>(function() {
  var array = wesabe.lang.array;
  var number = wesabe.lang.number;
  var date = wesabe.lang.date;
  var shared = wesabe.views.shared;
  var preferences = wesabe.data.preferences;

  var TRANSACTIONS_PER_PAGE = 30;

  wesabe.provide('views.pages.accounts', function() {
    this.init();
  });

  wesabe.views.pages.accounts.prototype = {
    // Contains the current selection for the page.
    // @type wesabe.util.Selection
    selection: null,

    // The current search term in use, if any.
    search: null,

    // References the #accounts node wrapped in a jQuery object.
    accounts: null,

    // References the #account-transactions node wrapped in a jQuery object.
    transactions: null,

    // References the #tags node wrapped in a jQuery object.
    tags: null,

    // essentially, what page of transactions are we on?
    offset: null,
    limit: TRANSACTIONS_PER_PAGE,

    // what date range should we be showing transactions in?
    start: null,
    end: null,

    // are we showing only unedited transactions?
    unedited: false,

    // have the various page components been loaded yet?
    _hasLoadedAccounts: false,
    _hasLoadedTags: false,
    _hasLoadedTransactions: false,

    init: function() {
      var self = this;

      shared
        .setPageTitle('My Accounts')
        .setCurrentTab('accounts');

      // create a shared selection for this page
      self.selection = new wesabe.util.Selection();
      self.selection.bind('changed', function(event, newsel, oldsel) {
        self.onSelectionChanged();
      });

      $.address.change(function() {
        self.attemptToReloadState();
      });

      // load all accounts view
      $('#accounts .module-header :header a, #nav-accounts > a')
        .click(function(event) {
          self.selection.clear();
          $.address.value('/accounts');
          return false;
        });

      wesabe.ready('wesabe.views.widgets.accounts.__instance__', function() {
        self.setUpAccountsWidget();
      });

      wesabe.ready('wesabe.views.widgets.account-transactions', function() {
        self.setUpTransactionWidget();
      });

      wesabe.ready('wesabe.views.widgets.tags.__instance__', function() {
        self.setUpTagsWidget();
      });

      shared.addSearchListener(function(query) {
        self.onSearch(query);
      });

      $(function(){ self.attemptToReloadState() });
    },

    onSearch: function(query) {
      this.search = query;
      this.storeState();
    },

    setUpAccountsWidget: function() {
      var self = this;

      self.accounts = wesabe.views.widgets.accounts.__instance__;
      // use the shared selection for the accounts widget's selection
      self.accounts.setSelection(self.selection);
      // wait until the accounts have loaded to try to restore selection
      function loaded() {
        self.accounts.unbind('loaded', loaded);
        self._hasLoadedAccounts = true;
        self.attemptToReloadState();
      }

      self.accounts
        .bind('loaded', loaded)
        .bind('account-updated', function() {
          // setTimeout(..., 0) cargo-culted from GWT -- I think it's like Thread.pass,
          // and won't block other callbacks to the account-updated event
          setTimeout(function() {
            self.refresh();
          }, 0);
        });

      if (self.accounts.hasDoneInitialLoad()) loaded();
    },

    setUpTransactionWidget: function() {
      var self = this;

      self.transactions = $('#account-transactions');
      // use the shared selection for the transaction widget's selection
      self.transactions.fn('selection', self.selection);
      // set the default offset/limit
      self.transactions.fn('offset', 0);
      self.transactions.fn('limit', TRANSACTIONS_PER_PAGE);
      // try to restore the selection in case this is the last widget loaded
      self._hasLoadedTransactions = true;
      self.attemptToReloadState();

      self.transactions
        // when a transaction is added/saved, reload the list, chart, accounts, and tags
        .bind('transaction-changed', function() {
          self.refreshTransactions();
          self.redrawChart();
          wesabe.data.accounts.sharedDataSource.requestData();
          wesabe.data.tags.sharedDataSource.requestData();
        })
        // toggle between All / Unedited
        .kvobserve('unedited', function(_, unedited) {
          if (self.unedited !== unedited) {
            self.unedited = unedited;
            self.storeState();
            self.reload();
          }
        })
        // handle clicking Earlier / Later buttons
        .kvobserve('offset', function(_, offset) {
          if (self.offset !== offset) {
            self.offset = offset;
            self.storeState();
            self.reload();
          }
        })
        // if the limit changes just refresh the data with the new value
        .kvobserve('limit', function(_, limit) {
          if (self.limit !== limit) {
            self.limit = limit;
            self.refresh();
          }
        });

      self.transactions.fn('transactionDataSource').subscribe({
        change: function(data) {
          self.transactions.fn('transactions', data);
        }
      });
    },

    // refreshing just means repopulating the list with new data
    refreshTransactions: function() {
      var ds = this.transactions.fn('transactionDataSource');
      ds.setParams(this.paramsForCurrentSelection());
      ds.requestData();
    },

    // reloading means hiding the list while refreshing
    reloadTransactions: function() {
      this.transactions.fn('loading', true);
      this.refreshTransactions();
    },

    setUpTagsWidget: function() {
      var self = this;

      function loaded() {
        self.tags.unbind('loaded', loaded);
        self._hasLoadedTags = true;
        self.attemptToReloadState();
      }

      self.tags = wesabe.views.widgets.tags.__instance__;
      // use the shared selection for the tags widget's selection
{'fraction_non_alphanumeric': 0.11785450668416304, 'fraction_numerical': 0.0008201427048306405, 'mean_word_length': 2.333515582285402, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5210520', 'n_tokens_mistral': 3423, 'n_tokens_neox': 3270, 'n_words': 840}