Skip to content

Commit

Permalink
assets: backwards compatibility for Flask-Assets
Browse files Browse the repository at this point in the history
* assets: backwards compatibility for Flask-Assets
* docs: improvements
* Closes #90
  • Loading branch information
roksys authored and ntarocco committed May 23, 2019
1 parent b79ffd2 commit e06483c
Show file tree
Hide file tree
Showing 396 changed files with 30,120 additions and 201 deletions.
10 changes: 9 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
Installation
============

Invenio-Previewers is on PyPI so all you need is::
Invenio-Previewer is on PyPI so all you need is::

pip install invenio-previewer

Invenio-Previewer depends on Invenio-Assets for assets bundling and Invenio-PidStore and Invenio-Records-UI for record
integration.

You will normally use it in combination with files. You can install the extra Invenio modules Invenio-Files-REST
and Invenio-Records-Files by specifying the ``files`` key in extras::

pip install invenio-previewer[files]
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


This module includes the following external libraries:

- PDF.js: https://mozilla.github.io/pdf.js/ licensed under Apache. Included in:
/assets/css/pdfjs
/assets/js/pdfjs
/static/css/pdfjs
/static/js/pdfjs
29 changes: 12 additions & 17 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ include *.txt
include .dockerignore
include .editorconfig
include .tx/config
include LICENSE
include babel.ini
include docs/requirements.txt
include examples/requirements.txt
include LICENSE
include pytest.ini
recursive-include docs *.bat
recursive-include docs *.py
Expand All @@ -24,34 +24,29 @@ recursive-include docs Makefile
recursive-include examples *.csv
recursive-include examples *.html
recursive-include examples *.ipynb
recursive-include examples *.ipynb
recursive-include examples *.jpg
recursive-include examples *.jpg
recursive-include examples *.json
recursive-include examples *.json
recursive-include examples *.md
recursive-include examples *.pdf
recursive-include examples *.png
recursive-include examples *.png
recursive-include examples *.py
recursive-include examples *.sh
recursive-include examples *.sh
recursive-include examples *.xml
recursive-include examples *.xml
recursive-include examples *.zip
recursive-include invenio_previewer *.html *.js *.css
recursive-include invenio_previewer *.po *.pot *.mo
recursive-include invenio_previewer *.bcmap
recursive-include invenio_previewer *.cur
recursive-include invenio_previewer *.gif
recursive-include invenio_previewer *.html *.js *.css
recursive-include invenio_previewer *.ico
recursive-include invenio_previewer *.png
recursive-include invenio_previewer *.po *.pot *.mo
recursive-include invenio_previewer *.properties
recursive-include invenio_previewer *.scss
recursive-include invenio_previewer *.svg
recursive-include tests *.py

# added by check_manifest.py
recursive-include examples *.ipynb
recursive-include examples *.jpg
recursive-include examples *.json
recursive-include examples *.png
recursive-include examples *.sh
recursive-include examples *.xml


# added by check_manifest.py
recursive-include invenio_previewer *.bcmap
recursive-include invenio_previewer *.ico
recursive-include invenio_previewer *.scss
2 changes: 2 additions & 0 deletions examples/app-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ npm install
cd ..

flask collect -v
# AMD/RequireJS has been deprecated and will be removed in future versions
# flask assets build
flask webpack buildall

flask fixtures
Expand Down
3 changes: 2 additions & 1 deletion examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
invenio-access>=1.1.0
invenio-accounts>=1.1.0
invenio-accounts>=1.1.0
invenio-db>=1.0.3
File renamed without changes.
17 changes: 17 additions & 0 deletions invenio_previewer/assets/css/prismjs/simple.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* This file is part of Invenio.
* Copyright (C) 2016-2019 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

code[class*="language-"],
pre[class*="language-"] {
line-height: 1.0;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: white;
}
103 changes: 103 additions & 0 deletions invenio_previewer/assets/js/csv_previewer/csv_d3js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* This file is part of Invenio.
* Copyright (C) 2015-2019 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import d3 from "d3";
import flight from "flightjs";

