Skip to content

Commit

Permalink
Error handling in crowdsourcing extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkica committed Feb 6, 2013
1 parent e789ff4 commit 06f2c6c
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 140 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.DS_Store
*.class
sourceforge.sh
.import-temp/
.gitignore
build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function ZemantaCrowdFlowerDialog(onDone) {

if(tabindex === 0) {
self._extension.new_job = true;
console.log("Creating new job...");

if(self._elmts.chkUploadToNewJob.is(':checked')) {
uploadData = true;
Expand All @@ -105,18 +104,15 @@ function ZemantaCrowdFlowerDialog(onDone) {
} else {
self._extension.new_job = false;
self._extension.job_id = self._elmts.allJobsList.children(":selected").val();
console.log("Uploading to existing job...: " + self._extension.job_id);

if(self._mappedFields.length > 0) {
console.log("Mapped fields? Is this for templates?");
$.each(self._mappedFields, function(index, value) {
var col = {};
col.name = value.column;
col.safe_name = value.field;
self._extension.column_names.push(col);
});
} else {
console.log("Adding other columns");
$('#project-columns-' + tabindex +' input.zem-col:checked').each( function() {
var col = {};
col.name = $(this).attr('value');
Expand All @@ -132,8 +128,7 @@ function ZemantaCrowdFlowerDialog(onDone) {

if(uploadData){
self._extension.upload = true;
console.log("Columns: " + JSON.stringify(self._extension.column_names));
} else {
} else {
console.log("No data will be uploaded...");
self._extension.upload = false;
}
Expand All @@ -151,7 +146,6 @@ function ZemantaCrowdFlowerDialog(onDone) {

this._elmts.jobTitle.blur(function () {
var title = self._elmts.jobTitle.val();
console.log("Title length: " + title.length);
if(title.length > 5 && title.length < 255 ) {
$('#title-warning').hide();
} else {
Expand Down Expand Up @@ -193,7 +187,6 @@ ZemantaCrowdFlowerDialog.prototype._copyAndUpdateJob = function(jobid) {

//add gold or all units
var option = $('input[name=units]:checked').val();
console.log("Copy option: " + option);

if(option == "all_units") {
self._extension.all_units = true;
Expand All @@ -202,8 +195,7 @@ ZemantaCrowdFlowerDialog.prototype._copyAndUpdateJob = function(jobid) {
}

ZemantaCrowdSourcingExtension.util.copyJob(self._extension, function(data){
console.log("Copy results: " + JSON.stringify(data));
if(data[status] === "ERROR") {
if(data[status] == "ERROR") {
alert("There was an error either during copying or updating list.");
self._elmts.statusMessage.html("There was an error either during copying or updating list.");
} else {
Expand All @@ -223,8 +215,6 @@ ZemantaCrowdFlowerDialog.prototype._updateJobList = function(data) {
var selected = "";
var status = data["status"];
var dismissBusy = DialogSystem.showBusy();

//console.log("Data: " + JSON.stringify(data));

selContainer.empty();

Expand All @@ -243,8 +233,7 @@ ZemantaCrowdFlowerDialog.prototype._updateJobList = function(data) {

for (var index = 0; index < jobs.length; index++) {
var value = jobs[index];
console.log("Value: " + value);


if(value.id === data.job_id) {
selected = " selected";
} else {
Expand Down Expand Up @@ -291,9 +280,7 @@ ZemantaCrowdFlowerDialog.prototype._renderAllExistingJobs = function() {
this._extension = {};
this._extension.job_id = $(this).children(":selected").val();
this._selectedJob = this._extension.job_id;

//console.log("Job id changed:" + JSON.stringify(this._extension));


ZemantaCrowdSourcingExtension.util.getJobInfo(this._extension, function(data){
self._updateJobInfo(data);
});
Expand All @@ -311,7 +298,6 @@ ZemantaCrowdFlowerDialog.prototype._updateJobInfo = function(data) {
self._fields = [];
self._mappedFields = [];

console.log("... updating job info");
var status = data["status"];

if(status === "ERROR") {
Expand Down Expand Up @@ -340,14 +326,11 @@ ZemantaCrowdFlowerDialog.prototype._updateJobInfo = function(data) {


if(data["fields"]!= null && data["fields"].length > 0) {
console.log("Job has fields");
self._elmts.extColumnsPanel.hide();
self._elmts.extFieldsPanel.show();
self._fields = data["fields"];
self._renderMappings();
} else {

console.log("Job has no fields, showing columns...");
} else {
self._elmts.extFieldsPanel.hide();
var tabindex = 1;
self._renderAllColumns2(self._elmts.columnsMenu_1, self._elmts.columnList_1, tabindex);
Expand Down Expand Up @@ -416,8 +399,6 @@ ZemantaCrowdFlowerDialog.prototype._showColumnsDialog = function(field, mapped_c

var bodyElmts = DOM.bind(body);

console.log("Mapped column: " + mapped_col);

$.each(columns, function(index, value){

var input = $('<input type="radio" name="columns" class="zem-col" value="' + value.name + '">' + value.name + '</input><br/>').appendTo(bodyElmts.projColumns);
Expand All @@ -442,10 +423,8 @@ ZemantaCrowdFlowerDialog.prototype._showColumnsDialog = function(field, mapped_c
footerElmts.cancelButton.click(dismiss);

footerElmts.okButton.click(function() {
console.log("Column selected:" + $('input[name=columns]:checked').val());
var new_mapped = $('input[name=columns]:checked').val();
self._addFCMapping(field, mapped_col, new_mapped);
console.log("Updated mappings: " + JSON.stringify(self._mappedFields));
dismiss();
self._renderMappings();
});
Expand All @@ -456,15 +435,11 @@ ZemantaCrowdFlowerDialog.prototype._renderMappings = function() {
var elm_fields = self._elmts.extJobFields;
elm_fields.empty();

console.log("Rendering mappings...");

$.each(self._fields, function(index, value) {
var link = $('<a title="' + value + '" href="javascript:{}">' + value + '</a>').appendTo(elm_fields);
$('<span>&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;</span>').appendTo(elm_fields);
var mapped_column = self._getMappedColumn(value);
console.log("Mapped column: " + mapped_column);
var col_name = ((mapped_column === "") ? "(click to add column mapping)": mapped_column);
console.log("Getting mapped column: " + col_name);

var link2 = $('<a href="javascript:{}" data-value="' + value + '">' + col_name + '</a><br/>').appendTo(elm_fields);

Expand Down Expand Up @@ -518,16 +493,12 @@ ZemantaCrowdFlowerDialog.prototype._updateFieldsFromTemplate = function (entityT
var self = this;
var title = "";
var instructions = "";
var cml = "";
var recon = "";
var reconSearchUrl = "";

//get selected template
var template = self._elmts.jobTemplates.children(":selected").val();

console.log("Entity type: " + entityType);
console.log("Template: " + template);

if(template === "blank") {
alert("Choose template first.");
return;
Expand Down Expand Up @@ -578,13 +549,4 @@ ZemantaCrowdFlowerDialog.prototype._updateFieldsFromTemplate = function (entityT
self._elmts.jobTitle.val(title);
self._elmts.jobInstructions.val(instructions);


console.log("Updating fields from template: " + template);
console.log("Generated CML\n" + cml);

//todo: upload cml to created job




};
65 changes: 31 additions & 34 deletions extensions/crowdsourcing/module/scripts/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ZemantaCrowdSourcingExtension.handlers.storeCrowdFlowerSettings = function() {
},
function(o) {
if (o.code == "error") {

alert(o.message);
}
},
Expand All @@ -26,7 +25,6 @@ ZemantaCrowdSourcingExtension.handlers.storeCrowdFlowerSettings = function() {
},
function(o) {
if (o.code == "error") {

alert(o.message);
}
},
Expand All @@ -53,13 +51,14 @@ ZemantaCrowdSourcingExtension.handlers.openJobSettingsDialog = function() {
},
function(o)
{
console.log("Status: " + o.status);
if(o.status==="OK" | o.status=="200") {
if(o.status != "ERROR") {
if(extension.new_job === true) {
alert("New job was created successfully.\n You can see it on your CrowdFlower account.");
alert("New job was created successfully.\nYou can see it on your CrowdFlower account.");
} else {
alert("Data was uploaded successfully.\n You can see it on your CrowdFlower account.");
alert("Data was uploaded successfully.\nYou can see it on your CrowdFlower account.");
}
} else {
alert("An error occured that prevented creating the job. \n" + o.message);
}
},
"json"
Expand All @@ -84,12 +83,10 @@ ZemantaCrowdSourcingExtension.handlers.evaluateReconDialog = function() {
alert("There is something wrong with your data. It was not uploaded to CrowdFlower Service.");
}
else {
console.log("Status: " + o.status);

if(o.status === "OK" | o.status === 200) {
if(o.status == "ok" || o.status == 200) {
alert("Data successfully uploaded. Check your CrowdFlower account.");
} else {
alert("Something went wrong while uploading. Error: \n" + o.status);
alert("Something went wrong while uploading. \n" + o.status);
}
}
},
Expand All @@ -114,29 +111,29 @@ ExtensionBar.addExtensionMenu({
"id": "crowdsourcing-ext",
"label": "Crowdsourcing",
"submenu": [
{
"id": "crowdsourcing-ext/create-crowdflower-job",
label: "Create new job / upload data",
click: ZemantaCrowdSourcingExtension.handlers.openJobSettingsDialog
},
{},
{
"id":"crowdsourcing-ext/templates",
"label": "Templates",
"submenu": [
{
"id": "crowdsourcing-ext/templates/eval-recon-data",
"label": "Evaluate reconciled data",
click: ZemantaCrowdSourcingExtension.handlers.evaluateReconDialog
},
]
},
{},
{
"id": "crowdsourcing-ext/settings",
"label": "CrowdFlower settings",
click: ZemantaCrowdSourcingExtension.handlers.storeCrowdFlowerSettings
}
]
{
"id": "crowdsourcing-ext/create-crowdflower-job",
label: "Create new job / upload data",
click: ZemantaCrowdSourcingExtension.handlers.openJobSettingsDialog
},
{},
{
"id":"crowdsourcing-ext/templates",
"label": "Templates",
"submenu": [
{
"id": "crowdsourcing-ext/templates/eval-recon-data",
"label": "Evaluate reconciled data",
click: ZemantaCrowdSourcingExtension.handlers.evaluateReconDialog
},
]
},
{},
{
"id": "crowdsourcing-ext/settings",
"label": "CrowdFlower settings",
click: ZemantaCrowdSourcingExtension.handlers.storeCrowdFlowerSettings
}
]
});

29 changes: 8 additions & 21 deletions extensions/crowdsourcing/module/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ ZemantaCrowdSourcingExtension.util.loadCrowdFlowerApiKeyFromSettings = function(
"/command/core/get-all-preferences",
{},
function (data) {
console.log("All CF settings: " + data.stringify());
if (data!=null && data["crowdflower.apikey"]!=null) {
if (data != null && data["crowdflower.apikey"] != null) {

getApiKey(data["crowdflower.apikey"]);
}
Expand All @@ -19,12 +18,10 @@ ZemantaCrowdSourcingExtension.util.loadCrowdFlowerApiKeyFromSettings = function(

ZemantaCrowdSourcingExtension.util.convert2SafeName = function(columnName) {

//console.log("Column name:" + columnName);
var patt = /(\s)+/ig;
var rep = '_';
var safeName = columnName.toLowerCase();
safeName = safeName.replace(patt, rep);
console.log("Safe name: " + safeName);
return safeName;

};
Expand All @@ -34,7 +31,6 @@ ZemantaCrowdSourcingExtension.util.generateCML = function(tabindex) {
var cml = '';
$('#project-columns-'+ tabindex + ' input.zem-col:checked').each( function() {
cml += '{{' + ZemantaExtension.util.convert2SafeName($(this).attr('value')) + '}}' + '<br/>';
console.log("CML: " + cml);
});

return cml;
Expand All @@ -48,14 +44,11 @@ ZemantaCrowdSourcingExtension.util.loadAllExistingJobs = function(getJobs) {
},
function(data)
{
if(data != null) {
console.log("Status: " + data.status);

if(data != null) {
if(data.status != "ERROR") {
getJobs(data['jobs'],data.status);
} else{
console.log(JSON.stringify(data));
alert("Error occured while loading existing jobs. Error: " + data.message);
alert("An error occured while loading existing jobs.\n" + data.message);
getJobs([], data.message);
}
}
Expand All @@ -72,14 +65,11 @@ ZemantaCrowdSourcingExtension.util.copyJob = function(extension, updateJobs) {
{"extension": JSON.stringify(extension)},
function(data)
{
console.log("Data returned: " + JSON.stringify(data));

if(data != null) {
console.log("Status: " + data.status);
updateJobs(data);
if(data != null && data.status != "ERROR") {
updateJobs(data);
}
else {
alert("Could not refresh list of jobs.");
alert("Could not refresh the job list.\n" + data.message);
}
},
"json"
Expand All @@ -94,13 +84,10 @@ ZemantaCrowdSourcingExtension.util.getJobInfo = function(extension, updateJobInf
{"extension": JSON.stringify(extension)},
function(data)
{
console.log("Data returned: " + JSON.stringify(data));

if(data != null) {
console.log("Status: " + data.status);
if(data != null && data.status != "ERROR") {
updateJobInfo(data);
} else {
alert("Error occured while updating job information.");
alert("Error occured while updating job information.\n" + data.message);
}
},
"json"
Expand Down
Loading

0 comments on commit 06f2c6c

Please sign in to comment.