Skip to content

Commit

Permalink
Merge pull request #436 from chrisbenincasa/make-dynamic-lists
Browse files Browse the repository at this point in the history
Create dynamic lists from Explore page
  • Loading branch information
chrisbenincasa authored Nov 17, 2019
2 parents ad53623 + bd24314 commit 5e8fd33
Show file tree
Hide file tree
Showing 75 changed files with 2,944 additions and 641 deletions.
36 changes: 36 additions & 0 deletions codebuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARG BASE_IMAGE=launcher.gcr.io/google/openjdk8
FROM ${BASE_IMAGE}

ARG SBT_VERSION=1.2.8
ARG SHA=f4b9fde91482705a772384c9ba6cdbb84d1c4f7a278fd2bfb34961cd9ed8e1d7
ARG BASE_URL=https://github.com/sbt/sbt/releases/download

ENV SBT_OPTS="\
-Djava.net.preferIPv4Stack=true \
-XX:+AggressiveOpts \
-XX:+UseParNewGC \
-XX:+UseConcMarkSweepGC \
-XX:+CMSParallelRemarkEnabled \
-XX:+CMSClassUnloadingEnabled \
-XX:ReservedCodeCacheSize=128m \
-XX:SurvivorRatio=128 \
-XX:MaxTenuringThreshold=0 \
-Xss8M \
-Xms512M \
-Xmx2G \
-server \
"

