From 76beb0cdcddde173ffe5fe07abe7873f267486eb Mon Sep 17 00:00:00 2001 From: Jose Gonzalez-Brenes Date: Thu, 25 Aug 2016 18:31:16 -0700 Subject: [PATCH] Added support to move to the next unannotated document --- CONTRIBUTORS.md | 1 + client/src/visualizer_ui.js | 25 +++++++++++++++++++++++++ index.xhtml | 4 +++- server/src/dispatch.py | 3 ++- server/src/document.py | 26 ++++++++++++++++++++++++++ static/img/fast_forward.png | Bin 0 -> 387 bytes 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 static/img/fast_forward.png diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 16d249cf8..b898c8142 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -16,6 +16,7 @@ In order by changed lines of code ([Ballmer][ballmer] says [SLOC][sloc] * David McClosky <david.mcclosky gmail com> * Antony Scerri <a.scerri elsevier com> * Jon Crump <jjcrump uw edu> +* Jose Gonzalez-Brenes <jgonzalez chegg com> Extracted using the following bash one-liner: diff --git a/client/src/visualizer_ui.js b/client/src/visualizer_ui.js index 24ebf888b..add383163 100644 --- a/client/src/visualizer_ui.js +++ b/client/src/visualizer_ui.js @@ -1530,6 +1530,26 @@ var VisualizerUI = (function($, window, undefined) { } }; + var refreshAndMove = function(response) { + dispatcher.post('setDocument', [selectorData.items[response.new_pos][2], + selectorData.items[response.new_pos][1]]); + return false; + + } + + var nextUnannotated = function(dir) { + var pos = currentSelectorPosition(); + // Request the server to reload collection: + console.log(selectorData.items) + dispatcher.post('ajax', + [{ action: 'get_next_unnanotated', collection: selectorData.collection, start: pos }, + 'refreshAndMove', + {collection: selectorData.collection, keep: true}]); + + + return false; + }; + var moveInFileBrowser = function(dir) { var pos = currentSelectorPosition(); var newPos = pos + dir; @@ -2264,6 +2284,10 @@ var VisualizerUI = (function($, window, undefined) { $('#type_collapse_limit')[0].value = Configuration.typeCollapseLimit; } + $('#fast_forward').button().click(function() { + return nextUnannotated(); + }); + $('#prev').button().click(function() { return moveInFileBrowser(-1); }); @@ -2307,6 +2331,7 @@ var VisualizerUI = (function($, window, undefined) { on('initForm', initForm). on('collectionLoaded', rememberNormDb). on('collectionLoaded', collectionLoaded). + on('refreshAndMove', refreshAndMove). on('spanAndAttributeTypesLoaded', spanAndAttributeTypesLoaded). on('isReloadOkay', isReloadOkay). on('current', gotCurrent). diff --git a/index.xhtml b/index.xhtml index 933e271cf..28abede85 100644 --- a/index.xhtml +++ b/index.xhtml @@ -111,7 +111,9 @@
- Previous document (Cursor Left)Next document (Cursor Right) + Previous document (Cursor Left) + Next document (Cursor Right) + Next document without annotation
diff --git a/server/src/dispatch.py b/server/src/dispatch.py index a849514e8..8ea460078 100644 --- a/server/src/dispatch.py +++ b/server/src/dispatch.py @@ -20,7 +20,7 @@ from config import DATA_DIR from convert.convert import convert from docimport import save_import -from document import (get_directory_information, get_document, +from document import (get_directory_information,get_next_unnanotated, get_document, get_document_timestamp, get_configuration) from download import download_file, download_collection from inspect import getargspec @@ -47,6 +47,7 @@ def logging_no_op(collection, document, log): # Function call-backs DISPATCHER = { 'getCollectionInformation': get_directory_information, + 'get_next_unnanotated': get_next_unnanotated, 'getDocument': get_document, 'getDocumentTimestamp': get_document_timestamp, 'importDocument': save_import, diff --git a/server/src/document.py b/server/src/document.py index 2f430983a..4831ec335 100644 --- a/server/src/document.py +++ b/server/src/document.py @@ -505,6 +505,32 @@ def _inject_annotation_type_conf(dir_path, json_dic=None): return json_dic +def get_next_unnanotated(collection, start): + directory = collection + start = int(start) + new_pos = start + real_dir = real_directory(directory) + + assert_allowed_to_read(real_dir) + + # Get the document names + base_names = [fn[0:-4] for fn in _listdir(real_dir) + if fn.endswith('txt')] + + try: + stats_types, doc_stats = get_statistics(real_dir, base_names) + except OSError: + # something like missing access permissions? + raise CollectionNotAccessibleError + + if start < len(doc_stats): + for i in range(start, len(doc_stats)): # Have to account for "." , ".." + if sum(doc_stats[i]) == 0: + new_pos = i + 1 + break + return {"new_pos": new_pos} + + # TODO: This is not the prettiest of functions def get_directory_information(collection): directory = collection diff --git a/static/img/fast_forward.png b/static/img/fast_forward.png new file mode 100644 index 0000000000000000000000000000000000000000..503f684d706a3cd08ec2211a0784a1c4f82b69f6 GIT binary patch literal 387 zcmV-}0et?6P)Nkl}N5!_ymFVjK^m{*lNb(7;Jokzt{Nz z{`o)U!N30?wqeipd&qpFuB-SB(QUhUrt$2L|3&-0{O`T_=f7_2g|A7QUn2NGd7ah^ zxDD}|fA4?6o=^WXw!8=9=JP-Pn|5FPAF$vdoUdMY;*5IjaqNcZww(U&GVStz$H^DK z7{t!l@#4Qm^$`@lQt5#+SPjrEr*J^B#h+@7CA<6)Fz?SLwL~=S%1AI3ts@ z9lHypvbTLz-TM7M-|Dabjdp$iFP66Pul$U=aK32jhBIPm>u`sGP}17hLOcKem)rCI zKY!fHGlGe$KcVpBR^pEZuJDCtBzFD(52Crl7RI3S38n+qz&U3?m@Qy-3^qPNz~no9 hCbQqP7+n0p2LRQb1Wtb2F+l(T002ovPDHLkV1fpk&LaQ- literal 0 HcmV?d00001