Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sites manager first last buttons #12276

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lang/en.json
Expand Up @@ -234,6 +234,7 @@
"IP": "IP",
"JsTrackingTag": "JavaScript Tracking Code",
"Language": "Language",
"Last": "Last",
"Languages": "Languages",
"LastDays": "Last %s days (including today)",
"LastDaysShort": "Last %s days",
Expand Down
8 changes: 4 additions & 4 deletions plugins/SitesManager/API.php
Expand Up @@ -319,12 +319,12 @@ public function getSitesIdWithVisits($timestamp = false)
* @param false|int $limit
* @return array for each site, an array of information (idsite, name, main_url, etc.)
*/
public function getSitesWithAdminAccess($fetchAliasUrls = false, $pattern = false, $limit = false)
public function getSitesWithAdminAccess($fetchAliasUrls = false, $pattern = false, $limit = false, $offset = false)
{
$sitesId = $this->getSitesIdWithAdminAccess();

if ($pattern === false) {
$sites = $this->getSitesFromIds($sitesId, $limit);
$sites = $this->getSitesFromIds($sitesId, $limit, $offset);
} else {
$sites = $this->getModel()->getPatternMatchSites($sitesId, $pattern, $limit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offset would need to be applied here as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in getPatternMatchSites

Site::setSitesFromArray($sites);
Expand Down Expand Up @@ -437,9 +437,9 @@ public function getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin = false)
* @param bool $limit
* @return array
*/
private function getSitesFromIds($idSites, $limit = false)
private function getSitesFromIds($idSites, $limit = false, $offset = false)
{
$sites = $this->getModel()->getSitesFromIds($idSites, $limit);
$sites = $this->getModel()->getSitesFromIds($idSites, $limit, $offset);

Site::setSitesFromArray($sites);

Expand Down
5 changes: 4 additions & 1 deletion plugins/SitesManager/Model.php
Expand Up @@ -198,14 +198,17 @@ public function deleteSite($idSite)
* @param bool $limit
* @return array
*/
public function getSitesFromIds($idSites, $limit = false)
public function getSitesFromIds($idSites, $limit = false, $offset = false)
{
if (count($idSites) === 0) {
return array();
}

if ($limit) {
$limit = "LIMIT " . (int)$limit;
if ($offset) {
$limit = $limit . " OFFSET " . (int)$offset;
}
} else {
$limit = '';
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/SitesManager.php
Expand Up @@ -301,8 +301,10 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "General_OrCancel";
$translationKeys[] = "General_Actions";
$translationKeys[] = "General_Search";
$translationKeys[] = "General_First";
$translationKeys[] = "General_Previous";
$translationKeys[] = "General_Next";
$translationKeys[] = "General_Last";
$translationKeys[] = "General_Pagination";
$translationKeys[] = "General_Cancel";
$translationKeys[] = "General_ClickToSearch";
Expand Down
Expand Up @@ -4,9 +4,9 @@
(function () {
angular.module('piwikApp').factory('sitesManagerAdminSitesModel', sitesManagerAdminSitesModel);

sitesManagerAdminSitesModel.$inject = ['piwikApi'];
sitesManagerAdminSitesModel.$inject = ['piwikApi', 'sitesManagerAPI'];

function sitesManagerAdminSitesModel(piwikApi)
function sitesManagerAdminSitesModel(piwikApi, sitesManagerAPI)
{
var model = {
sites : [],
Expand All @@ -16,10 +16,14 @@
currentPage : 0,
offsetStart : 0,
offsetEnd : 10,
hasFirst : false,
hasPrev : false,
hasNext : false,
hasLast : false,
firstPage: firstPage,
previousPage: previousPage,
nextPage: nextPage,
lastPage: lastPage,
searchSite: searchSite,
fetchLimitedSitesWithAdminAccess: fetchLimitedSitesWithAdminAccess
};
Expand All @@ -38,8 +42,10 @@
var numSites = sites.length;
model.offsetStart = model.currentPage * model.pageSize;
model.offsetEnd = model.offsetStart + numSites;
model.hasFirst = model.currentPage >= 1;
model.hasPrev = model.currentPage >= 1;
model.hasNext = numSites === model.pageSize;
model.hasLast = numSites === model.pageSize;
}

function setCurrentPage(page)
Expand All @@ -51,6 +57,12 @@
model.currentPage = page;
}

function firstPage()
{
setCurrentPage(0);
fetchLimitedSitesWithAdminAccess();
}

function previousPage()
{
setCurrentPage(model.currentPage - 1);
Expand All @@ -63,6 +75,16 @@
fetchLimitedSitesWithAdminAccess();
}

function lastPage()
{
sitesManagerAPI.getSitesIdWithAdminAccess(function (siteIds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it, but I reckon it might not work when the user is currently searching for a site and then goes to the last page because I think here getSitesIdWithAdminAccess would return really all sites whereas the number of results be lower when searching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes you are right.

if (siteIds && siteIds.length) {
setCurrentPage(Math.floor(siteIds.length / model.pageSize));
fetchLimitedSitesWithAdminAccess();
}
});
}

function searchSite (term)
{
model.searchTerm = term;
Expand All @@ -84,8 +106,9 @@
var params = {
method: 'SitesManager.getSitesWithAdminAccess',
fetchAliasUrls: true,
limit: limit + offset, // this is applied in SitesManager.getSitesWithAdminAccess API
filter_offset: offset, // filter_offset and filter_limit is applied in response builder
limit: limit, // this is applied in SitesManager.getSitesWithAdminAccess API
offset: offset, // this is applied in SitesManager.getSitesWithAdminAccess API
filter_offset: 0, // filter_offset and filter_limit is applied in response builder
filter_limit: limit
};

Expand Down
12 changes: 9 additions & 3 deletions plugins/SitesManager/templates/sites-list/add-site-link.html
Expand Up @@ -6,18 +6,21 @@
{{ availableTypes.length > 1 ? ('SitesManager_AddMeasurable'|translate) : ('SitesManager_AddSite'|translate) }}
</a>

<div class="search" ng-show="adminSites.hasPrev || adminSites.hasNext || adminSites.searchTerm">
<div class="search" ng-show="adminSites.hasFirst || adminSites.hasPrev || adminSites.hasNext || adminSites.hasLast || adminSites.searchTerm">
<input ng-model="adminSites.search" piwik-onenter="adminSites.searchSite(adminSites.search)"
placeholder="{{ 'Actions_SubmenuSitesearch' | translate }}" type="text">
<img ng-click="adminSites.searchSite(adminSites.search)" title="{{ 'General_ClickToSearch' | translate }}"
class="search_ico" src="plugins/Morpheus/images/search_ico.png"/>
</div>

<div class="paging" ng-show="adminSites.hasPrev || adminSites.hasNext">
<div class="paging" ng-show="adminSites.hasFirst || adminSites.hasPrev || adminSites.hasNext || adminSites.hasLast">
<a class="btn first" ng-disabled="!adminSites.hasFirst" ng-click="adminSites.firstPage()">
<span style="cursor:pointer;">&#171; {{ 'General_First'|translate }}</span>
</a>
<a class="btn prev" ng-disabled="!adminSites.hasPrev" ng-click="adminSites.previousPage()">
<span style="cursor:pointer;">&#171; {{ 'General_Previous'|translate }}</span>
</a>
<span class="counter" ng-show="adminSites.hasPrev || adminSites.hasNext">
<span class="counter" ng-show="adminSites.hasFirst || adminSites.hasPrev || adminSites.hasNext || adminSites.hasLast">
<span ng-if="adminSites.searchTerm">
{{ 'General_PaginationWithoutTotal'|translate:adminSites.offsetStart:adminSites.offsetEnd }}
</span>
Expand All @@ -28,6 +31,9 @@
<a class="btn next" ng-disabled="!adminSites.hasNext" ng-click="adminSites.nextPage()">
<span style="cursor:pointer;" class="pointer">{{ 'General_Next'|translate }} &#187;</span>
</a>
<a class="btn last" ng-disabled="!adminSites.hasLast" ng-click="adminSites.lastPage()">
<span style="cursor:pointer;" class="pointer">{{ 'General_Last'|translate }} &#187;</span>
</a>
</div>

</div>