Blame view

js/app/views/PlotComponents/intervalSelection/IntervalSelection.js 9.22 KB
2b1b3d60   Menouard AZIB   Create a base com...
1
2
3
4
5
6
7
// Define a constant for the layout style of the form
const LAYOUT_STYLE = {
    type: 'vbox', // vertical box layout
    pack: 'start', // controls the vertical alignment of child items
    align: 'stretch' // each child item is stretched to fill the width of the container
};

2dc9b65a   Menouard AZIB   All refactored cm...
8
// Width of button
aba2eb97   Menouard AZIB   Add InsertToTTCat...
9
10
const width = 100;

9ea5aa6b   Menouard AZIB   Add comments to I...
11
// Define the parent class for all classes to use time interval selection.
2b1b3d60   Menouard AZIB   Create a base com...
12
13
14
15
16
17
18
19
20
21
Ext.define('amdaPlotComp.intervalSelection.IntervalSelection', {
    extend: 'Ext.window.Window', // This class extends from Ext.window.Window
    // Window configurations
    x: 0, y: 0, // The initial position of the window
    title: 'Interval Selection', // The title of the window
    constrain: true, // Constrains the window to within the boundaries of its containing element
    collapsible: true, // Allows the window to be collapsed
    resizable: false, // Prevents the window from being resizable
    ghost: false, // Disables "ghosting" (semi-transparent representation of the window body) when moving or resizing

9ea5aa6b   Menouard AZIB   Add comments to I...
22
23
    form: null, // a panel which contains all components
    hostCmp: null, // The host component from which this class is instantiated.
1591d4c2   Menouard AZIB   Basic functionali...
24
25
    interactiveId: '',
    panelId: -1,
2b1b3d60   Menouard AZIB   Create a base com...
26

9ea5aa6b   Menouard AZIB   Add comments to I...
27
    // Attributes of this class
2b1b3d60   Menouard AZIB   Create a base com...
28
    config: {
1591d4c2   Menouard AZIB   Basic functionali...
29
30
        field1Type: 'datefield', // The xtype of field1. By default is datefield because we are working with time series.
        field1Label: 'Start Time', // The label of field1.
aba2eb97   Menouard AZIB   Add InsertToTTCat...
31
        field1Format: 'Y/m/d H:i:s.u',
1591d4c2   Menouard AZIB   Basic functionali...
32
33
        field2Type: 'datefield', // The xtype of field2. By default is datefield.
        field2Label: 'Stop Time', // The label of field2.
aba2eb97   Menouard AZIB   Add InsertToTTCat...
34
        field2Format: 'Y/m/d H:i:s.u',
1591d4c2   Menouard AZIB   Basic functionali...
35
        buttonApply: 'Apply'
2b1b3d60   Menouard AZIB   Create a base com...
36
37
    },

aba2eb97   Menouard AZIB   Add InsertToTTCat...
38
39
40
41
    // Define the itemIds as constants
    // These will be used to reference the fields later in the code
    FIELD1_ITEM_ID: 'field1',
    FIELD2_ITEM_ID: 'field2',
2dc9b65a   Menouard AZIB   All refactored cm...
42
    buttonUseTime: 'button-use-time',
aba2eb97   Menouard AZIB   Add InsertToTTCat...
43

2b1b3d60   Menouard AZIB   Create a base com...
44
    initComponent: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
45
46
        const self = this; // Reference to this instance for use in event handlers
        this.form = new Ext.form.FormPanel({ // Create a new FormPanel instance and assign it to form
2b1b3d60   Menouard AZIB   Create a base com...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
            frame: true, // Display a frame around the panel
            width: 255, // Set the width of the panel
            layout: LAYOUT_STYLE, // Set the layout style of the panel
            fieldDefaults: {
                labelWidth: 60 // Set default label width for fields in this panel
            },
            items: [{
                xtype: 'fieldset', // Create a new FieldSet to group related fields together
                title: 'Interval Selection',
                name: 'interval-selection-fieldset',
                collapsible: false,
                layout: LAYOUT_STYLE,
                items: [{
                    xtype: this.field1Type,
                    fieldLabel: this.field1Label,
aba2eb97   Menouard AZIB   Add InsertToTTCat...
62
                    itemId: this.FIELD1_ITEM_ID,
3bda2729   Menouard AZIB   Fix some unwanted...
63
64
65
66
                    format: this.field1Format,
                    listeners: {
                        change: function (field, newValue) {
                            if (newValue === null || newValue === undefined || newValue === '') return;
9ea5aa6b   Menouard AZIB   Add comments to I...
67
                            var field2 = self._getField2();
3bda2729   Menouard AZIB   Fix some unwanted...
68
69
70
71
72
73
74
75
76
77
78
79
80
                            // Check if field2 is not empty
                            const value2 = field2.getValue();
                            if (value2 !== null && value2 !== undefined && value2 !== '') {
                                if (newValue > value2) {
                                    // Update both field1 and field2 to the new values
                                    field2.suspendEvents();
                                    field2.setValue(newValue);
                                    field.setValue(value2);
                                    field2.resumeEvents();
                                }
                            }
                        }
                    }
2b1b3d60   Menouard AZIB   Create a base com...
81
82
83
84
                },
                {
                    xtype: this.field2Type,
                    fieldLabel: this.field2Label,
aba2eb97   Menouard AZIB   Add InsertToTTCat...
85
                    itemId: this.FIELD2_ITEM_ID,
2b1b3d60   Menouard AZIB   Create a base com...
86
87
88
                    format: this.field2Format,
                    listeners: {
                        change: function (field, newValue) {
3bda2729   Menouard AZIB   Fix some unwanted...
89
                            if (newValue === null || newValue === undefined || newValue === '') return;
9ea5aa6b   Menouard AZIB   Add comments to I...
90
                            var field1 = self._getField1();
2b1b3d60   Menouard AZIB   Create a base com...
91
92
93
94
                            // Check if field1 is not empty
                            const value1 = field1.getValue();
                            if (value1 !== null && value1 !== undefined && value1 !== '') {
                                if (newValue < value1) {
1591d4c2   Menouard AZIB   Basic functionali...
95
                                    // Update both field1 and field2 to the new values
3bda2729   Menouard AZIB   Fix some unwanted...
96
                                    field1.suspendEvents();
2b1b3d60   Menouard AZIB   Create a base com...
97
98
                                    field1.setValue(newValue);
                                    field.setValue(value1);
3bda2729   Menouard AZIB   Fix some unwanted...
99
                                    field1.resumeEvents();
2b1b3d60   Menouard AZIB   Create a base com...
100
101
102
103
104
105
106
                                }
                            }
                        }
                    }
                }, {
                    xtype: 'button',
                    text: 'Reset',
aba2eb97   Menouard AZIB   Add InsertToTTCat...
107
                    width: width,
2b1b3d60   Menouard AZIB   Create a base com...
108
                    handler: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
109
                        self.reset();
2b1b3d60   Menouard AZIB   Create a base com...
110
                    }
2dc9b65a   Menouard AZIB   All refactored cm...
111
112
                },
                {
2b1b3d60   Menouard AZIB   Create a base com...
113
114
                    xtype: 'button',
                    text: 'Use in Time Selection',
2dc9b65a   Menouard AZIB   All refactored cm...
115
                    itemId: this.buttonUseTime,
2b1b3d60   Menouard AZIB   Create a base com...
116
                    handler: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
117
                        self._setTimeInterval();
2b1b3d60   Menouard AZIB   Create a base com...
118
119
                    }
                }]
1591d4c2   Menouard AZIB   Basic functionali...
120
121
122
123
            }],
            fbar: [
                {
                    xtype: 'button',
2dc9b65a   Menouard AZIB   All refactored cm...
124
                    width: width,
1591d4c2   Menouard AZIB   Basic functionali...
125
126
                    text: this.buttonApply,
                    handler: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
127
                        self._apply();
1591d4c2   Menouard AZIB   Basic functionali...
128
129
130
                    }
                }
            ]
2b1b3d60   Menouard AZIB   Create a base com...
131
132
133
        })

        Ext.apply(this, {
9ea5aa6b   Menouard AZIB   Add comments to I...
134
            items: this.form
2b1b3d60   Menouard AZIB   Create a base com...
135
136
        });

