Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Walker Crouse <[email protected]>
  • Loading branch information
windy1 committed Apr 1, 2016
1 parent 8476c5f commit 6858024
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 65 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
logs
project/project
project/target
target
tmp
uploads
.history
dist
.idea
/*.iml
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This file is part of Sponge, licensed under the MIT License (MIT).
This file is part of Ore, licensed under the MIT License (MIT).

Copyright (c) SpongePowered.org <http://www.spongepowered.org>
Copyright (c) contributors
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class Application @Inject()(override val messagesApi: MessagesApi) extends Contr
val categoryArray = Categories.fromString(csv)
Storage.now(Storage.getProjects(categoryArray.map(_.id))) match {
case Failure(thrown) => throw thrown
case Success(projects) => Ok(views.index(projects, Some(categoryArray)))
case Success(projects) =>
// Don't pass "visible categories" if all categories are visible
val allCategories = Categories.values.subsetOf(categoryArray.toSet)
Ok(views.index(projects, if (allCategories) None else Some(categoryArray)))
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions app/controllers/Projects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,17 @@ class Projects @Inject()(override val messagesApi: MessagesApi) extends Controll
Storage.now(project.getChannels) match {
case Failure(thrown) => throw thrown
case Success(chans) =>
val channelNames = if (channels.isDefined) Some(channels.get.split(",")) else None
var channelNames = if (channels.isDefined) Some(channels.get.split(",")) else None
var visibleChannels = chans
if (channelNames.isDefined) {
visibleChannels = chans.filter(c => channelNames.get.contains(c.getName))
}

val versions: Seq[Version] = (for (c <- visibleChannels) yield {
Storage.now(c.getVersions) match {
case Failure(thrown) => throw thrown
case Success(versionSeq) => versionSeq
}
}).flatten
// Don't pass "visible channels" if all channels are visible
val versions = if (chans.equals(visibleChannels)) project.getVersions else project.getVersions(visibleChannels)
if (channelNames.isDefined && chans.map(_.getName).toSet.subsetOf(channelNames.get.toSet)) {
channelNames = None
}

Ok(views.projects.versions.list(project, chans, versions, channelNames));
}
Expand Down
18 changes: 9 additions & 9 deletions app/db/Storage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ object Storage {
filter[ChannelTable, Channel](classOf[Channel], c => c.projectId === projectId)
}

def getChannels(projectId: Int, names: Array[String]): Future[Seq[Channel]] = {
val query = for {
channel <- q[ChannelTable](classOf[Channel])
if channel.projectId === projectId
if channel.name inSetBind names
} yield channel
this.config.db.run(query.result)
}

def optChannel(projectId: Int, name: String): Future[Option[Channel]] = {
optOne[ChannelTable, Channel](classOf[Channel], c => c.projectId === projectId && c.name === name)
}
Expand Down Expand Up @@ -288,6 +279,15 @@ object Storage {
filter[VersionTable, Version](classOf[Version], v => v.channelId === channelId)
}

def getVersions(projectId: Int, channelIds: Seq[Int]): Future[Seq[Version]] = {
val query = for {
version <- q[VersionTable](classOf[Version])
if version.projectId === projectId
if version.channelId inSetBind channelIds
} yield version
this.config.db.run(query.result)
}

def optVersion(channelId: Int, versionString: String): Future[Option[Version]] = {
optOne[VersionTable, Version](classOf[Version], v => v.channelId === channelId && v.versionString === versionString)
}
Expand Down
24 changes: 16 additions & 8 deletions app/models/project/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.sql.Timestamp
import java.text.SimpleDateFormat
import java.util.Date

import com.google.common.base.Preconditions
import com.google.common.base.Preconditions._
import db.Storage
import models.author.Dev
import models.project.ChannelColors.ChannelColor
Expand Down Expand Up @@ -101,14 +103,6 @@ case class Project(id: Option[Int], private var createdAt: Option[Timestamp], pl
*/
def getChannels: Future[Seq[Channel]] = Storage.getChannels(this.id.get)

/**
* Returns the Channels with the specified names.
*
* @param names Names of channels to get
* @return Channels with specified names
*/
def getChannels(names: Array[String]): Future[Seq[Channel]] = Storage.getChannels(this.id.get, names)

