mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Converted entity-dash from vue to a component
This commit is contained in:
59
resources/js/components/entity-search.js
Normal file
59
resources/js/components/entity-search.js
Normal file
@ -0,0 +1,59 @@
|
||||
import {onSelect} from "../services/dom";
|
||||
|
||||
/**
|
||||
* Class EntitySearch
|
||||
* @extends {Component}
|
||||
*/
|
||||
class EntitySearch {
|
||||
setup() {
|
||||
this.entityId = this.$opts.entityId;
|
||||
this.entityType = this.$opts.entityType;
|
||||
|
||||
this.contentView = this.$refs.contentView;
|
||||
this.searchView = this.$refs.searchView;
|
||||
this.searchResults = this.$refs.searchResults;
|
||||
this.searchInput = this.$refs.searchInput;
|
||||
this.searchForm = this.$refs.searchForm;
|
||||
this.clearButton = this.$refs.clearButton;
|
||||
this.loadingBlock = this.$refs.loadingBlock;
|
||||
|
||||
this.setupListeners();
|
||||
}
|
||||
|
||||
setupListeners() {
|
||||
this.searchInput.addEventListener('change', this.runSearch.bind(this));
|
||||
this.searchForm.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
this.runSearch();
|
||||
});
|
||||
|
||||
onSelect(this.clearButton, this.clearSearch.bind(this));
|
||||
}
|
||||
|
||||
runSearch() {
|
||||
const term = this.searchInput.value.trim();
|
||||
if (term.length === 0) {
|
||||
return this.clearSearch();
|
||||
}
|
||||
|
||||
this.searchView.classList.remove('hidden');
|
||||
this.contentView.classList.add('hidden');
|
||||
this.loadingBlock.classList.remove('hidden');
|
||||
|
||||
const url = window.baseUrl(`/search/${this.entityType}/${this.entityId}`);
|
||||
window.$http.get(url, {term}).then(resp => {
|
||||
this.searchResults.innerHTML = resp.data;
|
||||
}).catch(console.error).then(() => {
|
||||
this.loadingBlock.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
clearSearch() {
|
||||
this.searchView.classList.add('hidden');
|
||||
this.contentView.classList.remove('hidden');
|
||||
this.loadingBlock.classList.add('hidden');
|
||||
this.searchInput.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
export default EntitySearch;
|
@ -1,44 +0,0 @@
|
||||
let data = {
|
||||
id: null,
|
||||
type: '',
|
||||
searching: false,
|
||||
searchTerm: '',
|
||||
searchResults: '',
|
||||
};
|
||||
|
||||
let computed = {
|
||||
|
||||
};
|
||||
|
||||
let methods = {
|
||||
|
||||
searchBook() {
|
||||
if (this.searchTerm.trim().length === 0) return;
|
||||
this.searching = true;
|
||||
this.searchResults = '';
|
||||
let url = window.baseUrl(`/search/${this.type}/${this.id}`);
|
||||
url += `?term=${encodeURIComponent(this.searchTerm)}`;
|
||||
this.$http.get(url).then(resp => {
|
||||
this.searchResults = resp.data;
|
||||
});
|
||||
},
|
||||
|
||||
checkSearchForm() {
|
||||
this.searching = this.searchTerm > 0;
|
||||
},
|
||||
|
||||
clearSearch() {
|
||||
this.searching = false;
|
||||
this.searchTerm = '';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function mounted() {
|
||||
this.id = Number(this.$el.getAttribute('entity-id'));
|
||||
this.type = this.$el.getAttribute('entity-type');
|
||||
}
|
||||
|
||||
export default {
|
||||
data, computed, methods, mounted
|
||||
};
|
@ -4,14 +4,12 @@ function exists(id) {
|
||||
return document.getElementById(id) !== null;
|
||||
}
|
||||
|
||||
import entityDashboard from "./entity-dashboard";
|
||||
import imageManager from "./image-manager";
|
||||
import tagManager from "./tag-manager";
|
||||
import attachmentManager from "./attachment-manager";
|
||||
import pageEditor from "./page-editor";
|
||||
|
||||
let vueMapping = {
|
||||
'entity-dashboard': entityDashboard,
|
||||
'image-manager': imageManager,
|
||||
'tag-manager': tagManager,
|
||||
'attachment-manager': attachmentManager,
|
||||
|
Reference in New Issue
Block a user