1591d4c2   Menouard AZIB   Basic functionali...
137
        this.setTitle(this.title + " - Panel Id : " + this.panelId);
2b1b3d60   Menouard AZIB   Create a base com...
138
139
140
        this.callParent(arguments);
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
141
142
143
144
145
    /**
     * Resets the time interval selection in the host component.
     * This function calls the resetZoom method on the panelImage of the host component,
     * effectively resetting any zoom applied to the image.
     */
2dc9b65a   Menouard AZIB   All refactored cm...
146
147
148
    _resetHostCmpSelection: function () {
        this.hostCmp.panelImage.resetZoom();
    },
1591d4c2   Menouard AZIB   Basic functionali...
149

9ea5aa6b   Menouard AZIB   Add comments to I...
150
151
152
153
154
155
156
    /**
 * Abstract method that must be implemented by subclasses.
 * Throws an error if not overridden.
 */
    _apply: function () {
        throw new Error('_apply() method must be implemented by subclass');
    },
1591d4c2   Menouard AZIB   Basic functionali...
157

9ea5aa6b   Menouard AZIB   Add comments to I...
158
159
160
161
    /**
     * Checks if the values of field1 and field2 are valid and if the form is valid.
     * Returns true if any of these conditions are not met.
     */
1591d4c2   Menouard AZIB   Basic functionali...
162
    _notValidValues: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
