Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root Workspace Sort Dropdown (Alphabetical) #3481

Open
wants to merge 53 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
eb536e0
Added basic drop down box for sort by
sharlotteg May 2, 2022
774aa5a
alphabeticSort
a1765159 May 2, 2022
3f17f7a
Merge branch 'develop' into createDropDown
sharlotteg May 2, 2022
4c1f092
fixed merge conflicts
May 2, 2022
ead85de
Added dummy function to test drop down
sharlotteg May 2, 2022
018ebd8
alphabeticSort function
a1765159 May 2, 2022
d7ab477
function parameter typing
a1765159 May 2, 2022
343d65e
moved function to its own .ts file
a1765159 May 2, 2022
0482c61
minor reformatting for passing eslint
May 3, 2022
8f18e02
added basic css formatting
May 3, 2022
e99fff9
Added styling to sort by drop down to be right aligned
sharlotteg May 4, 2022
cc2c81b
Usage of flex containers for dropdown positioning. Yet to confirm unw…
May 5, 2022
dcead56
file set-up
nidadavolu4 May 5, 2022
c37b974
base test-file
nidadavolu4 May 5, 2022
1bf4311
More test cases- file not functional
nidadavolu4 May 5, 2022
dc33cf4
fixed CSS to achieve expected behaviour
May 6, 2022
dc85886
Increased width of dropdown to see more of word
sharlotteg May 6, 2022
c4009fe
file name change
nidadavolu4 May 6, 2022
c8eacfe
changes done
May 6, 2022
6216590
sorting based on their names
a1765159 May 6, 2022
aa88475
changes done
May 6, 2022
6cb7329
changes done
May 6, 2022
fd2e3e5
changes done
May 6, 2022
3304f22
changes done
May 6, 2022
dcf1540
changes done
May 6, 2022
03eef22
changes done
May 6, 2022
c7d7c1f
changes done
May 12, 2022
053c43f
Merge branch 'createDropDown' of https://github.com/csjasonl/Zettlr i…
May 12, 2022
986aa70
prepared file-tree.vue for insertion of alphabeticSort code
May 12, 2022
88a698b
moved sort function css elements to universal body
May 12, 2022
0360de4
changes done
May 12, 2022
a6a1f49
Deleted alphabeticSort.ts
mo0nmann May 13, 2022
f178d64
Removed redundant code
mo0nmann May 13, 2022
082939d
Merge pull request #2 from csjasonl/unit-testing
mo0nmann May 13, 2022
9e1eb8a
Merge branch 'createDropDown' into alphabeticSort
mo0nmann May 13, 2022
51bfafb
Merge pull request #3 from csjasonl/alphabeticSort
mo0nmann May 13, 2022
e6873a9
Implemented sort handler
mo0nmann May 13, 2022
3ef69a6
Merge pull request #4 from csjasonl/createDropDown
mo0nmann May 13, 2022
b346017
added docmentation and addressed linting
a1765159 May 16, 2022
90fedfd
minor refactoring
a1765159 May 16, 2022
1eaac2b
renamed function/file
a1765159 May 16, 2022
411f271
addressed linting errors and warnings
a1765159 May 16, 2022
b5df383
refactoring & prepared for translation
May 16, 2022
04a513a
compare parent directories instead of path
a1765159 May 16, 2022
c48c6a9
added test case for the example from issue
a1765159 May 16, 2022
fcac078
reverted back due to null object error and windows backslash
a1765159 May 18, 2022
2f3d24d
Merge branch 'develop' of https://github.com/csjasonl/Zettlr into dev…
May 18, 2022
ec219fb
merged upstream develop
May 18, 2022
87311a3
Added to CHANGELOG.md
sharlotteg May 18, 2022
8a87615
Update CHANGELOG.md
csjasonl May 19, 2022
69110f7
Update package.json
csjasonl May 19, 2022
1e3808c
Update yarn.lock
csjasonl May 19, 2022
5f6295b
Removed redundant/missing function
csjasonl May 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## GUI and Functionality

