<commit_before>/**
 * Copyright 2015-2021 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "/web_modules/lit-element.js";
import {BaseManagerMixin} from "./base-manager.js";
import "../../commons/filters/variableset-id-autocomplete.js";
import "./annotation-manager.js";
import FormUtils from "../../../form-utils.js";


// eslint-disable-next-line new-cap
export default class AnnotationSetManager extends BaseManagerMixin(LitElement) {

    constructor() {
        super();
        this._init();
    }

    static get properties() {
        return {
            annotationSets: {
                type: Array
            }
        };
    }

    _init() {
        this.annotationSets = [];
        this.annotationSet = {
            annotations: {}
        };
        this.variableSetIds = [];
        this.annotations = {};
    }

    firstUpdated() {
        // Calling once this service
        this.variableSetObserver();
    }

    update(changedProperties) {
        if (this.annotationSets.length > 0) {
            this.annotationSetsObserver();
        }
        super.update(changedProperties);
    }

    async variableSetObserver() {
        try {
            const resp = await this.opencgaSession.opencgaClient.studies().variableSets(this.opencgaSession.study.fqn);
            this.variableSets = await resp.responses[0].results;
            this._variableSetIds = this.variableSets.map(item => item.id);
            const annotationSetIdsSelected = this.annotationSets.map(item => item.variableSetId);
            this.variableSetIds = this._variableSetIds.filter(variableSetId => !annotationSetIdsSelected.includes(variableSetId));
        } catch (error) {
            // TODO: Add Message to notify user;
            console.log(error);
        } finally {
            this._config = {...this.getDefaultConfig(), ...this.config};
            console.log("VariableSetId:...", this.variableSets);
        }
    }

    annotationSetsObserver() {
        const annotationSetIdsSelected = this.annotationSets.map(item => item.variableSetId);
        this.variableSetIds = this._variableSetIds.filter(variableSetId => !annotationSetIdsSelected.includes(variableSetId));
        this._config = {...this.getDefaultConfig(), ...this.config};
    }

    getVariablesById(variableId) {
        this.variableSet = this.variableSets.find(item => item.id === variableId);
        //     .variables.sort((a, b) => a.rank > b.rank? 1 : -1);
        console.log("Change AnnotationSetId ", this.variableSet);
        this._config = {...this.getDefaultConfig(), ...this.config};
        this.requestUpdate();
    }

    getDefaultConfig() {
        return {
            title: "Edit",
            icon: "fas fa-edit",<commit_msg>wc:retrieve variableSets with false internal value<commit_after>/**
 * Copyright 2015-2021 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "/web_modules/lit-element.js";
import {BaseManagerMixin} from "./base-manager.js";
import "../../commons/filters/variableset-id-autocomplete.js";
import "./annotation-manager.js";
import FormUtils from "../../../form-utils.js";


// eslint-disable-next-line new-cap
export default class AnnotationSetManager extends BaseManagerMixin(LitElement) {

    constructor() {
        super();
        this._init();
    }

    static get properties() {
        return {
            annotationSets: {
                type: Array
            }
        };
    }

    _init() {
        this.annotationSets = [];
        this.annotationSet = {
            annotations: {}
        };
        this.variableSetIds = [];
        this.annotations = {};
    }

    firstUpdated() {
        // Calling once this service
        this.variableSetObserver();
    }

    update(changedProperties) {
        if (this.annotationSets.length > 0) {
            this.annotationSetsObserver();
        }
        super.update(changedProperties);
    }

    async variableSetObserver() {
        try {
            const resp = await this.opencgaSession.opencgaClient.studies().variableSets(this.opencgaSession.study.fqn);
            this.variableSets = await resp.responses[0].results;
            this._variableSetIds = this.variableSets.filter(item => !item.internal).map(item => item.id);
            const annotationSetIdsSelected = this.annotationSets.map(item => item.variableSetId);
            this.variableSetIds = this._variableSetIds.filter(variableSetId => !annotationSetIdsSelected.includes(variableSetId));
        } catch (error) {
            // TODO: Add Message to notify user;
            console.log(error);
        } finally {
            this._config = {...this.getDefaultConfig(), ...this.config};
            console.log("VariableSetId:...", this.variableSets);
        }
    }

    annotationSetsObserver() {
        const annotationSetIdsSelected = this.annotationSets.map(item => item.variableSetId);
        this.variableSetIds = this._variableSetIds.filter(variableSetId => !annotationSetIdsSelected.includes(variableSetId));
        this._config = {...this.getDefaultConfig(), ...this.config};
    }

    getVariablesById(variableId) {
        this.variableSet = this.variableSets.find(item => item.id === variableId);
        //     .variables.sort((a, b) => a.rank > b.rank? 1 : -1);
        console.log("Change AnnotationSetId ", this.variableSet);
        this._config = {...this.getDefaultConfig(), ...this.config};
        this.requestUpdate();
    }

    getDefaultConfig() {
        return {
            title: "Edit",
            icon: "fas fa-edit",
{'fraction_non_alphanumeric': 0.12337858220211162, 'fraction_numerical': 0.0048265460030165915, 'mean_word_length': 2.486330178759201, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7589490', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1744, 'n_words': 417}