Skip to content

Commit

Permalink
remove material icons, add fontawsome pro, use cached icons
Browse files Browse the repository at this point in the history
  • Loading branch information
leifj committed Apr 17, 2018
1 parent 5a5fd41 commit 57ea601
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 76 deletions.
9 changes: 9 additions & 0 deletions src/pyff/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ class MetadataExpiredException(MetadataException):

class PyffException(Exception):
pass

class ResourceException(Exception):
def __init__(self, msg, wrapped=None, data=None):
self._wraped = wrapped
self._data = data
super(self.__class__, self).__init__(msg)

def raise_wraped(self):
raise self._wraped
29 changes: 3 additions & 26 deletions src/pyff/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,18 @@
from .logs import log
import os
import requests
from requests_file import FileAdapter
from .constants import config
from datetime import datetime
from collections import deque
from UserDict import DictMixin
from concurrent import futures
from .parse import parse_resource
from itertools import chain
from requests_cache.core import CachedSession
from copy import deepcopy
from .exceptions import ResourceException
from .utils import url_get

requests.packages.urllib3.disable_warnings()


class ResourceException(Exception):
def __init__(self, msg, wrapped=None, data=None):
self._wraped = wrapped
self._data = data
super(self.__class__, self).__init__(msg)

def raise_wraped(self):
raise self._wraped


class ResourceManager(DictMixin):
def __init__(self):
self._resources = dict()
Expand Down Expand Up @@ -180,18 +168,7 @@ def fetch(self, store=None):
data = self.url
info['Directory'] = self.url
elif '://' in self.url:
s = None
if 'file://' in self.url:
s = requests.session()
s.mount('file://', FileAdapter())
else:
s = CachedSession(cache_name="pyff_cache",
expire_after=config.request_cache_time,
old_data_on_error=True)

r = s.get(self.url, verify=False, timeout=config.request_timeout)
if config.request_override_encoding is not None:
r.encoding = config.request_override_encoding
r = url_get(self.url)

info['HTTP Response Headers'] = r.headers
log.debug("got status_code={:d}, encoding={} from_cache={} from {}".
Expand Down
42 changes: 27 additions & 15 deletions src/pyff/samlmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from .utils import parse_xml, check_signature, root, validate_document, xml_error, \
schema, iso2datetime, duration2timedelta, filter_lang, url2host, trunc_str, subdomains, \
has_tag, hash_id, load_callable, rreplace, dumptree, first_text
has_tag, hash_id, load_callable, rreplace, dumptree, first_text, url_get, img_to_data
from .logs import log
from .constants import config, NS, ATTRS, NF_URI, PLACEHOLDER_ICON
from lxml import etree
Expand All @@ -12,7 +12,6 @@
from copy import deepcopy
from .exceptions import *
from six import StringIO
from .parse import add_parser


class EntitySet(object):
Expand Down Expand Up @@ -427,8 +426,11 @@ def _u(an, values):

return d

def gen_icon(e):
scopes = entity_scopes(e)


def entity_icon(e, langs=None):
def entity_icon_url(e, langs=None):
for ico in filter_lang(e.iter("{%s}Logo" % NS['mdui']), langs=langs):
return dict(url=ico.text, width=ico.get('width'), height=ico.get('height'))

Expand Down Expand Up @@ -551,17 +553,33 @@ def discojson(e, langs=None):
elif 'sp' in eattr[ATTRS['role']]:
d['type'] = 'sp'

icon_info = entity_icon(e)
if icon_info is not None:
d['entity_icon'] = icon_info.get('url', PLACEHOLDER_ICON)
d['entity_icon_height'] = icon_info.get('height', 64)
d['entity_icon_width'] = icon_info.get('width', 64)

scopes = entity_scopes(e)
icon_info = entity_icon_url(e)
urls = []
if icon_info is not None and 'url' in icon_info:
url = icon_info['url']
urls.append(url)
if scopes is not None and len(scopes) == 1:
urls.append("https://{}/favico.ico".format(scopes[0]))
urls.append("https://www.{}/favico.ico".format(scopes[0]))

d['entity_icon'] = None
for url in urls:
if url.startswith("data:"):
d['entity_icon'] = url
break

if '://' in url:
r = url_get(url)
if r.ok and r.content:
d['entity_icon'] = img_to_data(r.content, r.headers.get('Content-Type'))
break

if scopes is not None and len(scopes) > 0:
d['scope'] = ",".join(scopes)
if len(scopes) == 1:
d['domain'] = scopes[0]
d['name_tag'] = (scopes[0].split('.'))[0].upper()

keywords = filter_lang(e.iter("{%s}Keywords" % NS['mdui']), langs=langs)
if keywords is not None:
Expand Down Expand Up @@ -594,12 +612,6 @@ def entity_simple_summary(e):
entityID=entity_id,
domains=";".join(sub_domains(e)),
id=hash_id(e, 'sha1'))
icon_info = entity_icon(e)
if icon_info is not None:
d['entity_icon'] = icon_info.get('url', PLACEHOLDER_ICON)
d['icon_url'] = d['entity_icon']
d['entity_icon_height'] = icon_info.get('height', 64)
d['entity_icon_width'] = icon_info.get('width', 64)

