:::{php:namespace} Atk4\Ui ::: (overview)= # Overview of Agile UI Agile UI is a PHP component framework for building User Interfaces entirely in PHP. Although the components of Agile UI will typically use HTML, JavaScript, jQuery and CSS, the goal of Agile UI is to abstract them away behind easy-to-use component objects. As a framework it's closely coupled with Agile Data (https://atk4-data.readthedocs.io/) which abstracts database interaction operations. The default UI template set uses Fomantic-UI (https://fomantic-ui.com) for presentation. At a glance, Agile UI consists of the following: :::{figure} images/all-atk-classes.png ::: Agile UI is designed and built for the Agile Toolkit (https://atk4.org/) platform, with the goal of providing a user-friendly experience when creating data-heavy API / UI backends. ## Agile UI Design Goals Our goal is to offer a free UI framework which can be used to easily develop the most complex business application UI in just a few hours, without diving deep into HTML/JS specifics. ### 1. Out of the box experience Sample scenario: If during the .COM boom you purchased 1000 good-looking .COM domains and are now selling them, you will need to track offers from buyers. You could use Excel, but what if your staff needs to access the data, or you need to implement business operations such as accepting offers? Agile UI is ideal for such a scenario. By simply describing your data model, relations, and operations you will get a fully working UI and API with minimal setup. ### 2. Compact and easy to integrate Simple scenario: Your domains such as "happy.com" receive a lot of offers, so you want to place a special form for potential buyers to fill out. To weed out spammers, you want to perform an address verification for filled-in data. Agile UI contains a Form component which you can integrate into your existing app. More importantly, it can securely access your offer database. ### 3. Compatible with RestAPI Simple scenario: You need a basic mobile app to check recent offers from your mobile phone. You can set up an API end-point for authorized access to your offer database, that follows the same business rules and has access to the same operations. ### 4. Deploy and Scale Simple scenario: You want to use serverless architecture where a 3rd party company is looking after your server, database, and security; you simply provide your app. Agile UI is designed and optimized for quick deployment into modern serverless architecture providers such as: Heroku, Docker, or even AWS Lambdas. Agile UI / PHP application has a minimum "start-up" time, has the best CPU usage, and gives you the highest efficiency and best scaling. ### 5. High-level Solution Simple scenario: You are a busy person who needs to get your application ready in one hour and then forget about it for the next few years. You are not particularly thrilled about digging through heaps of HTML, CSS, or JS frameworks and need a solution which will be quick and just works. (overview_example)= #### Overview Example Agile UI / Agile Data code for your app can fit into a single file. See below for clarifications: ``` addField('domain_name'); $this->addField('contact_email'); $this->addField('contact_phone'); $this->addField('date', ['type' => 'date']); $this->addField('offer', ['type' => 'atk4_money']); $this->addField('is_accepted', ['type' => 'boolean']); } } // create Application object and initialize Admin Layout $app = new \Atk4\Ui\App(['title' => 'Offer tracking system']); $app->initLayout([\Atk4\Ui\Layout\Admin::class]); // connect to database and place a fully-interactive Crud $db = new \Atk4\Data\Persistence\Sql($dsn); \Atk4\Ui\Crud::addTo($app) ->setModel(new Offer($db)); ``` Through the course of this example, We are performing several core actions: - `$app` is an object representing our Web Application and abstracting all the input, output, error-handling, and other technical implementation details of a standard web application. In most applications you would want to extend this class yourself. When integrating Agile UI with MVC framework, you would be using a different App class that properly integrates framework capabilities. For a {ref}`component` the App class provides level of abstraction and utility. For full documentation see {ref}`app`. - `$db` this is a database persistence object. It may be a Database which is either SQL or NoSQL but can also be RestAPI, a cache, or a pseudo-persistence. We used `Persistence\Sql` class, which takes advantage of a standard-compliant database server to speed up aggregation, multi-table, and multi-record operations. For a {ref}`component` the Persistence class provides data storage abstraction through the use of a Model class. Agile Data has full documentation at https://atk4-data.readthedocs.io/. - `Offer` is a Model - a database-agnostic declaration of your business entity. Model object represents a data-set for specific persistence and conditions. In our example, the object is created representing all our offer records that is then passed into the Crud {ref}`component`. For a {ref}`component`, the Model represents information about the structure and offers a mechanism to retrieve, store, and delete date from `$db` persistence. - `Crud` is a {ref}`component` class. Particularly Crud is bundled with Agile UI and implements out-of-the-box interface for displaying data in a table format with operations to add, delete, or edit the record. Although it's not obvious from the code, Crud relies on multiple other components such as {php:class}`Grid`, {php:class}`Form`, {php:class}`Menu`, {php:class}`Paginator`, and {php:class}`Button`. To sum up Agile UI in more technical terms: - Fully utilizes abstraction of Web technologies through components. - Contains concise syntax to define UI layouts in PHP. - Has built-in security and safety. - Decouples from data storage/retrieval mechanism. - Designed to be integrated into full-stack frameworks. - Abstains from duplicating field names, types, or validation logic outside of Model class. ### Best use of Agile UI - Creating admin backend UI for data entry and dashboards in shortest time and with minimum amount of code. - Building UI components which you are willing to use across multiple environments (Laravel, WordPress, Drupal, etc) - Creating MVP prototype for Web Apps. (component)= ## Component The component is a fundamental building block of Agile UI. Each component is fully self-sufficient and creating a class instance is enough to make a component work. That means that components may rely on each other and even though some may appear very basic to you, they are relied on by some other components for maximum flexibility. The next example adds a "Cancel" button to a form: ``` $button = \Atk4\Ui\Button::addTo($form, [ 'Cancel', 'icon' => new \Atk4\Ui\Icon('pencil'), ])->link('dashboard.php'); ``` {php:class}`Button` and {php:class}`Icon` are some of the most basic components in Agile UI. You will find Crud / Form / Grid components much more useful: :::{figure} images/all-atk-classes.png ::: ### Using Components Look above at the {ref}`overview_example`, component `GRID` was made part of application layout with a line: ``` \Atk4\Ui\Crud::addTo($app); ``` To render a component individually and get the HTML and JavaScript use this format: ``` $form = new Form(); $form->setApp($app); $form->invokeInit(); $form->setEntity(new User($db)); $html = $form->renderToHtml(); ``` This would render an individual component and will return HTML: ```