Skip to content

Commit

Permalink
Rename tiles to blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Oct 5, 2019
1 parent 90b6ed0 commit f821887
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 115 deletions.
46 changes: 23 additions & 23 deletions docs/source/tiles.rst → docs/source/blocks.rst
@@ -1,39 +1,39 @@
Tiles
Blocks
=====

.. note::
The tiles endpoint currently match only partially (the GET endpoints) the default Plone implementation.
The serialization of tiles didn't match the Mosaic (and plone.app.blocks) implementation and it's done to
The blocks endpoint currently match only partially (the GET endpoints) the default Plone implementation.
The serialization of blocks didn't match the Mosaic (and plone.app.blocks) implementation and it's done to
not rely on those technologies. The serialization of the tile information on objects are subject to change in
the future to extend or improve features.

A tile in Plone is an HTML snippet that can contain arbitrary content (e.g. text, images, videos).


Listing available tiles
Listing available blocks
-----------------------

.. note::
This endpoint currently does not return any data. The functionality needs to be implemented.

List all available tiles type by sending a GET request to the @tiles endpoint on the portal root::
List all available blocks type by sending a GET request to the @blocks endpoint on the portal root::

GET /plone/@tiles HTTP/1.1
GET /plone/@blocks HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

The server responds with a `Status 200` and list all available tiles::
The server responds with a `Status 200` and list all available blocks::

HTTP/1.1 200 OK
Content-Type: application/json
[
{
"@id": "http://localhost:55001/plone/@tiles/title",
"@id": "http://localhost:55001/plone/@blocks/title",
"title": "Title tile",
"description": "A field tile that will show the title of the content object",
},
{
"@id": "http://localhost:55001/plone/@tiles/description",
"@id": "http://localhost:55001/plone/@blocks/description",
"title": "Description tile",
"description": "A field tile that will show the description of the content object",
},
Expand All @@ -46,9 +46,9 @@ Retrieve JSON schema of an individual tile
.. note::
This endpoint currently does not return any data. The functionality needs to be implemented.

Retrieve the JSON schema of a specific tile by calling the '@tiles' endpoint with the id of the tile::
Retrieve the JSON schema of a specific tile by calling the '@blocks' endpoint with the id of the tile::

GET /plone/@tiles/title HTTP/1.1
GET /plone/@blocks/title HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

Expand All @@ -74,17 +74,17 @@ The server responds with a JSON schema definition for that particular tile::
}


Retrieving tiles on a content object
Retrieving blocks on a content object
------------------------------------

Tiles data are stored in the objects via a Dexterity behavior `plone.tiles`. It has two attributes that stores existing tiles in the object (`tiles`) and the current layout (`tiles_layout`).
Blocks data are stored in the objects via a Dexterity behavior `plone.blocks`. It has two attributes that stores existing blocks in the object (`blocks`) and the current layout (`blocks_layout`).
As it's a dexterity behavior, both attributes will be returned in a simple GET::

GET /plone/my-document HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

The server responds with a `Status 200` and list all stored tiles on that content object::
The server responds with a `Status 200` and list all stored blocks on that content object::

