- inizio di modifiche all'editor di Pagine Web
This commit is contained in:
@@ -1,103 +1,153 @@
|
||||
import { defineComponent, ref, watch, onMounted } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { IMyPage } from 'app/src/model'
|
||||
import { useGlobalStore } from 'app/src/store'
|
||||
import { PagesConfigurator } from '@src/components/PagesConfigurator'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import { defineComponent, ref, watch, onMounted } from 'vue';
|
||||
import { useQuasar } from 'quasar';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { IMyPage } from 'app/src/model';
|
||||
import { useGlobalStore } from 'app/src/store';
|
||||
import { PagesConfigurator } from '@src/components/PagesConfigurator';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PagesAdmin',
|
||||
components: { PagesConfigurator },
|
||||
setup () {
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n()
|
||||
setup() {
|
||||
const $q = useQuasar();
|
||||
const { t } = useI18n();
|
||||
|
||||
const globalStore = useGlobalStore()
|
||||
const { mypage } = storeToRefs(globalStore)
|
||||
const globalStore = useGlobalStore();
|
||||
const { mypage } = storeToRefs(globalStore);
|
||||
|
||||
const $router = useRouter()
|
||||
|
||||
// Copia locale per l’editing tramite v-model
|
||||
const pagesLocal = ref<IMyPage[]>([])
|
||||
const savingAll = ref(false)
|
||||
const pagesLocal = ref<IMyPage[]>([]);
|
||||
const savingAll = ref(false);
|
||||
|
||||
// Mantieni pagesLocal <-> store allineati
|
||||
const syncFromStore = () => {
|
||||
pagesLocal.value = (mypage.value || []).map(p => ({ ...p }))
|
||||
}
|
||||
pagesLocal.value = (mypage.value || []).map((p) => ({ ...p }));
|
||||
};
|
||||
|
||||
watch(mypage, syncFromStore, { deep: true })
|
||||
watch(mypage, syncFromStore, { deep: true });
|
||||
onMounted(async () => {
|
||||
// Se hai una funzione per caricare tutte le pagine, chiamala qui
|
||||
// es. await globalStore.loadAllPages()
|
||||
syncFromStore()
|
||||
})
|
||||
syncFromStore();
|
||||
});
|
||||
|
||||
// Salva singola pagina (chiamato da PagesConfigurator @save)
|
||||
async function saveOne (page: IMyPage) {
|
||||
try {
|
||||
const saved = await globalStore.savePage({ ...page })
|
||||
if (saved && typeof saved === 'object') {
|
||||
// rimpiazza nel local e nello store (lo store viene aggiornato da savePage)
|
||||
const idx = pagesLocal.value.findIndex(p =>
|
||||
(p._id && p._id === saved._id) || (p.path && p.path === saved.path)
|
||||
)
|
||||
if (idx >= 0) pagesLocal.value[idx] = { ...saved }
|
||||
$q.notify({ type: 'positive', message: `Salvata: ${saved.title || saved.path}` })
|
||||
} else {
|
||||
$q.notify({ type: 'positive', message: 'Salvataggio completato' })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
$q.notify({ type: 'negative', message: 'Errore nel salvataggio della pagina' })
|
||||
const lastOrderSnapshot = ref<Map<string, number>>(new Map());
|
||||
const savingOrders = ref(false);
|
||||
|
||||
// crea/ricostruisce lo snapshot (solo pagine con _id)
|
||||
function initOrderSnapshot(arr: IMyPage[]) {
|
||||
const m = new Map<string, number>();
|
||||
for (const p of arr) {
|
||||
if (p._id) m.set(p._id, p.order ?? 0);
|
||||
}
|
||||
lastOrderSnapshot.value = m;
|
||||
}
|
||||
|
||||
// call una volta dopo aver caricato le pagine
|
||||
onMounted(() => {
|
||||
initOrderSnapshot(pagesLocal.value); // pagesLocal è il tuo array locale già usato
|
||||
});
|
||||
|
||||
// quando salvi una pagina singola e ottieni l'_id, aggiorna lo snapshot
|
||||
async function saveOne(p: IMyPage) {
|
||||
try {
|
||||
const saved = await globalStore.savePage({ ...p });
|
||||
if (saved && saved._id) {
|
||||
// aggiorna la copia locale
|
||||
const idx = pagesLocal.value.findIndex(
|
||||
(x) => (x._id && x._id === saved._id) || (x.path && x.path === saved.path)
|
||||
);
|
||||
if (idx >= 0) pagesLocal.value[idx] = { ...saved };
|
||||
// aggiorna lo snapshot dell'ordinamento persistito
|
||||
lastOrderSnapshot.value.set(
|
||||
saved._id,
|
||||
saved.order ?? pagesLocal.value[idx]?.order ?? 0
|
||||
);
|
||||
$q.notify({
|
||||
type: 'positive',
|
||||
message: `Salvata: ${saved.title || saved.path}`,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$q.notify({ type: 'negative', message: 'Errore nel salvataggio della pagina' });
|
||||
}
|
||||
}
|
||||
// Salva l’ordinamento (fallback: batch di savePage per aggiornare order)
|
||||
async function saveOrder (orders: { id?: string; order: number }[]) {
|
||||
async function saveOrder(orders: { id?: string; order: number }[]) {
|
||||
try {
|
||||
// Applica l'order nella copia locale
|
||||
for (const { id, order } of orders) {
|
||||
const p = pagesLocal.value.find(x => x._id === id) ||
|
||||
pagesLocal.value.find(x => !id && typeof x.order === 'number' && x.order === order)
|
||||
if (p) p.order = order
|
||||
if (savingOrders.value) return;
|
||||
savingOrders.value = true;
|
||||
|
||||
// 1) calcola solo i cambi VERI su pagine già persistite (_id presente)
|
||||
const changedExisting = orders.filter((o) => {
|
||||
if (!o.id) return false; // ignora nuovi senza id
|
||||
const prev = lastOrderSnapshot.value.get(o.id);
|
||||
return prev === undefined ? false : prev !== o.order;
|
||||
});
|
||||
|
||||
// 2) se non è cambiato nulla di "persistito", esci silenziosamente
|
||||
if (changedExisting.length === 0) {
|
||||
// console.debug('[saveOrder] nessun cambiamento persistente')
|
||||
return;
|
||||
}
|
||||
// Fallback: se non hai un endpoint /reorder, salvi singolarmente
|
||||
|
||||
// fallback: salva solo le pagine cambiate
|
||||
await Promise.all(
|
||||
pagesLocal.value.map(p => globalStore.savePage({ ...p }))
|
||||
)
|
||||
$q.notify({ type: 'positive', message: 'Ordinamento salvato' })
|
||||
changedExisting.map(({ id, order }) => {
|
||||
const p = pagesLocal.value.find((x) => x._id === id);
|
||||
if (!p) return Promise.resolve();
|
||||
// se il tuo savePage accetta payload parziale, meglio passare solo {_id, order}
|
||||
// altrimenti manda l'oggetto intero con order aggiornato
|
||||
return globalStore.savePage({ ...p, order });
|
||||
})
|
||||
);
|
||||
|
||||
// 4) aggiorna lo snapshot solo per gli elementi realmente salvati
|
||||
for (const { id, order } of changedExisting) {
|
||||
if (id) lastOrderSnapshot.value.set(id, order);
|
||||
}
|
||||
|
||||
$q.notify({ type: 'positive', message: 'Ordinamento aggiornato' });
|
||||
|
||||
globalStore.aggiornaMenu($router);
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
$q.notify({ type: 'negative', message: 'Errore nel salvataggio dell’ordinamento' })
|
||||
console.error(err);
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: 'Errore nel salvataggio dell’ordinamento',
|
||||
});
|
||||
} finally {
|
||||
savingOrders.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Ricarica l’elenco (se disponibile una API globale; altrimenti rilegge dallo store)
|
||||
async function reloadAll () {
|
||||
async function reloadAll() {
|
||||
try {
|
||||
// Se esiste: await globalStore.loadAllPages()
|
||||
syncFromStore()
|
||||
$q.notify({ type: 'info', message: 'Elenco ricaricato' })
|
||||
syncFromStore();
|
||||
$q.notify({ type: 'info', message: 'Elenco ricaricato' });
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
$q.notify({ type: 'negative', message: 'Errore nel ricaricare l’elenco' })
|
||||
console.error(err);
|
||||
$q.notify({ type: 'negative', message: 'Errore nel ricaricare l’elenco' });
|
||||
}
|
||||
}
|
||||
|
||||
// Salva tutto (batch)
|
||||
async function saveAll () {
|
||||
async function saveAll() {
|
||||
try {
|
||||
savingAll.value = true
|
||||
await Promise.all(
|
||||
pagesLocal.value.map(p => globalStore.savePage({ ...p }))
|
||||
)
|
||||
$q.notify({ type: 'positive', message: 'Tutte le pagine salvate' })
|
||||
savingAll.value = true;
|
||||
await Promise.all(pagesLocal.value.map((p) => globalStore.savePage({ ...p })));
|
||||
$q.notify({ type: 'positive', message: 'Tutte le pagine salvate' });
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
$q.notify({ type: 'negative', message: 'Errore nel salvataggio massivo' })
|
||||
console.error(err);
|
||||
$q.notify({ type: 'negative', message: 'Errore nel salvataggio massivo' });
|
||||
} finally {
|
||||
savingAll.value = false
|
||||
savingAll.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +159,6 @@ export default defineComponent({
|
||||
saveAll,
|
||||
savingAll,
|
||||
t,
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<q-page class="q-pa-md">
|
||||
<q-toolbar class="q-mb-md">
|
||||
<q-toolbar-title>Configuratore Pagine</q-toolbar-title>
|
||||
<q-toolbar-title class="text-center">Configura Pagine</q-toolbar-title>
|
||||
<q-space />
|
||||
<q-btn
|
||||
flat
|
||||
|
||||
0
src/rootgen/admin/importaprodotti/importaprodotti.scss
Executable file
0
src/rootgen/admin/importaprodotti/importaprodotti.scss
Executable file
615
src/rootgen/admin/importaprodotti/importaprodotti.ts
Executable file
615
src/rootgen/admin/importaprodotti/importaprodotti.ts
Executable file
@@ -0,0 +1,615 @@
|
||||
import { CMyPage } from '../../../components/CMyPage/index'
|
||||
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
|
||||
import { defineComponent, ref, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { useQuasar } from 'quasar'
|
||||
import type { IParamsQuery } from 'model'
|
||||
import { toolsext } from '@store/Modules/toolsext'
|
||||
import { StringDecoder } from 'string_decoder'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'importaprodotti',
|
||||
components: { CMyPage },
|
||||
setup(props, { emit }) {
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n()
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const arrSector = ref(<any[]>[])
|
||||
const arrSectorGood = ref(<any[]>[])
|
||||
const arrSkill = ref(<any[]>[])
|
||||
const arrGood = ref(<any[]>[])
|
||||
|
||||
const importasulserver = ref(false)
|
||||
const skipfirstrow = ref(true)
|
||||
|
||||
const incaricamento = ref(false)
|
||||
const checkAggiornaQta = ref(false)
|
||||
|
||||
const cosafare = ref(shared_consts.Cmd.PRODUCTS_V2)
|
||||
|
||||
const inputfile = ref('')
|
||||
const risultato = ref('')
|
||||
const risraw = ref('')
|
||||
|
||||
const caricaDatiToggle = ref(false)
|
||||
|
||||
const ListaCmd = ref(
|
||||
[
|
||||
{
|
||||
label: 'Importa Prodotti',
|
||||
value: shared_consts.Cmd.PRODUCTS
|
||||
},
|
||||
{
|
||||
label: 'Importa Prodotti V2',
|
||||
value: shared_consts.Cmd.PRODUCTS_V2
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
function caricadati() {
|
||||
|
||||
if (!caricaDatiToggle.value) {
|
||||
arrSector.value = []
|
||||
arrSectorGood.value = []
|
||||
arrSkill.value = []
|
||||
arrGood.value = []
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const sortBy = 'descr'
|
||||
const descending = 1
|
||||
const myobj: any = {}
|
||||
if (descending)
|
||||
myobj[sortBy] = -1
|
||||
else
|
||||
myobj[sortBy] = 1
|
||||
|
||||
const params: IParamsQuery = {
|
||||
newvers: true,
|
||||
table: '',
|
||||
startRow: 0,
|
||||
endRow: 10000,
|
||||
filter: '',
|
||||
filterand: '',
|
||||
filtersearch: '',
|
||||
filtersearch2: '',
|
||||
filtercustom: '',
|
||||
filterextra: '',
|
||||
filterextra2: '',
|
||||
filter_gte: '',
|
||||
sortBy: myobj,
|
||||
descending,
|
||||
userId: '',
|
||||
noaut: false,
|
||||
}
|
||||
|
||||
if (true) {
|
||||
params.table = toolsext.TABSECTORS
|
||||
globalStore.loadTable(params).then((data) => {
|
||||
arrSector.value = data.rows
|
||||
})
|
||||
|
||||
params.table = 'sectorgoods'
|
||||
globalStore.loadTable(params).then((data) => {
|
||||
arrSectorGood.value = data.rows
|
||||
})
|
||||
|
||||
params.table = 'skills'
|
||||
globalStore.loadTable(params).then((data) => {
|
||||
arrSkill.value = data.rows
|
||||
})
|
||||
|
||||
params.table = 'goods'
|
||||
globalStore.loadTable(params).then((data) => {
|
||||
arrGood.value = data.rows
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function created() {
|
||||
|
||||
// se idapp = 18
|
||||
if (tools.getIdApp() === tools.IDAPP_MACRO) {
|
||||
cosafare.value = shared_consts.Cmd.MACRO_CATALOGO_JSON
|
||||
}
|
||||
inputfile.value = ''
|
||||
|
||||
if (caricaDatiToggle.value) {
|
||||
caricadati()
|
||||
}
|
||||
}
|
||||
|
||||
function createSector(cat: string, cmd: number) {
|
||||
let arr = []
|
||||
if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
arr = arrSectorGood.value
|
||||
} else {
|
||||
arr = arrSector.value
|
||||
}
|
||||
|
||||
const myid = arr.length + 1
|
||||
arr.push({ _id: myid, descr: cat })
|
||||
return myid
|
||||
}
|
||||
|
||||
function findidSector(cat: string, cmd: number) {
|
||||
let arr = []
|
||||
if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
arr = arrSectorGood.value
|
||||
} else {
|
||||
arr = arrSector.value
|
||||
}
|
||||
|
||||
const rec = arr.find((rec) => rec.descr === cat)
|
||||
if (rec) {
|
||||
return rec._id
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function findidSkill(cat: string, cmd: number) {
|
||||
let arr = []
|
||||
if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
arr = arrGood.value
|
||||
} else {
|
||||
arr = arrSkill.value
|
||||
}
|
||||
|
||||
const rec = arr.find((rec) => rec.descr === cat)
|
||||
if (rec) {
|
||||
return rec._id
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function createSkill(cat: string, cmd: number) {
|
||||
let arr = []
|
||||
if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
arr = arrGood.value
|
||||
} else {
|
||||
arr = arrSkill.value
|
||||
}
|
||||
const myid = arr.length + 1
|
||||
arr.push({ _id: myid, descr: cat })
|
||||
return myid
|
||||
}
|
||||
|
||||
|
||||
function importCmdTxt(cmd: number, testo: string) {
|
||||
|
||||
const delim = '\n';
|
||||
const righe = 1;
|
||||
let indrec = 0;
|
||||
let myarr = tools.CSVToArray(testo, delim)
|
||||
|
||||
let sector = ''
|
||||
let skill = ''
|
||||
let sotto_cat = ''
|
||||
let idSector = 0
|
||||
let idSkill = 0
|
||||
|
||||
let strskills = '';
|
||||
let strsubskills = '';
|
||||
let strsectors = '';
|
||||
|
||||
let indrecsub = 1;
|
||||
|
||||
myarr = myarr[0]
|
||||
let arrstr = []
|
||||
|
||||
// debugger;
|
||||
for (let i = 0; i < myarr.length; i = i + righe) {
|
||||
arrstr = myarr[i].split(',')
|
||||
sector = arrstr[0]
|
||||
skill = arrstr[1]
|
||||
// sotto_cat = arrstr[2]
|
||||
// sotto_cat = myarr[i].replace('\'', '\\\'')
|
||||
// sector = myarr[i+2]
|
||||
if (skill)
|
||||
skill = skill.replace('\'', '\\\'')
|
||||
if (sector)
|
||||
sector = sector.replace('\'', '\\\'')
|
||||
|
||||
if (sector) {
|
||||
idSector = findidSector(sector, cmd)
|
||||
if (!idSector) {
|
||||
idSector = createSector(sector, cmd)
|
||||
|
||||
// sectors
|
||||
strsectors += '{ \n'
|
||||
strsectors += ' _id:' + idSector + ','
|
||||
strsectors += ' descr:\'' + sector + '\','
|
||||
strsectors += '}, \n'
|
||||
}
|
||||
|
||||
if (skill !== '') {
|
||||
idSkill = findidSkill(skill, cmd)
|
||||
if (!idSkill) {
|
||||
idSkill = createSkill(skill, cmd)
|
||||
|
||||
// skills
|
||||
strskills += '{ \n'
|
||||
strskills += ' _id:' + idSkill + ','
|
||||
if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
strskills += ' idSectorGood: [' + idSector + '],'
|
||||
} else if (cmd === shared_consts.Cmd.CAT_SKILL_TXT) {
|
||||
strskills += ' idSector: [' + idSector + '],'
|
||||
}
|
||||
|
||||
strskills += ' descr:\'' + skill + '\','
|
||||
strskills += '}, \n'
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (sotto_cat !== '') {
|
||||
// subskills
|
||||
strsubskills += '{ \n'
|
||||
strsubskills += ' idSkill: ' + idSkill + ','
|
||||
strsubskills += ' descr:\'' + sotto_cat + '\','
|
||||
strsubskills += '}, \n'
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
indrecsub++
|
||||
}
|
||||
|
||||
let ris = 'module.exports = {\n' +
|
||||
' list: [' + strsectors + ']'
|
||||
ris += '<br><br><br><br>'
|
||||
ris += 'module.exports = {\n' +
|
||||
' list: [' + strskills + ']'
|
||||
ris += '<br><br><br><br>'
|
||||
/*ris += 'module.exports = {\n' +
|
||||
' list: [' + strsubskills + ']'
|
||||
|
||||
*/
|
||||
|
||||
return ris
|
||||
|
||||
}
|
||||
|
||||
function importMacroCatalogoJson(cmd: number, testo: string) {
|
||||
return testo
|
||||
}
|
||||
|
||||
function importNoSpazi(cmd: number, testo: string) {
|
||||
|
||||
const delim = '\n';
|
||||
const righe = 3;
|
||||
let indrec = 0;
|
||||
let myarr = tools.CSVToArray(testo, delim)
|
||||
|
||||
let sector = ''
|
||||
let sotto_cat = ''
|
||||
|
||||
myarr = myarr[0]
|
||||
|
||||
let txt = ''
|
||||
|
||||
// debugger;
|
||||
for (let i = 0; i < myarr.length; i = i + righe) {
|
||||
sotto_cat = myarr[i].replace('\'', '\\\'')
|
||||
sector = myarr[i + 2]
|
||||
|
||||
txt += sotto_cat + ',' + sector + '<br>'
|
||||
}
|
||||
|
||||
return txt
|
||||
|
||||
}
|
||||
|
||||
function importCmd(cmd: number, testo: string) {
|
||||
|
||||
let risultato = '(nessuno)'
|
||||
let delim = ','
|
||||
|
||||
if (cmd === shared_consts.Cmd.PROVINCE) {
|
||||
delim = ','
|
||||
} else if ((cmd === shared_consts.Cmd.COMUNI) || (cmd === shared_consts.Cmd.CITIES_SERVER)) {
|
||||
delim = ';'
|
||||
} else if (cmd === shared_consts.Cmd.CAT_SKILL_TXT) {
|
||||
return importCmdTxt(cmd, testo);
|
||||
} else if (cmd === shared_consts.Cmd.CAT_GOODS_TXT) {
|
||||
return importCmdTxt(cmd, testo);
|
||||
} else if (cmd === shared_consts.Cmd.CAT_NO_SPAZI) {
|
||||
return importNoSpazi(cmd, testo);
|
||||
} else if ((cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON || cmd === shared_consts.Cmd.MACRO_RANKING)) {
|
||||
return importMacroCatalogoJson(cmd, testo);
|
||||
} else if (cmd === shared_consts.Cmd.MACRO_DESCRELINKSITOWEB) {
|
||||
|
||||
// console.log('TESTO PRIMA:', testo)
|
||||
const testoJSON = tools.convertXMLStringToJSON(testo)
|
||||
|
||||
const testoJSONtoPrint = JSON.stringify(testoJSON, null, 2)
|
||||
// console.log(testoJSONtoPrint)
|
||||
|
||||
return importMacroCatalogoJson(cmd, testoJSONtoPrint)
|
||||
}
|
||||
|
||||
function addfield(col: number, field: string, rec: any, opt: any) {
|
||||
let risultato = ''
|
||||
try {
|
||||
let valstr = opt.strinput ? opt.strinput : rec[col]
|
||||
|
||||
if (opt.isnumero) {
|
||||
if (valstr === '')
|
||||
valstr = '0';
|
||||
valstr = valstr.replace(',', '.');
|
||||
}
|
||||
if (opt.iseuro) {
|
||||
valstr = tools.convertPriceEurToValue(valstr)
|
||||
}
|
||||
valstr = tools.removeescape_e_acapo(valstr)
|
||||
// valstr = tools.addslashes(valstr)
|
||||
if (!opt.primo)
|
||||
risultato += ', '
|
||||
|
||||
risultato += '"' + field + '":"' + valstr + '"'
|
||||
return risultato;
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
|
||||
const myarr = tools.CSVToArray(testo, delim)
|
||||
|
||||
let strris = ''
|
||||
|
||||
let ind = 1
|
||||
let primo = true
|
||||
|
||||
let arrCols: any = []
|
||||
|
||||
if (skipfirstrow.value) {
|
||||
arrCols = myarr[0]
|
||||
}
|
||||
console.log('arrCols', arrCols)
|
||||
|
||||
if (cmd === shared_consts.Cmd.PRODUCTS_V2) {
|
||||
skipfirstrow.value = false
|
||||
} else if ((cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) || (cmd === shared_consts.Cmd.MACRO_RANKING) || (cmd === shared_consts.Cmd.MACRO_DESCRELINKSITOWEB)) {
|
||||
skipfirstrow.value = false
|
||||
}
|
||||
|
||||
for (const rec of myarr) {
|
||||
|
||||
if (skipfirstrow.value) {
|
||||
if (ind === 1) {
|
||||
ind++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let lab = tools.addslashes(rec[0])
|
||||
let val = tools.addslashes(rec[1])
|
||||
if (cmd === shared_consts.Cmd.PROVINCE) {
|
||||
let reg = tools.addslashes(rec[1])
|
||||
val = tools.addslashes(rec[2])
|
||||
|
||||
strris += '{ \n'
|
||||
strris += ' _id:' + ind + ','
|
||||
strris += ' reg:\'' + reg + '\','
|
||||
strris += ' prov:\'' + val + '\','
|
||||
strris += ' descr:\'' + lab + '\','
|
||||
strris += '}, \n'
|
||||
|
||||
} else if (cmd === shared_consts.Cmd.COMUNI) {
|
||||
strris += '{ \n'
|
||||
strris += ' istat:\'' + tools.addslashes(rec[0]) + '\','
|
||||
strris += ' comune:\'' + tools.addslashes(rec[1]) + '\','
|
||||
strris += ' prov:\'' + tools.addslashes(rec[2]) + '\''
|
||||
} else if (cmd === shared_consts.Cmd.PRODUCTS) {
|
||||
if (!primo) {
|
||||
strris += ', '
|
||||
}
|
||||
|
||||
strris += '{ '
|
||||
let col = 0;
|
||||
strris += addfield(col, 'idapp', rec, { strinput: tools.appid(), primo: true });
|
||||
strris += addfield(col, 'code', rec, {}); col++;
|
||||
strris += addfield(col, 'name', rec, {}); col++;
|
||||
strris += addfield(col, 'price', rec, { iseuro: true }); col++;
|
||||
strris += addfield(col, 'stockQty', rec, { isnumero: true }); col++;
|
||||
col++;
|
||||
strris += addfield(col, 'weight', rec, { isnumero: true }); col++;
|
||||
strris += addfield(col, 'unit', rec, {}); col++;
|
||||
strris += addfield(col, 'link', rec, {}); col++;
|
||||
|
||||
|
||||
strris += addfield(col, 'perc_iva', rec, {}); col++;
|
||||
strris += addfield(col, 'price_acquistato', rec, { isnumero: true, iseuro: true }); col++;
|
||||
strris += addfield(col, 'minBuyQty', rec, { isnumero: true }); col++;
|
||||
strris += addfield(col, 'minStepQty', rec, { isnumero: true }); col++;
|
||||
strris += addfield(col, 'sconto', rec, {}); col++;
|
||||
|
||||
|
||||
strris += addfield(col, 'cat_name', rec, {}); col++;
|
||||
strris += addfield(col, 'subcat_name', rec, {}); col++;
|
||||
strris += addfield(col, 'producer_name', rec, {}); col++;
|
||||
strris += addfield(col, 'provider_name', rec, {}); col++;
|
||||
strris += addfield(col, 'magazzino_name', rec, {}); col++;
|
||||
strris += addfield(col, 'qtyToReachForGas', rec, { isnumero: true }); col++;
|
||||
strris += addfield(col, 'maxbookableGASQty', rec, { isnumero: true }); col++;
|
||||
strris += addfield(col, 'sconto1', rec, {}); col++;
|
||||
strris += addfield(col, 'sconto2', rec, {}); col++;
|
||||
strris += addfield(col, 'gas_name', rec, {}); col++;
|
||||
strris += addfield(col, 'note', rec, {}); col++;
|
||||
strris += '} '
|
||||
|
||||
} else if (cmd === shared_consts.Cmd.PRODUCTS_V2) {
|
||||
if (!primo) {
|
||||
strris += ', '
|
||||
}
|
||||
|
||||
strris += '{ '
|
||||
let col = 0;
|
||||
strris += addfield(col, 'idapp', rec, { strinput: tools.appid(), primo: true });
|
||||
for (const mycol of arrCols) {
|
||||
strris += addfield(col, mycol, rec, {}); col++;
|
||||
}
|
||||
|
||||
strris += '} '
|
||||
|
||||
} else if (cmd === shared_consts.Cmd.INVENTARIO) {
|
||||
if (!primo) {
|
||||
strris += ', '
|
||||
}
|
||||
|
||||
strris += '{ '
|
||||
let col = 0;
|
||||
strris += addfield(col, 'idapp', rec, { strinput: tools.appid(), primo: true });
|
||||
for (const mycol of arrCols) {
|
||||
strris += addfield(col, mycol, rec, {}); col++;
|
||||
}
|
||||
|
||||
strris += '} '
|
||||
|
||||
} else if (cmd === shared_consts.Cmd.CITIES_SERVER) {
|
||||
strris += '{ \n'
|
||||
strris += ' _id :' + ind + ',\n'
|
||||
strris += ' istat :\'' + rec[0] + '\'\n,'
|
||||
strris += ' comune :\'' + tools.addslashes(rec[1]) + '\'\n,'
|
||||
strris += ' prov :\'' + rec[2] + '\'\n,'
|
||||
strris += ' reg :\'' + tools.addslashes(rec[3]) + '\'\n,'
|
||||
strris += ' pref :\'' + tools.addslashes(rec[4]) + '\'\n,'
|
||||
strris += ' cap :\'' + rec[5] + '\'\n,'
|
||||
strris += ' abitanti :\'' + rec[6] + '\'\n,'
|
||||
strris += ' country : \'IT\'\n'
|
||||
strris += '}, \n'
|
||||
}
|
||||
ind += 1
|
||||
primo = false
|
||||
|
||||
}
|
||||
|
||||
if (cmd === shared_consts.Cmd.CITIES_SERVER) {
|
||||
userStore.importToServerCmd($q, t, cmd, null, true)
|
||||
} else if ((cmd === shared_consts.Cmd.PRODUCTS) || (cmd === shared_consts.Cmd.PRODUCTS_V2)) {
|
||||
let options = { aggiornaStockQty: checkAggiornaQta.value }
|
||||
if (importasulserver.value)
|
||||
userStore.importToServerCmd($q, t, cmd, { arrdata: JSON.stringify(strris, null, 2), options }, true)
|
||||
}
|
||||
risultato = strris
|
||||
|
||||
|
||||
return risultato
|
||||
}
|
||||
|
||||
function reset() {
|
||||
risultato.value = ''
|
||||
risraw.value = ''
|
||||
inputfile.value = ''
|
||||
}
|
||||
|
||||
function loadTextFromFile(ev: any) {
|
||||
try {
|
||||
console.log('ev', ev)
|
||||
reset()
|
||||
|
||||
if (ev.target && ev.target.files) {
|
||||
const file = ev.target.files[0]
|
||||
const reader = new FileReader()
|
||||
|
||||
reader.onload = (e: any) => {
|
||||
|
||||
const testo = e.target.result
|
||||
|
||||
risultato.value = importCmd(cosafare.value, testo)
|
||||
}
|
||||
|
||||
if (file)
|
||||
reader.readAsText(file)
|
||||
}
|
||||
} catch (e) {
|
||||
risultato.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
function eseguiCmd() {
|
||||
risultato.value = ''
|
||||
|
||||
userStore.importToServerCmd($q, t, cosafare.value, null)
|
||||
}
|
||||
|
||||
function eseguiCmdProduct() {
|
||||
let options = { aggiornaStockQty: checkAggiornaQta.value }
|
||||
userStore.importToServerCmd($q, t, cosafare.value, { arrdata: risultato.value, options }, true)
|
||||
risultato.value = ''
|
||||
}
|
||||
|
||||
function eseguiCmdInventario() {
|
||||
let options = { aggiornaStockQty: checkAggiornaQta.value }
|
||||
userStore.importToServerCmd($q, t, cosafare.value, { arrdata: risultato.value, options }, true)
|
||||
risultato.value = ''
|
||||
}
|
||||
|
||||
function eseguiCmdCatalogoJson() {
|
||||
let options = { aggiornaStockQty: checkAggiornaQta.value }
|
||||
|
||||
userStore.importToServerCmd($q, t, cosafare.value, { arrdata: risultato.value, options }, true)
|
||||
risultato.value = ''
|
||||
}
|
||||
|
||||
function createProvLink() {
|
||||
let str = ''
|
||||
|
||||
const arr = globalStore.provinces
|
||||
|
||||
let regione = ''
|
||||
let regid = ''
|
||||
|
||||
for (const prov of arr) {
|
||||
if (prov.link_grp) {
|
||||
if (prov.reg !== regid) {
|
||||
const myreg = shared_consts.Regions.find((rec: any) => rec.value === prov.reg)
|
||||
if (myreg) {
|
||||
regid = myreg.value
|
||||
regione = myreg.label
|
||||
str += '<br><div class="text-subtitle1">' + regione + '</div>'
|
||||
}
|
||||
}
|
||||
str += '<a class="prov" href="' + prov.link_grp + '" target="_blank">' + prov.descr + '</a><br>'
|
||||
}
|
||||
}
|
||||
|
||||
risultato.value = str
|
||||
risraw.value = str
|
||||
}
|
||||
|
||||
onMounted(created)
|
||||
|
||||
return {
|
||||
inputfile,
|
||||
shared_consts,
|
||||
loadTextFromFile,
|
||||
risultato,
|
||||
cosafare,
|
||||
ListaCmd,
|
||||
eseguiCmd,
|
||||
caricaDatiToggle,
|
||||
caricadati,
|
||||
createProvLink,
|
||||
risraw,
|
||||
importasulserver,
|
||||
skipfirstrow,
|
||||
eseguiCmdProduct,
|
||||
checkAggiornaQta,
|
||||
eseguiCmdInventario,
|
||||
eseguiCmdCatalogoJson,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
49
src/rootgen/admin/importaprodotti/importaprodotti.vue
Executable file
49
src/rootgen/admin/importaprodotti/importaprodotti.vue
Executable file
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<CMyPage
|
||||
img=""
|
||||
title="Importa Prodotti"
|
||||
keywords=""
|
||||
description=""
|
||||
>
|
||||
<div class="q-ma-sm">
|
||||
<q-toggle
|
||||
v-model="skipfirstrow"
|
||||
label="Salta la prima riga"
|
||||
></q-toggle>
|
||||
<q-toggle
|
||||
v-model="checkAggiornaQta"
|
||||
label="Aggiorna Quantità in Magazzino"
|
||||
></q-toggle>
|
||||
<label class="text-reader">
|
||||
<input
|
||||
type="file"
|
||||
@change="loadTextFromFile"
|
||||
/>
|
||||
</label>
|
||||
<br />
|
||||
|
||||
<br />
|
||||
<div class="row justify-center">
|
||||
<q-btn
|
||||
label="Importa Prodotti"
|
||||
@click="eseguiCmdProduct"
|
||||
></q-btn>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<div>{{ risraw }}</div>
|
||||
|
||||
<div
|
||||
v-if="risultato"
|
||||
v-html="risultato.substring(0, 1000)"
|
||||
></div>
|
||||
<br />
|
||||
<br />
|
||||
</div>
|
||||
</CMyPage>
|
||||
</template>
|
||||
<script lang="ts" src="./importaprodotti.ts"></script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './importaprodotti.scss';
|
||||
</style>
|
||||
Reference in New Issue
Block a user