Commit f1e01a8e authored by Romain Loth's avatar Romain Loth

cleanup crowdsourcingModule, fix one path there, and clarify overall doc for PHP setup

parent fd59aa7a
## Serving ProjectExplorer's PHP elements with nginx
Because ProjectExplorer is mostly static files + javascript, you actually **don't** need a webserver for most of the functionalities.
However, some elements rely on a PHP server and won't work without it:
- the topPapers backend under `twbackends/phpAPI` that can be used for relatedDocs queries in CSV or CortextDB databases
- the crowdsourcingModule under `twmodules/crowdsourcingModule` that can be used to save user suggestions
If you need to configure that kind of a server, we provide two examples, supposing:
- you cloned the ProjectExplorer distribution in /absolute/path/to/ProjectExplorer
- you installed php fpm (`sudo apt install php7.0-fpm`)
#### Exemple 1
In case of an nginx normal "`location`" configuration, something like this is the working minimal conf at time of writing:
```
server {
listen 80 default_server;
listen [::]:80 default_server;
# ---------------------------------
root /absolute/path/to/ProjectExplorer;
# ---------------------------------
server_name _;
location / {
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on php7.0-fpm.sock
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
```
#### Exemple 2
And in case of an nginx "`alias`" configuration, the path must be reconstructed by matching the entire path in a regexp without the alias part to get the correct relative path to the script. Something like this works:
```
server {
listen 80;
listen [::]:80 default_server;
root /somewhere_else_like_a_previous_website ;
location /myalias {
# ---------------------------------
alias /absolute/path/to/ProjectExplorer ;
# ---------------------------------
# (we use a regexp to capture the appropriate path into $1)
location ~ ^/myalias/(.+\.php)$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT/$1;
}
}
}
```
Refer to the [NGINX official documentation about PHP](https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/) for more information.
#### Path coherence
For API queries, the route prefix is set in ProjectExplorer's settings found under the entry `TWConf.relatedDocsAPIS`. **The rule to follow is to make sure that `$DOCUMENT_ROOT + '/' + TWConf.relatedDocsAPIS[yourdbtype]` forms a valid route to the PHP files in your project dirs.**
......@@ -7,7 +7,7 @@ TW.conf = (function(TW){
let TWConf = {}
TWConf.branding = 'ProjectExplorer' // <--- name displayed in upper left
TWConf.brandingLink = 'https://github.com/moma/ProjectExplorer' // <--- link to "home"
TWConf.brandingLink = 'http://iscpif.fr' // <--- link to "home"
// ==========================
......@@ -209,7 +209,9 @@ TW.conf = (function(TW){
TWConf.ModulesFlags["histogramModule"] = true ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TWConf.ModulesFlags["crowdsourcingModule"] = false ;
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = true ;
// Other GUI options
// ------------------
......
......@@ -12,37 +12,32 @@ Main use case is support for one-doc-by-row CSV files.
You need any kind of php server support with php > 5.0.
For instance on an ubuntu 16 with an nginx server, I'd install php 7 fpm:
```
sudo apt install php7.0-fpm
```
For instance on an ubuntu 16 with an nginx server, I would:
- install php 7 fpm:
```
sudo apt install php7.0-fpm
```
And then add this kind of configuration entry in `nginx.conf`:
```
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
- follow **[nginx_suggestions.md](https://github.com/moma/ProjectExplorer/blob/master/00.DOCUMENTATION/C-advanced/nginx_suggestions.md)** to correctly configure the web server routes relative to my filesystem paths and `settings_explorerjs` configuration.
fastcgi_param SCRIPT_FILENAME
/your/path/to/twbackends/phpAPI/$fastcgi_script_name;
# --------------------------------
}
```
###### CSV
It's enough to run any kind of gargantext-style gexf + CSV sets.
The prerequisites above are enough to run any kind of [gargantext](http://gargantext.org)-style {gexf + CSV} sets.
Optionally, especially in production, you should add memcached support for faster CSV search (it allows caching the CSV postings base).
```
sudo apt install php-memcached
sudo service php7.0-fpm restart
```
###### Cortext
For legacy cortext-style databases, you'll also need sqlite:
```
sudo apt install sqlite3 php7.0-sqlite3
```
#### Optional cache-ing
Optionally, especially in production, you should add memcached support for faster CSV search (it allows caching the CSV postings base).
```
sudo apt install php-memcached
sudo service php7.0-fpm restart
```
#### Usage
......@@ -51,9 +46,13 @@ sudo apt install sqlite3 php7.0-sqlite3
To use the API for the "topPapers" embedded search in ProjectExplorer, the corresponding settings should be picked either:
- via the interface (side panel menu)
- or directly in settings_explorerjs.js:
```
TWConf.relatedDocsType = "LocalDB" (CSV or CortextDB)
```
```
TWConf.relatedDocsType = "csv"
or
TWConf.relatedDocsType = "CortextDB"
```
Finally, to match the correct DB with the correct graph file:
- both should reside in `data/yoursubdir`
......
## Crowdsourcing Module
A module to allow saving user-suggestions from the search box in the map.
------------------------------------------------------
#### Initial Config
The user inputs (term/topic suggestions) are saved in an sqlite3 db in dir db/, under table terms.
For a new installation one should create the db with the following commands:
- For a new installation one should create the db with the following commands:
```
> cd db
> sqlite3 crowdsourcing.db
sqlite> CREATE TABLE terms (source CHAR(250),suggestion CHAR(250),time CHAR(30)) ;
sqlite> .exit
> chmod -v 775 crowdsourcing.db
```
- data saving is done by an XHR POST to a PHP script under `db/s.php` so you need a working php engine associated to your web server
For instance on an ubuntu 16 with an nginx server, I'd install php 7 fpm:
```
sudo apt install php7.0-fpm
```
And then add this kind of configuration entry in `nginx.conf`:
```
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME
/your/path/to/ProjectExplorer/$fastcgi_script_name;
# ------------------------------
}
```
For more information about the nginx configuration, you can find information in [nginx_suggestions.md](https://github.com/moma/ProjectExplorer/blob/master/00.DOCUMENTATION/C-advanced/nginx_suggestions.md).
------------------------------------------------------
#### Retrieving the suggestions
To export the table to csv, you can use this command.
```
> cd db
> sqlite3 crowdsourcing.db
sqlite> CREATE TABLE terms (source CHAR(250),suggestion CHAR(250),time CHAR(30)) ;
sqlite> .exit
> chmod -v 775 crowdsourcing.db
cd twmodules/crowdsourcingModule/db
echo 'SELECT * FROM terms;' | sqlite3 -header -csv crowdsourcing.db
```
......@@ -71,15 +71,12 @@ function save_suggestions(term) {
// console.log( "SAVE INFO:" + info )
$.ajax({
type: "POST",
url: "crowdsourcingModule/db/s.php",
// cache:false,
// contentType: "application/json",
url: "twmodules/crowdsourcingModule/db/s.php",
data: info,
dataType: "json",
success : function(data, textStatus, jqXHR) {
console.log( "SUCCESS" )
console.log( data )
//$("#sendcrowds").html(D["#sendcrowds"]["thanks"][LA]) //showing message
var p = $('<p>');
var i = $('<i>');
i.text('"'+term+'"');
......
alpha
beta
gamma
delta
epsilon
zeta
eta
theta
iota
kappa
lambda
mu
nu
xi
omicron
pi
rho
sigma
tau
upsilon
phi
khi
psi
omega
......@@ -206,6 +206,8 @@ TW.conf = (function(TW){
TWConf.ModulesFlags["histogramModule"] = false ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = false ;
// Other GUI options
......
......@@ -7,7 +7,7 @@ TW.conf = (function(TW){
let TWConf = {}
TWConf.branding = 'ProjectExplorer' // <--- name displayed in upper left
TWConf.brandingLink = 'https://github.com/moma/ProjectExplorer' // <--- link to "home"
TWConf.brandingLink = 'http://iscpif.fr' // <--- link to "home"
// ==========================
......@@ -209,7 +209,9 @@ TW.conf = (function(TW){
TWConf.ModulesFlags["histogramModule"] = true ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TWConf.ModulesFlags["crowdsourcingModule"] = false ;
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = true ;
// Other GUI options
// ------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment