<commit_before>/**
 * Created by <NAME> (<EMAIL>) on 6/7/17.
 */
import { AfterViewChecked, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Router } from '@angular/router';

import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import { ExtendedSearch, KnoraProperty } from '../shared/utilities/knora-api-params';
import { Config } from '../shared/config/env.config';
import { globalSearchVariableService } from '../suche/globalSearchVariablesService';
import { DateFormatService } from '../shared/utilities/date-format.service';

@Component({
  moduleId: module.id,
  selector: 'rae-fassung',
  templateUrl: 'fassung.component.html',
  styleUrls: [ 'fassung.component.css' ]
})
export class FassungComponent implements OnInit, AfterViewChecked {
  creationDate: string;
  modificationDate: string;

  zeigeKonstituiert: boolean = true;
  zeigeDiplomatisch: boolean = false;

  urlPrefix: string = 'http://rdfh.ch/kuno-raeber/';

  pageIRIs: Array<string>;
  diplomaticIRIs: Array<string>;

  poem_id: string;
  poemTitle: string;
  poemSeqnum: number;
  poemConvoluteIri: string;
  poemConvoluteType: string;
  convoluteProperty: string;
  editedPoemText: string;
  textEdition: string;
  konvolutType: string;
  konvolutIRI: string;
  konvolutTitel: string;
  konvolutLink: string;
  synopseIRI: string;
  workTitle: string;
  otherWorkExpressions: any[] = [];
  otherWorkExpressionsIri: string[];

  konvolutTypeName: string;

  nextPoem: string = '';
  prevPoem: string = '';

  poem_resizable: boolean;
  show_register: boolean;

  constructor(private http: Http, private router: Router, private cdr: ChangeDetectorRef, private dfs: DateFormatService) {
  }

  private static produceFassungsLink(titel: string, iri: string) {
    if (titel !== undefined && iri !== undefined) {
      return titel.split('/')[0] + '---' + iri.split('raeber/')[1];
    } else {
      return 'Linkinformation has not arrived yet';
    }
  }

  ngOnInit() {
    this.poem_resizable = true;
    this.show_register = true;
    this.konvolutTitel = decodeURIComponent(this.router.url.split('/')[1]);
    this.poem_id = this.router.url.split('/')[2].split('---')[1];
    this.updateView();

    if (this.konvolutTitel.includes('Notizbuch')) {
      this.konvolutLink = '/notizbuecher/notizbuch-' + this.konvolutTitel.split(' ')[1];
    } else if (this.konvolutTitel.includes('manuskripte')) {
      this.konvolutLink = '/manuskripte/manuskripte-' + this.konvolutTitel.split(' ')[1];
    } else if (this.konvolutTitel.includes('Typoskript')) {
      this.konvolutLink = '/typoskripte/typoskripte-' + this.konvolutTitel.split(' ')[1];
    } else {
      if (this.konvolutTitel === 'GESICHT IM MITTAG 1950') {
        this.konvolutLink = '/drucke/gesicht-im-mittag';
      } else if (this.konvolutTitel === 'Die verwandelten Schiffe 1957') {
        this.konvolutLink = '/drucke/die-verwandelten-schiffe';
      } else if (this.konvolutTitel === 'GEDICHTE 1960') {
        this.konvolutLink = '/drucke/gedichte';
      } else if (this.konvolutTitel === 'FLUSSUFER 1963') {
        this.konvolutLink = '/drucke/flussufer';
      } else if (this.konvolutTitel === 'Reduktionen 1981') {
        this.konvolutLink = '/drucke/reduktionen';
      } else if (this.konvolutTitel === 'Hochdeutsche Gedichte 1985') {
        this.konvolutLink = '/drucke/abgewandt-zugewandt-hochdeutsche-gedichte';
      } else if (this.konvolutTitel === 'Alemannische Gedichte 1985') {
        this.konvolutLink = '/drucke/abgewandt-zugewandt-alemannische-gedichte';
      } else {
        this.konvolutLink = '/drucke/verstreutes';
      }
    }
  }

