search-form.component.ts (dspace-angular-dspace-7.0) | : | search-form.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { Component, EventEmitter, Input, Output } from '@angular/core'; | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | |||
import { DSpaceObject } from '../../core/shared/dspace-object.model'; | import { DSpaceObject } from '../../core/shared/dspace-object.model'; | |||
import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | |||
import { isNotEmpty } from '../empty.util'; | import { isNotEmpty } from '../empty.util'; | |||
import { SearchService } from '../../core/shared/search/search.service'; | import { SearchService } from '../../core/shared/search/search.service'; | |||
import { currentPath } from '../utils/route.utils'; | import { currentPath } from '../utils/route.utils'; | |||
import { PaginationService } from '../../core/pagination/pagination.service'; | import { PaginationService } from '../../core/pagination/pagination.service'; | |||
import { SearchConfigurationService } from '../../core/shared/search/search-conf iguration.service'; | import { SearchConfigurationService } from '../../core/shared/search/search-conf iguration.service'; | |||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||||
import { ScopeSelectorModalComponent } from './scope-selector-modal/scope-select | ||||
or-modal.component'; | ||||
import { take } from 'rxjs/operators'; | ||||
import { BehaviorSubject } from 'rxjs'; | ||||
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv | ||||
ice'; | ||||
import { getFirstSucceededRemoteDataPayload } from '../../core/shared/operators' | ||||
; | ||||
/** | /** | |||
* This component renders a simple item page. | * This component renders a simple item page. | |||
* The route parameter 'id' is used to request the item it represents. | * The route parameter 'id' is used to request the item it represents. | |||
* All fields of the item that should be displayed, are defined in its template. | * All fields of the item that should be displayed, are defined in its template. | |||
*/ | */ | |||
@Component({ | @Component({ | |||
selector: 'ds-search-form', | selector: 'ds-search-form', | |||
styleUrls: ['./search-form.component.scss'], | styleUrls: ['./search-form.component.scss'], | |||
templateUrl: './search-form.component.html' | templateUrl: './search-form.component.html' | |||
}) | }) | |||
/** | /** | |||
* Component that represents the search form | * Component that represents the search form | |||
*/ | */ | |||
export class SearchFormComponent { | export class SearchFormComponent implements OnInit { | |||
/** | /** | |||
* The search query | * The search query | |||
*/ | */ | |||
@Input() query: string; | @Input() query: string; | |||
/** | /** | |||
* True when the search component should show results on the current page | * True when the search component should show results on the current page | |||
*/ | */ | |||
@Input() inPlaceSearch; | @Input() inPlaceSearch; | |||
/** | /** | |||
* The currently selected scope object's UUID | * The currently selected scope object's UUID | |||
*/ | */ | |||
@Input() | @Input() | |||
scope = ''; | scope = ''; | |||
@Input() currentUrl: string; | selectedScope: BehaviorSubject<DSpaceObject> = new BehaviorSubject<DSpaceObjec t>(undefined); | |||
/** | @Input() currentUrl: string; | |||
* The available scopes | ||||
*/ | ||||
@Input() scopes: DSpaceObject[]; | ||||
/** | /** | |||
* Whether or not the search button should be displayed large | * Whether or not the search button should be displayed large | |||
*/ | */ | |||
@Input() large = false; | @Input() large = false; | |||
/** | /** | |||
* The brand color of the search button | * The brand color of the search button | |||
*/ | */ | |||
@Input() brandColor = 'primary'; | @Input() brandColor = 'primary'; | |||
/** | /** | |||
* The placeholder of the search input | * The placeholder of the search input | |||
*/ | */ | |||
@Input() searchPlaceholder: string; | @Input() searchPlaceholder: string; | |||
/** | /** | |||
* Defines whether or not to show the scope selector | ||||
*/ | ||||
@Input() showScopeSelector = false; | ||||
/** | ||||
* Output the search data on submit | * Output the search data on submit | |||
*/ | */ | |||
@Output() submitSearch = new EventEmitter<any>(); | @Output() submitSearch = new EventEmitter<any>(); | |||
constructor(private router: Router, private searchService: SearchService, | constructor(private router: Router, | |||
private searchService: SearchService, | ||||
private paginationService: PaginationService, | private paginationService: PaginationService, | |||
private searchConfig: SearchConfigurationService | private searchConfig: SearchConfigurationService, | |||
) { | private modalService: NgbModal, | |||
private dsoService: DSpaceObjectDataService | ||||
) { | ||||
} | ||||
/** | ||||
* Retrieve the scope object from the URL so we can show its name | ||||
*/ | ||||
ngOnInit(): void { | ||||
if (isNotEmpty(this.scope)) { | ||||
this.dsoService.findById(this.scope).pipe(getFirstSucceededRemoteDataPaylo | ||||
ad()) | ||||
.subscribe((scope: DSpaceObject) => this.selectedScope.next(scope)); | ||||
} | ||||
} | } | |||
/** | /** | |||
* Updates the search when the form is submitted | * Updates the search when the form is submitted | |||
* @param data Values submitted using the form | * @param data Values submitted using the form | |||
*/ | */ | |||
onSubmit(data: any) { | onSubmit(data: any) { | |||
this.updateSearch(data); | this.updateSearch(data); | |||
this.submitSearch.emit(data); | this.submitSearch.emit(data); | |||
} | } | |||
/** | /** | |||
* Updates the search when the current scope has been changed | * Updates the search when the current scope has been changed | |||
* @param {string} scope The new scope | * @param {string} scope The new scope | |||
*/ | */ | |||
onScopeChange(scope: string) { | onScopeChange(scope: DSpaceObject) { | |||
this.updateSearch({ scope }); | this.updateSearch({ scope: scope ? scope.uuid : undefined }); | |||
} | } | |||
/** | /** | |||
* Updates the search URL | * Updates the search URL | |||
* @param data Updated parameters | * @param data Updated parameters | |||
*/ | */ | |||
updateSearch(data: any) { | updateSearch(data: any) { | |||
const queryParams = Object.assign({}, data); | const queryParams = Object.assign({}, data); | |||
const pageParam = this.paginationService.getPageParam(this.searchConfig.pa | const pageParam = this.paginationService.getPageParam(this.searchConfig.pagi | |||
ginationID); | nationID); | |||
queryParams[pageParam] = 1; | queryParams[pageParam] = 1; | |||
this.router.navigate(this.getSearchLinkParts(), { | this.router.navigate(this.getSearchLinkParts(), { | |||
queryParams: queryParams, | queryParams: queryParams, | |||
queryParamsHandling: 'merge' | queryParamsHandling: 'merge' | |||
}); | }); | |||
this.paginationService.updateRouteWithUrl(this.searchConfig.paginationID, th is.getSearchLinkParts(), { page: 1 }, data); | this.paginationService.updateRouteWithUrl(this.searchConfig.paginationID, th is.getSearchLinkParts(), { page: 1 }, data); | |||
} | } | |||
/** | /** | |||
* For usage of the isNotEmpty function in the template | * For usage of the isNotEmpty function in the template | |||
*/ | */ | |||
isNotEmpty(object: any) { | isNotEmpty(object: any) { | |||
skipping to change at line 134 | skipping to change at line 155 | |||
/** | /** | |||
* @returns {string[]} The base path to the search page, or the current page w hen inPlaceSearch is true, split in separate pieces | * @returns {string[]} The base path to the search page, or the current page w hen inPlaceSearch is true, split in separate pieces | |||
*/ | */ | |||
public getSearchLinkParts(): string[] { | public getSearchLinkParts(): string[] { | |||
if (this.inPlaceSearch) { | if (this.inPlaceSearch) { | |||
return []; | return []; | |||
} | } | |||
return this.getSearchLink().split('/'); | return this.getSearchLink().split('/'); | |||
} | } | |||
/** | ||||
* Open the scope modal so the user can select DSO as scope | ||||
*/ | ||||
openScopeModal() { | ||||
const ref = this.modalService.open(ScopeSelectorModalComponent); | ||||
ref.componentInstance.scopeChange.pipe(take(1)).subscribe((scope: DSpaceObje | ||||
ct) => { | ||||
this.selectedScope.next(scope); | ||||
this.onScopeChange(scope); | ||||
}); | ||||
} | ||||
} | } | |||
End of changes. 12 change blocks. | ||||
17 lines changed or deleted | 54 lines changed or added |