Skip to content

Commit

Permalink
Merge pull request #380 from raippl/master
Browse files Browse the repository at this point in the history
fix organizations on full, superset open, new form improvements
  • Loading branch information
raippl authored Sep 27, 2018
2 parents b69bffa + 833e652 commit 7d9a52a
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 93 deletions.
2 changes: 2 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ function fetchDatasetDetail(datasetname, query, isPublic) {
export function getSchema(filesToUpload, typeFile) {
console.log('getSchema');
var url = serviceurl.apiURLDatiGov + "/infer/kylo/" + typeFile
//var url = 'http://localhost:3001/dati-gov/v1/infer/kylo/csv'
var token = '';
if(localStorage.getItem('username') && localStorage.getItem('token') &&
localStorage.getItem('username') !== 'null' && localStorage.getItem('token') !== 'null'){
Expand All @@ -1180,6 +1181,7 @@ function fetchDatasetDetail(datasetname, query, isPublic) {
export function getSchemaWS(url, typeFile) {
console.log('getSchemaWS');
var url = serviceurl.apiURLDatiGov + "/infer/ws/kylo/" + encodeURIComponent(url) + "/" + typeFile
//var url = 'http://localhost:3001/dati-gov/v1/infer/kylo/csv'
var token = '';
if(localStorage.getItem('username') && localStorage.getItem('token') &&
localStorage.getItem('username') !== 'null' && localStorage.getItem('token') !== 'null'){
Expand Down
6 changes: 2 additions & 4 deletions src/components/Cards/WidgetCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ class WidgetCard extends Component {
}
}

//TODO: need review (PPL 11/09/2018)
//iframe_url:"https://bi.dataportal
var open
if(iframe.iframe_url && iframe.iframe_url.indexOf('https://bi.dataportal')===0){
if(iframe.iframe_url && iframe.iframe_url.indexOf(serviceurl.urlSuperset)>-1){
open = false
}else if(iframe.iframe_url && iframe.iframe_url.indexOf('https://bi.open.dataportal')===0){
}else if(iframe.iframe_url && iframe.iframe_url.indexOf(serviceurl.urlSupersetOpen)>-1){
open = true
}

Expand Down
130 changes: 130 additions & 0 deletions src/components/IngestionWizardForm/AutocompleteSemantic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React from 'react'
import Autocomplete from 'react-autocomplete'
import { serviceurl } from '../../config/serviceurl.js'

function escapeRegexCharacters(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

function getSuggestions(value, data) {
const escapedValue = escapeRegexCharacters(value.trim());
if (escapedValue === '') {
return [];
}

const regex = new RegExp('^' + escapedValue, 'i');
return ontologiesFilter(data, regex);
}

function ontologiesFilter(semantics, regex){
var res = [];

if(semantics.length>0){
semantics.forEach(function(entry) {
var domainId = entry.universe.value
var domain = entry.universe.domain.label[0].value
var property = entry.universe.property.label[0].value
var range = entry.universe.range.label[0].value
entry.name = '[' + domain +'] '+ property +'; ('+ range +')'
res.push(entry);
});
}
return res;
}

class AutocompleteSemantic extends React.Component {

state = {
value: '',
id: '',
suggestions: [],
}

getSuggestion(input) {
var that = this;
var token = '';
var url = serviceurl.urlSemantic;

var details = {
'name': input + '*',
'lang': 'it'
};
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");

if(localStorage.getItem('username') && localStorage.getItem('token') &&
localStorage.getItem('username') != 'null' && localStorage.getItem('token') != 'null'){
token = localStorage.getItem('token')
}
return fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: formBody
}).then(response => response.json())
.then(json => {
var test = getSuggestions(input, json)
.map((entry, index) => (
{'id': entry.universe.value, 'name' : entry.name, 'context': entry.contexts, 'subject': entry.universe.domain.id, 'predicate': entry.universe.property.id, 'rdf_object': entry.universe.range.id, 'uri_voc': entry.universe.range.controlledVocabularies&&entry.universe.range.controlledVocabularies.length>0?entry.universe.range.controlledVocabularies[0]:''}
)
)
this.setSuggestion(test)
})
}

setSuggestion(json){
this.setState({ suggestions: json });
}

render() {
const { label } = this.props;
return (
<div className="form-group row">
<label className="col-md-2 col-form-label">{label}</label>
<div className="col-md-10">
<Autocomplete
inputProps={{ id: 'states-autocomplete-semantic', name: this.props.input.name, type: 'text' }}
wrapperStyle={{ display: 'block' }}
value={this.state.value}
items={this.state.suggestions}
getItemValue={(item) => item.name}
onSelect={(value, item) => {
this.setState({ value, id: item.id, suggestions: [ item ] })
this.props.addSemanticToForm(value, item.id, item.context, item.subject, item.predicate, item.rdf_object, item.uri_voc, this.props.index, this.props.wizard, this.props.dispatchAction, this.props.aggiornaStato)
}}
onChange={(event, value) => {
this.setState({ value })
if(value!==''){
var suggestion = this.getSuggestion(value);
}else{
this.setState({ suggestions: [] });
this.props.addSemanticToForm('', '', '', '', '', '', '', this.props.index, this.props.wizard, this.props.dispatchAction, this.props.aggiornaStato)
}
}}
renderMenu={(children, index) => (
<div className="menu" key={index} style={{position: 'relative', zIndex: 9999}}>
{children}
</div>
)}

renderItem={(item, isHighlighted) => (
<div className={`item ${isHighlighted ? 'item-highlighted' : ''}`}
key={item.name}>
{(item.name)}
</div>
)}
/>
</div>
</div>
)
}
}

export default AutocompleteSemantic
24 changes: 24 additions & 0 deletions src/components/IngestionWizardForm/Convenzioni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {Component, PropTypes} from 'react';
import Dropzone from 'react-dropzone';
import { Field } from 'redux-form';

class Convenzioni extends Component {
constructor(props){
super(props)
this.state={
}
}

componentDidMount(){
}

render() {
const { } = this.props;
return (
<div>

</div>
);
}
}
export default Convenzioni
3 changes: 2 additions & 1 deletion src/components/IngestionWizardForm/WizardForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class WizardForm extends Component {
if(filesToUpload.length>0){
this.setState({errorDrop:''})
dispatch(getSchema(filesToUpload, 'csv'))//defaul value is csv
.then(json => { this.calcDataFields(fields, JSON.parse(json))
//.then(json => { this.calcDataFields(fields, JSON.parse(json))
.then(json => { this.calcDataFields(fields, json)
this.setUploading(false, undefined);
dispatch(change('wizard', 'separator', json.separator))
dispatch(change('wizard', 'filesToUpload', filesToUpload))
Expand Down
16 changes: 8 additions & 8 deletions src/components/IngestionWizardForm/WizardFormFirstPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Field, FieldArray, reduxForm, formValueSelector } from 'redux-form';
import { connect } from 'react-redux';
import { renderFieldInput, renderFieldTextArea, renderFieldSelect, renderFieldInputButton, renderFieldCheckbox} from './renderField';
import { publicOptions, tipodatasetOptions, modalitacaricamentoOptions, tempoDiPollingOptions, timerUnita } from './const';
import { ingestionFormOptions } from './const';
import validate from './validate';
import FileInput from './FileInput'

Expand All @@ -22,7 +22,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
/>
<Field
name="public"
options={publicOptions}
options={ingestionFormOptions.publicOptions}
component={renderFieldSelect}
label="Pubblico/OpenData"
/>
Expand Down Expand Up @@ -52,7 +52,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
/>
<Field
name="tipodataset"
options={tipodatasetOptions}
options={ingestionFormOptions.tipodatasetOptions}
component={renderFieldSelect}
label="Tipo Dataset"
/>
Expand All @@ -65,7 +65,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
<div>
<Field
name="modalitacaricamento"
options={modalitacaricamentoOptions}
options={ingestionFormOptions.modalitacaricamentoOptions}
component={renderFieldSelect}
label="Modalità Caricamento"
/>
Expand All @@ -82,7 +82,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
/>
<Field
name="tempopolling"
options={tempoDiPollingOptions}
options={ingestionFormOptions.tempoDiPollingOptions}
component={renderFieldSelect}
label="Tempo di Polling"
/>
Expand All @@ -102,7 +102,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
/>
<Field
name="timerunita"
options={timerUnita}
options={ingestionFormOptions.timerUnita}
component={renderFieldSelect}
label="Unità"
/>
Expand Down Expand Up @@ -150,7 +150,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
<div className="col-md-12">
<Field
name="tempopolling"
options={tempoDiPollingOptions}
options={ingestionFormOptions.tempoDiPollingOptions}
component={renderFieldSelect}
label="Tempo di Polling"
/>
Expand All @@ -170,7 +170,7 @@ const renderFieldArray = ({fields, setName, onDropFunction, getCategoria, sottoc
/>
<Field
name="timerunita"
options={timerUnita}
options={ingestionFormOptions.timerUnita}
component={renderFieldSelect}
label="Unità"
/>
Expand Down
41 changes: 32 additions & 9 deletions src/components/IngestionWizardForm/WizardFormSecondPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { Field, FieldArray, reduxForm, formValueSelector } from 'redux-form';
import { connect } from 'react-redux';
import validate from './validate';
import AutocompleteSemantic from '../Autocomplete/AutocompleteSemantic'
import { yesOrNoOptions } from './const'
import { ingestionFormOptions } from './const';
import AutocompleteSemantic from './AutocompleteSemantic'
import { renderFieldInput, renderFieldTextArea, renderFieldSelect, renderTipi, renderFieldTags, renderContesti, renderFieldCheckbox} from './renderField';
import Collapse from 'rc-collapse'
import 'rc-collapse/assets/index.css'
Expand Down Expand Up @@ -36,7 +36,17 @@ let WizardFormSecondPage = props => {

const renderFieldArray = ({fields, tipi, addTagsToForm, aggiornaStato, addSemanticToForm, context, previousPage, meta : {touched, error} }) =>
<div>
{fields.map((field, index) =>
{fields.map((field, index) => {
var convenzioniValue = fields.get(index).convenzioni
var campi = []
if(convenzioniValue && ingestionFormOptions.convenzioni){
for(var i=0;i<ingestionFormOptions.convenzioni.length;i++){
if(ingestionFormOptions.convenzioni[i].val==convenzioniValue){
campi = ingestionFormOptions.convenzioni[i].campi
}
}
}
return(
<div className="card" key={index}>
<div className="card-body">
<h5 className="card-title">Metadati campo <b>{fields.get(index).nome}</b></h5>
Expand Down Expand Up @@ -90,28 +100,40 @@ const renderFieldArray = ({fields, tipi, addTagsToForm, aggiornaStato, addSemant
<Panel header="Formato e Convenzioni">
<Field
name={`${field}.tipoinformazione`}
options={[]}
options={ingestionFormOptions.tipoinformazione}
component={renderFieldSelect}
label="Tipo Informazione"
value={`${field}.tipoinformazione`}
/>
<Field
name={`${field}.standardformat`}
options={[]}
options={ingestionFormOptions.standardformat}
component={renderFieldSelect}
label="Standard Format"
value={`${field}.standardformat`}
/>
<Field
name={`${field}.convenzioni`}
options={[]}
options={ingestionFormOptions.convenzioni}
component={renderFieldSelect}
label="Convenzioni"
value={`${field}.convenzioni`}
/>
{campi && campi.map((campo, index) => {
console.log('campo: ' + campo)
return(
<Field
name={`${field}.campo.${campo.val}`}
component={renderFieldInput}
label={campo.label}
value={`${field}.campo.${campo.val}`}
key={index}
/>)
})
}
<Field
name={`${field}.vocabolariocontrollato`}
options={[]}
options={ingestionFormOptions.vocabolariocontrollato}
component={renderFieldSelect}
label="Vocabolario Controllato"
value={`${field}.vocabolariocontrollato`}
Expand Down Expand Up @@ -198,14 +220,14 @@ const renderFieldArray = ({fields, tipi, addTagsToForm, aggiornaStato, addSemant
/>
<Field
name={`${field}.tipodatopersonale`}
options={[]}
options={ingestionFormOptions.tipodatopersonale}
component={renderFieldSelect}
label="Tipo Dato Personale"
value={`${field}.tipodatopersonale`}
/>
<Field
name={`${field}.tipomascheramento`}
options={[]}
options={ingestionFormOptions.tipomascheramento}
component={renderFieldSelect}
label="Tipo di Mascheramento"
value={`${field}.tipomascheramento`}
Expand All @@ -222,6 +244,7 @@ const renderFieldArray = ({fields, tipi, addTagsToForm, aggiornaStato, addSemant
</div>
</div>
)}
)}
<div>
<button type="button" className="btn btn-primary float-left" onClick={previousPage}>Indietro</button>
<button type="submit" className="btn btn-primary float-right">Avanti</button>
Expand Down
Loading

0 comments on commit 7d9a52a

Please sign in to comment.