Skip to content

Commit

Permalink
Merge branch 'feature/search-improvements' into feature/styling-searc…
Browse files Browse the repository at this point in the history
…h-cards
  • Loading branch information
chth0n1x authored Aug 16, 2023
2 parents 1bc0745 + 1fb2aba commit 73d1f30
Show file tree
Hide file tree
Showing 73 changed files with 2,841 additions and 475 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import ShareAdapter from './share-adapter';

export default class IndexPropertySearchAdapter extends ShareAdapter {
pathForType() {
return 'index-property-search';
}
export default class RelatedPropertyPathAdapter extends ShareAdapter {
}

declare module 'ember-data/types/registries/adapter' {
export default interface AdapterRegistry {
'index-property-search': IndexPropertySearchAdapter;
'related-property-path': RelatedPropertyPathAdapter;
} // eslint-disable-line semi
}
32 changes: 28 additions & 4 deletions app/models/index-card-search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Model, { AsyncBelongsTo, AsyncHasMany, attr, belongsTo, hasMany } from '@ember-data/model';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';

import IndexPropertySearchModel from './index-property-search';
import RelatedPropertyPathModel from './related-property-path';
import SearchResultModel from './search-result';

export interface SearchFilter {
Expand All @@ -17,8 +17,32 @@ export default class IndexCardSearchModel extends Model {
@hasMany('search-result', { inverse: null })
searchResultPage!: AsyncHasMany<SearchResultModel> & SearchResultModel[];

@belongsTo('index-property-search', { inverse: null })
relatedPropertySearch!: AsyncBelongsTo<IndexPropertySearchModel> & IndexPropertySearchModel;
@hasMany('related-property-path', { inverse: null })
relatedProperties!: RelatedPropertyPathModel[];

get firstPageCursor() {
if (this.searchResultPage.links.first?.href) {
const firstPageLinkUrl = new URL(this.searchResultPage.links.first?.href);
return firstPageLinkUrl.searchParams.get('page[cursor]');
}
return null;
}

get prevPageCursor() {
if (this.searchResultPage.links.prev?.href) {
const prevPageLinkUrl = new URL(this.searchResultPage.links.prev?.href);
return prevPageLinkUrl.searchParams.get('page[cursor]');
}
return null;
}

get nextPageCursor() {
if (this.searchResultPage.links.next?.href) {
const nextPageLinkUrl = new URL(this.searchResultPage.links.next?.href);
return nextPageLinkUrl.searchParams.get('page[cursor]');
}
return null;
}
}

declare module 'ember-data/types/registries/model' {
Expand Down
20 changes: 20 additions & 0 deletions app/models/index-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { inject as service } from '@ember/service';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';
import IntlService from 'ember-intl/services/intl';

import GetLocalizedPropertyHelper from 'ember-osf-web/helpers/get-localized-property';
import { getOwner } from '@ember/application';

export interface LanguageText {
'@language': string;
'@value': string;
Expand All @@ -17,6 +20,23 @@ export default class IndexCardModel extends Model {

@hasMany('index-card', { inverse: null })
relatedRecordSet!: AsyncHasMany<IndexCardModel> & IndexCardModel[];

getLocalizedString = new GetLocalizedPropertyHelper(getOwner(this));

get resourceId() {
return this.resourceIdentifier[0];
}

get label() {
const possibleLabelKeys = ['displayLabel', 'name', 'title'];
for (const key of possibleLabelKeys) {
if (this.resourceMetadata[key]) {
const label = this.getLocalizedString.compute([this.resourceMetadata, key]);
return label;
}
}
return '';
}
}

declare module 'ember-data/types/registries/model' {
Expand Down
21 changes: 0 additions & 21 deletions app/models/index-property-search.ts

This file was deleted.

8 changes: 2 additions & 6 deletions app/models/index-value-search.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import Model, { AsyncHasMany, AsyncBelongsTo, attr, belongsTo, hasMany } from '@ember-data/model';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';

import IndexPropertySearchModel from './index-property-search';
import { SearchFilter } from './index-card-search';
import SearchResultModel from './search-result';

export default class IndexValueSearchModel extends Model {
@attr('string') valueSearchText!: string;
@attr('array') valueSearchFilter!: SearchFilter[];
@attr('string') valueSearchPropertyPath!: string;
@attr('string') cardSearchText!: string;
@attr('array') cardSearchFilter!: SearchFilter[];
@attr('number') totalResultCount!: number;

@hasMany('search-result', { inverse: null })
searchResultPage!: AsyncHasMany<SearchResultModel> & SearchResultModel[];

@belongsTo('index-property-search', { inverse: null })
relatedPropertySearch!: AsyncBelongsTo<IndexPropertySearchModel> & IndexPropertySearchModel;
}

declare module 'ember-data/types/registries/model' {
Expand Down
54 changes: 54 additions & 0 deletions app/models/related-property-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { attr } from '@ember-data/model';
import { getOwner } from '@ember/application';

import GetLocalizedPropertyHelper from 'ember-osf-web/helpers/get-localized-property';

import OsfModel from './osf-model';
import { LanguageText } from './index-card';

interface PropertyPath {
'@id': string;
resourceType: Array<{ '@id': string }>;
displayLabel: LanguageText[];
shortFormLabel: LanguageText[];
}

export default class RelatedPropertyPathModel extends OsfModel {
@attr('string') propertyPathKey!: string;
@attr('number') cardSearchResultCount!: number;
@attr('array') osfmapPropertyPath!: string[];
@attr('array') propertyPath!: PropertyPath[];

getLocalizedString = new GetLocalizedPropertyHelper(getOwner(this));

get shortFormLabel() {
const labelArray = [];
// propertyPath is likely an array of length 1,
// unless it is nested property(e.g. file's isContainedBy.funder, file's isContainedBy.license)
for (const property of this.propertyPath) {
const label = this.getLocalizedString.compute(
[property as unknown as Record<string, LanguageText[]>, 'shortFormLabel'],
);
if (label) {
labelArray.push(label);
}
}
return labelArray.join(',');
}

get displayLabel() {
// propertyPath is likely an array of length 1,
// unless it is nested property(e.g. file's isContainedBy.funder, file's isContainedBy.license)
// in which case we just use the last property
const hash = this.propertyPath[this.propertyPath.length-1] as unknown as Record<string, LanguageText[]>;
const label = this.getLocalizedString.compute([hash, 'displayLabel']);
return label || '';
}

}

declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'related-property-path': RelatedPropertyPathModel;
} // eslint-disable-line semi
}
43 changes: 42 additions & 1 deletion app/models/search-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class SearchResultModel extends Model {
@service intl!: IntlService;

@attr('array') matchEvidence!: Array<IriMatchEvidence | TextMatchEvidence>;
@attr('number') recordResultCount!: number;
@attr('number') cardSearchResultCount!: number;

@belongsTo('index-card', { inverse: null })
indexCard!: IndexCardModel;
Expand Down Expand Up @@ -57,6 +57,13 @@ export default class SearchResultModel extends Model {
return this.resourceMetadata['title']?.[0]['@value'];
}

get fileTitle() {
if (this.resourceType === 'file') {
return this.resourceMetadata.title?.[0]['@value'];
}
return null;
}

get description() {
return this.resourceMetadata.description?.[0]?.['@value'];
}
Expand Down Expand Up @@ -141,6 +148,16 @@ export default class SearchResultModel extends Model {
return null;
}

get nodeFunders() {
if (this.resourceMetadata.isContainedBy?.[0]?.funder) {
return this.resourceMetadata.isContainedBy[0].funder.map( (item: any) => ({
name: item.name[0]['@value'],
identifier: item.identifier?.[0]['@value'],
}));
}
return null;
}

get provider() {
if (this.resourceMetadata.publisher) {
return {
Expand All @@ -165,6 +182,16 @@ export default class SearchResultModel extends Model {
return null;
}

get nodeLicense() {
if (this.resourceMetadata.isContainedBy?.[0]?.rights) {
return {
name: this.resourceMetadata.isContainedBy[0].rights?.[0].name[0]['@value'],
identifier: this.resourceMetadata.rights?.[0]['@id'],
};
}
return null;
}

get resourceType() {
const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']);
if (types.includes('Project')) {
Expand All @@ -185,6 +212,20 @@ export default class SearchResultModel extends Model {
return 'unknown';
}

get orcids() {
if (this.resourceMetadata.identifier) {
const orcids = this.resourceMetadata.identifier.filter(
(item: any) => item['@value'].includes('http://orcid.org/'),
);
return orcids.map( (item: any) => item['@value']);
}
return null;
}

get resourceNature() {
return this.resourceMetadata.resourceNature?.[0]?.displayLabel?.[0]?.['@value'];
}

get hasDataResource() {
return this.resourceMetadata.hasDataResource;
}
Expand Down
8 changes: 4 additions & 4 deletions app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Router.map(function() {
this.route('goodbye');
this.route('search');
this.route('institutions', function() {
this.route('discover', { path: '/:institution_id' });
// this.route('discover', { path: '/:institution_id' });
this.route('dashboard', { path: '/:institution_id/dashboard' });
});
this.route('preprints', function() {
this.route('discover', { path: '/:provider_id/discover' });
});
// this.route('preprints', function() {
// this.route('discover', { path: '/:provider_id/discover' });
// });
this.route('register');
this.route('settings', function() {
this.route('profile', function() {
Expand Down
4 changes: 3 additions & 1 deletion app/search/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/componen
export default class SearchController extends Controller {
@tracked cardSearchText?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked page?: string = '';

queryParams = ['cardSearchText', 'page', 'sort', 'resourceType'];

Expand All @@ -15,5 +16,6 @@ export default class SearchController extends Controller {
this.cardSearchText = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.page = queryOptions.page;
}
}
3 changes: 2 additions & 1 deletion app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

<SearchPage
@route='search'
@query={{this.q}}
@cardSearchText={{this.cardSearchText}}
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@showResourceTypeFilter={{true}}
@sort={{this.sort}}
@resourceType={{this.resourceType}}
@page={{this.page}}
/>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ShareSerializer from './share-serializer';

export default class IndexPropertySearchSerializer extends ShareSerializer {
export default class RelatedPropertyPathSerializer extends ShareSerializer {
}

declare module 'ember-data/types/registries/serializer' {
export default interface SerializerRegistry {
'index-property-search': IndexPropertySearchSerializer;
'related-property-path': RelatedPropertyPathSerializer;
} // eslint-disable-line semi
}
Loading

0 comments on commit 73d1f30

Please sign in to comment.