Skip to content

Commit c92facd

Browse files
authored
Merge pull request #11 from cantierecreativo/master
some fix and style improvements
2 parents 959e5cf + 6ac4f37 commit c92facd

52 files changed

Lines changed: 1533 additions & 875 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

editor/src/app/components/Info.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { Component } from "react";
2+
import { connect } from "react-redux";
3+
import { show } from "../store/infobox";
4+
5+
const ReadMore = props => {
6+
if (!props.description) return null;
7+
let partial = ellipsis(props.description);
8+
return <small className="form-text text-muted">{partial}</small>;
9+
};
10+
11+
const ellipsis = descr => {
12+
let partial = descr;
13+
if (descr.length > MAX_LEN) {
14+
partial = descr.substring(0, MAX_LEN - 1) + "...";
15+
}
16+
return partial;
17+
};
18+
19+
const MAX_LEN = 100;
20+
21+
const mapStateToProps = state => {
22+
return {};
23+
};
24+
25+
const mapDispatchToProps = dispatch => {
26+
return {
27+
show: data => dispatch(show(data))
28+
};
29+
};
30+
31+
@connect(
32+
mapStateToProps,
33+
mapDispatchToProps
34+
)
35+
export default class InfoBox extends Component {
36+
constructor(props) {
37+
super(props);
38+
}
39+
render() {
40+
if (!(this.props.title || this.props.description)) return null;
41+
let { title, description } = this.props;
42+
let partial = ellipsis(description);
43+
return (
44+
<div className="field_info">
45+
<small className="form-text text-muted">
46+
<span>{partial}</span>
47+
{description.length > MAX_LEN && (
48+
<span>
49+
<a
50+
href="#"
51+
className="link"
52+
onClick={() => {
53+
console.log("CLICK", description);
54+
this.props.show({ title, description });
55+
}}
56+
>
57+
Read more
58+
</a>
59+
</span>
60+
)}
61+
</small>
62+
</div>
63+
);
64+
}
65+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { Component } from "react";
2+
import { connect } from "react-redux";
3+
import { show, hide } from "../store/infobox";
4+
import classNames from "classnames";
5+
import img_close from "../../asset/img/close.svg";
6+
7+
const mapStateToProps = state => {
8+
return {
9+
infobox: state.infobox
10+
};
11+
};
12+
13+
const mapDispatchToProps = dispatch => {
14+
return {
15+
show: data => dispatch(show(data)),
16+
hide: () => dispatch(hide())
17+
};
18+
};
19+
20+
@connect(
21+
mapStateToProps,
22+
mapDispatchToProps
23+
)
24+
export default class InfoBox extends Component {
25+
constructor(props) {
26+
super(props);
27+
}
28+
render() {
29+
const { title, description, visible } = this.props.infobox;
30+
const className = classNames([
31+
"info__box",
32+
{ info__box__visible: visible }
33+
]);
34+
35+
console.log("CLASSNAME", className);
36+
return (
37+
<div className={className}>
38+
<div className="info__box__body">
39+
<div className="info__box__close">
40+
<a
41+
href="#"
42+
className="link"
43+
onClick={() => this.props.hide(description)}
44+
>
45+
<img src={img_close} />
46+
</a>
47+
</div>
48+
49+
<div className="info__box__content">
50+
<p className="info__box__title">{title}</p>
51+
<p>{description}</p>
52+
</div>
53+
</div>
54+
</div>
55+
);
56+
}
57+
}

editor/src/app/components/editor.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import jsyaml from "../../../node_modules/js-yaml/dist/js-yaml.js";
1515

1616
import _ from "lodash";
1717
import u from "updeep";
18-
import validator from "validator";
18+
import moment from "moment";
19+
1920
import cleanDeep from "clean-deep";
2021

2122
import Head from "./head";
2223
import Foot from "./foot";
2324
import EditorForm from "./editorForm";
25+
import InfoBox from "./InfoBox";
2426

2527
import LanguageSwitcher from "./languageSwitcher";
2628
import Sidebar from "./sidebar";
@@ -64,7 +66,8 @@ export default class Index extends Component {
6466
blocks: null,
6567
elements: null,
6668
activeSection: 0,
67-
allFields: null
69+
allFields: null,
70+
lastGen: null
6871
};
6972
}
7073

@@ -75,24 +78,28 @@ export default class Index extends Component {
7578
$('[data-toggle="dropdown"]').dropdown();
7679
}
7780