163
        return !this.getField1Value() || !this.getField2Value() || !this.form.getForm().isValid();
1591d4c2   Menouard AZIB   Basic functionali...
164
165
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
166
167
168
169
    /**
     * Retrieves the component associated with FIELD1_ITEM_ID in the form.
     * Returns the component if found, null otherwise.
     */
2b1b3d60   Menouard AZIB   Create a base com...
170
    _getField1: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
171
        return this.form.down('#' + this.FIELD1_ITEM_ID);
2b1b3d60   Menouard AZIB   Create a base com...
172
173
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
174
175
176
177
    /**
     * Retrieves the component associated with FIELD2_ITEM_ID in the form.
     * Returns the component if found, null otherwise.
     */
2b1b3d60   Menouard AZIB   Create a base com...
178
    _getField2: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
179
        return this.form.down('#' + this.FIELD2_ITEM_ID);
2b1b3d60   Menouard AZIB   Create a base com...
180
181
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
182
183
184
185
186
187
    /**
 * Sets the time interval of the plot based on the values of the fields.
 * This method is triggered when the buttonUseTime is clicked.
 * It creates a new time object with start, stop, and interactiveId properties,
 * and then calls the setTimeInterval method on the plot module with this object.
 */
a75892d1   Menouard AZIB   Cleaning the Plot...
188
189
190
191
192
193
194
195
196
    _setTimeInterval: function () {
        const timeObj = new Object();
        timeObj.start = this.getField1Value();
        timeObj.stop = this.getField2Value();
        timeObj.interactiveId = this.interactiveId;
        const plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
        plotModule.setTimeInterval(timeObj);
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
197
198
199
200
201
    /**
     * Hides the buttonUseTime when it's not needed.
     * For example, when we call Zoom on y-left axis we should not see this button.
     * It finds the button by its ID and then calls the hide method on it.
     */
a75892d1   Menouard AZIB   Cleaning the Plot...
202
    _removeUseTimeButton: function () {
9ea5aa6b   Menouard AZIB   Add comments to I...
203
        const buttonToHide = this.form.down('#' + this.buttonUseTime);
a75892d1   Menouard AZIB   Cleaning the Plot...
204
205
206
        buttonToHide.hide();
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
207
208
209
    /**
     * Retrieves the value of field1 from the form.
     */
2b1b3d60   Menouard AZIB   Create a base com...
210
211
212
213
    getField1Value: function () {
        return this._getField1().getValue();
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
214
215
216
    /**
     * Retrieves the value of field2 from the form.
     */
2b1b3d60   Menouard AZIB   Create a base com...
217
218
219
220
    getField2Value: function () {
        return this._getField2().getValue();
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
221
222
223
    /**
     * Sets a new value for field1 in the form.
     */
2b1b3d60   Menouard AZIB   Create a base com...
224
225
226
227
    setField1Value: function (value) {
        this._getField1().setValue(value);
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
228
229
230
    /**
     * Sets a new value for field2 in the form.
     */
2b1b3d60   Menouard AZIB   Create a base com...
231
232
    setField2Value: function (value) {
        this._getField2().setValue(value);
2dc9b65a   Menouard AZIB   All refactored cm...
233
234
    },

9ea5aa6b   Menouard AZIB   Add comments to I...
235
236
237
238
    /**
     * Resets the values of fields and host component selection.
     * It calls the reset method on field1 and field2, and then calls _resetHostCmpSelection.
     */
a75892d1   Menouard AZIB   Cleaning the Plot...
239
240
241
242
    reset: function () {
        this._getField1().reset();
        this._getField2().reset();
        this._resetHostCmpSelection();
2b1b3d60   Menouard AZIB   Create a base com...
243
    }
9ea5aa6b   Menouard AZIB   Add comments to I...
244

2b1b3d60   Menouard AZIB   Create a base com...
245
});