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

Behaviors #2

Merged
merged 12 commits into from
Mar 8, 2024
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
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ Changelog
1.0a5 (unreleased)
------------------

- Nothing changed yet.
- Refactor : collective.plausible is now based on a behavior
[remdub]

- Add viewlet to insert plausible tracking code in the page
[remdub]

- Refactor : server healthcheck is now a separate view @@plausible-healthcheck
[remdub]

1.0a4 (2024-02-22)
------------------
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Contributors

- Rémi Dubois, [email protected]
- Christophe Boulanger, [email protected]
- Benoît Suttor, [email protected]
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ Plausible integration into Plone 5 and Plone 6 classic UI
Features
--------

- Behavior to set plausible fields on content types
- Viewlet to include plausible tracking code in the page
- Statistics browserview @@plausible-view
- Optional link to statistics browserview in user menu
- Plausible server healthcheck in control panel
- Plausible server healthcheck browserview @@plausible-healthcheck
- Optional link to the browserviews in object menu



Expand Down Expand Up @@ -81,6 +83,7 @@ Contributors

- Rémi Dubois <[email protected]>
- Christophe Boulanger <[email protected]>
- Benoît Suttor <[email protected]>


Contribute
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions src/collective/plausible/behaviors/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone">

<include package="plone.behavior" file="meta.zcml"/>

<!-- -*- extra stuff goes here -*- -->

<plone:behavior
name="collective.plausible.plausible_fields"
title="PlausibleFields"
description="This behaviors adds Plausible fields on a content type"
provides=".plausible_fields.IPlausibleFields"
factory=".plausible_fields.PlausibleFields"
marker=".plausible_fields.IPlausibleFieldsMarker"
/>


</configure>
133 changes: 133 additions & 0 deletions src/collective/plausible/behaviors/plausible_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-

from collective.plausible import _
from plone import schema
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import directives
from plone.supermodel import model
from Products.CMFPlone.utils import safe_hasattr
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
from zope.interface import provider


class IPlausibleFieldsMarker(Interface):
pass


@provider(IFormFieldProvider)
class IPlausibleFields(model.Schema):
""" """

directives.fieldset(
"plausible_fields",
label=_("Plausible fields"),
description=_("Plausible analytics fields"),
fields=[
"plausible_enabled",
"plausible_url",
"plausible_site",
"plausible_token",
"plausible_link_object_action",
],
)

plausible_enabled = schema.Bool(
title=_("Enable Plausible"),
description=_(
"Enable Plausible analytics tracking on this content and all its children."
),
default=False,
required=False,
readonly=False,
)

plausible_url = schema.TextLine(
title=_("Plausible URL"),
description=_("Example : plausible.imio.be"),
default="",
required=False,
readonly=False,
)

plausible_site = schema.TextLine(
title=_("Plausible Site"),
description=_("Example : imio.be"),
default="",
required=False,
readonly=False,
)

plausible_token = schema.TextLine(
title=_("Plausible token"),
description=_("Plausible authentification token"),
default="",
required=False,
readonly=False,
)

plausible_link_object_action = schema.Bool(
title=_("Add a link in the object menu"),
description=_("Add a link to the statistics browser view in the object menu"),
default=False,
required=False,
readonly=False,
)


@implementer(IPlausibleFields)
@adapter(IPlausibleFieldsMarker)
class PlausibleFields(object): # pragma: no cover
def __init__(self, context):
self.context = context

@property
def plausible_enabled(self):
if safe_hasattr(self.context, "plausible_enabled"):
return self.context.plausible_enabled
return None

@plausible_enabled.setter
def plausible_enabled(self, value):
self.context.plausible_enabled = value

@property
def plausible_url(self):
if safe_hasattr(self.context, "plausible_url"):
return self.context.plausible_url
return None

@plausible_url.setter
def plausible_url(self, value):
self.context.plausible_url = value

