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..6c9507d80 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: // { @@ -27,6 +27,7 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', } else { // TODO: we'll need to go fetch these from the // server. + stage.stage_actions = []; } if (data.relationships.pictures.data === undefined && @@ -52,7 +53,6 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', } var buildStage = function(data, included) { - var stage = data.attributes; stage.id = data.id; @@ -60,6 +60,7 @@ openFarmModule.factory('stageService', ['$http', '$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. } @@ -68,14 +69,16 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', data.relationships.pictures.data.length === 0) { stage.pictures = []; } else { - mappedIds = data.relationships.pictures.data.map(function (pic) { + var 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 +139,7 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService', .success(function (response) { resolve(buildStage(response.data)); }).error(function (response, code) { + $log.error("error when updating a stage", response, code); reject(); alertsService.pushToAlerts(response, code); }); @@ -154,7 +158,7 @@ openFarmModule.factory('stageService', ['$http', '$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) { diff --git a/app/assets/javascripts/angular-libs/guides/guides.service.js b/app/assets/javascripts/angular-libs/guides/guides.service.js index 53973708b..d7b58d3fc 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; }; @@ -143,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); diff --git a/app/assets/javascripts/guides/new.js b/app/assets/javascripts/guides/new.js index 608650bb8..18d7ff46b 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){ 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