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/08/16 20:56:46 UTC
svn commit: r1514849 - in
/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script:
common/directives/Base.js common/resources/PagesForRenderResource.js
common/resources/index.js common/services/index.js portal/routes.js
Author: erinnp
Date: Fri Aug 16 18:56:46 2013
New Revision: 1514849
URL: http://svn.apache.org/r1514849
Log:
Added comments for clarity
Modified:
rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/directives/Base.js
rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/PagesForRenderResource.js
rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/index.js
rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/services/index.js
rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/portal/routes.js
Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/directives/Base.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/directives/Base.js?rev=1514849&r1=1514848&r2=1514849&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/directives/Base.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/directives/Base.js Fri Aug 16 18:56:46 2013
@@ -17,6 +17,11 @@
* under the License.
*/
+/**
+ * The Base directive looks at the <base href=".."> tag on the angular.jsp page and parses it to establish the
+ * hostedPath of the application. This is available on constants.hostedPath and should be injected to any
+ * service, etc that needs to build a url (see all common resources for example).
+ */
define([], function () {
return [ 'constants',
function (constants) {
Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/PagesForRenderResource.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/PagesForRenderResource.js?rev=1514849&r1=1514848&r2=1514849&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/PagesForRenderResource.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/PagesForRenderResource.js Fri Aug 16 18:56:46 2013
@@ -26,6 +26,15 @@ define(['underscore', 'rave'], function
_get: {method: 'GET'}
});
+ /**
+ * Overwriting the pagesForRender query / get methods to decompose the responses into their subordinate
+ * $resource types. This guarantees that the PagesForRender resource gets us objects on the scope that
+ * we can individually manipulate and update.
+ */
+ /*
+ TODO: One issue with this approach is that currently on a save to a page, the entire page AND all sub-objects
+ are getting posted to the server on $save() - same for regions
+ */
res.query = function (args, onSuccess, onError) {
return res._query.call(null, args).$then(function (res) {
//TODO: check for error
@@ -63,7 +72,6 @@ define(['underscore', 'rave'], function
});
}
-
return res;
}
];
Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/index.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/index.js?rev=1514849&r1=1514848&r2=1514849&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/index.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/resources/index.js Fri Aug 16 18:56:46 2013
@@ -24,6 +24,10 @@ define(['angular', './CategoriesResource
var resources = angular.module('common.resources', ['ngResource', 'common.services'])
+ /**
+ * For all ajax requests, if the request returns json data and has a .data property, return that.
+ * This lets us unwrap our api responses for $resources.
+ */
resources.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.transformResponse.push(function (data, headers) {
if (headers('CONTENT-TYPE') === 'application/json' && data.data) {
Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/services/index.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/services/index.js?rev=1514849&r1=1514848&r2=1514849&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/services/index.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/common/services/index.js Fri Aug 16 18:56:46 2013
@@ -20,6 +20,11 @@
define(['angular', 'common/directives/index'], function (angular) {
var services = angular.module('common.services', ['common.directives']);
+ /**
+ * Establishes the constants.hostedPath that can be injected into any service. Note that constants was made an object
+ * with a hostedPath property so that it is mutable. To contrast, services.constant('hostedPath', '') could never
+ * have its value set.
+ */
services.constant('constants', {
hostedPath: ''
});
Modified: rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/portal/routes.js
URL: http://svn.apache.org/viewvc/rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/portal/routes.js?rev=1514849&r1=1514848&r2=1514849&view=diff
==============================================================================
--- rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/portal/routes.js (original)
+++ rave/branches/angular/rave-portal-resources/src/main/webapp/static/script/portal/routes.js Fri Aug 16 18:56:46 2013
@@ -23,6 +23,12 @@ define(['angular', 'common/resources/ind
router.config(['$routeProvider', '$locationProvider', '$httpProvider',
function ($routeProvider, $locationProvider, $httpProvider) {
+ /**
+ * The resolve functions guarantee that needed data is requested and resolved from the server BEFORE route
+ * change is triggered. Notice that each function checks if the property already exists before triggering
+ * resource request. This is to prevent a new request on every change in navigation - it will only happen
+ * on initial load.
+ */
var resolve = {
pages: ['PagesForRender', '$q', '$rootScope',
function (PagesForRender, $q, $rootScope) {
@@ -61,6 +67,10 @@ define(['angular', 'common/resources/ind
]
}
+ /**
+ * The portal context single page app only supports the following routes: "/" or "/:tabId".
+ * Routing should change as user clicks on page tabs.
+ */
$routeProvider
.when('/', {
resolve: resolve
@@ -74,6 +84,11 @@ define(['angular', 'common/resources/ind
}
]);
+ /**
+ * This guarantees that pages, user (currently authenticated user), and currentPageId are always available on the
+ * root scope - and therefore any child scopes. currentPageId defaults to the pageId of the [0] element in the pages
+ * array.
+ */
router.run(['$route', '$rootScope', function ($route, $rootScope) {
$rootScope.$on('$routeChangeSuccess', function (evt, curr, prev) {
$rootScope.pages = curr.locals.pages;