I am trying to use a RESTful table in gadget and I came across some problem configuring the resource url for restful table.
What should I put in resource – all/self parameter? I always ran into “undefined not a function” error the red lines.
I am kinda new to AUI. Thanks !!
=================content part of gadget======================
<Content type="html" view="profile"> <![CDATA[ #requireResource("com.honeywell.acs.gadgets.kasaquan-gadgets:common-lite") #includeResources() <script type="text/javascript"> (function(){ var gadget = AJS.Gadget({ baseUrl: "__ATLASSIAN_BASE_URL__", useOauth: "/rest/gadget/1.0/currentUser", view:{ template: function(args){ var gadget = this; var $container = jQuery('<table id="customlinksTable"/>').appendTo(gadget.getView()); //var html = JIRA.ProjectConfig.getKey(); //$container.html("html"); var $componentsTable = jQuery("#project-config-components-table"); new AJS.RestfulTable({ autoFocus: true, el: $componentsTable, resources:{ all: "__ATLASSIAN_BASE_URL__"+"/rest/customlinksresource/1.0/customlinks", self: "__ATLASSIAN_BASE_URL__"+"/rest/customlinksresource/1.0/customlinks", }, columns:[… ], }); }, args:[{ key: "links", ajaxOptions: function(){return {url:"/rest/customlinksresource/1.0/customlinks"};} }] }, }); })(); </script> ]]> </Content>
=======================resource class=========================
@Path("customlinks") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public class CustomlinksResource { … @GET @Path("{id}") @AnonymousAllowed //@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getLinks(@PathParam ("id") final String id) { … return Response.ok(customlinks).cacheControl(cc).build(); } @PUT @Path ("{id}") public Response updateVersion(@PathParam ("id") final String id){ return Response.ok().build(); } @POST public Response createVersion(){ return Response.ok().build(); } @DELETE @Path ("{id}") public Response delete(@PathParam ("id") final String id){ return Response.ok().build(); } }
Community moderators have prevented the ability to post new answers.
The URL for self is okay, but you have to fix the resouce class - You have to add getVersion method like that :
@GET @Path("{id}") @AnonymousAllowed //@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getVersion(@PathParam ("id") final String id) { //get the object by id Version v = getById(id); .... … return Response.ok(v).build(); }
and then have a separate method for getting all the links with different path for example:
@GET @Path("all") @AnonymousAllowed //@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response getLinks() { … return Response.ok(customlinks).cacheControl(cc).build(); }
and then for "all" attribtue put "__ATLASSIAN_BASE_URL__"
+
"/rest/customlinksresource/1.0/customlinks/all"
This is pretty well described in the docs:
https://docs.atlassian.com/aui/latest/docs/restfulTable.html
Also the createVersion method should take parameter containing the data required to create a new object. But if you do not need create you might skip it.
The same also applies for updateVersion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your input Boris.. After I made some changes according to your suggestion, I now get the "TypeError: AJS.RestfulTable is not a constructor" function errir.
But I have added ajs and aui-exp-restfultable into xml and include the web-resource in my gadget. What is the problem? Should I remove target and rerun?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you provide your atlassian-plugin.xml, so I try to find any problem related to missing dependencies ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh thanks so much Boris. Problem solved! Just delet the target ane rerun. The restful table runs well now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Boris, I have now a problem that the entry content does not translate properly in my RESTful table, but only the keys show up. Do you have any idea how to fix this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The URL changed a little. https://docs.atlassian.com/aui/latest/docs/restful-table.html. Maybe you can update the link above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So you need to call a code to translate the keys to text from your message resource files. You can do that in the java code or in the JS code by calling either using com.atlassian.jira.util.I18nHelper.getText(String, Object) for java or AJS.getText(textKey) in JavaScript in a CustomReadView for the column you want to get translated. You can see how to specify custom read view here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.