From 6bcdbaace9ff4d38d7915b4a19741d25f754e722 Mon Sep 17 00:00:00 2001 From: ggoffy Date: Sun, 21 Feb 2021 21:43:15 +0100 Subject: [PATCH] - fixed problem with display collections - added search to index page --- assets/css/style.css | 16 +++++ class/PackagesHandler.php | 34 ++++++++++- docs/changelog.txt | 2 + index.php | 70 ++++++++++++++++++---- language/english/main.php | 5 ++ language/english/modinfo.php | 4 +- language/german/main.php | 5 ++ language/german/modinfo.php | 4 +- templates/wgtransifex_index.tpl | 40 +++++++++++-- templates/wgtransifex_packages_prolist.tpl | 27 +++++---- 10 files changed, 173 insertions(+), 34 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index 98463bb..90cdeb7 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -41,3 +41,19 @@ ul.menu > li + li:before { .wgt-icon24 { height:24px; } +.wgt-filter-row { + padding: 10px 0; +} +#formFilterIndex { + margin-bottom:50px; +} +.wgt-package-img { + padding: 0 10px 0 0 !important; +} +.wgt-package-img img{ + margin-top: 15px !important; +} +.wgt-package-row { + border-bottom: 1px solid #cccccc; + padding: 10px 0 5px 0; +} diff --git a/class/PackagesHandler.php b/class/PackagesHandler.php index 82c814a..b02c1d0 100644 --- a/class/PackagesHandler.php +++ b/class/PackagesHandler.php @@ -144,7 +144,6 @@ public function getFormAllPackages($action = false) $form = new \XoopsThemeForm(\_AM_WGTRANSIFEX_PACKAGES_AUTOCREATE, 'form', $action, 'post', true); $form->setExtra('enctype="multipart/form-data"'); - // Form Table projects $pkgProjectsSelect = new \XoopsFormSelect(\_AM_WGTRANSIFEX_PACKAGE_PRO_ID, 'pkgProIds', 0, 10, true); $crProjects = new \CriteriaCompo(); @@ -174,6 +173,39 @@ public function getFormAllPackages($action = false) return $form; } + /** + * @public function getForm + * @param bool|string $action + * @param string $pkgFilterText + * @return \XoopsThemeForm + */ + public function getFormFilterPackages($action = false, $pkgFilterText = '') + { + $helper = Helper::getInstance(); + $projectsHandler = $helper->getHandler('Projects'); + //$resourcesHandler = $helper->getHandler('Resources'); + $languagesHandler = $helper->getHandler('Languages'); + if (!$action) { + $action = $_SERVER['REQUEST_URI']; + } + + // Get Theme Form + \xoops_load('XoopsFormLoader'); + $form = new \XoopsSimpleForm('', 'formFilterIndex', $action, 'post', true); + $form->setExtra('enctype="multipart/form-data"'); + $searchTray = new \XoopsFormElementTray(\_AM_WGTRANSIFEX_PACKAGE_SEARCH . ': ', ' '); + // Form Table projects + $searchTray->addElement(new \XoopsFormText('', 'pkgFilterText', 50, 255, $pkgFilterText), true); + $searchTray->addElement(new \XoopsFormButton('', 'submit', \_SEARCH, 'submit')); + $searchTray->addElement(new \XoopsFormButton('', 'cancel', \_CANCEL, 'submit')); + $form->addElement($searchTray); + // To Save + $form->addElement(new \XoopsFormHidden('op', 'search')); + + + return $form; + } + /** * @param string $dir * @param string $pattern diff --git a/docs/changelog.txt b/docs/changelog.txt index e9a123b..e5378a1 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -6,6 +6,8 @@ - added image size (goffy) - fixed smarty default problem (goffy) - fixed data type bug (array/string) (goffy) + - fixed problem with display collections (goffy) + - added search to index page (goffy) =================================================================== 2020/12/13 Version 1.05 alpha diff --git a/index.php b/index.php index 15bdcab..07034d9 100644 --- a/index.php +++ b/index.php @@ -47,19 +47,44 @@ $start = Request::getInt('start', 0); $limit = Request::getInt('limit', $helper->getConfig('userpager')); -$form = $packagesHandler->getFormSearchPackages(); -$GLOBALS['xoopsTpl']->assign('form', $form->render()); +//handle filter +if (Request::hasVar('cancel', '')) { + $pkgFilterText = ''; +} else { + $pkgFilterText = Request::getString('pkgFilterText', ''); +} +$form = $packagesHandler->getFormFilterPackages(false, $pkgFilterText); +$GLOBALS['xoopsTpl']->assign('formFilter', $form->render()); +$GLOBALS['xoopsTpl']->assign('pkgFilterText', $pkgFilterText); +if ('' === $pkgFilterText) { + $GLOBALS['xoopsTpl']->assign('displayFormFilter', 'none'); + $GLOBALS['xoopsTpl']->assign('btnFormFilterLabel', \_MA_WGTRANSIFEX_FILTER_SHOW); +} else { + $GLOBALS['xoopsTpl']->assign('displayFormFilter', 'block'); + $GLOBALS['xoopsTpl']->assign('btnFormFilterLabel', \_MA_WGTRANSIFEX_FILTER_HIDE); +} switch ($indexDisplay) { case 'single': default: $GLOBALS['xoopsTpl']->assign('isAdmin', is_object($xoopsUser) && $xoopsUser->isAdmin()); $count = 1; - $packagesCount = $packagesHandler->getCountPackages(); + $crPackages = new \CriteriaCompo(); + if ('' !== $pkgFilterText) { + $crPkgFilter = new \CriteriaCompo(); + $crPkgFilter->add(new \Criteria('pkg_name', '*' . $pkgFilterText . '*', 'LIKE')); + $crPkgFilter->add(new \Criteria('pkg_desc', '*' . $pkgFilterText . '*', 'LIKE'), 'OR'); + $crPackages->add($crPkgFilter); + } + $packagesCount = $packagesHandler->getCount($crPackages); $GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount); if ($packagesCount > 0) { $GLOBALS['xoopsTpl']->assign('displaySingle', true); - $packagesAll = $packagesHandler->getAllPackages($start, $limit, 'pkg_date', 'DESC'); + $crPackages->setStart($start); + $crPackages->setLimit($limit); + $crPackages->setSort('pkg_date'); + $crPackages->setOrder('DESC'); + $packagesAll = $packagesHandler->getAll($crPackages); // Get All Packages $packages = []; foreach (\array_keys($packagesAll) as $i) { @@ -95,15 +120,24 @@ $projectsAll = $projectsHandler->getAll($crProjects); if ($projectsCount > 0) { $packagesList = []; - // Get All Projects + if ('' !== $pkgFilterText) { + $crPkgFilter = new \CriteriaCompo(); + $crPkgFilter->add(new \Criteria('pkg_name', '%' . $pkgFilterText . '%', 'LIKE')); + $crPkgFilter->add(new \Criteria('pkg_desc', '%' . $pkgFilterText . '%', 'LIKE'), 'OR'); + } + // Get All Project foreach (\array_keys($projectsAll) as $i) { + $pkgCounter = 0; $languagesList = []; //$projects[$i] = $projectsAll[$i]->getValuesProjects(); $proId = $projectsAll[$i]->getVar('pro_id'); - //get list of packages + //get list of packages of primary language $crPackages = new \CriteriaCompo(); $crPackages->add(new \Criteria('pkg_pro_id', $proId)); $crPackages->add(new \Criteria('pkg_lang_id', $langPrimary)); + if ('' !== $pkgFilterText) { + $crPackages->add($crPkgFilter); + } $packagesCount = $packagesHandler->getCount($crPackages); $GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount); $crPackages->setStart(0); @@ -126,11 +160,17 @@ 'traperc_text' => $package['traperc_text'], 'date' => $package['date'], ]; + $pkgCounter++; } unset($crPackages); + + //get list of packages of other languages $crPackages = new \CriteriaCompo(); $crPackages->add(new \Criteria('pkg_pro_id', $proId)); $crPackages->add(new \Criteria('pkg_lang_id', $langPrimary, '<>')); + if ('' !== $pkgFilterText) { + $crPackages->add($crPkgFilter); + } $packagesCount = $packagesHandler->getCount($crPackages); $GLOBALS['xoopsTpl']->assign('packagesCount', $packagesCount); $packagesAll = $packagesHandler->getAll($crPackages); @@ -145,18 +185,28 @@ 'traperc_text' => $package['traperc_text'], 'date' => $package['date'], ]; + $pkgCounter++; } - $primary = array_column($languagesList, 'lang_primary'); - $percentage = array_column($languagesList, 'traperc'); - array_multisort($primary, SORT_DESC, $percentage, SORT_DESC, $languagesList); + if($pkgCounter > 0) { + $primary = array_column($languagesList, 'lang_primary'); + $percentage = array_column($languagesList, 'traperc'); + array_multisort($primary, SORT_DESC, $percentage, SORT_DESC, $languagesList); - $packagesList[$proId] = [ + $packagesList[$proId] = [ 'name' => $pkgName, 'logo' => $pkgLogo, 'desc' => $pkgDesc, 'langs' => $languagesList ]; + } + } + // Display Navigation + if ($projectsCount > $limit) { + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; + $pagenav = new \XoopsPageNav($projectsCount, $limit, $start, 'start', 'op=list&limit=' . $limit); + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); } + $GLOBALS['xoopsTpl']->assign('lang_thereare', \sprintf(\_MA_WGTRANSIFEX_INDEX_THEREARE, $packagesCount)); } $GLOBALS['xoopsTpl']->assign('packagesList', $packagesList); break; diff --git a/language/english/main.php b/language/english/main.php index 58e27f9..17f46fc 100644 --- a/language/english/main.php +++ b/language/english/main.php @@ -33,6 +33,9 @@ \define('_MA_WGTRANSIFEX_NOPERM', 'You do not have the necessary permissions'); \define('_MA_WGTRANSIFEX_FORM_OK', 'Successfully saved'); \define('_MA_WGTRANSIFEX_FORM_SURE_BROKEN', "Are you sure to notify as broken: %s "); +\define('_MA_WGTRANSIFEX_FILTER_HIDE', 'Hide filter'); +\define('_MA_WGTRANSIFEX_FILTER_SHOW', 'Show filter'); +\define('_MA_WGTRANSIFEX_FILTER_RESULT', 'Result for filter'); // ---------------- Contents ---------------- // Project \define('_MA_WGTRANSIFEX_PROJECT', 'Project'); @@ -59,6 +62,8 @@ \define('_MA_WGTRANSIFEX_PACKAGES_TITLE', 'List of available packages'); \define('_MA_WGTRANSIFEX_PACKAGES_DESC', 'Packages description'); \define('_MA_WGTRANSIFEX_PACKAGES_LIST', 'List of Packages'); +\define('_MA_WGTRANSIFEX_PACKAGE_DETAILS', 'Details of Package'); +\define('_AM_WGTRANSIFEX_PACKAGE_SEARCH', 'Search for Package'); // Caption of Package \define('_MA_WGTRANSIFEX_PACKAGE_ID', 'Id'); \define('_MA_WGTRANSIFEX_PACKAGE_NAME', 'Language Package Name'); diff --git a/language/english/modinfo.php b/language/english/modinfo.php index 87c536d..1f8010f 100644 --- a/language/english/modinfo.php +++ b/language/english/modinfo.php @@ -90,8 +90,8 @@ \define('_MI_WGTRANSIFEX_PANEL_TYPE_DESC', 'Panel Type is the bootstrap html div.'); \define('_MI_WGTRANSIFEX_INDEX_DISPLAY', 'Index Display Type'); \define('_MI_WGTRANSIFEX_INDEX_DISPLAY_DESC', 'Define how you want to display translations on index page.'); -\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Each translation as single item'); -\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Create for each resource a collection of all available translations'); +\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Each packages as single item'); +\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Create for each project a collection of all available language packages'); \define('_MI_WGTRANSIFEX_IDPAYPAL', 'Paypal ID'); \define('_MI_WGTRANSIFEX_IDPAYPAL_DESC', 'Insert here your PayPal ID for donactions.'); \define('_MI_WGTRANSIFEX_ADVERTISE', 'Advertisement Code'); diff --git a/language/german/main.php b/language/german/main.php index 9d48c7e..c0c578c 100644 --- a/language/german/main.php +++ b/language/german/main.php @@ -33,6 +33,9 @@ \define('_MA_WGTRANSIFEX_NOPERM', 'Du hast nicht die erforderlichen Berechtigungen'); \define('_MA_WGTRANSIFEX_FORM_OK', 'Erfolgreich gespeichert'); \define('_MA_WGTRANSIFEX_FORM_SURE_BROKEN', "Willst du wirklich als fehlerhaft melden: %s "); +\define('_MA_WGTRANSIFEX_FILTER_HIDE', 'Filter ausblenden'); +\define('_MA_WGTRANSIFEX_FILTER_SHOW', 'Filter anzeigen'); +\define('_MA_WGTRANSIFEX_FILTER_RESULT', 'Ergebnis für Filter'); // ---------------- Contents ---------------- // Project \define('_MA_WGTRANSIFEX_PROJECT', 'Projekt'); @@ -59,6 +62,8 @@ \define('_MA_WGTRANSIFEX_PACKAGES_TITLE', 'Liste der Pakete'); \define('_MA_WGTRANSIFEX_PACKAGES_DESC', 'Beschreibung des Pakets'); \define('_MA_WGTRANSIFEX_PACKAGES_LIST', 'Liste der Pakete'); +\define('_MA_WGTRANSIFEX_PACKAGE_DETAILS', 'Details zu Paket'); +\define('_AM_WGTRANSIFEX_PACKAGE_SEARCH', 'Suche nach Sprachpaket'); // Caption of Package \define('_MA_WGTRANSIFEX_PACKAGE_ID', 'Id'); \define('_MA_WGTRANSIFEX_PACKAGE_NAME', 'Name Sprachpaket'); diff --git a/language/german/modinfo.php b/language/german/modinfo.php index f787efc..8b36bd8 100644 --- a/language/german/modinfo.php +++ b/language/german/modinfo.php @@ -90,8 +90,8 @@ \define('_MI_WGTRANSIFEX_PANEL_TYPE_DESC', 'Panel Type is the bootstrap html div.'); \define('_MI_WGTRANSIFEX_INDEX_DISPLAY', 'Anzeige Indexseite'); \define('_MI_WGTRANSIFEX_INDEX_DISPLAY_DESC', 'Definiere wie die Übersetzungen auf der Indexseite angezeigt werden sollen.'); -\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Jede Übersetzung als eigender Eintrag'); -\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Erstelle eine Zusammenstellung aller Übersetzungen je Sprachressource'); +\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_SINGLE', 'Jedes Sprachpakete als eigender Eintrag'); +\define('_MI_WGTRANSIFEX_INDEX_DISPLAY_COLLECTION', 'Erstelle eine Zusammenstellung aller Sprachpakete je Projekt'); \define('_MI_WGTRANSIFEX_IDPAYPAL', 'Paypal ID'); \define('_MI_WGTRANSIFEX_IDPAYPAL_DESC', 'Deinen PayPal IDfür Spenden hier angeben.'); \define('_MI_WGTRANSIFEX_ADVERTISE', 'Code Werbung'); diff --git a/templates/wgtransifex_index.tpl b/templates/wgtransifex_index.tpl index 0bbb353..55a2e75 100644 --- a/templates/wgtransifex_index.tpl +++ b/templates/wgtransifex_index.tpl @@ -1,8 +1,17 @@ <{include file='db:wgtransifex_header.tpl' }> -<{if $form|default:''}> - <{$form}> -<{/if}> + @@ -31,8 +40,28 @@
+<{if $pagenav|default:'' != ''}> +
+ + <{if $formFilter|default:''}> +
+
<{$formFilter}>
+
+ <{/if}> +
+<{/if}> + +
+ <{if $pkgFilterText|default:''}> + <{$smarty.const._MA_WGTRANSIFEX_FILTER_RESULT}>: <{$pkgFilterText}> + <{else}> + <{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}> + <{/if}> +
+ <{if $displaySingle|default:''}> -
<{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}>
<{if $packagesCount|default:0 > 0}> @@ -53,13 +82,12 @@ <{/if}> <{if $displayCollection|default:''}> -
<{$smarty.const._MA_WGTRANSIFEX_INDEX_LATEST_LIST}>
<{if $projectsCount|default:0 > 0}>
<{foreach item=packages from=$packagesList}> - <{if $packages|@count is div by $divideby}> diff --git a/templates/wgtransifex_packages_prolist.tpl b/templates/wgtransifex_packages_prolist.tpl index b5cc6c1..7f66f7d 100644 --- a/templates/wgtransifex_packages_prolist.tpl +++ b/templates/wgtransifex_packages_prolist.tpl @@ -1,26 +1,27 @@ -
-
+
+
<{$packages.name}>
-
<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_NAME}>: <{$packages.name}>
- <{if $packages.desc|default:''}> -
<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_DESC}>: <{$packages.desc}>
- <{/if}> +
+

<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_NAME}>: <{$packages.name}>

+ <{if $packages.desc|default:''}> +

<{$smarty.const._MA_WGTRANSIFEX_PACKAGE_DESC}>: <{$packages.desc}>

+ <{/if}> +
<{foreach item=pkglang from=$packages.langs}> -
+
- <{$pkglang.lang_id}> - <{$pkglang.lang_id}> - <{$pkglang.traperc_text}> + <{$pkglang.lang_id}> <{$pkglang.lang_id}> + <{$pkglang.traperc_text}>  <{$pkglang.date}>
+ <{include file='db:wgtransifex_packages_prolist.tpl' packages=$packages}>