55693: Authentication Guard and TSDocs

This commit is contained in:
Kristof De Langhe
2018-10-01 14:14:26 +02:00
parent 5f56d5959d
commit 24f6f982e9
3 changed files with 77 additions and 1 deletions

View File

@@ -28,13 +28,37 @@ import { TranslateService } from '@ngx-translate/core';
fadeInOut
]
})
/**
* Collection used to map items to a collection
*/
export class CollectionItemMapperComponent implements OnInit {
/**
* The collection to map items to
*/
collectionRD$: Observable<RemoteData<Collection>>;
/**
* Search options
*/
searchOptions$: Observable<PaginatedSearchOptions>;
/**
* List of items to show under the "Browse" tab
* Items inside the collection
*/
collectionItemsRD$: Observable<RemoteData<PaginatedList<DSpaceObject>>>;
/**
* List of items to show under the "Map" tab
* Items outside the collection
*/
mappingItemsRD$: Observable<RemoteData<PaginatedList<DSpaceObject>>>;
/**
* Sort on title ASC by default
* @type {SortOptions}
*/
defaultSortOptions: SortOptions = new SortOptions('dc.title', SortDirection.ASC);
constructor(private route: ActivatedRoute,
@@ -52,6 +76,11 @@ export class CollectionItemMapperComponent implements OnInit {
this.loadItemLists();
}
/**
* Load collectionItemsRD$ with a fixed scope to only obtain the items this collection owns
* Load mappingItemsRD$ to only obtain items this collection doesn't own
* TODO: When the API support it, fetch items excluding the collection's scope (currently fetches all items)
*/
loadItemLists() {
const collectionAndOptions$ = Observable.combineLatest(
this.collectionRD$,
@@ -79,6 +108,10 @@ export class CollectionItemMapperComponent implements OnInit {
);
}
/**
* Map the selected items to the collection and display notifications
* @param {string[]} ids The list of item UUID's to map to the collection
*/
mapItems(ids: string[]) {
const responses$ = this.collectionRD$.pipe(
getSucceededRemoteData(),
@@ -112,12 +145,20 @@ export class CollectionItemMapperComponent implements OnInit {
});
}
/**
* Clear url parameters on tab change (temporary fix until pagination is improved)
* @param event
*/
tabChange(event) {
// TODO: Fix tabs to maintain their own pagination options (once the current pagination system is improved)
// Temporary solution: Clear url params when changing tabs
this.router.navigateByUrl(this.getCurrentUrl());
}
/**
* Get current url without parameters
* @returns {string}
*/
getCurrentUrl(): string {
if (this.router.url.indexOf('?') > -1) {
return this.router.url.substring(0, this.router.url.indexOf('?'));

View File

@@ -4,6 +4,7 @@ import { RouterModule } from '@angular/router';
import { CollectionPageComponent } from './collection-page.component';
import { CollectionPageResolver } from './collection-page.resolver';
import { CollectionItemMapperComponent } from './collection-item-mapper/collection-item-mapper.component';
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
@NgModule({
imports: [
@@ -22,7 +23,8 @@ import { CollectionItemMapperComponent } from './collection-item-mapper/collecti
pathMatch: 'full',
resolve: {
collection: CollectionPageResolver
}
},
canActivate: [AuthenticatedGuard]
}
])
],

View File

@@ -14,20 +14,40 @@ import { take } from 'rxjs/operators';
templateUrl: './item-select.component.html'
})
/**
* A component used to select items from a specific list and returning the UUIDs of the selected items
*/
export class ItemSelectComponent implements OnInit {
/**
* The list of items to display
*/
@Input()
itemsRD$: Observable<RemoteData<PaginatedList<Item>>>;
/**
* The pagination options used to display the items
*/
@Input()
paginationOptions: PaginationComponentOptions;
/**
* The message key used for the confirm button
* @type {string}
*/
@Input()
confirmButton = 'item.select.confirm';
/**
* EventEmitter to return the selected UUIDs when the confirm button is pressed
* @type {EventEmitter<string[]>}
*/
@Output()
confirm: EventEmitter<string[]> = new EventEmitter<string[]>();
/**
* The list of selected UUIDs
*/
selectedIds$: Observable<string[]>;
constructor(private itemSelectService: ItemSelectService) {
@@ -37,14 +57,27 @@ export class ItemSelectComponent implements OnInit {
this.selectedIds$ = this.itemSelectService.getAllSelected();
}
/**
* Switch the state of a checkbox
* @param {string} id
*/
switch(id: string) {
this.itemSelectService.switch(id);
}
/**
* Get the current state of a checkbox
* @param {string} id The item's UUID
* @returns {Observable<boolean>}
*/
getSelected(id: string): Observable<boolean> {
return this.itemSelectService.getSelected(id);
}
/**
* Called when the confirm button is pressed
* Sends the selected UUIDs to the parent component
*/
confirmSelected() {
this.selectedIds$.pipe(
take(1)