scopes = entity_scopes(e)
if scopes is not None and len(scopes) > 0:
Expand Down
40 changes: 27 additions & 13 deletions src/pyff/site/static/css/ra21.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ h2 img {
margin-right: 5px;
}

a.identityprovider {
display: inline-block;
vertical-align: middle;
height: 73px;
width: 100%;
}

a.identityprovider li svg {
display: inline-block;
vertical-align: middle;
}

a.identityprovider li span {
display: inline-block;
vertical-align: middle;
text-align: left;
padding-top: 8px;
}

.default-label {
color: #3B3B3B;
display: inline;
Expand Down Expand Up @@ -68,6 +87,10 @@ h2 img {
position: relative;
}

.card-container {
height: 100% !important;
}

.card-container.card {
padding: 40px 40px;
text-align: left;
Expand Down Expand Up @@ -106,13 +129,8 @@ h2 img {
}





/*-------------------------------------------------*/



.input-group {
margin: 3px 0 5px 0;
}
Expand Down Expand Up @@ -200,14 +218,6 @@ p {
color:#999999;
}




.material-icons.md-18 { font-size: 18px; }




.d-flex {
display:flex;
}
Expand Down Expand Up @@ -417,6 +427,10 @@ footer .step {
max-width: 30%;
}

.d-flex > i.cancel {
margin-left: auto;
}

.d-flex > span.searchaux {
max-width: 75%;
font-size: small;
Expand Down
12 changes: 7 additions & 5 deletions src/pyff/site/static/js/jquery-ds-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jQuery(function ($) {
obj.input_field_selector = obj.options['input_field_selector'] || obj.element.attr('data-inputfieldselector') || 'input';
obj.selection_selector = obj.options['selection_selector'];
obj._ds = new DiscoveryService(obj.mdq_url, obj.discovery_service_storage_url, obj.sp_entity_id);
obj._count = 0;
var top_element = obj.element;

$('img.pyff-idp-icon').bind('error', function () {
Expand All @@ -136,30 +137,31 @@ jQuery(function ($) {
e.preventDefault();
});

$('body').on('click', '.close', function (e) {
$('body').on('click', '.cancel', function (e) {
e.stopPropagation();
var entity_element = $(this).closest(obj.selection_selector);
var entity_id = entity_element.attr('data-href');
if (entity_id) {
obj._ds.remove(entity_id).then(function () {
entity_element.remove();
}).then(function() {
obj._update();
obj._count -= 1;
obj._after(obj._count)
});
}
});

obj._ds.choices().then(function (entities) {
return obj.options['before'](entities);
}).then(function (entities) {
var count = 0;
obj._count = 0;
var saved_choices_element = $(obj.options['saved_choices_selector']);
entities.forEach(function (item) {
var entity_element = obj.options['render_saved_choice'](item.entity);
saved_choices_element.prepend(entity_element);
count++;
obj._count++;
});
return count;
return obj._count;
}).then(function (count) {
obj._after(count);
})
Expand Down
43 changes: 27 additions & 16 deletions src/pyff/templates/ra21.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="https://getbootstrap.com/favicon.ico">
<link rel="icon" href="/favicon.ico">

<title>RA21-Initial</title>

<!-- Bootstrap core CSS -->
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>


<!-- Custom styles for this template -->
<link href="/static/css/ra21.css" rel="stylesheet">

<!--Google Material icons-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<!--Font awesome-->
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>

<link href="/static/css/ra21.css" rel="stylesheet"/>

<script type="text/javascript" src="/static/js/fontawesome-all.min.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
<script type="text/javascript" src="/static/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/static/js/popper.min.js"></script>
Expand Down Expand Up @@ -76,15 +69,15 @@ <h1>Choose Your Institution
<div class="collapse" id="addwidget">
<hr>
<a data-toggle="collapse" href="#searchwidget" role="button" aria-expanded="false" aria-controls="searchwidget">
<li><div class="d-flex flex-row"><span class="label">Choose another</span><i id="add_circle" class="material-icons">add_circle</i></div></li>
<li><div class="d-flex flex-row"><span class="label">Choose another</span><i id="add_circle" class="far fa-plus-circle"></i></div></li>
</a>
</div>
</ul>
<div class="collapse" id="searchwidget">
<div class="input-group" role="button">
<input type="text" id="searchinput" type="search" class="form-control" placeholder="" aria-label="input group" aria-describedby="btnGroupAddon" autofocus>
<div class="input-group-append">
<button type="button" id="findbutton" class="btn btn-primary" aria-describedby="btnGroupAddon"><i class="material-icons">search</i></button>
<button type="button" id="findbutton" class="btn btn-primary" aria-describedby="btnGroupAddon"><i class="fas fa-search"></i></button>
</div>
</div>
<p id="examples" class="detailtextRA21">Examples: Science Institute, xxx@YourInstitution.edu, UCLA</p>
Expand Down Expand Up @@ -181,21 +174,39 @@ <h3>4. Explore</h3>
$(document).ready(function() {

{% raw %}
var search = Hogan.compile('<a class="institution identityprovider" data-href="{{entity_id}}"><li><div class="d-flex flex-row"><span class="label">{{title}}</span>{{#scopes}}<span class="label-url">{{scopes}}</span>{{/scopes}}<div class="external"><i class="material-icons">open_in_new</i></div></div>{{#descr}}<div class="d-flex flex-row"><span class="searchaux">{{descr}}</span></div>{{/descr}}<div class="d-flex flex-row"><span class="searchmatch">Search matched&nbsp;<em>{{matched}}</em></span></div></li></a>');
var saved = Hogan.compile('<a class="identityprovider" data-href="{{entity_id}}"><li class="known-inst"><img{{#entity_icon}} src="{{entity_icon}}"{{/entity_icon}} onError="$(this).attr(\'src\',\'/static/icons/1x1t.png\');" class="img-thumbnail rounded-circle logo"><span class="label">{{title}} <i class="close material-icons">clear </i></span></li></a>');
var search = Hogan.compile('<a class="institution identityprovider" data-href="{{entity_id}}">\
<li><div class="d-flex flex-row">\
<span class="label">{{title}}</span>{{#scopes}}<span class="label-url">{{scopes}}</span>{{/scopes}}\
<div class="external"><i class="far fa-external-link"></i></div>\
</div>\
{{#descr}}<div class="d-flex flex-row"><span class="searchaux">{{descr}}</span></div>{{/descr}}\
<div class="d-flex flex-row">\
<span class="searchmatch">Search matched&nbsp;<em>{{matched}}</em></span>\
</div></li></a>');
var saved = Hogan.compile('<a class="identityprovider" data-href="{{entity_id}}">\
<li class="known-inst"><div class="d-flex flex-row">\
{{#entity_icon}}\
<img src="{{entity_icon}}" onError="$(this).attr(\'src\',\'/static/icons/1x1t.png\');" class="img-thumbnail rounded-circle logo">\
{{/entity_icon}}\
{{^entity_icon}}\
<svg class="logo" width="40" height="40"><circle cx="20" cy="20" r="20" fill="#aeaeae" />\
<text x="50%" y="50%" text-anchor="middle" fill="white" font-size="12px" font-family="Arial" dy=".3em">{{name_tag}}</text></svg>\
{{/entity_icon}}\
<span class="label">{{title}}</span><i class="cancel far fa-times-circle"></i>\
</div></li></a>');
var no_results = Hogan.compile('<div class="alert alert-info mt-3" role="alert"><h3>No matching institution found</h3><ul><li>Try institution name, your institution email, or an abbreviation</li><li>Contact your institution librarian</li></ul></div>');
{% endraw %}

$("#searchwidget").on('hidden.bs.collapse',function(event) {
$("#titlefind").hide();
$("#titlechoose").show();
$("#searchwidget").hide();
$("#add_circle").html("add_circle");
$("#add_circle").removeClass("fa-minus-circle").addClass("fa-plus-circle");
}).on('shown.bs.collapse',function(event) {
$("#titlefind").show();
$("#titlechoose").hide();
$("#searchwidget").show();
$("#add_circle").html("remove_circle");
$("#add_circle").removeClass("fa-plus-circle").addClass("fa-minus-circle");
$("#searchinput").focus();
});

Expand Down
Loading

0 comments on commit 57ea601

Please sign in to comment.