BIDS-collaborative / brainspell

brainspell is a web platform to facilitate the creation of an open, human-curated, classification of the neuroimaging literature
https://gitter.im/BIDS-collaborative/brainspell
2 stars 6 forks source link

Create csv/json/others file that record the articles #12

Open EmilyVam opened 8 years ago

EmilyVam commented 8 years ago

Create a downloadable file (csv/json/other formats) at the bottom of the searching result page that store articles' info with given searching query. More discussion at #11

EmilyVam commented 8 years ago

I made some changes to the code (mainly brainspell.php) -> print out all the article titles at the beginning of the search result page (it is very messy, sorry!) with any query. Then I was trying to save the article titles into a CSV file, but it gives me a warning message (below), I pushed all the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark @jbpoline @r03ert0

jbpoline commented 8 years ago

Have you check the permissions ? if you are writting as root, do you have permission to write where you are trying to save the csv ?

May be Roberto will be able to help tomorrow ?

cheers JB

On Tue, Oct 27, 2015 at 7:49 PM, Emily Zhang notifications@github.com wrote:

I made some changes to the code (mainly brainspell.php) -> print out all the article titles at the beginning of the search result page (it is very messy, sorry!) with any query. Then I was trying to save the article titles into a CSV file, but it gives me a warning message (below), I pushed all the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark https://github.com/davclark @jbpoline https://github.com/jbpoline @r03ert0 https://github.com/r03ert0

— Reply to this email directly or view it on GitHub https://github.com/BIDS-collaborative/brainspell/issues/12#issuecomment-151706169 .

EmilyVam commented 8 years ago

I modified the brainspell.php file in the php folder, and I saved the csv file in the same folder. Maybe we can talk about it tomorrow.

Thanks, Emily

On Tue, Oct 27, 2015 at 7:57 PM, Jean-Baptiste Poline < notifications@github.com> wrote:

Have you check the permissions ? if you are writting as root, do you have permission to write where you are trying to save the csv ?

May be Roberto will be able to help tomorrow ?

cheers JB

On Tue, Oct 27, 2015 at 7:49 PM, Emily Zhang notifications@github.com wrote:

I made some changes to the code (mainly brainspell.php) -> print out all the article titles at the beginning of the search result page (it is very messy, sorry!) with any query. Then I was trying to save the article titles into a CSV file, but it gives me a warning message (below), I pushed all the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark https://github.com/davclark @jbpoline https://github.com/jbpoline @r03ert0 https://github.com/r03ert0

— Reply to this email directly or view it on GitHub < https://github.com/BIDS-collaborative/brainspell/issues/12#issuecomment-151706169

.

— Reply to this email directly or view it on GitHub https://github.com/BIDS-collaborative/brainspell/issues/12#issuecomment-151706957 .

Emily Zhang B.A. of Statistics and Economics University of California, Berkeley

r03ert0 commented 8 years ago

Ideally, you should do that in the client, not in the server. When you launch a search there's already an array that is sent with all the titles. The code is in brainspell-search.js. You should just add a button to the title of the query result (when brainspell tells how many papers responded to the query), and add a function to that button to download the csv file when clicked. Brainspell uses jQuery, and is very easy to append click functions to anything. If you have a button defined like

you append a function in the code like $("#download_csv").click(function() { /* my download csv function here */ });

For the download function, have a look at this function I use to save SVG paths in another app:

function savePaths() { var filename=prompt("File name",filename); var tmpRegions=JSON.parse(JSON.stringify(Regions)); for(var i=0;i<Regions.length;i++) tmpRegions[i].path=Regions[i].path.exportJSON(); var json = JSON.stringify(tmpRegions); var jsonData = 'data:text/json;charset=utf-8,'+encodeURIComponent(json); var a = document.createElement('a'); a.href = jsonData; a.download = filename+'.json'; document.body.appendChild(a); a.click(); }

cheers, roberto

On Wed, Oct 28, 2015 at 3:50 AM, Emily Zhang notifications@github.com wrote:

I made some changes to the code (mainly brainspell.php) -> print out all the article titles at the beginning of the search result page (it is very messy, sorry!) with any query. Then I was trying to save the article titles into a CSV file, but it gives me a warning message (below), I pushed all the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark https://github.com/davclark @jbpoline https://github.com/jbpoline @r03ert0 https://github.com/r03ert0

— Reply to this email directly or view it on GitHub https://github.com/BIDS-collaborative/brainspell/issues/12#issuecomment-151706169 .

EmilyVam commented 8 years ago

Meeting Updates & Next Steps:

davclark commented 8 years ago

@EmilyVam has implemented some sample downloader button (where?) and @anokhikastia has wired something up to the actual app (again, where?)!

EmilyVam commented 8 years ago

I have pushed all my changes on Emily branch. But here is the code I added in the base.html:

$('#give-me-something').click(function () {
    var filename="Test";
    var csvfile=["Articles", "\narticle1", "\narticle2", "\narticle3"]
    var csvData = 'data:text/json;charset=utf-8,'+ encodeURIComponent(csvfile);
    var a = document.createElement('a');
    a.href = csvData;
    a.download = filename+'.csv';
    document.body.appendChild(a);
    a.click();
});

@anokhikastia You can just copy this for the button you created on the brainspell.dev.

EmilyVam commented 8 years ago

Help! @davclark @jbpoline @r03ert0

Can anyone enlighten me how to pass a php variable to js file? It is kind of frustrated after I tried multiple ways (I learned from Google), but none of them worked.

Two of the methods I tried are:

var data = <?php echo $articles; ?>;
var data = <?php echo json_encode($articles); ?>; 

When I printed out the $articles variable in PHP, it listed all the article names I need, but when I print out the data variable in JS using document.print(data), it doesn't print out anything.

r03ert0 commented 8 years ago

Hi Emily,

brainspell.php passes data to the javascript code through the html page it generates. More in detail: when a user searches a query term, lets say 'vision', this gets transformed into a query for the following web page:

http://brainspell.org/search?query=vision

this web page does not exist before hand -- it is generated by the server (the php code). To generate the search result page, brainspell.php uses Lucene to query the DB that indexes all the papers. The result of this query is an array, similar to $articles in your example. However, instead of adding all the article data to the web page, brainspell.php generates a formated html list of papers, which is the list of papers you can see when you do a search (the 132 papers that correspond to 'vision'). This is the way in which brainspell.php is already passing the list of articles to the client. I don't think it's necessary to do it again.

what you can do now in the client is to recover the article data from the html page using jquery. All the papers in the list have the class "paper-stuff'. Inside the 'paper-stuff' div, the href attribute of the link elements contains the PMID of the papers, that we want to save to the CSV file. The text of the link contains the paper title, authors, journal, etc, that we may also want to save to the CSV file. You can get a javascript array with all the papers by typing:

$(".paper-stuff")

(this works even from the web browser console! give it a try!)

The jquery function each() may come handy for iterate through the results, you can use find() to find the elements that you need, attr() to get the value of specific attributes (such as href), and text() to get the text content of an element.

Hope this helps,

roberto

On Thu, Nov 12, 2015 at 2:38 AM, Emily Zhang notifications@github.com wrote:

Help! @davclark https://github.com/davclark @jbpoline https://github.com/jbpoline @r03ert0 https://github.com/r03ert0

Can anyone enlighten me how to pass a php variable to js file? It is kind of frustrated after I tried multiple ways (I learned from Google), but none of them worked.

Two of the methods I tried are:

var data = <?php echo $articles; ?>; var data = <?php echo json_encode($articles); ?>;

When I printed out the $articles variable in PHP, it listed all the article names I need, but when I print out the data variable in JS using document.print(data), it doesn't print out anything.

— Reply to this email directly or view it on GitHub https://github.com/BIDS-collaborative/brainspell/issues/12#issuecomment-155969692 .

EmilyVam commented 8 years ago

Updates:

Last week:

This week:

Next step: