| 2015 | const currentId = button.dataset.id; |
| 2016 | |
| 2017 | const create = () => { |
| 2018 | let requestUrl = OC.generateUrl('apps/analytics/threshold'); |
| 2019 | const selectedColumn = document.getElementById('thresholdDimension').value; |
| 2020 | const isFlexible = OCA.Analytics.Flexible.isFlexible(OCA.Analytics.currentReportData); |
| 2021 | const selectedIndex = parseInt(selectedColumn, 10); |
| 2022 | const isCalculatedColumn = selectedIndex >= OCA.Analytics.Visualization.thresholdCalculatedColumnOffset; |
| 2023 | let sourceColumnRef = isFlexible ? selectedColumn : null; |
| 2024 | if (isFlexible && isCalculatedColumn) { |
| 2025 | const calculationIndex = selectedIndex - OCA.Analytics.Visualization.thresholdCalculatedColumnOffset; |
| 2026 | const calculation = OCA.Analytics.Visualization.getCalculatedColumns( |
| 2027 | OCA.Analytics.currentReportData.options.tableoptions || {} |
| 2028 | )[calculationIndex]; |
| 2029 | sourceColumnRef = (calculation?.columns || []) |
| 2030 | .map(reference => String(reference).match(/^source-ref\|(c_[1-9][0-9]*)$/)?.[1]) |
| 2031 | .find(Boolean) || OCA.Analytics.currentReportData.columnRefs?.[0]; |
| 2032 | } |
| 2033 | fetch(requestUrl, { |
| 2034 | method: 'POST', |
| 2035 | headers: OCA.Analytics.headers(), |
| 2036 | body: JSON.stringify({ |
| 2037 | reportId: reportId, |
| 2038 | dimension: isFlexible && !isCalculatedColumn |
| 2039 | ? OCA.Analytics.Flexible.indexForReference(OCA.Analytics.currentReportData, selectedColumn) |
| 2040 | : selectedColumn, |
| 2041 | sourceColumnRef: sourceColumnRef, |
| 2042 | option: document.getElementById('thresholdOption').value, |
| 2043 | value: document.getElementById('thresholdValue').value, |
| 2044 | severity: document.getElementById('thresholdSeverity').value, |
| 2045 | coloring: document.getElementById('thresholdColoring').value, |
| 2046 | }) |
| 2047 | }) |
| 2048 | .then(response => response.json()) |
| 2049 | .then(data => { |
| 2050 | delete button.dataset.id; |
| 2051 | OCA.Analytics.Threshold.getThreholdList(reportId); |
| 2052 | OCA.Analytics.Threshold.resetThresholdInputs(); |
| 2053 | if (!OCA.Analytics.isDataset) { |
| 2054 | OCA.Analytics.Report.resetContentArea(); |
| 2055 | OCA.Analytics.Report.Backend.getData(); |
| 2056 | } |
| 2057 | }); |
| 2058 | }; |
| 2059 | |
| 2060 | if (currentId) { |
| 2061 | let delUrl = OC.generateUrl('apps/analytics/threshold/') + currentId; |