Skip to content

Commit 6b79891

Browse files
remdubbsuttor
andauthored
feat: behavior, viewlet
--------- Co-authored-by: Benoit Suttor <[email protected]>
1 parent 671d093 commit 6b79891

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1213
-442
lines changed

CHANGES.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ Changelog
55
1.0a5 (unreleased)
66
------------------
77

8-
- Nothing changed yet.
8+
- Refactor : collective.plausible is now based on a behavior
9+
[remdub]
10+
11+
- Add viewlet to insert plausible tracking code in the page
12+
[remdub]
913

14+
- Refactor : server healthcheck is now a separate view @@plausible-healthcheck
15+
[remdub]
1016

1117
1.0a4 (2024-02-22)
1218
------------------

CONTRIBUTORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Contributors
33

44
- Rémi Dubois, [email protected]
55
- Christophe Boulanger, [email protected]
6+
- Benoît Suttor, [email protected]

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ Plausible integration into Plone 5 and Plone 6 classic UI
3232
Features
3333
--------
3434

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

3941

4042

@@ -81,6 +83,7 @@ Contributors
8183

8284
- Rémi Dubois <[email protected]>
8385
- Christophe Boulanger <[email protected]>
86+
- Benoît Suttor <[email protected]>
8487

8588

8689
Contribute

src/collective/plausible/behaviors/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<configure
2+
xmlns="http://namespaces.zope.org/zope"
3+
xmlns:browser="http://namespaces.zope.org/browser"
4+
xmlns:plone="http://namespaces.plone.org/plone"
5+
xmlns:zcml="http://namespaces.zope.org/zcml"
6+
i18n_domain="plone">
7+
8+
<include package="plone.behavior" file="meta.zcml"/>
9+
10+
<!-- -*- extra stuff goes here -*- -->
11+
12+
<plone:behavior
13+
name="collective.plausible.plausible_fields"
14+
title="PlausibleFields"
15+
description="This behaviors adds Plausible fields on a content type"
16+
provides=".plausible_fields.IPlausibleFields"
17+
factory=".plausible_fields.PlausibleFields"
18+
marker=".plausible_fields.IPlausibleFieldsMarker"
19+
/>
20+
21+
22+
</configure>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from collective.plausible import _
4+
from plone import schema
5+
from plone.autoform.interfaces import IFormFieldProvider
6+
from plone.supermodel import directives
7+
from plone.supermodel import model
8+
from Products.CMFPlone.utils import safe_hasattr
9+
from zope.component import adapter
10+
from zope.interface import implementer
11+
from zope.interface import Interface
12+
from zope.interface import provider
13+
14+
15+
class IPlausibleFieldsMarker(Interface):
16+
pass
17+
18+
19+
@provider(IFormFieldProvider)
20+
class IPlausibleFields(model.Schema):
21+
""" """
22+
23+
directives.fieldset(
24+
"plausible_fields",
25+
label=_("Plausible fields"),
26+
description=_("Plausible analytics fields"),
27+
fields=[
28+
"plausible_enabled",
29+
"plausible_url",
30+
"plausible_site",
31+
"plausible_token",
32+
"plausible_link_object_action",
33+
],
34+
)
35+
36+
plausible_enabled = schema.Bool(
37+
title=_("Enable Plausible"),
38+
description=_(
39+
"Enable Plausible analytics tracking on this content and all its children."
40+
),
41+
default=False,
42+
required=False,
43+
readonly=False,
44+
)
45+
46+
plausible_url = schema.TextLine(
47+
title=_("Plausible URL"),
48+
description=_("Example : plausible.imio.be"),
49+
default="",
50+
required=False,
51+
readonly=False,
52+
)
53+
54+
plausible_site = schema.TextLine(
55+
title=_("Plausible Site"),
56+
description=_("Example : imio.be"),
57+
default="",
58+
required=False,
59+
readonly=False,
60+
)
61+
62+
plausible_token = schema.TextLine(
63+
title=_("Plausible token"),
64+
description=_("Plausible authentification token"),
65+
default="",
66+
required=False,
67+
readonly=False,
68+
)
69+
70+
plausible_link_object_action = schema.Bool(
71+
title=_("Add a link in the object menu"),
72+
description=_("Add a link to the statistics browser view in the object menu"),
73+
default=False,
74+
required=False,
75+
readonly=False,
76+
)
77+
78+
79+
@implementer(IPlausibleFields)
80+
@adapter(IPlausibleFieldsMarker)
81+
class PlausibleFields(object): # pragma: no cover
82+
def __init__(self, context):
83+
self.context = context
84+
85+
@property
86+
def plausible_enabled(self):
87+
if safe_hasattr(self.context, "plausible_enabled"):
88+
return self.context.plausible_enabled
89+
return None
90+
91+
@plausible_enabled.setter
92+
def plausible_enabled(self, value):
93+
self.context.plausible_enabled = value
94+
95+
@property
96+
def plausible_url(self):
97+
if safe_hasattr(self.context, "plausible_url"):
98+
return self.context.plausible_url
99+
return None
100+
101+
@plausible_url.setter
102+
def plausible_url(self, value):
103+
self.context.plausible_url = value
104+
105+
@property
106+
def plausible_site(self):
107+
if safe_hasattr(self.context, "plausible_site"):
108+
return self.context.plausible_site
109+
return None
110+
111+
@plausible_site.setter
112+
def plausible_site(self, value):
113+
self.context.plausible_site = value
114+
115+
@property
116+
def plausible_token(self):
117+
if safe_hasattr(self.context, "plausible_token"):
118+
return self.context.plausible_token
119+
return None
120+
121+
@plausible_token.setter
122+
def plausible_token(self, value):
123+
self.context.plausible_token = value
124+
125+
@property
126+
def plausible_link_object_action(self):
127+
if safe_hasattr(self.context, "plausible_link_object_action"):
128+
return self.context.plausible_link_object_action
129+
return None
130+
131+
@plausible_link_object_action.setter
132+
def plausible_link_object_action(self, value):
133+
self.context.plausible_link_object_action = value

