Skip to content

Commit

Permalink
managed to get hxl parsing working but got stucked on header on last …
Browse files Browse the repository at this point in the history
…index
  • Loading branch information
femmerling committed May 2, 2012
1 parent 9030ae5 commit a33dbd2
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 19 deletions.
80 changes: 69 additions & 11 deletions static/brunch/build/web/js/app.js
Expand Up @@ -11398,7 +11398,10 @@ window.jQuery = window.$ = jQuery;
function WorksheetView() {
this.fill_dropdown_child = __bind(this.fill_dropdown_child, this);
this.fill_dropdown_head = __bind(this.fill_dropdown_head, this);
this.create_json = __bind(this.create_json, this);
this.process_data = __bind(this.process_data, this);
this.generate_total_data = __bind(this.generate_total_data, this);
this.create_data_json = __bind(this.create_data_json, this);
this.create_head_json = __bind(this.create_head_json, this);
this.selectCell = __bind(this.selectCell, this);
this.render = __bind(this.render, this);
WorksheetView.__super__.constructor.apply(this, arguments);
Expand All @@ -11407,9 +11410,14 @@ window.jQuery = window.$ = jQuery;
WorksheetView.prototype.el = '#page';
WorksheetView.prototype.selected_from = '';
WorksheetView.prototype.data_json = [];
WorksheetView.prototype.head_json = [];
WorksheetView.prototype.data_from = '';
WorksheetView.prototype.data_to = '';
WorksheetView.prototype.selection_done = 0;
WorksheetView.prototype.colmin = 0;
WorksheetView.prototype.colmax = 0;
WorksheetView.prototype.converted_hxl = '';
WorksheetView.prototype.total_data = {};
WorksheetView.prototype.events = {
'click td.cell': 'selectCell',
'change #rdf-type': 'fill_dropdown_child'
Expand Down Expand Up @@ -11466,14 +11474,34 @@ window.jQuery = window.$ = jQuery;
this.selected_from = '';
result = confirm('have you selected the correct data?');
if (result) {
return this.create_json();
return this.create_head_json();
} else {
return this.selected_from = '';
}
}
};
WorksheetView.prototype.create_json = function() {
var data, from, i, imax, imin, j, jmax, jmin, rows, to;
WorksheetView.prototype.create_head_json = function() {
var from, i, imax, imin, jmax, jmin, selected_cell, to;
from = this.data_from;
to = this.data_to;
imin = parseInt(from[0]);
imax = parseInt(to[0]);
jmin = parseInt(from[1]);
this.colmin = jmin;
jmax = parseInt(to[1]) + 1;
this.colmax = jmax;
i = this.colmin;
while (i < this.colmax) {
selected_cell = $("#h-" + i).val();
this.head_json.push(selected_cell);
i++;
}
console.log(this.head_json);
console.log(this.head_json[12]);
return this.create_data_json();
};
WorksheetView.prototype.create_data_json = function() {
var data, from, i, id, imax, imin, j, jmax, jmin, now, row, to;
from = this.data_from;
to = this.data_to;
imin = parseInt(from[0]);
Expand All @@ -11482,20 +11510,50 @@ window.jQuery = window.$ = jQuery;
jmax = parseInt(to[1]) + 1;
i = imin;
while (i < imax) {
rows = [];
j = jmin;
now = new Date();
id = now.getTime();
row = {
id: id,
cells: []
};
while (j < jmax) {
data = $('#' + i + '-' + j).data('value');
rows.push({
id: i + '-' + j,
value: data
});
row.cells.push(data);
j++;
}
this.data_json.push(rows);
this.data_json.push(row);
i++;
}
return console.log(this.data_json);
return this.generate_total_data();
};
WorksheetView.prototype.generate_total_data = function() {
this.total_data = {
rows: this.data_json,
type: $('#rdf-type').val(),
headers: this.head_json
};
return this.process_data(this.total_data);
};
WorksheetView.prototype.process_data = function(data) {
var cell, header, i, row, _i, _len, _ref, _results;
_ref = data.rows;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
row = _ref[_i];
_results.push((function() {
var _len2, _ref2, _results2;
_ref2 = row.cells;
_results2 = [];
for (i = 0, _len2 = _ref2.length; i < _len2; i++) {
cell = _ref2[i];
header = data.headers[i];
_results2.push(this.converted_hxl += "<" + data.type + "/" + row.id + "> <" + header + "> " + cell + " .\n");
}
return _results2;
}).call(this));
}
return _results;
};
WorksheetView.prototype.fill_dropdown_head = function() {
var display_label, display_value, hxl_labels, hxl_type, key, value, _results;
Expand Down
138 changes: 131 additions & 7 deletions static/brunch/src/app/views/worksheet_view.coffee
Expand Up @@ -5,9 +5,14 @@ class exports.WorksheetView extends Backbone.View
el: '#page'
selected_from : ''
data_json : []
head_json : []
data_from : ''
data_to : ''
selection_done : 0
colmin : 0
colmax : 0
converted_hxl : ''
total_data : {}


events:
Expand Down Expand Up @@ -56,11 +61,42 @@ class exports.WorksheetView extends Backbone.View
@selected_from = ''
result = confirm 'have you selected the correct data?'
if result
@create_json()
@create_head_json()
else
@selected_from = ''
# rows = []
# for i in [range.rowmin..range.rowmax]
# sparql should generate the id << the generation of id based on carsten's code is using getTime()
# and maybe even the whole row directly as hxl
# row = {id: Math.floor(1000000*Math.random()), cells:[]}
# rows.push(row)
# for j in [range.colmin..range.colmax]
# unless skipped[j-range.colmin]
# # td with attribute data-value
# val = $("##{i}-#{j}").data("value")
# row.cells.push( val )

create_json: =>
create_head_json: =>
from = @data_from
to = @data_to
imin = parseInt(from[0])
imax = parseInt(to[0])
jmin = parseInt(from[1])
@colmin = jmin
jmax = parseInt(to[1]) + 1
@colmax = jmax

i = @colmin
while i < @colmax
selected_cell = $("#h-#{i}").val()
#console.log selected_cell
@head_json.push(selected_cell)
i++
console.log @head_json
console.log @head_json[12]
@create_data_json()

create_data_json: =>
from = @data_from
to = @data_to
imin = parseInt(from[0])
Expand All @@ -69,16 +105,44 @@ class exports.WorksheetView extends Backbone.View
jmax = parseInt(to[1]) + 1
i = imin
while i < imax
rows = []
j = jmin
now = new Date()
id = now.getTime()
row = {id:id, cells:[]}
while j < jmax
data = $('#' + i + '-' + j).data('value')
#sparql here to form the dictionary of headers
rows.push(id: i+'-'+j, value:data)
row.cells.push(data)
j++
@data_json.push(rows)
@data_json.push(row)
i++
console.log @data_json
@generate_total_data()

generate_total_data:=>
@total_data = {
rows:@data_json,
type: $('#rdf-type').val(),
headers:@head_json
}
@process_data(@total_data)
#console.log @total_data
# @process_data(@total_data)
# converts json data to a kind of dummy hxl format
# that should be displayed to the user somehow
# data_to_hxl : (data) =>
# converted = ""
# for row in data.rows
# for cell, i in row.cells
# header = data.headers[i]
# converted += "<#{data.type}/#{row.id}> <#{header}> #{cell} .\n"
# converted

process_data: (data) =>
#console.log data.headers[12]
for row in data.rows
for cell, i in row.cells
header = data.headers[i]
@converted_hxl += "<#{data.type}/#{row.id}> <#{header}> #{cell} .\n"
#console.log @converted_hxl

fill_dropdown_head:=>
hxl_type = app.hxl.hxltypes
Expand All @@ -98,3 +162,63 @@ class exports.WorksheetView extends Backbone.View
display_value = value
$('.child-name').append($("<option></option>").attr("value",display_value).text(display_label))

# isoDateString:(d)=>
# pad (n) =>
# if n < 10
# return '0'+n
# else
# return n
# return d.getUTCFullYear()+'-'+ d.getUTCFullYear()+'-'+ pad(d.getUTCMonth()+1)+'-'+ pad(d.getUTCDate())+'T'+ pad(d.getUTCHours())+':'+ pad(d.getUTCMinutes())+':'+ pad(d.getUTCSeconds())+'Z'




# returns an object that describes a the range of a selection
# the arguments must of the form '0-1', '0-2', etc...
# selection_range : (from_id, to_id) =>
# from = from_id.split('-')
# to = to_id.split('-')
# rowmin : Math.min(parseInt(from[0],10),parseInt(to[0],10))
# rowmax: Math.max(parseInt(from[0],10),parseInt(to[0],10))
# colmin: Math.min(parseInt(from[1],10),parseInt(to[1],10))
# colmax: Math.max(parseInt(from[1],10),parseInt(to[1],10))

# reads the data from the table
# and returns it in the format accepted by data_to_hxl
# the headers must be select fields with ids like h-0, h-1, etc...
# the cells (td) must have ids like 0-1, 0-2, etc...
# and an attribute data-value
# the arguments must be of the same form as cell ids '0-1' etc..
# selected_data : (selected_from, selected_to) =>
# range = selection_range(selected_from, selected_to)

# headers = []
# skipped = []
# for j in [range.colmin..range.colmax]
# selected = $("#h-#{j}").val() # a select field
# skip = (selected == "ignore")
# skipped.push(skip)
# headers.push(selected) unless skip


# data = {
# rows: rows,
# type: $('#rdf-type').val(), # a select field
# headers: headers }





# test data in the format that data_to_hxl accepts
# test_data: =>
# {
# type: 'affectedPopulation',
# headers: ['location','rope','tents'],
# rows: [{
# id: 1234,
# cells: ['dubai',50, 10]},
# {
# id: 14567,
# cells: ['new york', 40, 9]}]}

1 change: 0 additions & 1 deletion templates/index.html
Expand Up @@ -11,7 +11,6 @@
<meta name="distribution" content="global" />
<link href="/static/brunch/build/web/css/main.css" media="screen, projection" rel="stylesheet" type="text/css" />
<script src="/static/brunch/build/web/js/app.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>require('main');</script>
</head>
<body>
Expand Down

0 comments on commit a33dbd2

Please sign in to comment.