Skip to content

Commit

Permalink
Merge pull request #675 from simonv3/small-fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
simonv3 committed Aug 2, 2015
2 parents 7c5dcc1 + 27d7990 commit c16975e
Show file tree
Hide file tree
Showing 44 changed files with 4,285 additions and 385 deletions.
18 changes: 16 additions & 2 deletions app/assets/javascripts/angular-libs/angular.of.crops.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,22 @@ openFarmModule.factory('cropService', ['$http', '$q', '$log', 'alertsService',
});
}

var createCropWithPromise = function(cropObject) {
var url = '/api/v1/crops/';
return $q(function (resolve, reject) {
$http.post(url, buildParams(cropObject))
.success(function(response) {
resolve(buildCrop(response.data, response.included))
})
.error(function(response) {
alertsService.pushToAlerts(response.errors);
reject();
})
})
}

var updateCrop = function(cropId, cropObject, callback){
var url = '/api/v1/crops/' + cropId + '/';
$log.debug(url);
$http.put(url, buildParams(cropObject))
.success(function (response) {
return callback (true, buildCrop(response.data, response.included));
Expand All @@ -89,6 +102,7 @@ openFarmModule.factory('cropService', ['$http', '$q', '$log', 'alertsService',
},
'getCrop': getCrop,
'getCropWithPromise': getCropWithPromise,
'updateCrop': updateCrop
'updateCrop': updateCrop,
'createCropWithPromise': createCropWithPromise
};
}]);
34 changes: 23 additions & 11 deletions app/assets/javascripts/angular-libs/angular.of.directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ openFarmModule.directive('markdown', ['$sanitize',
};
}]);

openFarmModule.directive('loader', ['$rootScope',
function loader($rootScope) {
return {
restrict: 'A',
link: function () {
$rootScope.ofPageLoading = true;
}
};
}]);

