JIRA自定義字段型別

2021-09-26 23:13:59 字數 3963 閱讀 4148

jira中提供了許多自定義字段型別,如文字框,選擇等。但有時不能完全滿足我們的要求,我們需要自定義一些字段型別,下面以自定乙個問題選擇下拉框為例。

先看下官網的說明,示例中需要在atlassian-plugin.xml 檔案中新增 customfield-type 標籤。建立issueselect欄位,新增配置如下:

choose a issue from the project.

從以上配置中可以看到,待實現的有兩部分:

是自定義欄位的實現類 issueselectcftype

欄位在頁面中的顯示模板,也就是vm檔案

建立類 issueselectcftype,必需實現customfieldtype,此處繼承 abstractsinglefieldtype

public class issueselectcftype extends abstractsinglefieldtype
建立構造器

public issueselectcftype(customfieldvaluepersister customfieldvaluepersister, genericconfigmanager genericconfigmanager)

先把待實現的方法都實現

/**

* 儲存的資料庫型別

* @return

*/@nonnull

@override

protected persistencefieldtype getdatabasetype()

/** * 物件轉換為儲存型別

* 以 issue key 來儲存

* @param issue

* @return

*/@nullable

@override

protected object getdbvaluefromobject(issue issue)

/** * 儲存型別轉換為物件

* @param o

* @return

* @throws fieldvalidationexception

*/@nullable

@override

protected issue getobjectfromdbvalue(@nonnull object o) throws fieldvalidationexception

return null;

}/**

* 物件轉化為string

* 以issue key 作為標識

* @param issue

* @return

*/@override

public string getstringfromsingularobject(issue issue)

/** * string 轉換為 物件

* @param s

* @return

* @throws fieldvalidationexception

*/@override

public issue getsingularobjectfromstring(string s) throws fieldvalidationexception

由於是問題選擇,需要設定選項,還需要重寫另乙個方法getconfigurationitemtypes,該方法在abstractcustomfieldtype中預設實現如下:

@nonnull

public listgetconfigurationitemtypes() );

}

可見我們要定義自己的fieldconfigitemtype,

public class issuefieldconfigitemtype implements fieldconfigitemtype 

@override

public string getdisplayname()

@override

public string getdisplaynamekey()

@override

public string getviewhtml(fieldconfig fieldconfig, fieldlayoutitem fieldlayoutitem)

@override

public string getobjectkey()

@override

public object getconfigurationobject(issue issue, fieldconfig fieldconfig) catch (genericentityexception e)

}return new genericimmutableoptions(issues, fieldconfig);

}@override

public string getbaseediturl()

}

然後在issueselectcftype中重寫getconfigurationitemtypes

/**

* 設定 元件 選項

* @return

*/@nonnull

@override

public listgetconfigurationitemtypes()

以上自定義字段實現類就完成了。

#customcontrolheader ($action $customfield.id $customfield.name $fieldlayoutitem.required $displayparameters $auiparams)

#foreach ($option in $configs.options)

$textutils.htmlencode($option.summary)

#end

#customcontrolfooter ($action $customfield.id $fieldlayoutitem.fielddescription $displayparameters $auiparams)

#customcontrolheader ($action $customfield.id $customfield.name $fieldlayoutitem.required $displayparameters $auiparams)

#foreach ($option in $configs.options)

$textutils.htmlencode($option.summary)

#end

#customcontrolfooter ($action $customfield.id $fieldlayoutitem.fielddescription $displayparameters $auiparams)

#disable_html_escaping()

#if ($ctx.featuremanager.isenabled("com.atlassian.jira.plugin.export.xml.unified.enabled"))

#xmlescape($!value.summary)

#else

$!value.id

#end

選擇字段

使用效果

github 原始碼

[1]atlassian developer custom-field

[2]aui

Django模型中自定義字段型別

在使用django模型建立表時,有時候不存在或者不滿足條件我們想要的表字段型別。這時我們可以繼承django模型中的field來實現自定義字段型別。如下所示 建立了乙個tinyint型別的字段 建立自定義字段型別 tinyint class tinyintfield models.field def...

使用自定義字段

轉儲所有自定義字段作為列表顯示乙個特定自定義欄位的值id,mood true mood 將是自定義欄位的id值 顯示相同自定義欄位id的多個值id,songs false 僅在存在時顯示自定義字段 邏輯 url get post meta post id,snippet reference url ...

自定義型別

typedef型別 typedef 已有型別 新建型別 示例 typedef double area,volume typedef int number number i1 area a enum enum 列舉型別名 enum week 預設sun 0,可以比較 如果修改必須形如enum week...