|
165 | 165 | <script src="{% static 'bootstrap-table/dist/themes/bootstrap-table/bootstrap-table.min.js' %}"></script> |
166 | 166 |
|
167 | 167 | <script type="text/javascript"> |
| 168 | + // Tooltip message for unstable portfolios |
| 169 | + const IN_DEVELOPMENT_MSG = 'is in development'; |
| 170 | + // Wrench emoji HTML for unstable portfolios (no custom class, just Bootstrap) |
| 171 | + const WRENCH_HTML = '<span class="ms-2 float-end">🧪️</span>'; |
| 172 | + |
168 | 173 | let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); |
169 | 174 | let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { |
170 | 175 | const tooltip = new bootstrap.Tooltip(tooltipTriggerEl); |
|
185 | 190 | .then(response => response.json()) |
186 | 191 | .then(data => { |
187 | 192 | const selectedPortfolio = document.getElementById("selectPortfolio"); |
188 | | - selectedPortfolio.innerHTML = `<img src="${data.selected_portfolio.logo}" alt="${data.selected_portfolio.id}" width="25" height="25" class="rounded-circle me-2 sidebar-icon flex-shrink-0"><span class="sidebar-text">${data.selected_portfolio.name}</span>`; |
| 193 | + // Always keep dropdown functionality |
| 194 | + selectedPortfolio.setAttribute("data-bs-toggle", "dropdown"); |
| 195 | + selectedPortfolio.setAttribute("aria-expanded", "false"); |
| 196 | + selectedPortfolio.classList.add("dropdown-toggle"); |
| 197 | + selectedPortfolio.classList.remove("non-clickable"); |
| 198 | + |
| 199 | + // Consistent stability check: treat as stable unless stable is explicitly false |
| 200 | + const selectedStable = data.selected_portfolio.stable !== false; |
| 201 | + let selectedPortfolioHTML = `<img src="${data.selected_portfolio.logo}" alt="${data.selected_portfolio.id}" width="25" height="25" class="rounded-circle me-2 sidebar-icon flex-shrink-0"><span class="sidebar-text">${data.selected_portfolio.name}</span>`; |
| 202 | + if (!selectedStable) { |
| 203 | + selectedPortfolioHTML += WRENCH_HTML; |
| 204 | + selectedPortfolio.setAttribute("title", `${data.selected_portfolio.name} ${IN_DEVELOPMENT_MSG}`); |
| 205 | + // Initialize tooltip for selectPortfolio |
| 206 | + if (!bootstrap.Tooltip.getInstance(selectedPortfolio)) { |
| 207 | + new bootstrap.Tooltip(selectedPortfolio); |
| 208 | + } |
| 209 | + } else { |
| 210 | + selectedPortfolio.removeAttribute("title"); |
| 211 | + const tooltipInstance = bootstrap.Tooltip.getInstance(selectedPortfolio); |
| 212 | + if (tooltipInstance) tooltipInstance.dispose(); |
| 213 | + } |
| 214 | + selectedPortfolio.innerHTML = selectedPortfolioHTML; |
189 | 215 |
|
190 | 216 | const portfolioMenu = document.getElementById("sidebar-portfolio-menu"); |
191 | 217 | portfolioMenu.innerHTML = ""; // Clear existing menu items |
192 | 218 |
|
193 | 219 | if (data.available_portfolios.length === 1) { |
194 | 220 | // Remove the dropdown toggle if there is only one portfolio |
195 | 221 | selectedPortfolio.removeAttribute("data-bs-toggle"); |
| 222 | + selectedPortfolio.removeAttribute("aria-expanded"); |
196 | 223 | selectedPortfolio.classList.remove("dropdown-toggle"); |
197 | 224 | selectedPortfolio.classList.add("non-clickable"); |
198 | 225 | } else { |
199 | 226 | // Show the portfolio selector dropdown only when there are multiple portfolios |
200 | 227 | data.available_portfolios.forEach(portfolio => { |
201 | 228 | const menuItem = document.createElement("li"); |
202 | | - menuItem.innerHTML = `<a class="dropdown-item portfolio-link-filter" href="#" data-value="${portfolio.id}"><img src="${portfolio.logo}" alt="${portfolio.id}" width="25" height="25" class="rounded-circle me-2">${portfolio.name}</a>`; |
| 229 | + // Consistent stability check for each portfolio |
| 230 | + const isStable = portfolio.stable !== false; |
| 231 | + const tooltipAttrs = !isStable ? ` data-bs-toggle=\"tooltip\" title=\"${portfolio.name} ${IN_DEVELOPMENT_MSG}\"` : ''; |
| 232 | + const menuItemHTML = ` |
| 233 | + <a class="dropdown-item portfolio-link-filter d-flex align-items-center justify-content-between" href="#" data-value="${portfolio.id}"${tooltipAttrs}> |
| 234 | + <span> |
| 235 | + <img src="${portfolio.logo}" alt="${portfolio.id}" width="25" height="25" class="rounded-circle me-2"> |
| 236 | + ${portfolio.name} |
| 237 | + </span> |
| 238 | + ${!isStable ? WRENCH_HTML : ''} |
| 239 | + </a> |
| 240 | + `; |
| 241 | + menuItem.innerHTML = menuItemHTML; |
203 | 242 |
|
204 | 243 | // Add click event listener to menuItem |
205 | 244 | menuItem.querySelector("a").addEventListener("click", function(event) { |
|
225 | 264 | }); |
226 | 265 | } |
227 | 266 |
|
| 267 | + // Initialize tooltips for new elements |
| 268 | + const newTooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); |
| 269 | + newTooltipTriggerList.forEach(function (tooltipTriggerEl) { |
| 270 | + if (!bootstrap.Tooltip.getInstance(tooltipTriggerEl)) { |
| 271 | + new bootstrap.Tooltip(tooltipTriggerEl); |
| 272 | + } |
| 273 | + }); |
| 274 | + |
228 | 275 | // Restore sidebar state after portfolio data is loaded |
229 | 276 | restoreSidebarState(); |
230 | 277 | }); |
|
0 commit comments