diff options
author | Joris | 2017-01-01 19:46:15 +0100 |
---|---|---|
committer | Joris | 2017-01-01 19:46:15 +0100 |
commit | 36899517d126c8a7084f717cd3f3920fbb7f4cf2 (patch) | |
tree | cd8a46ae1fe7990afdda7224ae88216b5a843cfa /src/main/scala | |
parent | 97206cf6e709dd750a75af5bb79251198be4546c (diff) |
Add book covers
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/reading/component/index/Books.scala | 21 | ||||
-rw-r--r-- | src/main/scala/reading/component/index/FiltersMenu.scala | 8 | ||||
-rw-r--r-- | src/main/scala/reading/component/index/style/Books.scala | 16 | ||||
-rw-r--r-- | src/main/scala/reading/models/Difficulty.scala | 22 | ||||
-rw-r--r-- | src/main/scala/reading/models/Filter.scala | 16 | ||||
-rw-r--r-- | src/main/scala/reading/models/Grade.scala | 27 | ||||
-rw-r--r-- | src/main/scala/reading/models/Level.scala | 43 | ||||
-rw-r--r-- | src/main/scala/reading/models/Program.scala | 4 |
8 files changed, 86 insertions, 71 deletions
diff --git a/src/main/scala/reading/component/index/Books.scala b/src/main/scala/reading/component/index/Books.scala index 421fcec..23a42da 100644 --- a/src/main/scala/reading/component/index/Books.scala +++ b/src/main/scala/reading/component/index/Books.scala @@ -18,19 +18,26 @@ object Books { RxTag { implicit context => div( + BooksStyle.books, books().sorted.map { book => div( BooksStyle.book, div(BooksStyle.title, book.title), div(BooksStyle.author, s", ${book.author}"), div( - BooksStyle.description, - div(BooksStyle.item, s"classe : ${book.programs.map(Program.level).distinct.sorted.mkString(", ")}"), - div(BooksStyle.item, s"programme : ${book.programs.sorted.mkString(", ")}"), - div(BooksStyle.item, s"thème : ${book.themes.sorted.mkString(", ")}"), - div(BooksStyle.item, s"genre : ${book.genres.sorted.mkString(", ")}"), - div(BooksStyle.item, s"période : ${book.period}"), - div(BooksStyle.item, s"${book.pages} pages") + BooksStyle.detail, + img( + BooksStyle.cover, + src := s"cover/${book.title}.jpg" + ), + div( + div(BooksStyle.item, s"classe : ${book.programs.map(Program.grade).distinct.sorted.mkString(", ")}"), + div(BooksStyle.item, s"programme : ${book.programs.sorted.mkString(", ")}"), + div(BooksStyle.item, s"thème : ${book.themes.sorted.mkString(", ")}"), + div(BooksStyle.item, s"genre : ${book.genres.sorted.mkString(", ")}"), + div(BooksStyle.item, s"période : ${book.period}"), + div(BooksStyle.item, s"${book.pages} pages") + ) ) ) } diff --git a/src/main/scala/reading/component/index/FiltersMenu.scala b/src/main/scala/reading/component/index/FiltersMenu.scala index 51f8954..68ace94 100644 --- a/src/main/scala/reading/component/index/FiltersMenu.scala +++ b/src/main/scala/reading/component/index/FiltersMenu.scala @@ -17,15 +17,15 @@ object FiltersMenu { div( FiltersMenuStyle.render, FiltersMenuStyle.groups, - filters().find(_.kind == LevelKind) match { + filters().find(_.kind == GradeKind) match { case None => - group(books, filters, "Classe", Level.values.map(Filter.apply(_))) - case Some(level) => + group(books, filters, "Classe", Grade.values.map(Filter.apply(_))) + case Some(grade) => group(books, filters, "Programme", Program.values.map(Filter.apply(_))) }, group(books, filters, "Theme", Theme.values.map(Filter.apply(_))), group(books, filters, "Genre", Genre.values.map(Filter.apply(_))), - group(books, filters, "Niveau", Difficulty.filters), + group(books, filters, "Niveau", Level.filters), group(books, filters, "Période", Period.values.map(Filter.apply(_))) ) } diff --git a/src/main/scala/reading/component/index/style/Books.scala b/src/main/scala/reading/component/index/style/Books.scala index efc6af8..bbedf3a 100644 --- a/src/main/scala/reading/component/index/style/Books.scala +++ b/src/main/scala/reading/component/index/style/Books.scala @@ -8,16 +8,19 @@ object Books extends StyleSheet.Inline { import dsl._ val books = style( + display.flex, + flexWrap.wrap ) val book = style( - marginBottom(30.px) + marginBottom(30.px), + marginRight(30.px) ) val title = style( display.inlineBlock, fontWeight.bold, - marginBottom(15.px), + marginBottom(20.px), color(Col.congoBrown) ) @@ -25,8 +28,13 @@ object Books extends StyleSheet.Inline { display.inlineBlock ) - val description = style( - marginLeft(20.px) + val detail = style( + display.flex + ) + + val cover = style( + height(150.px), + marginRight(30.px) ) val item = style( diff --git a/src/main/scala/reading/models/Difficulty.scala b/src/main/scala/reading/models/Difficulty.scala deleted file mode 100644 index e20d7b2..0000000 --- a/src/main/scala/reading/models/Difficulty.scala +++ /dev/null @@ -1,22 +0,0 @@ -package reading.models - -object Difficulty { - val filters: Seq[Filter] = - Seq( - new Filter { - def filter(book: Book): Boolean = book.pages < 200 - val kind: FilterKind = DifficultyKind - val name: String = "facile" - }, - new Filter { - def filter(book: Book): Boolean = book.pages >= 200 && book.pages < 400 - val kind: FilterKind = DifficultyKind - val name: String = "moyen" - }, - new Filter { - def filter(book: Book): Boolean = book.pages > 400 - val kind: FilterKind = DifficultyKind - val name: String = "difficile" - } - ) -} diff --git a/src/main/scala/reading/models/Filter.scala b/src/main/scala/reading/models/Filter.scala index b8adcc1..00c7994 100644 --- a/src/main/scala/reading/models/Filter.scala +++ b/src/main/scala/reading/models/Filter.scala @@ -10,9 +10,9 @@ sealed trait FilterKind case object PeriodKind extends FilterKind case object ThemeKind extends FilterKind case object GenreKind extends FilterKind -case object DifficultyKind extends FilterKind -case object ProgramKind extends FilterKind case object LevelKind extends FilterKind +case object ProgramKind extends FilterKind +case object GradeKind extends FilterKind object Filter { def apply[T](in: T)(implicit filterFactory: FilterFactory[T]): Filter = @@ -26,7 +26,7 @@ object Filter { def remove(fs: Seq[Filter], rf: Filter): Seq[Filter] = fs.filterNot { f => - equals(f, rf) || rf.kind == LevelKind && f.kind == ProgramKind + equals(f, rf) || rf.kind == GradeKind && f.kind == ProgramKind } } @@ -71,12 +71,12 @@ object FilterFactory { } } - implicit object LevelFilter extends FilterFactory[Level] { - def create(level: Level): Filter = + implicit object GradeFilter extends FilterFactory[Grade] { + def create(grade: Grade): Filter = new Filter { - def filter(book: Book): Boolean = book.programs.map(Program.level).contains(level) - val kind: FilterKind = LevelKind - val name: String = level.toString() + def filter(book: Book): Boolean = book.programs.map(Program.grade).contains(grade) + val kind: FilterKind = GradeKind + val name: String = grade.toString() } } } diff --git a/src/main/scala/reading/models/Grade.scala b/src/main/scala/reading/models/Grade.scala new file mode 100644 index 0000000..e41d1a8 --- /dev/null +++ b/src/main/scala/reading/models/Grade.scala @@ -0,0 +1,27 @@ +package reading.models + +import enumeratum._ + +sealed trait Grade extends EnumEntry with Ordered[Grade] { + import Grade._ + + def compare(that: Grade): Int = { + values.indexOf(that) - values.indexOf(this) + } + + override def toString(): String = this match { + case Sixieme => "6ème" + case Cinquieme => "5ème" + case Quatrieme => "4ème" + case Troisieme => "3ème" + } +} + +object Grade extends Enum[Grade] { + val values = findValues + + case object Sixieme extends Grade + case object Cinquieme extends Grade + case object Quatrieme extends Grade + case object Troisieme extends Grade +} diff --git a/src/main/scala/reading/models/Level.scala b/src/main/scala/reading/models/Level.scala index 329c720..c297912 100644 --- a/src/main/scala/reading/models/Level.scala +++ b/src/main/scala/reading/models/Level.scala @@ -1,27 +1,22 @@ package reading.models -import enumeratum._ - -sealed trait Level extends EnumEntry with Ordered[Level] { - import Level._ - - def compare(that: Level): Int = { - values.indexOf(that) - values.indexOf(this) - } - - override def toString(): String = this match { - case Sixieme => "6ème" - case Cinquieme => "5ème" - case Quatrieme => "4ème" - case Troisieme => "3ème" - } -} - -object Level extends Enum[Level] { - val values = findValues - - case object Sixieme extends Level - case object Cinquieme extends Level - case object Quatrieme extends Level - case object Troisieme extends Level +object Level { + val filters: Seq[Filter] = + Seq( + new Filter { + def filter(book: Book): Boolean = book.pages < 200 + val kind: FilterKind = LevelKind + val name: String = "facile" + }, + new Filter { + def filter(book: Book): Boolean = book.pages >= 200 && book.pages < 400 + val kind: FilterKind = LevelKind + val name: String = "moyen" + }, + new Filter { + def filter(book: Book): Boolean = book.pages > 400 + val kind: FilterKind = LevelKind + val name: String = "difficile" + } + ) } diff --git a/src/main/scala/reading/models/Program.scala b/src/main/scala/reading/models/Program.scala index 641f352..4e59364 100644 --- a/src/main/scala/reading/models/Program.scala +++ b/src/main/scala/reading/models/Program.scala @@ -61,8 +61,8 @@ object Program extends Enum[Program] { case object AgirCite extends Program case object ProgresReveScientifique extends Program - def level(program: Program): Level = { - import Level._ + def grade(program: Program): Grade = { + import Grade._ program match { case Monstre | RecitAventure | CreationPoetique | Resister => Sixieme |