-
Search
+
@@ -14,18 +45,98 @@ const componentOptions = {
components: {
},
watch: {
+ config() {
+ this.makeTitle();
+ },
},
};
class Search {
_options = componentOptions;
+ collection = '';
+ projectName = '';
+
+ //search fields
+ author = '';
+ series = '';
+ title = '';
+ genre = '';
+ lang = '';
created() {
this.commit = this.$store.commit;
}
mounted() {
+ this.api = this.$root.api;
+
+ this.$refs.authorInput.focus();
+
+ this.refresh();//no await
}
+ get config() {
+ return this.$store.state.config;
+ }
+
+ makeTitle() {
+ const collection = this.config.dbConfig.inpxInfo.collection.split('\n');
+ this.collection = collection[0].trim();
+
+ this.projectName = `${this.config.name} v${this.config.version}`;
+ }
+
+ showSearchHelp() {
+ this.$root.stdDialog.alert(`
+
+ Здесь должна быть подсказка
+
+ `, 'Подсказка', {iconName: 'la la-info-circle'});
+ }
+
+ showCollectionInfo() {
+ this.$root.stdDialog.alert(`
+
+ Здесь должна быть информация о коллекции
+
+ `, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
+ }
+
+ async updateTableData() {
+ }
+
+ async refresh() {
+ const newQuery = {
+ author: this.author,
+ series: this.series,
+ title: this.title,
+ genre: this.genre,
+ lang: this.lang,
+ };
+
+ this.queryExecute = newQuery;
+
+ if (this.refreshing)
+ return;
+
+ this.refreshing = true;
+ try {
+ while (this.queryExecute) {
+ const query = this.queryExecute;
+ this.queryExecute = null;
+
+ try {
+ this.searchResult = await this.api.search(query);
+ } catch (e) {
+ this.$root.stdDialog.alert(e.message, 'Ошибка');
+ return;
+ }
+
+ this.updateTableData();//no await
+ }
+ } finally {
+ this.refreshing = false;
+ }
+ }
}
export default vueComponent(Search);
@@ -35,4 +146,18 @@ export default vueComponent(Search);
diff --git a/client/share/LockQueue.js b/client/share/LockQueue.js
new file mode 100644
index 0000000..ed350c5
--- /dev/null
+++ b/client/share/LockQueue.js
@@ -0,0 +1,53 @@
+class LockQueue {
+ constructor(queueSize) {
+ this.queueSize = queueSize;
+ this.freed = true;
+ this.waitingQueue = [];
+ }
+
+ //async
+ get(take = true) {
+ return new Promise((resolve, reject) => {
+ if (this.freed) {
+ if (take)
+ this.freed = false;
+ resolve();
+ return;
+ }
+
+ if (this.waitingQueue.length < this.queueSize) {
+ this.waitingQueue.push({resolve, reject});
+ } else {
+ reject(new Error('Lock queue is too long'));
+ }
+ });
+ }
+
+ ret() {
+ if (this.waitingQueue.length) {
+ this.waitingQueue.shift().resolve();
+ } else {
+ this.freed = true;
+ }
+ }
+
+ //async
+ wait() {
+ return this.get(false);
+ }
+
+ retAll() {
+ while (this.waitingQueue.length) {
+ this.waitingQueue.shift().resolve();
+ }
+ }
+
+ errAll(error = 'rejected') {
+ while (this.waitingQueue.length) {
+ this.waitingQueue.shift().reject(new Error(error));
+ }
+ }
+
+}
+
+export default LockQueue;
\ No newline at end of file
diff --git a/client/store/root.js b/client/store/root.js
index 1cd73ad..94ff9a7 100644
--- a/client/store/root.js
+++ b/client/store/root.js
@@ -1,6 +1,6 @@
// initial state
const state = {
- apiError: null,
+ config: {},
};
// getters
@@ -11,8 +11,8 @@ const actions = {};
// mutations
const mutations = {
- setApiError(state, value) {
- state.apiError = value;
+ setConfig(state, value) {
+ state.config = value;
},
};