Skip to content

Commit

Permalink
minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
necitboss committed Dec 12, 2024
1 parent d8a0ab9 commit a6c8b48
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 16 deletions.
4 changes: 3 additions & 1 deletion main/_front/dist/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ btn_submit.addEventListener('click', async (e) => {
const reader = new FileReader();
reader.onload = async e => {
const jsonContent = e.target.result;
console.log(jsonContent);
// console.log(jsonContent);
try {
const response = await fetch('http://localhost:4444/components/json',{
method: 'POST',
Expand All @@ -63,6 +63,8 @@ btn_submit.addEventListener('click', async (e) => {
body: jsonContent
})
console.log(response)
alert("Данные успешно загрузились")
input_file.value = ""
}catch (e) {
console.log(`Какая-то ошибка: ${e}`)
}
Expand Down
30 changes: 24 additions & 6 deletions main/_front/dist/js/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ const yes_event_handler = (e) => {
.then(res => res.json())
.then(data => {
if (!data.message) {
window.location.reload();
// window.location.reload();
const params = {};
if (filter_name.value.trim() !== ""){
params["name"] = filter_name.value.trim();
}
if (filter_to.value.trim() !== ""){
params["max_price"] = filter_to.value;
}
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value === "price"){
params["sort_by"] = "price"
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
}else {
closeDialog();
}
Expand All @@ -61,7 +79,7 @@ const openDialog = (name, id) => {
dialog_delete.classList.add('show');
document.body.classList.add('no-scroll')
const dialog_name = dialog_delete.querySelector(".dialog__name");
console.log(dialog_name)
// console.log(dialog_name)
dialog_name.textContent = name;
btn_yes.addEventListener("click", yes_event_handler)
btn_no.addEventListener("click", no_event_handler)
Expand Down Expand Up @@ -90,11 +108,11 @@ function createQueryParams(baseUrl, filters) {

const addCards = (filters) => {
const query = createQueryParams("http://localhost:4444/components", filters)
console.log(query)
// console.log(query)
fetch(query)
.then(res => res.json())
.then(data => {
console.log(data);
// console.log(data);
cards_place.replaceChildren();
data.forEach((item) => {
cards_place.insertAdjacentHTML("beforeend", `
Expand Down Expand Up @@ -140,8 +158,8 @@ choiceLists.forEach((choiceList) => {
if (choice === e.target) {
choiceList.dataset.value = choice.dataset.value;
choice.classList.add("active");
console.log(choice.dataset.value);
console.log("here");
// console.log(choice.dataset.value);
// console.log("here");
if (choiceList.id === "choice_components") {
const params = {
type: choice.dataset.value
Expand Down
21 changes: 20 additions & 1 deletion main/_front/dist/js/elems/choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ choiceLists.forEach((choiceList) => {
if (choice === e.target) {
choiceList.dataset.value = choice.dataset.value;
choice.classList.add("active");
console.log(choice.dataset.value);
// console.log(choice.dataset.value);
}else {
choice.classList.remove("active");
}
Expand All @@ -21,4 +21,23 @@ choiceLists.forEach((choiceList) => {
});
})

const choiceChange = (list, value) => {
const items = list.querySelectorAll(".choice__elem");
items.forEach((item) => {
if (item.dataset.value === value) {
item.classList.add("active");
list.dataset.value = value;
}else {
item.classList.remove("active");
}
console.log(item.dataset.value === value);
})
}


const change_parameter = document.querySelector("#change_parameter");
console.log(change_parameter);
change_parameter.addEventListener("click", (e) => {
choiceChange(document.querySelector("#type"), "gpu");
})

30 changes: 29 additions & 1 deletion main/_front/dist/js/elems/stepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,32 @@ steppers.forEach(stepper => {
}
}
})
})
})

const stepperChange = (item, value) => {
const minus_btn = item.querySelector('.stepper__minus');
const plus_btn = item.querySelector('.stepper__plus');
const stepper_value = item.querySelector('.stepper__value');

const max = item.dataset.max;
stepper_value.textContent = value;

if (checkMinDisabled(stepper_value)){
minus_btn.disabled = true;
stepper_value.textContent = "1";
}else {
minus_btn.disabled = false;
}
if (checkMaxDisabled(stepper_value, max)){
plus_btn.disabled = true;
stepper_value.textContent = max;
}else {
plus_btn.disabled = false;
}
}

const change_parameter = document.querySelector("#change_parameter");
console.log(change_parameter);
change_parameter.addEventListener("click", (e) => {
stepperChange(document.querySelector("#type"), 10);
})
4 changes: 3 additions & 1 deletion main/_front/src/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ btn_submit.addEventListener('click', async (e) => {
const reader = new FileReader();
reader.onload = async e => {
const jsonContent = e.target.result;
console.log(jsonContent);
// console.log(jsonContent);
try {
const response = await fetch('http://localhost:4444/components/json',{
method: 'POST',
Expand All @@ -63,6 +63,8 @@ btn_submit.addEventListener('click', async (e) => {
body: jsonContent
})
console.log(response)
alert("Данные успешно загрузились")
input_file.value = ""
}catch (e) {
console.log(`Какая-то ошибка: ${e}`)
}
Expand Down
30 changes: 24 additions & 6 deletions main/_front/src/js/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ const yes_event_handler = (e) => {
.then(res => res.json())
.then(data => {
if (!data.message) {
window.location.reload();
// window.location.reload();
const params = {};
if (filter_name.value.trim() !== ""){
params["name"] = filter_name.value.trim();
}
if (filter_to.value.trim() !== ""){
params["max_price"] = filter_to.value;
}
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value === "price"){
params["sort_by"] = "price"
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
}else {
closeDialog();
}
Expand All @@ -61,7 +79,7 @@ const openDialog = (name, id) => {
dialog_delete.classList.add('show');
document.body.classList.add('no-scroll')
const dialog_name = dialog_delete.querySelector(".dialog__name");
console.log(dialog_name)
// console.log(dialog_name)
dialog_name.textContent = name;
btn_yes.addEventListener("click", yes_event_handler)
btn_no.addEventListener("click", no_event_handler)
Expand Down Expand Up @@ -90,11 +108,11 @@ function createQueryParams(baseUrl, filters) {

const addCards = (filters) => {
const query = createQueryParams("http://localhost:4444/components", filters)
console.log(query)
// console.log(query)
fetch(query)
.then(res => res.json())
.then(data => {
console.log(data);
// console.log(data);
cards_place.replaceChildren();
data.forEach((item) => {
cards_place.insertAdjacentHTML("beforeend", `
Expand Down Expand Up @@ -140,8 +158,8 @@ choiceLists.forEach((choiceList) => {
if (choice === e.target) {
choiceList.dataset.value = choice.dataset.value;
choice.classList.add("active");
console.log(choice.dataset.value);
console.log("here");
// console.log(choice.dataset.value);
// console.log("here");
if (choiceList.id === "choice_components") {
const params = {
type: choice.dataset.value
Expand Down

0 comments on commit a6c8b48

Please sign in to comment.