Commits

Matt Ryall committed 84b3723

Macro which renders in Confluence and retrieves data. No updates yet.

  • Participants
  • Parent commits 4f29522

Comments (0)

Files changed (8)

File src/main/java/com/atlassian/confluence/plugin/planning/ProjectAction.java

 import com.atlassian.bandana.BandanaManager;
 import com.atlassian.confluence.core.ConfluenceActionSupport;
 import com.atlassian.confluence.json.JSONAction;
-import com.atlassian.confluence.json.parser.JSONException;
 import com.atlassian.confluence.setup.bandana.ConfluenceBandanaContext;
 import org.apache.commons.lang.StringUtils;
 

File src/main/java/com/atlassian/confluence/plugin/planning/ProjectPlanMacro.java

+package com.atlassian.confluence.plugin.planning;
+
+import com.atlassian.confluence.plugin.services.VelocityHelperService;
+import com.atlassian.renderer.RenderContext;
+import com.atlassian.renderer.v2.RenderMode;
+import com.atlassian.renderer.v2.macro.BaseMacro;
+import com.atlassian.renderer.v2.macro.MacroException;
+
+import java.util.Map;
+
+public final class ProjectPlanMacro extends BaseMacro
+{
+    private VelocityHelperService velocityHelperService;
+
+    public boolean hasBody()
+    {
+        return false;
+    }
+
+    public RenderMode getBodyRenderMode()
+    {
+        return RenderMode.NO_RENDER;
+    }
+
+    public String execute(Map parameters, String body, RenderContext renderContext) throws MacroException
+    {
+        if (!parameters.containsKey("name"))
+            throw new MacroException("Project plan macro requires a 'name' parameter.");
+
+        Map<String, Object> context = velocityHelperService.createDefaultVelocityContext();
+        context.put("projectName", parameters.get("name"));
+        return velocityHelperService.getRenderedTemplate("/planning/project-plan-macro.vm", context);
+    }
+
+    public void setVelocityHelperService(VelocityHelperService velocityHelperService)
+    {
+        this.velocityHelperService = velocityHelperService;
+    }
+}

File src/main/resources/atlassian-plugin.xml

             </action>
         </package>
     </xwork>
+
+    <macro key="project-plan-macro" name="project-plan" class="com.atlassian.confluence.plugin.planning.ProjectPlanMacro" />
+
+    <web-resource key="jquery-gchart">
+        <resource type="download" name="jquery.gchart.js" location="/planning/jquery.gchart-1.2.3/jquery.gchart.js"/>
+        <dependency>confluence.web.resources:ajs</dependency>
+    </web-resource>
+
+    <web-resource key="project-plan-macro-resources">
+        <resource type="download" name="project.js" location="/planning/project.js"/>
+        <resource type="download" name="load-projects.js" location="/planning/load-projects.js"/>
+        <resource type="download" name="project.css" location="/planning/project.css"/>
+        <dependency>confluence.web.resources:ajs</dependency>
+        <dependency>com.atlassian.confluence.plugin.confluence-planning-plugin:jquery-gchart</dependency>
+    </web-resource>
+
+    <resource type="download" name="images/" location="/planning/images/"/>
+
 </atlassian-plugin>

File src/main/resources/planning/index.html

     <script src="jquery.gchart-1.2.3/jquery.gchart.min.js" type="text/javascript"></script>
     <script src="project.js" type="text/javascript"></script>
     <script type="text/javascript" charset="utf-8">
