|
81
|
1 |
/*
|
|
|
2 |
* Copyright 2012 Tomas Zeman <tzeman@volny.cz>
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
package fis.pm.model
|
|
|
17 |
|
|
|
18 |
import fis.aaa.model._
|
|
101
|
19 |
import fis.base.model.{Entity, ReadOnlyField}
|
|
|
20 |
import fis.db.PgsqlSequencer
|
|
81
|
21 |
import fis.cl.model._
|
|
|
22 |
import net.liftweb.common._
|
|
101
|
23 |
import net.liftweb.record.{LifecycleCallbacks, MetaRecord, Record}
|
|
81
|
24 |
import net.liftweb.record.field._
|
|
103
|
25 |
import net.liftweb.squerylrecord.RecordTypeMode._
|
|
81
|
26 |
import net.liftweb.util._
|
|
|
27 |
import net.tz.lift.model._
|
|
|
28 |
import net.tz.lift.model.{FieldLabel => FL}
|
|
|
29 |
import org.squeryl.annotations.Column
|
|
103
|
30 |
import org.squeryl.dsl.QueryDsl
|
|
|
31 |
import org.squeryl.dsl.ast.LogicalBoolean
|
|
81
|
32 |
import scala.xml.Text
|
|
|
33 |
|
|
|
34 |
class Task private() extends Record[Task] with Entity[Task] {
|
|
|
35 |
def meta = Task
|
|
|
36 |
|
|
|
37 |
@Column("project_id")
|
|
|
38 |
val project = new LongField(this) with ProjectField with FL
|
|
|
39 |
val deadline = new JodaDateMidnightField(this) with FL
|
|
|
40 |
val taskType = new OptionalCodeListItemField(this, 'task_type) with FL
|
|
|
41 |
val responsible = new UserField(this, meta.users, getUserVendor) with
|
|
|
42 |
DefaultCurUser with FL
|
|
|
43 |
|
|
|
44 |
@Column("state")
|
|
|
45 |
protected[pm] val stateFld = new CodeListItemField(this,
|
|
|
46 |
CodeList('task_state), _.i1.toString, { v => Text(v.i1.toString)}) with FL
|
|
|
47 |
|
|
101
|
48 |
@Column("num")
|
|
|
49 |
protected val numFld = new TaskNumber(this)
|
|
|
50 |
lazy val ident = ReadOnlyField(numFld)
|
|
|
51 |
def number = (numFld.year, numFld.get)
|
|
|
52 |
def numberStr = numFld.toString
|
|
|
53 |
|
|
81
|
54 |
def state: TaskState =
|
|
|
55 |
stateFld.item.map { TaskState(_) } openOr EmptyTaskState
|
|
103
|
56 |
|
|
|
57 |
def delayed = !state.complete &&
|
|
|
58 |
deadline.date.plusDays(1).isBefore(null) // null means now
|
|
81
|
59 |
}
|
|
|
60 |
|
|
|
61 |
object Task extends Task with MetaRecord[Task] with SimpleInjector {
|
|
|
62 |
object users extends Inject[Iterable[User]](() => Nil)
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
abstract sealed class TaskState {
|
|
|
66 |
def id: Long
|
|
|
67 |
def finishedPercent: Int
|
|
|
68 |
def complete: Boolean
|
|
|
69 |
}
|
|
|
70 |
case class TaskStateItem(id: Long, finishedPercent: Int, complete: Boolean)
|
|
|
71 |
extends TaskState
|
|
|
72 |
case object EmptyTaskState extends TaskState {
|
|
|
73 |
def id = 0
|
|
|
74 |
def finishedPercent = 0
|
|
|
75 |
def complete = false
|
|
|
76 |
}
|
|
|
77 |
object TaskState {
|
|
|
78 |
def apply(i: CodeListItem): TaskState =
|
|
|
79 |
TaskStateItem(i.id, i.i1.get, i.i1.get == 100)
|
|
103
|
80 |
|
|
|
81 |
def unfinishedClause[T](i: CodeListItem)(implicit dsl: QueryDsl):
|
|
|
82 |
LogicalBoolean = (i.i1 <> 100)
|
|
81
|
83 |
}
|
|
|
84 |
|
|
101
|
85 |
private[model] class TaskNumber(t: Task) extends IntField[Task](t) with
|
|
|
86 |
LifecycleCallbacks with FL {
|
|
|
87 |
|
|
|
88 |
def year = t.createdAt.dateTime.getYear
|
|
|
89 |
override def beforeCreate {
|
|
|
90 |
val sequencer = PgsqlSequencer("task_%d".format(year))
|
|
|
91 |
set(sequencer.next.toInt)
|
|
|
92 |
}
|
|
|
93 |
override def toString = "%d/%03d".format(year, get)
|
|
|
94 |
override def asHtml = Text(toString)
|
|
|
95 |
}
|
|
|
96 |
|
|
81
|
97 |
// vim: set ts=2 sw=2 et:
|