<commit_before>import { Component, View, Inject } from 'angular2/core';
import { CORE_DIRECTIVES } from 'angular2/common';
import { Router, RouteParams, RouterLink } from 'angular2/router';

import { MindsTitle } from '../../services/ux/title';
import { Client } from '../../services/api';
import { Material } from '../../directives/material';
import { SessionFactory } from '../../services/session';
import { InfiniteScroll } from '../../directives/infinite-scroll';
import { CARDS } from '../../controllers/cards/cards';
import { BUTTON_COMPONENTS } from '../../components/buttons';


@Component({
  selector: 'minds-discovery',
  viewBindings: [ Client ],
  bindings: [ MindsTitle ]
})
@View({
  templateUrl: 'src/controllers/discovery/discovery.html',
  directives: [ CORE_DIRECTIVES, RouterLink, Material, InfiniteScroll, CARDS, BUTTON_COMPONENTS ]
})

export class Discovery {

  session  = SessionFactory.build();

  _filter : string = "featured";
  _owner : string = "";
  _type : string = "all";
  entities : Array<Object> = [];
  moreData : boolean = true;
  offset: string | number = "";
  inProgress : boolean = false;

  city : string = "";
  cities : Array<any> = [];
  nearby : boolean = false;
  hasNearby : boolean = false;
  distance : number = 5;

  constructor(public client: Client, public router: Router, public params: RouteParams, public title: MindsTitle){
    this._filter = params.params['filter'];

    switch(this._filter){
      case "all":
        break;
      case "suggested":
        if(!this.session.isLoggedIn()){
          this.router.navigate(['/Discovery', {'filter': 'featured', 'type': 'channels'}]);
          return;
        }

        this._type = "channels";
        if(this.session.getLoggedInUser().city){
          this.city = this.session.getLoggedInUser().city;
          this.nearby = true;
          this.hasNearby = false;
        }
        break;
      case "trending":
        this._type = "images";
        break;
      case "featured":
        this._type = "channels";
        break;
      case "owner":
        break;
      default:
        this._owner = this._filter;
        this._filter =  this._filter;
    }

    if(params.params['type'])
      this._type = params.params['type'];

    this.title.setTitle("Discovery");

    this.load(true);
  }

  load(refresh : boolean = false){

    if(this.inProgress)
      return false;

    if(refresh)
      this.offset = "";

    this.inProgress = true;

    var filter = this._filter;
    if(this._owner)
      filter = 'owner';

    this.client.get('api/v1/entities/'+filter+'/'+this._type+'/' + this._owner, {
        limit:12,
        offset: this.offset,
        skip: 0,
        nearby : this.nearby,
        distance : this.distance
      })
      .then((data : any) => {
        if(!data.entities){
          if(this.nearby){
            this.hasNearby = false;
            return this.setNearby(false);
          }
          this.moreData = false;
          this.inProgress = false;
          return false;
        }

        if(this.nearby){
          this.hasNearby = true;
        }

        if(refresh){
          this.entities = data.entities;
        }else{
          if(this.offset)
            this.entities.shift();
          this.entities = this.entities.concat(data.entities);
        }

        this.offset = data['load-next'];
        this.inProgress = false;

       })
       .catch((e) => {
         this.inProgress = false;
         if(this.nearby){
           this.setNearby(false);
         }
       });
  }

  pass(index : number){
    var entity : any = this.entities[index];
    this.client.post('api/v1/entities/suggested/pass/' + entity.guid);
    this.pop(index);
  }

  pop(index : number){
    this.entities.splice(index, 1);
    if(this.entities.length < 3){
      this.offset = 3;
      this.load(true);<commit_msg>(fix): data entities shift<commit_after>import { Component, View, Inject } from 'angular2/core';
import { CORE_DIRECTIVES } from 'angular2/common';
import { Router, RouteParams, RouterLink } from 'angular2/router';

import { MindsTitle } from '../../services/ux/title';
import { Client } from '../../services/api';
import { Material } from '../../directives/material';
import { SessionFactory } from '../../services/session';
import { InfiniteScroll } from '../../directives/infinite-scroll';
import { CARDS } from '../../controllers/cards/cards';
import { BUTTON_COMPONENTS } from '../../components/buttons';


@Component({
  selector: 'minds-discovery',
  viewBindings: [ Client ],
  bindings: [ MindsTitle ]
})
@View({
  templateUrl: 'src/controllers/discovery/discovery.html',
  directives: [ CORE_DIRECTIVES, RouterLink, Material, InfiniteScroll, CARDS, BUTTON_COMPONENTS ]
})

export class Discovery {

  session  = SessionFactory.build();

  _filter : string = "featured";
  _owner : string = "";
  _type : string = "all";
  entities : Array<Object> = [];
  moreData : boolean = true;
  offset: string | number = "";
  inProgress : boolean = false;

  city : string = "";
  cities : Array<any> = [];
  nearby : boolean = false;
  hasNearby : boolean = false;
  distance : number = 5;

  constructor(public client: Client, public router: Router, public params: RouteParams, public title: MindsTitle){
    this._filter = params.params['filter'];

    switch(this._filter){
      case "all":
        break;
      case "suggested":
        if(!this.session.isLoggedIn()){
          this.router.navigate(['/Discovery', {'filter': 'featured', 'type': 'channels'}]);
          return;
        }

        this._type = "channels";
        if(this.session.getLoggedInUser().city){
          this.city = this.session.getLoggedInUser().city;
          this.nearby = true;
          this.hasNearby = false;
        }
        break;
      case "trending":
        this._type = "images";
        break;
      case "featured":
        this._type = "channels";
        break;
      case "owner":
        break;
      default:
        this._owner = this._filter;
        this._filter =  this._filter;
    }

    if(params.params['type'])
      this._type = params.params['type'];

    this.title.setTitle("Discovery");

    this.load(true);
  }

  load(refresh : boolean = false){

    if(this.inProgress)
      return false;

    if(refresh)
      this.offset = "";

    this.inProgress = true;

    var filter = this._filter;
    if(this._owner)
      filter = 'owner';

    this.client.get('api/v1/entities/'+filter+'/'+this._type+'/' + this._owner, {
        limit:12,
        offset: this.offset,
        skip: 0,
        nearby : this.nearby,
        distance : this.distance
      })
      .then((data : any) => {
        if(!data.entities){
          if(this.nearby){
            this.hasNearby = false;
            return this.setNearby(false);
          }
          this.moreData = false;
          this.inProgress = false;
          return false;
        }

        if(this.nearby){
          this.hasNearby = true;
        }

        if(refresh){
          this.entities = data.entities;
        }else{
          if(this.offset)
            data.entities.shift();
          this.entities = this.entities.concat(data.entities);
        }

        this.offset = data['load-next'];
        this.inProgress = false;

       })
       .catch((e) => {
         this.inProgress = false;
         if(this.nearby){
           this.setNearby(false);
         }
       });
  }

  pass(index : number){
    var entity : any = this.entities[index];
    this.client.post('api/v1/entities/suggested/pass/' + entity.guid);
    this.pop(index);
  }

  pop(index : number){
    this.entities.splice(index, 1);
    if(this.entities.length < 3){
      this.offset = 3;
      this.load(true);
{'fraction_non_alphanumeric': 0.15120941663432932, 'fraction_numerical': 0.0031043849437330227, 'mean_word_length': 2.2487394957983193, 'pattern_counts': {'":': 10, '<': 9, '<?xml version=': 0, '>': 11, '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': '6876642', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2362, 'n_words': 476}