mirror of
https://github.com/alexwl/haskell-code-explorer.git
synced 2024-11-25 15:01:44 +03:00
Add an option to sort files by name/type
This commit is contained in:
parent
6b647e6446
commit
6954dbf99e
@ -35,23 +35,47 @@ const containsHaskellModule = function(node) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileExtension = function (filename) {
|
||||||
|
const idx = filename.lastIndexOf('.');
|
||||||
|
return (idx < 1) ? "" : filename.substr(idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
query: null,
|
query: null,
|
||||||
|
sortType: "alphabetical",
|
||||||
|
sortTypeObserver : Ember.observer('sortType',function() {
|
||||||
|
Ember.run.next(this,() => {
|
||||||
|
this.jstree.refresh();
|
||||||
|
});
|
||||||
|
}),
|
||||||
didInsertElement : function () {
|
didInsertElement : function () {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
const element = this.element.getElementsByClassName('file-tree')[0];
|
const element = this.element.getElementsByClassName('file-tree')[0];
|
||||||
|
const component = this;
|
||||||
|
|
||||||
const jstreeElement = Ember.$(element).jstree({
|
const jstreeElement = Ember.$(element).jstree({
|
||||||
'core' : {
|
'core' : {
|
||||||
'data' : directoryTreeToJsTree(this.get('packageId'),this.get('directoryTree'))
|
'data' : directoryTreeToJsTree(this.get('packageId'),this.get('directoryTree'))
|
||||||
},
|
},
|
||||||
"plugins" : [
|
"plugins" : [
|
||||||
"search"
|
"search",
|
||||||
|
"sort"
|
||||||
],
|
],
|
||||||
"search": {
|
"search": {
|
||||||
"case_insensitive": true,
|
"case_insensitive": true,
|
||||||
"show_only_matches" : true,
|
"show_only_matches" : true,
|
||||||
"show_only_matches_children": true
|
"show_only_matches_children": true
|
||||||
|
},
|
||||||
|
'sort' : function (a,b) {
|
||||||
|
const node1 = this.get_node(a).data;
|
||||||
|
const node2 = this.get_node(b).data;
|
||||||
|
if(component.get("sortType") === "alphabetical") {
|
||||||
|
return node1.name > node2.name;
|
||||||
|
} else {
|
||||||
|
const extendedName1 = (node1.tag === "Dir" ? "0" : "1") + fileExtension(node1.name) + node1.name;
|
||||||
|
const extendedName2 = (node2.tag === "Dir" ? "0" : "1") + fileExtension(node2.name) + node2.name;
|
||||||
|
return extendedName1 > extendedName2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -477,13 +477,13 @@ ul.autocomplete-items {
|
|||||||
top:0;
|
top:0;
|
||||||
left:0;
|
left:0;
|
||||||
right:0;
|
right:0;
|
||||||
height:50px;
|
height:65px;
|
||||||
margin:5px;
|
margin:5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-tree-content {
|
.file-tree-content {
|
||||||
position:absolute;
|
position:absolute;
|
||||||
top:50px;
|
top:70px;
|
||||||
left:0;
|
left:0;
|
||||||
right:0;
|
right:0;
|
||||||
bottom:0;
|
bottom:0;
|
||||||
|
@ -2,6 +2,18 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
{{input class="form-control" value=query placeholder="Filename"}}<a class="hide-file-tree" href="#" {{action "hide"}}>Hide</a>
|
{{input class="form-control" value=query placeholder="Filename"}}<a class="hide-file-tree" href="#" {{action "hide"}}>Hide</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
{{#radio-button
|
||||||
|
value="alphabetical"
|
||||||
|
groupValue=sortType}}
|
||||||
|
<span>Sort by name</span>
|
||||||
|
{{/radio-button}}
|
||||||
|
{{#radio-button
|
||||||
|
value="type"
|
||||||
|
groupValue=sortType}}
|
||||||
|
<span>Sort by type</span>
|
||||||
|
{{/radio-button}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="file-tree-content">
|
<div class="file-tree-content">
|
||||||
<div class="file-tree"></div>
|
<div class="file-tree"></div>
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user