From f97c2ab3d60ecfe70c818fcf8b8b3c05cff953f1 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 14:46:56 -0800 Subject: [PATCH 1/8] Getting more details from images errors --- .../angular-libs/angular.of.stages.service.js | 17 ++++++++++------- app/assets/javascripts/guides/new.js | 8 ++++---- .../styles/components/_alerts.css.scss | 6 ++++++ app/models/picture.rb | 9 +++++++-- config/environments/development.rb | 10 ++++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index fe1241d1a..806a46b98 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -1,5 +1,5 @@ -openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', - function stageService($http, $q, alertsService) { +openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', + function stageService($http, $log, $q, alertsService) { // Should return Stage model: // { @@ -71,11 +71,13 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', mappedIds = data.relationships.pictures.data.map(function (pic) { return pic.id; }) - stage.pictures = included.filter(function (pic) { - return mappedIds.indexOf(pic.id) !== -1 && pic.type === 'pictures'; - }).map(function(pic) { - return pic.attributes; - }) + if (included) { + stage.pictures = included.filter(function (pic) { + return mappedIds.indexOf(pic.id) !== -1 && pic.type === 'pictures'; + }).map(function(pic) { + return pic.attributes; + }) + } } return stage } @@ -136,6 +138,7 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', .success(function (response) { resolve(buildStage(response.data)); }).error(function (response, code) { + $log.error(response); reject(); alertsService.pushToAlerts(response, code); }); diff --git a/app/assets/javascripts/guides/new.js b/app/assets/javascripts/guides/new.js index 608650bb8..2928868cd 100644 --- a/app/assets/javascripts/guides/new.js +++ b/app/assets/javascripts/guides/new.js @@ -387,9 +387,9 @@ openFarmApp.controller('newGuideCtrl', ['$scope', '$http', '$q', console.log('updating stage'); stageService.updateStageWithPromise(stage.id, {'data': data}) .then(function(stage){ - stage.sent = true; - $scope.sending--; - $scope.checkNumberUpdated(); + stage.sent = true; + $scope.sending--; + $scope.checkNumberUpdated(); }); } else if (stage.exists){ @@ -412,7 +412,7 @@ openFarmApp.controller('newGuideCtrl', ['$scope', '$http', '$q', if ($scope.sending === 0){ localStorageService.remove('guide'); $scope.startedSending = false; - window.location.href = '/guides/' + $scope.newGuide.id + '/'; + // window.location.href = '/guides/' + $scope.newGuide.id + '/'; } }; diff --git a/app/assets/stylesheets/styles/components/_alerts.css.scss b/app/assets/stylesheets/styles/components/_alerts.css.scss index e37f00aae..8cd3f2025 100644 --- a/app/assets/stylesheets/styles/components/_alerts.css.scss +++ b/app/assets/stylesheets/styles/components/_alerts.css.scss @@ -6,8 +6,14 @@ transition: top .5s; z-index: 10; box-shadow: 0 0 1rem rgba(0, 0, 0, 0.25); + + .close { + top: 18px; + } } + + .home-alert-wrapper{ height: 0; } diff --git a/app/models/picture.rb b/app/models/picture.rb index 7332f7383..69d4c19cf 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -17,9 +17,14 @@ class Picture # SEE: http://stackoverflow.com/a/23141483/1064917 class << self - def from_url(url, parent) + def from_url(file_location, parent) pic = new(photographic: parent) - pic.attachment = open(url) + puts "file location #{file_location}" + if Paperclip::Attachment.default_options[:storage].to_s != 'filesystem' + pic.attachment = open(file_location) + else + pic.attachment = file_location + end pic.save! pic end diff --git a/config/environments/development.rb b/config/environments/development.rb index ff98daace..51e0a7b0e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,4 +13,14 @@ Crop.reindex Guide.reindex end + + # options = { storage: :s3, + # s3_protocol: :https, + # path: '/:rails_env/media/:class/:attachment/:id.:extension', + # s3_credentials: { bucket: ENV['S3_BUCKET_NAME'], + # s3_protocol: :https, + # access_key_id: ENV['SERVER_S3_ACCESS_KEY'], + # secret_access_key: ENV['SERVER_S3_SECRET_KEY'] } } + + # Paperclip::Attachment.default_options.merge!(options) end From 2875a889bceff07ab317b6433f767872042ea8cd Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 14:56:42 -0800 Subject: [PATCH 2/8] Add debug statements --- .../angular-libs/angular.of.stages.service.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index 806a46b98..a2447af28 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -52,7 +52,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', } var buildStage = function(data, included) { - + $log.debug('building stage', data, included); var stage = data.attributes; stage.id = data.id; @@ -66,9 +66,11 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', if (data.relationships.pictures.data === undefined && data.relationships.pictures.data.length === 0) { + $log.debug('no pictures'); stage.pictures = []; } else { - mappedIds = data.relationships.pictures.data.map(function (pic) { + $log.debug('some pictures'); + var mappedIds = data.relationships.pictures.data.map(function (pic) { return pic.id; }) if (included) { @@ -77,8 +79,10 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', }).map(function(pic) { return pic.attributes; }) + $log.debug('has included'); } } + $log.debug('exiting stage building', stage) return stage } @@ -138,7 +142,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', .success(function (response) { resolve(buildStage(response.data)); }).error(function (response, code) { - $log.error(response); + $log.error("error when updating a stage", response, code); reject(); alertsService.pushToAlerts(response, code); }); From f196099a28f9360ff39df1b721f01d9638d0b8c3 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 15:31:18 -0800 Subject: [PATCH 3/8] Change debug messages to error messages --- .../angular-libs/angular.of.stages.service.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index a2447af28..6eeeec160 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -52,7 +52,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', } var buildStage = function(data, included) { - $log.debug('building stage', data, included); + $log.error('building stage', data, included); var stage = data.attributes; stage.id = data.id; @@ -66,10 +66,10 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', if (data.relationships.pictures.data === undefined && data.relationships.pictures.data.length === 0) { - $log.debug('no pictures'); + $log.error('no pictures'); stage.pictures = []; } else { - $log.debug('some pictures'); + $log.error('some pictures'); var mappedIds = data.relationships.pictures.data.map(function (pic) { return pic.id; }) @@ -79,10 +79,10 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', }).map(function(pic) { return pic.attributes; }) - $log.debug('has included'); + $log.error('has included'); } } - $log.debug('exiting stage building', stage) + $log.error('exiting stage building', stage) return stage } From 406e7376514db0de5fd07e5beb50b59c70767980 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 15:36:03 -0800 Subject: [PATCH 4/8] Re-add the redirect --- .../javascripts/angular-libs/angular.of.stages.service.js | 5 ----- app/assets/javascripts/guides/new.js | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index 6eeeec160..1650b0c7f 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -52,7 +52,6 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', } var buildStage = function(data, included) { - $log.error('building stage', data, included); var stage = data.attributes; stage.id = data.id; @@ -66,10 +65,8 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', if (data.relationships.pictures.data === undefined && data.relationships.pictures.data.length === 0) { - $log.error('no pictures'); stage.pictures = []; } else { - $log.error('some pictures'); var mappedIds = data.relationships.pictures.data.map(function (pic) { return pic.id; }) @@ -79,10 +76,8 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', }).map(function(pic) { return pic.attributes; }) - $log.error('has included'); } } - $log.error('exiting stage building', stage) return stage } diff --git a/app/assets/javascripts/guides/new.js b/app/assets/javascripts/guides/new.js index 2928868cd..18d7ff46b 100644 --- a/app/assets/javascripts/guides/new.js +++ b/app/assets/javascripts/guides/new.js @@ -412,7 +412,7 @@ openFarmApp.controller('newGuideCtrl', ['$scope', '$http', '$q', if ($scope.sending === 0){ localStorageService.remove('guide'); $scope.startedSending = false; - // window.location.href = '/guides/' + $scope.newGuide.id + '/'; + window.location.href = '/guides/' + $scope.newGuide.id + '/'; } }; From c565f8f746ceef0c33ce223408c2825e9822c20b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 16:09:05 -0800 Subject: [PATCH 5/8] Make sure stage_actions exists --- app/assets/javascripts/angular-libs/angular.of.stages.service.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index 1650b0c7f..f8d6d710b 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -27,6 +27,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', } else { // TODO: we'll need to go fetch these from the // server. + stage.stage_actions = []; } if (data.relationships.pictures.data === undefined && From 9421b8fda796dfd467936412684ef2d36174f139 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 16:16:33 -0800 Subject: [PATCH 6/8] add some debugging things --- .../angular-libs/guides/guides.service.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/angular-libs/guides/guides.service.js b/app/assets/javascripts/angular-libs/guides/guides.service.js index 53973708b..ea293bdd7 100644 --- a/app/assets/javascripts/angular-libs/guides/guides.service.js +++ b/app/assets/javascripts/angular-libs/guides/guides.service.js @@ -50,6 +50,7 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService', } var buildGuide = function(data, included) { + console.log("Building Guide", data, included); var stages, user, crop; @@ -57,19 +58,21 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService', guide.id = data.id; guide.relationships = data.relationships; guide.links = data.links; - stages = included.filter(function(obj) { - return obj.type === 'stages'; - }).map(function(stage) { - return stageService.utilities.buildStage(stage, included); - }); + if (included) { + stages = included.filter(function(obj) { + return obj.type === 'stages'; + }).map(function(stage) { + return stageService.utilities.buildStage(stage, included); + }); - user = included.filter(function(obj) { - return obj.type === 'users'; - }); + user = included.filter(function(obj) { + return obj.type === 'users'; + }); - crop = included.filter(function(obj) { - return obj.type === 'crops'; - }); + crop = included.filter(function(obj) { + return obj.type === 'crops'; + }); + } if (user !== undefined && user.length > 0) { guide.user = userService.utilities.buildUser(user[0]); @@ -78,6 +81,7 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService', guide.crop = cropService.utilities.buildCrop(crop[0]); } guide.stages = stages; + console.log("Built Guide", guide); return guide; }; From 711c1a001a31914c0072fcb48c902f70fa59ca49 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 16:32:51 -0800 Subject: [PATCH 7/8] Another update --- app/assets/javascripts/angular-libs/angular.of.stages.service.js | 1 + app/assets/javascripts/angular-libs/guides/guides.service.js | 1 + 2 files changed, 2 insertions(+) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index f8d6d710b..7c6306b7d 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -60,6 +60,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', data.relationships.stage_actions.data.length === 0) { stage.stage_actions = []; } else { + stage.stage_actions = []; // TODO: we'll need to go fetch these from the // server. } diff --git a/app/assets/javascripts/angular-libs/guides/guides.service.js b/app/assets/javascripts/angular-libs/guides/guides.service.js index ea293bdd7..d7b58d3fc 100644 --- a/app/assets/javascripts/angular-libs/guides/guides.service.js +++ b/app/assets/javascripts/angular-libs/guides/guides.service.js @@ -147,6 +147,7 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService', if (guideId !== "" && guideId !== "new") { $http.get('/api/v1/guides/' + guideId) .success(function (response) { + console.log('getting guide'); resolve(buildGuide(response.data, response.included)); }).error(function (response, code) { alertsService.pushToAlerts(response.errors, code); From 860d8335dd8dbce6418b7360446f29dcba3fd22f Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 4 Aug 2015 16:38:44 -0800 Subject: [PATCH 8/8] Remove params from delete stage --- .../javascripts/angular-libs/angular.of.stages.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/angular-libs/angular.of.stages.service.js b/app/assets/javascripts/angular-libs/angular.of.stages.service.js index 7c6306b7d..6c9507d80 100644 --- a/app/assets/javascripts/angular-libs/angular.of.stages.service.js +++ b/app/assets/javascripts/angular-libs/angular.of.stages.service.js @@ -158,7 +158,7 @@ openFarmModule.factory('stageService', ['$http', '$log', '$q', 'alertsService', var deleteStageWithPromise = function(stageId) { return $q(function (resolve, reject) { - $http.delete('/api/v1/stages/' + stageId, params) + $http.delete('/api/v1/stages/' + stageId + '/') .success(function (response) { resolve(); }).error(function (response, code) {