Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
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
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
57ae83d4
Commit
57ae83d4
authored
Dec 02, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1741 from hypothesis/sticky-visibility-level-object
Use an object for privacy level models
parents
eabb1f59
1c2303aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
26 deletions
+30
-26
privacy.coffee
h/static/scripts/directives/privacy.coffee
+18
-15
privacy.html
h/templates/client/privacy.html
+7
-6
privacy-test.coffee
tests/js/directives/privacy-test.coffee
+5
-5
No files found.
h/static/scripts/directives/privacy.coffee
View file @
57ae83d4
...
...
@@ -2,6 +2,18 @@ privacy = ['$window', ($window) ->
VISIBILITY_KEY
=
'hypothesis.visibility'
VISIBILITY_PUBLIC
=
'public'
VISIBILITY_PRIVATE
=
'private'
levels
=
[
{
name
:
VISIBILITY_PUBLIC
,
text
:
'Public'
}
{
name
:
VISIBILITY_PRIVATE
,
text
:
'Only Me'
}
]
getLevel
=
(
name
)
->
for
level
in
levels
if
level
.
name
==
name
return
level
undefined
# Detection is needed because we run often as a third party widget and
# third party storage blocking often blocks cookies and local storage
# https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
...
...
@@ -18,8 +30,6 @@ privacy = ['$window', ($window) ->
setItem
:
(
key
,
value
)
->
memoryStorage
[
key
]
=
value
levels
=
[
'Public'
,
'Only Me'
]
link
:
(
scope
,
elem
,
attrs
,
controller
)
->
return
unless
controller
?
...
...
@@ -27,16 +37,16 @@ privacy = ['$window', ($window) ->
return
unless
permissions
?
if
'group:__world__'
in
(
permissions
.
read
or
[])
'Public'
getLevel
(
VISIBILITY_PUBLIC
)
else
'Only Me'
getLevel
(
VISIBILITY_PRIVATE
)
controller
.
$parsers
.
push
(
privacy
)
->
return
unless
privacy
?
permissions
=
controller
.
$modelValue
if
privacy
is
'Public'
if
privacy
.
name
is
VISIBILITY_PUBLIC
permissions
.
read
=
[
'group:__world__'
]
else
permissions
.
read
=
[
attrs
.
user
]
...
...
@@ -49,22 +59,15 @@ privacy = ['$window', ($window) ->
controller
.
$render
=
->
unless
controller
.
$modelValue
.
read
.
length
visibility
=
storage
.
getItem
VISIBILITY_KEY
level
=
if
visibility
is
VISIBILITY_PUBLIC
'Public'
else
'Only Me'
name
=
storage
.
getItem
VISIBILITY_KEY
level
=
getLevel
(
name
)
controller
.
$setViewValue
level
scope
.
level
=
controller
.
$viewValue
scope
.
levels
=
levels
scope
.
setLevel
=
(
level
)
->
visibility
=
if
level
is
'Public'
VISIBILITY_PUBLIC
else
VISIBILITY_PRIVATE
storage
.
setItem
VISIBILITY_KEY
,
visibility
storage
.
setItem
VISIBILITY_KEY
,
level
.
name
controller
.
$setViewValue
level
controller
.
$render
()
require
:
'?ngModel'
...
...
h/templates/client/privacy.html
View file @
57ae83d4
...
...
@@ -3,15 +3,16 @@
role=
"button"
class=
"dropdown-toggle"
data-toggle=
"dropdown"
>
<i
class=
"small"
ng-class=
"{'h-icon-earth': level == 'Public', 'h-icon-locked': level == 'Only Me'}"
></i>
{{level}}
<i
class=
"small"
ng-class=
"{'h-icon-earth': level.name == 'public',
'h-icon-locked': level.name == 'private'}"
></i>
{{level.text}}
<i
class=
"h-icon-triangle"
></i>
</span>
<ul
class=
"dropdown-menu"
role=
"menu"
>
<li
ng-repeat=
"
p in levels"
ng-click=
"setLevel(p
)"
>
<i
class=
"small"
ng-class=
"{'h-icon-earth':
p == 'P
ublic',
'h-icon-locked':
p == 'Only M
e'}"
></i>
{{
p
}}
<li
ng-repeat=
"
level in levels"
ng-click=
"setLevel(level
)"
>
<i
class=
"small"
ng-class=
"{'h-icon-earth':
level.name == 'p
ublic',
'h-icon-locked':
level.name == 'privat
e'}"
></i>
{{
level.text
}}
</li>
</ul>
</div>
tests/js/directives/privacy-test.coffee
View file @
57ae83d4
...
...
@@ -42,7 +42,7 @@ describe 'h.directives.privacy', ->
$element
=
$compile
(
'<privacy ng-model="permissions">'
)(
$scope
)
$scope
.
$digest
()
$isolateScope
=
$element
.
isolateScope
()
$isolateScope
.
setLevel
(
'Public'
)
$isolateScope
.
setLevel
(
name
:
VISIBILITY_PUBLIC
)
$scope2
.
permissions
=
{
read
:
[]}
$element
=
$compile
(
'<privacy ng-model="permissions">'
)(
$scope2
)
...
...
@@ -71,7 +71,7 @@ describe 'h.directives.privacy', ->
$element
=
$compile
(
'<privacy ng-model="permissions">'
)(
$scope
)
$scope
.
$digest
()
$isolateScope
=
$element
.
isolateScope
()
$isolateScope
.
setLevel
(
'Public'
)
$isolateScope
.
setLevel
(
name
:
VISIBILITY_PUBLIC
)
expected
=
VISIBILITY_PUBLIC
stored
=
store
.
getItem
VISIBILITY_KEY
...
...
@@ -94,14 +94,14 @@ describe 'h.directives.privacy', ->
$isolateScope
=
$element
.
isolateScope
()
it
'sets the initial permissions based on the stored privacy level'
,
->
assert
.
equal
$isolateScope
.
level
,
'Public'
assert
.
equal
$isolateScope
.
level
.
name
,
VISIBILITY_PUBLIC
it
'does not alter the level on subsequent renderings'
,
->
modelCtrl
=
$element
.
controller
(
'ngModel'
)
store
.
setItem
VISIBILITY_KEY
,
VISIBILITY_PRIVATE
$scope
.
permissions
.
read
=
[
'acct:user@example.com'
]
$scope
.
$digest
()
assert
.
equal
$isolateScope
.
level
,
'Public'
assert
.
equal
$isolateScope
.
level
.
name
,
VISIBILITY_PUBLIC
describe
'when permissions.read is filled'
,
->
it
'does not alter the level'
,
->
...
...
@@ -111,7 +111,7 @@ describe 'h.directives.privacy', ->
$element
=
$compile
(
'<privacy ng-model="permissions">'
)(
$scope
)
$scope
.
$digest
()
$isolateScope
=
$element
.
isolateScope
()
assert
.
equal
(
$isolateScope
.
level
,
'Public'
)
assert
.
equal
(
$isolateScope
.
level
.
name
,
VISIBILITY_PUBLIC
)
describe
'user attribute'
,
->
beforeEach
->
...
...
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