<commit_before>/**
 * Copyright 2015-2019 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 UtilsNew from "./../../utilsNew.js";
import "../commons/tool-header.js";

export default class StudyForm extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            project: {
                type: Object
            },
            opencgaSession: {
                type: Object
            },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._prefix = UtilsNew.randomString(8);
        this.newStudy = {}
    }

    connectedCallback() {
        super.connectedCallback();
        // this._config = { ...this.getDefaultConfig(), ...this.config };
    }

    update(changedProperties) {
        // checking if this component receive the project
        console.log("Project for the new Study: ",this.project?.fqn) 
        super.update(changedProperties);
    }

    onFieldChange(e) {
        switch (e.detail.param) {
            case "id":
            case "name":
            case "description":
                this.study[e.detail.param] = e.detail.value;
                break;
        }
    }

    getSaveForm(e) {
        console.log(e.detail.param)
    }

    onSave(e) {
        // TODO: Check it's ok ?
        this.opencgaSession.opencgaClient.studies().create(this.study, { project: this.project.fqn })
            .then(res => {
                this.study = {};
                this.requestUpdate();

                this.dispatchEvent(new CustomEvent("sessionUpdateRequest", {
                    detail: {
                    },
                    bubbles: true,
                    composed: true
                }));

                Swal.fire(
                    "New Study",
                    "New Study created correctly.",
                    "success"
                );
            })
            .catch(err => {
                console.error(err);
                params.error(err);
            });
    }

    onHide() {
        this.dispatchEvent(new CustomEvent("hide", {
            detail: {},
            bubbles: true,
            composed: true
        }));
    }

    getStudyFormConfig() {
        return {
            title: "Edit",
            icon: "fas fa-edit",
            type: "form",
            buttons: {
                show: true,
                cancelText: "Cancel",
                okText: "Save"
            },
            display: {
                style: "margin: 25px 50px 0px 0px",
                // mode: {
                //     type: "modal",
                //     title: "Review Variant",
                //     buttonClass: "btn-link"
                // },
                labelWidth: 3,
                labelAlign: "right",<commit_msg>wc:fix an add new study<commit_after>/**
 * Copyright 2015-2019 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 UtilsNew from "./../../utilsNew.js";
import "../commons/tool-header.js";

export default class StudyForm extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            project: {
                type: Object
            },
            opencgaSession: {
                type: Object
            },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._prefix = UtilsNew.randomString(8);
        this.newStudy = {}
        this.study = {}
    }

    connectedCallback() {
        super.connectedCallback();
        // this._config = { ...this.getDefaultConfig(), ...this.config };
    }

    update(changedProperties) {
        // checking if this component receive the project
        console.log("Project for the new Study: ",this.project?.fqn) 
        super.update(changedProperties);
    }

    onFieldChange(e) {
        switch (e.detail.param) {
            case "id":
            case "name":
            case "description":
                this.study[e.detail.param] = e.detail.value;
                break;
        }
    }

    getSaveForm(e) {
        console.log(e.detail.param)
    }

    onSave(e) {
        // TODO: Check it's ok ?
        this.opencgaSession.opencgaClient.studies().create(this.study, { project: this.project.fqn })
            .then(res => {
                this.study = {};
                this.requestUpdate();

                this.dispatchEvent(new CustomEvent("sessionUpdateRequest", {
                    detail: {
                    },
                    bubbles: true,
                    composed: true
                }));

                Swal.fire(
                    "New Study",
                    "New Study created correctly.",
                    "success"
                );
            })
            .catch(err => {
                console.error(err);
                params.error(err);
            });
            $(`#newStudy`).modal("hide"); // TODO: refactor this function.
    }

    onHide() {
        this.dispatchEvent(new CustomEvent("hide", {
            detail: {},
            bubbles: true,
            composed: true
        }));
    }

    getStudyFormConfig() {
        return {
            title: "Edit",
            icon: "fas fa-edit",
            type: "form",
            buttons: {
                show: true,
                cancelText: "Cancel",
                okText: "Save"
            },
            display: {
                style: "margin: 25px 50px 0px 0px",
                // mode: {
                //     type: "modal",
                //     title: "Review Variant",
                //     buttonClass: "btn-link"
                // },
                labelWidth: 3,
                labelAlign: "right",
{'fraction_non_alphanumeric': 0.1123486008631491, 'fraction_numerical': 0.005568703884170959, 'mean_word_length': 1.351554828150573, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, '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': '7047868', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1802, 'n_words': 477}