Skip to content

Commit

Permalink
more wiring in of functionality to facetview and jtedit. still a wee …
Browse files Browse the repository at this point in the history
…bit to go though.
  • Loading branch information
Mark MacGillivray committed Mar 17, 2012
1 parent b1b5049 commit 43c03b4
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 91 deletions.
6 changes: 4 additions & 2 deletions bibserver/dao.py
Expand Up @@ -94,7 +94,7 @@ def delete(self):
conn = httplib.HTTPConnection(url)
conn.request('DELETE', loc)
resp = conn.getresponse()
return True
return ''

@classmethod
def get(cls, id_):
Expand Down Expand Up @@ -234,9 +234,11 @@ def get_by_owner_coll(cls,owner,coll):
def delete(self):
url = str(config['ELASTIC_SEARCH_HOST'])
loc = config['ELASTIC_SEARCH_DB'] + "/" + self.__type__ + "/" + self.id
print loc
conn = httplib.HTTPConnection(url)
conn.request('DELETE', loc)
resp = conn.getresponse()
print resp.read()
for record in self.records:
record.delete()

Expand Down Expand Up @@ -267,6 +269,6 @@ def delete(self):
conn = httplib.HTTPConnection(url)
conn.request('DELETE', loc)
resp = conn.getresponse()
for coll in self.collections():
for coll in self.collections:
coll.delete()

42 changes: 29 additions & 13 deletions bibserver/search.py
Expand Up @@ -102,7 +102,9 @@ def record(self):
abort(401)
record.data = request.json
record.save()
return ''
resp = make_response( json.dumps(record.data, sort_keys=True, indent=4) )
resp.mimetype = "application/json"
return resp
else:
admin = True if auth.collection.update(self.current_user, collection) else False
return render_template('record.html',
Expand Down Expand Up @@ -131,9 +133,20 @@ def account(self):
elif request.method == 'POST':
if not auth.user.update(self.current_user,acc):
abort(401)
acc.data = request.json
info = request.json
if info.get('id',False):
if info['id'] != self.parts[0]:
acc = bibserver.dao.Account.get(info['id'])
else:
info['api_key'] = acc.data['api_key']
info['_created'] = acc.data['_created']
acc.data = info
if 'password' in info and not info['password'].startswith('sha1'):
acc.set_password(info['password'])
acc.save()
return ''
resp = make_response( json.dumps(acc.data, sort_keys=True, indent=4) )
resp.mimetype = "application/json"
return resp
else:
if util.request_wants_json():
if not auth.user.update(self.current_user,acc):
Expand Down Expand Up @@ -165,14 +178,9 @@ def collection(self):

# look for collection metadata
metadata = bibserver.dao.Collection.get_by_owner_coll(self.parts[0],self.parts[1])
if metadata:
if 'display_settings' in metadata:
# set display settings from collection info
#search_options = metadata['display_settings']
pass

if request.method == 'DELETE':
if metadata:
if metadata != None:
if not auth.collection.update(self.current_user, metadata):
abort(401)
else: metadata.delete()
Expand All @@ -186,9 +194,8 @@ def collection(self):
record = bibserver.dao.Record.get(rid['_id'])
if record: record.delete()
return ''

elif request.method == 'POST':
if metadata:
if metadata != None:
metadata.data = request.json
metadata.save()
return ''
Expand All @@ -204,8 +211,17 @@ def collection(self):
resp.mimetype = "application/json"
return resp
else:
admin = True if auth.collection.update(self.current_user, metadata) else False
return render_template('search/index.html', current_user=self.current_user, search_options=json.dumps(self.search_options), collection=metadata, admin=admin)
admin = True if metadata != None and auth.collection.update(self.current_user, metadata) else False
if metadata and 'display_settings' in metadata:
search_options = metadata['display_settings']
return render_template('search/index.html',
current_user=self.current_user,
search_options=json.dumps(self.search_options),
collection=metadata.data,
record = json.dumps(metadata.data),
admin=admin
)


def prettify(self,record):
result = ''
Expand Down
40 changes: 19 additions & 21 deletions bibserver/static/vendor/jtedit/jquery.jtedit.js
Expand Up @@ -20,12 +20,13 @@

// specify the defaults
var defaults = {
"editable":true, // whether or not to make the table editable
"editable":true, // whether or not to make the table editable
"source":undefined, // a source from which to GET the JSON data object
"target":undefined, // a target to which updated JSON should be POSTed
"noedit":[], // a list of keys that should not be editable, when edit is enabled
"hide":[], // a list of keys that should be hidden from view
"data":undefined, // a JSON object to render for editing
"delete_redirect":"#", // where to redirect to after deleting
"tags": []
}

Expand Down Expand Up @@ -85,23 +86,26 @@
}