@property
def plausible_site(self):
if safe_hasattr(self.context, "plausible_site"):
return self.context.plausible_site
return None

@plausible_site.setter
def plausible_site(self, value):
self.context.plausible_site = value

@property
def plausible_token(self):
if safe_hasattr(self.context, "plausible_token"):
return self.context.plausible_token
return None

@plausible_token.setter
def plausible_token(self, value):
self.context.plausible_token = value

@property
def plausible_link_object_action(self):
if safe_hasattr(self.context, "plausible_link_object_action"):
return self.context.plausible_link_object_action
return None

@plausible_link_object_action.setter
def plausible_link_object_action(self, value):
self.context.plausible_link_object_action = value
13 changes: 10 additions & 3 deletions src/collective/plausible/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
post_handler=".setuphandlers.post_install"
/>

<genericsetup:registerProfile
name="testing"
title="collective.plausible (testing)"
directory="profiles/testing"
description="Installs the collective.plausible.testing profile."
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="uninstall"
title="collective.plausible (uninstall)"
Expand All @@ -42,11 +50,10 @@

<!-- -*- extra stuff goes here -*- -->

<include package=".viewlets" />
<include package=".behaviors" />
<include package=".upgrades" />

<include package=".controlpanels" />


<include package=".views" />

</configure>
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,16 @@
</div>

<div id="content-core">
<div class="card" tal:condition="here/@@plausible-utils/is_plausible_set">
<div class="card-header">
<span i18n:domain="collective.plausible" i18n:translate="">Configuration state</span>
</div>
<div class="card-body portalMessage warning" role="status" >
<span i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are set (here or environment variables)</span>
</div>
<div class="card-header">
<span i18n:domain="collective.plausible" i18n:translate="">Plausible server healthcheck</span>
</div>
<div class="card-body portalMessage warning" role="status">
<ul tal:condition="here/@@plausible-utils/get_plausible_instance_healthcheck">
<li><span i18n:domain="collective.plausible" i18n:translate="">Clickhouse :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
<li><span i18n:domain="collective.plausible" i18n:translate="">Postgresql :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
<li><span i18n:domain="collective.plausible" i18n:translate="">Sites cache :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
</ul>
<span i18n:domain="collective.plausible" i18n:translate="" tal:condition="not: here/@@plausible-utils/get_plausible_instance_healthcheck">Error while trying to connect to Plausible API</span>
</div>
<div class="card">
<h2 i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are defined on content properties</h2>
</div>
<div class="card" tal:condition="not: here/@@plausible-utils/is_plausible_set">
<div class="card-header">
<span i18n:domain="collective.plausible" i18n:translate="">Configuration state</span>
</div>
<div class="card-body portalMessage warning" role="status" >
<span i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are not set yet. You can define it here or via environment variables.</span>
</div>
<!-- <div class="card">
<div class="card-header">
</div>
<div class="card">
<div class="card-header">
<span>Paramètres de Plausible</span>
</div>
<div id="layout-contents">
<span tal:replace="structure view/contents" />
</div>
<div id="layout-contents">
<span tal:replace="structure view/contents" />
</div>
</div> -->
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,7 @@


class IPlausibleControlPanel(Interface):
url = schema.TextLine(
title=_("Plausible URL"),
description=_("Example : plausible.imio.be"),
default="",
required=False,
readonly=False,
)

site = schema.TextLine(
title=_("Plausible Site"),
description=_("Example : imio.be"),
default="",
required=False,
readonly=False,
)

token = schema.TextLine(
title=_("Plausible token"),
description=_("Plausible authentification token"),
default="",
required=False,
readonly=False,
)

link_user_action = schema.Bool(
title=_("Add a link in the user menu"),
description=_("Add a link to the statistics browser view in the user menu"),
default=True,
required=False,
readonly=False,
)
pass


class PlausibleControlPanel(RegistryEditForm):
Expand Down
Loading
Loading