Merge: nitweb: add misc features
authorJean Privat <jean@pryen.org>
Wed, 8 Jun 2016 13:00:50 +0000 (09:00 -0400)
committerJean Privat <jean@pryen.org>
Wed, 8 Jun 2016 13:00:50 +0000 (09:00 -0400)
A little of everything in this PR:

* show all properties of a class: http://nitweb.moz-code.org/class/core::Array (see all props tab)
* show code into linearization card: http://nitweb.moz-code.org/class/core::Array (see linearization tab)
* show class definitions for modules: http://nitweb.moz-code.org/module/core::array

Pull-Request: #2172
Reviewed-by: Jean Privat <jean@pryen.org>

share/nitweb/directives/entity/defcard.html
share/nitweb/javascripts/entities.js
share/nitweb/javascripts/model.js
share/nitweb/stylesheets/nitweb.css
share/nitweb/views/class.html
share/nitweb/views/module.html
src/nitweb.nit
src/web/model_api.nit

index 2c0b9c8..5a024fe 100644 (file)
                        <span ng-if='!definition.mclassdef'>
                                in <entity-link mentity='definition.mmodule' />
                        </span>
+                       <div class='btn-bar'>
+                               <button class='btn btn-link' aria-expanded='false'
+                                       data-target='#{{codeId}}' ng-click='loadCardCode()'
+                                       aria-controls='{{codeId}}'>
+                                       <span class='glyphicon glyphicon-console'
+                                       title='Show code' />
+                               </button>
+                       </div>
                </h5>
+               <div id='{{codeId}}' class='collapse'>
+                       <pre ng-bind-html='code' />
+               </div>
                <entity-location mentity='definition' />
        </div>
 </div>
index 4428c89..9eefc9f 100644 (file)
                                        });
                        };
 
+                       this.loadEntityDefs = function() {
+                               Model.loadEntityDefs($routeParams.id,
+                                       function(data) {
+                                               $scope.defs = data;
+                                       }, function(err) {
+                                               $scope.error = err;
+                                       });
+                       };
+
                        this.loadEntityCode = function() {
                                Model.loadEntityCode($routeParams.id,
                                        function(data) {
                                        definition: '=',
                                        focus: '='
                                },
+                               templateUrl: '/directives/entity/defcard.html',
                                link: function ($scope, element, attrs) {
-                                       $scope.$watch("definition", function() {
-                                               /*.loadEntityDefs($scope.definition.full_name,
-                                                       function(data) {
-                                                               $scope.mentity = data;
-                                                       }, function(err) {
-                                                               $scope.error = err;
-                                                       });
-                                               Model.loadEntityCode($scope.definition.full_name,
-                                                       function(data) {
-                                                               $scope.code = data;
-                                                       }, function(err) {
-                                                               $scope.error = err;
-                                                       });*/
-                                       });
-                               },
-                               templateUrl: '/directives/entity/defcard.html'
+                                       $scope.codeId = 'code_' + $scope.definition.full_name.replace(/[^a-zA-Z0-9]/g, '_');
+                                       $scope.loadCardCode = function() {
+                                               if(!$scope.code) {
+                                                       Model.loadEntityCode($scope.definition.full_name,
+                                                               function(data) {
+                                                                       $scope.code = data;
+                                                                       setTimeout(function() { // smooth collapse
+                                                                               $('#' + $scope.codeId).collapse('show')
+                                                                       }, 1);
+                                                               }, function(err) {
+                                                                       $scope.code = err;
+                                                               });
+                                               } else {
+                                                       if($('#' + $scope.codeId).hasClass('in')) {
+                                                               $('#' + $scope.codeId).collapse('hide');
+                                                       } else {
+                                                               $('#' + $scope.codeId).collapse('show');
+                                                       }
+                                               }
+                                       };
+                               }
                        };
                }])
 })();
index b3e2248..2144983 100644 (file)
                                                .error(cbErr);
                                },
 
