Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Sep 24, 2011
2 parents 2201653 + 6a83ad1 commit 5fe4f0d
Show file tree
Hide file tree
Showing 9 changed files with 1,898 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ configlocal.js
sandbox/*
css/ckan
.*.swp
build/*
44 changes: 16 additions & 28 deletions lib/template/resource-form.js
Expand Up @@ -9,11 +9,24 @@ CKAN.Templates.resourceForm = ' \
<dd> \
<input id="Resource--url" name="Resource--url" type="text" value="${url}" placeholder="http://mydataset.com/file.csv" /> \
</dd> \
<dt> \
<label class="field_opt" for="Resource--type"> \
Kind \
</label> \
</dt> \
<dd> \
<select id="Resource--type" name="Resource--type"> \
<option selected="selected" value="file">File</option> \
<option value="api">API</option> \
<option value="listing">Listing</option> \
<option value="example">Example</option> \
</select> \
</dd> \
</dl> \
\
<fieldset> \
<legend> \
<h3>A Bit More Info</h3> \
<h3>Optional Info</h3> \
</legend> \
<dl> \
<dt> \
Expand All @@ -25,19 +38,6 @@ CKAN.Templates.resourceForm = ' \
<input id="Resource--description" name="Resource--description" type="text" value="${description}" placeholder="A short description ..."/> \
</dd> \
\
<dt> \
<label class="field_opt" for="Resource--kind"> \
Kind \
</label> \
</dt> \
<dd> \
<select id="Resource--license_id" name="Resource--license_id"> \
<option selected="selected" value="file">File</option> \
<option value="api">API</option> \
<option value="index">Index</option> \
<option value="example">Example</option> \
</select> \
</dd> \
\
<dt> \
<label class="field_opt" for="Resource--format"> \
Expand All @@ -47,19 +47,7 @@ CKAN.Templates.resourceForm = ' \
<dd> \
<input id="Resource--format" name="Resource--format" type="text" value="${format}" placeholder="e.g. csv, zip:csv (zipped csv), sparql"/> \
</dd> \
\
<dt> \
<label class="field_opt" for="Resource--license_id"> \
Licence \
</label> \
</dt> \
<dd> \
<select id="Resource--license_id" name="Resource--license_id"> \
<option selected="selected" value=""></option> \
<option value="notspecified">Other::License Not Specified</option> \
</select> \
</dd> \
</fieldset> \
</fieldset> \
\
<div class="submit"> \
<input id="save" name="save" type="submit" value="Save" /> \
Expand All @@ -72,7 +60,7 @@ CKAN.Templates.resourceCreate = ' \
<table> \
<tr class="heading"> \
<td> \
<h3>Link to data online (File, API etc)</h3> \
<h3>Link to data already online</h3> \
</td> \
<td><h3>or</h3></td> \
<td><h3>Upload data</h3></td> \
Expand Down
58 changes: 45 additions & 13 deletions lib/view/resource-upload.js
Expand Up @@ -30,7 +30,7 @@ this.CKAN.View || (this.CKAN.View = {});
setupFileUpload: function() {
var self = this;
this.el.find('.fileupload').fileupload({
// needed because we are posting to remove url
// needed because we are posting to remote url
forceIframeTransport: true,
replaceFileInput: false,
autoUpload: false,
Expand All @@ -40,23 +40,46 @@ this.CKAN.View || (this.CKAN.View = {});
add: function(e,data) {
self.fileData = data;
self.fileUploadData = data;
// TODO: sanitize file name ...
self.key = data.files[0].name;
self.key = self.makeUploadKey(data.files[0].name);
self.updateFormData(self.key);
},
send: function(e, data) {
self.setMessage('<h2>Uploading file ...</h2><img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" />');
self.setMessage('Uploading file ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="spinner" />');
},
done: function(e, data) {
self.setMessage('Uploaded OK. Creating Resource ...');
self.onUploadComplete(self.key);
}
})
},

ISODateString: function(d) {
function pad(n) {return n<10 ? '0'+n : n};
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds());
},

// Create an upload key/label for this file.
//
// Form: {current-date}/file-name. Do not just use the file name as this
// would lead to collisions.
// (Could add userid/username and/or a small random string to reduce
// collisions but chances seem very low already)
makeUploadKey: function(fileName) {
// note that we put hh mm ss as hhmmss rather hh:mm:ss (former is 'basic
// format')
var now = new Date();
// replace ':' with nothing
var str = this.ISODateString(now).replace(':', '').replace(':', '');
return str + '/' + fileName;
},

updateFormData: function(key) {
var self = this;
self.setMessage('<h2>Checking upload permissions ...</h2><img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" />');
self.setMessage('Checking upload permissions ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="spinner" />');
self.el.find('.fileinfo').text(key);
self.client.getStorageAuthForm(key, {
async: false,
Expand All @@ -71,7 +94,7 @@ this.CKAN.View || (this.CKAN.View = {});
},
error: function(jqXHR, textStatus, errorThrown) {
// TODO: more graceful error handling (e.g. of 409)
self.setMessage('<h2>Failed to get credentials for storage upload. Upload cannot proceed</h2>');
self.setMessage('Failed to get credentials for storage upload. Upload cannot proceed', 'error');
}
});
},
Expand All @@ -94,30 +117,39 @@ this.CKAN.View || (this.CKAN.View = {});
if (name && name.length > 0 && name[0] === '/') {
name = name.slice(1);
}
var d = new Date(data._last_modified);
var lastmod = self.ISODateString(d);
self.model.set({
url: data._location
, name: name
, size: data._content_length
, last_modified: data.last_modified
, last_modified: lastmod
, format: data._format
, mimetype: data._format
, type: 'file'
, resource_type: 'file.upload'
, owner: data['uploaded-by']
, hash: data._checksum
, cache_url: data._location
, cache_url_updated: lastmod
}
, {
error: function(model, error) {
var msg = 'Error on saving resource: ' + error + '.';
msg += 'You will need to create a resource directly. Uploaded file at: ' + data._location;
var msg = 'Filed uploaded OK but error adding resource: ' + error + '.';
msg += 'You may need to create a resource directly. Uploaded file at: ' + data._location;
CKAN.View.flash(msg, 'error');
}
}
);
CKAN.View.flash('Resource created and added to dataset');
self.setMessage('File uploaded OK and resource added', 'success');
CKAN.View.flash('File uploaded OK and resource added');
}
});
},

setMessage: function(msg) {
setMessage: function(msg, category) {
var category = category || 'notice';
this.$messages.removeClass('notice success error');
this.$messages.addClass(category);
this.$messages.show();
this.$messages.html(msg);
},
Expand Down
47 changes: 47 additions & 0 deletions make
@@ -0,0 +1,47 @@
#!/bin/bash
#
# this is the make script
# it requires installation of node.js with the following
# modules installed:
#
# - jshint, for checking the js syntax
# - uglify-js, for js minification
# - markdown-js, for translation of readme.md to index.html
#
# Usage:
# just run ./make and be happy
#

set -e
BUILD=pkg
OUTFILE=$BUILD/ckanjs.js
MINFILE=$BUILD/ckanjs.min.js

echo "Checking JS files"
while read LINE
do
echo Skipping $LINE
# jshint $LINE
done < manifest

echo "Combining JS files"
DATE=`date +%s`
TMP=tmp_$DATE
TMPFILE=$TMP/tmp.js
mkdir $TMP
touch $TMPFILE

while read LINE
do
cat $LINE >> $TMPFILE
done < manifest

mkdir -p $BUILD
cp $TMPFILE $OUTFILE

echo "Compressing JS files"
# uglifyjs -o $MINFILE $TMPFILE

# remove temporary folder
rm -Rf $TMP

13 changes: 13 additions & 0 deletions manifest
@@ -0,0 +1,13 @@
lib/client.js
lib/model.js
lib/templates.js
lib/view.js
lib/ui.js
lib/template/dataset-form.js
lib/template/dataset-view.js
lib/template/resource-form.js
lib/template/resource-upload.js
lib/template/resource-view.js
lib/view/dataset-listing.js
lib/view/resource-create.js
lib/view/resource-upload.js

0 comments on commit 5fe4f0d

Please sign in to comment.