[ZBXNEXT-2357] Introduce basic page controllers (mvc) Created: 2014 Jun 26  Updated: 2024 Apr 10  Resolved: 2017 Feb 16

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Frontend (F)
Affects Version/s: None
Fix Version/s: 2.5.0

Type: Change Request Priority: Major
Reporter: Alexei Vladishev Assignee: Unassigned
Resolution: Fixed Votes: 3
Labels: codequality, mvc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by ZBX-9546 ZBX_SERVER_NAME disapears from tab na... Closed
Team: Team A
Team: Team A
Sprint: Sprint 1

 Description   

There are number of goals for the initial step of MVC code refactoring:

  • improve structure/readability/maintainability of PHP code directly related to handling of forms, lists, etc
  • introduce page controllers, so it should be absolutely clear what code is used when we execute a particular action (for example, host creation)
  • forms should always specify an action by setting variable 'action' using POST or GET (preferably); for example, proxies.php?action=create
  • improve validation; for example, introduce support of array validation
  • get rid of use of the global variables such as _POST, _GET, _REQUEST, etc

Next step might be refactoring of page_header,php and page_footer.php as well as creation of a single front-controller.



 Comments   
Comment by Andrejs Čirkovs (Inactive) [ 2014 Jun 26 ]

Three more points that are needed:

1) Request / Response stack. We need to refactor out current code:

do_something($_GET);
echo "some string";
die();

to something like:

$request = Request::createFromGlobals();
$response = ZabbixKernel::processRequest($request, $debug = false, $environment = 'production');
$response->send();

so we can use the same approach in tests like

public function testZabbixPageHasZabbixString() {
    $request = Request::create('/dashboard', $debug = true, $environment = 'test');
    $response = ZabbixKernel::processRequest($request);
    $this->assertContains('Zabbix', $response->getBody());
    $this->assertEquals(200, $response->getStateus());
}

2) as stated above, we need to refactor/enhance ZBase, turning it into real HTTP Kernel, that can be instantiated many times, incapsulate request / response logic and most important, to be used in TESTS!! as shown above.

3) We need a very basic event engine for audit code.

Comment by Andrejs Čirkovs (Inactive) [ 2014 Jun 26 ]

more info / best practices on https://github.com/symfony/HttpFoundation

Comment by Andrejs Čirkovs (Inactive) [ 2014 Jun 27 ]

1a) One more idea why we need separate Request/Response classes is to check for redirections like:

public function testZabbixPageHasZabbixString() {
    $request = Request::create('/dashboard', $debug = true, $environment = 'test');
    $response = ZabbixKernel::processRequest($request);
    $this->assertTrue($response instanceof RedirectResponse);
    $this->assertEquals('/login', $response->getTarget());
}
Comment by Andrejs Čirkovs (Inactive) [ 2014 Jun 27 ]

4) Morover, we should need a routing. A lightweight routing who's primary reason would be not to have pretty urls but to validate url on generation - currently, we can put virtually any URI in html source; by introducing a routing, a uri validation would happen on generation process.

Comment by Andrejs Čirkovs (Inactive) [ 2014 Jun 27 ]

