<commit_before>import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Moment } from 'moment';
import * as moment from 'moment';
import { DataOfferService } from '../../data-management/data-offer.service';
import {Subscription, Observable} from 'rxjs/Rx';

declare var $: any;

@Component({
  selector: 'rump-offer-modal',
  templateUrl: './offer-modal.component.html',
  styleUrls: ['./offer-modal.component.scss']
})

export class OfferModalComponent implements OnInit {
  @Input() offer_index: number;
  @Input() offers: any;

  @Input() changeModal: Function;
  @Input() statsComponent: any;
  @Input() offerMode = 'untouched';

  public timeNow = Date.now();
  public claimSub: Subscription;
  private destroy: Function;
  public claimDisabled = true;
  public scrollTop: number;
  public offerDuration: number;
  public scrollShadow = false;
  public btnIcon = '';
  public btnText = 'Accept';
  public navDisabled = false;
  public offerStatus = 'untouched';
  public animateIn = false;

  constructor(private dataOfferSvc: DataOfferService) { }

  ngOnInit() {
    this.scrollTop = $('body').scrollTop();
    $('body, html').addClass('no-scroll');

    this.changeOffer(0);
    this.animateIn = true;
  }

  closeModal(): void {
    $('body, html').removeClass('no-scroll');
    $('body').scrollTop(this.scrollTop);

    const self = this;
    this.animateIn = false;
    setTimeout(function(){
      self.destroy();
    }, 1000);
  }


  prevOffer(): void {
    if (this.offer_index > 0 ) {
      this.changeOffer(-1);
    }
  }

  nextOffer(): void {
    if (this.offers.length > (this.offer_index + 1) ) {
      this.changeOffer(1);
    }
  }

  changeOffer(diff: number) {
    this.offer_index = this.offer_index + diff;
    this.offerDuration = moment.duration( this.offers[this.offer_index].collectFor ).as('days');

    this.claimDisabled = true;
    this.scrollShadow = false;
    this.navDisabled = false;
    this.btnIcon = '';
    this.btnText = 'Accept'

    if (this.offers[this.offer_index].claim === undefined) {
      this.offerStatus = 'untouched';
    } else {
      this.offerStatus = this.offers[this.offer_index].claim.status;
    }

    $('.rump-modal-footer .btn').removeClass('processing accepted failed');<commit_msg>Fixes offer duration<commit_after>import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Moment } from 'moment';
import * as moment from 'moment';
import { DataOfferService } from '../../data-management/data-offer.service';
import {Subscription, Observable} from 'rxjs/Rx';

declare var $: any;

@Component({
  selector: 'rump-offer-modal',
  templateUrl: './offer-modal.component.html',
  styleUrls: ['./offer-modal.component.scss']
})

export class OfferModalComponent implements OnInit {
  @Input() offer_index: number;
  @Input() offers: any;

  @Input() changeModal: Function;
  @Input() statsComponent: any;
  @Input() offerMode = 'untouched';

  public timeNow = Date.now();
  public claimSub: Subscription;
  private destroy: Function;
  public claimDisabled = true;
  public scrollTop: number;
  public offerDuration: number;
  public scrollShadow = false;
  public btnIcon = '';
  public btnText = 'Accept';
  public navDisabled = false;
  public offerStatus = 'untouched';
  public animateIn = false;

  constructor(private dataOfferSvc: DataOfferService) { }

  ngOnInit() {
    this.scrollTop = $('body').scrollTop();
    $('body, html').addClass('no-scroll');

    this.changeOffer(0);
    this.animateIn = true;
  }

  closeModal(): void {
    $('body, html').removeClass('no-scroll');
    $('body').scrollTop(this.scrollTop);

    const self = this;
    this.animateIn = false;
    setTimeout(function(){
      self.destroy();
    }, 1000);
  }


  prevOffer(): void {
    if (this.offer_index > 0 ) {
      this.changeOffer(-1);
    }
  }

  nextOffer(): void {
    if (this.offers.length > (this.offer_index + 1) ) {
      this.changeOffer(1);
    }
  }

  changeOffer(diff: number) {
    this.offer_index = this.offer_index + diff;
    this.offerDuration = this.offers[this.offer_index].collectFor;

    this.claimDisabled = true;
    this.scrollShadow = false;
    this.navDisabled = false;
    this.btnIcon = '';
    this.btnText = 'Accept'

    if (this.offers[this.offer_index].claim === undefined) {
      this.offerStatus = 'untouched';
    } else {
      this.offerStatus = this.offers[this.offer_index].claim.status;
    }

    $('.rump-modal-footer .btn').removeClass('processing accepted failed');
{'fraction_non_alphanumeric': 0.150561303103676, 'fraction_numerical': 0.003962139555359894, 'mean_word_length': 3.5852674066599395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5102074', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1429, 'n_words': 315}