nitweb: introduce ModelAction
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 16 Dec 2015 00:29:30 +0000 (19:29 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 19 Dec 2015 05:55:17 +0000 (00:55 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/web/web_actions.nit
src/web/web_base.nit

index 574e32e..b4e000c 100644 (file)
@@ -20,10 +20,7 @@ import model::model_collect
 
 # Display the tree of all loaded mentities.
 class TreeAction
-       super NitAction
-
-       # Model to explore and render.
-       var model: Model
+       super ModelAction
 
        # View to render.
        var view = new HtmlHomePage(model) is lazy
@@ -33,10 +30,7 @@ end
 
 # Display the list of mentities matching `namespace`.
 class SearchAction
-       super NitAction
-
-       # Model to explore and render.
-       var model: Model
+       super ModelAction
 
        # TODO handle more than full namespaces.
        redef fun answer(request, url) do
@@ -59,10 +53,7 @@ end
 
 # Display a MEntity source code.
 class CodeAction
-       super NitAction
-
-       # Model to explore and render.
-       var model: Model
+       super ModelAction
 
        # Modelbuilder used to access sources.
        var modelbuilder: ModelBuilder
@@ -84,10 +75,7 @@ end
 
 # Display the doc of a MEntity.
 class DocAction
-       super NitAction
-
-       # Model to explore and render.
-       var model: Model
+       super ModelAction
 
        # Modelbuilder used to access sources.
        var modelbuilder: ModelBuilder
@@ -109,10 +97,7 @@ end
 
 # Return a random list of MEntities.
 class RandomAction
-       super NitAction
-
-       # Model to explore and render.
-       var model: Model
+       super ModelAction
 
        # TODO handle more than full namespaces.
        redef fun answer(request, url) do
index 68d132c..ecf639e 100644 (file)
@@ -15,7 +15,7 @@
 # Base classes used by `nitweb`.
 module web_base
 
-import frontend
+import model::model_views
 import nitcorn
 import json
 
@@ -85,6 +85,29 @@ class NitAction
        end
 end
 
+# Specific nitcorn Action that uses a Model
+class ModelAction
+       super NitAction
+
+       # Model to use.
+       var model: Model
+
+       # Init the model view from the `req` uri parameters.
+       fun init_model_view(req: HttpRequest): ModelView do
+               var view = new ModelView(model)
+
+               var show_private = req.bool_arg("private") or else false
+               if not show_private then view.min_visibility = protected_visibility
+
+               view.include_fictive = req.bool_arg("fictive") or else false
+               view.include_empty_doc = req.bool_arg("empty-doc") or else true
+               view.include_test_suite = req.bool_arg("test-suite") or else false
+               view.include_attribute = req.bool_arg("attributes") or else true
+
+               return view
+       end
+end
+
 # A NitView is rendered by an action.
 interface NitView
        # Renders this view and returns something that can be written to a HTTP response.