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
cba3f7f7
Commit
cba3f7f7
authored
Mar 14, 2016
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3049 from hypothesis/direct-link-feature-flag
Add direct linking feature flag
parents
e0ef6831
f4981856
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
21 deletions
+59
-21
annotation.js
h/static/scripts/directive/annotation.js
+11
-4
annotation-test.js
h/static/scripts/directive/test/annotation-test.js
+45
-16
annotation-fixtures.js
h/static/scripts/test/annotation-fixtures.js
+2
-0
annotation.html
h/templates/client/annotation.html
+1
-1
No files found.
h/static/scripts/directive/annotation.js
View file @
cba3f7f7
/* jshint node: true */
/* jshint node: true */
'use strict'
;
'use strict'
;
var
Promise
=
require
(
'core-js/library/es6/promise'
);
var
annotationMetadata
=
require
(
'../annotation-metadata'
);
var
annotationMetadata
=
require
(
'../annotation-metadata'
);
var
dateUtil
=
require
(
'../date-util'
);
var
dateUtil
=
require
(
'../date-util'
);
var
documentDomain
=
require
(
'../filter/document-domain'
);
var
documentDomain
=
require
(
'../filter/document-domain'
);
...
@@ -111,13 +109,22 @@ function updateDomainModel(domainModel, vm, permissions) {
...
@@ -111,13 +109,22 @@ function updateDomainModel(domainModel, vm, permissions) {
}
}
/** Update the view model from the domain model changes. */
/** Update the view model from the domain model changes. */
function
updateViewModel
(
$scope
,
time
,
domainModel
,
vm
,
permissions
)
{
function
updateViewModel
(
$scope
,
time
,
domainModel
,
vm
,
permissions
)
{
vm
.
form
=
{
vm
.
form
=
{
text
:
domainModel
.
text
,
text
:
domainModel
.
text
,
tags
:
viewModelTagsFromDomainModelTags
(
domainModel
.
tags
),
tags
:
viewModelTagsFromDomainModelTags
(
domainModel
.
tags
),
};
};
vm
.
annotationURI
=
new
URL
(
'/a/'
+
domainModel
.
id
,
vm
.
serviceUrl
).
href
;
if
(
domainModel
.
links
)
{
vm
.
annotationURI
=
domainModel
.
links
.
incontext
||
domainModel
.
links
.
html
||
''
;
}
else
{
vm
.
annotationURI
=
''
;
}
vm
.
isPrivate
=
permissions
.
isPrivate
(
vm
.
isPrivate
=
permissions
.
isPrivate
(
domainModel
.
permissions
,
domainModel
.
user
);
domainModel
.
permissions
,
domainModel
.
user
);
...
...
h/static/scripts/directive/test/annotation-test.js
View file @
cba3f7f7
/* jshint node: true */
/* jshint node: true */
'use strict'
;
'use strict'
;
var
angular
=
require
(
'angular'
);
var
proxyquire
=
require
(
'proxyquire'
);
var
proxyquire
=
require
(
'proxyquire'
);
var
events
=
require
(
'../../events'
);
var
events
=
require
(
'../../events'
);
var
fixtures
=
require
(
'../../test/annotation-fixtures'
);
var
fixtures
=
require
(
'../../test/annotation-fixtures'
);
var
util
=
require
(
'./util'
);
var
util
=
require
(
'./util'
);
var
module
=
angular
.
mock
.
module
;
var
inject
=
angular
.
mock
.
inject
;
var
inject
=
angular
.
mock
.
inject
;
/**
/**
* Returns the annotation directive with helpers stubbed out.
* Returns the annotation directive with helpers stubbed out.
*/
*/
function
annotationDirective
()
{
function
annotationDirective
()
{
var
noop
=
function
()
{
return
''
};
var
noop
=
function
()
{
return
''
;
};
var
annotation
=
proxyquire
(
'../annotation'
,
{
var
annotation
=
proxyquire
(
'../annotation'
,
{
'../filter/document-domain'
:
noop
,
'../filter/document-domain'
:
noop
,
...
@@ -321,11 +321,9 @@ describe('annotation', function() {
...
@@ -321,11 +321,9 @@ describe('annotation', function() {
.
directive
(
'annotation'
,
annotationDirective
());
.
directive
(
'annotation'
,
annotationDirective
());
});
});
beforeEach
(
module
(
'h'
));
beforeEach
(
angular
.
mock
.
module
(
'h'
));
beforeEach
(
angular
.
mock
.
module
(
'h.templates'
));
beforeEach
(
module
(
'h.templates'
));
beforeEach
(
angular
.
mock
.
module
(
function
(
$provide
)
{
beforeEach
(
module
(
function
(
$provide
)
{
sandbox
=
sinon
.
sandbox
.
create
();
sandbox
=
sinon
.
sandbox
.
create
();
fakeAnnotationMapper
=
{
fakeAnnotationMapper
=
{
...
@@ -349,7 +347,7 @@ describe('annotation', function() {
...
@@ -349,7 +347,7 @@ describe('annotation', function() {
};
};
var
fakeFeatures
=
{
var
fakeFeatures
=
{
flagEnabled
:
sandbox
.
stub
().
returns
(
true
)
flagEnabled
:
sandbox
.
stub
().
returns
(
true
)
,
};
};
fakeFlash
=
{
fakeFlash
=
{
...
@@ -927,7 +925,7 @@ describe('annotation', function() {
...
@@ -927,7 +925,7 @@ describe('annotation', function() {
annotation
.
updated
=
null
;
annotation
.
updated
=
null
;
annotation
.
$create
=
function
()
{
annotation
.
$create
=
function
()
{
annotation
.
updated
=
(
new
Date
).
toString
();
annotation
.
updated
=
(
new
Date
()
).
toString
();
return
Promise
.
resolve
(
annotation
);
return
Promise
.
resolve
(
annotation
);
};
};
var
controller
=
createDirective
(
annotation
).
controller
;
var
controller
=
createDirective
(
annotation
).
controller
;
...
@@ -952,9 +950,9 @@ describe('annotation', function() {
...
@@ -952,9 +950,9 @@ describe('annotation', function() {
clock
.
tick
(
10
*
60
*
1000
);
clock
.
tick
(
10
*
60
*
1000
);
annotation
.
$update
=
function
()
{
annotation
.
$update
=
function
()
{
this
.
updated
=
(
new
Date
).
toString
();
this
.
updated
=
(
new
Date
()
).
toString
();
return
Promise
.
resolve
(
this
);
return
Promise
.
resolve
(
this
);
}
}
;
var
controller
=
createDirective
(
annotation
).
controller
;
var
controller
=
createDirective
(
annotation
).
controller
;
assert
.
equal
(
controller
.
relativeTimestamp
,
'ages ago'
);
assert
.
equal
(
controller
.
relativeTimestamp
,
'ages ago'
);
controller
.
edit
();
controller
.
edit
();
...
@@ -983,7 +981,7 @@ describe('annotation', function() {
...
@@ -983,7 +981,7 @@ describe('annotation', function() {
});
});
it
(
'is no longer updated after the scope is destroyed'
,
function
()
{
it
(
'is no longer updated after the scope is destroyed'
,
function
()
{
var
controller
=
createDirective
(
annotation
).
controller
;
createDirective
(
annotation
)
;
$scope
.
$digest
();
$scope
.
$digest
();
$scope
.
$destroy
();
$scope
.
$destroy
();
$timeout
.
flush
();
$timeout
.
flush
();
...
@@ -1038,10 +1036,14 @@ describe('annotation', function() {
...
@@ -1038,10 +1036,14 @@ describe('annotation', function() {
it
(
it
(
'doesn
\'
t call annotationMapper.delete() if the delete is cancelled'
,
'doesn
\'
t call annotationMapper.delete() if the delete is cancelled'
,
function
()
{
function
(
done
)
{
var
controller
=
createDirective
().
controller
;
var
parts
=
createDirective
()
;
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
false
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
false
);
assert
(
fakeAnnotationMapper
.
deleteAnnotation
.
notCalled
);
parts
.
controller
[
'delete'
]().
then
(
function
()
{
assert
.
notCalled
(
fakeAnnotationMapper
.
deleteAnnotation
);
done
();
});
$timeout
.
flush
();
}
}
);
);
...
@@ -1194,7 +1196,7 @@ describe('annotation', function() {
...
@@ -1194,7 +1196,7 @@ describe('annotation', function() {
'Passes group:<id> to the server when saving a new annotation'
,
'Passes group:<id> to the server when saving a new annotation'
,
function
()
{
function
()
{
fakeGroups
.
focused
=
function
()
{
fakeGroups
.
focused
=
function
()
{
return
{
id
:
'test-id'
}
return
{
id
:
'test-id'
}
;
};
};
var
annotation
=
{
var
annotation
=
{
user
:
'acct:fred@hypothes.is'
,
user
:
'acct:fred@hypothes.is'
,
...
@@ -1494,5 +1496,32 @@ describe('annotation', function() {
...
@@ -1494,5 +1496,32 @@ describe('annotation', function() {
'https://test.hypothes.is/stream?q=tag:atag'
);
'https://test.hypothes.is/stream?q=tag:atag'
);
});
});
});
});
describe
(
'annotation metadata'
,
function
()
{
function
findLink
(
directive
)
{
var
links
=
directive
.
element
[
0
]
.
querySelectorAll
(
'header .annotation-link'
);
return
links
[
links
.
length
-
1
];
}
it
(
'displays HTML links when in-context links are not available'
,
function
()
{
var
annotation
=
Object
.
assign
({},
fixtures
.
defaultAnnotation
(),
{
links
:
{
html
:
'https://test.hypothes.is/a/deadbeef'
},
});
var
directive
=
createDirective
(
annotation
);
assert
.
equal
(
findLink
(
directive
).
href
,
annotation
.
links
.
html
);
});
it
(
'displays in-context links when available'
,
function
()
{
var
annotation
=
Object
.
assign
({},
fixtures
.
defaultAnnotation
(),
{
links
:
{
html
:
'https://test.hypothes.is/a/deadbeef'
,
incontext
:
'https://hpt.is/deadbeef'
},
});
var
directive
=
createDirective
(
annotation
);
assert
.
equal
(
findLink
(
directive
).
href
,
annotation
.
links
.
incontext
);
});
});
});
});
});
});
h/static/scripts/test/annotation-fixtures.js
View file @
cba3f7f7
'use strict'
;
/**
/**
* Return a fake annotation with the basic properties filled in.
* Return a fake annotation with the basic properties filled in.
*/
*/
...
...
h/templates/client/annotation.html
View file @
cba3f7f7
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
target=
"_blank"
target=
"_blank"
title=
"{{vm.absoluteTimestamp}}"
title=
"{{vm.absoluteTimestamp}}"
ng-if=
"!vm.editing() && vm.updated()"
ng-if=
"!vm.editing() && vm.updated()"
ng-href=
"{{
::vm.serviceUrl}}a/{{vm.id()
}}"
ng-href=
"{{
vm.annotationURI
}}"
>
{{vm.relativeTimestamp}}
</a>
>
{{vm.relativeTimestamp}}
</a>
</header>
</header>
...
...
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