Make it possible for node types to have a 'custom view'
This 'custom view' means that the URL to view the node (as returned by url_for_node(…)) cannot be loaded via XHR and embedded in the project viewer, but should rather be used as the actual browser URL instead. Currently only blogs use this.
This commit is contained in:
parent
8ad2ee8729
commit
ddc52b969e
@ -10,6 +10,12 @@ from flask_login import current_user
|
||||
from pillar.web import system_util
|
||||
|
||||
GROUP_NODES = {'group', 'storage', 'group_texture', 'group_hdri'}
|
||||
|
||||
# Node types that shouldn't be embedded in the project view.
|
||||
# Rather those nodes have their own end point for viewing.
|
||||
# Such nodes should implement a finder in web/nodes/finders.py.
|
||||
CUSTOM_VIEW_NODE_TYPES = {'blog'}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -29,6 +35,7 @@ def jstree_parse_node(node, children=None):
|
||||
id="n_{0}".format(node._id),
|
||||
a_attr={"href": url_for_node(node=node)},
|
||||
li_attr={"data-node-type": node.node_type},
|
||||
custom_view=node_type in CUSTOM_VIEW_NODE_TYPES,
|
||||
text=Markup.escape(node.name),
|
||||
type=node_type,
|
||||
children=False)
|
||||
|
@ -605,8 +605,8 @@ script.
|
||||
}
|
||||
|
||||
// Check the type of node and act accordingly
|
||||
if (data.node.original.type == 'blog') {
|
||||
window.location.replace('blog');
|
||||
if (data.node.original.custom_view) {
|
||||
window.location = data.node.a_attr.href;
|
||||
} else {
|
||||
var currentNodeId = ProjectUtils.nodeId();
|
||||
if (currentNodeId != selectedNodeId) {
|
||||
|
@ -39,7 +39,42 @@ class JSTreeTest(AbstractPillarTest):
|
||||
'text': Markup('Live <strong>Edit</strong>'),
|
||||
'type': 'file',
|
||||
'children': False,
|
||||
'custom_view': False,
|
||||
})
|
||||
|
||||
def test_jstree_parse_blog_node(self):
|
||||
from pillar.web.utils.jstree import jstree_parse_node
|
||||
|
||||
node_doc = {'_id': ObjectId('55f338f92beb3300c4ff99fe'),
|
||||
'_created': parse('2015-09-11T22:26:33.000+0200'),
|
||||
'_updated': parse('2015-10-30T22:44:27.000+0100'),
|
||||
'_etag': '5248485b4ea7e55e858ff84b1bd4aae88917a37c',
|
||||
'picture': ObjectId('55f338f92beb3300c4ff99de'),
|
||||
'description': 'Play the full movie and see how it was cobbled together.',
|
||||
'parent': ObjectId('55f338f92beb3300c4ff99f9'),
|
||||
'project': ObjectId('55f338f92beb3300c4ff99e5'),
|
||||
'node_type': 'blog',
|
||||
'user': ObjectId('552b066b41acdf5dec4436f2'),
|
||||
'properties': {'status': 'published',
|
||||
'file': ObjectId('55f338f92beb3300c4ff99c2'),
|
||||
'content_type': 'file'},
|
||||
'name': 'Live <strong>Edit</strong>'}
|
||||
|
||||
# Mocking url_for_node prevents us from setting up a project and an URLer service.
|
||||
with mock.patch('pillar.web.nodes.routes.url_for_node') as mock_url_for_node:
|
||||
mock_url_for_node.return_value = '/the/url'
|
||||
parsed = jstree_parse_node(Node(node_doc))
|
||||
|
||||
self.assertEqual(parsed, {
|
||||
'id': 'n_55f338f92beb3300c4ff99fe',
|
||||
'a_attr': {'href': '/the/url'},
|
||||
'li_attr': {'data-node-type': 'blog'},
|
||||
'text': Markup('Live <strong>Edit</strong>'),
|
||||
'type': 'blog',
|
||||
'children': False,
|
||||
'custom_view': True,
|
||||
})
|
||||
|
||||
def test_jstree_parse_just_created_node(self):
|
||||
from pillar.web.utils.jstree import jstree_parse_node
|
||||
|
||||
@ -64,4 +99,5 @@ class JSTreeTest(AbstractPillarTest):
|
||||
'text': Markup('Live <strong>Edit</strong>'),
|
||||
'type': 'asset',
|
||||
'children': False,
|
||||
'custom_view': False,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user