<commit_before>import { Component, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { DistributionModel, SeriesModel, StoryModel, TabService } from '../../shared';

@Component({
  template: `
  <div>
    <publish-spinner *ngIf="!isLoaded"></publish-spinner>
    <section *ngIf="series && list">
      <div class="hint" *ngIf="noStories">
        You have no published stories in this series.
      </div>

      <section *ngIf="!noStories">
        <ul *ngIf="privateStories.length">
          <h4>Private</h4>
          <li *ngFor="let s of privateStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="private">No publication date set.</p>
          </li>
        </ul>

        <ul *ngIf="futurePublicStories.length">
          <h4>Set for future publication</h4>
          <li *ngFor="let s of futurePublicStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="futurePublic">Will be published {{s.pubDate}}.</p>
          </li>
        </ul>

        <ul *ngIf="publicStories.length">
          <h4>Public</h4>
          <li *ngFor="let s of publicStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="public">Published {{s.pubDate}}.</p>
          </li>
        </ul>

        <div class="extra" *ngIf="isLoaded">
          <a [routerLink]="['/search', { tab: 'stories', seriesId: series.id }]">
            Search among these stories.
          </a>
        </div>
      </section>
    </section>
    </div>
  `,
  styleUrls: ['./series-feed.component.css']
})

export class SeriesFeedComponent implements OnDestroy {

  isLoaded: boolean = false;
  noStories: boolean;
  series: SeriesModel;
  publicStories: StoryModel[] = [];
  futurePublicStories: StoryModel[] = [];
  privateStories: StoryModel[] = [];
  list: DistributionModel;
  tabSub: Subscription;

  constructor(tab: TabService) {
    this.noStories = false;
    this.tabSub = tab.model.subscribe((s: SeriesModel) => {
      this.series = s;
      s.loadRelated('distributions').subscribe((dists) => {
        this.list = dists[0];
        this.sortStories();
      });
    });
  }

  sortStories() {
    let total = this.series.doc.count('prx:stories');
    if (total === 0) {
      this.noStories = true;
      this.isLoaded = true;
    } else {
      this.series
          .doc
          .followItems('prx:stories', { per: total })
          .subscribe((docs) => {
            this.isLoaded = true;
            docs.forEach((doc) => {
                let story = new StoryModel(this.list.parent, doc, false);
                if (!story.publishedAt) {
                  this.privateStories.push(story);
                  return;
                }
                story['pubDate'] = story.publishedAt.toLocaleDateString();
                if (new Date(story.publishedAt) <= new Date()) {
                  this.publicStories.push(story);<commit_msg>Use series.doc instead of list.parent<commit_after>import { Component, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { DistributionModel, SeriesModel, StoryModel, TabService } from '../../shared';

@Component({
  template: `
  <div>
    <publish-spinner *ngIf="!isLoaded"></publish-spinner>
    <section *ngIf="series && list">
      <div class="hint" *ngIf="noStories">
        You have no published stories in this series.
      </div>

      <section *ngIf="!noStories">
        <ul *ngIf="privateStories.length">
          <h4>Private</h4>
          <li *ngFor="let s of privateStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="private">No publication date set.</p>
          </li>
        </ul>

        <ul *ngIf="futurePublicStories.length">
          <h4>Set for future publication</h4>
          <li *ngFor="let s of futurePublicStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="futurePublic">Will be published {{s.pubDate}}.</p>
          </li>
        </ul>

        <ul *ngIf="publicStories.length">
          <h4>Public</h4>
          <li *ngFor="let s of publicStories">
            <h5><a [routerLink]="['/story', s.id]">{{s.title}}</a></h5>
            <p class="public">Published {{s.pubDate}}.</p>
          </li>
        </ul>

        <div class="extra" *ngIf="isLoaded">
          <a [routerLink]="['/search', { tab: 'stories', seriesId: series.id }]">
            Search among these stories.
          </a>
        </div>
      </section>
    </section>
    </div>
  `,
  styleUrls: ['./series-feed.component.css']
})

export class SeriesFeedComponent implements OnDestroy {

  isLoaded: boolean = false;
  noStories: boolean;
  series: SeriesModel;
  publicStories: StoryModel[] = [];
  futurePublicStories: StoryModel[] = [];
  privateStories: StoryModel[] = [];
  list: DistributionModel;
  tabSub: Subscription;

  constructor(tab: TabService) {
    this.noStories = false;
    this.tabSub = tab.model.subscribe((s: SeriesModel) => {
      this.series = s;
      s.loadRelated('distributions').subscribe((dists) => {
        this.list = dists[0];
        this.sortStories();
      });
    });
  }

  sortStories() {
    let total = this.series.doc.count('prx:stories');
    if (total === 0) {
      this.noStories = true;
      this.isLoaded = true;
    } else {
      this.series
          .doc
          .followItems('prx:stories', { per: total })
          .subscribe((docs) => {
            this.isLoaded = true;
            docs.forEach((doc) => {
                let story = new StoryModel(this.series.doc, doc, false);
                if (!story.publishedAt) {
                  this.privateStories.push(story);
                  return;
                }
                story['pubDate'] = story.publishedAt.toLocaleDateString();
                if (new Date(story.publishedAt) <= new Date()) {
                  this.publicStories.push(story);
{'fraction_non_alphanumeric': 0.16996507566938301, 'fraction_numerical': 0.004656577415599534, 'mean_word_length': 2.193839617631439, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 111, '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': '4147381', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1866, 'n_words': 377}