<commit_before>import { Component, NgZone, OnInit, OnDestroy } from '@angular/core'
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'

import * as _ from "lodash"
import * as moment from "moment"

import { DatabaseService } from '../../../../_core/database/database.service'
import { RxPresentationDocument } from '../../data/presentation'

import { CreateComponent } from "../create/create.component"
import { UploadComponent } from "../upload/upload.component"
import { RxCollection, RxDocumentBase } from 'rxdb'

@Component({
  selector: 'app-presentations-overview',
  templateUrl: './overview.component.html',
  styleUrls: ['./overview.component.scss']
})
export class OverviewComponent implements OnInit, OnDestroy {

  db: RxCollection<RxPresentationDocument>
  presentations: RxPresentationDocument[] = []
  sub
  loading = true

  constructor(
    private dbService: DatabaseService,
    private zone: NgZone,
    private modal: NgbModal,
  ) { }

  closeResult: string

  ngOnInit() {
    this._show()
  }

  ngOnDestroy() {
    if (this.sub) {
      this.sub.unsubscribe()
    }
  }

  create() {
    const modalRef = this.modal.open(CreateComponent)
    modalRef.result
      .then((result) => {
        this._create(result.title)
      }, (reject) => {
        console.log("dismissed", reject)
      })
  }

  upload() {
    const modalRef = this.modal.open(UploadComponent)
    modalRef.result
      .then((result) => {
        this._create(result.title)
      }, (reject) => {
        console.log("dismissed", reject)
      })
  }

  private async _show() {
    this.db = await this.dbService.get<RxPresentationDocument>("presentation")
    const presentations$ = this.db.find().$
    this.sub = presentations$
      .subscribe(async presentations => {

        await this.loadPresentationsImage(presentations)

        const _presentations = _.chain(presentations)
          .map((presentation: RxDocumentBase<RxPresentationDocument> & RxPresentationDocument & any) => {
            presentation._docVersion =
              `${presentation.get("_rev").split("-")[0]} / ${moment(presentation.dateUpdated).fromNow()}`
            return presentation
          })
          .sortBy("dateCreated")
          .reverse()
          .value()
        this.zone.run(() => {
          this.presentations = _presentations
          this.loading = false
        })
      })
  }

  async loadPresentationsImage(presentations: any[]) {
    for (const presentation of presentations) {
      if (presentation.pages) {
        const contentImage = presentation.pages[0].params.image<commit_msg>fix pres. list<commit_after>import { Component, NgZone, OnInit, OnDestroy } from '@angular/core'
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'

import * as _ from "lodash"
import * as moment from "moment"

import { DatabaseService } from '../../../../_core/database/database.service'
import { RxPresentationDocument } from '../../data/presentation'

import { CreateComponent } from "../create/create.component"
import { UploadComponent } from "../upload/upload.component"
import { RxCollection, RxDocumentBase } from 'rxdb'

@Component({
  selector: 'app-presentations-overview',
  templateUrl: './overview.component.html',
  styleUrls: ['./overview.component.scss']
})
export class OverviewComponent implements OnInit, OnDestroy {

  db: RxCollection<RxPresentationDocument>
  presentations: RxPresentationDocument[] = []
  sub
  loading = true

  constructor(
    private dbService: DatabaseService,
    private zone: NgZone,
    private modal: NgbModal,
  ) { }

  closeResult: string

  ngOnInit() {
    this._show()
  }

  ngOnDestroy() {
    if (this.sub) {
      this.sub.unsubscribe()
    }
  }

  create() {
    const modalRef = this.modal.open(CreateComponent)
    modalRef.result
      .then((result) => {
        this._create(result.title)
      }, (reject) => {
        console.log("dismissed", reject)
      })
  }

  upload() {
    const modalRef = this.modal.open(UploadComponent)
    modalRef.result
      .then((result) => {
        this._create(result.title)
      }, (reject) => {
        console.log("dismissed", reject)
      })
  }

  private async _show() {
    this.db = await this.dbService.get<RxPresentationDocument>("presentation")
    const presentations$ = this.db.find().$
    this.sub = presentations$
      .subscribe(async presentations => {

        await this.loadPresentationsImage(presentations)

        const _presentations = _.chain(presentations)
          .map((presentation: RxDocumentBase<RxPresentationDocument> & RxPresentationDocument & any) => {
            presentation._docVersion =
              `${presentation.get("_rev").split("-")[0]} / ${moment(presentation.dateUpdated).fromNow()}`
            return presentation
          })
          .sortBy("dateCreated")
          .reverse()
          .value()
        this.zone.run(() => {
          this.presentations = _presentations
          this.loading = false
        })
      })
  }

  async loadPresentationsImage(presentations: any[]) {
    for (const presentation of presentations) {
      if (presentation.pages.length) {
        const contentImage = presentation.pages[0].params.image
{'fraction_non_alphanumeric': 0.133918351774132, 'fraction_numerical': 0.0007630675314765357, 'mean_word_length': 2.915608663181479, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '1893574', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1469, 'n_words': 297}