RUN apt-get update -qqy \
&& apt-get install -qqy curl bc \
&& mkdir -p /usr/share \
&& curl -fsSL -o "sbt-${SBT_VERSION}.zip" "${BASE_URL}/v${SBT_VERSION}/sbt-${SBT_VERSION}.zip" \
&& echo "${SHA} sbt-${SBT_VERSION}.zip" | sha256sum -c - \
&& unzip -qq "sbt-${SBT_VERSION}.zip" \
&& rm -f "sbt-${SBT_VERSION}.zip" \
&& mv sbt "/usr/share/sbt-${SBT_VERSION}" \
&& ln -s "/usr/share/sbt-${SBT_VERSION}/bin/sbt" /usr/bin/sbt \
&& apt-get remove -qqy --purge curl \
&& rm /var/lib/apt/lists/*_*

ENTRYPOINT ["/usr/bin/sbt"]
Original file line number Diff line number Diff line change
@@ -1,51 +1,90 @@
package com.teletracker.common.api.model

import com.teletracker.common.db.model.{
DynamicListDefaultSort,
DynamicListGenreRule,
DynamicListItemTypeRule,
DynamicListNetworkRule,
DynamicListPersonRule,
DynamicListReleaseYearRule,
DynamicListRule,
DynamicListRules,
DynamicListTagRule,
PersonAssociationType,
ThingType,
UserThingTagType
}
import java.util.UUID

object TrackedListRules {
def fromRow(dynamicListRules: DynamicListRules): TrackedListRules = {
TrackedListRules(
rules = dynamicListRules.rules.map(convertRule)
rules = dynamicListRules.rules.map(convertRule),
sortOptions = dynamicListRules.sort.map(
opts => TrackedListSortOptions(sort = opts.sort)
)
)
}

private def convertRule(dynamicListRule: DynamicListRule): TrackedListRule = {
dynamicListRule match {
case DynamicListPersonRule(personId, _) =>
TrackedListPersonRule(personId)
case DynamicListPersonRule(personId, associationType, _) =>
TrackedListPersonRule(personId, associationType)

case DynamicListTagRule(tagType, value, isPresent, _) =>
TrackedListTagRule(tagType, value, isPresent)

case DynamicListGenreRule(genreId, _) =>
TrackedListGenreRule(genreId)

case DynamicListItemTypeRule(itemType, _) =>
TrackedListItemTypeRule(itemType)

case DynamicListNetworkRule(networkId, _) =>
TrackedListNetworkRule(networkId)

case DynamicListReleaseYearRule(min, max, _) =>
TrackedListReleaseYearRule(min, max)
}
}

private def convertRule(trackedListRule: TrackedListRule): DynamicListRule = {
trackedListRule match {
case TrackedListPersonRule(personId) =>
DynamicListPersonRule(personId)
case TrackedListPersonRule(personId, associationType) =>
DynamicListPersonRule(personId, associationType)

case TrackedListTagRule(tagType, value, isPresent) =>
DynamicListTagRule(tagType, value, isPresent)

case TrackedListGenreRule(genreId) =>
DynamicListGenreRule(genreId)

case TrackedListItemTypeRule(itemType) =>
DynamicListItemTypeRule(itemType)

case TrackedListNetworkRule(networkId) =>
DynamicListNetworkRule(networkId)

case TrackedListReleaseYearRule(minimum, maximum) =>
DynamicListReleaseYearRule(minimum, maximum)
}
}
}

case class TrackedListRules(rules: List[TrackedListRule]) {
case class TrackedListRules(
rules: List[TrackedListRule],
sortOptions: Option[TrackedListSortOptions]) {
require(rules.nonEmpty)
def toRow: DynamicListRules = {
DynamicListRules(
rules = rules.map(TrackedListRules.convertRule)
rules = rules.map(TrackedListRules.convertRule),
sort = sortOptions.map(opts => DynamicListDefaultSort(opts.sort))
)
}
}

case class TrackedListSortOptions(sort: String)

sealed trait TrackedListRule

case class TrackedListTagRule(
Expand All @@ -54,4 +93,18 @@ case class TrackedListTagRule(
isPresent: Option[Boolean])
extends TrackedListRule

case class TrackedListPersonRule(personId: UUID) extends TrackedListRule
case class TrackedListPersonRule(
personId: UUID,
associationType: Option[PersonAssociationType])
extends TrackedListRule

case class TrackedListGenreRule(genreId: Int) extends TrackedListRule

case class TrackedListItemTypeRule(itemType: ThingType) extends TrackedListRule

case class TrackedListNetworkRule(networkId: Int) extends TrackedListRule

case class TrackedListReleaseYearRule(
minimum: Option[Int],
maximum: Option[Int])
extends TrackedListRule
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.teletracker.common.db.model

import com.teletracker.common.db.SortMode
import org.checkerframework.checker.units.qual.min
import java.util.UUID

sealed trait DynamicListRule {
def negated: Option[Boolean]
}

object DynamicListTagRule {
def ifPresent(tagType: UserThingTagType): DynamicListTagRule =
DynamicListTagRule(tagType, None, Some(true))

def watched = ifPresent(UserThingTagType.Watched)
def notWatched = watched.negate
}

case class DynamicListTagRule(
tagType: UserThingTagType,
value: Option[Double],
isPresent: Option[Boolean],
negated: Option[Boolean] = None)
extends DynamicListRule {
def withValue(value: Double): DynamicListTagRule =
this.copy(value = Some(value))

def negate: DynamicListTagRule = this.copy(negated = Some(true))
}

case class DynamicListPersonRule(
personId: UUID,
associationType: Option[PersonAssociationType],
negated: Option[Boolean] = None)
extends DynamicListRule

case class DynamicListGenreRule(
genreId: Int,
negated: Option[Boolean] = None)
extends DynamicListRule

case class DynamicListItemTypeRule(
itemType: ThingType,
negated: Option[Boolean] = None)
extends DynamicListRule

case class DynamicListNetworkRule(
networkId: Int,
negated: Option[Boolean] = None)
extends DynamicListRule

sealed trait DynamicListRangeRule[T] extends DynamicListRule {
def minimum: Option[T]
def maximum: Option[T]
def inclusive: Boolean = true
}

case class DynamicListReleaseYearRule(
minimum: Option[Int],
maximum: Option[Int],
negated: Option[Boolean] = None)
extends DynamicListRangeRule[Int]

case class DynamicListDefaultSort(sort: String)

case class DynamicListRules(
rules: List[DynamicListRule],
sort: Option[DynamicListDefaultSort]) {
require(rules.nonEmpty)
}

object DynamicListRules {
def watched =
DynamicListRules(
rules = DynamicListTagRule.ifPresent(UserThingTagType.Watched) :: Nil,
sort = None
)

def person(
id: UUID,
associationType: Option[PersonAssociationType] = None
) =
DynamicListRules(
rules = DynamicListPersonRule(id, associationType) :: Nil,
sort = None
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,6 @@ case class TrackedListRow(
def toFull: TrackedList = TrackedList.fromRow(this)
}

object DynamicListTagRule {
def ifPresent(tagType: UserThingTagType): DynamicListTagRule =
DynamicListTagRule(tagType, None, Some(true))

def watched = ifPresent(UserThingTagType.Watched)
def notWatched = watched.negate
}

sealed trait DynamicListRule {
def negated: Option[Boolean]
}

case class DynamicListTagRule(
tagType: UserThingTagType,
value: Option[Double],
isPresent: Option[Boolean],
negated: Option[Boolean] = None)
extends DynamicListRule {
def withValue(value: Double): DynamicListTagRule =
this.copy(value = Some(value))

def negate: DynamicListTagRule = this.copy(negated = Some(true))
}

case class DynamicListPersonRule(
personId: UUID,
negated: Option[Boolean] = None)
extends DynamicListRule

object DynamicListRules {
def watched =
DynamicListRules(
rules = DynamicListTagRule.ifPresent(UserThingTagType.Watched) :: Nil
)

def person(id: UUID) =
DynamicListRules(
rules = DynamicListPersonRule(id) :: Nil
)
}

case class DynamicListRules(rules: List[DynamicListRule]) {
require(rules.nonEmpty)
}

case class TrackedListRowOptions(removeWatchedItems: Boolean)

class TrackedLists @Inject()(
Expand Down
Loading

0 comments on commit 5e8fd33

Please sign in to comment.