openFarmModule.directive('location', [
function location() {
var geocoder = new google.maps.Geocoder();
Expand Down Expand Up @@ -145,17 +155,19 @@ openFarmModule.directive('alerts', ['$timeout',
}
});
scope.$watch('alerts.length', function() {
scope.alerts.forEach(function(alert, index) {
$timeout(function() {
if (index > 0) {
var height = element[0].children[index - 1].offsetHeight;
var top = scope.alerts[index - 1].top;
alert.top = height + top + 18;
} else {
alert.top = 64;
}
}, 500)
})
if (scope.alerts !== undefined) {
scope.alerts.forEach(function(alert, index) {
$timeout(function() {
if (index > 0) {
var height = element[0].children[index - 1].offsetHeight;
var top = scope.alerts[index - 1].top;
alert.top = height + top + 18;
} else {
alert.top = 64;
}
}, 200)
})
}
});
}],
templateUrl:'/assets/templates/angular.of.alerts.template.html'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ openFarmModule.factory('gardenService', ['$http','alertsService',
}
})
.error(function (response, code){
console.log(response);
alertsService.pushToAlerts(response.errors, code)
if (callback){
return callback(false, response, code);
Expand Down Expand Up @@ -255,7 +254,6 @@ openFarmModule.directive('addToGardens', ['$rootScope', 'gardenService',
function(success, response, code) {
if(success) {
scope.gardens = response;
console.log(scope.gardens);
scope.gardens.forEach(function(garden) {
var gardenCropCropIds = garden.garden_crops.map(
function(gc) {
Expand All @@ -265,7 +263,6 @@ openFarmModule.directive('addToGardens', ['$rootScope', 'gardenService',
return gc.crop.id;
}
})
console.log(gardenCropCropIds);
if (gardenCropCropIds.indexOf(scope.cropObject.id) !== -1) {
garden.added = true;
}
Expand Down
23 changes: 20 additions & 3 deletions app/assets/javascripts/angular-libs/angular.of.stages.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService',
// }

var buildStageWithPromise = function(data, included) {
return $q( function (resolve, reject) {
return $q(function (resolve, reject) {
var stage = data.attributes;

// The toExecute array gathers all the $q promises
Expand Down Expand Up @@ -68,13 +68,29 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService',
data.relationships.pictures.data.length === 0) {
stage.pictures = [];
} else {
// Figure this out.
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;
})
}
return stage
}

var getStageWithPromise = function(id) {
return $q(function (resolve, reject) {
$http.get('/api/v1/stages/' + stage.id + '/pictures')
.success(function(pictures) {
resolve(pictures.data);
})
});
}

var getPictures = function(stage) {
return $q( function (resolve, reject) {
return $q(function (resolve, reject) {
$http.get('/api/v1/stages/' + stage.id + '/pictures')
.success(function(pictures) {
resolve(pictures.data);
Expand Down Expand Up @@ -154,6 +170,7 @@ openFarmModule.factory('stageService', ['$http', '$q', 'alertsService',
'buildStage': buildStage,
'buildStageWithPromise': buildStageWithPromise
},
'getStageWithPromise': getStageWithPromise,
'createStageWithPromise': createStageWithPromise,
'updateStageWithPromise': updateStageWithPromise,
'deleteStageWithPromise': deleteStageWithPromise,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ openFarmApp.directive('stageButtons', ['$rootScope', '$location',
$scope.cancelUrl = $attrs.cancelUrl || '/';
$scope.backText = $attrs.backText || undefined;

$scope.previousStep = $scope.$parent.previousStep;
$scope.nextStep = $scope.nextFunction || $scope.$parent.nextStep;
// $scope.previousStep = $scope.previousStep;


$scope.switchToStep = function(step){
$rootScope.step = step;
Expand All @@ -45,14 +45,14 @@ openFarmApp.directive('stageButtons', ['$rootScope', '$location',
window.scrollTo($('.guides').scrollTop(), 0);
}

$scope.nextStep = function(){
if ($rootScope.step === 3){
$scope.newGuide.hasEditedStages = true;
}
$rootScope.step += 1;
$location.hash($rootScope.step);
scrollToTop();
};
// $scope.nextStep = function(){
// if ($rootScope.step === 3){
// $scope.newGuide.hasEditedStages = true;
// }
// $rootScope.step += 1;
// $location.hash($rootScope.step);
// scrollToTop();
// };

$scope.previousStep = function(){
$rootScope.step -= 1;
Expand All @@ -66,10 +66,16 @@ openFarmApp.directive('stageButtons', ['$rootScope', '$location',
}

$scope.nextStep = function(){
// if ($rootScope.step === 3){
// $scope.newGuide.hasEditedStages = true;
// }
$rootScope.step += 1;
$location.hash($rootScope.step);
scrollToTop();
}

$scope.nextStep = $scope.nextFunction || $scope.nextStep;

}],
templateUrl: '/assets/templates/_stage_buttons.html'
};
Expand Down
39 changes: 36 additions & 3 deletions app/assets/javascripts/angular-libs/guides/guides.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService',
var blankGuide = buildBlankGuide(null, [], blankPractices);
var truthy = (JSON.stringify(blankGuide) === JSON.stringify(guide) &&
blankGuide.crop === null);
console.log(truthy)
return truthy;
}

Expand All @@ -61,7 +60,7 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService',
stages = included.filter(function(obj) {
return obj.type === 'stages';
}).map(function(stage) {
return stageService.utilities.buildStage(stage);
return stageService.utilities.buildStage(stage, included);
});

user = included.filter(function(obj) {
Expand All @@ -80,7 +79,41 @@ openFarmModule.factory('guideService', ['$http', '$q', 'alertsService',
}
guide.stages = stages;
return guide;
}
};

// var buildGuideWithPromise = function(data, included) {
// return $q(function (resolve, reject) {
// 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.buildStageWithPromise(stage);
// });

// user = included.filter(function(obj) {
// return obj.type === 'users';
// });

// crop = included.filter(function(obj) {
// return obj.type === 'crops';
// });

// if (user !== undefined && user.length > 0) {
// guide.user = userService.utilities.buildUser(user[0]);
// }
// if (crop !== undefined && crop.length > 0) {
// guide.crop = cropService.utilities.buildCrop(crop[0]);
// }
// guide.stages = stages;
// return guide;
// })
// }

// Builds params according to JSON-API from the
// front end Guide model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ openFarmApp.directive('guidesActions', ['$http', '$modal', 'defaultService',
controller: ['$scope', '$modalInstance', 'stage',
'actionOptions',
function ($scope, $modalInstance, stage, actionOptions) {
console.log(stage);
$scope.actionOptions = actionOptions;
$scope.existingActions = stage.stage_action_options || [];

Expand Down
10 changes: 7 additions & 3 deletions app/assets/javascripts/angular-libs/ngs3upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ angular.module('ngS3upload.directives', []).
// Bind the button click event
var button = angular.element(element.children()[0]),
file = angular.element(element.find("input")[0]);
// element.bind('click', function (e) {
// file[0].click();
// });
element.children().on('dragover', function(){
element.addClass('dragging');
});
element.on('dragleave', function(){
element.removeClass('dragging');
})

scope.$watch('s3UploadExistingPictures', function(){
var objType = Object.prototype.toString.call(
Expand Down Expand Up @@ -263,6 +266,7 @@ angular.module('ngS3upload.directives', []).
};

element.bind('change', function (nVal) {
element.removeClass('dragging');
if (opts.submitOnChange) {
uploadFile();
}
Expand Down
Loading

0 comments on commit c16975e

Please sign in to comment.