OSDN Git Service

Implementation the cancelDesignCgangeByLine method.
authoruyaji <yuichiro.uyama@gmail.com>
Tue, 24 Sep 2013 10:16:16 +0000 (19:16 +0900)
committeruyaji <yuichiro.uyama@gmail.com>
Tue, 24 Sep 2013 10:16:16 +0000 (19:16 +0900)
PartsList/PartsList/app/controllers/DesignChangeController.scala
PartsList/PartsList/app/controllers/PartsListController.scala
PartsList/PartsList/app/models/services/DesignChangeManager.scala
PartsList/PartsList/app/views/designChangeRelationForm.scala.html
PartsList/PartsList/app/views/updateDesignChangeForm.scala.html
PartsList/PartsList/conf/routes

index e2ff4ff..0b0785d 100644 (file)
@@ -16,6 +16,7 @@ import models.PartRelation
 
 object DesignChangeController extends Controller{
    val Home = Redirect(routes.DesignChangeController.list(0,""))
+   val Home2 = Redirect(routes.PartsListController.index(0,0,""))
 
    val designChangeRegistForm = Form(
       mapping(
@@ -97,6 +98,55 @@ object DesignChangeController extends Controller{
       Redirect(routes.DesignChangeController.designChangeCoverModify(id, 0, ""))
      }
   }
+  
+  def designChangeCancelByLine(designChangeId: Long, delParentName: String, delChildName: String, addParentName: String, addChildName: String) = Action {
+    inTransaction {
+      val designChange = DesignChangeManager().getById(designChangeId)
+      if(!delParentName.isEmpty()) {
+        val delParent = PartManager().getByName(delParentName)
+        val delChild = PartManager().getByName(delChildName)
+        val cancelDelRelation = designChange.delPartRelation.where(pr => pr.parentId === delParent.id and pr.childId === delChild.id).head
+        DesignChangeManager().designChangeDelCancelBySeq(designChangeId, cancelDelRelation.dcSeq)
+      }
+      if(!addParentName.isEmpty()) {
+        val addParent = PartManager().getByName(addParentName)
+        val addChild = PartManager().getByName(addChildName)
+        val cancelAddRelation = designChange.addPartRelation.where(pr => pr.parentId === addParent.id and pr.childId === addChild.id).head
+        DesignChangeManager().designChangeAddCancelBySeq(designChangeId, cancelAddRelation.dcSeq)
+      }
+    }
+    Redirect(routes.DesignChangeController.designChangeCoverModify(designChangeId, 0, ""))    
+  }
+  
+  def designChangeForm(parentName:String, childName:String) = Action { implicit request =>
+    inTransaction {
+      var designChangeRelationForm = DesignChangeRelationForm(null, null, "")
+       // 設計変更追加の場合、変更前の上位品番はセットしない。
+      if(childName.isEmpty()) {
+        designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean("", childName), generatePartsListBean(parentName, childName), "")
+      } else {
+        designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean(parentName, childName), generatePartsListBean(parentName, childName), "")
+       }
+      Ok(views.html.designChangeRelationForm(designChangeRelationRegistForm.fill(designChangeRelationForm), ""))
+      }
+       }
+
+       def designChange() = Action { implicit request =>
+         designChangeRelationRegistForm.bindFromRequest.fold(
+             formWithErrors => BadRequest(views.html.designChangeRelationForm(formWithErrors, "")),
+             data => {
+                 inTransaction {
+                   val message = Check().loopCheckDc(data)
+                   if(message == null) {
+                     DesignChangeManager().designChange(data)
+                     Home2.flashing("success" -> "Relation %s has been changed".format(data.partsListBeanBefore.parent + "/" + data.partsListBeanBefore.child))
+                   } else {
+                     Ok(views.html.designChangeRelationForm(designChangeRelationRegistForm.fill(data), Messages(message)))
+                   }
+                 }
+             }
+         )
+       }
 
   def designChangeAppend(designChangeId: Long, dcSeq: Long, targetParentName: String) = Action {
     inTransaction {
index b99a012..8a72d7b 100644 (file)
@@ -26,22 +26,6 @@ object PartsListController extends Controller{
         )(PartsListBean.apply)(PartsListBean.unapply)
     )
     
-    val designChangeRegistForm = Form(
-        mapping(
-            "partsListBeanBefore" -> mapping(
-                "parent" -> text,
-                "child" -> text,
-                "quantity" -> longNumber
-                )(PartsListBean.apply)(PartsListBean.unapply),
-              "partsListBeanAfter" -> mapping(
-                  "parent" -> nonEmptyText,
-                  "child" -> text,
-                  "quantity" -> longNumber
-                  )(PartsListBean.apply)(PartsListBean.unapply),
-            "dcno" -> nonEmptyText
-         )(DesignChangeRelationForm.apply)(DesignChangeRelationForm.unapply)
-     )
-   
        def index(opt:Int, page:Int, key:String) = Action { implicit request =>
                var partBuffer = ArrayBuffer[PartsListBean]()
            inTransaction {
@@ -116,36 +100,6 @@ object PartsListController extends Controller{
          }
        }
        
-       def designChangeForm(parentName:String, childName:String) = Action { implicit request =>
-               inTransaction {
-                 var designChangeRelationForm = DesignChangeRelationForm(null, null, "")
-                 // 設計変更追加の場合、変更前の上位品番はセットしない。
-                 if(childName.isEmpty()) {
-                         designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean("", childName), generatePartsListBean(parentName, childName), "")
-                 } else {
-                         designChangeRelationForm = DesignChangeRelationForm(generatePartsListBean(parentName, childName), generatePartsListBean(parentName, childName), "")               
-                 }
-                       Ok(views.html.designChangeRelationForm(designChangeRegistForm.fill(designChangeRelationForm), ""))
-               }
-       }
-       
-       def designChange() = Action { implicit request =>
-         designChangeRegistForm.bindFromRequest.fold(
-             formWithErrors => BadRequest(views.html.designChangeRelationForm(formWithErrors, "")),
-             data => {
-                 inTransaction {
-                   val message = Check().loopCheckDc(data)
-                   if(message == null) {
-                     DesignChangeManager().designChange(data)
-                     Home.flashing("success" -> "Relation %s has been changed".format(data.partsListBeanBefore.parent + "/" + data.partsListBeanBefore.child))
-                   } else {
-                     Ok(views.html.designChangeRelationForm(designChangeRegistForm.fill(data), Messages(message)))
-                   }
-                 }
-             }
-         )
-       }
-               
        def generatePartsListBean(parentNo:String, childNo:String):PartsListBean = {
          if(childNo.isEmpty()) {
              PartsListBean(parentNo, childNo, 0)
index d19206a..876b590 100644 (file)
@@ -72,7 +72,7 @@ case class DesignChangeManager() {
       return designChangeBuffer
   }
   
-  def designChangeCancel(id: Long) ={
+  def designChangeCancel(id: Long) = {
     val cancelDesignChange = getById(id)
     for (cancelAddRelation <- cancelDesignChange.addPartRelation) {
       cancelAddRelation.parent.head.parts.dissociate(cancelAddRelation.child.head)
@@ -83,6 +83,20 @@ case class DesignChangeManager() {
       PartsListDb.partRelations.update(cancelDelRelation) 
     }
   }
+  
+  def designChangeAddCancelBySeq(designChangeId: Long, dcSeq: Long) = {
+    val designChange = getById(designChangeId)
+    val cancelAddRelation = designChange.addPartRelation.where(pr => pr.dcSeq === dcSeq).head
+    cancelAddRelation.parent.head.parts.dissociate(cancelAddRelation.child.head)
+  }
+
+  def designChangeDelCancelBySeq(designChangeId: Long, dcSeq: Long) = {
+    val designChange = getById(designChangeId)
+    val cancelDelRelation = designChange.delPartRelation.where(pr => pr.dcSeq === dcSeq).head
+    cancelDelRelation.delDcId = 0L
+    cancelDelRelation.dcSeq = 0L
+    PartsListDb.partRelations.update(cancelDelRelation)
+  }
 
   def designChangeUpdate(data: DesignChangeRelationForm, partName: String) = {
     val dc = getByName(data.dcno)
@@ -98,7 +112,7 @@ case class DesignChangeManager() {
       val updateRelation = dc.addPartRelation.where(pr => pr.parentId === parent.id and
           pr.childId === cancelChild.id).head
       val dcSeq = updateRelation.dcSeq
-      PartsListDb.partRelations.deleteWhere(pr => pr.addDcId === dc.id and pr.dcSeq === dcSeq)
+      updateRelation.parent.head.parts.dissociate(updateRelation.child.head)
       relationAdd(parent.name, child.name, data.partsListBeanAfter.quantity, dc, dcSeq)
     }
   }
index 7af335b..ff6e8bc 100644 (file)
@@ -4,7 +4,7 @@
 @main("Design Change by Play 2.1") {
        <h1>@Messages("title21")</h1>
        @error
-       @form(routes.PartsListController.designChange()) {
+       @form(routes.DesignChangeController.designChange()) {
                @commonDesignChangeRelationForm(designChangeRelationForm)
     }
    <br />
index ded4835..7b64166 100644 (file)
@@ -25,6 +25,7 @@
                                <th>@Messages("form.header11")@Messages("list.header1")</th>
                                <th>@Messages("form.header11")@Messages("list.header2")</th>
                                <th>@Messages("form.header11")@Messages("list.header3")</th>
+                               <th></th>
                        </tr>
                </thead>
                <tbody>
@@ -43,6 +44,7 @@
                                                <a href="/designChangeModify?designChangeId=@id&dcDelSeq=@delRelation.dcSeqBefore&dcAddSeq=@delRelation.dcSeqAfter&message=">@delRelation.quantityAfter</a>
                                                }
                                        </td>
+                                       <td><a href="/designChangeCancelByLine?designChangeId=@id&delParent=@delRelation.parentBefore&delChild=@delRelation.childBefore&addParent=@delRelation.parentAfter&addChild=@delRelation.childAfter">@Messages("list.link14")</a></td>
                                </tr>
                        }
                </tbody>
index cf9e2ef..6c19e49 100644 (file)
@@ -20,13 +20,14 @@ GET     /relationCreate                              controllers.PartsListController.createRelation(paren
 POST    /relationSave                           controllers.PartsListController.relationRegistration
 GET        /relationUpdate                              controllers.PartsListController.updateRelation(parent:String, child:String)
 POST    /relationChange                                 controllers.PartsListController.relationUpdate(childName:String)
-GET             /designChangeForm                       controllers.PartsListController.designChangeForm(parentName, childName)
-POST    /designChange                           controllers.PartsListController.designChange
 GET             /designChangeCoverForm          controllers.DesignChangeController.create
 POST    /designChangeCover                      controllers.DesignChangeController.designChangeCoverRegistration
 GET             /designChangeCoverModify        controllers.DesignChangeController.designChangeCoverModify(designChangeId:Long, dcSeq:Long, message:String)
 POST    /designChangeCoverModification         controllers.DesignChangeController.designChangeCoverModification(id: Long)
+GET             /designChangeForm                       controllers.DesignChangeController.designChangeForm(parentName, childName)
+POST    /designChange                           controllers.DesignChangeController.designChange
 POST    /designChangeCancel                     controllers.DesignChangeController.designChangeCancel(id:Long)
+GET             /designChangeCancelByLine       controllers.DesignChangeController.designChangeCancelByLine(designChangeId:Long, delParent:String, delChild:String, addParent:String, addChild:String)
 GET             /designChangeAppend                     controllers.DesignChangeController.designChangeAppend(designChangeId:Long, dcSeq:Long, parentName:String)
 GET             /designChangeModify                     controllers.DesignChangeController.designChangeRealtionModify(designChangeId: Long, dcDelSeq: Long, dcAddSeq: Long)
 POST    /designChangeModification       controllers.DesignChangeController.designChangeRelationModification(partName: String)