|
| 1 | + |
| 2 | +function getCurrentFolder(){ |
| 3 | + if (window.location.pathname.startsWith("/folder/")){ |
| 4 | + currentFolder = window.location.pathname.substring("/folder/".length) + "/" |
| 5 | + } else { |
| 6 | + currentFolder = "" |
| 7 | + } |
| 8 | + return currentFolder |
| 9 | +} |
| 10 | + |
| 11 | +function updateNavigationPanel(currentFolder){ |
| 12 | + let $folderNavigationPanel = $('#folderNavigationPanel'); |
| 13 | + $folderNavigationPanel.empty() |
| 14 | + |
| 15 | + if (currentFolder != "") { |
| 16 | + $folderNavigationPanel.append('<a href="/">Start</a>') |
| 17 | + parts = currentFolder.split("/") |
| 18 | + folderSoFar = "" |
| 19 | + for(let idx in parts){ |
| 20 | + part = parts[idx] |
| 21 | + if(part.length > 0){ |
| 22 | + folderSoFar = folderSoFar + "/" + part |
| 23 | + if(idx == parts.length - 2){ |
| 24 | + $folderNavigationPanel.append(' > <span>' + part + "</span>") |
| 25 | + }else{ |
| 26 | + $folderNavigationPanel.append(' > <a href="/folder' + folderSoFar + '">' + part + " </a>") |
| 27 | + } |
| 28 | + |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +function entryAfterLevel(path, level){ |
| 36 | + while(level > 0) { |
| 37 | + path = path.substring(path.indexOf('/') + 1) |
| 38 | + level = level - 1 |
| 39 | + } |
| 40 | + return path |
| 41 | +} |
| 42 | + |
| 43 | +function updateContents(currentFolder, entries){ |
| 44 | + let $cardContainer = $('#cardContainer'); |
| 45 | + $cardContainer.empty(); |
| 46 | + subfoldersInfo = {} |
| 47 | + reportParts = [] |
| 48 | + for (let report in entries) { |
| 49 | + report_data = entries[report] |
| 50 | + report_path = report_data.report_name |
| 51 | + if(!report_path.startsWith(currentFolder)){ |
| 52 | + continue; |
| 53 | + } |
| 54 | + remainingPath = report_path.substring(currentFolder.length) |
| 55 | + if(remainingPath.includes('/')) { |
| 56 | + // it is a folder |
| 57 | + subfolderPathName = remainingPath.substring(0, remainingPath.indexOf('/')) |
| 58 | + subfolderPath = currentFolder + subfolderPathName |
| 59 | + if (subfolderPath in subfoldersInfo) { |
| 60 | + info.reportCount = info.reportCount + 1 |
| 61 | + } else{ |
| 62 | + info = {} |
| 63 | + info.pathName = subfolderPathName |
| 64 | + info.path = subfolderPath |
| 65 | + info.reportCount = 1 |
| 66 | + subfoldersInfo[subfolderPath] = info |
| 67 | + } |
| 68 | + }else{ |
| 69 | + level = currentFolder.split('/').length - 1 |
| 70 | + displayName = entryAfterLevel(report, level) |
| 71 | + let stats = entries[report]; |
| 72 | + reportParts.push('<a class="ui card" href="/result_listing/' + stats.report_name + '">' + |
| 73 | + ' <div class="content">' + |
| 74 | + ' <h1>' + displayName + '</h1>\n' + |
| 75 | + ' <div class="meta">\n' + |
| 76 | + ' <span class="date">Last ran ' + stats.time_diff + ' ago</span>\n' + |
| 77 | + ' </div>' + |
| 78 | + ' <span>\n' + |
| 79 | + stats.count + |
| 80 | + ' Runs\n' + |
| 81 | + ' </span>' + |
| 82 | + '<br/>' + |
| 83 | + ' <span>\n' + |
| 84 | + stats.scheduler_runs + |
| 85 | + ' Scheduler Runs\n' + |
| 86 | + ' </span>' + |
| 87 | + ' </div>' + |
| 88 | + ' <div class="extra content">' + |
| 89 | + ' <span>Original report name: ' + stats.report_name + '</span>\n' + |
| 90 | + ' </div>' + |
| 91 | + '</a>'); |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + } |
| 96 | + // first add all folders |
| 97 | + for (let subfolder in subfoldersInfo) { |
| 98 | + info = subfoldersInfo[subfolder] |
| 99 | + $cardContainer.append( |
| 100 | + '<a class="ui card folder" href="/folder/' + info.path + '">' + |
| 101 | + ' <div class="content">' + |
| 102 | + ' <h1><i class="fa-solid fa-folder fa-xs"></i> ' + info.pathName + '</h1>\n' + |
| 103 | + ' <span>Reports: ' + info.reportCount + '</span>' + |
| 104 | + ' </div>' + |
| 105 | + '</a>'); |
| 106 | + } |
| 107 | + // only then add individual items |
| 108 | + for (let idx in reportParts) { |
| 109 | + $cardContainer.append(reportParts[idx]) |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | + |
1 | 114 | load_data = () => { |
2 | 115 | $.ajax({ |
3 | | - url: `/core/get_all_templates_with_results`, |
| 116 | + url: `/core/get_all_templates_with_results/folder/`.concat(getCurrentFolder()), |
4 | 117 | dataType: 'json', |
5 | 118 | success: (result) => { |
6 | | - let $cardContainer = $('#cardContainer'); |
7 | | - $cardContainer.empty(); |
8 | | - for (let report in result) { |
9 | | - let stats = result[report]; |
10 | | - $cardContainer.append( |
11 | | - '<a class="ui card" href="/result_listing/' + stats.report_name + '">' + |
12 | | - ' <div class="content">' + |
13 | | - ' <h1>' + report + '</h1>\n' + |
14 | | - ' <div class="meta">\n' + |
15 | | - ' <span class="date">Last ran ' + stats.time_diff + ' ago</span>\n' + |
16 | | - ' </div>' + |
17 | | - ' <span>\n' + |
18 | | - stats.count + |
19 | | - ' Runs\n' + |
20 | | - ' </span>' + |
21 | | - '<br/>' + |
22 | | - ' <span>\n' + |
23 | | - stats.scheduler_runs + |
24 | | - ' Scheduler Runs\n' + |
25 | | - ' </span>' + |
26 | | - ' </div>' + |
27 | | - ' <div class="extra content">' + |
28 | | - ' <span>Original report name: ' + stats.report_name + '</span>\n' + |
29 | | - ' </div>' + |
30 | | - '</a>'); |
31 | | - } |
| 119 | + currentFolder = getCurrentFolder() |
| 120 | + updateNavigationPanel(currentFolder) |
| 121 | + updateContents(currentFolder, result) |
32 | 122 | }, |
33 | 123 | error: (jqXHR, textStatus, errorThrown) => { |
34 | 124 | $('#failedLoad').fadeIn(); |
|
0 commit comments