0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-03-16 22:33:34 +00:00

show accouns list view

This commit is contained in:
Gyula Madarasz 2018-09-24 09:42:46 +01:00
parent 573ea29430
commit 600bdafa59
10 changed files with 389 additions and 49 deletions

View file

@ -5,10 +5,10 @@ use Api\V8\Factory\ParamsMiddlewareFactory;
use Api\V8\Param\CreateModuleParams;
use Api\V8\Param\CreateRelationshipParams;
use Api\V8\Param\DeleteModuleParams;
use Api\V8\Param\DeleteRelationshipParams;
use Api\V8\Param\GetModuleParams;
use Api\V8\Param\GetModulesParams;
use Api\V8\Param\GetRelationshipParams;
use Api\V8\Param\ListViewColumnsParams;
use Api\V8\Param\UpdateModuleParams;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Middleware\AuthorizationServerMiddleware;
@ -30,6 +30,10 @@ $app->group('', function () use ($app) {
* Logout
*/
$app->post('/logout', LogoutController::class);
$app
->get('/listview/columns/{moduleName}', 'Api\V8\Controller\ListViewController:getListViewColumns')
->add($paramsMiddlewareFactory->bind(ListViewColumnsParams::class));
/**
* Get module records

View file

@ -1,12 +1,19 @@
<?php
use Api\V8\Controller;
use Api\V8\Service\ListViewService;
use Api\V8\Service\LogoutService;
use Api\V8\Service\ModuleService;
use Api\V8\Service\RelationshipService;
use Interop\Container\ContainerInterface as Container;
use League\OAuth2\Server\ResourceServer;
return [
Controller\ListViewController::class => function (Container $container) {
return new Controller\ListViewController(
$container->get(ListViewService::class)
);
},
Controller\ModuleController::class => function (Container $container) {
return new Controller\ModuleController(
$container->get(ModuleService::class)
@ -15,7 +22,7 @@ return [
Controller\LogoutController::class => function (Container $container) {
return new Controller\LogoutController(
$container->get(LogoutService::class),
$container->get(\League\OAuth2\Server\ResourceServer::class)
$container->get(ResourceServer::class)
);
},
Controller\RelationshipController::class => function (Container $container) {

View file

@ -6,6 +6,12 @@ use Api\V8\Param;
use Interop\Container\ContainerInterface as Container;
return [
Param\ListViewColumnsParams::class => function (Container $container) {
return new Param\ListViewColumnsParams(
$container->get(ValidatorFactory::class),
$container->get(BeanManager::class)
);
},
Param\GetModuleParams::class => function (Container $container) {
return new Param\GetModuleParams(
$container->get(ValidatorFactory::class),

View file

@ -8,6 +8,14 @@ use Api\V8\Service;
use Interop\Container\ContainerInterface as Container;
return [
Service\ListViewService::class => function (Container $container) {
return new Service\ListViewService(
$container->get(BeanManager::class),
$container->get(AttributeObjectHelper::class),
$container->get(RelationshipObjectHelper::class),
$container->get(PaginationObjectHelper::class)
);
},
Service\ModuleService::class => function (Container $container) {
return new Service\ModuleService(
$container->get(BeanManager::class),

View file

@ -0,0 +1,86 @@
<?php
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
namespace Api\V8\Controller;
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
use Api\V8\Param\ListViewColumnsParams;
use Api\V8\Service\ListViewService;
use Api\V8\Service\ModuleService;
use Exception;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* ListViewController
*
* @author gyula
*/
class ListViewController extends BaseController {
/**
* @var ListViewService
*/
private $listViewService;
/**
* @param ModuleService $moduleService
*/
public function __construct(ListViewService $listViewService)
{
$this->listViewService = $listViewService;
}
public function getListViewColumns(Request $request, Response $response, array $args, ListViewColumnsParams $params) {
try {
$jsonResponse = $this->listViewService->getListViewDefs($params);
return $this->generateResponse($response, $jsonResponse, 200);
} catch (Exception $exception) {
return $this->generateErrorResponse($response, $exception, 400);
}
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
namespace Api\V8\Param;
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
use Api\V8\Param\Options as ParamOption;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* ListViewColumnsParams
*
* @author gyula
*/
class ListViewColumnsParams extends BaseParam {
/**
* @return string
*/
public function getModuleName()
{
return $this->parameters['moduleName'];
}
protected function configureParameters(\Symfony\Component\OptionsResolver\OptionsResolver $resolver) {
$this->setOptions(
$resolver,
[
ParamOption\ModuleName::class,
// ParamOption\Id::class,
// ParamOption\Fields::class,
]
);
}
}

View file

@ -0,0 +1,141 @@
<?php
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
namespace Api\V8\Service;
use Api\V8\BeanDecorator\BeanManager;
use Api\V8\JsonApi\Helper\AttributeObjectHelper;
use Api\V8\JsonApi\Helper\PaginationObjectHelper;
use Api\V8\JsonApi\Helper\RelationshipObjectHelper;
use Api\V8\JsonApi\Response\AttributeResponse;
use Api\V8\Param\ListViewColumnsParams;
use ListViewFacade;
use SuiteCRM\LangText;
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
include_once __DIR__ . '/../../../include/ListView/ListViewFacade.php';
/**
* ListViewService
*
* @author gyula
*/
class ListViewService {
/**
* an exact match to ListViewColumnInterface struct of Angular front-end
*
* @var array
*/
private static $listViewColumnInterface = [
'fieldName' => '',
'width' => '',
'label' => '',
'link' => false,
'default' => false,
'module' => '',
'id' => '',
'sortable' => false,
'customCode' => '', // TODO: deprecated from legacy (using only on PHP front-end)
];
/**
* @var BeanManager
*/
private $beanManager;
/**
* @var AttributeObjectHelper
*/
private $attributeHelper;
/**
* @var RelationshipObjectHelper
*/
private $relationshipHelper;
/**
* @var PaginationObjectHelper
*/
private $paginationHelper;
/**
* @param BeanManager $beanManager
* @param AttributeObjectHelper $attributeHelper
* @param RelationshipObjectHelper $relationshipHelper
* @param PaginationObjectHelper $paginationHelper
*/
public function __construct(
BeanManager $beanManager,
AttributeObjectHelper $attributeHelper,
RelationshipObjectHelper $relationshipHelper,
PaginationObjectHelper $paginationHelper
) {
$this->beanManager = $beanManager;
$this->attributeHelper = $attributeHelper;
$this->relationshipHelper = $relationshipHelper;
$this->paginationHelper = $paginationHelper;
}
/**
* @param ListViewColumnsParams $params
*
* @return JsonSerializable
*/
public function getListViewDefs(ListViewColumnsParams $params)
{
$displayColumns = ListViewFacade::getDisplayColumns($params->getModuleName());
$data = [];
foreach ($displayColumns as $key => $column) {
$column = array_merge(self::$listViewColumnInterface, $column);
$column['fieldName'] = strtolower($key); // TODO: get the vardef instead this "intuitive fieldName"
$text = new LangText($column['label'], null, LangText::USING_ALL_STRINGS, true, false);
$translated = $text->getText();
$column['label'] = $translated ? $translated : $column['label'];
// TODO: validate the column name (for e.g label and name should be requered etc...) also check the ListViewColumnInterface keys are match..
$data[] = $column;
}
$response = new AttributeResponse($data);
return $response;
}
}

View file

@ -134,7 +134,7 @@ class LangText
{ // TODO: rename the methode to LangText::translate()
// TODO: app_strings and mod_strings could be in separated methods
global $app_strings, $mod_strings;
global $app_strings, $mod_strings, $app_list_strings;
if (!is_null($key)) {
$this->key = $key;
@ -154,7 +154,9 @@ class LangText
$text = isset($app_strings[$this->key]) && $app_strings[$this->key] ? $app_strings[$this->key] : null;
} elseif ($this->use === self::USING_ALL_STRINGS) {
$text = isset($mod_strings[$this->key]) && $mod_strings[$this->key] ? $mod_strings[$this->key] : (
isset($app_strings[$this->key]) ? $app_strings[$this->key] : null
isset($app_strings[$this->key]) ? $app_strings[$this->key] : (
isset($app_list_strings[$this->key]) ? $app_list_strings[$this->key] : null
)
);
} else {
ErrorMessage::drop('Unknown use case for translation: ' . $this->use);

View file

@ -102,6 +102,56 @@ if (!defined('sugarEntry') || !sugarEntry) {
self::__construct($focus, $module, $type);
}
/**
* Retrieves display columns on list view of specified module
*
* @param string $module
* @param array $request
* @return array
*/
public static function getDisplayColumns($module, $request = [])
{
$metadataFile = null;
$foundViewDefs = false;
if (file_exists('custom/modules/' . $module. '/metadata/listviewdefs.php')) {
$metadataFile = 'custom/modules/' . $module . '/metadata/listviewdefs.php';
$foundViewDefs = true;
} else {
if (file_exists('custom/modules/'. $module.'/metadata/metafiles.php')) {
require_once('custom/modules/'. $module.'/metadata/metafiles.php');
if (!empty($metafiles[$module]['listviewdefs'])) {
$metadataFile = $metafiles[$module]['listviewdefs'];
$foundViewDefs = true;
}
} elseif (file_exists('modules/'. $module.'/metadata/metafiles.php')) {
require_once('modules/'. $module.'/metadata/metafiles.php');
if (!empty($metafiles[$module]['listviewdefs'])) {
$metadataFile = $metafiles[$module]['listviewdefs'];
$foundViewDefs = true;
}
}
}
if (!$foundViewDefs && file_exists('modules/'. $module.'/metadata/listviewdefs.php')) {
$metadataFile = 'modules/'. $module.'/metadata/listviewdefs.php';
}
require_once($metadataFile);
$displayColumns = array();
if (!empty($request['displayColumns'])) {
foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
if (!empty($listViewDefs[$module][$col])) {
$displayColumns[$col] = $listViewDefs[$module][$col];
}
}
} else {
foreach ($listViewDefs[$module] as $col => $params) {
if (!empty($params['default']) && $params['default']) {
$displayColumns[$col] = $params;
}
}
}
return $displayColumns;
}
public function build()
{
@ -111,51 +161,8 @@ if (!defined('sugarEntry') || !sugarEntry) {
$this->lv = new ListView();
$this->template = 'modules/'.$this->module.'/ListView.html';
} else {
$metadataFile = null;
$foundViewDefs = false;
if (file_exists('custom/modules/' . $this->module. '/metadata/listviewdefs.php')) {
$metadataFile = 'custom/modules/' . $this->module . '/metadata/listviewdefs.php';
$foundViewDefs = true;
} else {
if (file_exists('custom/modules/'. $this->module.'/metadata/metafiles.php')) {
require_once('custom/modules/'. $this->module.'/metadata/metafiles.php');
if (!empty($metafiles[ $this->module]['listviewdefs'])) {
$metadataFile = $metafiles[ $this->module]['listviewdefs'];
$foundViewDefs = true;
}
} elseif (file_exists('modules/'. $this->module.'/metadata/metafiles.php')) {
require_once('modules/'. $this->module.'/metadata/metafiles.php');
if (!empty($metafiles[ $this->module]['listviewdefs'])) {
$metadataFile = $metafiles[ $this->module]['listviewdefs'];
$foundViewDefs = true;
}
}
}
if (!$foundViewDefs && file_exists('modules/'. $this->module.'/metadata/listviewdefs.php')) {
$metadataFile = 'modules/'. $this->module.'/metadata/listviewdefs.php';
}
require_once($metadataFile);
$this->lv = new ListViewSmarty();
$displayColumns = array();
if (!empty($_REQUEST['displayColumns'])) {
foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
if (!empty($listViewDefs[$this->module][$col])) {
$displayColumns[$col] = $listViewDefs[$this->module][$col];
}
}
} else {
foreach ($listViewDefs[$this->module] as $col => $params) {
if (!empty($params['default']) && $params['default']) {
$displayColumns[$col] = $params;
}
}
}
$this->lv->displayColumns = $displayColumns;
$this->lv->displayColumns = self::getDisplayColumns($this->module, $_REQUEST);
$this->type = 2;
$this->template = 'include/ListView/ListViewGeneric.tpl';
}

View file

@ -451,7 +451,7 @@ class SearchForm
}
}
}
throw new Exception('Not found');
throw new Exception('Find Field Option Value: Not found');
}
/**