Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
daa-custom-stack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Felipe Vieira de Moraes Tavares
daa-custom-stack
Commits
1d0d8f43
Commit
1d0d8f43
authored
Feb 15, 2017
by
nemoNoboru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
done
parent
aedaf069
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
24 deletions
+71
-24
index.js
backend/app/index.js
+8
-6
people.js
backend/app/people/people.js
+6
-6
flatten.css
frontend/app/assets/css/flatten.css
+0
-3
people.css
frontend/app/assets/css/people.css
+7
-0
people.js
frontend/app/core/people.js
+23
-0
index.html
frontend/app/index.html
+27
-9
No files found.
backend/app/index.js
View file @
1d0d8f43
...
...
@@ -14,7 +14,6 @@ app.use(bodyParser.urlencoded({ extended: false }))
app
.
use
(
bodyParser
.
json
())
app
.
use
(
cors
())
var
people_path
=
'/people'
function
end
(
res
,
err
)
{
if
(
err
)
{
...
...
@@ -24,6 +23,8 @@ function end(res,err) {
}
}
var
people_path
=
'/people'
app
.
get
(
people_path
,
function
(
req
,
res
)
{
people
.
index
(
function
(
err
,
people
)
{
res
.
send
(
people
)
...
...
@@ -43,6 +44,12 @@ app.put(people_path,function (req,res) {
})
})
app
.
delete
(
people_path
+
"/:person_id/pets/:petname"
,
function
(
req
,
res
)
{
people
.
removePet
(
req
.
params
.
person_id
,
req
.
params
.
petname
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
delete
(
people_path
+
"/:person_id"
,
function
(
req
,
res
)
{
people
.
remove
(
req
.
params
.
person_id
,
function
(
err
)
{
end
(
res
,
err
)
...
...
@@ -55,10 +62,5 @@ app.post(people_path+"/pets",function (req,res) {
})
})
app
.
delete
(
people_path
+
"/pets"
,
function
(
req
,
res
)
{
people
.
removePet
(
req
.
body
.
person_id
,
req
.
body
.
petname
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
listen
(
port
)
backend/app/people/people.js
View file @
1d0d8f43
...
...
@@ -7,7 +7,7 @@ db.once('open',function () {
people
.
model
=
mongoose
.
model
(
'People'
,{
name
:
String
,
pets
:
Array
})
people
.
index
=
function
(
callback
)
{
people
.
model
.
find
({},
callback
)
people
.
model
.
find
({},
callback
)
}
people
.
create
=
function
(
personName
,
callback
)
{
...
...
@@ -15,27 +15,27 @@ db.once('open',function () {
newPeople
.
save
(
callback
)
}
people
.
modify
=
function
(
id
,
name
,
callback
)
{
people
.
modify
=
function
(
id
,
name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
name
=
name
person
.
save
(
callback
)
})
}
people
.
remove
=
function
(
id
,
callback
)
{
people
.
remove
=
function
(
id
,
callback
)
{
people
.
model
.
findById
(
id
).
remove
(
callback
)
}
people
.
addPet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
addPet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
pets
.
push
(
pet_name
)
person
.
save
(
callback
)
})
}
people
.
removePet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
removePet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
pets
.
remove
(
pet_name
)
person
.
pets
.
splice
(
person
.
pets
.
indexOf
(
pet_name
),
1
)
person
.
save
(
callback
)
})
}
...
...
frontend/app/assets/css/flatten.css
deleted
100644 → 0
View file @
aedaf069
.cfield
{
margin-bottom
:
30px
;
}
frontend/app/assets/css/people.css
0 → 100644
View file @
1d0d8f43
.margin
{
margin-bottom
:
20px
;
}
.name
{
margin
:
30px
;
}
frontend/app/core/people.js
View file @
1d0d8f43
...
...
@@ -15,6 +15,16 @@ app.service('people', function ($http) {
$http
.
put
(
'http://127.0.0.1:8000/people'
,{
person_id
:
item
.
_id
,
name
:
item
.
name
})
.
then
(
callback
)
}
this
.
addPet
=
function
(
item
,
pet_name
,
callback
)
{
$http
.
post
(
'http://127.0.0.1:8000/people/pets'
,{
person_id
:
item
.
_id
,
petname
:
pet_name
})
.
then
(
callback
)
}
this
.
removePet
=
function
(
item
,
pet_name
,
callback
)
{
$http
.
delete
(
'http://127.0.0.1:8000/people/'
+
item
.
_id
+
'/pets/'
+
pet_name
)
.
then
(
callback
)
}
})
app
.
controller
(
'peopleCtrl'
,
function
(
$scope
,
people
)
{
...
...
@@ -54,4 +64,17 @@ app.controller('peopleCtrl',function ($scope,people) {
})
}
$scope
.
addPet
=
function
(
person
,
pet
)
{
people
.
addPet
(
person
,
pet
,
function
()
{
self
.
load
()
$scope
.
pet
=
''
})
}
$scope
.
removePet
=
function
(
person
,
pet
)
{
people
.
removePet
(
person
,
pet
,
function
()
{
self
.
load
()
})
}
})
frontend/app/index.html
View file @
1d0d8f43
<html>
<head>
<title>
Flatten
!
</title>
<title>
People
!
</title>
<meta
charset=
"utf-8"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
<link
rel=
"stylesheet"
href=
"assets/css/main.css"
/>
<link
rel=
"stylesheet"
href=
"assets/css/
flatten
.css"
/>
<link
rel=
"stylesheet"
href=
"assets/css/
people
.css"
/>
</head>
<body
ng-app=
'daa'
>
<div
ng-controller=
'peopleCtrl as $ctrl'
>
...
...
@@ -24,13 +24,31 @@
</div>
<hr/>
<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>
<!-- just show name -->
<div
class=
"row"
>
<div
class=
"12u margin"
>
<span
class=
'name'
ng-hide=
'editing'
>
{{i.name}}
</span>
<button
ng-hide=
'editing'
ng-click=
'edit(i.name)'
>
edit
</button>
<button
ng-click=
'remove(i)'
>
Trash
</button>
<!-- hide name and show input text -->
<input
ng-show=
'editing'
class=
"text"
ng-model=
'e'
/>
<button
ng-click=
'save(i,e)'
ng-show=
'editing'
>
save
</button>
</div>
<div
class=
"12u margin"
>
<!-- pets -->
<button
ng-click=
'removePet(i,p)'
ng-repeat=
'p in i.pets'
>
{{p}} X
</button>
</div>
<div
class=
"10u"
>
<input
type=
"text"
ng-model=
'pet'
>
</div>
<div
class=
"2u margin"
>
<button
ng-click=
'addPet(i,pet)'
>
add
</button>
</div>
</div>
</div>
</div>
</section>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment