← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13080: implement deletion of interpretations in ui and controller (not for comments yet)

 

------------------------------------------------------------
revno: 13080
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-12-01 14:25:33 +0100
message:
  implement deletion of interpretations in ui and controller (not for comments yet)
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-11-12 15:04:52 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/InterpretationController.java	2013-12-01 13:25:33 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.api.controller.exception.NotFoundException;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;
@@ -54,6 +55,7 @@
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.Date;
@@ -63,7 +65,7 @@
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping( value = InterpretationController.RESOURCE_PATH )
+@RequestMapping(value = InterpretationController.RESOURCE_PATH)
 public class InterpretationController
     extends AbstractCrudController<Interpretation>
 {
@@ -118,9 +120,22 @@
         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 );
@@ -147,9 +162,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 );
@@ -167,11 +182,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 );
@@ -204,11 +219,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 );
@@ -242,19 +257,19 @@
         ContextUtils.createdResponse( response, "Interpretation created", InterpretationController.RESOURCE_PATH + "/" + interpretation.getUid() );
     }
 
-    @RequestMapping( value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" } )
+    @RequestMapping(value = "/{uid}/comment", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
     public void postComment(
-        @PathVariable( "uid" ) String uid,
+        @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 );

=== 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 12:25:04 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm	2013-12-01 13:25:33 +0000
@@ -14,6 +14,15 @@
 jQuery(function() {
   var dropDown = jQuery('.dropDown');
 
+  dropDown.on('click.dropdown', 'li', function(e) {
+    var jqTarget = jQuery(e.target).closest('li');
+    var targetFn = dhis2.contextmenu.utils.findFnInWindowScope(jqTarget.data('target-fn'));
+
+    if( typeof targetFn !== 'undefined' ) {
+      targetFn( e );
+    }
+  });
+
   jQuery('.gearDropDown').on('click', function( e ) {
     var jqTarget = jQuery(e.target);
 
@@ -40,6 +49,31 @@
     }
   });
 });
+
+function editIp( e ) {
+}
+
+function deleteIp( e ) {
+  var jqTarget = jQuery(e.target);
+  var jqActiveGearDropDown = jQuery('.gearDropDown.active');
+  var isHeader = jqActiveGearDropDown.parents('.interpretationName').length != 0;
+  var isComment = jqActiveGearDropDown.parents('.interpretationCommentArea').length != 0;
+  var jqInterpretation = jqActiveGearDropDown.parents('.interpretation');
+  var uid = jqInterpretation.data('ip-uid');
+
+  if( isHeader ) {
+    jQuery.ajax({
+      url: '../api/interpretations/' + uid,
+      type: 'DELETE'
+    }).done(function() {
+      jqInterpretation.parents('.interpretationContainer').remove();
+    }).error(function() {
+      setHeaderDelayMessage('Could not delete interpretation, please try again later');
+    });
+  } else if( isComment ) {
+
+  }
+}
 </script>
 
 <style>
@@ -97,7 +131,6 @@
   text-decoration  : none;
   background-color : #eee;
 }
-
 </style>
 
 #macro( gearDropDown )
@@ -108,8 +141,8 @@
 
 <div class="dropDown">
   <ul>
-    <li><a>Edit</a></li>
-    <li><a>Delete</a></li>
+    <li data-target-fn="editIp" ><a>$i18n.getString('edit')</a></li>
+    <li data-target-fn="deleteIp"><a>$i18n.getString('delete')</a></li>
   </ul>
 </div>
 
@@ -119,7 +152,7 @@
     #if( $ip.organisationUnit )#set( $ou = "&ou=" + $ip.organisationUnit.uid )#else#set( $ou = "" )#end
     #if( $ip.period )#set( $pe = "&pe=" + $ip.period.isoDate )#else#set( $pe = "" )#end
 
-    <div class="interpretation">
+    <div class="interpretation" data-ip-uid="$ip.uid">
 	    <div class="interpretationName">
 	    	<div class="interpretationSymbol">
 	    	  #getSymbol( $ip )