/**
* Returns the Channel in this project with the specified name.
*
Expand Down Expand Up @@ -175,6 +169,20 @@ case class Project(id: Option[Int], private var createdAt: Option[Timestamp], pl
case Success(versions) => versions
}

/**
* Returns all Versions belonging to the specified channels.
*
* @param channels Channels to get versions for
* @return All versions in channels
*/
def getVersions(channels: Seq[Channel]): Seq[Version] = {
channels.foreach(c => checkArgument(c.projectId == this.id.get, "channel doesn't belong to project", ""))
Storage.now(Storage.getVersions(this.id.get, channels.map(_.id.get))) match {
case Failure(thrown) => throw thrown
case Success(versions) => versions
}
}

/**
* Returns true if this Project already exists.
*
Expand Down
4 changes: 2 additions & 2 deletions app/views/projects/table.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ <h3 class="panel-title">@messages("project.category.plural")</h3>
@if(visibleCategories.isDefined) {
@if(!visibleCategories.get.contains(Categories(i).asInstanceOf[Category])) {
<a href="@routes.Application.index(Some(
(visibleCategories.get.map(_.id) :+ i).mkString("\u002c")
(visibleCategories.get.map(_.id) :+ i).mkString(",")
))">
<i class="fa fa-eye-slash"></i>
</a>
} else {
<a href="@routes.Application.index(Some(
visibleCategories.get.map(_.id).filterNot(id => id == i).mkString("\u002c")
visibleCategories.get.map(_.id).filterNot(id => id == i).mkString(",")
))">
<i class="fa fa-eye"></i>
</a>
Expand Down
59 changes: 24 additions & 35 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
# Application configuration
# Enable fakeUser to bypass standard authentication in a development environment
application.secret = "changeme"
application.secret = ${?APPLICATION_SECRET}
application.baseUrl = ${BASE_URL}
application.fakeUser = false
application.fakeUser = ${?FAKE_USER}
application.langs = "en-US"

play.i18n.langs = [ "en", "en-US" ]
# Play configuration
play.crypto.secret = "changeme"
play.crypto.secret = ${?APPLICATION_SECRET}
play.i18n.langs = [ "en", "en-US" ]
play.evolutions.autocommit = false
play.evolutions.db.default.autoApply = true

# Slick configuration
slick.dbs.default.driver = "slick.driver.PostgresDriver$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = ${JDBC_DATABASE_URL}
slick.dbs.default.db.user = ${JDBC_DATABASE_USERNAME}
slick.dbs.default.db.password = ""
slick.dbs.default.db.password = ${?JDBC_DATABASE_PASSWORD}

# Discourse SSO
discourse.sso.secret = ${?DISCOURSE_SSO_SECRET}
discourse.sso.url = ${?DISCOURSE_SSO_URL}

# Sponge stuff
sponge.logo = "https://forums-cdn.spongepowered.org/uploads/default/original/2X/7/77fa5f82289385db14561fac384ddea2a84a0070.png"
sponge.icon = "https://forums-cdn.spongepowered.org/uploads/default/original/2X/9/9ba706a80e45cf427617525ee2a19fad7bb6b109.png"

# Global object class
# ~~~~~
Expand Down Expand Up @@ -42,30 +57,4 @@ play.i18n.langs = [ "en", "en-US" ]
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root = ERROR

# Logger used by the framework:
logger.play = INFO

# Logger provided to your application:
logger.application = DEBUG

# Slick configuration
slick.dbs.default.driver = "slick.driver.PostgresDriver$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = ${JDBC_DATABASE_URL}
slick.dbs.default.db.user = ${JDBC_DATABASE_USERNAME}
slick.dbs.default.db.password = ""
slick.dbs.default.db.password = ${?JDBC_DATABASE_PASSWORD}
slick.dbs.default.db.connectionTestQuery = "select 1"

# Discourse SSO
discourse.sso.secret = ${?DISCOURSE_SSO_SECRET}
discourse.sso.url = ${?DISCOURSE_SSO_URL}

sponge.logo = "https://forums-cdn.spongepowered.org/uploads/default/original/2X/7/77fa5f82289385db14561fac384ddea2a84a0070.png"
sponge.icon = "https://forums-cdn.spongepowered.org/uploads/default/original/2X/9/9ba706a80e45cf427617525ee2a19fad7bb6b109.png"

play.evolutions.autocommit = false
play.evolutions.db.default.autoApply = true
# TODO: Configure logger

0 comments on commit 6858024

Please sign in to comment.