Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
d7da83ad
Commit
d7da83ad
authored
5 years ago
by
Kristof De Langhe
Browse files
Options
Downloads
Patches
Plain Diff
68729: Pagination disableRouteParameterUpdate input
parent
173f14c4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/shared/pagination/pagination.component.ts
+52
-16
52 additions, 16 deletions
src/app/shared/pagination/pagination.component.ts
with
52 additions
and
16 deletions
src/app/shared/pagination/pagination.component.ts
+
52
−
16
View file @
d7da83ad
...
...
@@ -99,6 +99,13 @@ export class PaginationComponent implements OnDestroy, OnInit {
*/
@
Input
()
public
hidePagerWhenSinglePage
=
true
;
/**
* Option for disabling updating and reading route parameters on pagination changes
* In other words, changing pagination won't add or update the url parameters on the current page, and the url
* parameters won't affect the pagination of this component
*/
@
Input
()
public
disableRouteParameterUpdate
=
false
;
/**
* Current page.
*/
...
...
@@ -173,20 +180,35 @@ export class PaginationComponent implements OnDestroy, OnInit {
this
.
checkConfig
(
this
.
paginationOptions
);
this
.
initializeConfig
();
// Listen to changes
this
.
subs
.
push
(
this
.
route
.
queryParams
.
subscribe
((
queryParams
)
=>
{
if
(
this
.
isEmptyPaginationParams
(
queryParams
))
{
this
.
initializeConfig
(
queryParams
);
if
(
!
this
.
disableRouteParameterUpdate
)
{
this
.
subs
.
push
(
this
.
route
.
queryParams
.
subscribe
((
queryParams
)
=>
{
this
.
initializeParams
(
queryParams
);
}));
}
}
/**
* Initialize the route and current parameters
* This method will fix any invalid or missing parameters
* @param params
*/
private
initializeParams
(
params
)
{
if
(
this
.
isEmptyPaginationParams
(
params
))
{
this
.
initializeConfig
(
params
);
}
else
{
this
.
currentQueryParams
=
params
;
const
fixedProperties
=
this
.
validateParams
(
params
);
if
(
isNotEmpty
(
fixedProperties
))
{
if
(
!
this
.
disableRouteParameterUpdate
)
{
this
.
fixRoute
(
fixedProperties
);
}
else
{
this
.
currentQueryParams
=
queryParams
;
const
fixedProperties
=
this
.
validateParams
(
queryParams
);
if
(
isNotEmpty
(
fixedProperties
))
{
this
.
fixRoute
(
fixedProperties
);
}
else
{
this
.
setFields
();
}
this
.
initializeParams
(
fixedProperties
);
}
}));
}
else
{
this
.
setFields
();
}
}
}
private
fixRoute
(
fixedProperties
)
{
...
...
@@ -247,7 +269,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
* The page being navigated to.
*/
public
doPageChange
(
page
:
number
)
{
this
.
update
Route
(
{
pageId
:
this
.
id
,
page
:
page
.
toString
()
});
this
.
update
Params
(
Object
.
assign
({},
this
.
currentQueryParams
,
{
pageId
:
this
.
id
,
page
:
page
.
toString
()
})
)
;
}
/**
...
...
@@ -257,7 +279,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
* The page size being navigated to.
*/
public
doPageSizeChange
(
pageSize
:
number
)
{
this
.
update
Route
(
{
pageId
:
this
.
id
,
page
:
1
,
pageSize
:
pageSize
});
this
.
update
Params
(
Object
.
assign
({},
this
.
currentQueryParams
,
{
pageId
:
this
.
id
,
page
:
1
,
pageSize
:
pageSize
})
)
;
}
/**
...
...
@@ -267,7 +289,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
* The sort direction being navigated to.
*/
public
doSortDirectionChange
(
sortDirection
:
SortDirection
)
{
this
.
update
Route
(
{
pageId
:
this
.
id
,
page
:
1
,
sortDirection
:
sortDirection
});
this
.
update
Params
(
Object
.
assign
({},
this
.
currentQueryParams
,
{
pageId
:
this
.
id
,
page
:
1
,
sortDirection
:
sortDirection
})
)
;
}
/**
...
...
@@ -277,7 +299,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
* The sort field being navigated to.
*/
public
doSortFieldChange
(
field
:
string
)
{
this
.
update
Route
(
{
pageId
:
this
.
id
,
page
:
1
,
sortField
:
field
});
this
.
update
Params
(
Object
.
assign
(
this
.
currentQueryParams
,
{
pageId
:
this
.
id
,
page
:
1
,
sortField
:
field
})
)
;
}
/**
...
...
@@ -347,6 +369,20 @@ export class PaginationComponent implements OnDestroy, OnInit {
})
}
/**
* Update the current query params and optionally update the route
* @param params
*/
private
updateParams
(
params
:
{})
{
if
(
isNotEmpty
(
difference
(
params
,
this
.
currentQueryParams
)))
{
if
(
!
this
.
disableRouteParameterUpdate
)
{
this
.
updateRoute
(
params
);
}
else
{
this
.
initializeParams
(
params
);
}
}
}
/**
* Method to update the route parameters
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment