Project

General

Profile

How to create a plugin to add a custom button and behavior to create/edit issue page?

Added by wuarmin dev over 3 years ago

I have a use-case, where I want to reformat the Redmine issue description content at a custom server, if the user clicks a button. So I need to do following:

1. add a button at Redmine new/edit issue page
2. read the current issue description content
3. make an async request to a custom server
4. paste back the response from custom serverinto description content

I'm on Easy Redmine. Is my intention technically feasible? Are there similar examples?

Thank You


Replies (9)

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by Liane Hampe over 3 years ago

Hello,

Does being on Easy Redmine mean that you have no administration rights or what is the main difference w.r.t. your problem?

Best Regards,
Liane

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by wuarmin dev over 3 years ago

Hello Liane,

thank you for your response. No, Easy Redmine (https://www.easyredmine.com) is a Redmine upgrade and I have administration rights. Furthermore I found out, that Redmine plugins should work at Easy Redmine as in vanilla Redmine.

My issue is, that I'm new to Redmine plugin development and so I need some hints. How is my intention technically feasible? Which Redmine Hook would be the right one?
Do you have some hints, or maybe, do you know a plugin, which add a feature to issue create/edit form, where code is open source?

Thank you
Best Regards,
Armin

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by Liane Hampe over 3 years ago

Hello Armin,

Having administration rights is a good starting point.

There are so many simple ways to reformat an issue description. Step 3 and 4 of your sketch above sounds a little bit complicated.

Are there special information on the custom server you cannot integrate directly in a plugin or why do you think it would work only this way?

Sorry, for asking all these questions, but I am trying to understand your problem better.

Best Regards,
Liane

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by wuarmin dev over 3 years ago

Good Morning Liane,

Step 3 and 4 of your sketch above sounds a little bit complicated.
Are there special information on the custom server you cannot integrate directly in a plugin or why do you think it would work only this way?
Sorry, for asking all these questions, but I am trying to understand your problem better.

Ok, let me become a bit more clear:

We have a use-case, where a user wants to copy some scheduled flight offers from a third party application. The raw offers are not appropriate for an end user. So the offers have to be reformatted. Here's a pseudo-example

raw:
AR2240 E 14JUN 2 AEPGRU HK1 0700 0945 1A/E
result:
AR2240 E 14. Juni 2017 Buenos Aires (AEP) - Sao Paulo (GRU) 07:00 - 09:45

The formatting is already implemented and runs on server-side. We have an outlook-addin, which does the same thing. Now we want to move the offer-handling to Redmine, therefore I need the same behavior in Redmine issue form as in Outlook new-email form: A button, a user clicks after a paste from the third party-app and a async request to our formatting-server.

Thank you,
Best Regards,
Armin

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by Liane Hampe over 3 years ago

Hello Armin,

What you like to implement should work in some way. Here are my roughly sketched ideas:

Using Redmines JSON or REST API even without Button

If I have got your problem right, then a button is not mandatory when using Redmines JSON or REST API.

You could notify your custom server as soon as a new ticket, which needs re-formating, was created by sending the ticket id.

Your custom server can fetch the id and request the respective description via Redmines API and send the re-formatted description back. This way your user should not be interrupted.

If you feel more comfortable with a button then it could work very similar. The difference is that you don't need to hook into the issues lifecycle to notify automatically.

Using only Call Hooks - no API

And if you don't want to use the API, then it should also work similar, because you would send the description directly via the same hook of Redmine instead of sending only the issue id.

If the response time of your custom server is not fast enough you could outsource the responsibilty of managing the re-formatting to another model what injects the re-formated description to the issue in the background if available.

Get started in either way

You should make a working copy of your Easy Redmine and search for for the everything starting with 'call_hook' in your issue_controller.rb. If the IssueController is the same as Redmines than there should be multiple hooks over the issues lifecycle. Redmine hooks are self explanatory. You should read also this: https://www.redmine.org/projects/redmine/wiki/Hooks

The call_hook for a button can be found similar by scanning through the issues views.

When you don't know how to register a Redmine plugin you should read https://www.redmine.org/projects/redmine/wiki/Developer_Guide

All other stuff is more or less related to plain ruby or Rails.

I hope, I explained it in a useful way...

Best Regards,
Liane

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by wuarmin dev over 3 years ago

Hello Liane,

thank you for your helpful suggestions and the Get Started stuff ;).

The automatic-approach (using only api) is not suitable, because users want to see the formatted result immediatly, before they save an issue. Furthermore, it is possible, that the formatting fails, because of i.e. missing airport data at the formatting-server. So I have to solve it with a button, like in the outlook add-in.

Summary
So I have to search a Redmine Hook, where I can execute some plugin-code, which adds a button to the issue-form. If user clicks the button I can do the async HTTP-call with Javascript and paste back the result to the issue-description
Am I right?

Best Regards,
Armin

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by Liane Hampe over 3 years ago

Hello Armin,

So I have to search a Redmine Hook, where I can execute some plugin-code, which adds a button to the issue-form. If user clicks the button I can do the async HTTP-call with Javascript and paste back the result to the issue-description

Yes, this is a way to do it. Moreover, you could validate the data before sending the request to inform your user early.

If you cannot find a suitable hook in the issue views look also in the layout views or use gem deface which can inject code somewhere in the respective view before rendering.

Just give it a try. There is no guarantee anyway since Easy Redmine is out of our scope here.

Happy coding!

Best Regards,
Liane

RE: How to create a plugin to add a custom button and behavior to create/edit issue page? - Added by wuarmin dev over 3 years ago

Hello Liane,

thank you for your help. I will give feedback, after I implemented the requirements.

Best Regards
Armin

    (1-9/9)