GET /plone/my-document HTTP/1.1
Accept: application/json
Expand All @@ -94,12 +94,12 @@ The server responds with a `Status 200` and list all stored tiles on that conten
{
"@id": "http://localhost:55001/plone/my-document",
...
"tiles_layout": [
"blocks_layout": [
"#title-1",
"#description-1",
"#image-1"
],
"tiles": {
"blocks": {
"#title-1": {
"@type": "title"
},
Expand All @@ -113,26 +113,26 @@ The server responds with a `Status 200` and list all stored tiles on that conten
}
}

Tiles objects will contain the tile metadata and the information to render it.
Blocks objects will contain the tile metadata and the information to render it.


Adding tiles to an object
Adding blocks to an object
-------------------------

Storing tiles is done also via a default PATCH content operation::
Storing blocks is done also via a default PATCH content operation::

PATCH /plone/my-document HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
"tiles_layout": [
"blocks_layout": [
"#title-1",
"#description-1",
"#image-1"
],
"tiles": {
"blocks": {
"#title-1": {
"@type": "title"
},
Expand All @@ -149,11 +149,11 @@ Storing tiles is done also via a default PATCH content operation::
If the tile has been added, the server responds with a `204` status code.


Proposal on saving tiles layout
Proposal on saving blocks layout
--------------------------------

.. note::
This is not implemented (yet) in the tiles_layout field, but it's a proposal on
This is not implemented (yet) in the blocks_layout field, but it's a proposal on
how could look like in the future. For now, we stick with the implementation shown in
previous sections.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Expand Up @@ -45,7 +45,7 @@ Contents
tusupload
vocabularies
controlpanels
tiles
blocks
querystring
querystringsearch
customization
Expand Down
20 changes: 10 additions & 10 deletions src/plone/restapi/behaviors.py
Expand Up @@ -8,7 +8,7 @@
import json


TILES_SCHEMA = json.dumps({"type": "object", "properties": {}})
BLOCKS_SCHEMA = json.dumps({"type": "object", "properties": {}})

LAYOUT_SCHEMA = json.dumps(
{
Expand All @@ -19,21 +19,21 @@


@provider(IFormFieldProvider)
class ITiles(model.Schema):
class IBlocks(model.Schema):

model.fieldset("layout", label=_(u"Layout"), fields=["tiles", "tiles_layout"])
model.fieldset("layout", label=_(u"Layout"), fields=["blocks", "blocks_layout"])

tiles = JSONField(
title=u"Tiles",
description=u"The JSON representation of the object tiles information. Must be a JSON object.", # noqa
schema=TILES_SCHEMA,
blocks = JSONField(
title=u"Blocks",
description=u"The JSON representation of the object blocks information. Must be a JSON object.", # noqa
schema=BLOCKS_SCHEMA,
default={},
required=False,
)

tiles_layout = JSONField(
title=u"Tiles Layout",
description=u"The JSON representation of the object tiles layout. Must be a JSON array.", # noqa
blocks_layout = JSONField(
title=u"Blocks Layout",
description=u"The JSON representation of the object blocks layout. Must be a JSON array.", # noqa
schema=LAYOUT_SCHEMA,
default={"items": []},
required=False,
Expand Down
14 changes: 7 additions & 7 deletions src/plone/restapi/configure.zcml
Expand Up @@ -46,10 +46,10 @@
/>

<genericsetup:registerProfile
name="tiles"
title="plone.restapi tiles"
directory="profiles/tiles"
description="Enables tiles on the Document content type"
name="blocks"
title="plone.restapi blocks"
directory="profiles/blocks"
description="Enables blocks on the Document content type"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

Expand Down Expand Up @@ -83,10 +83,10 @@
<include package="plone.behavior" file="meta.zcml"/>

<plone:behavior
name="plone.tiles"
name="plone.blocks"
title="Tiles"
description="Existing tiles on the object and their layout"
provides=".behaviors.ITiles"
description="Existing blocks on the object and their layout"
provides=".behaviors.IBlocks"
for="plone.dexterity.interfaces.IDexterityContent"
/>

Expand Down
16 changes: 8 additions & 8 deletions src/plone/restapi/deserializer/site.py
Expand Up @@ -35,24 +35,24 @@ def __call__(self, validate_all=False):
self.handle_ordering(data)

# Volto Tiles on the Plone Site root faker
if "tiles" in data:
if not getattr(self.context, "tiles", False):
if "blocks" in data:
if not getattr(self.context, "blocks", False):
self.context.manage_addProperty(
"tiles", json.dumps(data["tiles"]), "string"
"blocks", json.dumps(data["blocks"]), "string"
) # noqa
else:
self.context.manage_changeProperties(
tiles=json.dumps(data["tiles"])
blocks=json.dumps(data["blocks"])
) # noqa

if "tiles_layout" in data:
if not getattr(self.context, "tiles_layout", False):
if "blocks_layout" in data:
if not getattr(self.context, "blocks_layout", False):
self.context.manage_addProperty(
"tiles_layout", json.dumps(data["tiles_layout"]), "string"
"blocks_layout", json.dumps(data["blocks_layout"]), "string"
) # noqa
else:
self.context.manage_changeProperties(
tiles_layout=json.dumps(data["tiles_layout"])
blocks_layout=json.dumps(data["blocks_layout"])
) # noqa

if "title" in data:
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/plone/restapi/profiles/blocks/types/Document.xml
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<object name="Document" meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="behaviors" purge="false">
<element value="plone.restapi.behaviors.IBlocks" />
</property>

</object>
8 changes: 0 additions & 8 deletions src/plone/restapi/profiles/tiles/types/Document.xml

This file was deleted.

6 changes: 3 additions & 3 deletions src/plone/restapi/serializer/site.py
Expand Up @@ -49,9 +49,9 @@ def __call__(self, version=None):
"parent": {},
"is_folderish": True,
"description": self.context.description,
"tiles": json.loads(getattr(self.context, "tiles", "{}")),
"tiles_layout": json.loads(
getattr(self.context, "tiles_layout", "{}")
"blocks": json.loads(getattr(self.context, "blocks", "{}")),
"blocks_layout": json.loads(
getattr(self.context, "blocks_layout", "{}")
), # noqa
}

Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/tile.py
Expand Up @@ -9,7 +9,7 @@
from zope.interface import Interface


SERVICE_ID = "@tiles"
SERVICE_ID = "@blocks"


@implementer(ISerializeToJsonSummary)
Expand Down
Expand Up @@ -6,7 +6,7 @@
method="GET"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
factory=".get.TilesGet"
name="@tiles"
name="@blocks"
permission="zope2.View"
/>

Expand Down
Expand Up @@ -37,8 +37,8 @@ def reply(self):
}

result = []
tiles = getUtilitiesFor(ITileType, context=self.context)
for name, tile in tiles:
blocks = getUtilitiesFor(ITileType, context=self.context)
for name, tile in blocks:
serializer = getMultiAdapter((tile, self.request), ISerializeToJsonSummary)
if checkPermission(tile.add_permission, self.context):
result.append(serializer())
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/services/configure.zcml
Expand Up @@ -36,7 +36,7 @@
zcml:condition="have plone-5"/>
<include package=".email_send"
zcml:condition="have plone-5"/>
<include package=".tiles"
<include package=".blocks"
zcml:condition="installed plone.tiles" />

</configure>
2 changes: 1 addition & 1 deletion src/plone/restapi/setuphandlers.py
Expand Up @@ -17,7 +17,7 @@ def getNonInstallableProfiles(self): # pragma: no cover
return [
u"plone.restapi:performance",
u"plone.restapi:testing",
u"plone.restapi:tiles",
u"plone.restapi:blocks",
u"plone.restapi:uninstall",
]

Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/testing.py
Expand Up @@ -304,7 +304,7 @@ class PloneRestApiTilesLayer(PloneSandboxLayer):
defaultBases = (PLONE_RESTAPI_DX_FIXTURE,)

def setUpPloneSite(self, portal):
applyProfile(portal, "plone.restapi:tiles")
applyProfile(portal, "plone.restapi:blocks")


PLONE_RESTAPI_TILES_FIXTURE = PloneRestApiTilesLayer()
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/jwt_logged_in.resp
Expand Up @@ -15,6 +15,8 @@ Content-Type: application/json
},
"@id": "http://localhost:55001/plone/",
"@type": "Plone Site",
"blocks": {},
"blocks_layout": {},
"description": "",
"id": "plone",
"is_folderish": true,
Expand All @@ -29,7 +31,5 @@ Content-Type: application/json
],
"items_total": 1,
"parent": {},
"tiles": {},
"tiles_layout": {},
"title": "Plone site"
}
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/siteroot.resp
Expand Up @@ -15,6 +15,8 @@ Content-Type: application/json
},
"@id": "http://localhost:55001/plone",
"@type": "Plone Site",
"blocks": {},
"blocks_layout": {},
"description": "",
"id": "plone",
"is_folderish": true,
Expand All @@ -29,7 +31,5 @@ Content-Type: application/json
],
"items_total": 1,
"parent": {},
"tiles": {},
"tiles_layout": {},
"title": "Plone site"
}

0 comments on commit f821887

Please sign in to comment.