Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow marker selection by users #62

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions grambank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from pyramid.config import Configurator
from sqlalchemy.orm import joinedload

from clld.interfaces import (
IValue, IDomainElement, IMapMarker, IValueSet, ILinkAttrs, IContribution, ICtxFactoryQuery,
)
from clld.interfaces import IMapMarker, ILinkAttrs, IContribution, ICtxFactoryQuery
from clld.web.app import CtxFactoryQuery, menu_item
from clld_glottologfamily_plugin.util import LanguageByFamilyMapMarker
from clld.db.models import common
Expand All @@ -15,6 +13,7 @@
from grambank import models
from grambank import views
from grambank import datatables
from grambank.util import icon_from_req

_ = lambda s: s
_('Parameters')
Expand All @@ -25,21 +24,11 @@

class GrambankMapMarker(LanguageByFamilyMapMarker):
def __call__(self, ctx, req):
if IValue.providedBy(ctx): # pragma: no cover
icon = ctx.domainelement.jsondata['icon']
elif IValueSet.providedBy(ctx):
icon = ctx.values[0].domainelement.jsondata['icon']
elif IDomainElement.providedBy(ctx):
icon = ctx.jsondata['icon']
else:
icon = LanguageByFamilyMapMarker.get_icon(self, ctx, req)
icon = {
'cffffff': 'c0077bb',
'cff0000': 'ccc3311',
'c0000ff': 'c009988',
'cffff00': 'cee7733',
}.get(icon, icon)
return svg.data_url(svg.icon(icon, opacity=0.8))
icon = icon_from_req(ctx, req)
if icon:
return icon.url(req)
return svg.data_url(
svg.icon(LanguageByFamilyMapMarker.get_icon(self, ctx, req), opacity='0.7'))


class GrambankCtxFactoryQuery(CtxFactoryQuery):
Expand Down
3 changes: 0 additions & 3 deletions grambank/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def get_layers(self):
),
marker=helpers.map_marker_img(self.req, de, marker=self.map_marker))

#def get_default_options(self):
# return {'hash': True, 'icon_size': 15, 'base_layer': "Esri.WorldPhysical"}


def includeme(config):
config.register_map('parameter', FeatureMap)
2 changes: 1 addition & 1 deletion grambank/static/project.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ a:hover {
background-image: none;
}

img.leaflet-marker-icon {opacity: 0.5;}
/*img.leaflet-marker-icon {opacity: 0.5;}*/
14 changes: 7 additions & 7 deletions grambank/templates/combination/detail_html.mako
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<%inherit file="../${context.get('request').registry.settings.get('clld.app_template', 'app.mako')}"/>
<%namespace name="util" file="../util.mako"/>
<%! active_menu_item = "parameters" %>
<% from clld.web.icon import Icon %>

<%block name="title">F-Dependency ${'&#8594;'.join(p.id for p in ctx.parameters)|n}</%block>
<%block name="head">
${util.head_coloris()|n}
</%block>

<h3>${_('F-Dependency')} ${' &#8594; '.join(h.link(request, p) for p in ctx.parameters)|n}</h3>

Expand Down Expand Up @@ -30,13 +35,8 @@
</td>
<td>
% if item[1].languages:
% if iconselect:
<%self:iconselect id="iconselect${str(item[0])}" param="v${str(item[0])}" placement="right" tag="span">
<img height="20" width="20" src="${item[1].icon.url(request)}"/>
</%self:iconselect>
% else:
<img height="20" width="20" src="${item[1].icon.url(request)}"/>
% endif
${util.coloris_icon_picker(Icon.from_req(item[1], req))|n}
${util.parameter_map_reloader([Icon.from_req(de, req) for de in ctx.domain])|n}
% endif
</td>
<td>
Expand Down
22 changes: 22 additions & 0 deletions grambank/templates/parameter/detail_html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<%block name="head">
<link href="${request.static_url('clld:web/static/css/select2.css')}" rel="stylesheet">
<script src="${request.static_url('clld:web/static/js/select2.js')}"></script>
${util.head_coloris()|n}
</%block>


Expand Down Expand Up @@ -79,10 +80,31 @@ ${u.process_markdown(ctx.description, req)|n}
</form>
</div>


<div class="alert alert-info" style="float: right">
<button type="button" class="close" data-dismiss="alert">&times;</button>
Customize map markers:
<table class="table-condensed">
<tbody>
% for de in ctx.domain:
<tr>
<td>${util.coloris_icon_picker(u.icon_from_req(de, req))|n}</td>
<td>${de.name}</td>
<td>${de.description}</td>
</tr>
% endfor
</tbody>
</table>
${util.parameter_map_reloader([u.icon_from_req(de, req) for de in ctx.domain])}
</div>

<h3 id="map-container">
Map
<a href="#top" title="go to top of the page" style="vertical-align: bottom">&#x21eb;</a>
</h3>

<br style="clear: both">

${request.map.render()}

<h3 id="table-container">
Expand Down
13 changes: 13 additions & 0 deletions grambank/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from clld_glottologfamily_plugin.models import Family
from clld.web.util.multiselect import CombinationMultiSelect
from clld.web.icon import Icon
from clld.web.util import glottolog # used in templates!
from clld_phylogeny_plugin.models import Phylogeny
from clldutils.misc import slug
Expand All @@ -35,6 +36,18 @@
assert markdown


def icon_from_req(ctx, req):
return Icon.from_req(
ctx,
req,
icon_map={
'cffffff': 'c0077bb',
'cff0000': 'ccc3311',
'c0000ff': 'c009988',
'cffff00': 'cee7733',
})


def process_markdown(text, req, section=None):
from markdown import markdown

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
zip_safe=False,
install_requires=[
'cldfcatalog',
'clld>=9.2.1',
'clld>=11.0.1',
'clldmpg>=4.2',
'clld-glottologfamily-plugin>=4',
'clld-phylogeny-plugin>=1.5',
Expand Down