4
votes

Would it be possible to use a project-specific stylesheet for JIRA projects?

For example, if I would like to include project X in an iframe, I'd like to hide the logo and possibly the JIRA toolbar - for specific user groups for example (it's only for viewing purpose, it is not a security feature)

Granted that I'd have to implement this myself (through the webservice api for example) - are there templates for the standard issue page?

Thanks in advance!

4
If you are just trying to make a project read-only, hacking the css wouldn't be a good way to do this.Mike Miller
no the permission scheme is solid, people just don't need the toolbar. also it is embedded in another portal, so it would be nice to apply the same stylesheet for this particular project.Stefan Ernst
You could try using javascript to change the output or select a css.Mike Miller
yes I thought about manipulating the iframe but it seems kinda "hackish". the cleanest way to me seems like a stylesheet based on user groups.Stefan Ernst
Have you searched plugins.atlassian.com for existing plugins which modify the look and feel?tokes

4 Answers

9
votes

There is a (currently undocumented) plugin point in JIRA for inserting top navigation components, <top-navigation>.

You can use this plugin point to add your own navigation bar, and perhaps hide the normal bar using an inline CSS stylesheet. The following example triggers this behavior by using a ?hideit=true query parameter, which is the simplest way to approach the "embed in iframe" problem. You could make that "sticky" by storing it in a session or cookie.

Once you have created a plugin that plugins into the <top-navigation>, hiding the top bar is simple. Here is a velocity script that does it:

#if ($hideHeaderHack)
    <style>
        \#header {display:none;}
    </style>
    HIDDEN (remove this message eventually)
#else
    NORMAL (remove this message eventually)
#end

To create such a plugin, use the Atlassian Plugin SDK (use atlas-create-jira-plugin). Your atlassian-plugin.xml should look like:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
    </plugin-info>

    <top-navigation key="standard-navigation-top"
                    name="Tigerblood"
                    class="com.madbean.topnavhack.TopNav" state='enabled'>
        <resource type="velocity" name="view" location="topnav.vm"/>
        <order>5</order>
    </top-navigation>

</atlassian-plugin>

Your top-navigation implementation class (called com.madbean.topnavhack.TopNav above) should look like:

public class TopNav implements PluggableTopNavigation {
    private TopNavigationModuleDescriptor descriptor;

    public void init(TopNavigationModuleDescriptor descriptor)
    {
        this.descriptor = descriptor;
    }

    public String getHtml(HttpServletRequest request) {
        Map<String,Object> params = new HashMap<String, Object>();

        params.put("hideHeaderHack", "true".equals(request.getParameter("hideit")));

        return descriptor.getTopNavigationHtml(request, params);
    }
}

Your plugin will be laid out something like:

./pom.xml
./src/main/java/com/madbean/topnavhack/TopNav.java
./src/main/resources/atlassian-plugin.xml
./src/main/resources/topnav.vm

Disclaimer I work for Atlassian as a developer in the JIRA team.

2
votes

I don't believe this functionality is exposed directly, and you don't state what JIRA version you are using, but in 4.x in \atlassian-jira\includes\decorators there is a file called bodytop.jsp the has the following fragment that renders the top level navigation and toolbar elements:

// Render all the top nav plugins for (Iterator iterator = topNavPlugins.iterator(); iterator.hasNext();) { TopNavigationModuleDescriptor topNavModuleDescriptor = (TopNavigationModuleDescriptor) iterator.next(); PluggableTopNavigation pluggableTopNavigation = (PluggableTopNavigation) topNavModuleDescriptor.getModule();

%> <%= pluggableTopNavigation.getHtml(request) %> <% } %>

If you wanted to you could create a version of the dashboard rendering jsp that calls a modified bodytop.jsp that renders none of the usual nav elements.

1
votes

I would be tempted to write a basic plugin to do this.

Take a look at http://confluence.atlassian.com/display/JIRA/Web+Resource+Plugin+Module

If you have yet to write a jira plugin, now might be the time to try it out http://confluence.atlassian.com/display/DEVNET/Developing+your+Plugin+using+the+Atlassian+Plugin+SDK .

0
votes

I'm currently running Jira 4.2.2 and wrote a plugin that implements PluggableTopNavigation for a custom navigation bar. Unfortunately, this functionality, as detailed in the awarded question, is now depreciated.

My plugin added a div to the top of the Jira header that created a nice menu for use with our development pages. The source of the menu was hard-coded into the plugin and located as a static menu.html file on our server for sharing across different pages.

Since I'd have to completely redesign the plugin for Jira 5.2, I started searching for different ways to re-implement the menu. Here's what I settled on. It's not pretty, but it makes it so you don't have to write a plugin.

Change your announcement banner (quickly get there by typing 'gg', then search for announcement banner) to the following:

<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery.get("http://path.to.server/menu.html", function(data){
        jQuery("#header").prepend('<nav class="global" role="navigation">'+data+'</nav>');
        jQuery("#top-level-id-of-navbar a").css("color", "white")
    });
  });
</script>

Replace the menu.html link with your own link. The color of the header was inherited by the links in my menu, so I had to change them back to white after inserting the html page.

The result looks identical to Jira 4.2.2, so I'm happy.