doc/book/en/tutorials/base/discovering-the-ui.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 17 Jan 2011 12:43:07 +0100
branchstable
changeset 6835 87e2641d75f7
child 6837 7562418985ef
permissions -rw-r--r--
[doc] major rework of the simple blog tutorial


.. _TutosBaseDiscoveringTheUI:

Discovering the web interface
-----------------------------

You can now access your web instance to create blogs and post messages
by visiting the URL http://localhost:8080/.

By default, anonymous access is disabled, so a login form will appear. If you
asked to allow anonymous access when initailizing the instance, click on the
'login' link in the top right hand corner. To login, you need then use the admin
account you specified at the time you initialized the database with
``cubicweb-ctl create``.

.. image:: ../../images/tutos-base_login-form_en.png
   :alt: the login form


Once authenticated, you can start playing with your instance. The default index
page looks like the following:

.. image:: ../../images/tutos-base_index_en.png
   :alt: the index page


Minimal configuration
~~~~~~~~~~~~~~~~~~~~~

Before creating entities, let's change that 'unset title' thing that appeared
there and there. This is handled using |cubicweb| properties system. To set it,
click on the 'site configuration link' in the pop-up menu behind your login name
in the upper left-hand corner

.. image:: ../../images/tutos-base_user-menu_en.png
   :alt: the user pop-up menu

The site title is in the 'Ui' section. Simply set it to the desired value and
click the 'validate' button.

.. image:: ../../images/tutos-base_siteconfig_en.png
   :alt: the site configuration form

You should see a 'changes applied' message appear. You can now go back to the
index page by clicking on the |cubicweb| logo in the upper left-hand corner.

You will much likely still see 'unset title' at this point. This is because by
default the index page is cached. Force a refresh of the page (by typing Ctrl-R
in firefox for instance) and you should now see the title you entered.


Adding entities
~~~~~~~~~~~~~~~

The ``blog`` cube defines several entity types, among them ``Blog`` which is a
container for ``BlogEntry`` (e.g. post) on a particular topic. We can get a
graphical view of the schema by clicking on the 'site schema' link in the user
pop-up menu we've already seen:

.. image:: ../../images/tutos-base_schema_en.png
   :alt: graphical view of the schema (aka data-model)

Nice isn't it? Notice that this, as most other stuff we'll see in this tutorial,
is generated by the framework according to the model of the application. In our
case, the model defined by the ``blog`` cube.

Now let us create a few of these entities.


Add a blog
**********

Clicking on the `[+]` at the left of the 'Blog' link on the index page will lead
you to an HTML form to create a blog.

.. image:: ../../images/tutos-base_blog-form_en.png
   :alt: the blog creation form

For instance, call this new blog 'Tech-blog' and type in 'everything about
technology' as the description , then validate the form by clicking on
'Validate'. You'll be redirected to the `primary` view of the newly created blog.

.. image:: ../../images/tutos-base_blog-primary_en.png
   :alt: the blog primary view


Add a blog post
***************

There are several way to add a blog entry. The simplest is to click on the 'add
blog entry' link in the actions box on viewing the blog we've juste created.
You'll then see a form to create a post, with a 'blog entry of' selector preset
to the blog we're coming from. Enter a title, some content, click the 'validate'
button and you're done. You'll be redirected to the blog primary view, though you
now see that it contains the blog post you've just created.

.. image:: ../../images/tutos-base_blog-primary-after-post-creation_en.png
   :alt: the blog primary view after creation of a post

Notice there are some new boxes that appears in the left column.

You can achieve the same thing by following the same path as we did for the blog
creation, e.g. by clicking on the `[+]` at the left of the 'Blog entry' link on
the index page. The diffence being that since there is now context information,
the 'blog entry of' selector won't be preset to the blog.


If you click on the 'modify' link of the action box, you are back to the form to
edit the entity you just created, except that the form now has another section
with a combo-box entitled 'add relation'. It provices a generic way to edit
relations which don't appears in the above form. Choose the relation you want to
add and a second combobox appears where you can pick existing entities.  If there
are too much of them, you'll be proposed to navigate (so go away from the form to
go back to it later, once you've selected the entity you want to link with).

.. image:: ../../images/tutos-base_form-generic-relations_en.png
   :alt: the generic relations combobox

This combobox can't appear until the entity is actually created. That's why you
haven't seen it at creation time. You could also have hit 'Apply' instead of
'validate' and it would have showed up.


About ui auto-adaptation
~~~~~~~~~~~~~~~~~~~~~~~~

One thing among other that makes |cubicweb| different than other framework is
its automatic user interface that adapts itself according to the data being
displayed. Let's see an example.

If you go back to the home page an click on the 'Blog' link, you'll be redirected
to the primary view of the blog, the same we've seen earlier. Now, add another
blog, go back to the index page, and click again on this link. You'll see
a very different view (namely the 'list' view).

.. image:: ../../images/tutos-base_blogs-list_en.png
   :alt: the list view when there are more than one blog to display

This is because in the first case, the framework choosed to use the 'primary'
view since there were only one entity in the data to be displayed. Now that there
are two entities, the 'list' view is more appropriate and hence has been used.

There are various other places where it's able to adapt to display data in the best
way, the main being provided by views *selection* mecanism that will be detailled
later.


Digging deeper
~~~~~~~~~~~~~~

By following principles explained below, you should now be able to create new
user to your application, to configure with a finer grain, etc... You'll notice
that the index page list a lot of types you don't know about. Most are built-in
type provided by the framework to make work the whole system. You may ignore them
in a first time and discover them as time goes.

One thing that is worth playing with is the search box. It may be used in various
way, from simple full text search to advanced queries using the :ref:`RQL` .