fix: add setting to toggle "farmOS-style grid links"
not sure yet if users prefer farmOS style, but will assume so by default just to be safe. but i want the "traditional" behavior myself, so setting is needed either way
This commit is contained in:
parent
1af2b695dc
commit
e5e3d38365
8 changed files with 85 additions and 22 deletions
|
|
@ -7,6 +7,13 @@
|
|||
<h3 class="block is-size-3">farmOS</h3>
|
||||
<div class="block" style="padding-left: 2rem; width: 50%;">
|
||||
|
||||
<b-field label="farmOS URL">
|
||||
<b-input name="farmos.url.base"
|
||||
v-model="simpleSettings['farmos.url.base']"
|
||||
@input="settingsNeedSaved = true">
|
||||
</b-input>
|
||||
</b-field>
|
||||
|
||||
<b-field label="farmOS Integration Mode">
|
||||
<b-select name="${app.appname}.farmos_integration_mode"
|
||||
v-model="simpleSettings['${app.appname}.farmos_integration_mode']"
|
||||
|
|
@ -17,12 +24,26 @@
|
|||
</b-select>
|
||||
</b-field>
|
||||
|
||||
<b-field label="farmOS URL">
|
||||
<b-input name="farmos.url.base"
|
||||
v-model="simpleSettings['farmos.url.base']"
|
||||
@input="settingsNeedSaved = true">
|
||||
</b-input>
|
||||
</b-field>
|
||||
<b-checkbox name="${app.appname}.farmos_style_grid_links"
|
||||
v-model="simpleSettings['${app.appname}.farmos_style_grid_links']"
|
||||
native-value="true"
|
||||
@input="settingsNeedSaved = true">
|
||||
Use farmOS-style grid links
|
||||
</b-checkbox>
|
||||
<${b}-tooltip position="${'right' if request.use_oruga else 'is-right'}">
|
||||
<b-icon pack="fas" icon="info-circle" />
|
||||
<template #content>
|
||||
<p class="block">
|
||||
If set, certain column values in a grid may link
|
||||
to <span class="has-text-weight-bold">related</span>
|
||||
records.
|
||||
</p>
|
||||
<p class="block">
|
||||
If not set, column values will only link to view the
|
||||
<span class="has-text-weight-bold">current</span> record.
|
||||
</p>
|
||||
</template>
|
||||
</${b}-tooltip>
|
||||
|
||||
</div>
|
||||
</%def>
|
||||
|
|
|
|||
|
|
@ -38,3 +38,7 @@ def save_farmos_oauth2_token(request, token):
|
|||
|
||||
# save token to user session
|
||||
request.session["farmos.oauth2.token"] = token
|
||||
|
||||
|
||||
def use_farmos_style_grid_links(config):
|
||||
return config.get_bool(f"{config.appname}.farmos_style_grid_links", default=True)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
Master view for Animals
|
||||
"""
|
||||
|
||||
from webhelpers2.html import tags
|
||||
|
||||
from wuttaweb.forms.schema import WuttaDictEnum
|
||||
|
||||
from wuttafarm.db.model import AnimalType, AnimalAsset
|
||||
|
|
@ -189,6 +191,10 @@ class AnimalAssetView(AssetMasterView):
|
|||
g.set_joiner("animal_type", lambda q: q.join(model.AnimalType))
|
||||
g.set_sorter("animal_type", model.AnimalType.name)
|
||||
g.set_filter("animal_type", model.AnimalType.name)
|
||||
if self.farmos_style_grid_links:
|
||||
g.set_renderer("animal_type", self.render_animal_type_for_grid)
|
||||
else:
|
||||
g.set_link("animal_type")
|
||||
|
||||
# birthdate
|
||||
g.set_renderer("birthdate", "date")
|
||||
|
|
@ -196,6 +202,10 @@ class AnimalAssetView(AssetMasterView):
|
|||
# sex
|
||||
g.set_enum("sex", enum.ANIMAL_SEX)
|
||||
|
||||
def render_animal_type_for_grid(self, animal, field, value):
|
||||
url = self.request.route_url("animal_types.view", uuid=animal.animal_type_uuid)
|
||||
return tags.link_to(value, url)
|
||||
|
||||
def configure_form(self, form):
|
||||
f = form
|
||||
super().configure_form(f)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,10 @@ class AnimalView(AssetMasterView):
|
|||
g.set_filter("produces_eggs", NullableBooleanFilter)
|
||||
|
||||
# animal_type_name
|
||||
g.set_renderer("animal_type_name", self.render_animal_type_for_grid)
|
||||
if self.farmos_style_grid_links:
|
||||
g.set_renderer("animal_type_name", self.render_animal_type_for_grid)
|
||||
else:
|
||||
g.set_link("animal_type_name")
|
||||
g.set_sorter("animal_type_name", SimpleSorter("animal_type.name"))
|
||||
g.set_filter("animal_type_name", StringFilter, path="animal_type.name")
|
||||
|
||||
|
|
@ -137,11 +140,16 @@ class AnimalView(AssetMasterView):
|
|||
return tags.link_to(value, url)
|
||||
|
||||
def render_groups_for_grid(self, animal, field, value):
|
||||
links = []
|
||||
groups = []
|
||||
for group in animal["group_objects"]:
|
||||
url = self.request.route_url("farmos_group_assets.view", uuid=group["uuid"])
|
||||
links.append(tags.link_to(group["name"], url))
|
||||
return ", ".join(links)
|
||||
if self.farmos_style_grid_links:
|
||||
url = self.request.route_url(
|
||||
"farmos_group_assets.view", uuid=group["uuid"]
|
||||
)
|
||||
groups.append(tags.link_to(group["name"], url))
|
||||
else:
|
||||
groups.append(group["name"])
|
||||
return ", ".join(groups)
|
||||
|
||||
def get_instance(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -104,20 +104,26 @@ class AssetMasterView(FarmOSMasterView):
|
|||
g.set_filter("archived", BooleanFilter)
|
||||
|
||||
def render_owners_for_grid(self, asset, field, value):
|
||||
links = []
|
||||
owners = []
|
||||
for user in value:
|
||||
url = self.request.route_url("farmos_users.view", uuid=user["uuid"])
|
||||
links.append(tags.link_to(user["name"], url))
|
||||
return ", ".join(links)
|
||||
if self.farmos_style_grid_links:
|
||||
url = self.request.route_url("farmos_users.view", uuid=user["uuid"])
|
||||
owners.append(tags.link_to(user["name"], url))
|
||||
else:
|
||||
owners.append(user["name"])
|
||||
return ", ".join(owners)
|
||||
|
||||
def render_locations_for_grid(self, asset, field, value):
|
||||
links = []
|
||||
locations = []
|
||||
for location in value:
|
||||
asset_type = location["type"].split("--")[1]
|
||||
route = f"farmos_{asset_type}_assets.view"
|
||||
url = self.request.route_url(route, uuid=location["uuid"])
|
||||
links.append(tags.link_to(location["name"], url))
|
||||
return ", ".join(links)
|
||||
if self.farmos_style_grid_links:
|
||||
asset_type = location["type"].split("--")[1]
|
||||
route = f"farmos_{asset_type}_assets.view"
|
||||
url = self.request.route_url(route, uuid=location["uuid"])
|
||||
locations.append(tags.link_to(location["name"], url))
|
||||
else:
|
||||
locations.append(location["name"])
|
||||
return ", ".join(locations)
|
||||
|
||||
def grid_row_class(self, asset, data, i):
|
||||
""" """
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import markdown
|
|||
from wuttaweb.views import MasterView
|
||||
from wuttaweb.forms.schema import WuttaDateTime
|
||||
|
||||
from wuttafarm.web.util import save_farmos_oauth2_token
|
||||
from wuttafarm.web.util import save_farmos_oauth2_token, use_farmos_style_grid_links
|
||||
from wuttafarm.web.grids import ResourceData, StringFilter, SimpleSorter
|
||||
|
||||
|
||||
|
|
@ -65,6 +65,7 @@ class FarmOSMasterView(MasterView):
|
|||
self.farmos_client = self.get_farmos_client()
|
||||
self.farmos_4x = self.app.is_farmos_4x(self.farmos_client)
|
||||
self.raw_json = None
|
||||
self.farmos_style_grid_links = use_farmos_style_grid_links(self.config)
|
||||
|
||||
def get_farmos_client(self):
|
||||
token = self.request.session.get("farmos.oauth2.token")
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ from webhelpers2.html import tags
|
|||
|
||||
from wuttaweb.views import MasterView
|
||||
|
||||
from wuttafarm.web.util import use_farmos_style_grid_links
|
||||
|
||||
|
||||
class WuttaFarmMasterView(MasterView):
|
||||
"""
|
||||
|
|
@ -49,6 +51,10 @@ class WuttaFarmMasterView(MasterView):
|
|||
"thumbnail_url": "Thumbnail URL",
|
||||
}
|
||||
|
||||
def __init__(self, request, context=None):
|
||||
super().__init__(request, context=context)
|
||||
self.farmos_style_grid_links = use_farmos_style_grid_links(self.config)
|
||||
|
||||
def get_farmos_url(self, obj):
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ from webhelpers2.html import tags
|
|||
|
||||
from wuttaweb.views import settings as base
|
||||
|
||||
from wuttafarm.web.util import use_farmos_style_grid_links
|
||||
|
||||
|
||||
class AppInfoView(base.AppInfoView):
|
||||
"""
|
||||
|
|
@ -63,6 +65,11 @@ class AppInfoView(base.AppInfoView):
|
|||
"name": f"{self.app.appname}.farmos_integration_mode",
|
||||
"default": self.app.get_farmos_integration_mode(),
|
||||
},
|
||||
{
|
||||
"name": f"{self.app.appname}.farmos_style_grid_links",
|
||||
"type": bool,
|
||||
"default": use_farmos_style_grid_links(self.config),
|
||||
},
|
||||
]
|
||||
)
|
||||
return simple_settings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue