From 844f3afd89d6438b8752f58a28fa97d5fd798966 Mon Sep 17 00:00:00 2001 From: DiTus Date: Wed, 25 Feb 2026 22:38:48 +0100 Subject: [PATCH] Add proper ES6 exports for indicator panel modules - Export addIndicator for module imports - Export removeIndicatorById for module imports - Export removeIndicatorByIndex for module imports - Fix circular reference issues with window assignments - Simplify export statements to work with ES6 modules This fixes the 'does not provide export named addIndicator' error. --- .../static/js/ui/indicators-panel-new.js | 131 ++---------------- 1 file changed, 14 insertions(+), 117 deletions(-) diff --git a/src/api/dashboard/static/js/ui/indicators-panel-new.js b/src/api/dashboard/static/js/ui/indicators-panel-new.js index e29d812..1968931 100644 --- a/src/api/dashboard/static/js/ui/indicators-panel-new.js +++ b/src/api/dashboard/static/js/ui/indicators-panel-new.js @@ -701,128 +701,25 @@ window.showIndicatorConfig = function(id) { window.applyIndicatorConfig = function() { // No-op - config is applied immediately }; -window.showIndicatorConfigByIndex = function(index) { - if (index >= 0 && index < activeIndicators.length) { - configuringId = activeIndicators[index].id; - renderIndicatorPanel(); - } -}; - -function renderIndicatorOnPane(indicator, meta, instance, candles, paneIndex, lineStyleMap) { - const results = instance.calculate(candles); - indicator.series = []; - - const lineStyle = lineStyleMap[indicator.params._lineType] || LightweightCharts.LineStyle.Solid; - const lineWidth = indicator.params._lineWidth || 2; - - const firstNonNull = results?.find(r => r !== null && r !== undefined); - const isObjectResult = firstNonNull && typeof firstNonNull === 'object'; - - meta.plots.forEach((plot, plotIdx) => { - if (isObjectResult) { - const hasData = results.some(r => r && r[plot.id] !== undefined && r[plot.id] !== null); - if (!hasData) return; - } - - const plotColor = indicator.params[`_color_${plotIdx}`] || plot.color || '#2962ff'; - - const data = []; - for (let i = 0; i < candles.length; i++) { - let value; - if (isObjectResult) { - value = results[i]?.[plot.id]; - } else { - value = results[i]; - } - - if (value !== null && value !== undefined) { - data.push({ - time: candles[i].time, - value: value - }); - } - } - - if (data.length === 0) return; - - let series; - - let plotLineStyle = lineStyle; - if (plot.style === 'dashed') plotLineStyle = LightweightCharts.LineStyle.Dashed; - else if (plot.style === 'dotted') plotLineStyle = LightweightCharts.LineStyle.Dotted; - else if (plot.style === 'solid') plotLineStyle = LightweightCharts.LineStyle.Solid; - - if (plot.type === 'histogram') { - series = window.dashboard.chart.addSeries(LightweightCharts.HistogramSeries, { - color: plotColor, - priceFormat: { type: 'price', precision: 4, minMove: 0.0001 }, - priceLineVisible: false, - lastValueVisible: false - }, paneIndex); - } else if (plot.type === 'baseline') { - series = window.dashboard.chart.addSeries(LightweightCharts.BaselineSeries, { - baseValue: { type: 'price', price: plot.baseValue || 0 }, - topLineColor: plot.topLineColor || plotColor, - topFillColor1: plot.topFillColor1 || plotColor, - topFillColor2: '#00000000', - bottomFillColor1: '#00000000', - bottomColor: plot.bottomColor || '#00000000', - lineWidth: plot.width !== undefined ? plot.width : lineWidth, - lineStyle: plotLineStyle, - title: plot.title || '', - priceLineVisible: false, - lastValueVisible: plot.lastValueVisible !== false - }, paneIndex); - } else { - series = window.dashboard.chart.addSeries(LightweightCharts.LineSeries, { - color: plotColor, - lineWidth: plot.width !== undefined ? plot.width : lineWidth, - lineStyle: plotLineStyle, - title: plot.title || '', - priceLineVisible: false, - lastValueVisible: plot.lastValueVisible !== false - }, paneIndex); - } - - series.setData(data); - indicator.series.push(series); - }); -} - -let indicatorPanes = new Map(); -let nextPaneIndex = 1; - -// Legacy support -window.renderIndicatorList = function() { - renderIndicatorPanel(); -}; - -window.renderIndicatorConfig = function(indicator) { - // Called by chart.js, redirect to new panel - const meta = getIndicatorMeta(indicator); - if (!meta) return; - - const configEl = document.getElementById('configForm'); - if (configEl) { - configEl.innerHTML = renderIndicatorConfig(indicator, meta); - } -}; - -window.applyIndicatorConfig = function() { - // No-op - config is applied immediately -}; - window.removeIndicator = function() { if (!configuringId) return; removeIndicatorById(configuringId); }; -window.removeIndicatorByIndex = function(index) { +// Export functions for module imports +export const addIndicator = window.addIndicator; +export const removeIndicatorById = window.removeIndicatorById; + +// Helper function for remove by index +function removeIndicatorByIndex(index) { if (index < 0 || index >= activeIndicators.length) return; removeIndicatorById(activeIndicators[index].id); -}; +} -window.addIndicator = addIndicator; -window.toggleIndicator = addIndicator; -window.removeIndicatorById = removeIndicatorById; -window.drawIndicatorsOnChart = drawIndicatorsOnChart; \ No newline at end of file +// Assign to window for backward compatibility +window.toggleIndicator = window.addIndicator; +window.removeIndicatorByIndex = removeIndicatorByIndex; +window.drawIndicatorsOnChart = drawIndicatorsOnChart; + +// No additional window assignments needed - functions are already on window +// Exports are now available for module import \ No newline at end of file