<commit_before>import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';

import { PageScrollService, PageScrollInstance } from 'ng2-page-scroll';

import { AuthorizationService } from '../service/auth.service';
import { Transaction, TransactionComponent, TransactionsService } from '../service/transactions.service';

@Component({
  templateUrl: '../templates/components/transactions.pug'
})

export class TransactionsComponent {
  private editingTransaction: Transaction;

  totalsByCurrency(transaction: Transaction): {currency: string; amount: any;}[] {
    var totals = [];
    var totalsCurrency = this.transactionsService.totalsByCurrency(transaction);
    for(var currency in totalsCurrency){
      totals.push({currency: currency, amount: totalsCurrency[currency]});
    }
    return totals;
  }
  addTransaction() {
    var transaction = new Transaction();
    transaction.FinanceTransactionComponents = [];
    transaction.date = this.transactionsService.getDate();
    transaction.tags = [];
    transaction.type = this.transactionsService.defaultTransactionType.value;
    this.transactionsService.transactions.unshift(transaction);
    this.startEditing(transaction);
  }
  isEditing(transaction: Transaction): boolean {
    return this.editingTransaction === transaction;
  }
  startEditing(transaction: Transaction) {
    this.editingTransaction = transaction;
    if (transaction.id === undefined) {
      let pageScrollInstance: PageScrollInstance = PageScrollInstance.simpleInstance(this.document, '#transactionsStart');
      this.pageScrollService.start(pageScrollInstance);
    }
  }
  stopEditing() {
    this.editingTransaction = undefined;<commit_msg>Fixed a bug where a user could create multiple transactions (but edit only one of them).<commit_after>import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';

import { PageScrollService, PageScrollInstance } from 'ng2-page-scroll';

import { AuthorizationService } from '../service/auth.service';
import { Transaction, TransactionComponent, TransactionsService } from '../service/transactions.service';

@Component({
  templateUrl: '../templates/components/transactions.pug'
})

export class TransactionsComponent {
  private editingTransaction: Transaction;

  totalsByCurrency(transaction: Transaction): {currency: string; amount: any;}[] {
    var totals = [];
    var totalsCurrency = this.transactionsService.totalsByCurrency(transaction);
    for(var currency in totalsCurrency){
      totals.push({currency: currency, amount: totalsCurrency[currency]});
    }
    return totals;
  }
  addTransaction() {
    if(this.editingTransaction !== undefined) {
      this.editingTransaction = undefined;
      var prepare = () => {
        this.addTransaction();
      }
      this.transactionsService.update().subscribe(prepare, prepare);
      return;
    }
    var transaction = new Transaction();
    transaction.FinanceTransactionComponents = [];
    transaction.date = this.transactionsService.getDate();
    transaction.tags = [];
    transaction.type = this.transactionsService.defaultTransactionType.value;
    this.transactionsService.transactions.unshift(transaction);
    this.startEditing(transaction);
  }
  isEditing(transaction: Transaction): boolean {
    return this.editingTransaction === transaction;
  }
  startEditing(transaction: Transaction) {
    this.editingTransaction = transaction;
    if (transaction.id === undefined) {
      let pageScrollInstance: PageScrollInstance = PageScrollInstance.simpleInstance(this.document, '#transactionsStart');
      this.pageScrollService.start(pageScrollInstance);
    }
  }
  stopEditing() {
    this.editingTransaction = undefined;
{'fraction_non_alphanumeric': 0.11332271762208068, 'fraction_numerical': 0.0005307855626326964, 'mean_word_length': 4.727963525835866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6802045', 'n_tokens_mistral': 964, 'n_tokens_neox': 968, 'n_words': 202}