<commit_before>import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import { HalDoc, Upload } from '../../core';
import { BaseModel } from 'ngx-prx-styleguide';
import { DistributionModel } from './distribution.model';
import { REQUIRED, LENGTH } from './invalid';

export class SeriesImportModel extends BaseModel {

  public id: number;
  public url: string;
  public status: string;
  public createdAt: Date;
  public updatedAt: Date;
  public accountId: number;
  public feedEpisodeCount: number;

  public episodeImports: HalDoc[] = [];
  public episodeImportPlaceholders: HalDoc[] = [];

  // TODO
  public config: any;

  SETABLE = ['url', 'accountId'];

  VALIDATORS = {
    url:        [REQUIRED()],
    accountId:  [REQUIRED()],
    status:  [REQUIRED()]
  };

  constructor(account: HalDoc, seriesImportDoc?: HalDoc, loadRelated = true) {
    super();
    if (account) {
      this.set('accountId', account.id, true);
    }
    this.init(account, seriesImportDoc, loadRelated);
  }

  key() {
    if (this.doc) {
      return `prx.series-import.${this.doc.id}`;
    } else {
      return 'prx.series-import.new'; // new import
    }
  }

  related() {
    // TODO these are pure haldocs, no front-end model wrapper
    let episodeImports = Observable.of([]);
    let episodeImportPlaceholders = Observable.of([]);

    episodeImports = this.doc.followList('prx:episode-imports').map((episodes) => {
      return episodes;
    });

    episodeImportPlaceholders = this.doc.followList('prx:episode-import-placeholders').map((episodes) => {
      return episodes;
    });

    return {
      episodeImports,
      episodeImportPlaceholders
    };
  }

  decode() {
    this.id = this.doc['id'];
    this.url = this.doc['url'];
    this.status = this.doc['status'];
    this.createdAt = new Date(this.doc['createdAt']);
    this.updatedAt = new Date(this.doc['updatedAt']);
    this.accountId = this.doc['account'];
    this.feedEpisodeCount = this.doc['feedEpisodeCount'];
    this.config = this.doc['config'];
  }

  encode(): {} {
    let data = <any> {};

    data['id'] = this.id;
    data['url'] = this.url;
    data['accountId'] = this.accountId;
    // TODO implement the config for the episode only import
    data['config'] = {};

    return data;
  }


  saveNew(data: {}): Observable<HalDoc> {
    return this.parent.create('prx:podcast-imports', {}, data);
  }

  discard() {
    // TODO
  }

  entriesInRssFeed(){
    return this.feedEpisodeCount
      + this.episodeImportPlaceholders.length;
  }
<commit_msg>feedEpisodeCount contains the total count<commit_after>import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import { HalDoc, Upload } from '../../core';
import { BaseModel } from 'ngx-prx-styleguide';
import { DistributionModel } from './distribution.model';
import { REQUIRED, LENGTH } from './invalid';

export class SeriesImportModel extends BaseModel {

  public id: number;
  public url: string;
  public status: string;
  public createdAt: Date;
  public updatedAt: Date;
  public accountId: number;
  public feedEpisodeCount: number;

  public episodeImports: HalDoc[] = [];
  public episodeImportPlaceholders: HalDoc[] = [];

  // TODO
  public config: any;

  SETABLE = ['url', 'accountId'];

  VALIDATORS = {
    url:        [REQUIRED()],
    accountId:  [REQUIRED()],
    status:  [REQUIRED()]
  };

  constructor(account: HalDoc, seriesImportDoc?: HalDoc, loadRelated = true) {
    super();
    if (account) {
      this.set('accountId', account.id, true);
    }
    this.init(account, seriesImportDoc, loadRelated);
  }

  key() {
    if (this.doc) {
      return `prx.series-import.${this.doc.id}`;
    } else {
      return 'prx.series-import.new'; // new import
    }
  }

  related() {
    // TODO these are pure haldocs, no front-end model wrapper
    let episodeImports = Observable.of([]);
    let episodeImportPlaceholders = Observable.of([]);

    episodeImports = this.doc.followList('prx:episode-imports').map((episodes) => {
      return episodes;
    });

    episodeImportPlaceholders = this.doc.followList('prx:episode-import-placeholders').map((episodes) => {
      return episodes;
    });

    return {
      episodeImports,
      episodeImportPlaceholders
    };
  }

  decode() {
    this.id = this.doc['id'];
    this.url = this.doc['url'];
    this.status = this.doc['status'];
    this.createdAt = new Date(this.doc['createdAt']);
    this.updatedAt = new Date(this.doc['updatedAt']);
    this.accountId = this.doc['account'];
    this.feedEpisodeCount = this.doc['feedEpisodeCount'];
    this.config = this.doc['config'];
  }

  encode(): {} {
    let data = <any> {};

    data['id'] = this.id;
    data['url'] = this.url;
    data['accountId'] = this.accountId;
    // TODO implement the config for the episode only import
    data['config'] = {};

    return data;
  }


  saveNew(data: {}): Observable<HalDoc> {
    return this.parent.create('prx:podcast-imports', {}, data);
  }

  discard() {
    // TODO
  }

  entriesInRssFeed(){
    return this.feedEpisodeCount;
  }

{'fraction_non_alphanumeric': 0.1556201550387597, 'fraction_numerical': 0.0, 'mean_word_length': 3.1993490642799025, 'pattern_counts': {'":': 0, '<': 7, '<?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': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7139836', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1653, 'n_words': 355}