-        function createProject(project) {
-            jQuery(function ($) {
-                var currentProject = new Project(project.title);
-                currentProject.batchUpdate(function (currentProject) {
-                    var iteration, currentIteration, task, currentTask;
-                    for (var i=0; i<project.iterations.length; i++) {
-                        iteration = project.iterations[i];
-                        currentIteration = (iteration.title == "Backlog") ?
-                            currentProject.getBacklog() :
-                            currentProject.addIteration(iteration.title);
-                        for (var t=0; t<iteration.tasks.length; t++) {
-                            task = iteration.tasks[t];
-                            currentTask = currentIteration.addTask(task.title, task.estimate, task.notes);
-                            if (task.complete) currentTask.complete();
-                        }
+        jQuery(function ($) {
+            $(".project").each(function () {
+                var element = this;
+                var project = new Project(element);
+                var title = project.getTitle();
+                $.ajax({
+                    url: "data.js",
+                    success: function (data) {
+                        project.batchUpdate(function (project) {
+                            var iteration, currentIteration, task, currentTask;
+                            for (var i=0; i<data.iterations.length; i++) {
+                                iteration = data.iterations[i];
+                                currentIteration = (iteration.title == "Backlog") ?
+                                    project.getBacklog() :
+                                    project.addIteration(iteration.title);
+                                for (var t=0; t<iteration.tasks.length; t++) {
+                                    task = iteration.tasks[t];
+                                    currentTask = currentIteration.addTask(task.title, task.estimate, task.notes);
+                                    if (task.complete) currentTask.complete();
+                                }
+                            }
+                        });
                     }
                 });
-                // currentProject.$el.find(".hide-completed").click();
             });
-        }
+        });
     </script>
-    <script src="data.js" type="text/javascript"></script>
     <link rel="stylesheet" href="project.css" type="text/css">
 </head>
 <body>
 <h1>Project planning</h1>
-<script type="text/x-template" title="project-template">
 <div class="project hide-completed">
     <div class="header">
-        <h3 class="title">Untitled Project</h3>
+        <h3 class="title">Insert Link Dialog for 3.2</h3>
         <ul class="operations">
             <li><a href="#" class="show-chart">Show charts</a></li>
             <li><a href="#" class="hide-completed">Hide completed</a></li>
     <ol class="items">
     </ol>
 </div>
-</script>
 <script type="text/x-template" title="iteration-template">
 <li class="iteration">
     <h4 class="title editable"></h4>

File src/main/resources/planning/load-projects.js

+jQuery(function ($) {
+    var contextPath = jQuery("#confluence-context-path").attr("content");
+    $(".project-planning-macro").each(function () {
+        var element = this;
+        var project = new Project(element);
+        var title = project.getTitle();
+        $.ajax({
+            url: contextPath + "/plugins/planning/project.action",
+            dataType: 'json',
+            data: {
+                projectName: title
+            },
+            success: function (data) {
+                project.batchUpdate(function (project) {
+                    var iteration, currentIteration, task, currentTask;
+                    for (var i=0; i<data.iterations.length; i++) {
+                        iteration = data.iterations[i];
+                        currentIteration = (iteration.title == "Backlog") ?
+                            project.getBacklog() :
+                            project.addIteration(iteration.title);
+                        for (var t=0; t<iteration.tasks.length; t++) {
+                            task = iteration.tasks[t];
+                            currentTask = currentIteration.addTask(task.title, task.estimate, task.notes);
+                            if (task.complete) currentTask.complete();
+                        }
+                    }
+                });
+            }
+        });
+    });
+});

File src/main/resources/planning/project-plan-macro.vm

+#requireResource("com.atlassian.confluence.plugin.confluence-planning-plugin:project-plan-macro-resources")
+
+<div class="project hide-completed project-planning-macro">
+    <div class="header">
+        <h3 class="title">$projectName</h3>
+        <ul class="operations">
+            <li><a href="#" class="show-chart">Show charts</a></li>
+            <li><a href="#" class="hide-completed">Hide completed</a></li>
+            <li><a href="#" class="add-iteration">Add iteration</a></li>
+        </ul>
+    </div>
+    <div class="charts" style="display: none">
+        <div class="project-chart"></div>
+        <div class="iteration-chart"></div>
+    </div>
+    <div class="headings">
+        <span class="handle"></span>
+        <span class="status">Status</span>
+        <span class="title">Task</span>
+        <span class="estimate">Estimate</span>
+        <span class="notes">Notes</span>
+    </div>
+    <ol class="hidden-items">
+    </ol>
+    <ol class="items">
+    </ol>
+</div>
+
+<script type="text/x-template" title="iteration-template">
+<li class="iteration">
+    <h4 class="title editable"></h4>
+    <span class="estimate">0d</span>
+    <span class="notes">&nbsp;</span>
+    <span class="handle" title="Drag to move iteration">&bull;</span>
+    <ul class="operations">
+        <li><a href="#" class="add-task">Add task</a></li>
+    </ul>
+</li>
+</script>
+<script type="text/x-template" title="task-template">
+<li class="task">
+    <span class="status">Status</span>
+    <span class="title editable"></span>
+    <span class="estimate editable">4h</span>
+    <span class="notes editable">&nbsp;</span>
+    <span class="handle" title="Drag to reorder task">&bull;</span>
+</li>
+</script>

File src/main/resources/planning/project.css

 .project h3 {
     font-size: 1.2em;
     line-height: 24px;
+    color: #fff !important; /* override Confluence colors */
 }
 .project h4 {
     font-size: 1em;
+    color: #000 !important; /* override Confluence colors */
 }
 
 /* Task and iteration layout */

File src/main/resources/planning/project.js

 var Project;
 
 (function () {
+    var $ = jQuery;
     if (!window.console) window.console = { log: function () {} };
     
     // Shared functions
     };
     
     // public objects
-    Project = function (title) {
-        var $el = renderTemplate("project-template").appendTo($("body"));
-        $el[0].project = this;
-        if (title) $el.find("h3.title").text(title);
+    Project = function (el) {
+        el.project = this;
+        var $el = $(el);
         var $items = $el.find(".items");
         var backlog = new Iteration(this, "Backlog");
         backlog.$el.attr("id", "backlog").find(".title").removeClass("editable");
         this.getBacklog = function () {
             return backlog;
         };
+        this.getTitle = function () {
+            return $el.find("h3.title").text();
+        };
         this.addIteration = function (title) {
             var iteration = new Iteration(this, title);
             iteration.$el.insertBefore(backlog.$el);