diff --git a/src/app/main/model/search/eventsSearch.model.ts b/src/app/main/model/search/eventsSearch.model.ts index b5ad483536..abecaaa015 100644 --- a/src/app/main/model/search/eventsSearch.model.ts +++ b/src/app/main/model/search/eventsSearch.model.ts @@ -1,6 +1,5 @@ export interface EventsSearchModel { id: number; title: string; - creationDate: string; - tags: Array; + tags: string[]; } diff --git a/src/app/main/model/search/newsSearch.model.ts b/src/app/main/model/search/newsSearch.model.ts index 71bbd8bd91..8b1b81e898 100644 --- a/src/app/main/model/search/newsSearch.model.ts +++ b/src/app/main/model/search/newsSearch.model.ts @@ -1,10 +1,5 @@ export interface NewsSearchModel { id: number; title: string; - author: { - id: number; - name: string; - }; - creationDate: string; - tags: Array; + tags: string[]; } diff --git a/src/app/main/model/search/placesSearch.model.ts b/src/app/main/model/search/placesSearch.model.ts new file mode 100644 index 0000000000..8fdf08d754 --- /dev/null +++ b/src/app/main/model/search/placesSearch.model.ts @@ -0,0 +1,5 @@ +export interface PlacesSearchModel { + id: number; + name: string; + category: string; +} diff --git a/src/app/main/model/search/search.model.ts b/src/app/main/model/search/search.model.ts index ae64286a46..8fe72c8e6e 100644 --- a/src/app/main/model/search/search.model.ts +++ b/src/app/main/model/search/search.model.ts @@ -1,17 +1,6 @@ -import { NewsSearchModel } from './newsSearch.model'; -import { TipsSearchModel } from './tipsSearch.model'; -import { EventsSearchModel } from './eventsSearch.model'; - -export interface SearchModel { - countOfResults: number; - ecoNews: Array; - events: Array; - tipsAndTricks: Array; -} - -export interface SearchDataModel { +export interface SearchDataModel { currentPage: number; - page: Array; + page: Array; totalElements: number; totalPages: number; } diff --git a/src/app/main/service/search/search.service.ts b/src/app/main/service/search/search.service.ts index 81a011c20c..7a6b81087d 100644 --- a/src/app/main/service/search/search.service.ts +++ b/src/app/main/service/search/search.service.ts @@ -2,8 +2,9 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { environment } from '@environment/environment'; import { Observable, Subject } from 'rxjs'; -import { SearchDataModel, SearchModel } from '../../model/search/search.model'; +import { SearchDataModel } from '../../model/search/search.model'; import { SearchDto } from 'src/app/main/component/layout/components/models/search-dto'; +import { SearchCategory } from 'src/app/shared/search-popup/search-consts'; @Injectable({ providedIn: 'root' @@ -15,8 +16,8 @@ export class SearchService { allSearchSubject = new Subject(); allElements: SearchDto; - getAllResults(searchQuery: string, category, lang: string): Observable { - return this.http.get(`${this.backEndLink}search/${category}?lang=${lang}&searchQuery=${encodeURI(searchQuery)}`); + getAllResults(searchQuery: string, category: SearchCategory, lang: string): Observable { + return this.http.get(`${this.backEndLink}search/${category}?lang=${lang}&searchQuery=${encodeURI(searchQuery)}`); } getAllResultsByCat( diff --git a/src/app/shared/search-item/search-item.component.html b/src/app/shared/search-item/search-item.component.html index b4f5b73991..5dbf7fdb04 100644 --- a/src/app/shared/search-item/search-item.component.html +++ b/src/app/shared/search-item/search-item.component.html @@ -1,12 +1,10 @@
- diff --git a/src/app/shared/search-item/search-item.component.ts b/src/app/shared/search-item/search-item.component.ts index fa327d20c7..9947546e4b 100644 --- a/src/app/shared/search-item/search-item.component.ts +++ b/src/app/shared/search-item/search-item.component.ts @@ -1,16 +1,45 @@ import { userAssignedCardsIcons } from '../../main/image-pathes/profile-icons'; import { NewsSearchModel } from '@global-models/search/newsSearch.model'; import { EventsSearchModel } from '@global-models/search/eventsSearch.model'; -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { PlacesSearchModel } from '@global-models/search/placesSearch.model'; +import { CommonSearchModel } from './search-item.model'; @Component({ selector: 'app-search-item', templateUrl: './search-item.component.html', styleUrls: ['./search-item.component.scss'] }) -export class SearchItemComponent { - @Input() searchModel: NewsSearchModel | EventsSearchModel; +export class SearchItemComponent implements OnInit { + @Input() searchModel: NewsSearchModel | EventsSearchModel | PlacesSearchModel; @Input() type: string; @Output() closeSearch: EventEmitter = new EventEmitter(); profileIcons = userAssignedCardsIcons; + + commonModel: CommonSearchModel; + itemLink: (string | number)[]; + + ngOnInit(): void { + this.commonModel = this.convertToCommonModel(this.searchModel); + this.itemLink = ['/' + this.type]; + if (this.type !== 'places') { + this.itemLink.push(this.searchModel.id); + } + } + + private convertToCommonModel(model: NewsSearchModel | EventsSearchModel | PlacesSearchModel): CommonSearchModel { + if ('tags' in model) { + return { + id: model.id, + title: model.title, + tagsOrCategory: model.tags + }; + } else { + return { + id: model.id, + title: model.name, + tagsOrCategory: [model.category] + }; + } + } } diff --git a/src/app/shared/search-item/search-item.model.ts b/src/app/shared/search-item/search-item.model.ts new file mode 100644 index 0000000000..3cd0220f6d --- /dev/null +++ b/src/app/shared/search-item/search-item.model.ts @@ -0,0 +1,5 @@ +export interface CommonSearchModel { + id: number; + title: string; + tagsOrCategory: string[]; +} diff --git a/src/app/shared/search-popup/search-consts.ts b/src/app/shared/search-popup/search-consts.ts index 2aa322afd0..fbf0011eff 100644 --- a/src/app/shared/search-popup/search-consts.ts +++ b/src/app/shared/search-popup/search-consts.ts @@ -1,4 +1,5 @@ export enum SearchCategory { - NEWS = 'econews', - EVENTS = 'events' + NEWS = 'eco-news', + EVENTS = 'events', + PLACES = 'places' } diff --git a/src/app/shared/search-popup/search-popup.component.html b/src/app/shared/search-popup/search-popup.component.html index ca99cc05e8..d1ee014193 100644 --- a/src/app/shared/search-popup/search-popup.component.html +++ b/src/app/shared/search-popup/search-popup.component.html @@ -23,11 +23,13 @@
- {{ itemsFound }} {{ 'search.search-popup.items-found' | translate }} + {{ resultsCounters.total }} {{ 'search.search-popup.items-found' | translate }}
-

{{ 'search.search-popup.news' | translate }}

+

+ {{ 'search.search-popup.news' | translate }} ({{ resultsCounters.news }}) +

{{ 'search.search-popup.news' | translate }}
- diff --git a/src/app/shared/search-popup/search-popup.component.scss b/src/app/shared/search-popup/search-popup.component.scss index 1fffc7dc3c..2e6f5cd044 100644 --- a/src/app/shared/search-popup/search-popup.component.scss +++ b/src/app/shared/search-popup/search-popup.component.scss @@ -136,6 +136,10 @@ div.search-content-wrapper { display: block; } +span.counter { + opacity: 0.5; +} + @media (min-width: 576px) { .list-search-items { grid-template-columns: repeat(2, 254px); diff --git a/src/app/shared/search-popup/search-popup.component.spec.ts b/src/app/shared/search-popup/search-popup.component.spec.ts index bb0d3c7bf4..34d0ced308 100644 --- a/src/app/shared/search-popup/search-popup.component.spec.ts +++ b/src/app/shared/search-popup/search-popup.component.spec.ts @@ -18,6 +18,9 @@ import { LocalStorageService } from '@global-service/localstorage/local-storage. import { SharedModule } from 'src/app/shared/shared.module'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { EventsSearchModel } from '@global-models/search/eventsSearch.model'; +import { SearchDataModel } from '@global-models/search/search.model'; +import { SearchCategory } from './search-consts'; describe('SearchPopupComponent', () => { let component: SearchPopupComponent; @@ -26,28 +29,6 @@ describe('SearchPopupComponent', () => { const localStorageServiceMock: LocalStorageService = jasmine.createSpyObj('LocalStorageService', ['getCurrentLanguage']); localStorageServiceMock.getCurrentLanguage = () => 'ua' as Language; - const mockTipData = { - id: 1, - title: 'test', - author: { - id: 1, - name: 'test' - }, - creationDate: '0101', - tags: ['test'] - }; - - const mockNewsData = { - id: 1, - title: 'test', - author: { - id: 1, - name: 'test' - }, - creationDate: '0101', - tags: ['test'] - }; - const mockEventsData = { id: 1, title: 'test', @@ -55,16 +36,16 @@ describe('SearchPopupComponent', () => { tags: ['test'] }; - const searchModelMock = { - countOfResults: 2, - ecoNews: [mockNewsData], - events: [mockEventsData], - tipsAndTricks: [mockTipData] + const eventsSearchModelMock: SearchDataModel = { + currentPage: 1, + page: [mockEventsData], + totalElements: 1, + totalPages: 1 }; const searchMock: SearchService = jasmine.createSpyObj('SearchService', ['getAllResults']); searchMock.searchSubject = new Subject(); - searchMock.getAllResults = () => of(searchModelMock); + searchMock.getAllResults = () => of(eventsSearchModelMock); searchMock.closeSearchSignal = () => true; beforeEach(waitForAsync(() => { @@ -113,12 +94,12 @@ describe('SearchPopupComponent', () => { describe('Testing services:', () => { it('should handle search value changes', fakeAsync(() => { - const getSearchSpy = spyOn(component.searchService, 'getAllResults').and.returnValue(of(searchModelMock)); + const getSearchSpy = spyOn(component.searchService, 'getAllResults').and.returnValue(of(eventsSearchModelMock)); component.ngOnInit(); component.searchInput.setValue('test'); tick(300); - expect(getSearchSpy).toHaveBeenCalledWith('test', 'econews', 'ua'); + expect(getSearchSpy).toHaveBeenCalledWith('test', SearchCategory.EVENTS, 'ua'); })); it('closeSearch should open SearchService/closeSearchSignal', () => { diff --git a/src/app/shared/search-popup/search-popup.component.ts b/src/app/shared/search-popup/search-popup.component.ts index 224c4cd950..92083feabb 100644 --- a/src/app/shared/search-popup/search-popup.component.ts +++ b/src/app/shared/search-popup/search-popup.component.ts @@ -13,6 +13,8 @@ import { MatSnackBarComponent } from '@global-errors/mat-snack-bar/mat-snack-bar import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { MatDialog } from '@angular/material/dialog'; import { SearchCategory } from './search-consts'; +import { PlacesSearchModel } from '@global-models/search/placesSearch.model'; +import { PopupSearchResults } from './search-popup.model'; @Component({ selector: 'app-search-popup', @@ -20,10 +22,18 @@ import { SearchCategory } from './search-consts'; styleUrls: ['./search-popup.component.scss'] }) export class SearchPopupComponent implements OnInit, OnDestroy { + resultsCounters: { + news: number; + events: number; + places: number; + total: number; + } = { events: null, news: null, places: null, total: null }; + newsElements: NewsSearchModel[] = []; eventsElements: EventsSearchModel[] = []; + placesElements: PlacesSearchModel[] = []; + isSearchClicked = false; - itemsFound: number = null; searchModalSubscription: Subscription; searchInput = new FormControl(''); isLoading = false; @@ -53,15 +63,16 @@ export class SearchPopupComponent implements OnInit, OnDestroy { this.resetData(); this.isLoading = true; }), - switchMap((val: string) => { + switchMap((query: string) => { this.currentLanguage = this.localStorageService.getCurrentLanguage(); - return forkJoin([ - this.searchService.getAllResults(val, SearchCategory.NEWS, this.currentLanguage), - this.searchService.getAllResults(val, SearchCategory.EVENTS, this.currentLanguage) - ]); + return forkJoin({ + news: this.searchService.getAllResults(query, SearchCategory.NEWS, this.currentLanguage), + events: this.searchService.getAllResults(query, SearchCategory.EVENTS, this.currentLanguage), + places: this.searchService.getAllResults(query, SearchCategory.PLACES, this.currentLanguage) + }); }) ) - .subscribe((data: SearchDataModel[]) => { + .subscribe((data: PopupSearchResults) => { this.setData(data); }); @@ -80,12 +91,17 @@ export class SearchPopupComponent implements OnInit, OnDestroy { this.snackBar.openSnackBar('error'); } - private setData(data: SearchDataModel[]): void { + private setData(data: PopupSearchResults): void { this.isLoading = false; - this.newsElements = data[0].page; - this.eventsElements = data[1].page; - this.itemsFound = data[0].totalElements + data[1].totalElements; + this.newsElements = data.news.page; + this.eventsElements = data.events.page; + this.placesElements = data.places.page; + + this.resultsCounters.events = data.events.totalElements; + this.resultsCounters.news = data.news.totalElements; + this.resultsCounters.places = data.places.totalElements; + this.resultsCounters.total = data.events.totalElements + data.news.totalElements + data.places.totalElements; } private subscribeToSignal(signal: boolean): void { @@ -104,7 +120,7 @@ export class SearchPopupComponent implements OnInit, OnDestroy { private resetData(): void { this.newsElements = []; this.eventsElements = []; - this.itemsFound = null; + this.resultsCounters = { events: null, news: null, places: null, total: null }; } ngOnDestroy() { diff --git a/src/app/shared/search-popup/search-popup.model.ts b/src/app/shared/search-popup/search-popup.model.ts new file mode 100644 index 0000000000..c2b1d10209 --- /dev/null +++ b/src/app/shared/search-popup/search-popup.model.ts @@ -0,0 +1,10 @@ +import { EventsSearchModel } from '@global-models/search/eventsSearch.model'; +import { NewsSearchModel } from '@global-models/search/newsSearch.model'; +import { PlacesSearchModel } from '@global-models/search/placesSearch.model'; +import { SearchDataModel } from '@global-models/search/search.model'; + +export interface PopupSearchResults { + news: SearchDataModel; + events: SearchDataModel; + places: SearchDataModel; +} diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 2d8ee6b1e9..36fd1b4b2c 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -313,6 +313,7 @@ "items-found": "items found", "news": "News", "events": "Events", + "places": "Places", "see-all-news": "See all News", "see-all-results": "See all results" }, diff --git a/src/assets/i18n/ua.json b/src/assets/i18n/ua.json index 59ce5ebd15..f65f77b0ca 100644 --- a/src/assets/i18n/ua.json +++ b/src/assets/i18n/ua.json @@ -317,8 +317,8 @@ "items-found": "знайдено", "news": "Новини", "events": "Події", + "places": "Місця", "see-all-news": "Дивіться всі новини", - "see-all-tips": "Дивіться всі поради та підказки", "see-all-results": "Дивіться всі результати" }, "search-not-found": {