← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13081: delete ip-comment in ip-controller, only display gearbox if ip.user== or ip.comment.user=

 

------------------------------------------------------------
revno: 13081
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-12-01 15:12:59 +0100
message:
  delete ip-comment in ip-controller, only display gearbox if ip.user== or ip.comment.user=
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2013-12-01 13:25:33 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2013-12-01 14:12:59 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.interpretation.Interpretation;
+import org.hisp.dhis.interpretation.InterpretationComment;
 import org.hisp.dhis.interpretation.InterpretationService;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.mapping.MappingService;
@@ -59,13 +60,14 @@
 import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 
 /**
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping(value = InterpretationController.RESOURCE_PATH)
+@RequestMapping( value = InterpretationController.RESOURCE_PATH )
 public class InterpretationController
     extends AbstractCrudController<Interpretation>
 {
@@ -120,22 +122,9 @@
         return entityList;
     }
 
-    @Override
-    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
-    {
-        Interpretation interpretation = interpretationService.getInterpretation( uid );
-
-        if ( interpretation == null )
-        {
-            throw new NotFoundException( uid );
-        }
-
-        interpretationService.deleteInterpretation( interpretation );
-    }
-
     @RequestMapping( value = "/chart/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void shareChartInterpretation(
-        @PathVariable("uid") String chartUid,
+        @PathVariable( "uid" ) String chartUid,
         @RequestBody String text, HttpServletResponse response )
     {
         Chart chart = chartService.getChart( chartUid );
@@ -162,9 +151,9 @@
         ContextUtils.createdResponse( response, "Interpretation created", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() );
     }
 
-    @RequestMapping(value = "/map/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
+    @RequestMapping( value = "/map/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void shareMapInterpretation(
-        @PathVariable("uid") String mapUid,
+        @PathVariable( "uid" ) String mapUid,
         @RequestBody String text, HttpServletResponse response )
     {
         Map map = mappingService.getMap( mapUid );
@@ -182,11 +171,11 @@
         ContextUtils.createdResponse( response, "Interpretation created", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() );
     }
 
-    @RequestMapping(value = "/reportTable/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
+    @RequestMapping( value = "/reportTable/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void shareReportTableInterpretation(
-        @PathVariable("uid") String reportTableUid,
-        @RequestParam(value = "pe", required = false) String isoPeriod,
-        @RequestParam(value = "ou", required = false) String orgUnitUid,
+        @PathVariable( "uid" ) String reportTableUid,
+        @RequestParam( value = "pe", required = false ) String isoPeriod,
+        @RequestParam( value = "ou", required = false ) String orgUnitUid,
         @RequestBody String text, HttpServletResponse response )
     {
         ReportTable reportTable = reportTableService.getReportTable( reportTableUid );
@@ -219,11 +208,11 @@
         ContextUtils.createdResponse( response, "Interpretation created", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() );
     }
 
-    @RequestMapping(value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
+    @RequestMapping( value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
     public void shareDataSetReportInterpretation(
-        @PathVariable("uid") String dataSetUid,
-        @RequestParam("pe") String isoPeriod,
-        @RequestParam("ou") String orgUnitUid,
+        @PathVariable( "uid" ) String dataSetUid,
+        @RequestParam( "pe" ) String isoPeriod,
+        @RequestParam( "ou" ) String orgUnitUid,
         @RequestBody String text, HttpServletResponse response )
     {
         DataSet dataSet = dataSetService.getDataSet( dataSetUid );
@@ -257,21 +246,41 @@
         ContextUtils.createdResponse( response, "Interpretation created", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() );
     }
 
-    @RequestMapping(value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
-    public void postComment(
-        @PathVariable("uid") String uid,
-        @RequestBody String text, HttpServletResponse response )
-    {
-        Interpretation interpretation = interpretationService.getInterpretation( uid );
-
-        if ( interpretation == null )
-        {
-            ContextUtils.conflictResponse( response, "Interpretation does not exist: " + uid );
-            return;
-        }
-
-        interpretationService.addInterpretationComment( uid, text );
-
-        ContextUtils.createdResponse( response, "Commented created", InterpretationController.RESOURCE_PATH + "/" + uid );
+    @Override
+    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
+    {
+        Interpretation interpretation = interpretationService.getInterpretation( uid );
+
+        if ( interpretation == null )
+        {
+            throw new NotFoundException( uid );
+        }
+
+        interpretationService.deleteInterpretation( interpretation );
+    }
+
+    @RequestMapping( value = "/{uid}/comments/{cuid}", method = RequestMethod.DELETE )
+    public void deleteComment( @PathVariable( "uid" ) String uid, @PathVariable( "cuid" ) String cuid ) throws NotFoundException
+    {
+        Interpretation interpretation = interpretationService.getInterpretation( uid );
+
+        if ( interpretation == null )
+        {
+            throw new NotFoundException( uid );
+        }
+
+        Iterator<InterpretationComment> iterator = interpretation.getComments().iterator();
+
+        while ( iterator.hasNext() )
+        {
+            InterpretationComment comment = iterator.next();
+
+            if ( comment.getUid().equals( cuid ) )
+            {
+                iterator.remove();
+            }
+        }
+
+        interpretationService.updateInterpretation( interpretation );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm	2013-12-01 13:25:33 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm	2013-12-01 14:12:59 +0000
@@ -133,10 +133,12 @@
 }
 </style>
 
-#macro( gearDropDown )
-<div class="gearDropDown">
-  <span><i class="fa fa-gear"></i> <i class="fa fa-caret-down"></i></span>
-</div>
+#macro( gearDropDown $user )
+  #if( $!currentUser.username != $!user.username )
+  <div class="gearDropDown">
+    <span><i class="fa fa-gear"></i> <i class="fa fa-caret-down"></i></span>
+  </div>
+  #end
 #end
 
 <div class="dropDown">
@@ -161,7 +163,7 @@
            <a class="bold userLink" href="profile.action?id=${ip.user.uid}">${encoder.htmlEncode( $ip.user.name )}</a><br>
            <span class="tipText">${format.formatDate( $ip.created )}</span>
         </div>
-        #gearDropDown()
+        #gearDropDown( $ip.user )
 	    </div>
 	    <div class="interpretationText">
 	        $!dhisTextUtils.htmlify( ${ip.text} )
@@ -198,10 +200,11 @@
         	#end
         	<div id="comments${ip.uid}">
 	        #foreach( $comment in $comments )
-	        <div #if( $velocityCount <= $commentStartPos ) style="display:none"#end>
+	        <div #if( $velocityCount <= $commentStartPos ) style="display:none"#end class="interpretationComment" data-ip-comment-uid="$comment.uid">
 	            <div class="interpretationName">
-	                <a class="bold userLink" href="profile.action?id=${comment.user.uid}">${comment.user.name}</a>&nbsp;
-	                <span class="grey">${format.formatDate( $comment.created )}</span>
+                <a class="bold userLink" href="profile.action?id=${comment.user.uid}">${comment.user.name}</a>&nbsp;
+                <span class="grey">${format.formatDate( $comment.created )}</span>
+                #gearDropDown( $comment.user )
 	            </div>
 		        <div class="interpretationText">
 		            $!dhisTextUtils.htmlify( ${comment.text} )
@@ -209,8 +212,10 @@
             </div>
 	        #end
 	        </div>
-	        <textarea id="commentArea${ip.uid}" class="commentArea" placeholder="$i18n.getString( 'add_a_comment' )..."></textarea>
-	        <input type="button" class="commentButton" value="Post comment" onclick="postComment( '${ip.uid}' )">
+          <div style="clear: none;">
+            <textarea id="commentArea${ip.uid}" class="commentArea" placeholder="$i18n.getString( 'add_a_comment' )..."></textarea>
+            <input type="button" class="commentButton" value="Post comment" onclick="postComment( '${ip.uid}' )">
+          </div>
 	    </div>
     </div>
 </div>