fixed new entry load morphs

master
Malar Kannan 2017-07-27 13:09:48 +05:30
parent 576d61b0e2
commit b45e2268b2
4 changed files with 48 additions and 51 deletions

View File

@ -1,11 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { import { componentForType} from './LexSingleInput';
textInput,
selectInput,
imagePreview,
listInput
} from './LexSingleInput';
import { import {
Card, Card,
Button Button
@ -38,31 +33,11 @@ export class LexEdit extends React.Component<any, any> {
let origValue = fieldMeta.get(this.props.lexItem); let origValue = fieldMeta.get(this.props.lexItem);
let options = fieldMeta.options; let options = fieldMeta.options;
let changed = !_.isEqual(value, origValue) && this.props.existing; let changed = !_.isEqual(value, origValue) && this.props.existing;
let sh = (e: any) => { let sh = (v: any) => {
let eventData = {}; this.handleOnChange({ field, value: v });
eventData[field] = e.target.value;
this.handleOnChange(eventData);
}; };
let params = { field, sh, value, options, langSelOpts, changed }; let params = { field, sh, value, options, langSelOpts, changed };
switch (fieldMeta.type) { return componentForType(fieldMeta.type, params);
case 'text': {
return textInput(params);
}
case 'select': {
return selectInput(params);
}
case 'preview': {
return imagePreview(params);
}
case 'list': {
return listInput(params);
}
default: {
console.log('type discarded :', fieldMeta.type);
console.log('values discarded :', fieldMeta.get(li));
return null;
}
}
}); });
return ( return (
<Box m={2}> <Box m={2}>
@ -131,9 +106,8 @@ export class LexEdit extends React.Component<any, any> {
} }
private handleOnChange(event: any) { private handleOnChange(event: any) {
let type = _.keys(event)[0]; let { field, value } = event;
let value = _.values(event)[0] as string; let meta = this.props.fieldMetaMap[field];
let meta = this.props.fieldMetaMap[type];
let lexItem = meta.set(this.state.lexItem, value); let lexItem = meta.set(this.state.lexItem, value);
this.setState({ lexItem }); this.setState({ lexItem });
} }

View File

@ -39,7 +39,7 @@ function simpleAttrAccessor(attrPred: any) {
}); });
_.set(prop, '[0]._', value); _.set(prop, '[0]._', value);
} else { } else {
_.set(lexItem, lens, def(value)); _.set(lexItem, lens, [def(value)]);
} }
return lexItem; return lexItem;
} }

View File

@ -4,6 +4,7 @@ import { Label, Form } from 'semantic-ui-react';
const { Flex, Box } = require('reflexbox'); const { Flex, Box } = require('reflexbox');
import { import {
Input, Input,
Dropdown,
Image Image
} from 'semantic-ui-react'; } from 'semantic-ui-react';
@ -38,9 +39,7 @@ function changedLabel(changed: boolean, text: string) {
); );
} }
const imageRoot = '/png/'; function textInput(params: any) {
export function textInput(params: any) {
let { field, sh, value, changed } = params; let { field, sh, value, changed } = params;
return ( return (
<LexSingleInput <LexSingleInput
@ -48,7 +47,7 @@ export function textInput(params: any) {
key={field} key={field}
> >
<Input <Input
onChange={sh} onChange={(e, d) => { sh(d.value); }}
value={value} value={value}
placeholder={field} placeholder={field}
type="text" type="text"
@ -59,29 +58,31 @@ export function textInput(params: any) {
); );
} }
export function selectInput(params: any) { function selectInput(params: any) {
let { field, sh, value, options, langSelOpts, changed } = params; let { field, sh, value, options, langSelOpts, changed } = params;
let staticOpts = options; let staticOpts = options;
let fieldOpts = _.get<any>(langSelOpts, field, []); let fieldOpts = _.get<any>(langSelOpts, field, []);
let selOpts = staticOpts ? staticOpts : fieldOpts; let selOpts = staticOpts ? staticOpts : fieldOpts;
let dropOptions = selOpts.map((k: any, i: any, c: any) => {
return { key: i, value: k, text: k };
});
return ( return (
<LexSingleInput key={field} label={changedLabel(changed, field)}> <LexSingleInput key={field} label={changedLabel(changed, field)}>
<select <Dropdown
onChange={sh} options={dropOptions}
style={{ width: '10em' }} onChange={(e, d) => { sh(d.value); }}
value={value} value={value}
> compact={true}
{selOpts.map((k: any, i: any, c: any) => { selection={true}
return <option key={i} value={k}> {k}</option>; style={{ width: '10em' }}
})} />
</select>
</LexSingleInput> </LexSingleInput>
); );
} }
export function imagePreview(params: any) { function imagePreview(params: any) {
let { field, value, changed } = params; let { field, value, changed } = params;
let imageSrc = imageRoot + value; let imageSrc = '/png/' + value;
return value !== '' ? ( return value !== '' ? (
<LexSingleInput key={field} label={changedLabel(changed, field)}> <LexSingleInput key={field} label={changedLabel(changed, field)}>
<Image src={imageSrc} size="tiny" bordered={true} /> <Image src={imageSrc} size="tiny" bordered={true} />
@ -89,7 +90,7 @@ export function imagePreview(params: any) {
) : textInput(params); ) : textInput(params);
} }
export function listInput(params: any) { function listInput(params: any) {
let { field, value, changed } = params; let { field, value, changed } = params;
console.log('field: ', field, 'value: ', value); console.log('field: ', field, 'value: ', value);
return ( return (
@ -98,3 +99,25 @@ export function listInput(params: any) {
</LexSingleInput> </LexSingleInput>
); );
} }
export function componentForType(type: string, params: any) {
switch (type) {
case 'text': {
return textInput(params);
}
case 'select': {
return selectInput(params);
}
case 'preview': {
return imagePreview(params);
}
case 'list': {
return listInput(params);
}
default: {
console.log('type discarded :', type);
// console.log('values discarded :', fieldMeta.get(li));
return null;
}
}
}

View File

@ -1,6 +1,6 @@
from flask import Flask,send_from_directory,request from flask import Flask,send_from_directory,request
app = Flask(__name__,static_url_path='',static_folder='build') app = Flask(__name__,static_url_path='',static_folder='build')
# from freespeech_walle.get_morph_rule import get_morph from freespeech_walle.get_morph_rule import get_morph
# from freespeech_walle.wizard_helpers import get_morph_rule,get_frequency # from freespeech_walle.wizard_helpers import get_morph_rule,get_frequency
import json import json
@ -21,7 +21,7 @@ def walle_morph():
word = request.args.get('word','water') word = request.args.get('word','water')
pos_req = request.args.get('pos','N') pos_req = request.args.get('pos','N')
pos = pos_req if pos_req != '' else 'N'; pos = pos_req if pos_req != '' else 'N';
return json.dumps(get_morph_rule.get_morph(word,pos)) return json.dumps(get_morph(word,pos))
# hmr streaming # hmr streaming
# import requests # import requests