438 lines
12 KiB
JavaScript
438 lines
12 KiB
JavaScript
import apis from "~/apis/searchApi";
|
|
import adminApi from "~/apis/adminApi";
|
|
import settingsApi from "~/apis/settingsApi.js";
|
|
import { mapState, mapActions } from "pinia";
|
|
import stopWordContextMenu from "~/json/entity/json/stopWordContextMenu.json";
|
|
|
|
|
|
export const repetitionWordsMixin = {
|
|
props: ["selectedItem"],
|
|
emits: ["update-list", "close-modal", "delete-item"],
|
|
|
|
mounted() {
|
|
this.httpService = new HttpService(import.meta.env.VITE_REPO_BASE_URL);
|
|
this.entity = this.selectedItem;
|
|
// console.log(this.selectedItem);
|
|
this.getWordsWeight();
|
|
//this.getStopWordsData();
|
|
},
|
|
data() {
|
|
return {
|
|
counter: 0,
|
|
number: 5,
|
|
ret: [],
|
|
buttonLoading: false,
|
|
showButton: true,
|
|
currentTab: 1,
|
|
currentPage: 1,
|
|
fetchingData: false,
|
|
stopWords: "",
|
|
words1: [],
|
|
words2: [],
|
|
words3: [],
|
|
stopWordContextMenu: stopWordContextMenu,
|
|
buttonLoading: false,
|
|
fetchingData: false,
|
|
validationText: false,
|
|
busy: false,
|
|
startIndex: "",
|
|
showtext: true,
|
|
endIndex: "",
|
|
selectedWords: ["اقتصاد", "فرهنگ", "فرهنگی"],
|
|
repeats: [
|
|
{
|
|
id: 1,
|
|
title: "اقتصاد",
|
|
count: 4,
|
|
},
|
|
{
|
|
id: 2,
|
|
title: "اقتصاد 2",
|
|
count: 2,
|
|
},
|
|
{
|
|
id: 3,
|
|
title: "اقتصاد 3",
|
|
count: 10,
|
|
},
|
|
{
|
|
id: 4,
|
|
title: "اقتصاد 4",
|
|
count: 8,
|
|
},
|
|
{
|
|
id: 5,
|
|
title: "اقتصاد 5",
|
|
count: 0,
|
|
},
|
|
],
|
|
limit: 50,
|
|
indexWord: [0, 0, 0],
|
|
lenWords: [0, 0, 0],
|
|
oneWordArray1: [],
|
|
oneWordArray2: [],
|
|
oneWordArray3: [],
|
|
busy: false,
|
|
httpService: undefined,
|
|
entity: undefined,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapState("entity", [
|
|
"listEntityGetter",
|
|
"selectedItemEntityGetter",
|
|
|
|
"activeEntityViewSchemaGetter",
|
|
"entityViewSchemaGetter",
|
|
"activeTabGetter",
|
|
]),
|
|
...mapState(["currntUser"]),
|
|
buttonText() {
|
|
return this.selectedItem?.id || this.selectedItem?.guid
|
|
? "بروزرسانی"
|
|
: "ثبت";
|
|
},
|
|
},
|
|
watch: {
|
|
selectedItemEntityGetter(newVal) {
|
|
this.entity = newVal;
|
|
this.selectedItem = newVal;
|
|
this.getWordsWeight();
|
|
//this.getStopWordsData();
|
|
},
|
|
stopWords(newQuestion, oldQuestion) {
|
|
if (newQuestion.includes("?")) {
|
|
this.getWordsWeight();
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
...mapActions("entity", ["SET_REPEATED_WORDS"]),
|
|
mehdiTest() {},
|
|
// new
|
|
getPosts(ngram, wordsList) {
|
|
let index = ngram - 1;
|
|
if (this.indexWord[index] >= wordsList.length) return [];
|
|
let count =
|
|
this.indexWord[index] + this.limit >= wordsList.length
|
|
? wordsList.length - this.indexWord[index]
|
|
: this.limit;
|
|
let slicedArrray = wordsList.slice(
|
|
this.indexWord[index],
|
|
this.indexWord[index] + count
|
|
);
|
|
this.indexWord[index] += count;
|
|
this.busy = false;
|
|
return slicedArrray;
|
|
},
|
|
|
|
loadMore(index, $event) {
|
|
// const listElm = document.querySelector("#overlay-plugin2");
|
|
const listElm = $event.target;
|
|
const vm = this;
|
|
if (vm.busy) return;
|
|
|
|
if (
|
|
Math.ceil(listElm.scrollTop) + listElm.clientHeight >=
|
|
listElm.scrollHeight
|
|
) {
|
|
this.busy = true;
|
|
|
|
if (this.lenWords[index] > this.indexWord[index]) {
|
|
setTimeout(() => {
|
|
if (index == 1)
|
|
this.oneWordArray1 = [
|
|
...this.oneWordArray1,
|
|
...this.getPosts(index, this.words1),
|
|
];
|
|
else if (index == 2)
|
|
this.oneWordArray2 = [
|
|
...this.oneWordArray2,
|
|
...this.getPosts(index, this.words2),
|
|
];
|
|
else if (index == 3)
|
|
this.oneWordArray3 = [
|
|
...this.oneWordArray3,
|
|
...this.getPosts(index, this.words3),
|
|
];
|
|
}, 1000);
|
|
} else {
|
|
vm.mySwalToast({
|
|
title: "کاربر محترم",
|
|
|
|
html: "دیگر رکوردی جهت بارگزاری وجود ندارد.",
|
|
icon: "info",
|
|
position: "bottom-start",
|
|
});
|
|
vm.busy = false;
|
|
}
|
|
} else vm.busy = false;
|
|
},
|
|
|
|
// new
|
|
setListWords() {
|
|
let words = structuredClone(this.repeats);
|
|
this.words1 = Object.entries(words.word1);
|
|
this.words2 = Object.entries(words.word2);
|
|
this.words3 = Object.entries(words.word3);
|
|
|
|
this.indexWord = [0, 0, 0];
|
|
this.lenWords = [
|
|
this.words1.length,
|
|
this.words2.length,
|
|
this.words3.length,
|
|
];
|
|
this.oneWordArray1 = this.getPosts(1, this.words1);
|
|
this.oneWordArray2 = this.getPosts(2, this.words2);
|
|
this.oneWordArray3 = this.getPosts(3, this.words3);
|
|
|
|
this.counter++;
|
|
},
|
|
removeInStopWords(key) {
|
|
var vm = this;
|
|
this.fetchingData = true;
|
|
let url = settingsApi.user.remove_stopword;
|
|
url += this.currentUser.user_id + "/" + key;
|
|
this.httpService
|
|
.postRequest(url)
|
|
.then((response) => {})
|
|
.catch((error) => {})
|
|
.finally(() => {
|
|
vm.fetchingData = false;
|
|
this.removactiveCurrent();
|
|
});
|
|
},
|
|
removeItem(key, index) {
|
|
this.appendStopWords(key);
|
|
this.activeCurrent("id-" + index);
|
|
},
|
|
appendStopWords(key) {
|
|
var vm = this;
|
|
this.fetchingData = true;
|
|
let url = settingsApi.user.append_stopword;
|
|
url += this.currentUser.user_id + "/" + key;
|
|
|
|
// this.httpService.post('setting/stop_words/append/'+this.currentUser.user_id+'/'+text)
|
|
this.httpService
|
|
.postRequest(url)
|
|
.then((response) => {
|
|
// if (response.hits.hits.length) {
|
|
// this.stopWords = response.hits.hits[0]._source.value;
|
|
// this.data = response.hits.hits[0]._source;
|
|
// } else {
|
|
this.getAdminData();
|
|
// }
|
|
})
|
|
.catch((error) => {})
|
|
.finally(() => {
|
|
vm.fetchingData = false;
|
|
// this.save();
|
|
});
|
|
},
|
|
activeCurrent(tagId) {
|
|
if ((this.currentTab = 1)) {
|
|
const listGroupItem = document.getElementsByClassName("m1");
|
|
listGroupItem.forEach((item) => {
|
|
item.classList.remove("active");
|
|
});
|
|
const target = document.getElementById(tagId);
|
|
target.classList.add("change-active");
|
|
} else if ((this.currentTab = 2)) {
|
|
const listGroupItem = document.getElementsByClassName("m2");
|
|
listGroupItem.forEach((item) => {
|
|
item.classList.remove("active");
|
|
});
|
|
const target = document.getElementById(tagId);
|
|
target.classList.add("change-active");
|
|
} else if ((this.currentTab = 3)) {
|
|
const listGroupItem = document.getElementsByClassNam("m3");
|
|
listGroupItem.forEach((item) => {
|
|
item.classList.remove("active");
|
|
});
|
|
const target = document.getElementById(tagId);
|
|
target.classList.add("change-active");
|
|
}
|
|
},
|
|
savedata() {
|
|
this.removactiveCurrent(); //حذف استایل
|
|
this.getWordsWeight(); //1to3
|
|
//this.getStopWordsData(); // words_stop_148
|
|
// this.save(); //indexnew
|
|
},
|
|
removactiveCurrent() {
|
|
const listGroupItem = document.querySelectorAll(".list-group-item");
|
|
listGroupItem.forEach((item) => {
|
|
item.classList.remove("change-active");
|
|
});
|
|
},
|
|
getWordsWeight() {
|
|
let payload = {
|
|
stopwords: this.stopWords,
|
|
userId: this.currentUser.user_id,
|
|
id: this.selectedItem._id,
|
|
indexname: this.selectedItem._index,
|
|
};
|
|
|
|
let url = apis.wordSWeight.list;
|
|
if (this.activeEntityViewSchemaGetter?.key) {
|
|
if (
|
|
this.activeEntityViewSchemaGetter.key == "qasection" ||
|
|
this.activeEntityViewSchemaGetter.key == "rgsection"
|
|
)
|
|
payload.qanon_id = this.selectedItem.qanon_id;
|
|
|
|
url = url.replace(
|
|
"{{index_key}}",
|
|
this.activeEntityViewSchemaGetter?.key
|
|
);
|
|
} else url = url.replace("{{index_key}}/", "");
|
|
|
|
this.httpService
|
|
.postRequest(url, payload)
|
|
|
|
.then((data) => {
|
|
this.repeats = data;
|
|
this.setListWords();
|
|
// this.repeats["word4"] =this.stopWords
|
|
})
|
|
.finally(() => {
|
|
// this.removactiveCurrent();
|
|
// this.save();
|
|
});
|
|
},
|
|
getStopWordsData() {
|
|
var vm = this;
|
|
this.fetchingData = true;
|
|
|
|
let url = adminApi.admin.get.replace(
|
|
"{{system}}",
|
|
this.$route.meta.apiKey
|
|
);
|
|
url += "_" + this.currentUser.user_id;
|
|
|
|
this.httpService
|
|
.getRequest(url)
|
|
.then((response) => {
|
|
if (response.hits.hits.length) {
|
|
this.stopWords = response.hits.hits[0]._source.value;
|
|
this.data = response.hits.hits[0]._source;
|
|
vm.fetchingData = false;
|
|
} else {
|
|
this.getAdminData();
|
|
// this.getWordsWeight()1;
|
|
}
|
|
})
|
|
.catch((error) => {})
|
|
.finally(() => {
|
|
this.getWordsWeight();
|
|
// با این کار کلماتی که در حذفی هست از لیست خارج می شود
|
|
});
|
|
},
|
|
getAdminData() {
|
|
var vm = this;
|
|
let url = adminApi.admin.get.replace(
|
|
"{{system}}",
|
|
this.$route.meta.apiKey
|
|
);
|
|
|
|
this.httpService
|
|
.getRequest(url)
|
|
.then((response) => {
|
|
this.stopWords = response.hits.hits[0]._source.value;
|
|
this.data = response.hits.hits[0]._source;
|
|
})
|
|
.catch((error) => {})
|
|
.finally(() => {
|
|
vm.fetchingData = false;
|
|
});
|
|
},
|
|
save() {
|
|
var vm = this;
|
|
this.fetchingData = true;
|
|
// const payload = {
|
|
// ...this.dataStopWords,
|
|
// ...{
|
|
// value: this.stopWords,
|
|
// user_id: this.currentUser.user_id,
|
|
// username: "",
|
|
// },
|
|
// };
|
|
|
|
// var url = adminApi.admin.save;
|
|
|
|
let payload = {
|
|
words_stop: this.stopWords,
|
|
};
|
|
let url = repoUrl() + settingsApi.user.setKey;
|
|
|
|
|
|
this.httpService
|
|
.postRequest(url, payload)
|
|
.then((response) => {
|
|
vm.fetchingData = false;
|
|
})
|
|
.catch((error) => {})
|
|
.finally(() => {
|
|
vm.fetchingData = false;
|
|
});
|
|
},
|
|
|
|
ReturnToInitialSettings() {
|
|
this.getAdminData();
|
|
},
|
|
showButtonRemove() {},
|
|
|
|
closeModal() {
|
|
this.$emit("close-modal");
|
|
},
|
|
updateList() {
|
|
this.$emit("update-list");
|
|
},
|
|
deleteItem() {
|
|
this.$emit("delete-item");
|
|
},
|
|
setTab(tab) {
|
|
this.currentTab = tab;
|
|
this.counter++;
|
|
|
|
if (tab === 4) {
|
|
this.getStopWordsData();
|
|
}
|
|
this.prepareAndGetChartData();
|
|
},
|
|
prepareAndGetChartData() {
|
|
const chartData = [];
|
|
let count = 0;
|
|
this["words" + this.currentTab]?.forEach((element) => {
|
|
count++;
|
|
if (count < 100)
|
|
chartData.push({
|
|
name: element[0],
|
|
weight: element[1],
|
|
});
|
|
});
|
|
|
|
// this.$emit('on-chart-data-ready',chartData)
|
|
return chartData;
|
|
},
|
|
},
|
|
components: {
|
|
StopWord: () =>
|
|
import(/* webpackChunkName: "StopWord" */ "~/dataSetting/StopWord.vue"),
|
|
// ItemForm: () =>
|
|
// import(/* webpackChunkName: "ز" */ "~/entity/forms/ItemForm.vue"),
|
|
SearchAccordion: () =>
|
|
import(
|
|
/* webpackChunkName: "SearchAccordion" */ "~/entity/components/SearchAccordion.vue"
|
|
),
|
|
ContextMenu: () =>
|
|
import(
|
|
/* webpackChunkName: "ContextMenu" */ "~/components/ContextMenu.vue"
|
|
),
|
|
SubjectForm: () =>
|
|
import(
|
|
/* webpackChunkName: "SubjectForm" */ "~/entity/forms/SubjectForm.vue"
|
|
),
|
|
},
|
|
};
|