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

Added search bar at the top of the file manager and filter files and … #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/components/blocks/NavbarBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@
</button>
</div>
</div>
<div class="col-4">
<div class="d-flex border rounded">
<input
type="text"
class="border-0 form-control search-input"
placeholder="Search files and folders"
:value="search"
@input="setSearch"
/>

<button class="border-0 mr-2" type="button" @click="setSearch('')">
<i class="bi bi-x navbar-icon"></i>
</button>
</div>
</div>
<div class="col-auto text-right">
<div class="btn-group" role="group">
<button
Expand Down Expand Up @@ -247,6 +262,13 @@ export default {
hiddenFiles() {
return this.$store.state.fm.settings.hiddenFiles;
},

/**
* Search string
*/
search() {
return this.$store.state.fm[this.activeManager].search;
}
},
methods: {
/**
Expand Down Expand Up @@ -353,6 +375,15 @@ export default {

this.$store.commit('fm/screenToggle');
},

/**
* Set search string
* @param {any} e
*/
setSearch(e) {
let newSearch = e == ''? '' : e.target.value;
this.$store.dispatch(`fm/${this.activeManager}/searchFilesOrFolders`, newSearch);
},
},
};
</script>
Expand All @@ -364,5 +395,10 @@ export default {
.col-auto > .btn-group:not(:last-child) {
margin-right: 0.4rem;
}

.search-input:focus{
outline: none;
box-shadow: none;
}
}
</style>
9 changes: 9 additions & 0 deletions src/store/manager/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ export default {
commit('pointerForward');
},

/**
* Search files and folders
* @param commit
* @param newSearch
*/
searchFilesOrFolders({ commit }, newSearch) {
commit('setSearch', newSearch);
},

/**
* Sort data by field
* @param context
Expand Down
12 changes: 8 additions & 4 deletions src/store/manager/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export default {
* @param rootState
*/
files(state, getters, rootState) {
const files = state.files.filter((item) => item.basename.match(new RegExp(`^.*${state.search}.*`, 'i')));

if (rootState.fm.settings.hiddenFiles) {
return state.files;
return files;
}

return state.files.filter((item) => item.basename.match(/^([^.]).*/i));
return files.filter((item) => item.basename.match(/^([^.]).*/i));
},

/**
Expand All @@ -21,11 +23,13 @@ export default {
* @returns {*}
*/
directories(state, getters, rootState) {
const directories = state.directories.filter((item) => item.basename.match(new RegExp(`^.*${state.search}.*`, 'i')));

if (rootState.fm.settings.hiddenFiles) {
return state.directories;
return directories;
}

return state.directories.filter((item) => item.basename.match(/^([^.]).*/i));
return directories.filter((item) => item.basename.match(/^([^.]).*/i));
},

/**
Expand Down
9 changes: 9 additions & 0 deletions src/store/manager/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ export default {
state.sort.direction = direction;
},

/**
* Set search string
* @param state
* @param newSearch
*/
setSearch(state, newSearch) {
state.search = newSearch;
},

/**
* Reset sort settings
* @param state
Expand Down
3 changes: 3 additions & 0 deletions src/store/manager/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default {

// view type - table or grid - (default - table)
viewType: 'table',

// search files and folders
search: "",
};
},
mutations,
Expand Down