Skip to content

Commit

Permalink
Merge pull request #261 from simonv3/gardens
Browse files Browse the repository at this point in the history
Start laying the groundwork for the Garden Model
  • Loading branch information
RickCarlino committed Oct 23, 2014
2 parents ce0ee31 + 8478cbb commit 0f01455
Show file tree
Hide file tree
Showing 38 changed files with 490 additions and 128 deletions.
1 change: 1 addition & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ InlineComment:
Enabled: false
java_script:
enabled: true
config_file: config/javascript.json
coffee_script:
enabled: true
84 changes: 70 additions & 14 deletions app/assets/javascripts/angular-libs/angular.openfarm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
var openFarmModule = angular.module('openFarmModule', ['ngSanitize']);
var openFarmApp = angular.module('openFarmApp', [
'mm.foundation',
'ng-rails-csrf',
'ngS3upload',
'openFarmModule',
]);

var openFarmModule = angular.module('openFarmModule', [
'ngSanitize'
]);

openFarmModule.factory('guideService', ['$http',
function guideService($http) {
Expand All @@ -11,7 +20,7 @@ openFarmModule.factory('guideService', ['$http',
}).success(function (response) {
return callback (true, response.guide);
}).error(function (response, code) {
return callback(false, response, code)
return callback(false, response, code);
});
};
return {
Expand All @@ -30,7 +39,7 @@ openFarmModule.factory('userService', ['$http',
}).success(function (response) {
return callback (true, response.user);
}).error(function (response, code) {
return callback(false, response, code)
return callback(false, response, code);
});
};
return {
Expand All @@ -42,19 +51,66 @@ openFarmModule.directive('markdown', ['$sanitize',
function markdown($sanitize) {
var converter = new Showdown.converter();
return {
restrict: 'A',
link: function (scope, element, attrs) {
function renderMarkdown() {
var htmlText = converter.makeHtml(scope.$eval(attrs.markdown) || '');
element.html($sanitize(htmlText));
}
scope.$watch(attrs.markdown, function(){
renderMarkdown();
});
renderMarkdown();
restrict: 'A',
link: function (scope, element, attrs) {
function renderMarkdown() {
var htmlText = converter.makeHtml(scope.$eval(attrs.markdown) || '');
element.html($sanitize(htmlText));
}
}
scope.$watch(attrs.markdown, function(){
renderMarkdown();
});
renderMarkdown();
}
};
}]);

openFarmModule.directive('location', [
function location() {
var geocoder = new google.maps.Geocoder();
return {
restrict: 'A',
require: '?ngModel',
scope: true,
controller: ['$scope', '$element', '$attrs',
function ($scope, $element, $attrs) {
$scope.loadingText = $attrs.loadingText;
$scope.getLocation = function(val) {
if (geocoder) {
geocoder.geocode({ 'address': val }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var addresses = [];
angular.forEach(results, function(item){
addresses.push(item.formatted_address);
});
$scope.addresses = addresses;
}
else {
console.log("Geocoding failed: " + status);
}
});
}
};

$scope.addresses = [];
}],
template: '<input type="text"'+
'ng-model="location"'+
'autocomplete="off"'+
'id="location"'+
'placeholder="Ex: Hanoi, Portland, California"'+
'typeahead="address for address in addresses"'+
'ng-change="getLocation(location)"'+
'typeahead-min-length="3"'+
'typeahead-loading="loadingLocations"'+
'typeahead-wait-ms="555"'+
'name="location">'+
'<i ng-show="loadingLocations" '+
'class="fa fa-refresh" ng-bind="loadingText"></i>',
};
}]);





5 changes: 2 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//= require foundation/foundation.topbar
//= require foundation/mm-foundation-0.3.0.js
//= require foundation/mm-foundation-tpls-0.3.0.js
//= require_tree ./guides
//= require delete_me_later


Expand Down Expand Up @@ -56,6 +55,6 @@ var getUrlVar = function(key) {
};

var getIDFromURL = function(key) {
var result = new RegExp(key + "/([0-9a-f]*)", "i").exec(window.location.pathname);
var result = new RegExp(key + "/([0-9a-zA-Z\-]*)", "i").exec(window.location.pathname);
return result && unescape(result[1]) || "";
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3027,7 +3027,6 @@ angular.module('mm.foundation.typeahead', ['mm.foundation.position', 'mm.foundat
var getMatchesAsync = function(inputValue) {
var locals = {$viewValue: inputValue};
isLoadingSetter(originalScope, true);
console.log(originalScope.loadingCrops);
$q.when(parserResult.source(originalScope, locals)).then(function(matches) {

//it might happen that several async queries were in progress if a user were typing fast
Expand Down
Empty file.
21 changes: 11 additions & 10 deletions app/assets/javascripts/guides/edit.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var editGuidesApp = angular.module('editGuidesApp', [
'mm.foundation',
'ngS3upload',
'ng-rails-csrf',
'openFarmModule'
]);
// var editGuidesApp = angular.module('editGuidesApp', [
// 'mm.foundation',
// 'ngS3upload',
// 'ng-rails-csrf',
// 'openFarmModule'
// ]);

editGuidesApp.controller('editGuideCtrl', ['$scope', '$http', 'guideService',
function editGuidesApp($scope, $http, guideService) {
openFarmApp.controller('editGuideCtrl', ['$scope', '$http', 'guideService',
function editGuideCtrl($scope, $http, guideService) {
// setting this to true temporarily because
// other wise the ajax loader doesn't load
$scope.saving = true;

$scope.guide_id = getIDFromURL("guides");
$scope.guide_id = getIDFromURL("guides") || GUIDE_ID;
console.log($scope.guide_id);

$scope.alerts = [];

Expand Down Expand Up @@ -236,7 +237,7 @@ editGuidesApp.controller('editGuideCtrl', ['$scope', '$http', 'guideService',
};
}]);

editGuidesApp.directive('focusMe', function($timeout, $parse) {
openFarmApp.directive('focusMe', function($timeout, $parse) {
return {
//scope: true, // optionally create a child scope
link: function(scope, element, attrs) {
Expand Down
54 changes: 13 additions & 41 deletions app/assets/javascripts/guides/new.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
var guidesApp = angular.module('guidesApp', [
'mm.foundation',
'ng-rails-csrf'
]);

guidesApp.controller('newGuideCtrl', ['$scope', '$http',
function guidesApp($scope, $http, $location) {
openFarmApp.controller('newGuideCtrl', ['$scope', '$http',
function newGuideCtrl($scope, $http) {
$scope.alerts = [];
$scope.crops = [];
$scope.step = 1;
Expand All @@ -20,7 +15,6 @@ guidesApp.controller('newGuideCtrl', ['$scope', '$http',
if (getUrlVar("crop_id")){
$http.get('/api/crops/' + getUrlVar("crop_id"))
.success(function(r){
console.log(r);
$scope.new_guide.crop = r.crop;
$scope.query = r.crop.name;
})
Expand All @@ -37,7 +31,7 @@ guidesApp.controller('newGuideCtrl', ['$scope', '$http',

$scope.$watch('loadingCrops', function(){
// console.log($scope.loadingCrops);
})
});

//Typeahead search for crops
$scope.search = function () {
Expand Down Expand Up @@ -74,22 +68,23 @@ guidesApp.controller('newGuideCtrl', ['$scope', '$http',

$scope.createCrop = function(){
window.location.href = '/crops/new/?name=' + $scope.query;
}
};

$scope.nextStep = function(){
$scope.step += 1;
}
};

$scope.previousStep = function(){
$scope.step -= 1;
}
};

$scope.submitForm = function () {
var params = {
name: $scope.new_guide.name,
crop_id: $scope.new_guide.crop._id,
overview: $scope.new_guide.overview || null,
location: $scope.new_guide.location || null
}
name: $scope.new_guide.name,
crop_id: $scope.new_guide.crop._id,
overview: $scope.new_guide.overview || null,
location: $scope.new_guide.location || null
};
$http.post('/api/guides/', params)
.success(function (r) {
// console.log(r);
Expand All @@ -104,33 +99,10 @@ guidesApp.controller('newGuideCtrl', ['$scope', '$http',
});
};

var geocoder = new google.maps.Geocoder();

// Any function returning a promise object can be used to load values asynchronously
$scope.getLocation = function(val) {
console.log('val', val);
if (geocoder) {
geocoder.geocode({ 'address': val }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var addresses = [];
angular.forEach(results, function(item){
addresses.push(item.formatted_address);
})
console.log('addresses');
$scope.addresses = addresses;
}
else {
console.log("Geocoding failed: " + status);
}

});
}
};

$scope.cancel = function(path){
window.location.href = path || '/';
}


};
}]);

19 changes: 6 additions & 13 deletions app/assets/javascripts/guides/show.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
var showGuidesApp = angular.module('showGuidesApp', [
'mm.foundation',
'ngS3upload',
'ng-rails-csrf',
'openFarmModule'
]);

showGuidesApp.controller('showGuideCtrl', ['$scope', '$http', 'guideService',
openFarmApp.controller('showGuideCtrl', ['$scope', '$http', 'guideService',
'userService',
function showGuidesApp($scope, $http, guideService, userService) {

$scope.guide_id = getIDFromURL('guides');
function showGuideCtrl($scope, $http, guideService, userService) {
$scope.guide_id = getIDFromURL('guides') || GUIDE_ID;
$scope.alerts = [];

$scope.setUser = function(success, object, code){

Expand All @@ -22,7 +15,7 @@ showGuidesApp.controller('showGuideCtrl', ['$scope', '$http', 'guideService',
type: 'warning'
});
}
}
};

$scope.setGuide = function(success, object, code){
if (success){
Expand All @@ -35,7 +28,7 @@ showGuidesApp.controller('showGuideCtrl', ['$scope', '$http', 'guideService',
type: 'warning'
});
}
}
};

guideService.getGuide($scope.guide_id, $scope.setGuide);
}]);
11 changes: 3 additions & 8 deletions app/assets/javascripts/search.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
var searchApp = angular.module('searchApp', [
'mm.foundation',
'ng-rails-csrf'
]);

searchApp.controller('searchCtrl', ['$scope', '$http', '$location',
function searchApp($scope, $http, $location) {
openFarmApp.controller('searchCtrl', ['$scope', '$http',
function searchCtrl($scope, $http) {
$scope.crops = [];

//Typeahead search for crops
Expand All @@ -22,7 +17,7 @@ searchApp.controller('searchCtrl', ['$scope', '$http', '$location',
if (response.crops.length){
$scope.crops = response.crops;
}
})
});
}
};
}]);
Empty file added app/assets/javascripts/users.js
Empty file.
4 changes: 4 additions & 0 deletions app/assets/javascripts/users/finish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openFarmApp.controller('finishCtrl', ['$scope', '$http',
function finishCtrl($scope, $http) {

}]);
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ small.error{
}

.button{
@include background-gradient(#A2BD6A, #A2BF6B);
@include background-gradient(#A2BD6A, #83A544);
border-radius: 3px;
/*font-family: SourceSansPro-Bold;*/
transition: .2s background-image;
}

.button:hover{
@include background-gradient(#8FAB54, #7A9841);
}

.button[disabled=disabled].loading, .button[disabled].loading, .button[disabled].loading:hover{
Expand Down Expand Up @@ -113,7 +117,6 @@ small.error{

h2, h5 {
display: inline-block;
color: white;
font-weight: 600;
}

Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/requirement.css.scss

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/stylesheets/stages.css.scss

This file was deleted.

Empty file.
17 changes: 17 additions & 0 deletions app/assets/stylesheets/users/_finish.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.title{
text-align: center;
margin-bottom: 2rem;

h2{
font-size: 1.6rem;
color: #222;
}
}

.row.submit{
margin: 2rem auto 4rem;
}

.finish .row{
max-width: 640px;
}
File renamed without changes.
2 changes: 2 additions & 0 deletions app/controllers/gardens_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class GardensController < ApplicationController
end
Loading

0 comments on commit 0f01455

Please sign in to comment.