Giter Site home page Giter Site logo

beholder's Introduction

Beholder: Play-Slick library for data presentation

Build Status

Standard part of many application are list of data that is not a effect of simple query from one table but junction and aggregation of data from many tables. Beholder provides support for such elemets.

Features:

  • views as table
  • declaring filters for data
  • support for sorting, filtering on multiple (custom) datatypes

Contributors

Authors:

Feel free to use it, test it and to contribute!

Getting beholder

For latest version (Scala 2.13.0 compatible) use:

// https://mvnrepository.com/artifact/org.virtuslab/beholder
libraryDependencies += "org.virtuslab" %% "beholder" % "1.4.2"

Or see Maven repository for 2.10, 2.11, 2.12 and 2.13.

Or see our mvnrepository page.

Examples

Lets assume that we created simple entries

case class MachineId(id: Long) extends AnyVal with BaseId
case class UserId(id: Long) extends AnyVal with BaseId

and junction table joined them by ids.

Defining view

Usually for data in view does not came form single table so we have to create view that is materialisation of some query. Beholder provides such utility. We can create Slick's table that operate on view (it is read only).

case class UserMachineView(email: String, system: String, cores: Int)

val usersMachinesQuery = for {
  user <- Users
  userMachine <- UserMachines if user.id === userMachine.userId
  machine <- Machines if machine.id === userMachine.machineId
} yield (user, machine)


val UsersMachineView = FilterableViews.createView(name = "USERS_MACHINE_VIEW",
  apply = UserMachineView.apply _,
  unapply = UserMachineView.unapply _,
  baseQuery = usersMachinesQuery) {
  case (user, machine) =>
    //naming the fields
    ("email" -> user.email,
      "system" -> machine.system,
      "cores" -> machine.cores)
}

UsersMachineView.viewDDL.create

Defining filter

We create a filter by specify table query (view or normal table) and mapping for field

val UsersMachineFilter = new FiltersGenerator[UserMachineView].create(view,
  inText,
  inText,
  inIntField
)

Do the filtering from request

UsersMachineFilter.filterForm.bindFromRequest().fold(
  errors => handleError(),
  filterData => showResult(UsersMachineFilter.filter(filterData))
)

beholder's People

Contributors

bartosz822 avatar fazzou avatar kwestor avatar liosedhel avatar mkljakubowski avatar odisseus avatar pbatko avatar romanowski avatar tgodzik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.