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

link items by subcategories

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