fixed new entry load morphs
parent
576d61b0e2
commit
b45e2268b2
|
|
@ -1,11 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import * as _ from 'lodash';
|
||||
import {
|
||||
textInput,
|
||||
selectInput,
|
||||
imagePreview,
|
||||
listInput
|
||||
} from './LexSingleInput';
|
||||
import { componentForType} from './LexSingleInput';
|
||||
import {
|
||||
Card,
|
||||
Button
|
||||
|
|
@ -38,31 +33,11 @@ export class LexEdit extends React.Component<any, any> {
|
|||
let origValue = fieldMeta.get(this.props.lexItem);
|
||||
let options = fieldMeta.options;
|
||||
let changed = !_.isEqual(value, origValue) && this.props.existing;
|
||||
let sh = (e: any) => {
|
||||
let eventData = {};
|
||||
eventData[field] = e.target.value;
|
||||
this.handleOnChange(eventData);
|
||||
let sh = (v: any) => {
|
||||
this.handleOnChange({ field, value: v });
|
||||
};
|
||||
let params = { field, sh, value, options, langSelOpts, changed };
|
||||
switch (fieldMeta.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 :', fieldMeta.type);
|
||||
console.log('values discarded :', fieldMeta.get(li));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return componentForType(fieldMeta.type, params);
|
||||
});
|
||||
return (
|
||||
<Box m={2}>
|
||||
|
|
@ -131,9 +106,8 @@ export class LexEdit extends React.Component<any, any> {
|
|||
}
|
||||
|
||||
private handleOnChange(event: any) {
|
||||
let type = _.keys(event)[0];
|
||||
let value = _.values(event)[0] as string;
|
||||
let meta = this.props.fieldMetaMap[type];
|
||||
let { field, value } = event;
|
||||
let meta = this.props.fieldMetaMap[field];
|
||||
let lexItem = meta.set(this.state.lexItem, value);
|
||||
this.setState({ lexItem });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ function simpleAttrAccessor(attrPred: any) {
|
|||
});
|
||||
_.set(prop, '[0]._', value);
|
||||
} else {
|
||||
_.set(lexItem, lens, def(value));
|
||||
_.set(lexItem, lens, [def(value)]);
|
||||
}
|
||||
return lexItem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Label, Form } from 'semantic-ui-react';
|
|||
const { Flex, Box } = require('reflexbox');
|
||||
import {
|
||||
Input,
|
||||
Dropdown,
|
||||
Image
|
||||
} from 'semantic-ui-react';
|
||||
|
||||
|
|
@ -38,9 +39,7 @@ function changedLabel(changed: boolean, text: string) {
|
|||
);
|
||||
}
|
||||
|
||||
const imageRoot = '/png/';
|
||||
|
||||
export function textInput(params: any) {
|
||||
function textInput(params: any) {
|
||||
let { field, sh, value, changed } = params;
|
||||
return (
|
||||
<LexSingleInput
|
||||
|
|
@ -48,7 +47,7 @@ export function textInput(params: any) {
|
|||
key={field}
|
||||
>
|
||||
<Input
|
||||
onChange={sh}
|
||||
onChange={(e, d) => { sh(d.value); }}
|
||||
value={value}
|
||||
placeholder={field}
|
||||
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 staticOpts = options;
|
||||
let fieldOpts = _.get<any>(langSelOpts, field, []);
|
||||
let selOpts = staticOpts ? staticOpts : fieldOpts;
|
||||
let dropOptions = selOpts.map((k: any, i: any, c: any) => {
|
||||
return { key: i, value: k, text: k };
|
||||
});
|
||||
return (
|
||||
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
||||
<select
|
||||
onChange={sh}
|
||||
style={{ width: '10em' }}
|
||||
<Dropdown
|
||||
options={dropOptions}
|
||||
onChange={(e, d) => { sh(d.value); }}
|
||||
value={value}
|
||||
>
|
||||
{selOpts.map((k: any, i: any, c: any) => {
|
||||
return <option key={i} value={k}> {k}</option>;
|
||||
})}
|
||||
</select>
|
||||
compact={true}
|
||||
selection={true}
|
||||
style={{ width: '10em' }}
|
||||
/>
|
||||
</LexSingleInput>
|
||||
);
|
||||
}
|
||||
|
||||
export function imagePreview(params: any) {
|
||||
function imagePreview(params: any) {
|
||||
let { field, value, changed } = params;
|
||||
let imageSrc = imageRoot + value;
|
||||
let imageSrc = '/png/' + value;
|
||||
return value !== '' ? (
|
||||
<LexSingleInput key={field} label={changedLabel(changed, field)}>
|
||||
<Image src={imageSrc} size="tiny" bordered={true} />
|
||||
|
|
@ -89,7 +90,7 @@ export function imagePreview(params: any) {
|
|||
) : textInput(params);
|
||||
}
|
||||
|
||||
export function listInput(params: any) {
|
||||
function listInput(params: any) {
|
||||
let { field, value, changed } = params;
|
||||
console.log('field: ', field, 'value: ', value);
|
||||
return (
|
||||
|
|
@ -98,3 +99,25 @@ export function listInput(params: any) {
|
|||
</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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from flask import Flask,send_from_directory,request
|
||||
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
|
||||
import json
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ def walle_morph():
|
|||
word = request.args.get('word','water')
|
||||
pos_req = request.args.get('pos','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
|
||||
# import requests
|
||||
|
|
|
|||
Loading…
Reference in New Issue