78-
componentDidMount() {
79-
this.initData();
81+
async componentDidMount() {
82+
await this.initData();
8083
this.switchLang("eng");
84+
this.switchCountry("it");
8185
}
8286

83-
initData(country = null) {
87+
async initData(country = null) {
8488
//has state
85-
let { elements, blocks, allFields } = getData(country);
89+
console.log("initData");
90+
let { elements, blocks, allFields } = await getData(country);
8691
this.setState({ elements, blocks, country, allFields });
8792
this.initBootstrap();
8893
}
8994

9095
parseYml(yaml) {
9196
//HAS STATE
92-
97+
this.setState({ loading: true });
9398
let obj = null;
9499
try {
95100
obj = jsyaml.load(yaml);
101+
// let errors = fv.validatePubliccodeYml(obj);
102+
// if (errors) alert(errors);
96103
} catch (e) {
97104
alert("Error loading yaml");
98105
return;
@@ -113,7 +120,8 @@ export default class Index extends Component {
113120
yaml,
114121
languages,
115122
values,
116-
country
123+
country,
124+
loading: false
117125
});
118126

119127
//RESET FORM
@@ -122,11 +130,16 @@ export default class Index extends Component {
122130
}
123131

124132
generate(formValues) {
133+
let lastGen = moment();
134+
this.setState({ loading: true, lastGen });
125135
//has state
126136
let { values, currentLanguage, country } = this.state;
127137
//values[currentLanguage] = formValues;
128138
let obj = ft.transform(values, country);
129139

140+
// let errors = await fv.validatePubliccodeYml(obj);
141+
// if (errors) alert(errors);
142+
130143
//SET TIMESTAMP
131144
this.showResults(obj);
132145
//this.showResults(obj);
@@ -136,7 +149,7 @@ export default class Index extends Component {
136149
//has state
137150
try {
138151
let yaml = jsyaml.dump(values);
139-
this.setState({ yaml });
152+
this.setState({ yaml, loading: false });
140153
} catch (e) {
141154
console.error(e);
142155
}
@@ -172,10 +185,14 @@ export default class Index extends Component {
172185
//has state
173186
let errors = {};
174187
let { values, currentLanguage, elements } = this.state;
188+
175189
//CHECK REQUIRED FIELDS
176-
errors = fv.validateRequired(contents, elements, errors);
190+
let required = fv.validateRequired(contents, elements);
177191
//VALIDATE TYPES AND SUBOBJECT
178-
errors = fv.validateSubTypes(contents, elements, errors);
192+
let objs_n_arrays = fv.validateSubTypes(contents, elements);
193+
errors = Object.assign(required, objs_n_arrays);
194+
// console.log(errors);
195+
179196
//UPDATE STATE
180197
values[currentLanguage] = contents;
181198
this.setState({
@@ -188,7 +205,7 @@ export default class Index extends Component {
188205
return errors;
189206
}
190207

191-
reset() {
208+
async reset() {
192209
//has state
193210
this.props.initialize(APP_FORM, null);
194211
this.setState({
@@ -207,7 +224,7 @@ export default class Index extends Component {
207224
activeSection: null
208225
});
209226
this.props.notify({ type: "info", msg: "Reset" });
210-
this.initData();
227+
await this.initData();
211228
}
212229

213230
renderFoot() {
@@ -317,10 +334,10 @@ export default class Index extends Component {
317334
this.props.initialize(APP_FORM, currentValues);
318335
}
319336

320-
switchCountry(country) {
337+
async switchCountry(country) {
321338
//has state
322339
let { currentValues } = this.state;
323-
this.initData(country);
340+
await this.initData(country);
324341
this.props.initialize(APP_FORM, currentValues);
325342
}
326343

@@ -346,7 +363,8 @@ export default class Index extends Component {
346363
blocks,
347364
activeSection,
348365
country,
349-
allFields
366+
allFields,
367+
lastGen
350368
} = this.state;
351369

352370
let errors = null;
@@ -363,7 +381,7 @@ export default class Index extends Component {
363381
return (
364382
<Fragment>
365383
<div className="content">
366-
<Head />
384+
<Head lastGen={lastGen} />
367385
{this.langSwitcher()}
368386
<div className="content__main" id="content__main">
369387
{currentLanguage &&
@@ -382,6 +400,7 @@ export default class Index extends Component {
382400
)}
383401
</div>
384402
{currentLanguage && this.renderFoot()}
403+
<InfoBox />
385404
</div>
386405
{this.renderSidebar()}
387406
</Fragment>

editor/src/app/components/editorForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const renderBlockItems = (items, id) => {
3737

3838
const renderHeader = props => {
3939
let img_arrow = img_accordion_closed;
40-
if (props.activeSection == (props.block.index-1)) {
40+
if (props.activeSection == props.block.index - 1) {
4141
img_arrow = img_accordion_open;
4242
}
4343
return (

editor/src/app/components/foot.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ export default class foot extends Component {
2828
<div className="content__foot">
2929
<div className="content__foot_item">
3030
<button
31-
className="btn btn-lg btn-outline-primary"
31+
className="editor_button editor_button--custom"
3232
onClick={() => this.props.reset()}
3333
>
3434
Reset
3535
</button>
3636
</div>
37-
<div className="content__foot_item" />
3837
<div className="content__foot_item">
3938
<button
4039
type="button"
41-
className="btn btn-lg btn-primary"
40+
className="editor_button editor_button--primary"
41+
4242
onClick={() => {
4343
this.props.submit(APP_FORM);
4444
setTimeout(() => {
@@ -53,4 +53,4 @@ export default class foot extends Component {
5353
);
5454
}
5555
}
56-
// disabled={form[APP_FORM].submitFailed && form[APP_FORM].syncErrors}
56+
//disabled={form[APP_FORM].submitFailed && form[APP_FORM].syncErrors}

0 commit comments

Comments
 (0)