- **New Feature**: Users can use a drop down to order root directories (currently only alphabetically ascending/descending )
- **New Feature**: You can hide the toolbar button and words count block in the
preference
- Added "Copy filename", "Copy path" and "Copy ID" to document tabs context
Expand Down
63 changes: 59 additions & 4 deletions source/win-main/file-manager/file-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{{ noResultsMessage }}
</div>
</div>

<div v-show="getFiles.length > 0" id="directories-files-header">
<clr-icon
shape="file"
Expand All @@ -33,6 +32,20 @@
shape="tree-view"
role="presentation"
></clr-icon>{{ workspaceSectionHeading }}
<select id="sort-header" v-model="sortSelection">
<option
value="null"
selected
>
Sort By{{ sortByOption }}
</option>
<option value="AlphaA">
Alphabetical (Ascending){{ alphabeticalAscOption }}
</option>
<option value="AlphaD">
Alphabetical (Descending){{ alphabeticalDescOption }}
</option>
</select>
</div>
<TreeItem
v-for="item in getDirectories"
Expand Down Expand Up @@ -75,6 +88,7 @@ import matchQuery from './util/match-query'
import matchTree from './util/match-tree'
import { defineComponent } from 'vue'
import { MDFileMeta, CodeFileMeta, DirMeta } from '@dts/common/fsal'
import sortDirectories from './util/sort-directories'

const ipcRenderer = window.ipc

Expand All @@ -94,7 +108,9 @@ export default defineComponent({
}
},
data: function () {
return {}
return {
sortSelection: null
}
},
computed: {
fileTree: function (): Array<MDFileMeta|CodeFileMeta|DirMeta> {
Expand Down Expand Up @@ -136,7 +152,12 @@ export default defineComponent({
return this.getFilteredTree.filter(item => item.type !== 'directory') as Array<MDFileMeta|CodeFileMeta>
},
getDirectories: function (): DirMeta[] {
return this.getFilteredTree.filter(item => item.type === 'directory') as DirMeta[]
if (this.sortSelection === 'AlphaA' || this.sortSelection === 'AlphaD') {
let temp = this.getFilteredTree.filter(item => item.type === 'directory') as DirMeta[]
return sortDirectories(temp, this.sortSelection) as DirMeta[]
} else {
return this.getFilteredTree.filter(item => item.type === 'directory') as DirMeta[]
}
},
fileSectionHeading: function (): string {
return trans('gui.files')
Expand All @@ -149,6 +170,15 @@ export default defineComponent({
},
noResultsMessage: function () {
return trans('gui.no_search_results')
},
sortByOption: function () {
return trans('gui.sort_by_option')
},
alphabeticalAscOption: function () {
return trans('gui.alphabetical_asc_option')
},
alphabeticalDescOption: function () {
return trans('gui.alphabetical_desc_option')
}
},
methods: {
Expand Down Expand Up @@ -194,6 +224,9 @@ body {
margin-right: 3px;
vertical-align: bottom;
}
display: flex;
flex-flow: row wrap;
align-items: center;
}

.list-item {
Expand All @@ -218,6 +251,16 @@ body {
}
}
}

#sort-header {
font-size: 11px;
width: 12vw;
padding: 0px 0px 0px 0px;
margin-top: 0px;
margin-bottom: 0px;
margin-right: 5px;
margin-left: auto;
}
}

body.darwin {
Expand All @@ -231,7 +274,6 @@ body.darwin {
font-weight: bold;
font-size: inherit;
margin: 20px 0px 5px 10px;

clr-icon { display: none; }
}
}
Expand All @@ -246,9 +288,22 @@ body.win32 {
font-size: 11px;
padding: 5px 0px 5px 10px;
margin: 0px 0px 5px 0px;
//display: flex;
//flex-flow: row wrap;
//align-items: center;
}
}

// #sort-header {
// font-size: 11px;
// width: 12vw;
// padding: 0px 0px 0px 0px;
// margin-top: 0px;
// margin-bottom: 0px;
// margin-right: 5px;
// margin-left: auto;
// }

&.dark {
#file-tree {
background-color: rgb(30, 30, 40);
Expand Down
55 changes: 55 additions & 0 deletions source/win-main/file-manager/util/sort-directories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @ignore
* BEGIN HEADER
*
* Contains: sortDirectories
* CVM-Role: Utility Function
* Maintainer: Hendrik Erz
* License: GNU GPL v3
*
* Description: A utility function that sorts a given array of directories.
* The function should be passed the array and a string determining
* how to sort the array.
*
* END HEADER
*/

import { DirMeta } from '@dts/common/fsal'

/**
* Returns a sorted array of directories
*
* @param {DirMeta} dirArray The directories to be sorted
* @param {string} sortBy How to sort the directories
*
* @return {DirMeta[]} The sorted array
*/
export default function sortDirectories (dirArray: DirMeta[], sortBy: string): DirMeta[] {
function compare (a: DirMeta, b: DirMeta): number {
// get names of directory in lowercase due to ASCII values
let nameA = a.name.toLowerCase()
let nameB = b.name.toLowerCase()

// if directories have the same name, compare the names of the directory they are in
if (nameA === nameB) {
let dirA = a.dir
let dirB = b.dir
if (dirA < dirB) { return -1 }
if (dirA > dirB) { return 1 }

// else compare regularly
} else {
if (nameA < nameB) { return -1 }
if (nameA > nameB) { return 1 }
}
return 0
}

// return array in reverse alphabetical order
if (sortBy === 'AlphaD') {
return dirArray.sort(compare).reverse()
}

// return array in alphabetical order
return dirArray.sort(compare)
}
56 changes: 56 additions & 0 deletions test/sort-directories.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable no-undef */
/**
* @ignore
* BEGIN HEADER
*
* Contains: sortDirectories tester
* CVM-Role: TESTING
* Maintainer: Hendrik Erz
* License: GNU GPL v3
*
* Description: This file tests a component of Zettlr.
*
* END HEADER
*/

import sortDirectories from '../source/win-main/file-manager/util/sort-directories'
import { deepStrictEqual } from 'assert'
import { DirMeta } from '@dts/common/fsal'

const sort = 'AlphaD'

const sortDirectoriesTesters = [
{
input: [{ name: 'titled', dir: 'Documents' }, { name: 'titled', dir: 'Desktop' }],
expected: [{ name: 'titled', dir: 'Documents' }, { name: 'titled', dir: 'Desktop' }],
message: `Should return {name: 'titled', dir: 'Documents' } , { name: 'titled', dir: 'Desktop' }`
},
{
input: [{ name: 'untitled', dir: 'Downloads' }, { name: 'titled', dir: 'Documents' }],
expected: [{ name: 'untitled', dir: 'Downloads' }, { name: 'titled', dir: 'Documents' }],
message: `Should return { name: 'untitled', dir: 'Downloads' } , { name: 'titled', dir: 'Documents' }`
},
{
input: [{ name: 'first', dir: 'Applications' }, { name: 'first', dir: 'Music' }],
expected: [{ name: 'first', dir: 'Music' }, { name: 'first', dir: 'Applications' }],
message: `Should return { name: 'first', dir: 'Music' } , { name: 'first', dir: 'Applications' }`
},
{
input: [{ name: 'file', dir: 'Test' }, { name: 'file', dir: 'Beats' }],
expected: [{ name: 'file', dir: 'Test' }, { name: 'file', dir: 'Beats' }],
message: `Should return { name: 'file', dir: 'Test' } , { name: 'file', dir: 'Beats' }`
},
{
input: [{ name: 'Root', dir: '/home/B' }, { name: 'Root', dir: '/home/D' }, { name: 'Root', dir: '/home/C' }, { name: 'Root', dir: '/home/A' }],
expected: [{ name: 'Root', dir: '/home/D' }, { name: 'Root', dir: '/home/C' }, { name: 'Root', dir: '/home/B' }, { name: 'Root', dir: '/home/A' }],
message: `Should return { name: 'Root', dir: '/home/D' }, { name: 'Root', dir: '/home/C' }, { name: 'Root', dir: '/home/B' }, { name: 'Root', dir: '/home/A' }`
}
]

describe('Utility#sortDirectories()', function () {
for (const test of sortDirectoriesTesters) {
it(`${test.message}`, function () {
deepStrictEqual(sortDirectories(test.input as DirMeta[], sort), test.expected)
})
}
})