Commit aedaf069 authored by nemoNoboru's avatar nemoNoboru

added modify name in frontend

parent 8e9a7be3
......@@ -18,7 +18,7 @@ var people_path = '/people'
function end(res,err) {
if (err) {
return res.status(500).send(err)
res.status(500).send(err)
}else{
res.send("ok")
}
......@@ -37,8 +37,8 @@ app.post(people_path,function (req,res) {
})
})
app.put(people_path+"/:person_id",function (req,res) {
people.modify(req.params.person_id,req.body.name, function (err) {
app.put(people_path,function (req,res) {
people.modify(req.body.person_id,req.body.name, function (err) {
end(res,err)
})
})
......@@ -50,13 +50,13 @@ app.delete(people_path+"/:person_id",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)
})
})
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)
})
})
......
db:
image: mongo
ports:
- "27017:27017"
- "27018:27017"
command: "--smallfiles --logpath=/dev/null"
web:
build: .
......
......@@ -10,10 +10,16 @@ app.service('people', function ($http) {
this.add = function (n,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) {
var self = this
$scope.editing = false
this.load = function () {
people.index(function (people) {
......@@ -34,4 +40,18 @@ app.controller('peopleCtrl',function ($scope,people) {
$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 @@
</div>
</div>
<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'>
<button class='align-right' ng-click='remove(i)'>Trash</button>
</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