Commit d203ac43 by Иван Кубота

link items by subcategories

parent 0d810859
Pipeline #542 canceled with stage
......@@ -441,7 +441,8 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
//fs.writeFileSync('tmp.json',JSON.stringify(Object.values(data.products).map(({id, title})=>({id, title}))));
data.more = data.more || [];
var tid = 1, cid = 1;
var tagsHash = {};
data.more = data.more.concat([
{p: '1cards.csv', i: '1components.csv'},
{q: '2questions.csv', a: '2answers.csv', c: '2cards.csv'},
......@@ -452,6 +453,8 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
let theInc = ()=>id++;
if(data.more){
for( let i = 0, _i = data.more.length; i < _i; i++ ){
var adishen = i*300;
const moreElement = data.more[ i ];
if( moreElement.p ){
data.products = await readCSV({
......@@ -481,14 +484,30 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
a.use = ( a.use + '' )[ 0 ].toLowerCase() in { 'д': 1, '1': 1, 'y': '1', 'c': '1' };
a.type = 1;
id = Math.max(id, a.id);
a.id = adishen+a.id;
a.category_id = a.category_id |0;
let h = dumpedHash[normalizeText(a.title)]
if(h)
a.image = h.image;
a.items = [];
/* var norm = normalizeText(a.subcat);
if(!norm)
debugger
if(!(norm in tagsHash)){
console.log(norm, a.subcat)
data.tags.push(tagsHash[norm] = {id: tid++, name: a.subcat})
}
data.connections.push({
cid: cid++,
type: 0,
eid: a.id,
tag: tagsHash[norm].id
});*/
},
index: 'id'
});
debugger
theInc();
data.components = await readCSV({
fileName: path.join(base, moreElement.i),
......@@ -502,6 +521,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
},
postProcess: (a, inc) => {
a.iID = inc()
a.id = adishen+a.id;
data.products[a.id].items.push(a);
},
......@@ -525,7 +545,10 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
image: String
},
postProcess: ( a, inc ) => {
if( a.description.trim() === '' ) return false;
a.id = adishen+a.id;
a.use = ( a.use + '' )[ 0 ].toLowerCase() in { 'д': 1, '1': 1, 'y': '1', 'c': '1' };
a.type = 2;
a.category_id = moreElement.c[0]|0;
......@@ -562,6 +585,9 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
},
postProcess: ( a ) => {
if( a.title.trim() === '' ) return false;
a.cardInfoID = adishen+a.cardInfoID;
a.qID = adishen+a.qID;
a.answers = [];
a.multiple = ( a.multiple + '' )[ 0 ].toLowerCase() in { 'д': 1, '1': 1, 'y': '1', 'c': '1' };
a.image = null;
......@@ -584,6 +610,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
postProcess: ( a, inc ) => {
if( a.title.trim() === '' ) return false;
a.id = inc();
a.qID += adishen
a.correct = ( a.correct + '' )[ 0 ].toLowerCase() in { 'д': 1, '1': 1, 'y': '1', 'c': '1' };
},
index: 'id'
......
......@@ -34,18 +34,20 @@ const dataProvider = {
(dP.componentsListHashByProduct[cmp.id] || (dP.componentsListHashByProduct[cmp.id] = [])).push(cmp);
}
if(useSubSub){
data.tags = [];
data.connections = [];
dP.tagsHash = {};
Object.values( data.products ).forEach( function( item ){
const tag = dP.Tag.getOrCreate( item.subsubcat );
dP.Tag.connectToProduct( dP.Product.getByID( item.id ), tag );
if(item.subcat){
const tag = dP.Tag.getOrCreate( item.subcat );
dP.Tag.connectToProduct( dP.Product.getByID( item.id ), tag );
}
} );
}else{
dP.tagsHash = data.tags.reduce( ( store, item ) => {
dP.maxTagID = Math.max( dP.maxTagID, item.id );
store[ item.id ] = item;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment