Skip to content

Commit

Permalink
FEATURE : Duplicate portfolio (closes #190)
Browse files Browse the repository at this point in the history
  • Loading branch information
AxelRagobert committed Jun 13, 2019
1 parent 77f001d commit 2b6c57b
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 28 deletions.
2 changes: 2 additions & 0 deletions etapes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modifier etc host
ajouter reverse proxy en local
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
"dependencies": {
"bootstrap": "^4.1.1",
"hypertopic": "^3.1.4",
"jquery": "^3.4.1",
"js-tree": "^2.0.1",
"json-groupby": "^1.0.2",
"open-iconic": "^1.1.1",
"query-string": "^4.3.4",
"react": "^16.4.0",
"react-autosuggest": "^9.3.4",
"react-bootstrap": "^1.0.0-beta.8",
"react-dom": "^16.4.0",
"react-router-dom": "^4.1.1",
"sort-by": "^1.2.0"
"sort-by": "^1.2.0",
"styled-components": "^4.2.0"
},
"devDependencies": {
"react-scripts": "1.1.5",
Expand Down
18 changes: 18 additions & 0 deletions reverse-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "reverse-proxy",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"express-http-proxy": "^1.5.1",
"http-proxy": "^1.17.0"
}
}
21 changes: 21 additions & 0 deletions reverse-proxy/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var express = require('express')
var cors = require('cors')
const proxy = require('express-http-proxy');

var app = express()

var corsOptions = {
origin: true,
optionsSuccessStatus: 200,
credentials: true
}

app.use(cors(corsOptions));
app.use(proxy('argos2.test.hypertopic.org'));




app.listen(80, function () {
console.log('CORS-enabled web server listening on port 80')
})
37 changes: 28 additions & 9 deletions src/components/Authenticated/Authenticated.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { Component } from 'react';
import conf from '../../config/config.json';
import Duplicator from '../Duplication/Duplicator'
import { Dropdown, DropdownButton, ButtonGroup, Button, Form } from 'react-bootstrap';

const SESSION_URI = conf.services[0] + '/_session';

