mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
fix: update new additions with web panel and sleep operations (#606)
This commit is contained in:
@@ -261,6 +261,11 @@ const store = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const defaultStoreData = {
|
||||||
|
maxPageSleep: browser.maxSleep,
|
||||||
|
minPageSleep: browser.minSleep
|
||||||
|
};
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
browser,
|
browser,
|
||||||
docker,
|
docker,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import {config, defaultStoreData} from '../../config';
|
||||||
import {Adorama} from './adorama';
|
import {Adorama} from './adorama';
|
||||||
import {Alternate} from './alternate';
|
import {Alternate} from './alternate';
|
||||||
import {AlternateNL} from './alternate-nl';
|
import {AlternateNL} from './alternate-nl';
|
||||||
@@ -44,6 +45,7 @@ import {Saturn} from './saturn';
|
|||||||
import {Scan} from './scan';
|
import {Scan} from './scan';
|
||||||
import {Very} from './very';
|
import {Very} from './very';
|
||||||
import {Zotac} from './zotac';
|
import {Zotac} from './zotac';
|
||||||
|
import {logger} from '../../logger';
|
||||||
|
|
||||||
export const storeList = new Map([
|
export const storeList = new Map([
|
||||||
[Adorama.name, Adorama],
|
[Adorama.name, Adorama],
|
||||||
@@ -97,12 +99,31 @@ export const storeList = new Map([
|
|||||||
const brands = new Set();
|
const brands = new Set();
|
||||||
const series = new Set();
|
const series = new Set();
|
||||||
const models = new Set();
|
const models = new Set();
|
||||||
|
|
||||||
|
for (const storeData of config.store.stores) {
|
||||||
|
const store = storeList.get(storeData.name);
|
||||||
|
if (store) {
|
||||||
|
store.minPageSleep = storeData.minPageSleep;
|
||||||
|
store.maxPageSleep = storeData.maxPageSleep;
|
||||||
|
} else {
|
||||||
|
logger.warn(`No store named ${storeData.name}, skipping.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const store of storeList.values()) {
|
for (const store of storeList.values()) {
|
||||||
for (const link of store.links) {
|
for (const link of store.links) {
|
||||||
brands.add(link.brand);
|
brands.add(link.brand);
|
||||||
series.add(link.series);
|
series.add(link.series);
|
||||||
models.add(link.model);
|
models.add(link.model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (store.minPageSleep === undefined) {
|
||||||
|
store.minPageSleep = defaultStoreData.minPageSleep;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (store.maxPageSleep === undefined) {
|
||||||
|
store.maxPageSleep = defaultStoreData.maxPageSleep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllBrands() {
|
export function getAllBrands() {
|
||||||
@@ -117,4 +138,22 @@ export function getAllModels() {
|
|||||||
return Array.from(models);
|
return Array.from(models);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.store.stores.length > 0) {
|
||||||
|
logger.info(`ℹ selected stores: ${config.store.stores.map(store => store.name).join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.store.showOnlyBrands.length > 0) {
|
||||||
|
logger.info(`ℹ selected brands: ${config.store.showOnlyBrands.join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.store.showOnlyModels.length > 0) {
|
||||||
|
logger.info(`ℹ selected models: ${config.store.showOnlyModels.map(entry => {
|
||||||
|
return entry.series ? entry.name + ' (' + entry.series + ')' : entry.name;
|
||||||
|
}).join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.store.showOnlySeries.length > 0) {
|
||||||
|
logger.info(`ℹ selected series: ${config.store.showOnlySeries.join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
export * from './store';
|
export * from './store';
|
||||||
|
|||||||
+47
-4
@@ -9,6 +9,29 @@
|
|||||||
let series;
|
let series;
|
||||||
let models;
|
let models;
|
||||||
|
|
||||||
|
function renderListSubfield(id, elements, selectionArray, subfield) {
|
||||||
|
const list = document.getElementById(id);
|
||||||
|
list.innerHTML = '';
|
||||||
|
for (const element of elements) {
|
||||||
|
const name = `${id}_${element}`;
|
||||||
|
const htmlElement = document.createElement('input');
|
||||||
|
htmlElement.type = 'checkbox';
|
||||||
|
htmlElement.value = element;
|
||||||
|
htmlElement.innerHTML = element;
|
||||||
|
htmlElement.name = name;
|
||||||
|
htmlElement.id = name;
|
||||||
|
if (selectionArray.length === 0 || selectionArray.find(obj => element === obj[subfield])) {
|
||||||
|
htmlElement.checked = true;
|
||||||
|
}
|
||||||
|
list.appendChild(htmlElement);
|
||||||
|
const htmlLabelElement = document.createElement('label');
|
||||||
|
htmlLabelElement.for = name;
|
||||||
|
htmlLabelElement.innerText = element;
|
||||||
|
list.appendChild(htmlLabelElement);
|
||||||
|
list.appendChild(document.createElement('br'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function renderList(id, elements, selectionArray) {
|
function renderList(id, elements, selectionArray) {
|
||||||
const list = document.getElementById(id);
|
const list = document.getElementById(id);
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
@@ -50,13 +73,33 @@
|
|||||||
return resArray;
|
return resArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function listToArraySubfield(id, selectionArray, subfield) {
|
||||||
|
const list = document.getElementById(id);
|
||||||
|
const resArray = [];
|
||||||
|
let allSelected = true;
|
||||||
|
for (const htmlElement of list.childNodes) {
|
||||||
|
if (htmlElement.checked) {
|
||||||
|
const obj = {};
|
||||||
|
obj[subfield] = htmlElement.value;
|
||||||
|
resArray.push(obj);
|
||||||
|
} else {
|
||||||
|
allSelected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allSelected) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return resArray;
|
||||||
|
}
|
||||||
|
|
||||||
async function onReceiveConfig(resp) {
|
async function onReceiveConfig(resp) {
|
||||||
config = await resp.json();
|
config = await resp.json();
|
||||||
|
|
||||||
renderList('storeList', stores, config.store.stores);
|
renderListSubfield('storeList', stores, config.store.stores, 'name');
|
||||||
renderList('brandList', brands, config.store.showOnlyBrands);
|
renderList('brandList', brands, config.store.showOnlyBrands);
|
||||||
renderList('seriesList', series, config.store.showOnlySeries);
|
renderList('seriesList', series, config.store.showOnlySeries);
|
||||||
renderList('modelList', models, config.store.showOnlyModels);
|
renderListSubfield('modelList', models, config.store.showOnlyModels, 'name');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setConfig() {
|
async function setConfig() {
|
||||||
@@ -64,10 +107,10 @@
|
|||||||
throw new Error('Config not loaded yet');
|
throw new Error('Config not loaded yet');
|
||||||
}
|
}
|
||||||
|
|
||||||
config.store.stores = listToArray('storeList');
|
config.store.stores = listToArraySubfield('storeList', 'name');
|
||||||
config.store.showOnlyBrands = listToArray('brandList');
|
config.store.showOnlyBrands = listToArray('brandList');
|
||||||
config.store.showOnlySeries = listToArray('seriesList');
|
config.store.showOnlySeries = listToArray('seriesList');
|
||||||
config.store.showOnlyModels = listToArray('modelList');
|
config.store.showOnlyModels = listToArraySubfield('modelList', 'name');
|
||||||
|
|
||||||
const resp = await fetch('/api/config', {
|
const resp = await fetch('/api/config', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|||||||
Reference in New Issue
Block a user