Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPMification & Reactification #139

Merged
merged 25 commits into from
Feb 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f40c024
Add npm package.json and setup webpack to transpile ES6/JSX and compi…
williaster Feb 19, 2016
0eb3dcd
Update readme.md
Feb 19, 2016
af34549
partial refactor of explore page, visualizations not managed with web…
williaster Feb 19, 2016
79e6fc9
huge npm refactor of all visualizations. table views are broken due t…
williaster Feb 24, 2016
f5e0ed7
A simple base template for npm
mistercrunch Feb 23, 2016
d582efe
Fixing 2 links
mistercrunch Feb 24, 2016
dbb9f66
Merge pull request #141 from mistercrunch/npm
mistercrunch Feb 24, 2016
9552d09
A few cosmetic fixes (nvd3 tooltips, buttons, tables)
mistercrunch Feb 24, 2016
df8ea52
Adjustments based on comment
mistercrunch Feb 24, 2016
71073d8
Merge pull request #142 from mistercrunch/npm
mistercrunch Feb 24, 2016
3e83460
Remove base.entry.js, declare all JS dependencies in explore using np…
williaster Feb 24, 2016
171301b
Moving files around
mistercrunch Feb 24, 2016
e70542d
NPMify sql.html
mistercrunch Feb 25, 2016
71b1111
Merge pull request #145 from mistercrunch/npm
williaster Feb 25, 2016
8dcd5e0
Tackling Featured Datasets
mistercrunch Feb 25, 2016
d8409c1
Fixing table and pivot_table
mistercrunch Feb 26, 2016
e4e7b91
Fixing dashboard.html
mistercrunch Feb 26, 2016
70e1aa3
Adding missing fonts
mistercrunch Feb 26, 2016
fd0e680
Cleaning up assets/vendors
mistercrunch Feb 27, 2016
c929b2a
npmify datamaps dependency
mistercrunch Feb 27, 2016
4f4c67c
Moving html assets back to flask template folder
mistercrunch Feb 27, 2016
c304cc4
Moving content of assets/readme.md to contributing.md
mistercrunch Feb 27, 2016
58c7b8c
Removing js_files and css_files entries from viz.py
mistercrunch Feb 27, 2016
bc41820
Rolling back to previous theme until we polish bootswarch.paper
mistercrunch Feb 28, 2016
d40664b
Merge pull request #147 from mistercrunch/npm
mistercrunch Feb 28, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ dist
panoramix.egg-info/
app.db
*.bak

# Node.js, webpack artifacts
*.entry.js
*.js.map
node_modules
npm-debug.log
62 changes: 56 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ open to whoever wants to implement it.
Look through the GitHub issues for features. Anything tagged with
"feature" is open to whoever wants to implement it.

We've created the operators, hooks, macros and executors we needed, but we
made sure that this part of Panoramix is extensible. New operators,
hooks and operators are very welcomed!

### Documentation

Panoramix could always use better documentation,
Expand All @@ -55,7 +51,7 @@ If you are proposing a feature:

[API Documentation](http://pythonhosted.com/panoramix)

## Setting up a development environment
## Setting up a Python development environment

# fork the repo on github and then clone it
# alternatively you may want to clone the main repo but that won't work
Expand Down Expand Up @@ -84,7 +80,61 @@ If you are proposing a feature:
# start a dev web server
panoramix runserver -d

For every development session you may have to

## Setting up the node / npm javascript environment

`panoramix/assets` contains all npm-managed, front end assets.
Flask-Appbuilder itself comes bundled with jQuery and bootstrap.
While these may be phased out over time, these packages are currently not
managed with npm.


### Using npm to generate bundled files

#### npm
First, npm must be available in your environment. If it is not you can run the following commands
(taken from [this source](https://gist.github.com/DanHerbert/9520689))
```
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
```

The final step is to add
`~/.node/bin` to your `PATH` so commands you install globally are usable.
Add something like this to your `.bashrc` file.
```
export PATH="$HOME/.node/bin:$PATH"
```

#### npm packages
To install third party libraries defined in `package.json`, run the
following within this directory which will install them in a
new `node_modules/` folder within `assets/`.

```
npm install
```

To parse and generate bundled files for panoramix, run either of the
following commands. The `dev` flag will keep the npm script running and
re-run it upon any changes within the assets directory.

```
# Compiles the production / optimized js & css
npm run prod

# Start a web server that manages and updates your assets as you modify them
npm run dev
```

For every development session you will have to start a flask dev server
as well as an npm watcher

```
panoramix runserver -d -p 8081
npm run dev
```

## Testing

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ getting the foundation for free
* The Flask ecosystem - Simply amazing. So much Plug, easy play.
* NVD3 - One of the best charting library out there
* Much more, check out the requirements.txt file!


Contributing
------------

Interested in contributing? Casual hacking? Check out the `CONTRIBUTING.md`
file in the repository to get started!
10 changes: 7 additions & 3 deletions panoramix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os
from flask import Flask
from flask import Flask, redirect
from flask.ext.appbuilder import SQLA, AppBuilder, IndexView
from flask.ext.appbuilder.baseviews import expose
from flask.ext.migrate import Migrate
from panoramix import config

Expand All @@ -20,10 +21,13 @@


class MyIndexView(IndexView):
index_template = 'index.html'
@expose('/')
def index(self):
return redirect('/panoramix/featured')

appbuilder = AppBuilder(
app, db.session, base_template='panoramix/base.html',
app, db.session,
base_template='panoramix/base.html',
indexview=MyIndexView,
security_manager_class=app.config.get("CUSTOM_SECURITY_MANAGER"))

Expand Down
3 changes: 3 additions & 0 deletions panoramix/assets/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets" : ["es2015", "react"]
}
Binary file added panoramix/assets/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 155 additions & 0 deletions panoramix/assets/javascripts/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var px = require('./modules/panoramix.js');
var d3 = require('d3');
require('bootstrap');

var ace = require('brace');
require('brace/mode/css');
require('brace/theme/crimson_editor');

require('select2');
require('../node_modules/gridster/dist/jquery.gridster.min.js');
require('../node_modules/gridster/dist/jquery.gridster.min.js');

var dashboard;

var Dashboard = function(id){
var dash = {
slices: [],
filters: {},
id: id,
addFilter: function(slice_id, filters) {
this.filters[slice_id] = filters;
this.refreshExcept(slice_id);
},
readFilters: function() {
// Returns a list of human readable active filters
return JSON.stringify(this.filters, null, 4);
},
refreshExcept: function(slice_id) {
this.slices.forEach(function(slice){
if(slice.data.slice_id != slice_id){
slice.render();
}
});
},
clearFilter: function(slice_id) {
delete this.filters[slice_id];
this.refreshExcept(slice_id);
},
getSlice: function(slice_id) {
for(var i=0; i<this.slices.length; i++){
if (this.slices[i].data.slice_id == slice_id)
return this.slices[i];
}
}
}
$('.dashboard li.widget').each(function() {
var data = $(this).data('slice');
var slice = px.Slice(data, dash);
$(this).find('a.refresh').click(function(){
slice.render();
});
dash.slices.push(slice);
slice.render();
});
dashboard = dash;
return dash;
}

function initDashboardView() {
var gridster = $(".gridster ul").gridster({
widget_margins: [5, 5],
widget_base_dimensions: [100, 100],
draggable: {
handle: '.drag',
},
resize: {
enabled: true,
stop: function(e, ui, element) {
var slice_data = $(element).data('slice');
dashboard.getSlice(slice_data.slice_id).resize();
}
},
serialize_params: function(_w, wgd) {
return {
slice_id: $(_w).attr('slice_id'),
col: wgd.col,
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y
};
},
}).data('gridster');
$("div.gridster").css('visibility', 'visible');
$("#savedash").click(function() {
var expanded_slices = {};
$.each($(".slice_info"), function(i, d){
var widget = $(this).parents('.widget');
var slice_description = widget.find('.slice_description');
if(slice_description.is(":visible"))
expanded_slices[$(d).attr('slice_id')] = true;
});
var data = {
positions: gridster.serialize(),
css: editor.getValue(),
expanded_slices: expanded_slices,
};
$.ajax({
type: "POST",
url: '/panoramix/save_dash/' + dashboard.id + '/',
data: {'data': JSON.stringify(data)},
success: function() {alert("Saved!")},
error: function() {alert("Error :(")},
});
});

var editor = ace.edit("dash_css");
editor.$blockScrolling = Infinity

editor.setTheme("ace/theme/crimson_editor");
editor.setOptions({
minLines: 16,
maxLines: Infinity,
});
editor.getSession().setMode("ace/mode/css");

$(".select2").select2({dropdownAutoWidth : true});
$("#css_template").on("change", function() {
var css = $(this).find('option:selected').data('css');
editor.setValue(css);
$('#dash_css').val(css);
$("#user_style").html(css);
});
$('#filters').click( function(){
alert(dashboard.readFilters());
});
$("a.closeslice").click(function() {
var li = $(this).parents("li");
gridster.remove_widget(li);
});
$(".slice_info").click(function(){
var widget = $(this).parents('.widget');
var slice_description = widget.find('.slice_description');
slice_description.slideToggle(500, function(){
widget.find('.refresh').click();
});
});
$("table.slice_header").mouseover(function() {
$(this).find("td.icons nobr").show();
});
$("table.slice_header").mouseout(function() {
$(this).find("td.icons nobr").hide();
});
editor.on("change", function(){
var css = editor.getValue();
$('#dash_css').val(css);
$("#user_style").html(css);
});
}

$(document).ready(function() {
initDashboardView();
var dashboard = Dashboard($('#dashboard_id').val());
});
Loading