Expand All @@ -18,24 +20,39 @@ class Authenticated extends Component {

render() {
if (this.state.user) {
if(this.props.portfolio){
return (
<div className="Authenticated">
<DropdownButton variant="secondary" alignRight as={ButtonGroup} title={this.state.user} id="bg-nested-dropdown">
<Dropdown.Item eventKey="1" onClick={this.handleLogout}>Se déconnecter</Dropdown.Item>
<Duplicator portfolio={this.props.portfolio} userConnected={this.state.user} viewpoints={this.props.viewpoints} corpora={this.props.corpora}/>
</DropdownButton>
</div>
);
}

return (
<div className="Authenticated"> {this.state.user}
<a href="#logout" onClick={this.handleLogout}>Se déconnecter</a>
<div className="Authenticated">
<DropdownButton variant="secondary" alignRight as={ButtonGroup} title={this.state.user} id="bg-nested-dropdown">
<Dropdown.Item eventKey="1" onClick={this.handleLogout}>Se déconnecter</Dropdown.Item>
</DropdownButton>
</div>
);
}
if (this.state.ask) {
return(
<form className="Authenticated" onSubmit={this.handleLogin}>
<input placeholder="nom d'utilisateur" ref={(x) => this.login = x} />
<input placeholder="mot de passe" ref={(x) => this.password = x} type="password" />
<input type="submit" value="Se connecter" />
</form>
<Form className="FormConnect" onSubmit={this.handleLogin}>
<Form.Control type="text" ref={(x) => this.login = x} placeholder="Nom d'utilisateur" />
<Form.Control type="password" ref={(x) => this.password = x} placeholder="Mot de passe" />
<Button variant="secondary" type="submit">
Confirmer
</Button>
</Form>
);
}
return (
<div className="Authenticated">
<a href="#login" onClick={this.handleAsk}>Se connecter...</a>
<Button href="#login" onClick={this.handleAsk} variant="secondary">Se connecter</Button>
</div>
);
}
Expand Down Expand Up @@ -82,7 +99,9 @@ class Authenticated extends Component {

_closeSession() {
fetch(SESSION_URI, {method:'DELETE', credentials:'include'})
.then(() => this.setState({user: ''}));
.then(() => {
this.setState({user: ''})
});
}

componentDidMount() {
Expand Down
213 changes: 213 additions & 0 deletions src/components/Duplication/Duplicator.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
import React, { Component } from 'react';
import { Modal, Button, Dropdown } from 'react-bootstrap';
import $ from 'jquery'
var hypertopic = require("hypertopic")

class Duplicator extends Component {

constructor(props) {
super(props);

this.state = {
showModal: false,
showModalConfirmation: false,
showToast: false,
corpora: [],
viewpoints: []
};
this.handleShow = this.handleShow.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleValidate = this.handleValidate.bind(this);
this.handleConfirm = this.handleConfirm.bind(this);
this.onChangeCheckBox = this.onChangeCheckBox.bind(this);
this.closeToast = this.closeToast.bind(this)
this.addUserToEntity = this.addUserToEntity.bind(this)
}

handleClose() {
this.setState({ showModal: false, showModalConfirmation: false });
}

handleShow() {
this.setState({ showModal: true });
}

handleValidate() {
if(this.state.viewpoints.length > 0 || this.state.corpora.length > 0) {
console.log(this.state.viewpoints)
console.log(this.state.corpora)
this.nameDuplicatedPortfolio = $('#portfolioDuplicatedName').val()
this.handleClose();
this.setState({ showModalConfirmation: true})
}
}

async handleConfirm() {
this.setState({ showModalConfirmation: false, showToast: true });

var ids = this.state.viewpoints.concat(this.state.corpora)
let that = this

await Promise.all(ids.map(id => that.addUserToEntity(id)))
//refresh page
this.setState({showToast: false });
window.location.replace("http://" + this.nameDuplicatedPortfolio + ".local:3000");

}

addUserToEntity(user){
let db = hypertopic([
"http://localhost",
"http://steatite.hypertopic.org"
]);

const _error = (x) => {
console.error(x.message)
return x
};

return db.get({_id:user})
.then( (x) => {
if(!x.users.includes(this.nameDuplicatedPortfolio))
x.users.push(this.nameDuplicatedPortfolio)
return x
})
.then(db.post)
.then((x) => {
console.log(x)
})
.catch(_error);
}

closeToast() {
this.setState(() => {
return {
showToast: false
};
});
}
onChangeCheckBox(e) {
$('.checkCorpora').each(function() {
if ($(this).is(":checked")) {
$('.Corpus').each(function() {
$(this).prop('checked', true);
$(this).prop('disabled', true);
});
}else{
$('.Corpus').each(function() {
$(this).prop('disabled', false);
});
}
});

$('.checkViewPoints').each(function() {
if ($(this).is(":checked")) {
$('.ViewPoint').each(function() {
$(this).prop('checked', true);
$(this).prop('disabled', true);
});
}else{
$('.ViewPoint').each(function() {
$(this).prop('disabled', false);
});
}
});

var selectedViewPoints = [];
$('.ViewPoint').each(function() {
if ($(this).is(":checked")) {
selectedViewPoints.push($(this).attr('value'));
}
});

var selectedCorpora = [];
$('.Corpus').each(function() {
if ($(this).is(":checked")) {
selectedCorpora.push($(this).attr('value'));
}
});

this.setState({
corpora: selectedCorpora,
viewpoints: selectedViewPoints
})
}

render() {
let name = this.props.userConnected + '-' + this.props.portfolio
let corpora = this.props.corpora.map((v, i) =>
<div className='Modal-Group' key={v.id}>
<input className='Modal-CheckBox Corpus' value={v.id} onChange={this.onChangeCheckBox} type="checkbox"/>
{v.id}
</div>
);

let viewpoints = this.props.viewpoints.map((v, i) =>
<div className='Modal-Group' key={v.id}>
<input className='Modal-CheckBox ViewPoint' value={v.id} onChange={this.onChangeCheckBox} type="checkbox"/>
{v.name}
</div>
);


return (
<div>
<Modal show={this.state.showToast}>
<Modal.Body>
<h3>Redirection à la nouvelle page...</h3>
</Modal.Body>
</Modal>

<Modal show={this.state.showModalConfirmation}>
<Modal.Body>
<h3>Créer le nouveau portfolio</h3>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.handleClose}>
Annuler
</Button>
<Button variant="primary" onClick={this.handleConfirm}>
Confirmer
</Button>
</Modal.Footer>
</Modal>

<Modal show={this.state.showModal}>
<Modal.Body>
<h3>Nom du portfolio</h3>
<input type='text' className='Modal-Input form-control' defaultValue={name} placeholder='Nom du nouveau portfolio' id="portfolioDuplicatedName"/>
<div className='Modal-Group Modal-Title'>
<h3>Corpus</h3>
<div className='Modal-Group'><input className='Modal-CheckBox checkCorpora' type="checkbox" onChange={this.onChangeCheckBox}/>Tout</div>
</div>
<hr/>
<div id="corporaList">
{corpora}
</div>
<br/>
<div className='Modal-Group Modal-Title'>
<h3>Points de vue</h3>
<div className='Modal-Group'><input className='Modal-CheckBox checkViewPoints' type="checkbox" onChange={this.onChangeCheckBox}/>Tout</div>
</div>
<hr/>
<div id="viewPointsList">
{viewpoints}
</div>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.handleClose}>
Annuler
</Button>
<Button variant="primary" onClick={this.handleValidate}>
Valider
</Button>
</Modal.Footer>
</Modal>
<Dropdown.Item eventKey="2" onClick={this.handleShow}>Dupliquer</Dropdown.Item>
</div>

)
}
}

export default Duplicator;
10 changes: 6 additions & 4 deletions src/components/Item/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ class Item extends Component {
<div className="App container-fluid">
<Header />
<div className="Status row h5">
<Authenticated/>
<Link to="/" className="badge badge-pill badge-light TopicTag">
<span className="badge badge-pill badge-dark oi oi-chevron-left"> </span> Retour à l'accueil
</Link>
<ul>
<li><Link to="/" className="badge badge-pill badge-light TopicTag">
<span className="badge badge-pill badge-dark oi oi-chevron-left"> </span> Retour à l'accueil
</Link></li>
<li><Authenticated/></li>
</ul>
</div>
<div className="container-fluid">
<div className="App-content row">
Expand Down
8 changes: 5 additions & 3 deletions src/components/Outliner/Outliner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class Outliner extends React.Component {
<div className="App container-fluid">
<Header />
<div className="Status row h5">
<Authenticated/>
<Link to="/" className="badge badge-pill badge-light TopicTag">
<ul>
<li><Link to="/" className="badge badge-pill badge-light TopicTag">
<span className="badge badge-pill badge-dark oi oi-chevron-left"> </span> Retour à l'accueil
</Link>
</Link></li>
<li><Authenticated/></li>
</ul>
</div>
<div className="container-fluid">
<div className="App-content row">
Expand Down
Loading

0 comments on commit 2b6c57b

Please sign in to comment.