def sectionsAndTags()

in app/controllers/Admin.scala [232:265]


  def sectionsAndTags(selectedSectionIdOption: Option[Long]) = (AuthAction andThen PermissionFilter).async {

    val selectedSectionOptionFt:Future[Option[Section]] = selectedSectionIdOption match {
      case Some(selectedSectionId) =>
        for {
          sections <- getSortedSections()
        } yield Some(sections.filter( x => x.id == selectedSectionId ).head)
      case None => Future(None)
    }
    val tagIdsFuture: Future[List[String]] = selectedSectionIdOption match {
      case Some(selectedSectionId) =>
        val tagIdsFt: Future[Either[ApiError, List[String]]] = sectionsAPI.getTagsForSectionFt(selectedSectionId).asFuture
        tagIdsFt.map(_.toOption.get)
      case None => Future.successful(List())
    }
    for {
      deskList <- getDesks()
      sectionListFromDB <- getSortedSections()
      tagIds <- tagIdsFuture
      selectedSectionOption <- selectedSectionOptionFt
    } yield {
      val capiKeyJson: Json = parser.parse(s"""{"CAPI_API_KEY": ${config.capiKey}}""").toOption.get
      Ok(
        views.html.admin.sectionsAndTags(
          capiKeyJson,
          sectionListFromDB,
          selectedSectionIdOption,
          selectedSectionOption,
          tagIds,
          addSectionTagForm
        )
      )
    }
  }