gpt4 book ai didi

javascript - Jira 小工具 - 在配置屏幕上重新加载 AJAX

转载 作者:行者123 更新时间:2023-11-30 06:41:50 29 4
gpt4 key购买 nike

无法在任何地方找到解决方案,我真的希望这是可能的。

我正在编写一个 Jira 小工具,我有一个包含 2 个字段的配置屏幕。一个是快速查找项目选择器;您键入它会找到项目,然后单击您想要的项目。

第二个字段是组件。您可以选择要作为过滤依据的项目组件。但是,每个项目的组件都不同,因此组件字段填充了在“配置”部分的“args”部分的小工具中指定的 AJAX 调用。

唯一的问题是此 AJAX 仅在首次加载小工具时被调用;即:在选择项目之前,结果始终是“选择项目”。

我需要一种方法来在所选项目发生更改时重新运行此 AJAX 调用。

这可能吗?或者有替代解决方案吗?我试过定时器来检查变化,但也有一些问题;主要是我无法访问/更改组件下拉框字段。小工具只会拒绝加载。

更新:下面是小工具的 Javascript。如您所见,我添加了一个 refreshComponents() Javascript 方法,它可以在给定项目 ID 的情况下检索组件,但是我无法将其附加到适当的事件。此外,我似乎无法使用 jQuery 或普通 JS 之类的方式直接更改页面上的任何组件

<div id="chart_div" style="overflow: auto;"></div>

<script type="text/javascript">

var gadget = this;
google.load('visualization', '1.0', {'packages':['corechart']});

var oldProject = "initiated";
var globalGadget;
function timedComponentUpdate()
{
//alert(globalGadget.getPref("projectId"));
//setTimeout("timedComponentUpdate()",3000);
}

function refreshComponents(idString)
{
//refetch components
var url = "__ATLASSIAN_BASE_URL__/rest/severity-gadget/1.0/severity-issues/getComponents.json";
url += "?projectId=" + idString;
alert(url);

var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
//document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}

xmlhttp.open("GET",url,true);
xmlhttp.send();
}

function drawChart(args, bugtype, comp) {
//setup for whether were getting opened or closed
var axisTitle;
var compTitle;
var chart;

if(bugtype == "Bug")
axisTitle = "Bug";
else
axisTitle = "Issue";

if(comp == "All")
compTitle = "";
else
compTitle = " - Component: " + comp;

var wVar = gadgets.window.getViewportDimensions().width-20;
var hVar = wVar/3;
var hVar = hVar*2;

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Issues');
data.addColumn('number', 'Trivial');
data.addColumn('number', 'Minor');
data.addColumn('number', 'Major');
data.addColumn('number', 'Critical');
data.addColumn('number', 'Blocker');

AJS.$(args.weeks).each(function() {
data.addRow(["Week "+this.number,
parseInt(this.issues[0]),
parseInt(this.issues[1]),
parseInt(this.issues[2]),
parseInt(this.issues[3]),
parseInt(this.issues[4])
]);
});

var options = {'title':'Weekly '+axisTitle+' Backlog' + compTitle,
'width':wVar,
'height':hVar,
axisFontSize:4,
isStacked:true,
fontName: '"Arial"'
};

chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}

var gadget = AJS.Gadget(
{
baseUrl: "__ATLASSIAN_BASE_URL__",
useOauth: "/rest/gadget/1.0/currentUser",
config: {
descriptor: function(args)
{
document.getElementById("chart_div").innerHTML = "";

var gadget = this;
var projectPicker = AJS.gadget.fields.projectOrFilterPicker(gadget, "projectId", args.projectOptions);

//bh
oldProject = this.getPref("projectId");
//refreshComponents(this.getPref("projectId"));

return {
theme : function()
{
if (gadgets.window.getViewportDimensions().width < 450)
{
return "gdt top-label";
}
else
{
return "gdt";
}
}(),
fields: [
AJS.gadget.fields.nowConfigured(),
projectPicker,
AJS.gadget.fields.days(gadget, "weeksPrevious"),
{
userpref: "issueType",
label: "Issue Type:",
description:"Choose which issue type you would like",
type: "select",
selected: this.getPref("issueType"),
options:[
{
label:"Any",
value:"Any"
},
{
label:"Bug",
value:"Bug"
}
]
},
{
userpref: "component",
label: "Component:",
description:"Choose which issue type you would like",
type: "select",
selected: this.getPref("component"),
options:args.components
}
]
};
},
args: function()
{
return [
{
key: "components",
ajaxOptions: function() {
var ajaxProject = this.getPref("projectId");
if(ajaxProject == "")
ajaxProject = "null";

return {
url: "/rest/severity-gadget/1.0/severity-issues/getComponents.json",
data:
{
projectId : ajaxProject
}
}
}

}

];
}()
},
view: {
onResizeReload: true,
onResizeAdjustHeight: true,
template: function(args) {
var gadget = this;

gadget.getView().empty();

drawChart(args.issueData, this.getPref("issueType"), this.getPref("component"));

gadget.resize();
},
args: [{
key: "issueData",
ajaxOptions: function() {
return {
url: "/rest/severity-gadget/1.0/severity-issues.json",
data: {
projectId : gadgets.util.unescapeString(this.getPref("projectId")),
weeksPrevious: this.getPref("weeksPrevious"),
issueType: this.getPref("issueType"),
component: this.getPref("component"),
backlog: true
}
};
}
}]
}
}
);
</script>

最佳答案

我想你需要把你的组件字段变成一个 Callback Builder .

在回调函数中你需要做一些事情:

  1. 通过 AJAX 请求检索选项
  2. 呈现下拉列表
  3. 附加事件处理程序以在特定事件发生时刷新列表

您的新组件字段可能看起来像这样......为了简洁起见,我假设您已经使用了 jQuery。

{
userpref: "component",
label: "Component",
id: "component_field_id"
description: "Choose which issue type you would like",
type: "callbackBuilder",
callback: function(parentDiv){

function renderOptions(options){
// Remove elements from the parentDiv and replace them
// with new elements based on the options param
// You can use gadget.getPref('component') to ensure you
// mark the right option as selected
}

function getOptions(){
$.ajax({
url: "__ATLASSIAN_BASE_URL__/rest/severity-gadget/1.0/severity-issues/getComponents.json",
data: {
// You might be able to get hold of the selected value
// from the gadget object instead of like this
projectId: $("#filter_projectOrFilterId_id").val()
}
}).done(renderOptions);
}

// Retrieve and render options on gadget load
getOptions();

// Retrieve and render options on an event
$(parentDiv).on("update-options", getOptions);
}
}

此外,您需要在项目选择字段值更改时触发一个事件。在您的 JS 代码的其他地方(不在小工具定义内)您需要放置这样的代码,但您需要确认项目/过滤器选择器的 CSS 选择器:

$(document).on("change", "#filter_projectOrFilterId_id", function(){
$("#component_field_id").trigger("update-options");
});

我没有对此进行测试,但这就是我尝试实现您所要求的方式。

关于javascript - Jira 小工具 - 在配置屏幕上重新加载 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10634507/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com