function CSV_D3JS() {
var CSV_D3JS;

this.tabulate = function(data, target, columns) {
var table = d3
.select(target)
.append("table")
.classed({
table: true,
"table-hover": true,
"table-bordered": true,
});
CSV_D3JS.thead = table.append("thead");
CSV_D3JS.tbody = table.append("tbody");
CSV_D3JS.columns = columns;
CSV_D3JS.data = data;

// append the header row
CSV_D3JS.thead
.append("tr")
.selectAll("th")
.data(CSV_D3JS.columns)
.enter()
.append("th")
.text(function(column) {
return column;
});

CSV_D3JS.next = 1;
CSV_D3JS.chunk_size = 500;
CSV_D3JS.chunks = Math.ceil(CSV_D3JS.data.length / CSV_D3JS.chunk_size);

CSV_D3JS.loadNext(undefined, {
id: CSV_D3JS.id,
});
if (CSV_D3JS.chunks > 1) {
CSV_D3JS.trigger(document, "showLoader", {
id: CSV_D3JS.id,
});
}

return true;
};

this.loadNext = function(ev, data) {
if (data.id === CSV_D3JS.id && CSV_D3JS.next <= CSV_D3JS.chunks) {
// create a row for each object in the data chunk
CSV_D3JS.tbody
.selectAll("tr")
.data(CSV_D3JS.data.slice(0, CSV_D3JS.next * CSV_D3JS.chunk_size))
.enter()
.append("tr")
.selectAll("td")
.data(function(row) {
return CSV_D3JS.columns.map(function(column) {
return { column: column, value: row[column] };
});
})
.enter()
.append("td")
.text(function(d) {
return d.value;
});

if (CSV_D3JS.next === CSV_D3JS.chunks) {
CSV_D3JS.trigger(document, "hideLoader", {
id: CSV_D3JS.id,
});
}
CSV_D3JS.next += 1;
}
};

this.after("initialize", function() {
CSV_D3JS = this;
CSV_D3JS.id = CSV_D3JS.node.id;

var delimiter = CSV_D3JS.$node.data("csv-delimiter"),
encoding = CSV_D3JS.$node.data("csv-encoding"),
resource = CSV_D3JS.$node.data("csv-source"),
dsv = d3.dsv(delimiter, "text/csv; charset=" + encoding);

dsv(resource, function(data) {
var col = Object.keys(data[0]);
CSV_D3JS.tabulate(data, CSV_D3JS.node, col);
});

this.on(document, "loadNext", this.loadNext);
});
}

export default flight.component(CSV_D3JS);
20 changes: 20 additions & 0 deletions invenio_previewer/assets/js/csv_previewer/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of Invenio.
* Copyright (C) 2015-2019 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import $ from 'jquery';
import CSV_D3JS from './csv_d3js';
import Loader from './loader.js';

$(function () {
$("[data-csv-source]").each(function () {
CSV_D3JS.attachTo($(this));
})
$("[data-csv-target]").each(function () {
Loader.attachTo($(this));
})
})
43 changes: 43 additions & 0 deletions invenio_previewer/assets/js/csv_previewer/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of Invenio.
* Copyright (C) 2015-2019 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import flight from "flightjs";

function Loader() {
var Loader;

this.handleShowLoader = function(ev, data) {
if (data.id === Loader.id) {
this.$node.show();
}
};

this.handleHideLoader = function(ev, data) {
if (data.id === Loader.id) {
this.$node.hide();
}
};

this.after("initialize", function() {
Loader = this;
Loader.id = Loader.$node.data("csv-target");

Loader.on(document, "showLoader", Loader.handleShowLoader);
Loader.on(document, "hideLoader", Loader.handleHideLoader);
Loader.on("click", function(ev) {
ev.preventDefault();
Loader.trigger(document, "loadNext", {
id: Loader.id,
});
});

Loader.$node.hide();
});
}

export default flight.component(Loader);
File renamed without changes.
File renamed without changes.

0 comments on commit e06483c

Please sign in to comment.