<commit_before>import React, {Component} from 'react';
import axios from 'axios';
import HmkList from './HmkList';
import HmkCreateEdit from './HmkCreateEdit';
import NavBar from './NavBar';
import Login from './Login';
import Filter from './Filter';
import * as api from '../api';

class SmartPlanner extends Component {
  constructor(props) {
    super(props);

    this.state = {
      hmks : [],
      login: 'show',
      createEditShow: 'hidden',
      userEditShow: 'hidden',
      hmkEditor: 'hidden',
      user: {'user_name':''},
      category: 'history',
      order: 'priorized'
    }

  }

  /*obtiene al usurio con username dado*/
  getUser = (username, callback, errCallback) => { api.getUser(username, (user)=>{
                                                          console.log('este '+user);
                                                          this.setState({'user':user});
                                                          if(callback) callback(user);
                                                        }, errCallback)};

  /*Obtiene las tareas con parametros dados*/
  getHmks = (userId, category, order, callback, errCallback) => { api.getHmks(userId, category, order, callback, errCallback)};

  /*establece el nuevo usuario actual*/
  setUser = ( obj ) => {
    console.log("set user");
    console.log(obj);
    this.getHmks(obj[0]._id, this.state.category, this.state.order, (hmks)=>{ //se estan pidiendo inicialmente todas las tareas
        console.log('tareas');
        console.log(hmks);
        this.setState({login:'hidden', user:obj[0], hmks: hmks});
      });
  };

  //resetHmk = ()=>{};

  resetCreateForm = (callback) => {
    this.resetHmk = (obj, str) => {callback(obj, str);}
  };

  resetEditView = (obj, str) =>{
    this.resetHmk(obj, str);
  };

  /*Actualiza las tareas teniendo en cuenta parametros de filtro cambiados*/
  updateQuery = (query) => {
    var userId = this.state.user._id;
    var category = query.category || this.state.category;
    var order = query.order || this.state.order;
    this.setState({category:category,
                   order:order});
    this.getHmks(userId, category, order, (hmks)=>{
        console.log('tareas actualizadas por filtro');
        console.log(hmks);
        this.setState({'hmks': hmks});
      });
  }

  /*Agregar tarea al usurio actual*/
  postHmk = (hmk, str, errCallback, callback) => {
    if(str === 'Editar'){
      this.updateHmk(hmk, errCallback);
    }else{
    var userId = this.state.user._id;
    api.addHmkToUser(userId, hmk,(resp) => {
      console.log('Respuesta post tarea');
      console.log(resp);
      callback();
      this.updateQuery({});
    }, errCallback);
    }
  }

  /*Elimina una tarea del usuario actual*/
  deleteHmk = (hmkId, errCallback) => {
    var userId = this.state.user._id;
    api.deleteHmk(userId, hmkId, (resp) => {
      console.log('Respuesta delete tarea');
      console.log(resp);
      this.updateQuery({});
    }, errCallback);
  }

  /*Actualiza una tarea*/
  updateHmk = (hmk, errCallback) => {
    var userId = this.state.user._id;
    var hmkId = hmk._id;
    hmk.done_percentage = hmk.done_percentage;
    api.updateHmk(userId, hmkId, hmk, (resp) => {
      console.log('Respuesta put tarea');
      console.log(resp);
      this.updateQuery({});
    }, errCallback);
  }

  /*Agregar tarea al usurio actual*/
  postUser = (user, errCallback, callback) => {
    var userId = this.state.user._id;
    api.updateUser(userId, user,(resp) => {
      console.log('Respuesta post usuario');
      console.log(resp);
      callback();
      this.getUser(user.user_name);
    }, errCallback);
  }

  render() {
    console.log('SP');
    console.log(this);
    return(
      <div>
        <Login getUser={this.getUser} setUser={this.setUser} user={this.state.user} login={this.state.login}/>
        <NavBar user={this.state.user} postUser={this.postUser} postHmk={this.postHmk} toggleLogin={(loginState) => {this.setState({login: loginState})}}
                                       toggleAddHmk={(addState) => {this.setState({createEditShow: addState})}}
                                        addHmk={this.state.createEditShow}
                                        toggleEditUser={(addState)=>{this.setState({userEditShow: addState})}}
                                        editUser={this.state.userEditShow} resetCreateForm={this.resetCreateForm}/>
        <div className="row">
        <HmkList user={this.state.user} hmkList={this.state.hmks} updateHmk={this.updateHmk} deleteHmk={this.deleteHmk}<commit_msg>pequeños cambios<commit_after>import React, {Component} from 'react';
import axios from 'axios';
import HmkList from './HmkList';
import HmkCreateEdit from './HmkCreateEdit';
import NavBar from './NavBar';
import Login from './Login';
import Filter from './Filter';
import * as api from '../api';

class SmartPlanner extends Component {
  constructor(props) {
    super(props);

    this.state = {
      hmks : [],
      login: 'show',
      createEditShow: 'hidden',
      userEditShow: 'hidden',
      hmkEditor: 'hidden',
      user: {'user_name':''},
      category: 'history',
      order: 'priorized'
    }

  }

  /*obtiene al usurio con username dado*/
  getUser = (username, callback, errCallback) => { api.getUser(username, (user)=>{
                                                          console.log('este '+user);
                                                          this.setState({'user':user});
                                                          if(callback) callback(user);
                                                        }, errCallback)};

  /*Obtiene las tareas con parametros dados*/
  getHmks = (userId, category, order, callback, errCallback) => { api.getHmks(userId, category, order, callback, errCallback)};

  /*establece el nuevo usuario actual*/
  setUser = ( obj ) => {
    console.log("set user");
    console.log(obj);
    this.getHmks(obj[0]._id, this.state.category, this.state.order, (hmks)=>{ //se estan pidiendo inicialmente todas las tareas
        console.log('tareas');
        console.log(hmks);
        this.setState({login:'hidden', user:obj[0], hmks: hmks});
      });
  };

  //resetHmk = ()=>{};

  resetCreateForm = (callback) => {
    this.resetHmk = (obj, str) => {callback(obj, str);}
  };

  resetEditView = (obj, str) =>{
    this.resetHmk(obj, str);
  };

  /*Actualiza las tareas teniendo en cuenta parametros de filtro cambiados*/
  updateQuery = (query) => {
    var userId = this.state.user._id;
    var category = query.category || this.state.category;
    var order = query.order || this.state.order;
    this.setState({category:category,
                   order:order});
    this.getHmks(userId, category, order, (hmks)=>{
        console.log('tareas actualizadas por filtro');
        console.log(hmks);
        this.setState({'hmks': hmks});
      });
  }

  /*Agregar tarea al usurio actual*/
  postHmk = (hmk, str, errCallback, callback) => {
    if(str === 'Editar'){
      this.updateHmk(hmk, errCallback, callback);
    }else{
    var userId = this.state.user._id;
    api.addHmkToUser(userId, hmk,(resp) => {
      console.log('Respuesta post tarea');
      console.log(resp);
      callback();
      this.updateQuery({});
    }, errCallback);
    }
  }

  /*Elimina una tarea del usuario actual*/
  deleteHmk = (hmkId, errCallback) => {
    var userId = this.state.user._id;
    api.deleteHmk(userId, hmkId, (resp) => {
      console.log('Respuesta delete tarea');
      console.log(resp);
      this.updateQuery({});
    }, errCallback);
  }

  /*Actualiza una tarea*/
  updateHmk = (hmk, errCallback, callback) => {
    var userId = this.state.user._id;
    var hmkId = hmk._id;
    hmk.done_percentage = hmk.done_percentage;
    api.updateHmk(userId, hmkId, hmk, (resp) => {
      console.log('Respuesta put tarea');
      console.log(resp);
      callback();
      this.updateQuery({});
    }, errCallback);
  }

  /*Agregar tarea al usurio actual*/
  postUser = (user, errCallback, callback) => {
    var userId = this.state.user._id;
    api.updateUser(userId, user,(resp) => {
      console.log('Respuesta post usuario');
      console.log(resp);
      callback();
      this.getUser(user.user_name);
    }, errCallback);
  }

  render() {
    console.log('SP');
    console.log(this);
    return(
      <div>
        <Login getUser={this.getUser} setUser={this.setUser} user={this.state.user} login={this.state.login}/>
        <NavBar user={this.state.user} postUser={this.postUser} postHmk={this.postHmk} toggleLogin={(loginState) => {this.setState({login: loginState})}}
                                       toggleAddHmk={(addState) => {this.setState({createEditShow: addState})}}
                                        addHmk={this.state.createEditShow}
                                        toggleEditUser={(addState)=>{this.setState({userEditShow: addState})}}
                                        editUser={this.state.userEditShow} resetCreateForm={this.resetCreateForm}/>
        <div className="row">
        <HmkList user={this.state.user} hmkList={this.state.hmks} updateHmk={this.updateHmk} deleteHmk={this.deleteHmk}
{'fraction_non_alphanumeric': 0.15183700010837758, 'fraction_numerical': 0.00043351035005960767, 'mean_word_length': 2.401400663472171, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5605078', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2875, 'n_words': 587}