| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 23 Apr 2013 10:36:04 +0200 | |
| changeset 108 | ef4e3e0ef83f |
| permissions | -rw-r--r-- |
|
108
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
/* |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
2 |
* Copyright 2012 Tomas Zeman <tzeman@volny.cz> |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
* |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
* you may not use this file except in compliance with the License. |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
* You may obtain a copy of the License at |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
* |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
* |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
13 |
* See the License for the specific language governing permissions and |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
14 |
* limitations under the License. |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
15 |
*/ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
16 |
package fis.pm.ui |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
17 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
18 |
import fis.notif._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
19 |
import fis.pm.model._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
20 |
import net.liftweb.common._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
21 |
import net.liftweb.http._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
22 |
import net.liftweb.sitemap._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
23 |
import net.liftweb.util._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
24 |
import net.liftweb.util.Helpers._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
25 |
import net.tz.lift.model._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
26 |
import net.tz.lift.snippet._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
27 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
28 |
trait TaskNotification extends Loggable {
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
29 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
30 |
def viewLoc: Loc[Task] |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
31 |
def panel(t: Task): CssTr |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
32 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
33 |
def apply(orig: Box[Task], task: Box[Task]) {
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
34 |
for {
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
35 |
t <- task |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
36 |
} {
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
37 |
val submitter = t.createdBy.valueBox |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
38 |
val resp = t.responsible.valueBox |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
39 |
val respN = t.responsible.user.dmap("")(_.linkName)
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
40 |
val origResp = orig map(_.responsible.valueBox) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
41 |
val origRespU = orig flatMap(_.responsible.user) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
42 |
val updater = t.updatedBy.valueBox |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
43 |
val by = t.updatedBy.user.dmap("")(_.linkName)
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
44 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
45 |
logger.debug("Executing notifications for task %s".format(t.linkName))
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
46 |
val ne = new NotificationEngine |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
47 |
import ne._ |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
48 |
execute {
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
49 |
val cnt = content(panel(t)) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
50 |
val _title = title("*" #> a(viewLoc.calcHref(t))(viewLoc.title(t)))
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
51 |
"Task update" when(origResp == resp) then ( |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
52 |
subject(l10n("[Task %s] %s modified by %s", t.numberStr, t.linkName, by)),
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
53 |
_title, cnt, |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
54 |
to(t.createdBy.user filterNot { u => updater == submitter }),
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
55 |
to(t.responsible.user filterNot { u => updater == resp })
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
56 |
) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
57 |
"Task assignment" when(!(origResp == resp)) then ( |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
58 |
subject(l10n("[Task %s] %s assigned to %s by %s", t.numberStr, t.linkName, respN, by)),
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
59 |
_title, cnt, |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
60 |
to(t.createdBy.user filterNot { u => updater == submitter }),
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
61 |
to(origRespU filterNot { u => updater == origResp })
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
62 |
) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
63 |
"Task assigned to you" when(!(origResp == resp) && !(updater == resp)) then ( |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
64 |
subject(l10n("[Task %s] %s assigned to you by %s", t.numberStr, t.linkName, by)),
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
65 |
_title, cnt, |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
66 |
to(t.responsible.user) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
67 |
) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
68 |
} foreach { res =>
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
69 |
S notice(l10n("Sent notification to [%s] with subject %s",
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
70 |
res._3 mkString ",", res._2)) |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
71 |
} |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
72 |
} |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
73 |
} |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
74 |
} |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
75 |
|
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
76 |
// vim: set ts=2 sw=2 et: |
|
ef4e3e0ef83f
84a94fa29a67504b Task/Project notifications
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
77 |