aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorJoris2016-12-21 10:14:05 +0100
committerJoris2016-12-21 10:14:05 +0100
commit92100eeb139e8de68620b3524519b66a641e2e0c (patch)
treef8efe5fd02a082fc43fe158afd784f57548fa43c /src/main/scala
parent6b7588970de3cc5e80bf444c5b9141ec0b72da0a (diff)
Add genres and themes, sort books by removing « Les » and « Le »
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/reading/Books.scala42
-rw-r--r--src/main/scala/reading/component/Index.scala7
-rw-r--r--src/main/scala/reading/component/index/Books.scala12
-rw-r--r--src/main/scala/reading/component/index/style/Books.scala6
-rw-r--r--src/main/scala/reading/models/Book.scala19
-rw-r--r--src/main/scala/reading/models/Genre.scala26
-rw-r--r--src/main/scala/reading/models/Theme.scala68
7 files changed, 148 insertions, 32 deletions
diff --git a/src/main/scala/reading/Books.scala b/src/main/scala/reading/Books.scala
new file mode 100644
index 0000000..743d06c
--- /dev/null
+++ b/src/main/scala/reading/Books.scala
@@ -0,0 +1,42 @@
+package reading
+
+import reading.models.{Book, Theme, Genre}, Theme._, Genre._
+
+object Books {
+ def apply(): Seq[Book] = Seq(
+ Book(
+ title = "Les Dix petits nègres",
+ author = "Agatha Christie",
+ genres = Seq(Policier),
+ themes = Seq(Peur)
+ ),
+
+ Book(
+ title = "Le Joueur",
+ author = "Fiódor Dostoyevski",
+ genres = Seq(),
+ themes = Seq(Peur)
+ ),
+
+ Book(
+ title = "Voyage au bout de la nuit",
+ author = "Céline",
+ genres = Seq(),
+ themes = Seq(Peur)
+ ),
+
+ Book(
+ title = "Le Petit Prince",
+ author = "Antoine de Saint Exupéry",
+ genres = Seq(Policier),
+ themes = Seq(Amitie)
+ ),
+
+ Book(
+ title = "Les Frères Karamazov",
+ author = "Fiódor Dostoyevski",
+ genres = Seq(),
+ themes = Seq(Famille)
+ )
+ )
+}
diff --git a/src/main/scala/reading/component/Index.scala b/src/main/scala/reading/component/Index.scala
index 28d9081..ef8ae51 100644
--- a/src/main/scala/reading/component/Index.scala
+++ b/src/main/scala/reading/component/Index.scala
@@ -7,8 +7,9 @@ import scalatags.JsDom.all._
import scalacss.Defaults._
import scalacss.ScalatagsCss._
+import reading.Books
import reading.component.style.{Index => IndexStyle}
-import reading.component.index.{FiltersMenu, Filters, Books}
+import reading.component.index.{FiltersMenu, Filters, Books => BooksComponent}
import reading.models.{Book, Filter}
import reading.utils.RxAttr
@@ -16,7 +17,7 @@ object Index {
def apply(): Frag = {
val filters: Var[Seq[Filter]] = Var(Nil)
val books: Rx[Seq[Book]] = Rx {
- if(filters().isEmpty) Book.all else Book.filter(Book.all, filters())
+ if(filters().isEmpty) Books() else Book.filter(Books(), filters())
}
div(
@@ -34,7 +35,7 @@ object Index {
div(
IndexStyle.main,
Filters(filters),
- Books(books)
+ BooksComponent(books)
)
)
)
diff --git a/src/main/scala/reading/component/index/Books.scala b/src/main/scala/reading/component/index/Books.scala
index 6ce1b2b..ef0f413 100644
--- a/src/main/scala/reading/component/index/Books.scala
+++ b/src/main/scala/reading/component/index/Books.scala
@@ -18,13 +18,19 @@ object Books {
RxTag { implicit context =>
div(
- books().sortBy(_.title).map { book =>
+ books().sorted.map { book =>
div(
BooksStyle.book,
div(BooksStyle.title, book.title),
div(BooksStyle.author, book.author),
- div(BooksStyle.genres, book.genres.mkString(", ")),
- div(BooksStyle.themes, book.themes.mkString(", "))
+ div(
+ BooksStyle.genres,
+ span(s"genre: ${book.genres.mkString(", ")}")
+ ),
+ div(
+ BooksStyle.themes,
+ span(s"thème: ${book.themes.mkString(", ")}")
+ )
)
}
)
diff --git a/src/main/scala/reading/component/index/style/Books.scala b/src/main/scala/reading/component/index/style/Books.scala
index 2c0dfc0..fa97849 100644
--- a/src/main/scala/reading/component/index/style/Books.scala
+++ b/src/main/scala/reading/component/index/style/Books.scala
@@ -15,17 +15,23 @@ object Books extends StyleSheet.Inline {
)
val title = style(
+ display.inlineBlock,
fontWeight.bold,
marginBottom(10.px),
+ marginRight(10.px),
color(Col.congoBrown)
)
val author = style(
+ display.inlineBlock
)
val genres = style(
+ marginLeft(20.px),
+ marginBottom(10.px)
)
val themes = style(
+ marginLeft(20.px)
)
}
diff --git a/src/main/scala/reading/models/Book.scala b/src/main/scala/reading/models/Book.scala
index 1e4b81a..b856b7d 100644
--- a/src/main/scala/reading/models/Book.scala
+++ b/src/main/scala/reading/models/Book.scala
@@ -1,21 +1,20 @@
package reading.models
-case class Book(
+case class Book (
title: String,
author: String,
genres: Seq[Genre],
themes: Seq[Theme]
-)
+) extends Ordered[Book] {
+ def compare(that: Book) = {
+ def formatTitle(title: String) =
+ title.toLowerCase.replaceAll("^les ", "").replaceAll("^le ", "")
-object Book {
- def all: Seq[Book] = Seq(
- Book("Les dix petits nègres", "Agatha Christie", Seq(Genre.Detective), Seq(Theme.Fear)),
- Book("Le joueur", "Fiódor Dostoyevski", Seq(Genre.Adventure), Seq(Theme.Fear)),
- Book("Voyage au bout de la nuit", "Céline", Seq(Genre.Adventure), Seq(Theme.Fear)),
- Book("Le petit prince", "Antoine de Saint Exupéry", Seq(Genre.Adventure), Seq(Theme.Friendship)),
- Book("Les frères Karamazov", "Fiódor Dostoyevski", Seq(Genre.Adventure), Seq(Theme.Family))
- )
+ formatTitle(this.title).compare(formatTitle(that.title))
+ }
+}
+object Book {
def filter(books: Seq[Book], filters: Seq[Filter]): Seq[Book] =
books.filter(b => filters.forall(_.filter(b)))
}
diff --git a/src/main/scala/reading/models/Genre.scala b/src/main/scala/reading/models/Genre.scala
index 44da79d..bc5d219 100644
--- a/src/main/scala/reading/models/Genre.scala
+++ b/src/main/scala/reading/models/Genre.scala
@@ -3,19 +3,29 @@ package reading.models
import enumeratum._
sealed trait Genre extends EnumEntry {
+ import Genre._
+
override def toString(): String = this match {
- case Genre.Adventure => "aventure"
- case Genre.Fantastic => "fantastique"
- case Genre.Detective => "policier"
- case Genre.Marvellous => "merveilleux"
+ case JournalIntime => "journal intime"
+ case RomanHistorique => "roman historique"
+ case Policier => "policier"
+ case Fantastique => "fantastique"
+ case Fantasy => "fantasy"
+ case Merveilleux => "merveilleux"
+ case SF => "SF"
+ case BD => "BD"
}
}
object Genre extends Enum[Genre] {
val values = findValues
- case object Adventure extends Genre
- case object Fantastic extends Genre
- case object Detective extends Genre
- case object Marvellous extends Genre
+ case object JournalIntime extends Genre
+ case object RomanHistorique extends Genre
+ case object Policier extends Genre
+ case object Fantastique extends Genre
+ case object Fantasy extends Genre
+ case object Merveilleux extends Genre
+ case object SF extends Genre
+ case object BD extends Genre
}
diff --git a/src/main/scala/reading/models/Theme.scala b/src/main/scala/reading/models/Theme.scala
index ed7ee0b..35b84b8 100644
--- a/src/main/scala/reading/models/Theme.scala
+++ b/src/main/scala/reading/models/Theme.scala
@@ -3,19 +3,71 @@ package reading.models
import enumeratum._
sealed trait Theme extends EnumEntry {
+ import Theme._
+
override def toString(): String = this match {
- case Theme.Love => "amour"
- case Theme.Friendship => "amitié"
- case Theme.Family => "famille"
- case Theme.Fear => "peur"
+ case Amitie => "amitié"
+ case Aventure => "aventure"
+ case Amour => "amour"
+ case Animal => "animal"
+ case Adolescence => "adolescence"
+ case Ecole => "école"
+ case Enquete => "enquête"
+ case Enfants => "enfants"
+ case Emancipation => "émancipation"
+ case Folie => "folie"
+ case Complot => "complot"
+ case Combat => "combat"
+ case Cour => "cour"
+ case Dragon => "dragon"
+ case Famille => "famille"
+ case Fratrie => "fratrie"
+ case Guerre => "guerre"
+ case Histoire => "histoire"
+ case Humour => "humour"
+ case Initiation => "initiation"
+ case JeuVideo => "jeu vidéo"
+ case Litterature => "littérature"
+ case Malediction => "malédiction"
+ case Magie => "magie"
+ case Nature => "nature"
+ case Parents => "parents"
+ case Peur => "peur"
+ case Pirate => "pirate"
+ case Rivalite => "rivalité"
}
}
object Theme extends Enum[Theme] {
val values = findValues
- case object Love extends Theme
- case object Friendship extends Theme
- case object Family extends Theme
- case object Fear extends Theme
+ case object Amitie extends Theme
+ case object Aventure extends Theme
+ case object Amour extends Theme
+ case object Animal extends Theme
+ case object Adolescence extends Theme
+ case object Ecole extends Theme
+ case object Enquete extends Theme
+ case object Enfants extends Theme
+ case object Emancipation extends Theme
+ case object Folie extends Theme
+ case object Complot extends Theme
+ case object Combat extends Theme
+ case object Cour extends Theme
+ case object Dragon extends Theme
+ case object Famille extends Theme
+ case object Fratrie extends Theme
+ case object Guerre extends Theme
+ case object Histoire extends Theme
+ case object Humour extends Theme
+ case object Initiation extends Theme
+ case object JeuVideo extends Theme
+ case object Litterature extends Theme
+ case object Malediction extends Theme
+ case object Magie extends Theme
+ case object Nature extends Theme
+ case object Parents extends Theme
+ case object Peur extends Theme
+ case object Pirate extends Theme
+ case object Rivalite extends Theme
}