<commit_before>import {Component} from '@angular/core';
import { BackandService } from '@backand/angular2-sdk'
import { NavController, NavParams, ToastController,AlertController } from 'ionic-angular';

@Component({
  templateUrl: 'crud.html',
  selector: 'page-crud'
})

export class CrudPage {

  public email: string = '';
  description: string = 'abastecimento';
  quantidade = 0;
  consumo = 0 ;
  odometro = 0 ;
  datareg: string = '14/04/2017';

  get score() {
    let consumo = this.odometro / this.quantidade;
    return consumo;
  }

  public items:any[] = [];
  searchQuery: string;

  username:string = '';
  password:string = '';
  auth_type:string = "N/A";
  is_auth_error:boolean = false;
  auth_status:string = null;
  loggedInUser: string = '';

  constructor(
    private backand: BackandService,
    private alertCtrl: AlertController)
  {
    this.searchQuery = '';
    let that = this;
    this.backand.on("items_updated",
      (res: any) => {
        let a = res.data as any[];
        let newItem = {};
        a.forEach((kv)=> newItem[kv.Key] = kv.Value);
        that.items.unshift(newItem);
      }
    );
    this.backand.user.getUserDetails().then(
      (res: any) => {
        if(res.data) {
          this.loggedInUser = res.data.username;
          this.email = res.data.username;
          this.auth_status = 'OK';
          this.auth_type = res.data.token_type == 'Anonymous' ? 'Anonymous' : 'Token';
        }
        },
        (err: any) => {
          this.loggedInUser = null;
          this.auth_status = null;
          this.auth_type = null;
        }
      );
  }

  public mostraAlerta() {
  let alert = this.alertCtrl.create({
    title: 'Low battery',
    subTitle: '10% of battery remaining',
    buttons: ['Dismiss']
  });
  alert.present();
}

  public postItem() {
    let item = {
      email: this.loggedInUser,
      description: this.description,
      quantidade: this.quantidade,
      consumo: this.consumo,
      odometro: this.odometro,
      datareg: this.datareg
    };

    let sum = this.odometro / this.quantidade;
    let alert = this.alertCtrl.create({
      title: 'Consumo',
      subTitle: 'alo',
      buttons: ['Dismiss']
    });
    alert.present();

    if (item.email && item.description)
    {
      this.backand.object.create('todo', item)
      .then((res: any) => {
        // add to beginning of array
        // this.items.unshift({ id: null, name: this.name, description: this.description, idlogin: this.loggedInUser });
        // this.name = '';
        // this.description = '';
      },
      (err: any) => {<commit_msg>noite<commit_after>import {Component} from '@angular/core';
import { BackandService } from '@backand/angular2-sdk'
import { AlertController } from 'ionic-angular';

@Component({
  templateUrl: 'crud.html',
  selector: 'page-crud'
})

export class CrudPage {

  public email: string = '';
  description: string = 'abastecimento';
  quantidade: number;
  consumo: number;
  odometro: number;
  datareg: string = '14/04/2017';
  dataregistro: string;

  get score() {
    let consumo = this.odometro / this.quantidade;
    return consumo;
  }

  public items:any[] = [];
  searchQuery: string;

  username:string = '';
  password:string = '';
  auth_type:string = "N/A";
  is_auth_error:boolean = false;
  auth_status:string = null;
  loggedInUser: string = '';

  constructor(
    private backand: BackandService,
    public alertCtrl: AlertController)
  {
    this.searchQuery = '';
    let that = this;
    this.backand.on("items_updated",
      (res: any) => {
        let a = res.data as any[];
        let newItem = {};
        a.forEach((kv)=> newItem[kv.Key] = kv.Value);
        that.items.unshift(newItem);
      }
    );
    this.backand.user.getUserDetails().then(
      (res: any) => {
        if(res.data) {
          this.loggedInUser = res.data.username;
          this.email = res.data.username;
          this.auth_status = 'OK';
          this.auth_type = res.data.token_type == 'Anonymous' ? 'Anonymous' : 'Token';
        }
        },
        (err: any) => {
          this.loggedInUser = null;
          this.auth_status = null;
          this.auth_type = null;
        }
      );
  }

  mostraAlerta() {
      let alert = this.alertCtrl.create({
        title: 'Consumo',
        message: 'Your friend, <NAME> Kenobi, just approved your friend request!',
        buttons: ['Ok']
      });
      alert.present()
    }

  public postItem() {
    let mileage = this.odometro / this.quantidade;

    let item = {
      email: this.loggedInUser,
      description: this.description,
      quantidade: this.quantidade,
      odometro: this.odometro,
      consumo: mileage,
      datareg: this.datareg
    };

    if (item.email && item.description)
    {
      this.backand.object.create('todo', item)
      .then((res: any) => {
        // add to beginning of array
        // this.items.unshift({ id: null, name: this.name, description: this.description, idlogin: this.loggedInUser });
        // this.name = '';
        // this.description = '';
      },
      (err: any) => {
{'fraction_non_alphanumeric': 0.14585375416584984, 'fraction_numerical': 0.004508919819643208, 'mean_word_length': 2.390033222591362, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, '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': '4296254', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1652, 'n_words': 349}