Skip to content

Commit

Permalink
Merge branch 'testing-images'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonv3 committed Aug 5, 2015
2 parents c16975e + 860d833 commit 662f00e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 26 deletions.
24 changes: 14 additions & 10 deletions app/assets/javascripts/angular-libs/angular.of.stages.service.js
Original file line number Diff line number Diff line change
@@ -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:
// {
Expand Down Expand Up @@ -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 &&
Expand All @@ -52,14 +53,14 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService',
}

var buildStage = function(data, included) {

var stage = data.attributes;
stage.id = data.id;

if (data.relationships.stage_actions.data === undefined ||
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.
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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);
});
Expand All @@ -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) {
Expand Down
27 changes: 16 additions & 11 deletions app/assets/javascripts/angular-libs/guides/guides.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,29 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService',
}

var buildGuide = function(data, included) {
console.log("Building Guide", data, included);
var stages,
user,
crop;
var guide = data.attributes;
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]);
Expand All @@ -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;
};

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/guides/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/styles/components/_alerts.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions app/models/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 662f00e

Please sign in to comment.