Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
0c55dfcf
Commit
0c55dfcf
authored
Mar 13, 2013
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #25 from rll/feature/kevin/pinning
Feature/kevin/pinning
parents
0769389d
a071e152
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
0 deletions
+29
-0
api/pins.rb
+8
-0
app.rb
+1
-0
lib/helpers.rb
+17
-0
models/comment_thread.rb
+3
-0
No files found.
api/pins.rb
0 → 100644
View file @
0c55dfcf
put
"
#{
APIPREFIX
}
/threads/:thread_id/pin"
do
|
thread_id
|
pin
thread
end
put
"
#{
APIPREFIX
}
/threads/:thread_id/unpin"
do
|
thread_id
|
unpin
thread
end
app.rb
View file @
0c55dfcf
...
@@ -60,6 +60,7 @@ require './api/comment_threads'
...
@@ -60,6 +60,7 @@ require './api/comment_threads'
require
'./api/comments'
require
'./api/comments'
require
'./api/users'
require
'./api/users'
require
'./api/votes'
require
'./api/votes'
require
'./api/pins'
require
'./api/notifications_and_subscriptions'
require
'./api/notifications_and_subscriptions'
if
RACK_ENV
.
to_s
==
"development"
if
RACK_ENV
.
to_s
==
"development"
...
...
lib/helpers.rb
View file @
0c55dfcf
...
@@ -43,6 +43,22 @@ helpers do
...
@@ -43,6 +43,22 @@ helpers do
obj
.
reload
.
to_hash
.
to_json
obj
.
reload
.
to_hash
.
to_json
end
end
def
pin
(
obj
)
raise
ArgumentError
,
"User id is required"
unless
user
obj
.
pinned
=
true
obj
.
save
obj
.
reload
.
to_hash
.
to_json
end
def
unpin
(
obj
)
raise
ArgumentError
,
"User id is required"
unless
user
obj
.
pinned
=
nil
obj
.
save
obj
.
reload
.
to_hash
.
to_json
end
def
value_to_boolean
(
value
)
def
value_to_boolean
(
value
)
!!
(
value
.
to_s
=~
/^true$/i
)
!!
(
value
.
to_s
=~
/^true$/i
)
end
end
...
@@ -111,6 +127,7 @@ helpers do
...
@@ -111,6 +127,7 @@ helpers do
else
else
page
=
(
params
[
"page"
]
||
DEFAULT_PAGE
).
to_i
page
=
(
params
[
"page"
]
||
DEFAULT_PAGE
).
to_i
per_page
=
(
params
[
"per_page"
]
||
DEFAULT_PER_PAGE
).
to_i
per_page
=
(
params
[
"per_page"
]
||
DEFAULT_PER_PAGE
).
to_i
#KChugh turns out we don't need to go through all the extra work on the back end because the client is resorting anyway
comment_threads
=
comment_threads
.
order_by
(
"
#{
sort_key
}
#{
sort_order
}
"
)
if
sort_key
&&
sort_order
comment_threads
=
comment_threads
.
order_by
(
"
#{
sort_key
}
#{
sort_order
}
"
)
if
sort_key
&&
sort_order
num_pages
=
[
1
,
(
comment_threads
.
count
/
per_page
.
to_f
).
ceil
].
max
num_pages
=
[
1
,
(
comment_threads
.
count
/
per_page
.
to_f
).
ceil
].
max
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
page
=
[
num_pages
,
[
1
,
page
].
max
].
min
...
...
models/comment_thread.rb
View file @
0c55dfcf
...
@@ -22,6 +22,7 @@ class CommentThread < Content
...
@@ -22,6 +22,7 @@ class CommentThread < Content
field
:at_position_list
,
type:
Array
,
default:
[]
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
field
:last_activity_at
,
type:
Time
field
:group_id
,
type:
Integer
field
:group_id
,
type:
Integer
field
:pinned
,
type:
Boolean
index
({
author_id:
1
,
course_id:
1
})
index
({
author_id:
1
,
course_id:
1
})
...
@@ -44,6 +45,7 @@ class CommentThread < Content
...
@@ -44,6 +45,7 @@ class CommentThread < Content
indexes
:commentable_id
,
type: :string
,
index: :not_analyzed
,
included_in_all:
false
indexes
:commentable_id
,
type: :string
,
index: :not_analyzed
,
included_in_all:
false
indexes
:author_id
,
type: :string
,
as:
'author_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:author_id
,
type: :string
,
as:
'author_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:group_id
,
type: :integer
,
as:
'group_id'
,
index: :not_analyzed
,
included_in_all:
false
indexes
:group_id
,
type: :integer
,
as:
'group_id'
,
index: :not_analyzed
,
included_in_all:
false
#indexes :pinned, type: :boolean, as: 'pinned', index: :not_analyzed, included_in_all: false
end
end
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
#, autosave: true
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
#, autosave: true
...
@@ -176,6 +178,7 @@ class CommentThread < Content
...
@@ -176,6 +178,7 @@ class CommentThread < Content
"tags"
=>
tags_array
,
"tags"
=>
tags_array
,
"type"
=>
"thread"
,
"type"
=>
"thread"
,
"group_id"
=>
group_id
,
"group_id"
=>
group_id
,
"pinned"
=>
pinned?
,
"endorsed"
=>
endorsed?
)
"endorsed"
=>
endorsed?
)
if
params
[
:recursive
]
if
params
[
:recursive
]
...
...
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