-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mircea Danila Dumitrescu
committed
May 16, 2014
1 parent
bd7d324
commit c22a5d3
Showing
35 changed files
with
2,103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"directory": "public/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
node_modules | ||
*.iml | ||
.idea | ||
.jshintrc | ||
Procfile | ||
.idea/ | ||
atlassian-ide-plugin.xml | ||
bower_components | ||
lib | ||
node_modules | ||
tmp | ||
public/lib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
shopcade_analytics | ||
================== | ||
|
||
Shopcade analytics workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var express = require('express'), | ||
util = require('util'), | ||
path = require('path'), | ||
http = require('http'), | ||
fs = require('fs'), | ||
app = express(), | ||
port = 3001; | ||
|
||
app.use("/", express.static('public')); | ||
// env | ||
|
||
app.set('port', process.env.port || port); | ||
app.set('views', path.join(__dirname, '/public/views')); | ||
app.set('view engine', 'jade'); | ||
//app.use(express.bodyParser()); | ||
app.disable('x-powered-by'); | ||
|
||
/** | ||
* route | ||
*/ | ||
app.get('/', function (req, res) { | ||
res.render('overview', {title: 'overview'}); | ||
}); | ||
|
||
app.get('/:page', function (req, res) { | ||
var page = req.params.page; | ||
res.render(page, {title: page}); | ||
}); | ||
|
||
/** | ||
* read fs | ||
*/ | ||
fs.readdirSync('public').forEach(function (file) { // iterate through every sub-folder | ||
if (!file.match(/(\.ico$|views)/)) { | ||
app.use(express.static('public/' + file)); | ||
} | ||
}); | ||
|
||
(function () { | ||
http.createServer(app).listen(app.get('port'), function (req, res) { | ||
util.log('View server listening on port ' + port); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "analytics", | ||
"version": "0.0.1", | ||
"ignore": [ | ||
".jshintrc", | ||
"**/*.txt", | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": { | ||
"jquery": "2.1.0", | ||
"bootstrap": "3.1.1", | ||
"d3": "3.3.*", | ||
"crossfilter": "1.2.0", | ||
"nvd3": "1.1.*", | ||
"dcjs": "1.6.0" | ||
}, | ||
"directory": "public/lib", | ||
"authors": [ | ||
"yeqing <[email protected]>" | ||
], | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
var FilterModel = Backbone.Model.extend({ | ||
initialize: function () { | ||
console.log('model is created'); | ||
}, | ||
defaults: { | ||
name: 'Filter', | ||
/** | ||
* {<field>: {<operator>: <value>}} | ||
*/ | ||
condition: null, | ||
change: function () { | ||
var _condition = {}; | ||
_condition[this.get('field')] = {}; | ||
_condition[this.get('field')][this.get('operator')] = this.get('value'); | ||
this.set('condition', _condition); | ||
}, | ||
render: function () { | ||
return this.get('condition'); | ||
}, | ||
reset: function () { | ||
this.set('condition', null); | ||
} | ||
} | ||
}); | ||
|
||
var FilterView = Backbone.View.extend({ | ||
tagName: 'li', | ||
|
||
events: { | ||
'click button.remove': 'remove', | ||
'change input,select': 'change' | ||
}, | ||
|
||
initialize: function () { | ||
_.bindAll(this, 'render', 'unrender', 'remove', 'reset', 'change'); | ||
this.model.bind('change', this.change); | ||
this.model.bind('remove', this.unrender); | ||
this.model.bind('reset', this.reset); | ||
|
||
this._create_condition_html = function () { | ||
var _columns = []; | ||
columns.forEach(function (d) { | ||
if (!d.match('dim')) { | ||
_columns.push(d); | ||
} | ||
}); | ||
var $li = $('<li class="filter-segment-condition">'); | ||
$li | ||
.append(createSelOpts( | ||
createElem('select', {className: 'field', placeholder: 'field name'}), | ||
_columns | ||
)) | ||
.append(createSelOpts( | ||
createElem('select', {className: 'operator'}), | ||
[ | ||
'equal to (=)', | ||
'not equal to (!=)', | ||
'greater than or equal to (>=)', | ||
'greater than (>)', | ||
'smaller than or equal to (<=)', | ||
'smaller than (<)', | ||
'between (e.g. 0-10)', | ||
'contains (regex)' | ||
], | ||
{ | ||
'equal to (=)': null, | ||
'not equal to (!=)': '$ne', | ||
'greater than or equal to (>=)': '$gte', | ||
'greater than (>)': '$gt', | ||
'smaller than or equal to (<=)': '$lte', | ||
'smaller than (<)': '$lt', | ||
'between (e.g. 0-10)': 'btwn', | ||
'contains (regex)': '$regex' | ||
} | ||
)) | ||
.append(createElem('input', {className: 'value', placeholder: 'value'})) | ||
.append(createElem('button', {className: 'reset'}, 'reset')) | ||
.append(createElem('button', {className: 'remove'}, 'remove')) | ||
// .append(createElem('div', {className: 'text hidden'})) //debug | ||
return $li.html(); | ||
}; | ||
}, | ||
|
||
render: function () { | ||
$(this.el).append(this._create_condition_html()); | ||
return this; | ||
}, | ||
|
||
unrender: function () { | ||
$(this.el).remove(); | ||
}, | ||
|
||
remove: function () { | ||
this.model.destroy(); | ||
}, | ||
|
||
reset: function () { | ||
$('input', this.el).val(''); | ||
this.model.set('condition', {}); | ||
}, | ||
|
||
/** | ||
* {<field>: {<operator>: <value>}} | ||
*/ | ||
change: function () { | ||
var field = $('.field', this.el).val(), | ||
operator = $('.operator', this.el).val(), | ||
value = $('.value', this.el).val(); | ||
value = !isNaN(Number(value)) ? Number(value) : value; | ||
var _condition = {}; | ||
_condition[field] = {}; | ||
if (String(operator) == 'null') { // equal to | ||
_condition[field] = value; | ||
} else if (operator == 'btwn') { // between | ||
if (value) { | ||
value = value.split('-'); | ||
if (value.length > 1) { | ||
value.forEach(function (d, i) { | ||
value[i] = !isNaN(Number(value[i].split(' ').join(''))) ? Number(value[i].split(' ').join('')) : value[i]; | ||
}); | ||
_condition[field]['$gte'] = value[0]; | ||
_condition[field]['$lte'] = value[1]; | ||
} | ||
} | ||
} else if (String(operator) != 'null') { | ||
_condition[field][operator] = value; | ||
} else { | ||
//TODO | ||
} | ||
this.model.set('condition', _condition); | ||
// $('div.text', this.el).text(JSON.stringify(this.model.get('condition'))); //debug | ||
} | ||
}); | ||
|
||
var FiltersCollection = Backbone.Collection.extend({ | ||
model: FilterModel | ||
}); | ||
|
||
var FiltersCollectionView = Backbone.View.extend({ | ||
el: '', | ||
|
||
events: { | ||
'click button#add': 'addItem' | ||
}, | ||
|
||
initialize: function () { | ||
_.bindAll(this, 'render', 'addItem', 'appendItem', 'change'); | ||
this.counter = 0; | ||
this.conditions = {}; | ||
this.getConditions = function () { | ||
if (_size(this.conditions)) { | ||
return this.conditions | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
this.collection = new FiltersCollection(); | ||
this.collection.bind('add', this.appendItem); | ||
this.collection.bind('change', this.change); | ||
this.collection.bind('remove', this.change); | ||
|
||
this.render(); | ||
}, | ||
|
||
render: function () { | ||
var _this = this; | ||
var $div = $('<div/>') | ||
.append(createElem('button', {id: 'add'}, 'Add Condition')) | ||
.append(createElem('div', {className: 'text hidden'})) //debug | ||
var $ul = $('<ul class="filter-segment">'); | ||
$(this.el).html($div.append($ul).html()); | ||
_(this.collection.models).each(function (item) { // in case collection is not empty | ||
_this.appendItem(item); | ||
}, this); | ||
}, | ||
|
||
addItem: function () { | ||
this.counter++; | ||
var item = new FilterModel(); | ||
this.collection.add(item); | ||
}, | ||
|
||
appendItem: function (item) { | ||
var itemView = new FilterView({ | ||
model: item | ||
}); | ||
$('ul', this.el).append(itemView.render().el); | ||
}, | ||
|
||
change: function () { | ||
// $('div.text', this.el).text(JSON.stringify(this.output())); //debug | ||
this.conditions = this.output(); | ||
}, | ||
/** | ||
* output conditions object | ||
* @returns {object} | ||
*/ | ||
output: function () { | ||
var _conditions = {}; | ||
_(this.collection.models).each(function (item) { | ||
var _condition = item.get('condition'); | ||
for (var key in _condition) { | ||
if (_condition.hasOwnProperty(key)) { | ||
_conditions[key] = _condition[key]; | ||
} | ||
} | ||
}); | ||
return _conditions; | ||
} | ||
}); |
Oops, something went wrong.