src/collective/plausible/configure.zcml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
post_handler=".setuphandlers.post_install"
2727
/>
2828

29+
<genericsetup:registerProfile
30+
name="testing"
31+
title="collective.plausible (testing)"
32+
directory="profiles/testing"
33+
description="Installs the collective.plausible.testing profile."
34+
provides="Products.GenericSetup.interfaces.EXTENSION"
35+
/>
36+
2937
<genericsetup:registerProfile
3038
name="uninstall"
3139
title="collective.plausible (uninstall)"
@@ -42,11 +50,10 @@
4250

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

53+
<include package=".viewlets" />
54+
<include package=".behaviors" />
4555
<include package=".upgrades" />
46-
4756
<include package=".controlpanels" />
48-
49-
5057
<include package=".views" />
5158

5259
</configure>

src/collective/plausible/controlpanels/plausible_control_panel/controlpanel.pt

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,16 @@
4040
</div>
4141

4242
<div id="content-core">
43-
<div class="card" tal:condition="here/@@plausible-utils/is_plausible_set">
44-
<div class="card-header">
45-
<span i18n:domain="collective.plausible" i18n:translate="">Configuration state</span>
46-
</div>
47-
<div class="card-body portalMessage warning" role="status" >
48-
<span i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are set (here or environment variables)</span>
49-
</div>
50-
<div class="card-header">
51-
<span i18n:domain="collective.plausible" i18n:translate="">Plausible server healthcheck</span>
52-
</div>
53-
<div class="card-body portalMessage warning" role="status">
54-
<ul tal:condition="here/@@plausible-utils/get_plausible_instance_healthcheck">
55-
<li><span i18n:domain="collective.plausible" i18n:translate="">Clickhouse :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
56-
<li><span i18n:domain="collective.plausible" i18n:translate="">Postgresql :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
57-
<li><span i18n:domain="collective.plausible" i18n:translate="">Sites cache :&nbsp;</span><span tal:content="here/@@plausible-utils/get_plausible_instance_healthcheck/clickhouse" /></li>
58-
</ul>
59-
<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>
60-
</div>
43+
<div class="card">
44+
<h2 i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are defined on content properties</h2>
6145
</div>
62-
<div class="card" tal:condition="not: here/@@plausible-utils/is_plausible_set">
63-
<div class="card-header">
64-
<span i18n:domain="collective.plausible" i18n:translate="">Configuration state</span>
65-
</div>
66-
<div class="card-body portalMessage warning" role="status" >
67-
<span i18n:domain="collective.plausible" i18n:translate="">Plausible parameters are not set yet. You can define it here or via environment variables.</span>
68-
</div>
46+
<!-- <div class="card">
47+
<div class="card-header">
6948
</div>
70-
<div class="card">
71-
<div class="card-header">
72-
<span>Paramètres de Plausible</span>
73-
</div>
74-
<div id="layout-contents">
75-
<span tal:replace="structure view/contents" />
76-
</div>
49+
<div id="layout-contents">
50+
<span tal:replace="structure view/contents" />
7751
</div>
52+
</div> -->
7853
</div>
7954

8055
</div>

src/collective/plausible/controlpanels/plausible_control_panel/controlpanel.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,7 @@
1111

1212

1313
class IPlausibleControlPanel(Interface):
14-
url = schema.TextLine(
15-
title=_("Plausible URL"),
16-
description=_("Example : plausible.imio.be"),
17-
default="",
18-
required=False,
19-
readonly=False,
20-
)
21-
22-
site = schema.TextLine(
23-
title=_("Plausible Site"),
24-
description=_("Example : imio.be"),
25-
default="",
26-
required=False,
27-
readonly=False,
28-
)
29-
30-
token = schema.TextLine(
31-
title=_("Plausible token"),
32-
description=_("Plausible authentification token"),
33-
default="",
34-
required=False,
35-
readonly=False,
36-
)
37-
38-
link_user_action = schema.Bool(
39-
title=_("Add a link in the user menu"),
40-
description=_("Add a link to the statistics browser view in the user menu"),
41-
default=True,
42-
required=False,
43-
readonly=False,
44-
)
14+
pass
4515

4616

4717
class PlausibleControlPanel(RegistryEditForm):

0 commit comments

Comments
 (0)