mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-11-03 18:00:11 +00:00 
			
		
		
		
	Allow to use the created timestamp in item queries
Refs: 925
This commit is contained in:
		@@ -53,6 +53,7 @@ object ItemQuery {
 | 
			
		||||
    case object ItemId      extends StringAttr
 | 
			
		||||
    case object Date        extends DateAttr
 | 
			
		||||
    case object DueDate     extends DateAttr
 | 
			
		||||
    case object CreatedDate extends DateAttr
 | 
			
		||||
    case object AttachCount extends IntAttr
 | 
			
		||||
 | 
			
		||||
    object Correspondent {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,9 @@ object AttrParser {
 | 
			
		||||
  val dueDate: P[Attr.DateAttr] =
 | 
			
		||||
    P.ignoreCase(C.due).as(Attr.DueDate)
 | 
			
		||||
 | 
			
		||||
  val created: P[Attr.DateAttr] =
 | 
			
		||||
    P.ignoreCase(C.created).as(Attr.CreatedDate)
 | 
			
		||||
 | 
			
		||||
  val corrOrgId: P[Attr.StringAttr] =
 | 
			
		||||
    P.ignoreCase(C.corrOrgId)
 | 
			
		||||
      .as(Attr.Correspondent.OrgId)
 | 
			
		||||
@@ -78,7 +81,7 @@ object AttrParser {
 | 
			
		||||
    attachCountAttr
 | 
			
		||||
 | 
			
		||||
  val dateAttr: P[Attr.DateAttr] =
 | 
			
		||||
    P.oneOf(List(date, dueDate))
 | 
			
		||||
    P.oneOf(List(date, dueDate, created))
 | 
			
		||||
 | 
			
		||||
  val stringAttr: P[Attr.StringAttr] =
 | 
			
		||||
    P.oneOf(
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,8 @@ object Constants {
 | 
			
		||||
  val corrOrgName   = "corr.org.name"
 | 
			
		||||
  val corrPersId    = "corr.pers.id"
 | 
			
		||||
  val corrPersName  = "corr.pers.name"
 | 
			
		||||
  val created       = "created"
 | 
			
		||||
  val createdIn     = "createdIn"
 | 
			
		||||
  val customField   = "f"
 | 
			
		||||
  val customFieldId = "f.id"
 | 
			
		||||
  val date          = "date"
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,9 @@ object MacroParser {
 | 
			
		||||
  val dueDateRangeMacro: P[Expr.DateRangeMacro] =
 | 
			
		||||
    dateRangeMacroImpl(C.dueIn, Attr.DueDate)
 | 
			
		||||
 | 
			
		||||
  val createdDateRangeMacro: P[Expr.DateRangeMacro] =
 | 
			
		||||
    dateRangeMacroImpl(C.createdIn, Attr.CreatedDate)
 | 
			
		||||
 | 
			
		||||
  val yearDateMacro: P[Expr.YearMacro] =
 | 
			
		||||
    yearMacroImpl(C.year, Attr.Date)
 | 
			
		||||
 | 
			
		||||
@@ -52,6 +55,7 @@ object MacroParser {
 | 
			
		||||
        namesMacro,
 | 
			
		||||
        dateRangeMacro,
 | 
			
		||||
        dueDateRangeMacro,
 | 
			
		||||
        createdDateRangeMacro,
 | 
			
		||||
        yearDateMacro,
 | 
			
		||||
        corrMacro,
 | 
			
		||||
        concMacro
 | 
			
		||||
 
 | 
			
		||||
@@ -56,6 +56,14 @@ class SimpleExprParserTest extends FunSuite with ValueHelper {
 | 
			
		||||
      p.parseAll("due<2021-03-14"),
 | 
			
		||||
      Right(dateExpr(Operator.Lt, Attr.DueDate, ld(2021, 3, 14)))
 | 
			
		||||
    )
 | 
			
		||||
    assertEquals(
 | 
			
		||||
      p.parseAll("created:2021-03-14"),
 | 
			
		||||
      Right(dateExpr(Operator.Like, Attr.CreatedDate, ld(2021, 3, 14)))
 | 
			
		||||
    )
 | 
			
		||||
    assertEquals(
 | 
			
		||||
      p.parseAll("created<2021-03-14"),
 | 
			
		||||
      Right(dateExpr(Operator.Lt, Attr.CreatedDate, ld(2021, 3, 14)))
 | 
			
		||||
    )
 | 
			
		||||
    assertEquals(
 | 
			
		||||
      p.parseAll("due~=2021-03-14,2021-03-13"),
 | 
			
		||||
      Right(Expr.InDateExpr(Attr.DueDate, Nel.of(ld(2021, 3, 14), ld(2021, 3, 13))))
 | 
			
		||||
 
 | 
			
		||||
@@ -228,6 +228,8 @@ object ItemQueryGenerator {
 | 
			
		||||
        coalesce(tables.item.itemDate.s, tables.item.created.s).s
 | 
			
		||||
      case Attr.DueDate =>
 | 
			
		||||
        tables.item.dueDate.s
 | 
			
		||||
      case Attr.CreatedDate =>
 | 
			
		||||
        tables.item.created.s
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  private def stringColumn(tables: Tables)(attr: Attr.StringAttr): Column[String] =
 | 
			
		||||
 
 | 
			
		||||
@@ -88,6 +88,7 @@ These fields map to at most one value:
 | 
			
		||||
- `id` the item id
 | 
			
		||||
- `date` the item date
 | 
			
		||||
- `due` the due date of the item
 | 
			
		||||
- `created` the date when the item was created
 | 
			
		||||
- `attach.count` the number of attachments of the item
 | 
			
		||||
- `corr.org.id` the id of the correspondent organization
 | 
			
		||||
- `corr.org.name` the name of the correspondent organization
 | 
			
		||||
@@ -124,6 +125,7 @@ Other special fields:
 | 
			
		||||
- `f.id` for referencing custom fields by their id
 | 
			
		||||
- `dateIn` a shortcut for a range search
 | 
			
		||||
- `dueIn` a shortcut for a range search
 | 
			
		||||
- `createdIn` a shortcut for a range search
 | 
			
		||||
- `exist` check if some porperty exists
 | 
			
		||||
- `names` a shortcut to search in several names via `:`
 | 
			
		||||
- `year` a shortcut for a year range
 | 
			
		||||
@@ -469,7 +471,7 @@ attach.id=5YjdnuTAdKJ-V6ofWTYsqKV-mAwB5aXTNWE-FAbeRU58qLb
 | 
			
		||||
Shortcuts are only a short form of a longer query and are provided for
 | 
			
		||||
convenience. The following exist:
 | 
			
		||||
 | 
			
		||||
- `dateIn` and `dueIn`
 | 
			
		||||
- `dateIn`, `dueIn` and `createdIn`
 | 
			
		||||
- `year`
 | 
			
		||||
- `names`
 | 
			
		||||
- `conc`
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user