Compare pages. Simple plugin for Atlassian Confluence

 3r3-3589. 3r3-31. Atlassian Confluence has a wonderful page version comparison functionality. It is convenient to use them, but it will not be possible to go beyond the change history. How to be? Search for a ready-made plug in Marketplace 3r3777. He gave no results and it was decided to write his own. 3r? 3574.  3r3-3589.
3r33577. 3r? 3574.  3r3-3589.

Tools

3r? 3574.  3r3-3589. We will need: 3r37474.  3r3-3589. 3r? 3574.  3r3-3589. 3r33469.  3r3-3589.
Oracle JDK or AdoptOpenJDK 1.? working with OpenJDK is not officially supported; 3r33490.  3r3-3589.
Atlassian SDK - can be downloaded from the official site for
Windows 3r3777. and
Linux /Mac 3r37777. without SMS and registration; 3r33490.  3r3-3589.
Apache Maven; 3r33490.  3r3-3589.
My favorite development environment, I have IntelliJ IDEA. 3r33490.  3r3-3589.
3r? 3574.  3r3-3589.

Create a project 3r3442. 3r? 3574.  3r3-3589. Install the SDK and run the script. atlas-create-confluence-plugin . 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. We enter: 3r37474.  3r3-3589. 3r? 3574.  3r3-3589. 3r33469.  3r3-3589. 3r371. group-id: [/b] com.kshch.confluence.plugins  3r3-3589. 3r371. artifact-id: [/b] diff-page  3r3-3589. 3r371. version: [/b] ???-SNAPSHOT  3r3-3589. 3r371. package: [/b] com.kshch.confluence.plugins.diff.page  3r3-3589. 3r? 3574.  3r3-3589. To build, you can use maven and dependencies from the SDK, but it's easier to connect additional repositories in your settings.xml. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542. 3r3-3589. atlassian-public 3r3-3589. https://packages.atlassian.com/maven/repository/public 3r3-3589. 3r3-3589. 3r3128. true 3r3-3589. 3r3138. never 3r3-3589. 3r3141. warn 3r3-3589. 3r3144. 3r3-3589. 3r3-3589. 3r3128. true 3r3-3589. 3r3141. warn 3r3-3589. 3r3133. 3r3-3589. 3r3115. 3r3-3589. 3r3-3589. 3r3118. 3r3-3589. atlassian-public 3r3-3589. https://maven.atlassian.com/repository/public 3r3-3589. 3r3-3589. 3r3128. true 3r3-3589. 3r3141. warn 3r3-3589. 3r3133. 3r3-3589. 3r3-3589. 3r3138. never 3r3-3589. 3r3141. warn 3r3-3589. 3r3144. 3r3-3589. 3r3146. 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Open the resulting project in the IDE, run Confluence in debug mode, 3r-3565. confluence: debug 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r3158. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. and check the local installation at 3r3163. http: //localhost: 1990 /confluence / . Login admin, password admin. The database has already created a demonstration space and several articles. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589.

A little functional 3r3442. 3r? 3574.  3r3-3589. Let's start with the menu. Add the web-item module to the atlassian-plugin.xml plugin descriptor. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542. 3r3179. 3r3-3589. 3r3303. Add diff item to drop-down menu 3r3-3589. 3r3184. 3r3-3589. 3r3186. /plugins/diffPage/diffPagePopup.action?spaceKey=${space.key}&sourcePageId=${page.id} 3r3-3589. 3r3189. 3r3-3589. 3r3191. 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Where: 3r37474.  3r3-3589. 3r? 3574.  3r3-3589. 3r33469.  3r3-3589.

section attribute - defines the place of appearance of the menu item; 3r33490.  3r3-3589. weight attribute - responsible for sorting order; 3r33490.  3r3-3589. The key attribute of the label tag is the key by which the name of the displayed menu item is in the resource files; 3r33490.  3r3-3589. tag link - contains the link, and the linkId attribute is its id; 3r33490.  3r3-3589. condition - defines the condition of appearance, in our case only on pages. 3r33490.  3r3-3589. 3r? 3574.  3r3-3589. Add to diff-page.properties line:
 3r3-3589. 3r33565. diff.page.menu.name = Diff page 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. If you need translation support, we will create additional properties, for example, for Russian localization the file will be called diff-page_ru_RU.properties. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. Perform 3r36565. maven package . The plugin will automatically restart and our menu item will appear. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. Compare pages. Simple plugin for Atlassian Confluence 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589.

Modal window

3r? 3574.  3r3-3589. To select a page, it is convenient to use a modal window. Continue to edit atlassian-plugin.xml
 3r3-3589. 3r? 3574.  3r3-3589. Add a few resources:
 3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542. 3r3-3589. com.atlassian.auiplugin: ajs 3r3-3589. com.atlassian.auiplugin: dialog2 3r3-3589. 3r3-3589. page 3r3-3589. 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Where: 3r37474.  3r3-3589. 3r? 3574.  3r3-3589. 3r33469.  3r3-3589. tag dependency - dependency; 3r33490.  3r3-3589. the resource attributes indicate the type of resource, the name and location on the file system; 3r33490.  3r3-3589. context tag - defines the visibility depending on the context. 3r33490.  3r3-3589. 3r? 3574.  3r3-3589. We define the handlers of our urls:
 3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542. 3r33333. 3r3-3589. 3r3303. Diff page action 3r3-3589. 3r3306. 3r3-3589. 3r3308. 3r3-3589. dialog2 3r3777. from the framework AUI 3r3777. . 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. Add to the dialog form, submit button and input with css classes autocomplete-space and autocomplete-page, which will allow without additional efforts to organize the choice of space and page. Save the result in /templates/diff-page-popup.vm. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542.
