[ckan-changes] commit/ckan: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Sep 8 16:41:27 UTC 2011
2 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/f262e08a6572/
changeset: f262e08a6572
branch: feature-1294-ux-improvements-dataset
user: zephod
date: 2011-09-08 16:29:48
summary: [ux,package/edit][l]: (refs #1296) Removed flexitable. Js table manipulations from Backbone views.
affected #: 5 files (5.5 KB)
--- a/ckan/public/css/style.css Wed Sep 07 14:58:58 2011 +0100
+++ b/ckan/public/css/style.css Thu Sep 08 15:29:48 2011 +0100
@@ -233,7 +233,10 @@
}
tbody tr:nth-child(even) td, tbody tr.even td {
- background-color: #fff7c0;
+ background-color: #FCF6CF;
+}
+tbody tr:nth-child(odd) td, tbody tr.odd td {
+ background-color: #FEFEF2;
}
tbody tr td.table-empty {
@@ -753,6 +756,19 @@
display: block;
}
+
+
+
+/* ====================== */
+/* = Add Resources Page = */
+/* ====================== */
+
+input#Resource--url {
+ width: 60%;
+}
+
+
+
/* =============================== */
/* = Mini-Tabs [Markdown Editor] = */
/* =============================== */
--- a/ckan/public/scripts/application.js Wed Sep 07 14:58:58 2011 +0100
+++ b/ckan/public/scripts/application.js Thu Sep 08 15:29:48 2011 +0100
@@ -7,6 +7,15 @@
CKAN.Utils.setupFormatAutocomplete($('input.autocomplete-format'));
CKAN.Utils.setupMarkdownEditor($('.markdown-editor a, .markdown-editor .markdown-preview'));
CKAN.Utils.setupDatasetEditNavigation();
+ // set up ckan js
+ var config = {
+ endpoint: '/'
+ };
+ var client = new CKAN.Client(config);
+ // serious hack to deal with hacky code in ckanjs
+ CKAN.UI.workspace = {
+ client: client
+ };
var isDatasetNew = $('body.package.new').length > 0;
if (isDatasetNew) {
@@ -16,23 +25,14 @@
$('#save').val("Add Dataset")
}
- var isPackageRead = $('body.package.read').length > 0;
- var config = {
- endpoint: '/'
- };
- var client = new CKAN.Client(config);
- // serious hack to deal with hacky code in ckanjs
- CKAN.UI.workspace = {
- client: client
- };
- if (isPackageRead) {
- var dataset = client.getDatasetById(LOCAL_packageId);
- var $el = $('#dataset');
-
- var view = new CKAN.View.DatasetFullForCore({
- model: dataset,
+ var isDatasetEdit = $('body.package.edit').length > 0;
+ if (isDatasetEdit) {
+ var $el=$('.resource-add');
+ var view=new CKAN.View.ResourceAdd({
+ model: null,
el: $el
});
+ view.render();
}
});
}(jQuery));
@@ -224,6 +224,7 @@
});
};
+
// Show/hide fieldset sections from the edit dataset form.
my.setupDatasetEditNavigation = function() {
@@ -365,6 +366,90 @@
}(jQuery, CKAN.Utils || {});
+CKAN.View.ResourceAddLinkFile = Backbone.View.extend({
+ initialize: function() {
+ _.bindAll(this, 'render');
+ },
+
+ render: function() {
+ var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkFile);
+ $(this.el).html(tmpl);
+ return this;
+ },
+
+ events: {
+ 'submit form': 'addNewResource',
+ },
+
+ addNewResource: function(e) {
+ e.preventDefault();
+ var maxId = 0;
+ var ids = $.map($('.resource-table').find('input'), function(item, idx) {
+ var thisId = parseInt($(item).attr('name').split('__')[1]);
+ maxId=Math.max(maxId, thisId);
+ });
+
+ var urlVal=this.el.find('input[name=url]').val();
+ var $newRow = $.tmpl(CKAN.Templates.resourceEntry, { url: urlVal, num: maxId+1 });
+
+ $('.resource-table tbody').append($newRow);
+ }
+});
+
+
+CKAN.View.ResourceAdd = Backbone.View.extend({
+ initialize: function() {
+ _.bindAll(this, 'render');
+ this.$sub = this.el.find('.resource-add-form');
+ },
+
+ render: function() {
+ },
+
+ events: {
+ 'click .action-resource-tab': 'clickAdd',
+ 'click #reset': 'reset'
+ },
+
+ reset: function(e) {
+ e.preventDefault();
+
+ },
+
+ clickAdd: function(e) {
+ e.preventDefault();
+ var action = $(e.target).attr('action');
+
+ var resource = new CKAN.Model.Resource({
+ 'dataset': this.model
+ });
+ // Open sub-pane
+ if (action=='upload-file') {
+ this.subView = new CKAN.View.ResourceUpload({
+ el: this.$sub,
+ model: resource,
+ // TODO: horrible reverse depedency ...
+ client: CKAN.UI.workspace.client
+ });
+ }
+ else if (action=='link-file') {
+ this.subView = new CKAN.View.ResourceAddLinkFile({
+ el: this.$sub,
+ model: resource,
+ // TODO: horrible reverse depedency ...
+ client: CKAN.UI.workspace.client
+ });
+ }
+ else if (action=='link-api') {
+ alert('TODO');
+ }
+ this.subView.render();
+ this.$sub.show();
+ return false;
+ }
+});
+
+
CKAN.View.DatasetFullForCore = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/public/scripts/templates.js Thu Sep 08 15:29:48 2011 +0100
@@ -0,0 +1,67 @@
+
+CKAN.Templates.resourceAddChoice = ' \
+ <ul> \
+ <li>Add a resource:</li> \
+ <li><a href="#" action="upload-file" class="action-resource-tab">Upload a file</a></li> \
+ <li><a href="#" action="link-file" class="action-resource-tab">Link to a file</a></li> \
+ <li><a href="#" action="link-api" class="action-resource-tab">Link to an API</a></li> \
+ </ul> \
+';
+
+CKAN.Templates.resourceAddLinkFile = ' \
+ <form class="resource-add" action=""> \
+ <dl> \
+ <dt> \
+ <label class="field_opt" for="url"> \
+ Link \
+ </label> \
+ </dt> \
+ <dd> \
+ <input name="url" type="text" placeholder="http://mydataset.com/file.csv" /> \
+ <input name="save" type="submit" class="pretty primary" value="Add" /> \
+ <input name="reset" type="reset" class="pretty" value="Cancel" /> \
+ </dd> \
+ </dl> \
+ \
+ </form> \
+';
+
+CKAN.Templates.resourceAddUploadFile = ' \
+ <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 id="upload" name="upload" type="submit" class="pretty primary" value="Upload" /> \
+ <input id="reset" name="reset" type="reset" class="pretty" value="Cancel" /> \
+ </div> \
+ </form> \
+ <div class="messages" style="display: none;"></div> \
+ </div> \
+';
+
+CKAN.Templates.resourceEntry = ' \
+ <tr> \
+ <td class="resource-url"> \
+ <input name="resources__${num}__url" type="text" value="${url}" class="short" /> \
+ </td> \
+ <td class="resource-format"> \
+ <input name="resources__${num}__format" type="text" value="" class="autocomplete-format short" /> \
+ </td> \
+ <td class="resource-description"> \
+ <input name="resources__${num}__description" type="text" value="" class="medium-width" /> \
+ </td> \
+ <td class="resource-hash"> \
+ <input name="resources__${num}__hash" type="text" value="" class="short" /> \
+ </td> \
+ <td class="resource-id"> \
+ <input name="resources__${num}__id" type="hidden" value="" /> \
+ </td> \
+</tr> \
+';
--- a/ckan/templates/layout_base.html Wed Sep 07 14:58:58 2011 +0100
+++ b/ckan/templates/layout_base.html Thu Sep 08 15:29:48 2011 +0100
@@ -53,10 +53,12 @@
<script type="text/javascript" src="${g.site_url}/scripts/vendor/showdown/showdown.js"></script><script type="text/javascript" src="${g.site_url}/scripts/vendor/jquery.fileupload/20110801/jquery.iframe-transport.js"></script><script type="text/javascript" src="${g.site_url}/scripts/vendor/jquery.fileupload/20110801/jquery.fileupload.js"></script>
- <script type="text/javascript" src="https://raw.github.com/okfn/ckanjs/master/pkg/ckanjs.js"></script>
- <!--script><![CDATA[window.CKAN.Client || document.write("<script src='${g.site_url}/scripts/ckanjs.js'>\x3C/script>")]]></script-->
+ <script type="text/javascript" src="${g.site_url}/scripts/ckanjs.js"></script>
+ <!--script><![CDATA[window.CKAN.Client || document.write("<script src='https://raw.github.com/okfn/ckanjs/master/pkg/ckanjs.js'>\x3C/script>")]]></script--><!-- finally our application js that sets everything up--><script type="text/javascript" src="${g.site_url}/scripts/application.js?lang=${c.locale}"></script>
+ <script type="text/javascript" src="${g.site_url}/scripts/templates.js"></script>
+
<script src="${g.site_url}/scripts/vendor/modernizr/1.7/modernizr.min.js"></script>
--- a/ckan/templates/package/new_package_form.html Wed Sep 07 14:58:58 2011 +0100
+++ b/ckan/templates/package/new_package_form.html Thu Sep 08 15:29:48 2011 +0100
@@ -72,18 +72,17 @@
<fieldset id="resources"><div class="instructions basic"><h3>Resources: the files and APIs associated with this dataset</h3></div>
- <table class="flexitable">
+ <table class="resource-table edit"><thead><tr><th class="field_req resource-url">URL*</th><th class="field_opt resource-format">Format</th><th class="field_opt resource-description">Description</th>
- <th class="field_opt resource-hash">Hash</th></tr></thead><tbody>
- <py:for each="num, res in enumerate(data.get('resources', []) + [{}])">
- <tr>
+ <py:for each="num, res in enumerate(data.get('resources', []))">
+ <tr class="resource-summary"><py:for each="col in c.resource_columns"><td py:choose="" class="resource-${col}"><input py:when="col == 'format'"
@@ -98,12 +97,45 @@
class="${'medium-width' if col=='description' else 'short'}" /></td></py:for>
- <td class="resource-id"><input name="resources__${num}__id" type="hidden" value="${res.get('id', '')}" /></td>
+ <td class="resource-id">
+ <input name="resources__${num}__id" type="hidden" value="${res.get('id', '')}" />
+ </td></tr></py:for>
+ <tr class="hook-last-row" style="display: none;">
+ <py:for each="col in c.resource_columns">
+ <td py:choose="" class="resource-${col}">
+ <input py:when="col == 'format'"
+ name="resources__0__${col}"
+ type="text" value=""
+ class="autocomplete-format short"
+ />
+ <input py:otherwise=""
+ name="resources__0__${col}"
+ type="text"
+ value=""
+ class="${'medium-width' if col=='description' else 'short'}" />
+ </td>
+ </py:for>
+ <td class="resource-id">
+ <input name="resources__0__id" type="hidden" value="" />
+ </td>
+
+ </tr></tbody></table>
+
+ <div class="resource-add">
+ <ul class="tabs">
+ <li>Add a resource:</li>
+ <li><a href="#" action="upload-file" class="action-resource-tab">Upload a file</a></li>
+ <li><a href="#" action="link-file" class="action-resource-tab">Link to a file</a></li>
+ <li><a href="#" action="link-api" class="action-resource-tab">Link to an API</a></li>
+ </ul>
+ <div class="resource-add-form"></div>
+ </div>
+
<!--
<div class="instructions basic">The files containing the data or address of the APIs for accessing it.</div><div class="instructions further"><br />These can be repeated as required. For example if the data is being supplied in multiple formats, or split into different areas or time periods, each file is a different 'resource' which should be described differently. They will all appear on the dataset page on CKAN together.<br /><br /><b>URL:</b> This is the Internet link directly to the data - by selecting this link in a web browser, the user will immediately download the full dataset. Note that datasets are not hosted on this site, but by the publisher of the data. Alternatively the URL can point to an API server such as a SPARQL endpoint or JSON-P service.<br /><b>Format:</b> This should give the file format in which the data is supplied. <br /><b>Description</b> Any information you want to add to describe the resource.<br /></div>
http://bitbucket.org/okfn/ckan/changeset/1141317ad57a/
changeset: 1141317ad57a
branch: feature-1294-ux-improvements-dataset
user: zephod
date: 2011-09-08 16:54:02
summary: [ux,package/edit][s]: (refs #1296) Enabled Add API link; tidied Upload File option; glitchfixed.
affected #: 2 files (809 bytes)
--- a/ckan/public/scripts/application.js Thu Sep 08 15:29:48 2011 +0100
+++ b/ckan/public/scripts/application.js Thu Sep 08 15:54:02 2011 +0100
@@ -366,13 +366,19 @@
}(jQuery, CKAN.Utils || {});
-CKAN.View.ResourceAddLinkFile = Backbone.View.extend({
- initialize: function() {
+CKAN.View.ResourceAddLink = Backbone.View.extend({
+ initialize: function(options) {
_.bindAll(this, 'render');
+ this.mode = options.mode;
},
render: function() {
- var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkFile);
+ if (this.mode=='file') {
+ var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkFile);
+ }
+ else if (this.mode=='api') {
+ var tmpl = $.tmpl(CKAN.Templates.resourceAddLinkApi);
+ }
$(this.el).html(tmpl);
return this;
},
@@ -400,7 +406,6 @@
CKAN.View.ResourceAdd = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
- this.$sub = this.el.find('.resource-add-form');
},
render: function() {
@@ -420,31 +425,33 @@
e.preventDefault();
var action = $(e.target).attr('action');
+ $(this.el).find('.resource-add-subpane').remove();
+
+ var $subPane = $('<div />').addClass('resource-add-subpane');
+ this.el.append($subPane);
+
var resource = new CKAN.Model.Resource({
'dataset': this.model
});
// Open sub-pane
if (action=='upload-file') {
this.subView = new CKAN.View.ResourceUpload({
- el: this.$sub,
+ el: $subPane,
model: resource,
// TODO: horrible reverse depedency ...
client: CKAN.UI.workspace.client
});
}
- else if (action=='link-file') {
- this.subView = new CKAN.View.ResourceAddLinkFile({
- el: this.$sub,
+ else if (action=='link-file' || action=='link-api') {
+ this.subView = new CKAN.View.ResourceAddLink({
+ el: $subPane,
model: resource,
+ mode: (action=='link-file')? 'file' : 'api',
// TODO: horrible reverse depedency ...
client: CKAN.UI.workspace.client
});
}
- else if (action=='link-api') {
- alert('TODO');
- }
this.subView.render();
- this.$sub.show();
return false;
}
});
--- a/ckan/public/scripts/templates.js Thu Sep 08 15:29:48 2011 +0100
+++ b/ckan/public/scripts/templates.js Thu Sep 08 15:54:02 2011 +0100
@@ -13,11 +13,11 @@
<dl> \
<dt> \
<label class="field_opt" for="url"> \
- Link \
+ File URL \
</label> \
</dt> \
<dd> \
- <input name="url" type="text" placeholder="http://mydataset.com/file.csv" /> \
+ <input name="url" type="text" placeholder="http://mydataset.com/file.csv" style="width: 60%"/> \
<input name="save" type="submit" class="pretty primary" value="Add" /> \
<input name="reset" type="reset" class="pretty" value="Cancel" /> \
</dd> \
@@ -26,21 +26,42 @@
</form> \
';
-CKAN.Templates.resourceAddUploadFile = ' \
+CKAN.Templates.resourceAddLinkApi = ' \
+ <form class="resource-add" action=""> \
+ <dl> \
+ <dt> \
+ <label class="field_opt" for="url"> \
+ Api URL \
+ </label> \
+ </dt> \
+ <dd> \
+ <input name="url" type="text" placeholder="http://mydataset.com/file.csv" style="width: 60%" /> \
+ <input name="save" type="submit" class="pretty primary" value="Add" /> \
+ <input name="reset" type="reset" class="pretty" value="Cancel" /> \
+ </dd> \
+ </dl> \
+ \
+ </form> \
+';
+
+CKAN.Templates.resourceUpload = ' \
<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 id="upload" name="upload" type="submit" class="pretty primary" value="Upload" /> \
+ <dl> \
+ <dt> \
+ <label class="field_opt fileinput-button" for="file"> \
+ File \
+ </label> \
+ </dt> \
+ <dd> \
+ <input type="file" name="file" /> \
+ <span class="fileinfo"></span> \
+ <input id="upload" name="upload" type="submit" class="pretty primary" value="Add" /> \
<input id="reset" name="reset" type="reset" class="pretty" value="Cancel" /> \
- </div> \
+ </dd> \
+ </dl> \
</form> \
<div class="messages" style="display: none;"></div> \
</div> \
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list