5) Lastly, we should consider changing our template engine, since the current one is not supported at all (except internally) and is a burden of loosely-coupled objects. To prevent developers for shouting themselves in the leg we should use HTML-less template engine, such as Jade or Haml (which is, in fact, my favorite and has native php port:

http://haml.info/tutorial.html

it basically renders:

#content
  .left.column
    %h2 Welcome to our site!
    %p= print_information
  .right.column
    = render :partial => "sidebar"

into:

<div id='content'>
  <div class='left column'>
    <h2>Welcome to our site!</h2>
    <p><%= print_information %></p>
  </div>
  <div class="right column">
    <%= render :partial => "sidebar" %>
  </div>
</div>

native PHP port is here: https://github.com/arnaud-lb/MtHaml

Comment by Vadim Nesterov [ 2015 Jan 07 ]

Why don't you want to use modern js frameworks?
You are reinventing a wheel...

Comment by richlv [ 2015 Jan 27 ]

(1) it has been mentioned that ZBXNEXT-1099 might be considered/solved here - let's figure that out when this issue nears completion

Comment by Alexei Vladishev [ 2015 Feb 09 ]

Vadim, the transformation cannot be done in one go. The work also depends on the API, which is going to be moved to the server side. Think about MVC as a first phase of broader redesign.

Comment by richlv [ 2015 Feb 13 ]

(2) changed translation strings ?

New strings

  • Scripts deleted
  • Script name cannot be empty.
  • Script command cannot be empty.
  • Proxies deleted
  • Media types deleted
  • Fatal error, please report to the Zabbix team
  • Delete media type?
  • Cannot delete scripts
  • Cannot include JS file "%s".
  • Cannot delete proxies
  • Cannot delete media types

Deleted strings

  • Remove from
  • Please enter confirmation text.
  • Empty name for script.
  • Duplicate script name "%1$s".
  • Delete selected media type?
  • Command cannot be empty.
  • Add to

sasha Fixed typo in r53346. RESOLVED

<richlv> the list seems to match, thanks
a couple of remarks :

  • "Fatal error, please report to Zabbix Team" suggested to change to "Fatal error, please report to the Zabbix team"
  • "Something wrong happened" - maybe possible to make this sound a bit better, also - would this appear without any other information ?

martins-v I agree to the first suggestion. As for the second I have often seen "Something went wrong" messages in similar contexts, which seems slightly better.

<richlv> as discussed, style of the first message has been improved and second made the same as the first one directly in trunk r53495.

<richlv> the above is relevant for trunk up to r53496. unfortunately, since then, there have been more unverified changes merged, and translations in trunk can't be synced at this time. see subissue (9) for continuation on this.
this subissue CLOSED

Comment by richlv [ 2015 Feb 18 ]

(3) looks like db patches for user profile "url" field are missing. as discussed, probably the best action is to do a simple substring replacement

sasha the list of URLs which must be replaced:

dashboard.php   => zabbix.php?action=dashboard.view
discovery.php   => zabbix.php?action=discovery.view
maps.php        => zabbix.php?action=map.view
httpmon.php     => zabbix.php?action=web.view
media_types.php => zabbix.php?action=mediatype.list
proxies.php     => zabbix.php?action=proxy.list
scripts.php     => zabbix.php?action=script.list
report3.php     => zabbix.php?action=report.services
report1.php     => zabbix.php?action=report.status

wiper Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBXNEXT-2357-db

sasha

  • new URL must be checked for length overflow
  • empty URLs shouldn't be selected from database

REOPENED

Take a look at my changes in r57507.

wiper Thanks. RESOLVED in r57509

sasha Successfully TESTED! Take a look at my changes in r57510, r57511, r57512.

wiper Thanks, CLOSED

Comment by richlv [ 2015 Feb 18 ]

(4) documentation

  • url changes
  • regression - field name validation in some forms ("description" vs "Name" etc)
  • ability to clone mediatypes
Comment by Oleg Egorov (Inactive) [ 2015 Mar 24 ]

(5) White page
http://localhost/trunk/frontends/php/zabbix.php?action=dashboard.view2
If action doesn't exist

Comment by Alexander Vladishev [ 2015 Apr 09 ]

(6) Broken permission check. "guest" user can open any pages (configuration and administration)

sasha RESOLVED in trunk r53032.

alexei CLOSED

Comment by Alexander Vladishev [ 2015 Apr 29 ]

(7) Broken browserwarning.php

PHP Warning:  require_once(include/classes/core/CView.php): failed to open stream: No such file or directory in browserwarning.php on line 25
PHP Stack trace:
PHP   1. {main}() browserwarning.php:0
PHP Fatal error:  require_once(): Failed opening required 'include/classes/core/CView.php' (include_path='.:/usr/share/php:/usr/share/pear') in browserwarning.php on line 25
PHP Stack trace:
PHP   1. {main}() browserwarning.php:0

sasha RESOLVED directly in trunk in r53407.

Comment by Alexander Vladishev [ 2015 May 05 ]

(8) No server name in the new pages

<richlv> for the record this is about upper right corner and the page title. also includes the "fatal error" page.

Comment by richlv [ 2015 May 12 ]

(9) changed strings take 2. since r53496, there have been more unverified string changes. splitting out as a separate subissue.
there's at least one mistake (using uppercase "WEB" - it's not an acronym).

Comment by Oleg Egorov (Inactive) [ 2015 Jun 03 ]

(10) CheckBox issues
In all new places, where forms use checkboxes, they don't save new values.
For example in:
Administration -> Media types
Administration -> Scripts
Configuration -> Screens -> Resource: Plain text -> Show text as HTML

This happens because unchecked checkbox don't send any value.

Most popular solution is <input type="hidden" ...> with same name as checkbox.

Hidden fields use all most popular Web frameworks.

Comment by Ivo Kurzemnieks [ 2015 Sep 21 ]

(11) Impossible to debug fatal error problems. All we get is "Fatal error, please report to the Zabbix team" and controller + action. Framework should specify full paths,passed POST and GET parameters, all data, expected results and what we got in the end. For example missing files, views etc. Maybe the validation in checkInput() was wrong due to FALSE from validateInput(), but we are looking for problem in doAction() which is actually incorrect. We should specify field that did not pass the validation and why it didn't. Also redirection to /frontends/php/zabbix.php?action=system.warning is annyoing. I order to retry submitting a larger form with a lot of data, user needs to find that form again and everything has to be re-entered again.

Comment by Ivo Kurzemnieks [ 2015 Oct 07 ]

(12) API calls should be handled on controller side, not in views. For example: monitoring.widget.hosts.view.php, monitoring.widget.web.view, monitoring.widget.discovery.view.

Comment by Alexander Vladishev [ 2015 Nov 27 ]

(14) The new MVC pages: Monitoring -> Web and Monitoring -> IT Services -> Service report

alexei RESOLVED in r55907

sasha TESTED. Take a look at my changes in r56893 - r56906.

sasha Released in pre-3.0.0alpha5 r56976

CLOSED

Comment by Alexander Vladishev [ 2015 Nov 27 ]

(15) changed translation strings

Deleted strings:

  • Status of Web monitoring

alexei CLOSED

Comment by Gunars Pujats (Inactive) [ 2016 Jan 04 ]

(16) Dashboard widgets should load in parallel. Now widgets load sequentially because each widget locks session data during execution time.

gunarspujats RESOLVED in development branch svn://svn.zabbix.com/branches/dev/ZBXNEXT-2357

sasha

  1. Take a look at my changes in r57508, r57514
    • r57508: fixed getting of form parameters from the session
    • r57514: fixed displaying of messages from MVC pages
  2. API shouldn't contain calls of the session-related functions frontends/php/include/classes/api/services/CUser.php:995

REOPENED

gunarspujats

  1. CLOSED
  2. RESOLVED in r57532

sasha Successfully TESTED!

Comment by Andris Zeila [ 2016 Jan 11 ]

Database patch to convert user URLs to the new format (3) is available in:

  • pre-3.0.0alpha6 r57518
Comment by Alexander Vladishev [ 2017 Feb 16 ]

It is decided to close this problem as is. Opened sub-issues can be opened as separate ZBX or ZBXNEXT projects.

Generated at Fri Apr 19 06:18:31 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.