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
rgrp committed Aug 13, 2011
2 parents f847417 + 9c7bc45 commit 7a8f899
Show file tree
Hide file tree
Showing 20 changed files with 2,095 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -28,7 +28,7 @@ Here's how to do this on Apache::

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, PUT, GET, OPTIONS"
Header always set Access-Control-Allow-Headers "X-CKAN-API-KEY"
Header always set Access-Control-Allow-Headers "X-CKAN-API-KEY, Content-Type"

# Respond to all OPTIONS requests with 200 OK
# This could be done in the webapp
Expand Down
21 changes: 21 additions & 0 deletions app/css/ckanjs.css
Expand Up @@ -206,3 +206,24 @@ form dl dd .preview ul {
p.hints {
margin-bottom: 0;
}

/****************************************
* Resource Create
***************************************/

.resource-create table td {
vertical-align: top;
}

.resource-create table .separator {
background-color: #d2d2d2;
width: 5px;
}
.resource-create table td.upload {
padding-left: 10px;
}

.resource-create tr.heading td {
text-align: center;
}

16 changes: 12 additions & 4 deletions app/index.html
Expand Up @@ -34,19 +34,27 @@
<script src="../vendor/json2.js"></script>
<script src="../vendor/jquery.tmpl/beta1/jquery.tmpl.min.js"></script>
<script src="../vendor/jqueryui/1.8.4/jquery-ui.min.js"></script>
<script src="../vendor/showdown/showdown.js"></script>
<script src="../vendor/jquery.jeditable/1.7.2/jquery.jeditable.min.js"></script>
<script src="../vendor/underscore/1.1.6/underscore.js"></script>
<script src="../vendor/backbone/0.5.1/backbone.js"></script>

<script src="../vendor/showdown/showdown.js"></script>
<script src="../vendor/jquery.jeditable/1.7.2/jquery.jeditable.min.js"></script>
<script src="../vendor/jquery.fileupload/20110801/jquery.iframe-transport.js"></script>
<script src="../vendor/jquery.fileupload/20110801/jquery.fileupload.js"></script>

<script src="../lib/client.js"></script>
<script src="../lib/model.js"></script>

<script src="../lib/templates.js"></script>
<script src="../lib/template/dataset-view.js"></script>
<script src="../lib/template/dataset-form.js"></script>
<script src="../lib/template/resource-form.js"></script>
<script src="../lib/template/resource-view.js"></script>
<script src="../lib/client.js"></script>
<script src="../lib/model.js"></script>
<script src="../lib/view.js"></script>
<script src="../lib/view/resource-create.js"></script>
<script src="../lib/template/resource-upload.js"></script>
<script src="../lib/view/resource-upload.js"></script>

<script src="../lib/ui.js"></script>

<script src="../test/fixtures.js"></script>
Expand Down
32 changes: 32 additions & 0 deletions lib/client.js
Expand Up @@ -170,6 +170,38 @@ this.CKAN.Client = (function (CKAN, $, _, Backbone, undefined) {
}, this);

return new CKAN.Model.SearchCollection(models, {total: json.count});
},

// Performs a query on CKAN API.
// The `options` argument can contain any keys supported by jQuery.ajax().
// In addition it should contain either a url or offset variable. If
// offset provided it will be used to construct the full api url by
// prepending the endpoint plus 'api' (i.e. offset of '/2/rest/package'
// will become '{endpoint}/api/2/rest'.
//
// The `options.success` method (and any other success callbacks) will
// recieve a `SearchCollection` containing `Dataset` models. The method
// returns a jqXHR object so that additional callbacks can be registered
// with .success() and .error().
apiCall: function (options) {
options = options || {};
// Add additional request options.
options = _.extend({}, {
url: this.environment('endpoint') + '/api' + options.offset,
headers: {
'X-CKAN-API-KEY': this.environment('apiKey')
}
}, options);

return $.ajax(options);
},

// wrap CKAN /api/storage/auth/form - see http://packages.python.org/ckanext-storage
// params and returns value are as for that API
// key is file label/path
getStorageAuthForm: function(key, options) {
options.offset = '/storage/auth/form/' + key;
this.apiCall(options);
}
});

