From 192f5c5c143db03cbc08d1cc0ffc650a44991fe6 Mon Sep 17 00:00:00 2001 From: Branson Stephens <stephenb@uwm.edu> Date: Wed, 17 Apr 2013 14:58:13 -0500 Subject: [PATCH] added forms for tagging new and existing log messages. Also provide Display Name. --- gracedb/views.py | 44 +++++++----- static/css/style.css | 23 ++++++ static/images/minusButton.gif | Bin 0 -> 148 bytes static/images/plusButton.gif | Bin 0 -> 212 bytes templates/gracedb/event_detail.html | 108 +++++++++++++++++++++------- 5 files changed, 133 insertions(+), 42 deletions(-) create mode 100644 static/images/minusButton.gif create mode 100644 static/images/plusButton.gif diff --git a/gracedb/views.py b/gracedb/views.py index d558bb3ec..09b9b3a8f 100644 --- a/gracedb/views.py +++ b/gracedb/views.py @@ -444,6 +444,7 @@ def sanitize_html(data): def logentry(request, graceid, num=None): + logger = logging.getLogger(__name__) try: event = Event.getByGraceid(graceid) except Event.DoesNotExist: @@ -453,6 +454,28 @@ def logentry(request, graceid, num=None): elog = EventLog(event=event, issuer=request.ligouser) elog.comment = request.POST.get('comment') or request.GET.get('comment') elog.save() + logger.debug("just saved log entry") + tagname = request.POST.get('tagname') + logger.debug("tagname = %s" % tagname) + if tagname: + # Look for the tag. If it doesn't already exist, create it. + try: + tag = Tag.objects.filter(name=tagname)[0] + except: + displayName = request.POST.get('displayName') + logger.debug("disp name = %s" % displayName) + tag = Tag(name=tagname, displayName=displayName) + tag.save() + logger.debug("just saved tag") + + tag.eventlogs.add(elog) + # Create a log entry to document the tag creation. + num = elog.getN() + msg = "Tagged message %s: %s " % (num, tagname) + tlog = EventLog(event=event, + issuer=request.ligouser, + comment=msg) + tlog.save() else: try: elog = event.eventlog_set.order_by('created').all()[int(num)] @@ -467,6 +490,8 @@ def logentry(request, graceid, num=None): rv['issuer'] = elog.issuer.name rv['created'] = elog.created.isoformat() rv['comment'] = elog.comment + if tagname: + rv['tagname'] = tagname return HttpResponse(json.dumps(rv), content_type="application/json") @@ -1001,17 +1026,14 @@ def latest(request): #----------------------------------------------------------------------------------- def taglogentry(request, graceid, num, tagname): - logger = logging.getLogger(__name__) try: event = Event.getByGraceid(graceid) eventlog = event.eventlog_set.order_by("created").all()[int(num)] - logger.debug("got event and eventlog") except: # Either the event or the log does not exist. raise Http404 - if request.method == "PUT": - logger.debug("using put method") + if request.method == "POST": try: # Has this tag-eventlog relationship already been created? tag = eventlog.tag_set.filter(name=tagname)[0] @@ -1019,44 +1041,32 @@ def taglogentry(request, graceid, num, tagname): return HttpResponse(msg, content_type="text") except: # Look for the tag. If it doesn't already exist, create it. - logger.debug("before looking for tag") try: tag = Tag.objects.filter(name=tagname)[0] - logger.debug("got the tag") except: - displayName = request.DATA.get('displayName') + displayName = request.POST['displayName'] tag = Tag(name=tagname, displayName=displayName) tag.save() - logger.debug("created tag") - - logger.debug("before adding eventlog") # Now add the log message to this tag. tag.eventlogs.add(eventlog) - logger.debug("after adding eventlog") - # Create a log entry to document the tag creation. msg = "Tagged message %s: %s " % (num, tagname) logentry = EventLog(event=event, issuer=request.ligouser, comment=msg) logentry.save() - - logger.debug("after saving logentry") else: # We will only allow PUT here. Anything else is a bad request: 400 return HttpResponseBadRequest - logger.debug("before checking for ajax") # Hopefully, this will only ever be called form inside a script. Just in case... if not request.is_ajax(): return HttpResponseRedirect(reverse(view, args=[graceid])) - logger.debug("after checking for ajax") # no need for a JSON response. msg = "Successfully applied tag %s to log message %s." % (tagname, num) msg = msg + " Refresh to see chages (if any) to the presentation." - logger.debug("before returning final message") return HttpResponse(msg, content_type="text") diff --git a/static/css/style.css b/static/css/style.css index db5ab5f69..76f5aaf68 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -24,6 +24,29 @@ table.analysis_specific {width:100%} table.figures tr.figrow {text-align:center;} table.figures {width:300px;height:270px;border:1px solid gray;} +.tundra.eventDetail .pmTitlePaneClass .dijitOpen .dijitArrowNode { + background-repeat: no-repeat; + height: 14px; + width: 14px; +} + +.tundra.eventDetail .pmTitlePaneClass .dijitClosed .dijitArrowNode { + background-repeat: no-repeat; + height: 14px; + width: 14px; +} + +.tundra.eventDetail .pmTitlePaneClass .dijitClosed .dijitArrowNode { + background-image: url('/branson-static/images/plusButton.gif'); + background-position: 0px 0px; +} + +.tundra.eventDetail .pmTitlePaneClass .dijitOpen .dijitArrowNode { + background-image: url('/branson-static/images/minusButton.gif'); + background-position: 0px 0px; +} + + /* End Branson */ td, th {padding:3px;border:none;} diff --git a/static/images/minusButton.gif b/static/images/minusButton.gif new file mode 100644 index 0000000000000000000000000000000000000000..48d5172470f250383e7696c7b61c727b9df06eb0 GIT binary patch literal 148 zcmZ?wbhEHb<YVAt*v!E2=FOY$-@g|Y7M7NlK6&!w_wU~?Uc7kv^y$x^Kc78&_V@4K zSFc|E|NnpX?AZ)pp!kyoOzVJ1kQodtjvG#TYVWp)UuiwrOQUaL$efHSFOS#z){3w= v=U(5;!r=7&yY<N=4;?<$wk1U~r>M-k@FKWqMb!FG&cxGi^RyGZSQxAUy8cA) literal 0 HcmV?d00001 diff --git a/static/images/plusButton.gif b/static/images/plusButton.gif new file mode 100644 index 0000000000000000000000000000000000000000..103c021daa0668c5b0ba53ac0bace43eb1f1f7ee GIT binary patch literal 212 zcmZ?wbhEHb<YVAtIKsf-<>lq!;ZasrmY<(rP*6}_UjF9IoA2Mh7Zw(lmX`kh{rkm> z7e9ageD>_w-@kufy?XWJ$&;r~pZ@><fA;Lz3`79MpDbWiIv^5cCj)EX1C_oM&AAy> zU0K?lelp^%GTmPDE?4OpIV^AxVCmv(ZxLb$P@ACC%;?C=vVvpfi-S*vIAYgjII7j3 eP6<rjE5~yqJ21s>{dw03d+O%v|MXO3um%7=piZy= literal 0 HcmV?d00001 diff --git a/templates/gracedb/event_detail.html b/templates/gracedb/event_detail.html index caa992d9f..a7b7f156f 100644 --- a/templates/gracedb/event_detail.html +++ b/templates/gracedb/event_detail.html @@ -6,7 +6,7 @@ {% block title %}View {{ object.graceid }}{% endblock %} {% block heading %}{% endblock %} -{% block bodyattrs %}class="tundra"{% endblock %} +{% block bodyattrs %}class="tundra eventDetail"{% endblock %} {% block jscript %} {# XXX http/https depending on this pages' protocol #} @@ -48,8 +48,12 @@ var editor_div = dom.byId("editor"); var preview_div = dom.byId("previewer"); + // Branson messing around. + var newLogTag_pane_holder = dom.byId("newLogTag_pane_holder"); + dojo.style(preview_div, { 'display':'none'}); dojo.style(editor_div, { 'display':'none'}); + dojo.style(newLogTag_pane_holder, { 'display':'none'}); var button_element = dojo.create('button'); dojo.place(button_element, logtitle, "right"); @@ -59,12 +63,14 @@ onClick: function(){ if (this.state == 'add') { dojo.style(editor_div, {'display':'block'}); + dojo.style(newLogTag_pane_holder, {'display':'block'}); button.set('label', "Cancel Log Entry"); button.set('state', 'cancel'); editor.focus(); } else { dojo.style(editor_div, {'display':'none'}); + dojo.style(newLogTag_pane_holder, {'display':'none'}); dojo.style(preview_div, {'display':'none'}); button.set('label', "Add Log Entry"); button.set('state', 'add'); @@ -86,15 +92,19 @@ alert("o hai " + error); }, save: function(postdata) { - var postArgs = { + var newTagName = domForm.fieldToObject("newTagSelect"); + var newTagDispName = domForm.fieldToObject("newTagDispName"); + var postArgs = { url: this.url, - content: { comment: postdata }, + content: { comment: postdata, tagname: newTagName, displayName: newTagDispName }, handleAs: "json" }; this.button.set("disabled", true); var deferred = dojo.xhrPost(postArgs); deferred.addCallback(dojo.hitch(this, this.onSuccess)); deferred.addErrback(dojo.hitch(this, this.onError)); + // Call whatever function is necessary to attach the tag + // or add to the postdata and handle in the django view? } }); @@ -111,6 +121,25 @@ } }); + // Branson: set up infrastructure for tagging log messages. +{% if blessed_tags %} + var blessedTagStore = new Memory({ + data: [ + {% for bt in blessed_tags %} + {name:"{{bt}}"}, + {% endfor %} + ] + }); + + // Branson messing around. + var tagbox = new ComboBox({ + id: "newTagSelect", + name: "newTagSelect", + value: "insert tag here", + store: blessedTagStore, + searchAttr: "name" + }, "newTagSelect"); + var editor = new Editor({ extraPlugins : ['foreColor','hiliteColor','|','createLink', 'insertImage','fullscreen','viewsource','newpage', '|', previewbutton, savebutton] @@ -149,7 +178,6 @@ {% for tag in object.getAvailableTags %} {% if tag.name in blessed_tags %} if (dom.byId("{{tag.name}}_figure_container")) { - console.log("detected figure container for {{tag.name}}"); figure_container_ids.push("{{tag.name}}_figure_container"); } {% endif %} @@ -164,38 +192,50 @@ {% endif %} - // Branson: set up infrastructure for tagging log messages. -{% if blessed_tags %} - var blessedTagStore = new Memory({ - data: [ - {% for bt in blessed_tags %} - {name:"{{bt}}"}, - {% endfor %} - ] - }); - + // Form for tagging log messages. var cb = new ComboBox({ - id: "tagSelect", - name: "tagSelect", + id: "existingTagSelect", + name: "existingTagSelect", value: "None", store: blessedTagStore, searchAttr: "name" - }, "tagSelect"); + }, "existingTagSelect"); + + + // Work on panes for the tagging forms here. + var newLogTag = dom.byId("newLogTag"); + //var newLogTag_pane_hoder = dom.byId("newLogTag_pane_holder"); + var existingLogTag = dom.byId("existingLogTag"); + var existingLogTag_pane_holder = dom.byId("existingLogTag_pane_holder"); + + tp_new = new dijit.TitlePane({title:"Tag this message", + content:newLogTag.innerHTML, + open:false}); + newLogTag_pane_holder.appendChild(tp_new.domNode); + dojo.destroy(newLogTag); + + tp_existing = new dijit.TitlePane({title:"Add tag", + content:existingLogTag.innerHTML, + open:false}); + existingLogTag_pane_holder.appendChild(tp_existing.domNode); + dojo.destroy(existingLogTag); var form = dom.byId('tagForm'); + on(form, "submit", function(evt){ evt.stopPropagation(); evt.preventDefault(); - var n = domForm.fieldToObject("n"); - var tagName = domForm.fieldToObject("tagSelect"); + var n = domForm.fieldToObject("n"); + var tagName = domForm.fieldToObject("existingTagSelect"); + var tagDispName = domForm.fieldToObject("existingTagDispName"); var tagUrl = "{% url taglogentry object.graceid "000" "temp" %}" tagUrl = tagUrl.replace("000",n); tagUrl = tagUrl.replace("temp",tagName); - // The put request does not need any data in the body. - // XXX Unless we want to give a display name. - request.put(tagUrl).then( + request.post(tagUrl, { + data: {displayName: tagDispName} + }).then( function(text){ alert(text); // You may want to force the page to reload. @@ -203,8 +243,10 @@ }, function(error){alert(error);} ); + }); - + + {% endif %} }); @@ -359,6 +401,16 @@ {# panes are log messages #} {% if object.getAvailableTags %} <h3 id="logmessagetitle">Event Log Messages</h3> + <div id="newLogTag"> + <p> Use this form to apply a tag to your new log entry. Choose a tag + name from the dropdown menu or enter a new one. If you are + creating a new tag, please also provide a display name. </p> + <form> + Tag name <input id="newTagSelect" name="newTagSelect" /> + Display name <input type="text" id="newTagDispName" name="newTagDispName" /> + </form> + </div> + <div id="newLogTag_pane_holder" class="pmTitlePaneClass"></div> <div id="previewer"></div> <div id="editor"></div> {% endif %} @@ -455,12 +507,18 @@ {% if object.eventlog_set.count %} <!-- Branson. Here's where you should put the new form. --> {% if blessed_tags %} - <p>Apply a new tag: + <div id="existingLogTag"> + <p> Use this form to tag an existing log message. Choose a tag name from the + dropdown menu or enter a new one. If you are creating a new tag, please + also provide a display name. <form id="tagForm"> Log No. <input id="n" name="n" type="text" size="4" /> - Tag name <input id="tagSelect" name="tagSelect" /> + Tag name <input id="existingTagSelect" name="existingTagSelect" /> + Display name <input type="text" id="existingTagDispName" name="existingTagDispName"/> <input type="submit" name="submit" value="Submit" /> </p> </form> + </div> + <div id="existingLogTag_pane_holder" class="pmTitlePaneClass"></div> {% endif %} <table class="event"> -- GitLab