[piketec-tpt] Extract inline script block and event handlers in TrendGraph/index.html

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Problems

      == Inline Script Block
      Line: 75
      ----
      <script>
      		//0 buildNummer
      		// 1 total
      		// 2 failed
      		// 3 inconclusive
      		// 4 error
      		// 5 passed Test
      		var dataD = document.getElementById('data').innerHTML
      		var builds = JSON.parse(dataD);
      		
      
              var BUILDS = [];
      		var wieVieleBuilds = 10; //User Input
      		
      		var PassedTest = []; //Get from Java
      		var InconclusiveTest = []; //Get from Java
      		var FailedTest = []; //Get from Java
      		var ErrorTest = []; //Get from Java
      		var TotalTest = [];
      		
      		//TotalTest.push(builds[0].total);
      		//temporaer , spaeter nur de Werte von Java
      		for(var i = builds.data.length-1; i >=  0; i--){
      		BUILDS.push(builds.data[i][0].buildNummer);
      		PassedTest.push(builds.data[i][5].passed);
      		InconclusiveTest.push(builds.data[i][3].inconclusive);
      		FailedTest.push(builds.data[i][2].failed);
      		ErrorTest.push(builds.data[i][4].error);
      		TotalTest.push(builds.data[i][1].total);
      		}
      		
      		var obereGrenze = Math.max(...TotalTest);
      		var skala = 0;
      		if(obereGrenze > 50){
      			obereGrenze = Math.ceil(obereGrenze/100)*100;
      		    skala = obereGrenze % 10;
      		}else if (obereGrenze > 20){
      			obereGrenze = 50;
      			skala = 5;
      		}else if(obereGrenze > 10){
      			obereGrenze = 20;
      			skala = 2;
      		}else{
      			obereGrenze = 10;
      			skala = 1;
      		}
      		
              var config = {
                  type: 'line',
                  data: {
                      labels: BUILDS,
                      datasets: [{
                          label: "Total Tests",
      					lineTension: 0,
                          backgroundColor: window.chartColors.blue,
                          borderColor: window.chartColors.blue,
                          data: TotalTest,
                          fill: false,
      					hidden: false,
                      }, {
                          label: "Passed Tests",
                          fill: false,
      					lineTension: 0,
                          backgroundColor: "#4CAF50",
                          borderColor: "#4CAF50",
                          data: PassedTest,
      					hidden: false,
                      },{
                          label: "Inconclusive Tests",
                          fill: false,
      					lineTension: 0,
                          backgroundColor: "#e1ed09",
                          borderColor: "#e1ed09",
                          data: InconclusiveTest,
      					hidden: false,
                      },
      				
      				{
                          label: "Error Tests",
                          fill: false,
      					lineTension: 0,
                          backgroundColor: "#a32525",
                          borderColor: "#a32525",
                          data: ErrorTest,
      					hidden: false,
                      },
      				
      				{
                          label: "Failed Tests",
      					lineTension: 0,
                          fill: false,
                          backgroundColor: "#f22424",
                          borderColor: "#f22424",
                          data: FailedTest,
      					hidden: false,
                      }
      				
      				
      				
      				]
                  },
                  options: {
      				
                      responsive: true,
      				legend:{
      					onClick: "",
      				},
                      title:{
                          display:true,
                          text:'Trend Graph from Builds'
                      },
                      tooltips: {
                          mode: 'index',
                          intersect: false,
                      },
                      hover: {
                          mode: 'nearest',
                          intersect: true
                      },
                      scales: {
                          xAxes: [{
                              display: true,
                              scaleLabel: {
                                  display: true,
                                  labelString: 'Build Number'
                              }
                          }],
                          yAxes: [{
                              display: true,
                              scaleLabel: {
                                  display: true,
                                  labelString: 'Test Results'
      							
                              },
      						 ticks: {
                      max: obereGrenze, //Set depending on max Value Total Tests
                      min: 0, // Set depending on Min Value TOtal TEst
                      stepSize: skala //Set depending two above
                  }
      
      						
      						
                          }]
                      },
      				 onClick: handleClick
                  }
              };
              window.onload = function() {
                  var ctx = document.getElementById("canvas").getContext("2d");
                  window.myLine = new Chart(ctx, config);
      			
              };
      		
      		
      		function update(index){
      	var indexInArray = index;
      			var chart = this.myLine;
      			config.data.datasets[indexInArray].hidden = !config.data.datasets[indexInArray].hidden;
      			chart.update();
      	
      	
      	}
      		
      		function handleClick(evt)
           {
          var activeElement = myLine.getElementsAtXAxis(evt);
      	var link = window.location.href;
      	var replacedLink = link.replace("TPTtrendResults/index.html","");
      	window.open(
         replacedLink+BUILDS[activeElement[0]._index]+ '/TPT_Report/',
        '_blank' 
      );
      	};
      		
              
             
          </script>
      ----
      
      == Inline Event Handler
      Line: 59
      ----
      <button class="button" onClick="update(0)" style="background-color:#36a2eb">
      ----
      
      == Inline Event Handler
      Line: 60
      ----
      <button class="button" onClick="update(1)" style="background-color:#4CAF50">
      ----
      
      == Inline Event Handler
      Line: 61
      ----
      <button class="button" onClick="update(2)" style="background-color:#e1ed09;">
      ----
      
      == Inline Event Handler
      Line: 62
      ----
      <button class="button" onClick="update(3)" style="background-color:#a32525">
      ----
      
      == Inline Event Handler
      Line: 63
      ----
      <button class="button" onClick="update(4)" style="background-color:#f22424">
      ----
      

      Solutions

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks
      https://www.jenkins.io/doc/developer/security/csp/#inline-event-handlers

            Assignee:
            Unassigned
            Reporter:
            Basil Crow
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: