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

V1.5.0 dev #300

Merged
merged 18 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
24 changes: 0 additions & 24 deletions build/test-page/explorer-local.html

This file was deleted.

65 changes: 0 additions & 65 deletions build/test-page/explorer.js

This file was deleted.

50 changes: 0 additions & 50 deletions build/test-page/index.js

This file was deleted.

151 changes: 129 additions & 22 deletions build/webcodebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4559,12 +4559,14 @@
var defaultSettings$3 = {
ignoredColumns: [],
meta: [],
defaultCodebookSettings: {},
tableConfig: {
sortable: false,
searchable: false,
pagination: false,
exportable: false
}
},
fileLoader: false
};

function setDefaults$1(explorer) {
Expand All @@ -4583,9 +4585,15 @@
explorer.config.tableConfig =
explorer.config.tableConfig || defaultSettings$3.tableConfig;

/********************* defaultCodebookSettings ***************/
explorer.config.defaultCodebookSettings =
explorer.config.defaultCodebookSettings ||
defaultSettings$3.defaultCodebookSettings;

/********************* files[].settings ***************/
explorer.config.files.forEach(function(f) {
f.settings = f.settings || {};
explorer.config.files.forEach(function(f, i) {
f.settings = f.settings || explorer.config.defaultCodebookSettings;
f.fileID = i;
});
}

Expand All @@ -4594,6 +4602,10 @@
\------------------------------------------------------------------------------------------------*/

function init$14() {
this.events.init.call(this);

//set the defailts
console.log(this.config.files);
setDefaults$1(this);

//prepare to draw the codebook for the first file
Expand Down Expand Up @@ -4628,10 +4640,7 @@
.select('tbody')
.selectAll('tr')
.filter(function(f) {
return (
f[explorer.config.labelColumn] ===
explorer.current[explorer.config.labelColumn]
);
return f.fileID === explorer.current.fileID;
})
.classed('selected', true);

Expand Down Expand Up @@ -4666,7 +4675,9 @@
return explorer.config.ignoredColumns.indexOf(f) == -1;
})
.filter(function(f) {
return ['settings', 'selected', 'event', 'json'].indexOf(f) == -1;
return (
['fileID', 'settings', 'selected', 'event', 'json'].indexOf(f) == -1
);
}); //drop system variables from table

//Create the table
Expand All @@ -4679,6 +4690,7 @@
explorer.config.files.forEach(function(d) {
return (d.selected = d == explorer.current);
});
console.log(explorer);
var sortedFiles = explorer.config.files.sort(function(a, b) {
return a.selected ? -1 : b.selected ? 1 : 0;
});
Expand All @@ -4696,6 +4708,93 @@
init: init$15
};

function addFile(label, csv_raw) {
var explorer = this;

// parse the file object
this.newFileObject = {};
this.newFileObject[explorer.config.labelColumn] = label;
this.newFileObject.json = d3.csv.parse(csv_raw);
this.newFileObject.settings = {};
this.newFileObject.fileID = explorer.config.files.length + 1;

//call the addFile event (if any)
explorer.events.addFile.call(this);

//add new files to file list
this.config.files = d3$1.merge([
[explorer.newFileObject],
this.config.files
]);

//re-draw the file listing
explorer.codebook.fileListing.table.draw(this.config.files);
}

function initFileLoad() {
//draw the control
var explorer = this;
explorer.dataFileLoad = {};
explorer.dataFileLoad.wrap = explorer.codebook.fileListing.wrap
.insert('div', '*')
.attr('class', 'dataLoader');

explorer.dataFileLoad.wrap.append('span').text('Add a local .csv file: ');

explorer.dataFileLoad.loader_wrap = explorer.dataFileLoad.wrap
.append('label')
.attr('class', 'file-load-label');

explorer.dataFileLoad.loader_label = explorer.dataFileLoad.loader_wrap
.append('span')
.text('Choose a File');

explorer.dataFileLoad.loader_input = explorer.dataFileLoad.loader_wrap
.append('input')
.attr('type', 'file')
.attr('class', 'file-load-input')
.on('change', function() {
var files = this.files;
explorer.dataFileLoad.loader_label.text(files[0].name);

if (this.value.slice(-4).toLowerCase() == '.csv') {
loadStatus.text(' loading ...').style('color', 'green');
var fr = new FileReader();
fr.onload = function(e) {
// get the current date/time
var d = new Date();
var n = d3.time.format('%X')(d);

addFile.call(explorer, files[0].name, e.target.result);

//clear the file input
loadStatus.text('Loaded.').style('color', 'green');
explorer.dataFileLoad.loader_input.property('value', '');
};

fr.readAsText(files.item(0));
} else {
loadStatus
.text("Can't Load. File is not a csv.")
.style('color', 'red');
}
});

var loadStatus = explorer.dataFileLoad.wrap
.append('span')
.attr('class', 'loadStatus')
.text('');

loadStatus
.append('sup')
.html('ⓘ')
.property(
'title',
'Create a codebook for a local file. File is added to the data set list, and is only available for a single session and is not saved.'
)
.style('cursor', 'help');
}

function makeCodebook(explorer) {
var _this = this;

Expand Down Expand Up @@ -4739,6 +4838,9 @@

explorer.codebook.on('complete', function() {
explorer.fileListing.init(explorer);
if (explorer.config.fileLoader) {
initFileLoad.call(explorer);
}
});

if (this.current.json) {
Expand All @@ -4750,20 +4852,9 @@
} else {
alert('No data provided for the selected file.');
}
}

function addFiles(files) {
var explorer = this;
//remove duplicates
var newFiles = files.filter(function(f) {
return explorer.config.files.indexOf(f) == -1;
});

//add new files to file list
this.config.files = d3$1.merge([this.config.files, newFiles]);

//re-draw the file listing
explorer.codebook.fileListing.table.draw(this.config.files);
//call the makeCodebook event (if any)
explorer.events.makeCodebook.call(this);
}

function createExplorer() {
Expand All @@ -4780,7 +4871,23 @@
layout: layout$2,
fileListing: fileListing,
makeCodebook: makeCodebook,
addFiles: addFiles
addFile: addFile
};

explorer.events = {
init: function init() {},
addFile: function addFile$$1() {},
makeCodebook: function makeCodebook$$1() {}
};

explorer.on = function(event, callback) {
var possible_events = ['init', 'addFile', 'makeCodebook'];
if (possible_events.indexOf(event) < 0) {
return;
}
if (callback) {
explorer.events[event] = callback;
}
};

return explorer;
Expand Down
Loading