All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.sonar-tmc-panel.js Maven / Gradle / Ivy

/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

AJS.$.namespace("AJS.sonar.tmc.panel");

/**
 * Base object containing all the options for the panel
 */
AJS.sonar.tmc.panel.config = {
	chartColumn : '#chart-metrics-column',
	chartContainer : '#chart-container',
	metricsContainer : '#metrics-container',
	versionsColumn : '#versions-column',
	thobber: '#thobber',
	defaultMetrics : [ 'violations_density', 'complexity', 'coverage' ],
	context : 0,
	afterInit : function() {},
	associationId : 0
};

/**
 * Initiate the Sonar panel
 * 
 * @param panel the configuration object for the panel
 */
AJS.sonar.tmc.panel.initPanel = function(options) {
	jQuery.extend(AJS.sonar.tmc.panel.config, options);
	AJS.sonar.tmc.panel.resetPanel();
	AJS.sonar.tmc.panel.config.afterInit();
}

/**
 * Reset the Sonar Panel
 */
AJS.sonar.tmc.panel.resetPanel = function() {
	AJS.$(AJS.sonar.tmc.panel.config.chartContainer).empty();
	AJS.$(AJS.sonar.tmc.panel.config.metricsContainer).empty();
	AJS.$(AJS.sonar.tmc.panel.config.versionsColumn).empty();
}

/**
 * After initialization of the Panel, load the content of the gadgets for the given association id.
 * 
 * @param associationId the association ID to load
 */
AJS.sonar.tmc.panel.loadAssociation = function(associationId) {
	AJS.sonar.tmc.panel.config.associationId = associationId;
	AJS.$(AJS.sonar.tmc.panel.config.thobber).addClass('loading');
	AJS.sonar.tmc.panel.resetPanel();
	// Update versions (sync), metrics (async), chart (sync/default metrics)
	AJS.$.ajax({
		type : "GET",
		async: false,
		dataType: "xml",
		url : contextPath + "/rest/sonar/1.0/association/" + AJS.sonar.tmc.panel.config.associationId
			+ "/project/versions",
		success: function(data) {
			$xml = AJS.$(data);
			var versionsColumn = AJS.$(AJS.sonar.tmc.panel.config.versionsColumn).empty();
			AJS.$("
").addClass("mod-header").append( AJS.$("

").addClass("toggle-title").text("Versions") ).appendTo(versionsColumn); var versionsList = AJS.$("
    ").appendTo(versionsColumn); AJS.$($xml.find("version")).each(function(index, item) { var $version = AJS.$(item); var versionLi = AJS.$("
  1. "); var versionId = $version.find("sid").text(); AJS.$("").attr({ "type": "checkbox", "name": "tm-version", "value": $version.find("date").text(), "id" : "tm-version-" + versionId, "checked" : ((index < 5) ? "checked" : "") }).click(function() { AJS.sonar.tmc.panel.updateChart(); }).appendTo(versionLi); AJS.$("
    ").addClass("desc").text(new Date($version.find("date").text()).format("M jS, Y")) .appendTo(versionLi); versionLi.appendTo(versionsList); }); AJS.sonar.tmc.panel.updateChart(); }, error: function() { AJS.sonar.panel.createErrorMessage("Failed to load the versions related to the selected association.") .appendTo(versionsColumn); } }); AJS.$.ajax({ type: "GET", async: true, dataType: "xml", url : contextPath + "/rest/sonar/1.0/association/" + AJS.sonar.tmc.panel.config.associationId + "/server/metrics", success: function(data) { $xml = AJS.$(data); var metricsColumn = AJS.$(AJS.sonar.tmc.panel.config.metricsContainer).empty(); AJS.$("
    ").addClass("mod-header").append( AJS.$("

    ").addClass("toggle-title").text("Metrics") ).appendTo(metricsColumn); var metricsList = AJS.$("
      ").appendTo(metricsColumn); AJS.$($xml.find("metric")).each(function(index, item) { var $metric = AJS.$(item); var metricLi = AJS.$("
    • "); var metricKey = $metric.find("key").text(); AJS.$("").attr({ "type": "checkbox", "name": "tm-metric", "value": metricKey, "id" : "tm-metric-" + metricKey, "checked" : ((AJS.$.inArray(metricKey, AJS.sonar.tmc.panel.config.defaultMetrics) != -1) ? "checked" : "") }).click(function() { AJS.sonar.tmc.panel.updateChart(); }).appendTo(metricLi); AJS.$("





© 2015 - 2024 Weber Informatics LLC | Privacy Policy