| author | Tomas Zeman <tzeman@volny.cz> |
| Wed, 30 Nov 2011 16:59:10 +0100 | |
| changeset 22 | 6b1a7f3429ca |
| parent 2 | cf829ec742b3 |
| permissions | -rw-r--r-- |
| 2 | 1 |
/* |
2 |
* Copyright 2011 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 bootstrap.liftweb |
|
17 |
||
18 |
import net.liftweb.common._ |
|
19 |
import net.liftweb.http._ |
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
20 |
import net.liftweb.http.js.JsObj |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
21 |
import net.liftweb.http.js.JE.JsObj |
| 2 | 22 |
import net.liftweb.mapper._ |
23 |
import net.liftweb.sitemap._ |
|
24 |
import net.liftweb.sitemap.Loc._ |
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
25 |
import net.liftweb.widgets.menu.MenuStyle |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
26 |
import net.liftweb.widgets.menu.{MenuWidget => LiftMenuWidget}
|
| 2 | 27 |
import net.liftweb.util._ |
28 |
import net.tz.lift.snippet.ActionLinks |
|
29 |
import net.tz.lift.util.YmdDateTimeConverter |
|
30 |
import radview.model._ |
|
31 |
import radview.snippet._ |
|
32 |
import scala.xml.NodeSeq |
|
33 |
||
34 |
class Boot extends Logger {
|
|
35 |
||
36 |
def boot = {
|
|
37 |
/* DB stuff */ |
|
38 |
initDb("radacct", RadAcctConnectionIdentifier)
|
|
39 |
initDb("radius", RadiusConnectionIdentifier)
|
|
40 |
initDb("syslog", SyslogConnectionIdentifier)
|
|
41 |
S.addAround(DB.buildLoanWrapper(List(RadAcctConnectionIdentifier, |
|
42 |
RadiusConnectionIdentifier, SyslogConnectionIdentifier))) |
|
43 |
||
44 |
if (Props.mode == Props.RunModes.Development) |
|
45 |
DB.addLogFunc { (dbLog, l) => dbLog.statementEntries.foreach { e =>
|
|
46 |
debug("Query: " + e.statement)
|
|
47 |
}} |
|
48 |
||
49 |
/* Date format */ |
|
50 |
LiftRules.dateTimeConverter.default.set { () => YmdDateTimeConverter }
|
|
51 |
||
52 |
/* Handle end slash and drop it (except for home page) */ |
|
53 |
LiftRules.statelessRewrite.append {
|
|
54 |
case RewriteRequest(ParsePath(xs,_,_,true),_,_) if (xs.size > 1) && |
|
55 |
(xs.lastOption == Some("index")) =>
|
|
56 |
RewriteResponse(xs dropRight 1) |
|
57 |
} |
|
58 |
||
59 |
/* Snippet dispatch */ |
|
60 |
LiftRules.snippetDispatch.append {
|
|
61 |
case "Menubar" => new AnyRef with DispatchSnippet {
|
|
62 |
def dispatch: DispatchIt = {
|
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
63 |
case _ => { xhtml =>
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
64 |
new MenuWidget(MenuStyle.HORIZONTAL, JsObj(), Nil) render |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
65 |
} |
| 2 | 66 |
} |
67 |
} |
|
68 |
case "action-links" => ActionLinks |
|
69 |
} |
|
70 |
||
71 |
/* Sitemap */ |
|
72 |
SiteMap.enforceUniqueLinks = false |
|
73 |
||
74 |
LiftRules.setSiteMap(SiteMap( |
|
75 |
Menu.i("Home") / "index" >> Hidden,
|
|
76 |
Menu(CellSnippet), |
|
77 |
Menu.i("Cells") / "cell",
|
|
78 |
Menu(SessionSnippet), |
|
79 |
Menu(AccountSnippet), |
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
80 |
Menu.i("Accounts") / "account",
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
81 |
DynIpSnippet.menu |
| 2 | 82 |
)) |
83 |
||
84 |
/* Menu widget */ |
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
85 |
LiftMenuWidget.init() |
| 2 | 86 |
|
87 |
/* Http conf */ |
|
88 |
LiftRules.logServiceRequestTiming = false |
|
89 |
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
|
|
90 |
} |
|
91 |
||
92 |
def initDb(ident: String, connId: ConnectionIdentifier) = {
|
|
93 |
val driver = "com.mysql.jdbc.Driver" |
|
94 |
val vendor = new StandardDBVendor(driver, |
|
95 |
Props.get("db."+ident+".url") openOr ("jdbc:mysql://localhost/"+ident),
|
|
96 |
Props.get("db."+ident+".user"), Props.get("db."+ident+".pass"))
|
|
97 |
//LiftRules.unloadHooks.append(vendor.closeAllConnections_! _) |
|
98 |
DB.defineConnectionManager(connId, vendor) |
|
99 |
vendor.newConnection(connId) |
|
100 |
} |
|
101 |
} |
|
102 |
||
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
103 |
class MenuWidget(style: MenuStyle.Value, jsObj: JsObj, groups : List[String]) |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
104 |
extends LiftMenuWidget(style, jsObj, groups) {
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
105 |
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
106 |
override def render: NodeSeq = {
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
107 |
head ++ <div>{groups match {
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
108 |
case Nil => |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
109 |
<lift:Menu.builder expandAll="true" linkToSelf="true" top:class={style.toString} />
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
110 |
case xs => groups.flatMap(group => |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
111 |
<lift:Menu.builder expandAll="true" linkToSelf="true" top:class={style.toString} group={group} />)
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
112 |
}}</div> |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
113 |
} |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
114 |
} |
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
115 |
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
116 |
|
| 2 | 117 |
// vim: set ts=2 sw=2 et: |