<commit_before>import {customElement, bindable, bindingMode, LogManager} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator';
import {OpenbelapiService} from './resources/openbelapi-service';
import {PubmedService} from './resources/pubmed-service';

let logger = LogManager.getLogger('bel-citation');

@bindable({
    name: 'nanopub', //name of the property on the class
    attribute: 'nanopub', //name of the attribute in HTML e.g. x.bind=""
    changeHandler: 'nanopubChanged', //name of the method to invoke when the property changes
    defaultBindingMode: bindingMode.twoWay, //default binding mode used with the .bind command
    defaultValue: undefined //default value of the property, if not bound or set in HTML
})
@customElement('bel-citation')
export class BelCitation {
    citationId;
    lastCitationId;

    static inject = [OpenbelapiService, PubmedService, EventAggregator];
    constructor(openbelapiService, pubmedService, eventAggregator) {
        this.api = openbelapiService;
        this.pubmedService = pubmedService;
        this.ea = eventAggregator;
    }

    /**
     * Force the nanopub object to be recreated for force an update of the nested
     * object binding in the View
     */
    refreshNanopubObjBinding() {
        let temp = this.nanopub;
        this.nanopub = {};
        this.nanopub = temp;
    }

    publish(payload) {
        this.ea.publish('pubmed', payload);
        logger.debug('Publish pubmed data');
    }

    attached() {
        logger.debug('Attached Nanopub: ', this.nanopub);
        if (this.nanopub.citation.id) {
            this.citationId = this.nanopub.citation.id;
        } else {
            this.nanopub.citation = {};
            this.nanopub.citation.type = 'PubMed';
        }

        if (this.citationId && this.nanopub.citation.type === 'PubMed') {
            logger.debug('Here', this.nanopub.citation.type);
            this.collectPubmed();
        }
    }

    copyCitationId() {
        this.lastCitationId = JSON.parse(JSON.stringify(this.citationId));
        logger.debug('Copying CitationId to Last', this.lastCitationId);
    }

    nanopubChanged(value) {
        logger.debug('CitationChanged: ', this.nanopub);
    }

    collectPubmed() {
        this.nanopub.citation.id = this.citationId;

        logger.debug('Id: ', this.citationId, 'Last', this.lastCitationId, ' Type: ', this.nanopub.citation.type);

        // Collect Pubmed data from service
        if (this.citationId && this.nanopub.citation.type === 'PubMed') {
            logger.debug('Id2: ', this.citationId, 'Last2', this.lastCitationId, ' Type: ', this.nanopub.citation.type);
            this.pubmedService.getPubmed(this.citationId)
              .then(pubmed => {
                  this.pubmed = pubmed;
                  if (this.citationId === this.lastCitationId) {
                      this.citationPubmedChecks();
                  } else {  // replace citation data if new CitationId<commit_msg>Fixed missing citation id in form<commit_after>import {customElement, bindable, bindingMode, LogManager} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator';
import {OpenbelapiService} from './resources/openbelapi-service';
import {PubmedService} from './resources/pubmed-service';

let logger = LogManager.getLogger('bel-citation');

@bindable({
    name: 'nanopub', //name of the property on the class
    attribute: 'nanopub', //name of the attribute in HTML e.g. x.bind=""
    changeHandler: 'nanopubChanged', //name of the method to invoke when the property changes
    defaultBindingMode: bindingMode.twoWay, //default binding mode used with the .bind command
    defaultValue: undefined //default value of the property, if not bound or set in HTML
})
@customElement('bel-citation')
export class BelCitation {
    citationId;
    lastCitationId;

    static inject = [OpenbelapiService, PubmedService, EventAggregator];
    constructor(openbelapiService, pubmedService, eventAggregator) {
        this.api = openbelapiService;
        this.pubmedService = pubmedService;
        this.ea = eventAggregator;
    }

    /**
     * Force the nanopub object to be recreated for force an update of the nested
     * object binding in the View
     */
    refreshNanopubObjBinding() {
        let temp = this.nanopub;
        this.nanopub = {};
        this.nanopub = temp;
    }

    publish(payload) {
        this.ea.publish('pubmed', payload);
        logger.debug('Publish pubmed data');
    }

    attached() {
        logger.debug('Attached Nanopub: ', this.nanopub);
        if (this.nanopub.citation.id) {
            this.citationId = this.nanopub.citation.id;
        } else {
            this.nanopub.citation = {};
            this.nanopub.citation.type = 'PubMed';
        }

        if (this.citationId && this.nanopub.citation.type === 'PubMed') {
            logger.debug('Here', this.nanopub.citation.type);
            this.collectPubmed();
        }
    }

    copyCitationId() {
        this.lastCitationId = JSON.parse(JSON.stringify(this.citationId));
        logger.debug('Copying CitationId to Last', this.lastCitationId);
    }

    nanopubChanged(value) {
        logger.debug('CitationChanged: ', this.nanopub);
        if (this.nanopub.citation.id) {
            this.citationId = this.nanopub.citation.id;
        } else {
            this.nanopub.citation = {};
            this.nanopub.citation.type = 'PubMed';
        }

        if (this.citationId && this.nanopub.citation.type === 'PubMed') {
            logger.debug('Here', this.nanopub.citation.type);
            this.collectPubmed();
        }
    }

    collectPubmed() {
        this.nanopub.citation.id = this.citationId;

        logger.debug('Id: ', this.citationId, 'Last', this.lastCitationId, ' Type: ', this.nanopub.citation.type);

        // Collect Pubmed data from service
        if (this.citationId && this.nanopub.citation.type === 'PubMed') {
            logger.debug('Id2: ', this.citationId, 'Last2', this.lastCitationId, ' Type: ', this.nanopub.citation.type);
            this.pubmedService.getPubmed(this.citationId)
              .then(pubmed => {
                  this.pubmed = pubmed;
                  if (this.citationId === this.lastCitationId) {
                      this.citationPubmedChecks();
                  } else {  // replace citation data if new CitationId
{'fraction_non_alphanumeric': 0.1200747547111042, 'fraction_numerical': 0.0006229559258682448, 'mean_word_length': 2.573734001112966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '486979', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1849, 'n_words': 417}