Commit aedaf069 authored by nemoNoboru's avatar nemoNoboru

added modify name in frontend

parent 8e9a7be3
...@@ -18,7 +18,7 @@ var people_path = '/people' ...@@ -18,7 +18,7 @@ var people_path = '/people'
function end(res,err) { function end(res,err) {
if (err) { if (err) {
return res.status(500).send(err) res.status(500).send(err)
}else{ }else{
res.send("ok") res.send("ok")
} }
...@@ -37,8 +37,8 @@ app.post(people_path,function (req,res) { ...@@ -37,8 +37,8 @@ app.post(people_path,function (req,res) {
}) })
}) })
app.put(people_path+"/:person_id",function (req,res) { app.put(people_path,function (req,res) {
people.modify(req.params.person_id,req.body.name, function (err) { people.modify(req.body.person_id,req.body.name, function (err) {
end(res,err) end(res,err)
}) })
}) })
...@@ -50,13 +50,13 @@ app.delete(people_path+"/:person_id",function (req,res) { ...@@ -50,13 +50,13 @@ app.delete(people_path+"/:person_id",function (req,res) {
}) })
app.post(people_path+"/pets",function (req,res) { app.post(people_path+"/pets",function (req,res) {
people.addPet(req.body.id,req.body.petname, function (err) { people.addPet(req.body.person_id,req.body.petname, function (err) {
end(res,err) end(res,err)
}) })
}) })
app.delete(people_path+"/pets",function (req,res) { app.delete(people_path+"/pets",function (req,res) {
people.removePet(req.body.id,req.body.petname, function (err) { people.removePet(req.body.person_id,req.body.petname, function (err) {
end(res,err) end(res,err)
}) })
}) })
......
db: db:
image: mongo image: mongo
ports: ports:
- "27017:27017" - "27018:27017"
command: "--smallfiles --logpath=/dev/null" command: "--smallfiles --logpath=/dev/null"
web: web:
build: . build: .
......
...@@ -10,10 +10,16 @@ app.service('people', function ($http) { ...@@ -10,10 +10,16 @@ app.service('people', function ($http) {
this.add = function (n,callback) { this.add = function (n,callback) {
$http.post('http://127.0.0.1:8000/people',{name:n}).then(callback) $http.post('http://127.0.0.1:8000/people',{name:n}).then(callback)
} }
this.modify = function (item,callback) {
$http.put('http://127.0.0.1:8000/people',{person_id: item._id, name: item.name})
.then(callback)
}
}) })
app.controller('peopleCtrl',function ($scope,people) { app.controller('peopleCtrl',function ($scope,people) {
var self = this var self = this
$scope.editing = false
this.load = function () { this.load = function () {
people.index(function (people) { people.index(function (people) {
...@@ -34,4 +40,18 @@ app.controller('peopleCtrl',function ($scope,people) { ...@@ -34,4 +40,18 @@ app.controller('peopleCtrl',function ($scope,people) {
$scope.name = '' $scope.name = ''
} }
$scope.edit = function (name) {
$scope.editing = true;
$scope.e = name
}
$scope.save = function (item,e) {
item.name = e
console.log(e)
people.modify(item,function (err) {
self.load()
$scope.editing = false
})
}
}) })
...@@ -23,7 +23,11 @@ ...@@ -23,7 +23,11 @@
</div> </div>
</div> </div>
<hr/> <hr/>
<div class="box" ng-repeat='i in people_list'>{{i.name }} <div class="box" ng-repeat='i in people_list'>
<span ng-hide='editing'>{{i.name}}</span>
<button ng-hide='editing' ng-click='edit(i.name)'>edit</button>
<input ng-show='editing' class="text" ng-model='e'/>
<button ng-click='save(i,e)' ng-show='editing'>save</button>
<section class='align-right'> <section class='align-right'>
<button class='align-right' ng-click='remove(i)'>Trash</button> <button class='align-right' ng-click='remove(i)'>Trash</button>
</section> </section>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment