From aa68d0a0219f7ef829e8231e764d2f4e4f608b5e Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Sat, 2 Sep 2023 18:40:16 +0200 Subject: [PATCH] [indexing] IDEA-310006 Externalize index diagnostic dumber static resources GitOrigin-RevId: ca9771ac527ce0ec0b6258a67c4a16f00db5cad5 --- .../presentation/jsonToHtmlConverter.kt | 215 +++--------------- .../presentation/res/hide-elements.js | 7 + .../diagnostic/presentation/res/logo.svg | 21 ++ .../diagnostic/presentation/res/styles.css | 131 +++++++++++ .../diagnostic/presentation/res/table-row.js | 9 + 5 files changed, 201 insertions(+), 182 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/hide-elements.js create mode 100644 platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/logo.svg create mode 100644 platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/styles.css create mode 100644 platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/table-row.js diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/jsonToHtmlConverter.kt b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/jsonToHtmlConverter.kt index 7992f80e7538..68180e6f09f7 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/jsonToHtmlConverter.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/jsonToHtmlConverter.kt @@ -12,7 +12,7 @@ import com.intellij.util.indexing.diagnostic.JsonSharedIndexDiagnosticEvent import com.intellij.util.indexing.diagnostic.dto.* import kotlinx.html.* import kotlinx.html.stream.appendHTML -import org.intellij.lang.annotations.Language +import java.nio.charset.StandardCharsets import java.util.* internal fun createAggregateActivityHtml( @@ -969,190 +969,41 @@ private fun DIV.printProjectNameForActivity(projectName: String) { } } - -@Suppress("CssUnusedSymbol") -@Language("CSS") -private val CSS_STYLE = """ - body { - font-family: Arial, sans-serif; - margin: 0; - } - - table, th, td { - border: 1px solid black; - border-collapse: collapse; - } - - table { - width: 80%; - } - - table.activity-table { - width: 100%; - } - - table.narrow-activity-table { - width: 80%; - } - - table.two-columns td { - width: 50%; - } - - th, td { - padding: 3px; - } - - th { - background: lightgrey; - } - - td { - white-space: pre-wrap; - word-break: break-word; - } - - .stats-content { - margin-left: 20%; - } - - .stats-activity-content { - margin-left: 20%; - margin-right: 5%; - } - - .aggregate-report-content { - margin-left: 10%; - } - - .aggregate-activity-report-content { - margin-left: 15%; - margin-right: 15%; - } - - .aggregate-header { - padding-top: 1em; - padding-bottom: 1em; - margin-bottom: 0; - } - - .table-with-margin{ - margin-top: 1em; - margin-bottom: 2em; - } - - .navigation-bar { - width: 15%; - background-color: lightgrey; - position: fixed; - height: 100%; - } - - div.navigation-bar ul { - list-style-type: none; - overflow: auto; - margin: 0; - padding: 0; - font-size: 24px; - } - - div.navigation-bar ul li a, label { - display: block; - color: #000; - padding: 8px 20px; - text-decoration: none; - } - - label input { - margin-left: 10px; - width: 20px; - height: 20px; - } - - div.navigation-bar ul li a:hover { - background-color: #555; - color: white; - } - - .minor-data {} - - .invisible { - display: none; - } - - .jetbrains-logo { - width: 50%; - bottom: 5%; - position: absolute; - left: 20%; - } - - .centered-text { - text-align: center; - } - - .linkable-table-row:hover { - background: #f2f3ff; - outline: none; - cursor: pointer; - } - - .scanning-table-row { - background-color: aliceblue; - } - - .not-applicable-data{ - color: darkgrey; - } -""".trimIndent() - -@Language("JavaScript") -private val LINKABLE_TABLE_ROW_SCRIPT = """ - document.addEventListener("DOMContentLoaded", () => { - const rows = document.getElementsByClassName("linkable-table-row") - for (const row of rows) { - const href = row.getAttribute("href") - row.addEventListener("click", () => { - window.open(href, "_blank"); - }); - } - }); -""".trimIndent() - -@Language("JavaScript") -private val JS_SCRIPT = """ - function hideElementsHavingClass(className, hideOrShow) { - const elements = document.getElementsByClassName(className) - const displayType = hideOrShow ? 'none' : 'initial' - for (const element of elements) { - element.classList.toggle('invisible', hideOrShow) +private val CSS_STYLE: String + get() { + val inputStream = IndexDiagnosticDumper::class.java.getResourceAsStream( + "/com/intellij/util/indexing/diagnostic/presentation/res/styles.css") + return inputStream!!.use { + it.readAllBytes().toString(StandardCharsets.UTF_8) } } -""".trimIndent() -private val JETBRAINS_GRAYSCALE_LOGO_SVG = """ - - logo-grey - - - - - - - - - - - - - - - - - - - -""".trimIndent() +private val LINKABLE_TABLE_ROW_SCRIPT : String + get() { + val inputStream = IndexDiagnosticDumper::class.java.getResourceAsStream( + "/com/intellij/util/indexing/diagnostic/presentation/res/table-row.js") + return inputStream!!.use { + it.readAllBytes().toString(StandardCharsets.UTF_8) + } + } + +private val JS_SCRIPT: String + get() { + val inputStream = IndexDiagnosticDumper::class.java.getResourceAsStream( + "/com/intellij/util/indexing/diagnostic/presentation/res/hide-elements.js") + return inputStream!!.use { + it.readAllBytes().toString(StandardCharsets.UTF_8) + } + } + +private val JETBRAINS_GRAYSCALE_LOGO_SVG: String + get() { + val inputStream = IndexDiagnosticDumper::class.java.getResourceAsStream( + "/com/intellij/util/indexing/diagnostic/presentation/res/logo.svg") + return inputStream!!.use { + it.readAllBytes().toString(StandardCharsets.UTF_8) + } + } private inline fun FlowContent.div(id: String, crossinline block : DIV.() -> Unit = {}) { div { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/hide-elements.js b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/hide-elements.js new file mode 100644 index 000000000000..091dfedca3e1 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/hide-elements.js @@ -0,0 +1,7 @@ +function hideElementsHavingClass(className, hideOrShow) { + const elements = document.getElementsByClassName(className) + const displayType = hideOrShow ? 'none' : 'initial' + for (const element of elements) { + element.classList.toggle('invisible', hideOrShow) + } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/logo.svg b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/logo.svg new file mode 100644 index 000000000000..0b7e45b25cea --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/logo.svg @@ -0,0 +1,21 @@ + + logo-grey + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/styles.css b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/styles.css new file mode 100644 index 000000000000..6e8ae71e8c45 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/styles.css @@ -0,0 +1,131 @@ +body { + font-family: Arial, sans-serif; + margin: 0; +} + +table, th, td { + border: 1px solid black; + border-collapse: collapse; +} + +table { + width: 80%; +} + +table.activity-table { + width: 100%; +} + +table.narrow-activity-table { + width: 80%; +} + +table.two-columns td { + width: 50%; +} + +th, td { + padding: 3px; +} + +th { + background: lightgrey; +} + +td { + white-space: pre-wrap; + word-break: break-word; +} + +.stats-content { + margin-left: 20%; +} + +.stats-activity-content { + margin-left: 20%; + margin-right: 5%; +} + +.aggregate-report-content { + margin-left: 10%; +} + +.aggregate-activity-report-content { + margin-left: 15%; + margin-right: 15%; +} + +.aggregate-header { + padding-top: 1em; + padding-bottom: 1em; + margin-bottom: 0; +} + +.table-with-margin{ + margin-top: 1em; + margin-bottom: 2em; +} + +.navigation-bar { + width: 15%; + background-color: lightgrey; + position: fixed; + height: 100%; +} + +div.navigation-bar ul { + list-style-type: none; + overflow: auto; + margin: 0; + padding: 0; + font-size: 24px; +} + +div.navigation-bar ul li a, label { + display: block; + color: #000; + padding: 8px 20px; + text-decoration: none; +} + +label input { + margin-left: 10px; + width: 20px; + height: 20px; +} + +div.navigation-bar ul li a:hover { + background-color: #555; + color: white; +} + +.minor-data {} + +.invisible { + display: none; +} + +.jetbrains-logo { + width: 50%; + bottom: 5%; + position: absolute; + left: 20%; +} + +.centered-text { + text-align: center; +} + +.linkable-table-row:hover { + background: #f2f3ff; + outline: none; + cursor: pointer; +} + +.scanning-table-row { + background-color: aliceblue; +} + +.not-applicable-data{ + color: darkgrey; +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/table-row.js b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/table-row.js new file mode 100644 index 000000000000..366fdd6a8e89 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/diagnostic/presentation/res/table-row.js @@ -0,0 +1,9 @@ +document.addEventListener("DOMContentLoaded", () => { + const rows = document.getElementsByClassName("linkable-table-row") + for (const row of rows) { + const href = row.getAttribute("href") + row.addEventListener("click", () => { + window.open(href, "_blank"); + }); + } +}); \ No newline at end of file