3r3-3589. 3r???. 3r3-3589.
3r33333. $ action.getText ("diff.rp.upop.diff") 3r3-3589. 3r???. 3r33393. 3r3-3589. 3r33395. 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. To display the window, create in the resources /js/diff-page-popup.js with the following contents:
 3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r3406. (function ($) {3r3-3589. $ (function () {3r-3589. AJS. $ ('# diff-page'). unbind ('click'); 3r3-3589. AJS. $ ('# diff-page'). bind ("click", function (e) {3r3-3589. e.preventDefault (); 3r-3589. Var link = AJS. $ (this); 3r-3-3589. AJS. $. get (link.attr ('href'), function (response ) {3r3-3589. AJS. $ ('. Aui-page-panel'). After (response); 3r-5389. AJS.dialog2 ("# diff-page-popup"). Show ();
Confluence.Binder.autocompletetePage (AJS. $ ("# Diff-page-popup-binder")); 3r3-3589.}); 3r3-3589. Return false; 3r-5?589.}); 3r-3589.}; 3r38989.}) (AJS. $); 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. His task is to override the standard click event and show us a pop-up window, and not to follow the link. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. Perform 3r36565. maven package and try to choose a page and space. The prompt is activated after typing 2 characters. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589.

The main functionality 3r3442. 3r? 3574.  3r3-3589. Let's start implementation of the main functionality. Add to the com.kshch.confluence.plugins.diff.page.action package another DiffPageAction class that extends ConfluenceActionSupport and implements the PageAware interface with the following fields. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r???. private Long sourcePageId; 3r3-3589. private Long destinationPageId; 3r3-3589. private String spaceKey; 3r3-3589. private String destinationPageName; 3r3-3589. private String sourcePageTitle; 3r3-3589. private String destinationPageTitle; 3r3-3589. private string diff; 3r3-3589. private Page sourcePage; 3r3-3589. private Differ differ; 3r3-3589. private final PageManager pageManager; 3r3-3589. 3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Where: 3r37474.  3r3-3589. 3r? 3574.  3r3-3589. 3r33469.  3r3-3589.

sourcePageId - source page id; 3r33490.  3r3-3589.
destinationPageId - id of the compared page; 3r33490.  3r3-3589. spaceKey - space key; 3r33490.  3r3-3589. destinationPageName is the name of the compared page; 3r33490.  3r3-3589. sourcePageTitle - source page title; 3r33490.  3r3-3589. destinationPageTitle - the title of the compared page; 3r33490.  3r3-3589. diff is the result of the comparison. 3r33490.  3r3-3589. 3r? 3574.  3r3-3589. We will generate getters and setters, implement all methods except getPage, as suggested by the IDE by default. The fields sourcePageId, spaceKey and destinationPageName will contain the data that came from the form inside dialog2. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r???. @Override
public AbstractPage getPage () {3r3353589. returnthis.sourcePage; 3r3-3589.}
3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Override the execute method with our own. It is in it that the main logic of the plug-in work is concluded. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r???. @Override
public String execute () throws Exception {3r3353589. if (this.sourcePageId! = null && this.spaceKey! = null && this.destinationPageName! = null) {
this.sourcePage = this.pageManager.getPage (this.sourcePageId); 3r3-3589. Page destinationPage = this.pageManager.getPage (this.spaceKey, this.destinationPageName); 3r3-3589. if (this.sourcePage! = null && destinationPage! = null) {
this.destinationPageId = destinationPage.getId (); 3r3-3589. this.sourcePageTitle = this.sourcePage.getTitle (); 3r3-3589. this.destinationPageTitle = destinationPage.getTitle (); 3r3-3589. this.diff = this.differ.diff (this.sourcePage, destinationPage); 3r3-3589.}
}
return super.execute (); 3r3-3589.}
3r3566. 3r? 3562. 3r? 3574.  3r3-3589. It remains to implement a frontend comparison of 2 pages. It is much easier to popup. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. Create in /templates/diff-page.vm resources. In it, besides the layout, we implement the simplest error checking. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33535. 3r33542. #if ($ action.getDiff ())
#diffBody ()
#else
3r33546. 3r3-3589. 3r33548. 3r3-3589. 3r33550. $ action.getText ("diff.rror") 3r3-3589. 3r33556. 3r3-3589. 3r33555. $ action.getText ("diff.rror.message") 3r3-3589. 3r33585. 3r3-3589. #end
3r3566. 3r? 3562. 3r? 3574.  3r3-3589. Writing the plugin is finished. Perform again. maven package , choose a page and enjoy the result. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. 3r33571. 3r? 3574.  3r3-3589. 3r? 3574.  3r3-3589. The full project code is available at
GitHub
. 3r33585. 3r3-3589. 3r3-3589. 3r3-3589. 3r33582. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e. ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r?383. 3r3-3589. 3r33585. 3r3-3589. 3r3-3589. 3r3-3589. 3r3-3589.
+ 0 -

Add comment