From 21ed38929ee7c009e920510921775fb548106501 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Sun, 24 Aug 2014 14:49:09 -0500 Subject: [PATCH 1/8] Added restangular --- applications/default/public/index.html | 2 ++ applications/default/public/js/app.js | 37 ++++++++++++++++++++++++++ bower.json | 3 ++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/applications/default/public/index.html b/applications/default/public/index.html index 4d7814b..3ebd62c 100644 --- a/applications/default/public/index.html +++ b/applications/default/public/index.html @@ -44,6 +44,8 @@ + + diff --git a/applications/default/public/js/app.js b/applications/default/public/js/app.js index 2c7f0c0..0706d1e 100644 --- a/applications/default/public/js/app.js +++ b/applications/default/public/js/app.js @@ -1,7 +1,44 @@ 'use strict'; // Declare app level module which depends on services, directives and filters. +<<<<<<< HEAD angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'angularFileUpload', 'choko.services', 'choko.directives', 'choko.filters', 'choko.controllers']) +======= +angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'restangular', 'angularFileUpload', 'choko.services', 'choko.directives', 'choko.filters']) +>>>>>>> Added restangular .config(['$locationProvider', function($locationProvider) { //$locationProvider.html5Mode(true); +}]) +.config(['RestangularProvider', function(RestangularProvider) { + RestangularProvider.setBaseUrl('/rest'); + + // Add a response intereceptor + RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) { + var extractedData; + + if (operation === "getList") { + var temp = []; + + Object.keys(data.data).forEach(function(name){ + temp.push(data.data[name]) + }); + + extractedData = temp; + } else { + extractedData = data.data; + } + return extractedData; + }); + + RestangularProvider.setResponseExtractor(function(response) { + var newResponse = response; + if (angular.isArray(response)) { + angular.forEach(newResponse, function(value, key) { + newResponse[key].originalElement = angular.copy(value); + }); + } else { + newResponse.originalElement = angular.copy(response); + } + return newResponse; + }); }]); diff --git a/bower.json b/bower.json index 15a5207..13b3e97 100644 --- a/bower.json +++ b/bower.json @@ -10,6 +10,7 @@ "angular-sanitize": "1.2.x", "summernote": "0.5.x", "angular-summernote": "0.2.x", - "ng-file-upload": "1.6.x" + "ng-file-upload": "1.6.x", + "restangular": "~1.4.0" } } From 3c49f6f82ace6e38a3fe862246b6e3293e67bb8e Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 15:40:05 -0500 Subject: [PATCH 2/8] Resolved minor bug. --- applications/default/public/js/app.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/applications/default/public/js/app.js b/applications/default/public/js/app.js index 0706d1e..ecc9911 100644 --- a/applications/default/public/js/app.js +++ b/applications/default/public/js/app.js @@ -1,11 +1,8 @@ 'use strict'; // Declare app level module which depends on services, directives and filters. -<<<<<<< HEAD -angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'angularFileUpload', 'choko.services', 'choko.directives', 'choko.filters', 'choko.controllers']) -======= -angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'restangular', 'angularFileUpload', 'choko.services', 'choko.directives', 'choko.filters']) ->>>>>>> Added restangular + +angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'restangular', 'angularFileUpload', 'choko.services', 'choko.directives', 'choko.filters', 'choko.controllers']) .config(['$locationProvider', function($locationProvider) { //$locationProvider.html5Mode(true); }]) From 47071039af413d7161d7ef7abbf65dd71042f60c Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 19:10:18 -0500 Subject: [PATCH 3/8] Enabled support caching GET requests --- applications/default/public/js/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/default/public/js/app.js b/applications/default/public/js/app.js index ecc9911..042fe53 100644 --- a/applications/default/public/js/app.js +++ b/applications/default/public/js/app.js @@ -9,6 +9,8 @@ angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'r .config(['RestangularProvider', function(RestangularProvider) { RestangularProvider.setBaseUrl('/rest'); + RestangularProvider.setDefaultHttpFields({cache: true}); + // Add a response intereceptor RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) { var extractedData; From 2d443e149772ce6d44ef7b39ec6e1240b02eb328 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 21:18:16 -0500 Subject: [PATCH 4/8] Migrating ViewController for use Restangular. --- applications/default/public/js/controllers.js | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/applications/default/public/js/controllers.js b/applications/default/public/js/controllers.js index 80b68ef..8de5391 100644 --- a/applications/default/public/js/controllers.js +++ b/applications/default/public/js/controllers.js @@ -320,14 +320,18 @@ angular.module('choko.controllers', []) }; }]) - .controller('ViewController', ['$scope', '$location', '$http', 'Choko', - function ($scope, $location, $http, Choko) { + .controller('ViewController', ['$scope', '$location', '$http', 'Choko', 'Restangular', + function ($scope, $location, $http, Choko, Restangular) { + + // Prevente creation of service if no itemType set. + if ($scope.view.itemType) { + // Create a new Service for Itemtype. + var ItemTypeREST = Restangular.service($scope.view.itemType); + } // Handle 'list' type views. if ($scope.view.type === 'list' && $scope.view.itemType) { - var query = { - type: $scope.view.itemType - }; + var query = {}; if ($scope.view.query) { angular.extend(query, $scope.view.query); @@ -335,7 +339,7 @@ angular.module('choko.controllers', []) $scope.items = {}; - Choko.get(query, function(response) { + ItemTypeREST.getList(query).then(function(response) { $scope.items = response; }); @@ -358,11 +362,11 @@ angular.module('choko.controllers', []) if ($scope.view.type === 'item' && $scope.view.itemType) { $scope.data = {}; $scope.view.title = ''; - Choko.get({type: $scope.view.itemType, key: $scope.view.itemKey}, function(response) { + + ItemTypeREST.one($scope.view.itemKey).get().then(function(response) { $scope.data = response; $scope.view.title = response.title; - }, - function(response) { + }, function(response) { // Error. if ($scope.page) { // If it's a page, show error, otherwise fail silently. @@ -376,31 +380,35 @@ angular.module('choko.controllers', []) // Handle 'form' type views. if ($scope.view.type === 'form' && $scope.view.formName) { $scope.data = {}; + var typeForm = 'post'; if ($scope.view.itemType && $scope.view.itemKey) { - Choko.get({type: $scope.view.itemType, key: $scope.view.itemKey}, function(response) { + ItemTypeREST.one($scope.view.itemKey).then(function(response) { $scope.data = response; + typeForm = 'put' }); } $scope.submit = function(url, redirect) { - // Add itemKey to the URL if any. - if ($scope.view.itemKey) { - url += '/' + $scope.view.itemKey; + + var FormREST = null; + + if(!ItemTypeREST){ + FormREST = Restangular.oneUrl('url', url).post('', $scope.data); + } else { + FormREST = typeForm == 'post'? ItemTypeREST.post($scope.data) : ItemTypeREST.put($scope.data); } - $http.post(url, $scope.data) - .success(function(data, status, headers, config) { - $scope.data = data; - delete $scope.errors; - if (redirect) { - $location.path(redirect); - } - }) - .error(function(data, status, headers, config) { - $scope.status = status; - $scope.errors = data.data; - }); + FormREST.then(function(response) { + $scope.data = response; + delete $scope.errors; + if (redirect) { + $location.path(redirect); + } + }, function(response) { + $scope.errors = response.data.data; + $scope.status = response.status; + }); }; Choko.get({type: 'form', key: $scope.view.formName}, function(response) { From 188db7bb45669f732a9fe22ea28753d4a1e9d36a Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 22:05:12 -0500 Subject: [PATCH 5/8] Improving code style. --- applications/default/public/js/app.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/applications/default/public/js/app.js b/applications/default/public/js/app.js index 042fe53..e7e5cc3 100644 --- a/applications/default/public/js/app.js +++ b/applications/default/public/js/app.js @@ -15,15 +15,15 @@ angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'r RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) { var extractedData; - if (operation === "getList") { + if (operation === 'getList') { var temp = []; Object.keys(data.data).forEach(function(name){ - temp.push(data.data[name]) + temp.push(data.data[name]); }); - extractedData = temp; - } else { + } + else { extractedData = data.data; } return extractedData; @@ -31,11 +31,13 @@ angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'r RestangularProvider.setResponseExtractor(function(response) { var newResponse = response; + if (angular.isArray(response)) { angular.forEach(newResponse, function(value, key) { newResponse[key].originalElement = angular.copy(value); }); - } else { + } + else { newResponse.originalElement = angular.copy(response); } return newResponse; From e6cbec5dd77dde12fb269a264e7e1b9c9739cabd Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 22:59:56 -0500 Subject: [PATCH 6/8] More improvements style code. --- applications/default/public/js/controllers.js | 21 ++++++++++--------- bower.json | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/applications/default/public/js/controllers.js b/applications/default/public/js/controllers.js index 8de5391..a129e8f 100644 --- a/applications/default/public/js/controllers.js +++ b/applications/default/public/js/controllers.js @@ -326,7 +326,7 @@ angular.module('choko.controllers', []) // Prevente creation of service if no itemType set. if ($scope.view.itemType) { // Create a new Service for Itemtype. - var ItemTypeREST = Restangular.service($scope.view.itemType); + var itemTypeREST = Restangular.service($scope.view.itemType); } // Handle 'list' type views. @@ -339,7 +339,7 @@ angular.module('choko.controllers', []) $scope.items = {}; - ItemTypeREST.getList(query).then(function(response) { + itemTypeREST.getList(query).then(function(response) { $scope.items = response; }); @@ -363,7 +363,7 @@ angular.module('choko.controllers', []) $scope.data = {}; $scope.view.title = ''; - ItemTypeREST.one($scope.view.itemKey).get().then(function(response) { + itemTypeREST.one($scope.view.itemKey).get().then(function(response) { $scope.data = response; $scope.view.title = response.title; }, function(response) { @@ -383,7 +383,7 @@ angular.module('choko.controllers', []) var typeForm = 'post'; if ($scope.view.itemType && $scope.view.itemKey) { - ItemTypeREST.one($scope.view.itemKey).then(function(response) { + itemTypeREST.one($scope.view.itemKey).then(function(response) { $scope.data = response; typeForm = 'put' }); @@ -391,15 +391,16 @@ angular.module('choko.controllers', []) $scope.submit = function(url, redirect) { - var FormREST = null; + var formREST = null; - if(!ItemTypeREST){ - FormREST = Restangular.oneUrl('url', url).post('', $scope.data); - } else { - FormREST = typeForm == 'post'? ItemTypeREST.post($scope.data) : ItemTypeREST.put($scope.data); + if(!itemTypeREST) { + formREST = Restangular.oneUrl('url', url).post('', $scope.data); + } + else { + formREST = typeForm == 'post'? itemTypeREST.post($scope.data) : itemTypeREST.put($scope.data); } - FormREST.then(function(response) { + formREST.then(function(response) { $scope.data = response; delete $scope.errors; if (redirect) { diff --git a/bower.json b/bower.json index 13b3e97..dd20be2 100644 --- a/bower.json +++ b/bower.json @@ -11,6 +11,6 @@ "summernote": "0.5.x", "angular-summernote": "0.2.x", "ng-file-upload": "1.6.x", - "restangular": "~1.4.0" + "restangular": "1.4.x" } } From bfa5b0ae5ee3dd7bfeedd8a5917464781857cbb6 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 27 Aug 2014 23:15:55 -0500 Subject: [PATCH 7/8] Disable caching functionality. --- applications/default/public/js/app.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/applications/default/public/js/app.js b/applications/default/public/js/app.js index e7e5cc3..c6640eb 100644 --- a/applications/default/public/js/app.js +++ b/applications/default/public/js/app.js @@ -9,7 +9,10 @@ angular.module('choko', ['ngRoute', 'ngResource', 'ngSanitize', 'summernote', 'r .config(['RestangularProvider', function(RestangularProvider) { RestangularProvider.setBaseUrl('/rest'); - RestangularProvider.setDefaultHttpFields({cache: true}); + // @todo: We need improve the caching functionality. + // The items list not change after add an ítem, because + // he get the items list from the caché. + RestangularProvider.setDefaultHttpFields({cache: false}); // Add a response intereceptor RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) { From 240276dacdd5ba4d28601d1c49513675c08f2661 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Thu, 16 Apr 2015 18:49:28 -0500 Subject: [PATCH 8/8] Added missing file commited --- .../user/forms/edit-account.form.json | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 applications/default/extensions/user/forms/edit-account.form.json diff --git a/applications/default/extensions/user/forms/edit-account.form.json b/applications/default/extensions/user/forms/edit-account.form.json new file mode 100644 index 0000000..2f93ffd --- /dev/null +++ b/applications/default/extensions/user/forms/edit-account.form.json @@ -0,0 +1,20 @@ +{ + "title": "Edit account", + "description": "Edit your account.", + "elements": [ + { + "name": "email", + "title": "Email address", + "type": "email", + "required": true, + "weight": -10 + }, + { + "name": "submit", + "title": "Save", + "type": "submit", + "url": "/settings/edit-account-submit/[:username|user]", + "weight": 15 + } + ] +}