  updateView() {
    // TODO: Change when route definitions have been changed
    this.http
      .get(Config.API + 'resources/' + encodeURIComponent(this.urlPrefix + this.poem_id))
      .map(result => result.json())
      .subscribe(res => {
        console.log(res);
        this.poemTitle = res.props[ 'http://www.knora.org/ontology/text#hasTitle' ].values[ 0 ].utf8str;
        this.textEdition = res.props[ 'http://www.knora.org/ontology/kuno-raeber#hasEdition' ].values[ 0 ];
        this.getEditedPoemText(this.textEdition);
        this.pageIRIs = res.props[ 'http://www.knora.org/ontology/kuno-raeber#isOnPage' ].values;
        this.diplomaticIRIs = res.props[ 'http://www.knora.org/ontology/kuno-raeber#hasDiplomaticTranscription' ].values;
        this.poemSeqnum = res.props[ 'http://www.knora.org/ontology/knora-base#seqnum' ].values[ 0 ];
        this.creationDate = this.dfs.germanLongDate(res.props[ 'http://www.knora.org/ontology/human#hasCreationDate' ].values[ 0 ].dateval1);
        this.modificationDate = this.dfs.germanLongDate(res.props[ 'http://www.knora.org/ontology/human#hasModificationDate' ].values[ 0 ].utf8str);
        this.poemConvoluteType = res.resdata[ 'restype_name' ].split('#')[ 1 ];
        switch (this.poemConvoluteType) {
          case 'PoemNote':
            this.convoluteProperty = 'http://www.knora.org/ontology/kuno-raeber#isInNotebook';
            this.konvolutTypeName = 'Notizbuch';
            break;
          case 'HandwrittenPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isInManuscript';
            this.konvolutTypeName = 'Manuskript';
            break;
          case 'PostCardPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isOnPostcard';
            this.konvolutTypeName = 'Manuskript';
            break;
          case 'TypewrittenPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isInTypescript';
            this.konvolutTypeName = 'Typoskript';
            break;
          case 'PublicationPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/work#isPublishedIn';
            this.konvolutTypeName = 'DRUCK';
            break;
        }
        this.poemConvoluteIri = res.props[ this.convoluteProperty ].values[ 0 ];
        this.getPrevNextPoems(this.poemSeqnum);
      });

    this.http
      .get(Config.API + 'graphdata/' + encodeURIComponent(this.urlPrefix + this.poem_id) + '?depth=2')
      .map(result => result.json())
      .subscribe(res => {
        for (const r of res.nodes) {
          //console.log(r);
          if (r[ 'resourceClassIri' ].split('#')[ 1 ] === ('PoemNotebook' ||
              'PoemManuscriptConvolute' ||
              'PoemPostcardConvolute' ||
              'PoemTypescriptConvolute' ||
              'PrintedPoemBookPublication' ||
              'PolyAuthorPublication')) {
            //this.konvolutIRI = r[ 'resourceIri' ];
            this.konvolutType = r[ 'resourceClassIri' ].split('#')[ 1 ];
          }
          if (r[ 'resourceClassIri' ].split('#')[ 1 ] === 'Work') {
            this.synopseIRI = r[ 'resourceIri' ];
            this.getWork(this.synopseIRI);
          }
        }
      });

    this.http
      .get(globalSearchVariableService.API_URL +
        globalSearchVariableService.extendedSearch +
        'http%3A%2F%2Fwww.knora.org%2Fontology%2Fkuno-raeber-gui%23Poem' +
        '&property_id=http%3A%2F%2Fwww.knora.org%2Fontology%2Fkuno-raeber-gui%23hasPoemIRI' +
        '&compop=EQ' +<commit_msg>Don't request isOnPage and hasDiplomaticTranscription<commit_after>/**
 * Created by <NAME> (<EMAIL>) on 6/7/17.
 */
import { AfterViewChecked, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Router } from '@angular/router';

import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import { ExtendedSearch, KnoraProperty } from '../shared/utilities/knora-api-params';
import { Config } from '../shared/config/env.config';
import { globalSearchVariableService } from '../suche/globalSearchVariablesService';
import { DateFormatService } from '../shared/utilities/date-format.service';

@Component({
  moduleId: module.id,
  selector: 'rae-fassung',
  templateUrl: 'fassung.component.html',
  styleUrls: [ 'fassung.component.css' ]
})
export class FassungComponent implements OnInit, AfterViewChecked {
  creationDate: string;
  modificationDate: string;

  zeigeKonstituiert: boolean = true;
  zeigeDiplomatisch: boolean = false;

  urlPrefix: string = 'http://rdfh.ch/kuno-raeber/';

  diplomaticIRIs: Array<string>;

  poem_id: string;
  poemTitle: string;
  poemSeqnum: number;
  poemConvoluteIri: string;
  poemConvoluteType: string;
  convoluteProperty: string;
  editedPoemText: string;
  textEdition: string;
  konvolutType: string;
  konvolutIRI: string;
  konvolutTitel: string;
  konvolutLink: string;
  synopseIRI: string;
  workTitle: string;
  otherWorkExpressions: any[] = [];
  otherWorkExpressionsIri: string[];

  konvolutTypeName: string;

  nextPoem: string = '';
  prevPoem: string = '';

  poem_resizable: boolean;
  show_register: boolean;

  constructor(private http: Http, private router: Router, private cdr: ChangeDetectorRef, private dfs: DateFormatService) {
  }

  private static produceFassungsLink(titel: string, iri: string) {
    if (titel !== undefined && iri !== undefined) {
      return titel.split('/')[ 0 ] + '---' + iri.split('raeber/')[ 1 ];
    } else {
      return 'Linkinformation has not arrived yet';
    }
  }

  ngOnInit() {
    this.poem_resizable = true;
    this.show_register = true;
    this.konvolutTitel = decodeURIComponent(this.router.url.split('/')[ 1 ]);
    this.poem_id = this.router.url.split('/')[ 2 ].split('---')[ 1 ];
    this.updateView();

    if (this.konvolutTitel.includes('Notizbuch')) {
      this.konvolutLink = '/notizbuecher/notizbuch-' + this.konvolutTitel.split(' ')[ 1 ];
    } else if (this.konvolutTitel.includes('manuskripte')) {
      this.konvolutLink = '/manuskripte/manuskripte-' + this.konvolutTitel.split(' ')[ 1 ];
    } else if (this.konvolutTitel.includes('Typoskript')) {
      this.konvolutLink = '/typoskripte/typoskripte-' + this.konvolutTitel.split(' ')[ 1 ];
    } else {
      if (this.konvolutTitel === 'GESICHT IM MITTAG 1950') {
        this.konvolutLink = '/drucke/gesicht-im-mittag';
      } else if (this.konvolutTitel === 'Die verwandelten Schiffe 1957') {
        this.konvolutLink = '/drucke/die-verwandelten-schiffe';
      } else if (this.konvolutTitel === 'GEDICHTE 1960') {
        this.konvolutLink = '/drucke/gedichte';
      } else if (this.konvolutTitel === 'FLUSSUFER 1963') {
        this.konvolutLink = '/drucke/flussufer';
      } else if (this.konvolutTitel === 'Reduktionen 1981') {
        this.konvolutLink = '/drucke/reduktionen';
      } else if (this.konvolutTitel === 'Hochdeutsche Gedichte 1985') {
        this.konvolutLink = '/drucke/abgewandt-zugewandt-hochdeutsche-gedichte';
      } else if (this.konvolutTitel === 'Alemannische Gedichte 1985') {
        this.konvolutLink = '/drucke/abgewandt-zugewandt-alemannische-gedichte';
      } else {
        this.konvolutLink = '/drucke/verstreutes';
      }
    }
  }

  updateView() {
    // TODO: Change when route definitions have been changed
    console.log('IRI: ' + Config.API + 'resources/' + encodeURIComponent(this.urlPrefix + this.poem_id));
    this.http
      .get(Config.API + 'resources/' + encodeURIComponent(this.urlPrefix + this.poem_id))
      .map(result => result.json())
      .subscribe(res => {
        console.log(res);
        this.poemConvoluteType = res.resinfo[ 'restype_id' ].split('#')[ 1 ];
        this.poemTitle = res.props[ 'http://www.knora.org/ontology/text#hasTitle' ].values[ 0 ].utf8str;
        this.textEdition = res.props[ 'http://www.knora.org/ontology/kuno-raeber#hasEdition' ].values[ 0 ];
        this.getEditedPoemText(this.textEdition);
        this.poemSeqnum = res.props[ 'http://www.knora.org/ontology/knora-base#seqnum' ].values[ 0 ];
        this.creationDate = this.dfs.germanLongDate(res.props[ 'http://www.knora.org/ontology/human#hasCreationDate' ].values[ 0 ].dateval1);
        this.modificationDate = this.dfs.germanLongDate(res.props[ 'http://www.knora.org/ontology/human#hasModificationDate' ].values[ 0 ].utf8str);
        switch (this.poemConvoluteType) {
          case 'PoemNote':
            this.convoluteProperty = 'http://www.knora.org/ontology/kuno-raeber#isInNotebook';
            this.diplomaticIRIs = res.props[ 'http://www.knora.org/ontology/kuno-raeber#hasDiplomaticTranscription' ].values;
            this.konvolutTypeName = 'Notizbuch';
            break;
          case 'HandwrittenPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isInManuscript';
            this.diplomaticIRIs = res.props[ 'http://www.knora.org/ontology/kuno-raeber#hasDiplomaticTranscription' ].values;
            this.konvolutTypeName = 'Manuskript';
            break;
          case 'PostCardPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isOnPostcard';
            this.konvolutTypeName = 'Manuskript';
            break;
          case 'TypewrittenPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/text#isInTypescript';
            this.konvolutTypeName = 'Typoskript';
            break;
          case 'PublicationPoem':
            this.convoluteProperty = 'http://www.knora.org/ontology/work#isPublishedIn';
            this.konvolutTypeName = 'DRUCK';
            break;
        }
        this.poemConvoluteIri = res.props[ this.convoluteProperty ].values[ 0 ];
        this.getPrevNextPoems(this.poemSeqnum);
      });

    this.http
      .get(Config.API + 'graphdata/' + encodeURIComponent(this.urlPrefix + this.poem_id) + '?depth=2')
      .map(result => result.json())
      .subscribe(res => {
        for (const r of res.nodes) {
          console.log('Konvolutyp (Model): ' + r[ 'resourceClassIri' ].split('#')[ 1 ]);
          if (r[ 'resourceClassIri' ].split('#')[ 1 ] === ('PoemNotebook' ||
              'PoemManuscriptConvolute' ||
              'PoemPostcardConvolute' ||
              'PoemTypescriptConvolute' ||
              'PrintedPoemBookPublication' ||
              'PolyAuthorPublication')) {
            //this.konvolutIRI = r[ 'resourceIri' ];
            this.konvolutType = r[ 'resourceClassIri' ].split('#')[ 1 ];
          }
          if (r[ 'resourceClassIri' ].split('#')[ 1 ] === 'Work') {
            this.synopseIRI = r[ 'resourceIri' ];
            this.getWork(this.synopseIRI);
          }
        }
      });

    this.http
      .get(globalSearchVariableService.API_URL +
        globalSearchVariableService.extendedSearch +
        'http%3A%2F%2Fwww.knora.org%2Fontology%2Fkuno-raeber-gui%23Poem' +
        '&property_id=http%3A%2F%2Fwww.knora.org%2Fontology%2Fkuno-raeber-gui%23hasPoemIRI' +
        '&compop=EQ' +
{'fraction_non_alphanumeric': 0.14759199134199133, 'fraction_numerical': 0.009266774891774892, 'mean_word_length': 3.060697610546553, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 28, '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': '663982', 'n_tokens_mistral': 5155, 'n_tokens_neox': 5086, 'n_words': 806}