From 714a151fefd4685e60c8340464666e4df775b605 Mon Sep 17 00:00:00 2001 From: uyaji Date: Wed, 28 May 2014 12:06:31 +0900 Subject: [PATCH] Asynchronous implements --- .../app/controllers/PartsListController.scala | 22 ++++++++++++---------- .../app/controllers/services/PartsList.scala | 3 +++ .../PartsList/app/views/partslistshow.scala.html | 2 +- PartsList/PartsList/conf/routes | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/PartsList/PartsList/app/controllers/PartsListController.scala b/PartsList/PartsList/app/controllers/PartsListController.scala index fbf1ce6..a9bb6b2 100644 --- a/PartsList/PartsList/app/controllers/PartsListController.scala +++ b/PartsList/PartsList/app/controllers/PartsListController.scala @@ -21,6 +21,8 @@ import com.google.inject._ import modules._ import scala.io.Source import java.io.FileInputStream +import scala.concurrent.Future +import play.api.libs.concurrent.Execution.Implicits._ object PartsListController extends Controller{ val inject = Guice.createInjector(new ServiceModules) @@ -59,21 +61,21 @@ object PartsListController extends Controller{ } } - def downLoad(opt:Int, page:Int, key:String, relationKey:String) = AuthAction { + def downLoadFuture(opt:Int, page:Int, key:String, relationKey:String) = AuthAction { Action { implicit request => if(request == null) { Ok(views.html.errors.errorNotAuthentication()) } else { - inTransaction{ - val partsBuffer = PartsList().getPartsBuffer(opt, page, key, relationKey) - var totalCost:Long =0 - for(partBuffer <- partsBuffer) { - totalCost += partBuffer.cost - } - val attachment = "attachment; filename=" + key + "_download.csv" - Ok(views.html.partsListsCsv(partsBuffer)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv") + val futureOfPartsBuffer: Future[Seq[PartsListShowBean]] = Future { + PartsList().getPartsBuffer(opt, page, key, relationKey) + } + val attachment = "attachment; filename=" + key + "_download.csv" + Async { + futureOfPartsBuffer.map { fpb => + Ok(views.html.partsListsCsv(fpb)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv") } - } + } + } } } diff --git a/PartsList/PartsList/app/controllers/services/PartsList.scala b/PartsList/PartsList/app/controllers/services/PartsList.scala index 667e688..af712ae 100644 --- a/PartsList/PartsList/app/controllers/services/PartsList.scala +++ b/PartsList/PartsList/app/controllers/services/PartsList.scala @@ -1,11 +1,13 @@ package controllers.services import scala.collection.immutable.Map import scala.collection.immutable.Seq +import org.squeryl.PrimitiveTypeMode._ import beans._ import models._ import models.services._ case class PartsList() { def getPartsBuffer(opt:Int, page:Int, key:String, relationKey:String):Seq[PartsListShowBean] = { + inTransaction { var partsBuffer = Seq[PartsListShowBean]() val targetParts = PartManager().getByName(key) if(targetParts.size != 0) { @@ -14,6 +16,7 @@ case class PartsList() { } } return partsBuffer + } } def getMatrixPartsList(partsListBeans: Seq[Seq[PartsListShowBean]], allChildren: Seq[Part]): Map[Part, Seq[MultiPartsListBean]] = { diff --git a/PartsList/PartsList/app/views/partslistshow.scala.html b/PartsList/PartsList/app/views/partslistshow.scala.html index a1763ee..54e6f0a 100644 --- a/PartsList/PartsList/app/views/partslistshow.scala.html +++ b/PartsList/PartsList/app/views/partslistshow.scala.html @@ -101,7 +101,7 @@
- @helper.form(action=routes.PartsListController.downLoad(opt, page, key, relationKey)) { + @helper.form(action=routes.PartsListController.downLoadFuture(opt, page, key, relationKey)) { diff --git a/PartsList/PartsList/conf/routes b/PartsList/PartsList/conf/routes index 4b69c9e..94d320f 100644 --- a/PartsList/PartsList/conf/routes +++ b/PartsList/PartsList/conf/routes @@ -5,7 +5,7 @@ # Home page GET / controllers.Application.index GET /single_partslist controllers.PartsListController.index(opt:Int=0, page:Int, key:String, relationKey:String) -GET /single_partslist_download controllers.PartsListController.downLoad(opt:Int, page:Int, key:String, relationKey:String) +GET /single_partslist_download_future controllers.PartsListController.downLoadFuture(opt:Int, page:Int, key:String, relationKey:String) GET /multi_partslist controllers.PartsListController.index(opt:Int=1, page:Int, key:String, relationKey:String) POST /multi_partslist controllers.PartsListController.index(opt:Int=1, page:Int, key:String, relationKey:String) GET /matrix_partslists controllers.PartsListController.matrixPartList(project:String) -- 2.11.0