if (editable) {
if (data[key].constructor.toString().indexOf("Array") != -1) { // if this key points to a list
} else {
}
if ( data.constructor.toString().indexOf("Array") == -1 ) {
var addname = key
} else {
var addname = ''
}
s += '<div class="jtedit_opts btn-group">'
s += '<a class="btn" href=""><i class="icon-plus"></i> add ' + addname + '</a>'
s += '<div class="jtedit_opts btn-group"'
if (data[key].constructor.toString().indexOf("Array") == -1) { // if this key does not point to a list
s += ' style="display:none;"'
}
s += '>'
if (data[key].constructor.toString().indexOf("Array") != -1) { // if this key points to a list
s += '<a class="btn" href=""><i class="icon-plus"></i> add ' + addname + '</a>'
}
s += '<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cog"></i> <span class="caret"></span></a>'
s += '<ul class="dropdown-menu">'
s += '<li><a class="jtedit_remove" href="#"><i class="icon-remove"></i> Remove entry</a></li>'
if (data[key].constructor.toString().indexOf("Array") == -1) { // if this key does not point to a list
s += '<li><a class="jtedit_tolist" href="#"><i class="icon-edit"></i> Convert to list</a></li>'
}
s += '<li><a class="jtedit_showhidedetails" href="#"><i class="icon-minus"></i> Hide details</a></li>'
//s += '<li><a class="jtedit_showhidedetails" href="#"><i class="icon-minus"></i> Hide details</a></li>'
s += '</ul></div>'
}
s += '</div>' // close the listitems
Expand Down Expand Up @@ -175,23 +179,19 @@
// save the record
var jtedit_saveit = function(event,datain) {
event.preventDefault()
if ($(this).attr('href') == "saveas") {
// trigger a save as new record instead of save over
alert("do saveas")
}
!datain ? datain = $.parseJSON(jQuery('#jtedit_json').val()) : false
!options.source ? options.source = prompt('Please provide URL to save this record to:') : false
if (options.source) {
!options.target ? options.target = prompt('Please provide URL to save this record to:') : false
if (options.target) {
$.ajax({
url: options.source
url: options.target
, type: 'POST'
, data: JSON.stringify(datain)
, contentType: "application/json; charset=utf-8"
, dataType: 'json'
, processData: false
, success: function(data, statusText, xhr) {
alert("Changes saved")
//window.location = '#'
window.location = window.location
}
, error: function(xhr, message, error) {
alert("Error... " + error)
Expand All @@ -205,18 +205,17 @@
// delete the record
var jtedit_deleteit = function(event) {
event.preventDefault()
if (!options.source) {
if (!options.target) {
alert('There is no available source URL to delete from')
} else {
var confirmed = confirm("You are about to irrevocably delete this. Are you sure you want to do so?")
if (confirmed) {
$.ajax({
url: options.source
url: options.target
, type: 'DELETE'
, success: function(data, statusText, xhr) {
alert("Record deleted.")
//window.location = '../'
//$('body').html('')
window.location = options.delete_redirect
}
, error: function(xhr, message, error) {
alert("Error... " + error)
Expand Down Expand Up @@ -323,10 +322,9 @@
'<li><a class="jtedit_mode" href="json">JSON</a></li>' +
'</ul></div>' +
'<a class="jtedit_saveit btn btn-primary" href="save"><i class="icon-check icon-white"></i> save</a> ' +
'<a class="jtedit_saveit btn btn-primary" href="saveas"><i class="icon-share icon-white"></i> save as</a> ' +
'<a class="btn btn-warning" href=""><i class="icon-refresh icon-white"></i> reload</a> ' +
'<a class="jtedit_deleteit btn btn-danger" href=""><i class="icon-remove icon-white"></i> delete</a></div>'
$('#jtedit').append(actions + '<div id="jtedit_visual"></div><textarea id="jtedit_json"></textarea>' + actions)
$('#jtedit').append(actions + '<div id="jtedit_visual"></div><textarea id="jtedit_json"></textarea>') // + actions)

var testdata = '{"abstract": "Folien zu einem Vortrag auf der ODOK 2010 in Leoben zu Linked Data und Open Data, mit einer knappen Darstellung der Linked-Open-Data-Aktivit\u110e\u1162ten im hbz-Verbund.", "added-at": "2011-02-17T13:00:20.000+0100", "author": ["pretend",["list","inalist"],{"id": "PohlAdrian","name": "Pohl, Adrian"},{"id": "PohlAdrian","name": "Pohl, Adrian"}], "journal":{"id":"somejournal","name":"somename"}, "biburl": "http://www.bibsonomy.org/bibtex/229ff5da471fd9d2706f2fd08c17b43dc/acka47", "cid": "Pohl_2010_LOD", "collection": "pohl", "copyright": "http://creativecommons.org/licenses/by/2.5/", "howpublished": "published via slideshare.net", "id": "531e7aa806574787897314010f29d4cf", "interhash": "558af6397a6aad826d47925a12eda76c", "intrahash": "29ff5da471fd9d2706f2fd08c17b43dc", "keyword": ["ODOK hbz libraries linkeddata myown opendata presentation"], "link": [{"url": "http://www.slideshare.net/acka47/pohl-20100923-odoklod"}], "month": "September", "owner": "test", "timestamp": "2011-02-17T13:00:20.000+0100", "title": "Freie Katalogdaten und Linked Data", "type": "misc", "url": "http://localhost:5000/test/pohl/Pohl_2010_LOD", "year": "2010" }'

Expand Down
6 changes: 3 additions & 3 deletions bibserver/templates/account/register.html
Expand Up @@ -11,18 +11,18 @@
{{ render_field(form.email, placeholder="hello@mywebsite.org") }}
{{ render_field(form.password, placeholder="********") }}
{{ render_field(form.confirm, placeholder="********") }}
{{ render_field(form.about, placeholder="just a bit") }}
{{ render_field(form.description, placeholder="just a bit") }}
<div class="actions">
<input type="submit" value="Signup" class="btn btn-primary" />
</div>
</form>
</div>
<div class="span5">
<p>It is necessary to register to use this service. This is only so that
your collections can be allocated to you. There is no cost. You will never be emailed.</p>
your collections can be allocated to you. There is no cost. You will only be emailed about service issues.</p>

<p>After registering and signing in, you can view your user information
by clicking your username on the top right menu. This includes your API-KEY,
by clicking your username on the top right menu. This includes your api_key,
which you will need if you want to send data via the API.</p>

<p>Don't get your username wrong! We can't change it! (If you do, just
Expand Down
17 changes: 17 additions & 0 deletions bibserver/templates/account/users.html
@@ -0,0 +1,17 @@
{% extends "base.html" %}

{% block content %}

{% for user in users %}

<div style="padding:20px; margin:20px; border:2px solid #ccc; width:300px; height:100px; float:left; overflow:hidden;">
<h2><a href="/{{ user.id }}">{{ user.id }}</a></h2>
<p>{{ user.description}}</p>
</div>

{% endfor %}

<div class="clearfix"></div>

{% endblock %}

43 changes: 23 additions & 20 deletions bibserver/templates/account/view.html
Expand Up @@ -12,27 +12,34 @@

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#user').jtedit({"data": {{ record | safe }} })
jQuery('#user').jtedit({
"data": {{ record | safe }},
"hide": ["api_key","_created","_last_modified","id"],
"target": "#",
"delete_redirect": "/"
})
});
</script>

<div class="hero-unit clearfix">
<div class="span4">
<div class="span5">
<h2>Hi {{ current_user.id }}</h2>
<p>{{ current_user.description }}</p>
<p><br />Your api_key is:<p>
<p> {{current_user['api_key']}}</p>
<p>You need to append this to your API calls if you want to make changes.</p>
{% if superuser %}
<p>You are the superuser!
<br />You can view and edit anything!
<p>You are the superuser! You can view and edit anything!
<br />Be careful...</p>
{% endif %}
</div>
<div class="span6">
<p>Your api_key is {{current_user['api_key']}}
<br />You need to append this to your API calls if you want to make changes.</p>
<div id="user" class="span5">
<h2>Edit your details</h2>
</div>
</div>

<div class="row">
<div class="span6">
<div class="span3">
<h3>Your collections</h3>
<p>Choose one to view, and your admin options will be available at the
bottom of the result display page.</p>
Expand All @@ -45,33 +52,29 @@ <h3>Your collections</h3>
{% endfor %}
{% endif %}
</div>
<div id="user" class="span6">
<h3>Edit your user profile</h3>
<div id="panel" class="span9">
<h3>All your records</h3>
</div>
</div>

{% else %}

<div class="hero-unit">
<div class="span4">
<h2>{{ account.id }}</h2>
</div>
<div class="hero-unit clearfix">
<div class="span6">
<h2>{{ account.id }}</h2>
<p>{{ account.description }}</p>
</div>
<div class="span4">
<p>You are not logged in as this user. Use the <a href="/account/login">login page</a> if you want to change this</p>
</div>
</div>

<div class="row">
<div class="span12">
<p>You are not logged in as this user. Use the <a href="/account/login">login page</a> if you want to change this</p>
<div id="panel" class="span12">
</div>
</div>

{% endif %}

<div id="panel" class="hero-unit">
<h3>{{ account.id }} - all records</h3>
</div>

{% endblock %}

2 changes: 1 addition & 1 deletion bibserver/templates/base.html
Expand Up @@ -104,7 +104,7 @@
<h4>About</h4>
<ul>
<li><a href="/faq">FAQ</a> / <a href="https://github.com/okfn/bibserver/issues">Feedback</a></li>
<li>Powered by <a href="https://github.com/okfn/bibserver">BibServer</a> (open source) <span style="color:#ccc">v0.4.0</span></li>
<li>Powered by <a href="https://github.com/okfn/bibserver">BibServer</a> (open source) v0.5.0</li>
<li>Following the <a href="http://openbiblio.net/principles/">Open Biblio Principles</a> (bibliographic metadata are facts)
and <a href="http://bibjson.org">BibJSON conventions</a></li>
</ul>
Expand Down

0 comments on commit 43c03b4

Please sign in to comment.