@@ -15,12 +15,14 @@ import jsyaml from "../../../node_modules/js-yaml/dist/js-yaml.js";
1515
1616import _ from "lodash" ;
1717import u from "updeep" ;
18- import validator from "validator" ;
18+ import moment from "moment" ;
19+
1920import cleanDeep from "clean-deep" ;
2021
2122import Head from "./head" ;
2223import Foot from "./foot" ;
2324import EditorForm from "./editorForm" ;
25+ import InfoBox from "./InfoBox" ;
2426
2527import LanguageSwitcher from "./languageSwitcher" ;
2628import 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 >
0 commit comments