+                               loadEntityDefs: function(id, cb, cbErr) {
+                                       $http.get(apiUrl + '/defs/' + id)
+                                               .success(cb)
+                                               .error(cbErr);
+                               },
+
                                loadEntityCode: function(id, cb, cbErr) {
                                        $http.get(apiUrl + '/code/' + id)
                                                .success(cb)
index eb82ee6..941b5a4 100644 (file)
@@ -77,6 +77,9 @@ a {
 
 /* ui */
 
+.btn-bar { margin-top: -5px; float: right }
+.btn-bar .btn { padding: 5px 10px; }
+
 entity-list .btn-filter {
        visibility: hidden;
 }
index 2585705..4950546 100644 (file)
                        </a>
                </li>
                <li role='presentation'>
+                       <a data-toggle='tab' data-target='#all_props'>
+                               <span class='glyphicon glyphicon-tags'/> All properties
+                       </a>
+               </li>
+               <li role='presentation'>
                        <a data-toggle='tab' role='tab' data-target='#linearization' aria-controls='linearization' ng-click='entityCtrl.loadEntityLinearization()'>
                                <span class='glyphicon glyphicon-arrow-down'/> Linearization
                        </a>
                                list-entities='mentity.redef_mproperties'
                                list-object-filter='{is_init: "!true"}' />
                </div>
+               <div role='tabpanel' class='tab-pane fade' id='all_props'>
+                       <entity-list list-title='All properties' list-entities='mentity.all_mproperties'
+                               list-object-filter='{}' />
+               </div>
                <div role='tabpanel' class='tab-pane fade' id='linearization'>
                        <entity-linearization
                                list-title='Class definitions'
index 34ddd28..9a15c76 100644 (file)
@@ -5,16 +5,21 @@
        </div>
 
        <ul class='nav nav-tabs'>
-               <li class='active'>
+               <li role='presentation' class='active'>
                        <a data-toggle='tab' data-target='#doc'>
                                <span class='glyphicon glyphicon-book'/> Doc
                        </a>
                </li>
-               <li>
+               <li role='presentation'>
                        <a data-toggle='tab' data-target='#code' ng-click="entityCtrl.loadEntityCode()">
                                <span class='glyphicon glyphicon-console'/> Code
                        </a>
                </li>
+               <li role='presentation'>
+                       <a data-toggle='tab' data-target='#defs' ng-click="entityCtrl.loadEntityDefs()">
+                               <span class='glyphicon glyphicon-asterisk'/> Class definitions
+                       </a>
+               </li>
        </ul>
 
        <div class='tab-content'>
@@ -39,5 +44,9 @@
                                </div>
                        </div>
                </div>
+               <div role='tabpanel' class='tab-pane fade' id='defs'>
+                       <entity-list list-title='Class definitions' list-entities='defs'
+                               list-object-filter='{}' />
+               </div>
        </div>
 </div>
index ef83fb6..a1a41a3 100644 (file)
@@ -101,6 +101,7 @@ class APIRouter
                use("/code/:id", new APIEntityCode(model, mainmodule, modelbuilder))
                use("/uml/:id", new APIEntityUML(model, mainmodule))
                use("/linearization/:id", new APIEntityLinearization(model, mainmodule))
+               use("/defs/:id", new APIEntityDefs(model, mainmodule))
        end
 end
 
index 5b24282..0d4c205 100644 (file)
@@ -141,6 +141,31 @@ class APIEntityLinearization
        end
 end
 
+# List definitions of a MEntity.
+#
+# Example: `GET /defs/core::Array`
+class APIEntityDefs
+       super APIHandler
+
+       redef fun get(req, res) do
+               var mentity = mentity_from_uri(req, res)
+               var arr = new JsonArray
+               if mentity isa MModule then
+                       for mclassdef in mentity.mclassdefs do arr.add mclassdef
+               else if mentity isa MClass then
+                       for mclassdef in mentity.mclassdefs do arr.add mclassdef
+               else if mentity isa MClassDef then
+                       for mpropdef in mentity.mpropdefs do arr.add mpropdef
+               else if mentity isa MProperty then
+                       for mpropdef in mentity.mpropdefs do arr.add mpropdef
+               else
+                       res.error 404
+                       return
+               end
+               res.json arr
+       end
+end
+
 # Return a UML representation of MEntity.
 #
 # Example: `GET /entity/core::Array/uml`