This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Viliam Rockai
committed
May 28, 2015
1 parent
dad695a
commit 713f255
Showing
4 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ui/console/src/main/scripts/plugins/metrics/plugins/metrics/html/url-pagination.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="text-center hk-fade-in"> | ||
<ul class="pagination" ng-show="goTos.length > 1"> | ||
<li> | ||
<a href="#" ng-click="setPage(currentPage - 1)"> | ||
<span class="i fa fa-angle-left"></span> | ||
</a> | ||
</li> | ||
<li ng-repeat="i in goTos track by $index" | ||
ng-class="{'active' : currentPage === {{$index}}}"> | ||
<a href="#" ng-click="setPage($index)">{{$index+1}}</a> | ||
</li> | ||
<li> | ||
<a href="#" ng-click="setPage(currentPage + 1)"> | ||
<span class="i fa fa-angle-right"></span> | ||
</a> | ||
</li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
ui/console/src/main/scripts/plugins/metrics/plugins/metrics/ts/pagination.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/// | ||
/// Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
/// | ||
|
||
/// <reference path="metricsPlugin.ts"/> | ||
/// <reference path="../../includes.ts"/> | ||
|
||
module HawkularMetrics { | ||
|
||
export interface IHkHeaderParser { | ||
parse(headers: any): any; | ||
} | ||
|
||
export class HkHeaderParser implements IHkHeaderParser { | ||
|
||
public static $inject = []; | ||
|
||
private PARAMETER_EXPRESSION = /(rel)="(\w+)"/; | ||
private total = 0; | ||
|
||
private parseLinkHeader(value): any { | ||
var relationLinks = {}; | ||
|
||
if (!value) { | ||
return relationLinks; | ||
} | ||
|
||
var links = value.split(', '); | ||
|
||
for (var i = 0; i < links.length; i++) { | ||
var linkParts = links[i].split('>'); | ||
var linkHref = linkParts[0].substring(1); | ||
var linkRelationParameterString = linkParts[1]; | ||
var linkRelationParameterParts = this.PARAMETER_EXPRESSION.exec(linkRelationParameterString); | ||
|
||
// Get the relation name for current Link | ||
if (linkRelationParameterParts && linkRelationParameterParts[1] === 'rel' && linkRelationParameterParts[2]) { | ||
//debugger; | ||
relationLinks[linkRelationParameterParts[2]] = { | ||
href: linkHref | ||
}; | ||
|
||
// Get the parameters (page, per_page, ...) of current link | ||
relationLinks[linkRelationParameterParts[2]]['params'] = {}; | ||
|
||
var linkHrefParts = linkHref.split('?'); | ||
var linkHrefParametersString = linkHrefParts[1]; | ||
var hrefParamsPairStringParts = linkHrefParametersString.split('&'); | ||
for (var j = 0; j < hrefParamsPairStringParts.length; j++) { | ||
var parameterPair = hrefParamsPairStringParts[j]; | ||
var parameterPairParts = parameterPair.split('='); | ||
|
||
if (parameterPairParts[0] && parameterPairParts[1]) { | ||
relationLinks[linkRelationParameterParts[2]]['params'][parameterPairParts[0]] = parameterPairParts[1]; | ||
} | ||
} | ||
} | ||
} | ||
return relationLinks; | ||
} | ||
|
||
parse(headers: any): any { | ||
return { | ||
total: headers['x-total-count'], | ||
rel: this.parseLinkHeader(headers.link) | ||
}; | ||
} | ||
}; | ||
|
||
_module.service('HkHeaderParser', HkHeaderParser); | ||
|
||
class HkPagination { | ||
public link: (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => void; | ||
public templateUrl = 'plugins/metrics/html/url-pagination.html'; | ||
public scope = { | ||
resourceList: '=', | ||
currentPage: '=', | ||
linkHeader: '=', | ||
pageSetter: '&', | ||
perPage: '=', | ||
headers: '=' | ||
}; | ||
public replace = 'true'; | ||
|
||
constructor(/*list of dependencies*/) { | ||
this.link = (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => { | ||
|
||
scope.setPage = function(pageNumber){ | ||
var pagesNumber = Math.ceil((scope.headers.total || 1) / scope.perPage); | ||
|
||
if (pageNumber < 1) { | ||
scope.pageSetter({pageNumber: 0}); | ||
} else if (pageNumber >= pagesNumber) { | ||
scope.pageSetter({pageNumber: pagesNumber - 1}); | ||
} else { | ||
scope.pageSetter({pageNumber: pageNumber}); | ||
} | ||
}; | ||
|
||
scope.goTos = [0]; | ||
scope.$watchGroup(['headers', 'perPage'], () => { | ||
var pagesNumber = Math.ceil((scope.headers.total || 1) / scope.perPage); | ||
console.log('pagesNumber', pagesNumber); | ||
scope.goTos = new Array(pagesNumber); | ||
}); | ||
|
||
}; | ||
} | ||
|
||
public static Factory() { | ||
var directive = () => { | ||
return new HkPagination(); | ||
}; | ||
|
||
directive['$inject'] = []; | ||
|
||
return directive; | ||
} | ||
} | ||
|
||
_module.directive('hkPagination', HkPagination.Factory()); | ||
} |