Skip to content

Commit adc0e0e

Browse files
committed
updatig model and angular controles and partials to save data to mongo
1 parent e08bde5 commit adc0e0e

File tree

5 files changed

+39
-76
lines changed

5 files changed

+39
-76
lines changed

app/model.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ var Schema = mongoose.Schema;
44

55
// Creates a User Schema. This will be the basis of how user data is stored in the db
66
var UserSchema = new Schema({
7-
username: {type: String, required: true},
7+
name: {type: String, required: true},
88
gender: {type: String, required: true},
9-
age: {type: Number, required: true},
10-
favlang: {type: String, required: true},
9+
description: { type: String, required: true },
10+
skillRequired: { type: String, required: true },
11+
phone: { type: String, required: true },
1112
location: {type: [Number], required: true}, // [Long, Lat]
1213
htmlverified: String,
1314
created_at: {type: Date, default: Date.now},

app/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = function(app) {
2929
app.post('/users', function(req, res){
3030

3131
// Creates a new User based on the Mongoose schema and the post bo.dy
32+
console.log(req.body);
3233
var newuser = new User(req.body);
3334

3435
// New User is saved in the db.

public/js/addCtrl.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ addCtrl.controller('addCtrl', function($scope, $http, $rootScope, geolocation, g
6161

6262
// Grabs all of the text box fields
6363
var userData = {
64-
username: $scope.formData.username,
65-
gender: $scope.formData.gender,
66-
age: $scope.formData.age,
67-
favlang: $scope.formData.favlang,
64+
name: $scope.formData.name,
65+
description: $scope.formData.description,
66+
skillRequired: $scope.formData.skillRequired,
67+
phone: $scope.formData.phone,
6868
location: [$scope.formData.longitude, $scope.formData.latitude],
6969
htmlverified: $scope.formData.htmlverified
7070
};
@@ -74,10 +74,10 @@ addCtrl.controller('addCtrl', function($scope, $http, $rootScope, geolocation, g
7474
.success(function (data) {
7575

7676
// Once complete, clear the form (except location)
77-
$scope.formData.username = "";
78-
$scope.formData.gender = "";
79-
$scope.formData.age = "";
80-
$scope.formData.favlang = "";
77+
$scope.formData.name = "";
78+
$scope.formData.description = "";
79+
$scope.formData.skillrequired = "";
80+
$scope.formData.phone = "";
8181

8282
// Refresh the map with new data
8383
gservice.refresh($scope.formData.latitude, $scope.formData.longitude);
@@ -87,4 +87,3 @@ addCtrl.controller('addCtrl', function($scope, $http, $rootScope, geolocation, g
8787
});
8888
};
8989
});
90-

public/js/gservice.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ angular.module('gservice', [])
7171
var user = response[i];
7272

7373
// Create popup windows for each record
74-
var contentString = '<p><b>Username</b>: ' + user.username + '<br><b>Age</b>: ' + user.age + '<br>' +
75-
'<b>Gender</b>: ' + user.gender + '<br><b>Favorite Language</b>: ' + user.favlang + '</p>';
74+
var contentString = user.name + '<br><b>Busca ayuda en </b>: ' + user.skillRequired + '<br>' +
75+
'<b>situacion</b>: ' + user.description + '</p>';
7676

7777
// Converts each of the JSON records into Google Maps Location format (Note Lat, Lng format).
7878
locations.push(new Location(
@@ -81,24 +81,22 @@ angular.module('gservice', [])
8181
content: contentString,
8282
maxWidth: 320
8383
}),
84-
user.username,
85-
user.gender,
86-
user.age,
87-
user.favlang
84+
user.name,
85+
user.skillRequired,
86+
user.description
8887
))
8988
}
9089
// location is now an array populated with records in Google Maps format
9190
return locations;
9291
};
9392

9493
// Constructor for generic location
95-
var Location = function(latlon, message, username, gender, age, favlang){
94+
var Location = function(latlon, message, name, skillRequired, description){
9695
this.latlon = latlon;
9796
this.message = message;
98-
this.username = username;
99-
this.gender = gender;
100-
this.age = age;
101-
this.favlang = favlang
97+
this.name = name;
98+
this.skillRequired = skillRequired;
99+
this.description = description;
102100
};
103101

104102
// Initializes the map

public/partials/addForm.html

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,40 @@ <h2 class="panel-title text-center">Requiero un servicio de... <span class="glyp
1717

1818
<!-- Text Boxes and Other User Inputs. Note ng-model binds the values to Angular $scope -->
1919
<div class="form-group">
20-
<label for="username">Tu nombre: <span class="badge">campos requeridos</span></label>
21-
<input type="text" class="form-control" id="username" ng-model="formData.username" required>
22-
</div>
23-
<!--
24-
<label class="radio control-label">Gender</label>
25-
<div class="radio">
26-
<label>
27-
<input type="radio" name="optionsRadios" id="radiomale" value="Male" ng-model="formData.gender">
28-
Male
29-
</label>
30-
</div>
31-
<div class="radio" required>
32-
<label>
33-
<input type="radio" name="optionsRadios" id="radiofemale" value="Female" ng-model="formData.gender">
34-
Female
35-
</label>
36-
</div>
37-
<div class="radio">
38-
<label>
39-
<input type="radio" name="optionsRadios" id="radioother" value="What's it to ya?" ng-model="formData.gender">
40-
What's it to ya?
41-
</label>
20+
<label for="name">Tu nombre: <span class="badge">campos requeridos</span></label>
21+
<input type="text" class="form-control" id="name" ng-model="formData.name" required>
4222
</div>
4323

4424
<div class="form-group">
45-
<label for="age">Age</label>
46-
<input type="number" class="form-control" id="age" placeholder="72" ng-model="formData.age" required>
47-
</div>
48-
-->
49-
<div class="form-group">
50-
<label for="language">Servicio requerido</label>
51-
<input type="text" class="form-control" id="language" placeholder="Fontarería, Albañilería, Jardinería" ng-model="formData.favlang" required>
25+
<label for="skillrequired">Servicio requerido</label>
26+
<input type="text" class="form-control" id="skillrequired" placeholder="Fontarería, Albañilería, Jardinería" ng-model="formData.skillrequired" required>
5227
</div>
5328
<div class="form-group">
54-
<label for="language">Descripcion de la chamba</label>
55-
<input type="text" class="form-control" id="language" placeholder="Se rompio la llave del grifo" ng-model="formData.favlang" required>
29+
<label for="description">Descripcion de la chamba</label>
30+
<input type="text" class="form-control" id="description" placeholder="Se rompio la llave del grifo" ng-model="formData.description" required>
5631
</div>
57-
<label>Contactar me por:</label>
32+
5833
<div class="form-group">
59-
<label class="checkbox-inline">
60-
<input type="checkbox" name="optionsRadios" id="checkphone" value="telefono" ng-model="formData.male" ng-true-value = "'Telefono'">
61-
Telefono
62-
</label>
63-
<label class="checkbox-inline">
64-
<input type="checkbox" name="optionsRadios" id="checkwhatsapp" value="whatsapp" ng-model="formData.female" ng-true-value="'WhatsApp'">
65-
WhatsApp
66-
</label>
67-
<label class="checkbox-inline">
68-
<input type="checkbox" name="optionsRadios" id="checkchambapp" value="chambapp" ng-model="formData.other" ng-true-value="'ChambApp'">
69-
ChambApp
70-
</label>
34+
<label for="phone">telefono</label>
35+
<input type="text" class="form-control" id="phone" placeholder="+52 33 36 45 18" ng-model="formData.phone" required>
7136
</div>
72-
<!--
73-
<div class="form-group">
37+
38+
<div class="form-group" hidden>
7439
<label for="latitude">Latitud</label>
75-
<input type="text" class="form-control" id="latitude" value="39.500" ng-model="formData.latitude" readonly>
40+
<input type="text" class="form-control" id="latitude" value="20.734699" ng-model="formData.latitude" readonly>
7641
</div>
77-
<div class="form-group">
42+
<div class="form-group" hidden>
7843
<label for="longitude">Longitud</label>
79-
<input type="text" class="form-control" id="longitude" value="-98.350" ng-model="formData.longitude" readonly>
44+
<input type="text" class="form-control" id="longitude" value="-103.455321" ng-model="formData.longitude" readonly>
8045
</div>
8146
<div class="form-group">
8247
<!-- Note RefreshLoc button tied to addCtrl. This requests a refresh of the HTML5 verified location. -->
83-
<!--
84-
<label for="verified">HTML5 Verified Location? <span><button ng-click="refreshLoc()" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-refresh"></span></button></span></label>
48+
<label for="verified">Verificar mi ubicacion <span><button ng-click="refreshLoc()" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-refresh"></span></button></span></label>
8549
<input type="text" class="form-control" id="verified" placeholder= "Nope (Thanks for spamming my map...)" ng-model="formData.htmlverified" readonly>
8650
</div>
87-
-->
51+
8852
<!-- Submit button. Note that its tied to createUser() function from addCtrl. Also note ng-disabled logic which prevents early submits. -->
89-
<button type="submit" class="btn btn-danger btn-block" ng-click="createUser()" ng-disabled="addForm.$invalid">Buscar</button>
53+
<button type="submit" class="btn btn-danger btn-block" ng-click="createUser()" ng-disabled="addForm.$invalid">Buscar Ayudante</button>
9054
</form>
9155
</div>
9256
</div>

0 commit comments

Comments
 (0)