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
2510769f
Commit
2510769f
authored
Oct 20, 2015
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2640 from robertknight/t91-sort_dropdown_refactor
Extract sort dropdown into own component
parents
35e22378
4739b664
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
15 deletions
+89
-15
app.coffee
h/static/scripts/app.coffee
+1
-0
sort-dropdown.js
h/static/scripts/directive/sort-dropdown.js
+11
-0
sort-dropdown-test.js
h/static/scripts/directive/test/sort-dropdown-test.js
+30
-0
util.js
h/static/scripts/directive/test/util.js
+27
-1
stream-controller.coffee
h/static/scripts/stream-controller.coffee
+1
-0
widget-controller.coffee
h/static/scripts/widget-controller.coffee
+1
-0
sort_dropdown.html
h/templates/client/sort_dropdown.html
+13
-0
viewer.html
h/templates/client/viewer.html
+5
-14
No files found.
h/static/scripts/app.coffee
View file @
2510769f
...
@@ -125,6 +125,7 @@ module.exports = angular.module('h', [
...
@@ -125,6 +125,7 @@ module.exports = angular.module('h', [
.
directive
(
'dropdownMenuBtn'
,
require
(
'./directive/dropdown-menu-btn'
))
.
directive
(
'dropdownMenuBtn'
,
require
(
'./directive/dropdown-menu-btn'
))
.
directive
(
'publishAnnotationBtn'
,
require
(
'./directive/publish-annotation-btn'
))
.
directive
(
'publishAnnotationBtn'
,
require
(
'./directive/publish-annotation-btn'
))
.
directive
(
'searchStatusBar'
,
require
(
'./directive/search-status-bar'
))
.
directive
(
'searchStatusBar'
,
require
(
'./directive/search-status-bar'
))
.
directive
(
'sortDropdown'
,
require
(
'./directive/sort-dropdown'
))
.
directive
(
'topBar'
,
require
(
'./directive/top-bar'
))
.
directive
(
'topBar'
,
require
(
'./directive/top-bar'
))
.
filter
(
'converter'
,
require
(
'./filter/converter'
))
.
filter
(
'converter'
,
require
(
'./filter/converter'
))
...
...
h/static/scripts/directive/sort-dropdown.js
0 → 100644
View file @
2510769f
module
.
exports
=
function
()
{
return
{
restrict
:
'E'
,
scope
:
{
sortBy
:
'='
,
sortOptions
:
'='
,
onChangeSortBy
:
'&'
,
},
templateUrl
:
'sort_dropdown.html'
,
}
}
h/static/scripts/directive/test/sort-dropdown-test.js
0 → 100644
View file @
2510769f
'use strict'
;
var
util
=
require
(
'./util'
);
describe
(
'sortDropdown'
,
function
()
{
before
(
function
()
{
angular
.
module
(
'app'
,
[])
.
directive
(
'sortDropdown'
,
require
(
'../sort-dropdown'
));
});
beforeEach
(
function
()
{
angular
.
mock
.
module
(
'app'
);
angular
.
mock
.
module
(
'h.templates'
);
});
it
(
'should update the sort mode on click'
,
function
()
{
var
changeSpy
=
sinon
.
spy
();
var
elem
=
util
.
createDirective
(
document
,
'sortDropdown'
,
{
sortOptions
:
[
'Newest'
,
'Oldest'
],
sortBy
:
'Newest'
,
onChangeSortBy
:
{
args
:
[
'sortBy'
],
callback
:
changeSpy
,
}
});
var
links
=
elem
.
find
(
'li'
);
angular
.
element
(
links
[
0
]).
click
();
assert
.
calledWith
(
changeSpy
,
'Newest'
);
});
});
h/static/scripts/directive/test/util.js
View file @
2510769f
...
@@ -23,6 +23,26 @@ function hyphenate(name) {
...
@@ -23,6 +23,26 @@ function hyphenate(name) {
*
*
* { attrA: 'initial-value', scopeProperty: scopeValue }
* { attrA: 'initial-value', scopeProperty: scopeValue }
*
*
* The initial value may be a callback function to invoke. eg:
*
* var domElement = createDirective('myComponent', {
* onEvent: function () {
* console.log('event triggered');
* }
* });
*
* If the callback accepts named arguments, these need to be specified
* via an object with 'args' and 'callback' properties:
*
* var domElement = createDirective('myComponent', {
* onEvent: {
* args: ['arg1'],
* callback: function (arg1) {
* console.log('callback called with arg', arg1);
* }
* }
* });
*
* @param {Document} document - The DOM Document to create the element in
* @param {Document} document - The DOM Document to create the element in
* @param {string} name - The name of the directive to instantiate
* @param {string} name - The name of the directive to instantiate
* @param {Object} [attrs] - A map of attribute names (in camelCase) to initial
* @param {Object} [attrs] - A map of attribute names (in camelCase) to initial
...
@@ -55,6 +75,8 @@ function createDirective(document, name, attrs, initialScope, initialHtml) {
...
@@ -55,6 +75,8 @@ function createDirective(document, name, attrs, initialScope, initialHtml) {
var
attrKey
=
key
;
var
attrKey
=
key
;
if
(
typeof
attrs
[
key
]
===
'function'
)
{
if
(
typeof
attrs
[
key
]
===
'function'
)
{
attrKey
+=
'()'
;
attrKey
+=
'()'
;
}
else
if
(
attrs
[
key
].
callback
)
{
attrKey
+=
'('
+
attrs
[
key
].
args
.
join
(
','
)
+
')'
;
}
}
templateElement
.
setAttribute
(
attrName
,
attrKey
);
templateElement
.
setAttribute
(
attrName
,
attrKey
);
});
});
...
@@ -62,7 +84,11 @@ function createDirective(document, name, attrs, initialScope, initialHtml) {
...
@@ -62,7 +84,11 @@ function createDirective(document, name, attrs, initialScope, initialHtml) {
// setup initial scope
// setup initial scope
Object
.
keys
(
attrs
).
forEach
(
function
(
key
)
{
Object
.
keys
(
attrs
).
forEach
(
function
(
key
)
{
if
(
attrs
[
key
].
callback
)
{
$scope
[
key
]
=
attrs
[
key
].
callback
;
}
else
{
$scope
[
key
]
=
attrs
[
key
];
$scope
[
key
]
=
attrs
[
key
];
}
});
});
// compile the template
// compile the template
...
...
h/static/scripts/stream-controller.coffee
View file @
2510769f
...
@@ -51,6 +51,7 @@ module.exports = class StreamController
...
@@ -51,6 +51,7 @@ module.exports = class StreamController
fetch
(
20
)
fetch
(
20
)
$scope
.
isStream
=
true
$scope
.
isStream
=
true
$scope
.
sortOptions
=
[
'Newest'
,
'Oldest'
]
$scope
.
sort
.
name
=
'Newest'
$scope
.
sort
.
name
=
'Newest'
$scope
.
threadRoot
=
threading
.
root
$scope
.
threadRoot
=
threading
.
root
$scope
.
loadMore
=
fetch
$scope
.
loadMore
=
fetch
h/static/scripts/widget-controller.coffee
View file @
2510769f
...
@@ -12,6 +12,7 @@ module.exports = class WidgetController
...
@@ -12,6 +12,7 @@ module.exports = class WidgetController
)
->
)
->
$scope
.
isStream
=
true
$scope
.
isStream
=
true
$scope
.
threadRoot
=
threading
.
root
$scope
.
threadRoot
=
threading
.
root
$scope
.
sortOptions
=
[
'Newest'
,
'Oldest'
,
'Location'
]
@
chunkSize
=
200
@
chunkSize
=
200
loaded
=
[]
loaded
=
[]
...
...
h/templates/client/sort_dropdown.html
0 → 100644
View file @
2510769f
<span
class=
"ng-cloak"
dropdown
keyboard-nav
>
<span
role=
"button"
data-toggle=
"dropdown"
dropdown-toggle
>
Sorted by {{sortBy | lowercase}}
<i
class=
"h-icon-arrow-drop-down"
></i>
</span>
<ul
class=
"dropdown-menu pull-right"
role=
"menu"
>
<li
ng-repeat=
"sortOption in sortOptions"
ng-click=
"onChangeSortBy({sortBy: sortOption})"
><a
class=
"dropdown-menu__link"
href=
""
>
{{sortOption}}
</a></li>
</ul>
</span>
h/templates/client/viewer.html
View file @
2510769f
...
@@ -11,20 +11,11 @@
...
@@ -11,20 +11,11 @@
on-clear-selection=
"clearSelection()"
>
on-clear-selection=
"clearSelection()"
>
</search-status-bar>
</search-status-bar>
<li
ng-show=
"isStream"
>
<li
ng-show=
"isStream"
>
<span
class=
"ng-cloak"
dropdown
keyboard-nav
>
<sort-dropdown
<span
role=
"button"
sort-by=
"sort.name"
data-toggle=
"dropdown"
sort-options=
"sortOptions"
dropdown-toggle
>
on-change-sort-by=
"sort.name = sortBy"
>
Sorted by {{sort.name | lowercase}}
</sort-dropdown>
<i
class=
"h-icon-arrow-drop-down"
></i>
</span>
<ul
class=
"dropdown-menu pull-right"
role=
"menu"
>
<li
ng-click=
"sort.name = option"
ng-hide=
"option == 'Location' && !isSidebar"
ng-repeat=
"option in ['Newest', 'Oldest', 'Location']"
><a
class=
"dropdown-menu__link"
href=
""
>
{{option}}
</a></li>
</ul>
</span>
</li>
</li>
<li
id=
"{{vm.id}}"
<li
id=
"{{vm.id}}"
class=
"paper thread"
class=
"paper thread"
...
...
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