Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

AUI RESTful table resources

Quan Jiang March 30, 2014

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();
    }
}

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

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

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

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

Quan Jiang March 30, 2014

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?

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

Can you provide your atlassian-plugin.xml, so I try to find any problem related to missing dependencies ?

Quan Jiang March 30, 2014

Oh thanks so much Boris. Problem solved! Just delet the target ane rerun. The restful table runs well now.

Like emir likes this
Quan Jiang March 31, 2014

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?

Holger Schimanski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2015

The URL changed a little. https://docs.atlassian.com/aui/latest/docs/restful-table.html. Maybe you can update the link above.

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2014

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

http://searchcode.com/codesearch/view/32878355

TAGS
AUG Leaders

Atlassian Community Events