Expand Down
3 changes: 1 addition & 2 deletions lib/model.js
Expand Up @@ -186,7 +186,6 @@ CKAN.Model = function ($, _, Backbone, undefined) {
// NOTE: Returns localised URL.
toTemplateJSON: function () {
var out = this.toJSON();
out.ckan_url = '/package/' + this.get('name');
var title = this.get('title');
out.displaytitle = title ? title : 'No title ...';
var notes = this.get('notes');
Expand Down Expand Up @@ -270,7 +269,7 @@ CKAN.Model = function ($, _, Backbone, undefined) {

// Validates the provided attributes. Returns an object literal of
// attribute/error pairs if invalid, `undefined` otherwise.
validate: validator('url', 'dataset')
validate: validator('url')
});

// Helper function that returns a stub method that warns the devloper that
Expand Down
8 changes: 7 additions & 1 deletion lib/template/dataset-view.js
Expand Up @@ -2,7 +2,9 @@ CKAN.Templates.datasetView = ' \
<div class="dataset view" dataset-id="${dataset.id}"> \
<div class="extract"> \
${dataset.snippet} \
{{if dataset.snippet.length > 50}} \
<a href="#anchor-notes">Read more</a> \
{{/if}} \
</div> \
<div class="tags"> \
{{if dataset.tags.length}} \
Expand Down Expand Up @@ -49,6 +51,9 @@ CKAN.Templates.datasetView = ' \
<h3 id="anchor-notes">Notes</h3> \
<div class="notes-body"> \
{{html dataset.notesHtml}} \
{{if !dataset.notes || dataset.notes.length === 0}} \
<em>No notes yet. Click to add some ...</em> \
{{/if}} \
</div> \
</div> \
<div class="details subsection"> \
Expand Down Expand Up @@ -87,7 +92,8 @@ CKAN.Templates.sidebarDatasetView = ' \
<ul> \
{{each dataset.relationships}} \
<li> \
<a href="...">${$value.package}</a> \
${$value.type} dataset \
<a href="#dataset/${$value.object}/view">${$value.object}</a> \
{{if $value.comment}} \
<span class="relationship_comment"> \
(${$value.comment}) \
Expand Down
18 changes: 18 additions & 0 deletions lib/template/resource-form.js
Expand Up @@ -67,3 +67,21 @@ CKAN.Templates.resourceForm = ' \
</form> \
';

CKAN.Templates.resourceCreate = ' \
<div class="resource-create"> \
<table> \
<tr class="heading"> \
<td> \
<h3>Link to data online (File, API etc)</h3> \
</td> \
<td><h3>or</h3></td> \
<td><h3>Upload data</h3></td> \
</tr> \
<tr> \
<td class="edit"></td> \
<td class="separator"></td> \
<td class="upload"></td> \
</tr> \
</table> \
</div> \
';
20 changes: 20 additions & 0 deletions lib/template/resource-upload.js
@@ -0,0 +1,20 @@
CKAN.Templates.resourceUpload = ' \
<div class="fileupload"> \
<form action="http://test-ckan-net-storage.commondatastorage.googleapis.com/" class="resource-upload" \
enctype="multipart/form-data" \
method="POST"> \
\
<div class="fileupload-buttonbar"> \
<div class="hidden-inputs"></div> \
<label class="fileinput-button"> \
File \
</label> \
<input type="file" name="file" /> \
<span class="fileinfo"></span> \
<input type="submit" value="upload" /> \
</div> \
</form> \
<div class="messages" style="display: none;"></div> \
</div> \
';

2 changes: 1 addition & 1 deletion lib/templates.js
Expand Up @@ -5,7 +5,7 @@ CKAN.Templates = {
<li class="dataset summary" dataset-id="${dataset.id}"> \
<div class="header"> \
<span class="title" > \
<a href="${domain}${dataset.ckan_url}" ckan-attrname="title" class="editable">${dataset.displaytitle}</a> \
<a href="${dataset.ckan_url}" ckan-attrname="title" class="editable">${dataset.displaytitle}</a> \
</span> \
<div class="search_meta"> \
{{if dataset.resources.length}} \
Expand Down
1 change: 0 additions & 1 deletion lib/ui.js
Expand Up @@ -46,7 +46,6 @@ CKAN.UI = function($) {

var searchView = this.searchView = new CKAN.View.DatasetSearchView({
client: this.client,
domain: config.endpoint,
el: $('#search-page')
});

Expand Down
33 changes: 26 additions & 7 deletions lib/view.js
Expand Up @@ -4,6 +4,17 @@ CKAN.View = function($) {
var my = {};
var showdown = new Showdown.converter();

// Flash a notification message
//
// Parameters: msg, type. type is set as class on notification and should be one of success, error.
// If type not defined defaults to success
my.flash = function(msg, type) {
if (type === undefined) {
var type = 'success'
}
$.event.trigger('notification', [msg, type]);
};

my.NotificationView = Backbone.View.extend({
initialize: function() {
$.template('notificationTemplate',
Expand Down Expand Up @@ -48,7 +59,7 @@ CKAN.View = function($) {
updateConfig: function(e) {
e.preventDefault();
this.saveConfig();
$.event.trigger('notification', ['Saved configuration', 'success']);
CKAN.View.flash('Saved configuration');
},

saveConfig: function() {
Expand Down Expand Up @@ -96,7 +107,7 @@ CKAN.View = function($) {
this.model.set(this.getData());
this.model.save({}, {
success: function(model) {
$.event.trigger('notification', ['Saved dataset', 'success']);
CKAN.View.flash('Saved dataset');
window.location.hash = '#dataset/' + model.id + '/view';
}
});
Expand Down Expand Up @@ -187,11 +198,19 @@ CKAN.View = function($) {
var res = self.model.get('resources');
res.add(model);
$el.remove()
// TODO: save the model?
self.render();
self.model.save({}, {
success: function(model) {
CKAN.View.flash('Saved dataset');
// TODO: no need to re-render (should happen automatically)
self.render();
}
, error: function(model, error) {
CKAN.View.flash('Failed to save: ' + error, 'error');
}
});
}
resource.bind('change', handleNewResourceSave);
var resourceView = new my.ResourceEditView({
var resourceView = new CKAN.View.ResourceCreate({
el: $el,
model: resource
});
Expand All @@ -200,7 +219,7 @@ CKAN.View = function($) {
// does not seem to work for width ...
position: ['center', 'center'],
buttons: [],
width: 400,
width: 660,
resize: 'auto',
modal: false,
draggable: true,
Expand Down Expand Up @@ -248,7 +267,7 @@ CKAN.View = function($) {
},

addOne: function(pkg) {
var newView = new CKAN.View.DatasetSummaryView({model: pkg, domain: this.options.domain});
var newView = new CKAN.View.DatasetSummaryView({model: pkg});
//this.datasetSummaryViews[pkg.cid] = newView;
this.$results.find('.datasets').append(newView.render().el);
return this;
Expand Down
40 changes: 40 additions & 0 deletions lib/view/resource-create.js
@@ -0,0 +1,40 @@
this.CKAN || (this.CKAN = {});
this.CKAN.View || (this.CKAN.View = {});

(function (CKAN, $, _, Backbone, undefined) {
CKAN.View.ResourceCreate = Backbone.View.extend({
initialize: function() {
this.el = $(this.el);
_.bindAll(this, 'renderMain');
this.renderMain();
this.$edit = $(this.el.find('.edit')[0]);
this.$upload = $(this.el.find('.upload')[0]);
this.editView = new CKAN.View.ResourceEditView({
model: this.model,
el: this.$edit
});
this.uploadView = new CKAN.View.ResourceUpload({
el: this.$upload,
model: this.model,
// TODO: horrible reverse depedency ...
client: CKAN.UI.workspace.client
});
},

renderMain: function () {
this.el.empty();
tmplData = {
};
var tmpl = $.tmpl(CKAN.Templates.resourceCreate, tmplData);
this.el.html(tmpl);
return this;
},

render: function () {
this.editView.render();
this.uploadView.render();
}
});

})(CKAN, $, _, Backbone, undefined);

0 comments on commit 7a8f899

Please sign in to comment.