ParamField.js 4.11 KB
/**
 * Un composant de 'PlotFunction' qui permet d'afficher le min samplig de chaque paramètre et le nombre de points théoriques entre un start time et stop time
 */
Ext.define('amdaPlotComp.plotFunction.ParamField', {
    extend: 'Ext.form.Panel',
    /**
     * id du composant de type numberfield qui hébérge le min sampling
     */
    label_number_field: "NUMBERFIELD",
    /**
     * id du composant de type numberfield qui hébérge le nombre de points
     */
    label_number_field1: "NUMBERFIELD1",
    /**
     * Le composant parent de celui-ci
     */
    parent: null,

    initComponent: function () {
        const items_params = [];
        const minSampling = "Sampling Time (s)";
        const minValue = 0;
        const labelWitdh = 120;
        const width = 30;

        for (p in this.params) {
            const param = this.params[p];
            const fieldSet = {
                xtype: 'fieldset',
                name: 'FIELDSET' + param.id,
                title: param.id,
                collapsible: false,
                layout: {
                    type: 'vbox',
                    align: 'stretch',
                },
                items: [
                    {
                        xtype: 'numberfield',
                        name: this.label_number_field + param.id,
                        labelWidth: labelWitdh,
                        width: width,
                        value: param.MinSampling,
                        minValue: minValue,
                        disabled: true,
                        fieldLabel: minSampling
                    },
                    {
                        xtype: 'numberfield',
                        name: this.label_number_field1 + param.id,
                        labelWidth: labelWitdh,
                        width: width,
                        value: 0,
                        minValue: minValue,
                        fieldLabel: "Nb Points"
                    }
                ]
            };

            items_params.push(fieldSet);
        }

        const tabParams = Ext.create('Ext.tab.Panel', {
            layout: 'fit',
            plain: true,
            bodyStyle: 'background: none',
            items: items_params
        });

        const config =
        {
            title: 'Parameters Sampling',
            layout: 'fit',
            bodyStyle: { background: '#dfe8f6' },
            items: [tabParams]
        };

        Ext.apply(this, config);
        //Les arguments sont les paramètres, chaque paramètre contient un id et un min Sampling
        this.callParent(arguments);
    },

    /**
     * Set parent
     * @param {*} parent_ le parent qui contient ce composant
     */
    setParent: function (parent_) {
        this.parent = parent_;
    },

    /**
     * Retourne les valeurs d'id, min sampling et nb_points de tout les parametres passés comme argument 
     * @returns id1@minSampling1@nb_points1@id2@minSampling2@nb_points2....
     */
    getValues: function () {
        let list = "";
        const delimeter = "@";
        let i = 0;
        for (p in this.params) {
            let param = this.params[p];
            const ui_item = this.parent.findField(this.label_number_field1 + param.id);
            if (i > 0) list += delimeter;
            if (ui_item !== undefined && ui_item !== null) {
                list += param.id + delimeter + param.MinSampling + delimeter + ui_item.getValue() + delimeter + "5";
            }
            i++;
        }
        return { "param_nb_points": list };
    },

    /**
     * Mettre à jour le nb_points en fonction de la valeur de start time et stop time passés en paramètres
     * @param {*} startTime le start time issu du ZoomPlugin
     * @param {*} stopTime le stop time issu du ZoomPlugin
     */
    setValues: function (startTime, stopTime) {
        for (p in this.params) {
            let param = this.params[p];
            const nb_points = (stopTime.getTime() - startTime.getTime()) / (1000. * param.MinSampling);
            const ui_item = this.parent.findField(this.label_number_field1 + param.id);
            ui_item.setValue(parseInt(nb_points));
        }
    }
});