Skip to content

Commit

Permalink
NON-DUPLICATE Link + proper display of html in IIIF metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
SeguinBe committed Jan 4, 2018
1 parent 663483b commit 1417a7f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ The import script takes two additional parameters in order to specify which IIIF

```
bin/neo4j stop
bin/neo4j-admin dump --to=/mnt/cluster-nas/benoit/neo4j_backups/2017_12_08.dump
bin/neo4j-admin dump --to=/mnt/cluster-nas/benoit/neo4j_backups/2018_01_04.dump
bin/neo4j start
```
38 changes: 26 additions & 12 deletions replica_core/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class VisualLink(StructuredNode, BaseElement):
class Type:
PROPOSAL = 'PROPOSAL'
DUPLICATE = 'DUPLICATE'
NONDUPLICATE = 'NON-DUPLICATE'
POSITIVE = 'POSITIVE'
NEGATIVE = 'NEGATIVE'
UNDEFINED = 'UNDEFINED'
VALID_TYPES = [DUPLICATE, POSITIVE, NEGATIVE, UNDEFINED]
VALID_TYPES = [DUPLICATE, NONDUPLICATE, POSITIVE, NEGATIVE, UNDEFINED]
ALL_TYPES = VALID_TYPES + [PROPOSAL]

# User that proposed or created the link
Expand All @@ -33,17 +34,6 @@ class Type:

images = RelationshipTo('.iiif.Image', 'LINKS')

@classmethod
def get_from_images(cls, img1_uid: str, img2_uid: str, user=None) -> Union[None, 'VisualLink']:
results, _ = db.cypher_query('''MATCH (i2:Image)<-[:LINKS]-(l:'''+str(cls.__name__)+''')-[:LINKS]->(i1:Image)
WHERE i1.uid={img1} and i2.uid={img2}
RETURN l''',
dict(img1=img1_uid, img2=img2_uid))
if len(results) > 0:
return cls.inflate(results[0][0])
else:
return None

def annotate(self, user: 'User', link_type: 'Type'):
if link_type not in VisualLink.Type.VALID_TYPES:
raise ValueError('Type is invalid : {}'.format(link_type))
Expand All @@ -65,6 +55,30 @@ def remove_annotation(self, user=None):
self.save()
self.annotator.disconnect(old_annotator)

def plot(self):
from IPython.core.display import display, HTML
html_code = """
<span>Type : {} <br>
Creator : {} <br>
Annotator : {}</span>
<div style="float:left;">
<img style="display:inline-block;" src="{}/full/300,/0/default.jpg",width=300/>
<img style="display:inline-block;" src="{}/full/300,/0/default.jpg",width=300/>
</div>
""".format(self.type, self.creator.get().username, self.annotator.get_or_none(), *(img.iiif_url for img in self.images))
display(HTML(html_code))

@classmethod
def get_from_images(cls, img1_uid: str, img2_uid: str, user=None) -> Union[None, 'VisualLink']:
results, _ = db.cypher_query('''MATCH (i2:Image)<-[:LINKS]-(l:'''+str(cls.__name__)+''')-[:LINKS]->(i1:Image)
WHERE i1.uid={img1} and i2.uid={img2}
RETURN l''',
dict(img1=img1_uid, img2=img2_uid))
if len(results) > 0:
return cls.inflate(results[0][0])
else:
return None

@classmethod
def create_proposal(cls, img1: Image, img2: Image, user: 'User', exist_ok=True):
if not (img1 and img2):
Expand Down
2 changes: 1 addition & 1 deletion static/dialog/image_dialog.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3 ng-if="element.links.length>0">Linked with</h3>
<md-list>
<md-list-item ng-repeat="m in element.cho.raw_metadata">
<p> {{ m.label }} </p>
<div class="text-right">{{ m.value }}</div>
<div class="text-right"><div ng-bind-html="renderHtml(m.value)"></div></div>
</md-list-item>
</md-list>
</md-card>
Expand Down
7 changes: 5 additions & 2 deletions static/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ replicaModule.controller('mainController', function ($scope, $http, $mdDialog, $
multiple: true
});

function DialogController($scope, $mdDialog, locals, rootScope) {
function DialogController($scope, $mdDialog, $sce, locals, rootScope) {
$scope.getImage = function (e) {
if (e != undefined)
return e.iiif_url + "/full/!1000,1000/0/default.jpg";
else
return "";
};
$scope.renderHtml = function (htmlCode) {
return $sce.trustAsHtml(htmlCode);
};
$scope.locals = locals;
$scope.element = null;
$scope.showImageDialog = rootScope.showImageDialog;
Expand Down Expand Up @@ -308,7 +311,7 @@ replicaModule.controller('proposalsListController', function ($scope, $http, $md
'</md-dialog>',
locals: { rootScope: $scope },
controller: function ($mdDialog, $scope, rootScope) {
$scope.POSSIBLE_TYPES = ['DUPLICATE', 'POSITIVE', 'NEGATIVE'];
$scope.POSSIBLE_TYPES = ['DUPLICATE', 'NON-DUPLICATE', 'POSITIVE', 'NEGATIVE'];
$scope.link = {
img1: rootScope.proposalsList[i].images[0],
img2: rootScope.proposalsList[i].images[1]
Expand Down
3 changes: 3 additions & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from core_server import app
from werkzeug.contrib.fixers import ProxyFix

if __name__ == "__main__":
# For proper https forwarding? (see https://github.com/noirbizarre/flask-restplus/issues/54)
app.wsgi_app = ProxyFix(app.wsgi_app)
app.run()

0 comments on commit 1417a7f

Please sign in to comment.