added list editor for syntacticprops and selection for cat/subcat

master
Malar Kannan 2017-07-27 17:13:40 +05:30
parent b45e2268b2
commit c715944fa2
2 changed files with 87 additions and 11 deletions

View File

@ -47,6 +47,36 @@ function simpleAttrAccessor(attrPred: any) {
}
function listAttrAccessor(attrPred: any) {
let { pred, lens } = attrPred;
return {
get: (li: any) => {
let def: any = [];
let morphProps = _.get<any>(li, lens, def);
let morphExps = _.filter<any>(morphProps, (m) => {
return pred(m);
});
let mEs = morphExps.map((me) => {
return _.get<any>(me, '_', me);
});
return mEs;
},
set: (li: any, value: any) => {
let lexItem = _.cloneDeep(li);
let allProps = _.get<any>(lexItem, lens, []);
if (allProps.length > 0) {
let keepProps = _.filter<any>(allProps, (m) => {
return !pred(m);
});
_.set(lexItem, lens, _.concat(keepProps, value));
} else {
_.set(lexItem, lens, value);
}
return lexItem;
}
};
}
function propListAttrAccessor(attrPred: any) {
let { attribKey, pred, lens } = attrPred;
return {
get: (li: any) => {
@ -66,10 +96,10 @@ function listAttrAccessor(attrPred: any) {
let lexItem = _.cloneDeep(li);
let allProps = _.get<any>(lexItem, lens, []);
if (allProps.length > 0) {
let prop = _.filter<any>(allProps, (m) => {
return pred(m);
let keepProps = _.filter<any>(allProps, (m) => {
return !pred(m);
});
_.set(prop, '[0]._', value);
_.set(lexItem, lens, _.concat(keepProps, value));
} else {
_.set(lexItem, lens, value);
}
@ -103,6 +133,24 @@ const fieldMetaMap = {
_.isEqual
)),
},
cat: {
type: 'select',
...simpleAttrAccessor(attrPredGen(
'uiprops[0].property',
'id',
'cat',
_.isEqual
)),
},
subcat: {
type: 'select',
...simpleAttrAccessor(attrPredGen(
'uiprops[0].property',
'id',
'subcat',
_.isEqual
)),
},
morphclass: {
type: 'select',
...simpleAttrAccessor(attrPredGen(
@ -113,8 +161,8 @@ const fieldMetaMap = {
))
},
morphexceptions: {
type: 'list',
...listAttrAccessor(attrPredGen(
type: 'proplist',
...propListAttrAccessor(attrPredGen(
'lexprops[0].morphology[0].morph',
'form',
'morphclass',
@ -135,6 +183,7 @@ const fieldMetaMap = {
_.negate(_.isEqual)
))
},
};
const xmlToEntries = (xmlData: any) => {
@ -158,12 +207,14 @@ const xmlToEntries = (xmlData: any) => {
let langs = _.keys(langEntries);
let selectFields = _.fromPairs(langs.map((lang) => {
let langOpts = _.fromPairs(_.keys(fieldMetaMap).filter((s) => {
return fieldMetaMap[s].type === 'select';
return _.includes(['select', 'list'], fieldMetaMap[s].type);
}).map((s) => {
let entries = _.get<any>(langEntries, lang, 'en');
let selectOptions = _.uniq(entries.map((q: any) => {
let allOpts = entries.map((q: any) => {
return fieldMetaMap[s].get(q);
}));
});
let select = _.isEqual(fieldMetaMap[s].type, 'select');
let selectOptions = select ? _.uniq(allOpts) : _.uniq(_.flatten(allOpts));
return [s, selectOptions];
}));
return [lang, langOpts];

View File

@ -74,6 +74,7 @@ function selectInput(params: any) {
value={value}
compact={true}
selection={true}
search={true}
style={{ width: '10em' }}
/>
</LexSingleInput>
@ -91,11 +92,34 @@ function imagePreview(params: any) {
}
function listInput(params: any) {
let { field, value, changed } = params;
console.log('field: ', field, 'value: ', value);
let { field, sh, langSelOpts, value, changed } = params;
let fieldOpts = _.get<any>(langSelOpts, field, []);
let renderLabel = (label: any) => ({
content: `${label.value}`,
});
let dropOptions = fieldOpts.map((k: any, i: any, c: any) => {
return {
key: i,
value: k,
text: k,
};
});
return (
<LexSingleInput key={field} label={changedLabel(changed, field)}>
<pre>{JSON.stringify(value)}</pre>
<Dropdown
options={dropOptions}
onChange={(e, d) => {
sh(d.value);
}}
value={value}
compact={true}
selection={true}
search={true}
multiple={true}
fluid={true}
style={{ width: '10em' }}
renderLabel={renderLabel}
/>
</LexSingleInput>
);
}
@ -112,6 +136,7 @@ export function componentForType(type: string, params: any) {
return imagePreview(params);
}
case 'list': {
// return (<ListInput params={params} />);
return listInput(params);
}
default: {