44024: simple search finalisation

This commit is contained in:
Lotte Hofstede
2017-09-05 17:09:17 +02:00
parent 29d04c06b9
commit 872984e505
16 changed files with 62 additions and 28 deletions

View File

@@ -20,4 +20,6 @@ html {
.main-content { .main-content {
flex: 1 0 auto; flex: 1 0 auto;
margin-top: $content-spacing;
margin-bottom: $content-spacing;
} }

View File

@@ -3,6 +3,8 @@
display: block; display: block;
margin-right: ($grid-gutter-width / -2); margin-right: ($grid-gutter-width / -2);
margin-left: ($grid-gutter-width / -2); margin-left: ($grid-gutter-width / -2);
margin-top: -$content-spacing;
margin-bottom: -$content-spacing;
} }
.dspace-logo-container { .dspace-logo-container {

View File

@@ -1,2 +1,3 @@
<ds-home-news></ds-home-news> <ds-home-news></ds-home-news>
<ds-search-form></ds-search-form>
<ds-top-level-community-list></ds-top-level-community-list> <ds-top-level-community-list></ds-top-level-community-list>

View File

@@ -7,7 +7,7 @@ import { Collection } from '../../../core/shared/collection.model';
@Component({ @Component({
selector: 'ds-collection-search-result-list-element', selector: 'ds-collection-search-result-list-element',
styleUrls: ['collection-search-result-list-element.component.scss'], styleUrls: ['../search-result-list-element.component.scss', 'collection-search-result-list-element.component.scss'],
templateUrl: 'collection-search-result-list-element.component.html' templateUrl: 'collection-search-result-list-element.component.html'
}) })

View File

@@ -7,7 +7,7 @@ import { Community } from '../../../core/shared/community.model';
@Component({ @Component({
selector: 'ds-community-search-result-list-element', selector: 'ds-community-search-result-list-element',
styleUrls: ['community-search-result-list-element.component.scss'], styleUrls: ['../search-result-list-element.component.scss', 'community-search-result-list-element.component.scss'],
templateUrl: 'community-search-result-list-element.component.html' templateUrl: 'community-search-result-list-element.component.html'
}) })

View File

@@ -7,7 +7,7 @@ import { Item } from '../../../core/shared/item.model';
@Component({ @Component({
selector: 'ds-item-search-result-list-element', selector: 'ds-item-search-result-list-element',
styleUrls: ['item-search-result-list-element.component.scss'], styleUrls: ['../search-result-list-element.component.scss', 'item-search-result-list-element.component.scss'],
templateUrl: 'item-search-result-list-element.component.html' templateUrl: 'item-search-result-list-element.component.html'
}) })

View File

@@ -0,0 +1,7 @@
@import '../../../styles/shared_imports.scss';
:host {
/deep/ em {
font-weight: bold;
font-style: normal;
}
}

View File

@@ -1,4 +1,4 @@
<div class="search-page"> <div class="search-page">
<ds-search-form (formSubmit)="updateSearch($event)" [query]="query"></ds-search-form> <ds-search-form [query]="query" [scope]="(scopeObject?.payload | async)" [currentParams]="currentParams"></ds-search-form>
<ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results> <ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results>
</div> </div>

View File

@@ -7,6 +7,8 @@ import { DSpaceObject } from '../core/shared/dspace-object.model';
import { SortOptions } from '../core/cache/models/sort-options.model'; import { SortOptions } from '../core/cache/models/sort-options.model';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { SearchOptions } from '../search/search-options.model'; import { SearchOptions } from '../search/search-options.model';
import { CommunityDataService } from '../core/data/community-data.service';
import { hasValue } from '../shared/empty.util';
/** /**
* This component renders a simple item page. * This component renders a simple item page.
@@ -23,6 +25,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
private sub; private sub;
query: string; query: string;
private scope: string; private scope: string;
scopeObject: RemoteData<DSpaceObject>;
private page: number; private page: number;
results: RemoteData<Array<SearchResult<DSpaceObject>>>; results: RemoteData<Array<SearchResult<DSpaceObject>>>;
private currentParams = {}; private currentParams = {};
@@ -30,7 +33,8 @@ export class SearchPageComponent implements OnInit, OnDestroy {
constructor(private service: SearchService, constructor(private service: SearchService,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router,) { private communityService: CommunityDataService,
) {
} }
ngOnInit(): void { ngOnInit(): void {
@@ -48,6 +52,11 @@ export class SearchPageComponent implements OnInit, OnDestroy {
const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection); const sort: SortOptions = new SortOptions(params.sortField, params.sortDirection);
this.searchOptions = {pagination: pagination, sort: sort}; this.searchOptions = {pagination: pagination, sort: sort};
this.results = this.service.search(this.query, this.scope, this.searchOptions); this.results = this.service.search(this.query, this.scope, this.searchOptions);
if (hasValue(this.scope)) {
this.scopeObject = this.communityService.findById(this.scope);
} else {
this.scopeObject = undefined;
}
} }
); );
} }
@@ -55,17 +64,4 @@ export class SearchPageComponent implements OnInit, OnDestroy {
ngOnDestroy() { ngOnDestroy() {
this.sub.unsubscribe(); this.sub.unsubscribe();
} }
updateSearch(data: any) {
this.router.navigate([], {
queryParams: Object.assign({}, this.currentParams,
{
query: data.query,
scope: data.scope,
page: data.page || 1
}
)
})
;
}
} }

View File

@@ -25,7 +25,6 @@ import { CommunitySearchResultListElementComponent } from '../object-list/search
], ],
declarations: [ declarations: [
SearchPageComponent, SearchPageComponent,
SearchFormComponent,
SearchResultsComponent, SearchResultsComponent,
ItemSearchResultListElementComponent, ItemSearchResultListElementComponent,
CollectionSearchResultListElementComponent, CollectionSearchResultListElementComponent,

View File

@@ -1,8 +1,8 @@
<form #form="ngForm" (ngSubmit)="onSubmit(form.value)"> <form #form="ngForm" (ngSubmit)="onSubmit(form.value, scope?.id)">
<div class="form-group input-group"> <div class="form-group input-group">
<input type="text" [ngModel]="query" name="query" class="form-control" aria-label="Search input"> <input type="text" [ngModel]="query" name="query" class="form-control" aria-label="Search input">
<div class="input-group-btn" ngbDropdown> <div class="input-group-btn" ngbDropdown>
<button type="submit" class="btn btn-secondary">{{ 'search.form.search_dspace' | translate }}</button> <button type="submit" class="search-button btn btn-secondary">{{ scope ? scope.name : ('search.form.search_dspace' | translate) }}</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" id="searchDropdown" ngbDropdownToggle> aria-haspopup="true" aria-expanded="false" id="searchDropdown" ngbDropdownToggle>
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>

View File

@@ -1,4 +1,6 @@
import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core'; import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { Router, ActivatedRoute } from '@angular/router';
/** /**
* This component renders a simple item page. * This component renders a simple item page.
@@ -12,11 +14,31 @@ import { Component, OnInit, EventEmitter, Output, Input } from '@angular/core';
templateUrl: './search-form.component.html', templateUrl: './search-form.component.html',
}) })
export class SearchFormComponent { export class SearchFormComponent {
@Output() formSubmit: EventEmitter<any> = new EventEmitter<any>();
@Input() query: string; @Input() query: string;
@Input() scope: DSpaceObject;
onSubmit(form: any, scope?: string) { // Optional existing search parameters
@Input() currentParams: {};
constructor(private router: Router) {
}
onSubmit(form: any, scope ?: string) {
const data: any = Object.assign({}, form, { scope: scope }); const data: any = Object.assign({}, form, { scope: scope });
this.formSubmit.emit(data); this.updateSearch(data);
}
updateSearch(data: any) {
this.router.navigate(['/search'], {
queryParams: Object.assign({}, this.currentParams,
{
query: data.query,
scope: data.scope,
page: data.page || 1
}
)
})
;
} }
} }

View File

@@ -26,6 +26,7 @@ import { CollectionListElementComponent } from '../object-list/collection-list-e
import { TruncatePipe } from './utils/truncate.pipe'; import { TruncatePipe } from './utils/truncate.pipe';
import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component';
import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component';
import { SearchFormComponent } from './search-form/search-form.component';
const MODULES = [ const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here // Do NOT include UniversalModule, HttpModule, or JsonpModule here
@@ -55,7 +56,8 @@ const COMPONENTS = [
ComcolPageLogoComponent, ComcolPageLogoComponent,
ObjectListComponent, ObjectListComponent,
ObjectListElementComponent, ObjectListElementComponent,
WrapperListElementComponent WrapperListElementComponent,
SearchFormComponent
]; ];
const ENTRY_COMPONENTS = [ const ENTRY_COMPONENTS = [

View File

@@ -28,3 +28,4 @@ $theme-colors: (
) !default; ) !default;
/* Fonts */ /* Fonts */
$link-color: map-get($theme-colors, info) !default; $link-color: map-get($theme-colors, info) !default;

View File

@@ -0,0 +1 @@
$content-spacing: $spacer * 1.5;

View File

@@ -1,4 +1,5 @@
@import 'variables.scss'; @import 'bootstrap_variables.scss';
@import '../../node_modules/bootstrap/scss/bootstrap.scss'; @import '../../node_modules/bootstrap/scss/bootstrap.scss';
@import "../../node_modules/font-awesome/scss/font-awesome.scss"; @import "../../node_modules/font-awesome/scss/font-awesome.scss";
@import 'mixins.scss'; @import 'mixins.scss';
@import 'custom_variables.scss';