You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by er...@apache.org on 2013/04/19 20:09:29 UTC

svn commit: r1469977 - in /rave/branches/angular/rave-portal-resources/src/main/webapp: WEB-INF/jsp/views/ static/css/ static/html/ static/html/portal/ static/script/angular-portal/ static/script/core/

Author: erinnp
Date: Fri Apr 19 18:09:28 2013
New Revision: 1469977

URL: http://svn.apache.org/r1469977
Log:
Refactor of portal controller, cleaner controller code.

Modified:
    rave/branches/angular/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/angular.jsp
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/css/rave-css.less
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/portal/tabs.html
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/profile.html
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/app.js
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/controllers.js
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/services.js
    rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/core/rave_widget.js

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/angular.jsp
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/angular.jsp?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/angular.jsp (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/angular.jsp Fri Apr 19 18:09:28 2013
@@ -16,6 +16,7 @@
 <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
+<script src="http://code.angularjs.org/1.1.4/angular-resource.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.0.3/bootstrap.min.js"></script>
 
 

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/css/rave-css.less
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/css/rave-css.less?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/css/rave-css.less (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/css/rave-css.less Fri Apr 19 18:09:28 2013
@@ -254,7 +254,6 @@ width: 90%;*/
 .widget-prefs {
   border: 1px solid #D3D3D3;
   background-color: white;
-  display: none;
 }
 
 .widget-prefs-required-text {

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/portal/tabs.html
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/portal/tabs.html?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/portal/tabs.html (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/portal/tabs.html Fri Apr 19 18:09:28 2013
@@ -1,6 +1,10 @@
-<div ng-controller="tabsController">
+<div ng-controller="PortalController">
     <nav>
         <ul class="nav nav-tabs">
+            <li ng-repeat="page in pages" ng-class="{active:page.id == selectedPageId, dropdown:page.id == selectedPageId}"
+                    ng-include=" page.id == selectedPageId && 'currentTab'|| 'otherTab' ">
+            </li>
+
             <script type="text/ng-template" id="currentTab">
                 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                     {{page.name}}<b class="caret"></b>
@@ -14,37 +18,36 @@
                     <li class="menu-item-disabled"><a href="#">Remove share</a></li>
                 </ul>
             </script>
+
             <script type="text/ng-template" id="otherTab">
                 <a href="{{page.id}}">
                     {{page.name}}
                 </a>
             </script>
-            <li ng-repeat="page in pages" ng-class="{active:page.isCurrent, dropdown:page.isCurrent}"
-                ng-include="page.template">
-            </li>
+
             <li id="addPageButton"><a href="#"><i class="icon-plus"></i></a></li>
         </ul>
     </nav>
     <div class="row-fluid">
-        <div class="tab-content">
-            <div ng-repeat="(regionIndex, region) in currentPage.regions" ng-class="currentPage.pageLayoutCode+'_'+regionIndex" class="region regionNonDragging">
+        <div class="tab-content" ng-show="selectedPageId == page.id" ng-repeat="page in pages">
+            <div ng-repeat="(regionIndex, region) in page.regions" ng-class="page.pageLayoutCode+'_'+regionIndex" class="region regionNonDragging">
                 <div ng-repeat="regionWidget in region.regionWidgets">
-                    <div class="widget-wrapper">
+                    <div class="widget-wrapper" ng-controller="WidgetController" ng-init="init(regionWidget.id)">
                         <div class="widget-title-bar widget-title-bar-draggable">
-                            <div class="widget-toolbar-toggle-collapse" title="Collapse/Restore Widget" style="">
-                                <i class="icon-chevron-down"></i>
+                            <div class="widget-toolbar-toggle-collapse" title="Collapse/Restore Widget">
+                                <i ng-class="{'icon-chevron-down':!regionWidget.collapsed, 'icon-chevron-up':regionWidget.collapsed}" ng-click="toggleCollapse()"></i>
                             </div>
                             <div class="widget-title">
                                 {{regionWidget.widgetUrl}}
                             </div>
                             <div class="widget-toolbar ">
                                 <div class="dropdown widget-menu-wrapper" style="">
-                                    <a class="dropdown-toggle">
+                                    <a class="dropdown-toggle" data-toggle="dropdown">
                                         <i class="icon-cog"></i>
                                     </a>
                                     <ul class="dropdown-menu widget-menu">
                                         <li class="">
-                                            <a href="#">
+                                            <a ng-click="showPrefs=true">
                                                 Edit Preferences
                                             </a>
                                         </li>
@@ -81,14 +84,14 @@
                                         </li>
                                     </ul>
                                 </div>
-                            <span class="widget-toolbar-btn widget-toolbar-btn-min" style="display: none;">
+                            <span class="widget-toolbar-btn widget-toolbar-btn-min">
                                 <i class="icon-resize-small"></i>
                             </span>
                             </div>
                         </div>
 
-                        <div class="widget-prefs"></div>
-                        <div class="widget" render-widget="regionWidget.id">
+                        <div class="widget-prefs" ng-show="showPrefs">Edit Prefs Pane</div>
+                        <div class="widget" render-widget="regionWidget.id" ng-hide="regionWidget.collapsed">
 
                         </div>
                     </div>

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/profile.html
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/profile.html?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/profile.html (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/html/profile.html Fri Apr 19 18:09:28 2013
@@ -1,9 +1 @@
-<!DOCTYPE html>
-<html>
-<head>
-    <title></title>
-</head>
-<body>
-
-</body>
-</html>
\ No newline at end of file
+This is the profile page
\ No newline at end of file

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/app.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/app.js?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/app.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/app.js Fri Apr 19 18:09:28 2013
@@ -1,3 +1,4 @@
 angular.module('rave', ['rave.controller', 'rave.directive', 'rave.service', 'rave.routing'])
 
-
+//TODO: drop it!
+rave.api.setContext('/portal/app/');
\ No newline at end of file

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/controllers.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/controllers.js?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/controllers.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/controllers.js Fri Apr 19 18:09:28 2013
@@ -1,40 +1,46 @@
 angular.module('rave.controller', [])
-    .controller('tabsController', ['$scope', 'rave', 'pages', '$routeParams', function ($scope, rave, pages, $routeParams) {
-        $scope.pages;
-        $scope.currentPage;
+    .controller('PortalController', ['$scope', 'rave', 'Pages', '$routeParams', '$q', function ($scope, rave, Pages, $routeParams, $q) {
+        $scope.user;
+        $scope.portalPrefs;
+        $scope.pages = Pages.get('portal', '@self');
+        $scope.selectedPageId = $routeParams.tabId;
 
-        $scope.$on('$routeChangeSuccess', function(oldRoute, newRoute){
-            setCurrentPage(newRoute.params.tabId);
-        });
+        if (_.isUndefined($scope.selectedPageId)) {
+            $scope.pages.then(function (pages) {
+                $scope.selectedPageId = pages[0] && pages[0].id;
+            });
+        }
+        $scope.pages.then(registerWidgetsForPages);
 
-        pages.then(function(pages){
-            $scope.pages = pages;
-            setCurrentPage($routeParams.tabId);
-            registerWidgets();
+        $scope.$on('$routeChangeSuccess', function (oldRoute, newRoute) {
+            $scope.selectedPageId = newRoute.params.tabId;
         });
 
-        function setCurrentPage(pageId) {
-            if(_.isUndefined(pageId)) {
-                pageId = $scope.pages[0].id;
-            }
-            _.each($scope.pages, function(page) {
-                page.template = 'otherTab'
-                page.isCurrent = false;
-                if(page.id == pageId) {
-                    page.isCurrent = true;
-                    page.template = 'currentTab'
-                    $scope.currentPage = page;
-                }
-            })
-        }
-
-        function registerWidgets(){
+        function registerWidgetsForPages(pages) {
             rave.init();
-            var widgets = _.chain($scope.pages).pluck('regions').flatten().pluck('regionWidgets').flatten().value();
+            var widgets = _.chain(pages).pluck('regions').flatten().pluck('regionWidgets').flatten().value();
             var i = 0;
-            _.each(widgets, function(widget){
+            _.each(widgets, function (widget) {
                 widget.metadata = JSON.parse(widget.metadata);
                 rave.registerWidget(widget);
             });
         }
-    }]);
\ No newline at end of file
+    }])
+    .controller('WidgetController', ['$scope', 'rave',
+        function ($scope, rave) {
+            $scope.regionWidget;
+            $scope.showPrefs = false;
+
+            $scope.init = function (regionWidgetId) {
+                $scope.regionWidget = rave.getWidget(regionWidgetId);
+            }
+
+            $scope.toggleCollapse = function () {
+                if ($scope.regionWidget.collapsed) {
+                    $scope.regionWidget.show();
+                } else {
+                    $scope.regionWidget.hide();
+                }
+            }
+        }
+    ]);
\ No newline at end of file

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/services.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/services.js?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/services.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/angular-portal/services.js Fri Apr 19 18:09:28 2013
@@ -1,8 +1,29 @@
-angular.module('rave.service', [])
+angular.module('rave.service', ['ngResource'])
     .value('rave', rave)
-    .value('context')
-    .service('pages', ['$http', function($http){
-        return $http.get('/portal/api/rest/pages/portal/@self').then(function(response){
-            return response.data.Page;
-        });
-    }]);
\ No newline at end of file
+    .service('Pages', ['$http', '$interpolate',
+        function ($http, $interpolate) {
+/*
+            return $http.get('/portal/api/rest/pages/portal/@self').then(function (response) {
+                return response.data.Page;
+            });*/
+
+
+            var urlTemplate = $interpolate('/portal/api/rest/pages/{{context}}/{{identifier}}');
+            var Pages = {};
+
+            Pages.get = function(context, identifier, id) {
+                return $http.get(urlTemplate({context: context, identifier: identifier})).then(function (response) {
+                    return response.data.Page;
+                });
+            }
+
+            return Pages;
+
+
+        }
+    ])
+    .service('settings', ['$resource',
+        function () {
+
+        }
+    ]);
\ No newline at end of file

Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/core/rave_widget.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/core/rave_widget.js?rev=1469977&r1=1469976&r2=1469977&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/core/rave_widget.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/core/rave_widget.js Fri Apr 19 18:09:28 2013
@@ -85,7 +85,7 @@ rave.RegionWidget = (function () {
         this.collapsed = true;
 
         rave.api.rest.saveWidgetCollapsedState({
-            regionWidgetId: this.regionWidgetId,
+            regionWidgetId: this.id,
             collapsed: this.collapsed
         });
     }
@@ -94,7 +94,7 @@ rave.RegionWidget = (function () {
         this.collapsed = false;
 
         rave.api.rest.saveWidgetCollapsedState({
-            regionWidgetId: this.regionWidgetId,
+            regionWidgetId: this.id,
             collapsed: this.collapsed
         });
     }
@@ -106,21 +106,21 @@ rave.RegionWidget = (function () {
         }
 
         rave.api.rpc.removeWidget({
-            regionWidgetId: this.regionWidgetId
+            regionWidgetId: this.id
         });
     }
 
     Widget.prototype.moveToPage = function (toPageId, cb) {
         rave.api.rpc.moveWidgetToPage({
             toPageId: toPageId,
-            regionWidgetId: this.regionWidgetId,
+            regionWidgetId: this.id,
             successCallback: cb
         });
     }
 
     Widget.prototype.moveToRegion = function (fromRegionId, toRegionId, toIndex) {
         rave.api.rpc.moveWidgetToRegion({
-            regionWidgetId: this.regionWidgetId,
+            regionWidgetId: this.id,
             fromRegionId: fromRegionId,
             toRegionId: toRegionId,
             toIndex: toIndex
@@ -129,12 +129,12 @@ rave.RegionWidget = (function () {
 
     Widget.prototype.savePreference = function (name, val) {
         this.userPrefs[name] = val;
-        rave.api.rest.saveWidgetPreference({regionWidgetId: this.regionWidgetId, prefName: name, prefValue: val});
+        rave.api.rest.saveWidgetPreference({regionWidgetId: this.id, prefName: name, prefValue: val});
     }
 
     Widget.prototype.savePreferences = function (updatedPrefs) {
         this.userPrefs = updatedPrefs;
-        rave.api.rest.saveWidgetPreferences({regionWidgetId: this.regionWidgetId, userPrefs: updatedPrefs});
+        rave.api.rest.saveWidgetPreferences({regionWidgetId: this.id, userPrefs: updatedPrefs});
     }