From e08eccc810edf02ca9a3c245ddb1c8c8f9dbc82b Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 31 May 2023 22:53:00 -0400 Subject: [PATCH 01/24] prelim --- app/models/index-card.ts | 1 + app/models/search-result.ts | 42 +++++++++++++++++++++++++++++++++++-- translations/en-us.yml | 3 +++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/models/index-card.ts b/app/models/index-card.ts index 8881f63dc8..175c327654 100644 --- a/app/models/index-card.ts +++ b/app/models/index-card.ts @@ -12,6 +12,7 @@ export default class IndexCardModel extends Model { @attr('array') resourceType!: string[]; @attr('array') resourceIdentifier!: string[]; + // TODO: can we add a type for resourceMetadata? @attr('object') resourceMetadata!: any; @hasMany('index-card', { inverse: null }) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index e97e9001dc..36f88330a5 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -1,4 +1,4 @@ -import Model, { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; +import Model, { attr, belongsTo } from '@ember-data/model'; import IndexCardModel from './index-card'; @@ -19,7 +19,45 @@ export default class SearchResultModel extends Model { @attr('number') recordResultCount!: number; @belongsTo('index-card', { inverse: null }) - indexCard!: AsyncBelongsTo | IndexCardModel; + indexCard!: IndexCardModel; + + // TODO: double check how matchEvidence works + get context() { + return this.matchEvidence.reduce( + (acc, current) => acc.concat( + `${current.propertyPath}: + ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, + ), + '', + ); + } + + get displayTitle() { + if (this.indexCard.resourceType.includes('foaf:person')) { + return this.indexCard.resourceMetadata['foaf:name']; + } else if (this.indexCard.resourceType.includes('osf:File')) { + return this.indexCard.resourceMetadata['osf:fileName']; + } + return this.indexCard.resourceMetadata['dcterms:title']; + } + + // returns list of contributors for osf objects + // returns list of affiliated institutions for osf users + get affiliatedEntities() { + if (this.indexCard.resourceType.includes('foaf:person')) { + // return something + } else { + // return something else + } + } + + get dateFields() { + if (this.indexCard.resourceType.includes('foaf:person')) { + return []; + } else if (this.indexCard.resourceType) { + return []; + } + } } declare module 'ember-data/types/registries/model' { diff --git a/translations/en-us.yml b/translations/en-us.yml index 05fe5917e0..f2f678b81f 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1822,6 +1822,9 @@ routes: institution: Institution email: Email osf-components: + search-result-card: + date_created: Date created + last_edited: Last edited resources-list: add_instructions: 'Link a DOI from a repository to your registration by clicking the green “+” button.' add_instructions_adhere: 'Contributors affirmed to adhere to the criteria for each badge.' From 5ae7b9fa245efc4d60898ca96f99858cf6af5bec Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 1 Jun 2023 06:16:42 -0400 Subject: [PATCH 02/24] some more --- .../search-result-card/component.ts | 12 +++++ .../components/search-result-card/styles.scss | 19 ++++++++ .../search-result-card/template.hbs | 46 +++++++++++++++++++ .../search-result-card/component.js | 1 + .../components/search-result-card/template.js | 1 + 5 files changed, 79 insertions(+) create mode 100644 lib/osf-components/addon/components/search-result-card/component.ts create mode 100644 lib/osf-components/addon/components/search-result-card/styles.scss create mode 100644 lib/osf-components/addon/components/search-result-card/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/component.js create mode 100644 lib/osf-components/app/components/search-result-card/template.js diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts new file mode 100644 index 0000000000..0c90fdcde6 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -0,0 +1,12 @@ +import { action } from '@ember/object'; +import Component from '@glimmer/component' +import { tracked } from '@glimmer/tracking' + +export default class SearchResultCard extends Component { + @tracked isOpenSecondaryMetadata = false; + + @action + toggleSecondaryMetadata() { + this.isOpenSecondaryMetadata = !this.isOpenSecondaryMetadata; + } +} diff --git a/lib/osf-components/addon/components/search-result-card/styles.scss b/lib/osf-components/addon/components/search-result-card/styles.scss new file mode 100644 index 0000000000..c8fd315a5c --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/styles.scss @@ -0,0 +1,19 @@ +.result-card-container { + margin: 10px; +} + +.primary-metadata-container { + display: flex; + flex-direction: column; +} + +.header { + display: flex; + justify-content: space-between; +} + +.type-label { + width: fit-content; + padding: 5px; + background-color: $color-gradient-primary; +} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs new file mode 100644 index 0000000000..61c06870e7 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -0,0 +1,46 @@ +
+
+
+
+ Label +
+ +
+

+ This is the title +

+
+ Yeji Huang + Ryujin Shin +
+
+ date | + date +
+
+

Lorem ipsum dolor sit amet, + consectetur adipiscing elit, + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+
+
+ + +
+ This is the body +
+
+
\ No newline at end of file diff --git a/lib/osf-components/app/components/search-result-card/component.js b/lib/osf-components/app/components/search-result-card/component.js new file mode 100644 index 0000000000..9ca7a8b5cf --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/component.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/component'; diff --git a/lib/osf-components/app/components/search-result-card/template.js b/lib/osf-components/app/components/search-result-card/template.js new file mode 100644 index 0000000000..f99efc30de --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/template'; From a178a8d1a52e794c3f1b7d778f797a85486dfba2 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Fri, 2 Jun 2023 12:01:13 -0400 Subject: [PATCH 03/24] moar --- .../addon/components/search-result-card/component.ts | 10 +++++++++- .../addon/components/search-result-card/template.hbs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 0c90fdcde6..55f0267be4 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -2,7 +2,15 @@ import { action } from '@ember/object'; import Component from '@glimmer/component' import { tracked } from '@glimmer/tracking' -export default class SearchResultCard extends Component { +interface Args { + displayName: string; + nameFields: string[]; + dateFields: string[]; + context: string; + secondaryMetadata: any; +} + +export default class SearchResultCard extends Component { @tracked isOpenSecondaryMetadata = false; @action diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 61c06870e7..a983be91a0 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -19,7 +19,7 @@

- This is the title + This is the title

Yeji Huang From e96576964a35c795a3f8f602be4cf7a25aef0198 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Tue, 13 Jun 2023 09:07:18 -0400 Subject: [PATCH 04/24] moar --- app/models/search-result.ts | 45 ++++++++++++++----- .../search-result-card/component.ts | 27 ++++++++--- .../search-result-card/template.hbs | 16 ++++--- translations/en-us.yml | 8 ++++ 4 files changed, 76 insertions(+), 20 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 36f88330a5..016731f575 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -33,30 +33,55 @@ export default class SearchResultModel extends Model { } get displayTitle() { - if (this.indexCard.resourceType.includes('foaf:person')) { - return this.indexCard.resourceMetadata['foaf:name']; - } else if (this.indexCard.resourceType.includes('osf:File')) { - return this.indexCard.resourceMetadata['osf:fileName']; + if (this.resourceType === 'user') { + return this.indexCard.get('resourceMetadata')['name'][0]['@value']; + } else if (this.resourceType === 'file') { + return this.indexCard.get('resourceMetadata')['fileName'][0]['@value']; } - return this.indexCard.resourceMetadata['dcterms:title']; + return this.indexCard.get('resourceMetadata')['title'][0]['@value']; + } + + get absoluteUrl() { + return this.indexCard.get('resourceMetadata')['@id']; } // returns list of contributors for osf objects // returns list of affiliated institutions for osf users get affiliatedEntities() { - if (this.indexCard.resourceType.includes('foaf:person')) { + if (this.resourceType === 'user') { // return something } else { - // return something else + return this.indexCard.get('resourceMetadata').creator.map( (item:any) => item.name[0]['@value']); } } get dateFields() { - if (this.indexCard.resourceType.includes('foaf:person')) { - return []; - } else if (this.indexCard.resourceType) { + if (this.resourceType === 'user') { return []; } + return [ + { label: 'Date created', date: this.indexCard.get('resourceMetadata').created }, + { label: 'Last edited', date: this.indexCard.get('resourceMetadata').modified }, + ] + } + + get resourceType() { + const types = this.indexCard.get('resourceMetadata').resourceType.map( (item: any) => item['@id']); + if (types.includes('Project')) { + return 'project'; + } else if (types.includes('Registration')) { + return 'registration'; + } else if (types.includes('Preprint')) { + return 'preprint'; + } else if (types.includes('ProjectComponent')) { + return 'project_component'; + } else if (types.includes('RegistrationComponent')) { + return 'registration_component'; + } else if (types.includes('Person')) { + return 'user'; + } else if(types.includes('File')) { + return 'file'; + } } } diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 55f0267be4..4fda401ace 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -1,20 +1,37 @@ import { action } from '@ember/object'; import Component from '@glimmer/component' import { tracked } from '@glimmer/tracking' +import SearchResultModel from 'ember-osf-web/models/search-result'; +import { inject as service } from '@ember/service'; +import Intl from 'ember-intl/services/intl'; interface Args { - displayName: string; - nameFields: string[]; - dateFields: string[]; - context: string; - secondaryMetadata: any; + result: SearchResultModel; + // displayName: string; + // nameFields: string[]; + // dateFields: string[]; + // context: string; + // secondaryMetadata: any; +} + +const ResourceTypeCardLabelMap = { + 'osf:Registration': 'registration', + 'osf:RegistrationComponent': 'registration_component', + 'osf:Project': 'project', + 'osf:ProjectComponent': 'project_component', + 'osf:File': 'file', } export default class SearchResultCard extends Component { + @service intl!: Intl; @tracked isOpenSecondaryMetadata = false; @action toggleSecondaryMetadata() { this.isOpenSecondaryMetadata = !this.isOpenSecondaryMetadata; } + + get cardTypeLabel() { + return this.intl.t(`osf-components.search-result-card.${this.args.result.resourceType}`); + } } diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index a983be91a0..697411706d 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -2,7 +2,7 @@
- Label + {{this.cardTypeLabel}}
-

- This is the title +

+ {{@result.displayTitle}}

- Yeji Huang - Ryujin Shin + + {{list.item}} +
date | diff --git a/translations/en-us.yml b/translations/en-us.yml index f2f678b81f..4baf97b2e1 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1825,6 +1825,14 @@ osf-components: search-result-card: date_created: Date created last_edited: Last edited + member_since: Member since + project: Project + registration: Registration + preprint: Preprint + file: File + user: User + project_component: Project component + registration_component: Registration component resources-list: add_instructions: 'Link a DOI from a repository to your registration by clicking the green “+” button.' add_instructions_adhere: 'Contributors affirmed to adhere to the criteria for each badge.' From ca34e25fb81228f819e55122a2d4ef4667c1a958 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Fri, 16 Jun 2023 08:58:37 -0400 Subject: [PATCH 05/24] moar --- app/models/search-result.ts | 18 +++++++++++------- .../components/search-result-card/template.hbs | 11 +++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 016731f575..1b47c22322 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -23,13 +23,16 @@ export default class SearchResultModel extends Model { // TODO: double check how matchEvidence works get context() { - return this.matchEvidence.reduce( - (acc, current) => acc.concat( - `${current.propertyPath}: - ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, - ), - '', - ); + if (this.matchEvidence) { + return this.matchEvidence.reduce( + (acc, current) => acc.concat( + `${current.propertyPath}: + ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, + ), + '', + ); + } + return null; } get displayTitle() { @@ -82,6 +85,7 @@ export default class SearchResultModel extends Model { } else if(types.includes('File')) { return 'file'; } + return 'unknown'; } } diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 697411706d..65b54fefec 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -32,14 +32,13 @@
- date | - date + {{#each @result.dateFields as |field|}} + {{field.label}}: {{field.date}} + {{/each}}
-

Lorem ipsum dolor sit amet, - consectetur adipiscing elit, - sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+ {{@result.context}}

From bd5cfdd8f8ff180d115007ec49ecc53b3743b2cf Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Sun, 30 Jul 2023 03:12:14 -0400 Subject: [PATCH 06/24] some moar --- app/models/search-result.ts | 62 +++++++++++++++---- .../addon/components/search-page/template.hbs | 3 + .../search-result-card/component.ts | 17 +---- .../components/search-result-card/styles.scss | 8 +++ .../search-result-card/template.hbs | 7 ++- translations/en-us.yml | 3 + 6 files changed, 73 insertions(+), 27 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 1b47c22322..2b40061f46 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -1,4 +1,6 @@ import Model, { attr, belongsTo } from '@ember-data/model'; +import { inject as service } from '@ember/service'; +import IntlService from 'ember-intl/services/intl'; import IndexCardModel from './index-card'; @@ -15,12 +17,18 @@ export interface TextMatchEvidence { } export default class SearchResultModel extends Model { + @service intl!: IntlService; + @attr('array') matchEvidence!: Array; @attr('number') recordResultCount!: number; @belongsTo('index-card', { inverse: null }) indexCard!: IndexCardModel; + get resourceMetadata() { + return this.indexCard.get('resourceMetadata'); + } + // TODO: double check how matchEvidence works get context() { if (this.matchEvidence) { @@ -37,15 +45,15 @@ export default class SearchResultModel extends Model { get displayTitle() { if (this.resourceType === 'user') { - return this.indexCard.get('resourceMetadata')['name'][0]['@value']; + return this.resourceMetadata['name'][0]['@value']; } else if (this.resourceType === 'file') { - return this.indexCard.get('resourceMetadata')['fileName'][0]['@value']; + return this.resourceMetadata['fileName'][0]['@value']; } - return this.indexCard.get('resourceMetadata')['title'][0]['@value']; + return this.resourceMetadata['title'][0]['@value']; } get absoluteUrl() { - return this.indexCard.get('resourceMetadata')['@id']; + return this.resourceMetadata['@id']; } // returns list of contributors for osf objects @@ -54,22 +62,54 @@ export default class SearchResultModel extends Model { if (this.resourceType === 'user') { // return something } else { - return this.indexCard.get('resourceMetadata').creator.map( (item:any) => item.name[0]['@value']); + return this.resourceMetadata.creator.map( (item:any) => item.name[0]['@value']); } } get dateFields() { - if (this.resourceType === 'user') { + switch (this.resourceType) { + case 'user': return []; + case 'registration': + case 'registration_component': + return [ + { + label: this.intl.t('osf-components.search-result-card.date_registered'), + date: this.resourceMetadata.dateCreated[0]['@value'], + }, + { + label: this.intl.t('osf-components.search-result-card.date_modified'), + date: this.resourceMetadata.dateModified[0]['@value'], + }, + ]; + default: + return [ + { + label: this.intl.t('osf-components.search-result-card.date_created'), + date: this.resourceMetadata.dateCreated[0]['@value'], + }, + { + label: this.intl.t('osf-components.search-result-card.date_modified'), + date: this.resourceMetadata.dateModified[0]['@value'], + }, + ]; } - return [ - { label: 'Date created', date: this.indexCard.get('resourceMetadata').created }, - { label: 'Last edited', date: this.indexCard.get('resourceMetadata').modified }, - ] + } + + get isPartOf() { + const isPartOf = this.resourceMetadata.isPartOf; + if (isPartOf) { + return { + label: this.intl.t('osf-components.search-result-card.from'), + title: this.resourceMetadata.isPartOf[0].title[0]['@value'], + absoluteUrl: this.resourceMetadata.isPartOf[0]['@id'], + }; + } + return null; } get resourceType() { - const types = this.indexCard.get('resourceMetadata').resourceType.map( (item: any) => item['@id']); + const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']); if (types.includes('Project')) { return 'project'; } else if (types.includes('Registration')) { diff --git a/lib/osf-components/addon/components/search-page/template.hbs b/lib/osf-components/addon/components/search-page/template.hbs index 48e94b066e..57a6e1398b 100644 --- a/lib/osf-components/addon/components/search-page/template.hbs +++ b/lib/osf-components/addon/components/search-page/template.hbs @@ -178,5 +178,8 @@ as |layout|>
{{/unless}} + {{#each this.searchResults as |item|}} + + {{/each}} diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 4fda401ace..9c9de50ee9 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -1,25 +1,12 @@ import { action } from '@ember/object'; -import Component from '@glimmer/component' -import { tracked } from '@glimmer/tracking' +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; import SearchResultModel from 'ember-osf-web/models/search-result'; import { inject as service } from '@ember/service'; import Intl from 'ember-intl/services/intl'; interface Args { result: SearchResultModel; - // displayName: string; - // nameFields: string[]; - // dateFields: string[]; - // context: string; - // secondaryMetadata: any; -} - -const ResourceTypeCardLabelMap = { - 'osf:Registration': 'registration', - 'osf:RegistrationComponent': 'registration_component', - 'osf:Project': 'project', - 'osf:ProjectComponent': 'project_component', - 'osf:File': 'file', } export default class SearchResultCard extends Component { diff --git a/lib/osf-components/addon/components/search-result-card/styles.scss b/lib/osf-components/addon/components/search-result-card/styles.scss index c8fd315a5c..347f743074 100644 --- a/lib/osf-components/addon/components/search-result-card/styles.scss +++ b/lib/osf-components/addon/components/search-result-card/styles.scss @@ -17,3 +17,11 @@ padding: 5px; background-color: $color-gradient-primary; } + +.date-fields { + span { + &:not(:last-child)::after { + content: ' | '; + } + } +} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 65b54fefec..fe6a9a6abc 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -19,7 +19,7 @@

- {{@result.displayTitle}} + {{@result.displayTitle}}

+ {{#if @result.isPartOf}} +
+ {{@result.isPartOf.label}}: {{@result.isPartOf.title}} +
+ {{/if}}
{{#each @result.dateFields as |field|}} {{field.label}}: {{field.date}} diff --git a/translations/en-us.yml b/translations/en-us.yml index 4baf97b2e1..c739d7915c 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1823,7 +1823,10 @@ routes: email: Email osf-components: search-result-card: + from: From date_created: Date created + date_registered: Date registered + date_modified: Date modified last_edited: Last edited member_since: Member since project: Project From c6051515fd08569fee8397861c12601c26c7f4d9 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Sun, 30 Jul 2023 19:07:24 -0400 Subject: [PATCH 07/24] registration secondary metadata --- app/models/search-result.ts | 18 ++++++++++++ .../template.hbs | 28 +++++++++++++++++++ .../search-result-card/template.hbs | 4 ++- .../template.js | 1 + translations/en-us.yml | 5 ++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 2b40061f46..7c5ee74d97 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -108,6 +108,24 @@ export default class SearchResultModel extends Model { return null; } + get funders() { + return this.resourceMetadata.funder.map( (item: any) => ({ + name: item.name[0]['@value'], + identifier: item.identifier[0]['@value'], + })); + } + + get doi() { + return this.indexCard.get('resourceIdentifier').filter(id => id.includes('https://doi.org')); + } + + get license() { + return { + name: this.resourceMetadata.rights[0].name[0]['@value'], + identifier: this.resourceMetadata.rights[0]['@id'], + }; + } + get resourceType() { const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']); if (types.includes('Project')) { diff --git a/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs new file mode 100644 index 0000000000..d5e2999ea4 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs @@ -0,0 +1,28 @@ +
+ {{t 'osf-components.search-result-card.funder'}}: + + {{list.item.name}} + +
+
+ {{t 'osf-components.search-result-card.registration_template'}}: +
+
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
\ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index fe6a9a6abc..4c15cf10b1 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -50,7 +50,9 @@
- This is the body + {{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + + {{/if}}
\ No newline at end of file diff --git a/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js b/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js new file mode 100644 index 0000000000..f76c747316 --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/registration-secondary-metadata/template'; diff --git a/translations/en-us.yml b/translations/en-us.yml index c739d7915c..45e3e8e828 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1823,6 +1823,11 @@ routes: email: Email osf-components: search-result-card: + funder: Funder + registration_template: Registration template + doi: DOI + description: Description + license: License from: From date_created: Date created date_registered: Date registered From 74d0b85d5bcc782c0ff4ca0ff30d8a75413b9b22 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 2 Aug 2023 02:38:57 -0400 Subject: [PATCH 08/24] prelim project secondary metadata --- app/models/search-result.ts | 11 ++++--- .../project-secondary-metadata/template.hbs | 30 +++++++++++++++++++ .../search-result-card/template.hbs | 2 ++ .../project-secondary-metadata/template.js | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 7c5ee74d97..47e78caa07 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -109,10 +109,13 @@ export default class SearchResultModel extends Model { } get funders() { - return this.resourceMetadata.funder.map( (item: any) => ({ - name: item.name[0]['@value'], - identifier: item.identifier[0]['@value'], - })); + if (this.resourceMetadata.funder) { + return this.resourceMetadata.funder.map( (item: any) => ({ + name: item.name[0]['@value'], + identifier: item.identifier[0]['@value'], + })); + } + return null; } get doi() { diff --git a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs new file mode 100644 index 0000000000..cea2044043 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs @@ -0,0 +1,30 @@ +{{#if @result.funders}} +
+ {{t 'osf-components.search-result-card.funder'}}: + + {{list.item.name}} + +
+{{/if}} +
+ {{t 'osf-components.search-result-card.description'}}: +
+
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
\ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 4c15cf10b1..e203af8075 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -52,6 +52,8 @@
{{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + {{else if (or (eq @result.resourceType 'project') (eq @result.resourceType 'project_component'))}} + {{/if}} diff --git a/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js b/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js new file mode 100644 index 0000000000..7ab736d92f --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/project-secondary-metadata/template'; From e7e18a67f2f34ecc689e4175dfbaf9a13fbb7718 Mon Sep 17 00:00:00 2001 From: Futa Ikeda Date: Fri, 4 Aug 2023 16:27:24 -0400 Subject: [PATCH 09/24] Add preprint-secondary-metadata --- app/models/search-result.ts | 10 +++ .../search-result-card/component.ts | 7 ++ .../preprint-secondary-metadata/template.hbs | 78 +++++++++++++++++++ .../components/search-result-card/styles.scss | 4 + .../search-result-card/template.hbs | 29 ++++--- .../preprint-secondary-metadata/template.js | 1 + translations/en-us.yml | 6 ++ 7 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/preprint-secondary-metadata/template.js diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 47e78caa07..eb4425dcbb 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -118,6 +118,16 @@ export default class SearchResultModel extends Model { return null; } + get provider() { + if (this.resourceMetadata.publisher) { + return { + name: this.resourceMetadata.publisher[0].name[0]['@value'], + identifier: this.resourceMetadata.publisher[0]['@id'], + }; + } + return null; + } + get doi() { return this.indexCard.get('resourceIdentifier').filter(id => id.includes('https://doi.org')); } diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 9c9de50ee9..d487ff36a0 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -21,4 +21,11 @@ export default class SearchResultCard extends Component { get cardTypeLabel() { return this.intl.t(`osf-components.search-result-card.${this.args.result.resourceType}`); } + + // not sure if this is the best way, as there was a resourceType of "unknown" out in the wild + get secondaryMetadataComponent() { + const { resourceType } = this.args.result; + + return `search-result-card/${resourceType.replace('_component', '')}-secondary-metadata`; + } } diff --git a/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs new file mode 100644 index 0000000000..ba7f69064f --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs @@ -0,0 +1,78 @@ +
+ {{!-- Description --}} +
{{t 'osf-components.search-result-card.description'}}:
+
{{@result.description}}
+ + {{!-- Preprint Provider --}} +
{{t 'osf-components.search-result-card.preprint_provider'}}
+
{{@result.provider.name}}
+ + {{!-- License --}} +
{{t 'osf-components.search-result-card.license'}}
+
{{@result.license.name}}
+ + {{!-- DOI --}} + {{#if @result.doi}} +
{{t 'osf-components.search-result-card.doi'}}
+
+ + {{list.item}} + +
+ {{/if}} + + {{!-- Conflict of interest statement statedConflictOfInterest: [{ @id: 'no-conflict-of-interest' | @value: 'This is my conflict of interest that I input' }] --}} + {{#if @result.resourceMetadata.statedConflictOfInterest}} +
{{t 'osf-components.search-result-card.conflict_of_interest'}}
+
+ {{#if @result.resourceMetadata.statedConflictOfInterest.[0].[@value]}} + {{@result.resourceMetadata.statedConflictOfInterest.[0].[@value]}} + {{else}} + {{t 'osf-components.search-result-card.no_conflict_of_interest'}} + {{/if}} +
+ {{/if}} + + {{!-- Associated Data hasDataResource: [{ @id: 'https://myurl.com'}] --}} + {{#if @result.resourceMetadata.hasDataResource}} +
{{t 'osf-components.search-result-card.associated_data'}}
+
+ + {{list.item.[@id]}} + +
+ {{/if}} + + {{!-- Associated Preregistration hasPreregisteredAnalysisPlan and/or hasPreregisteredStudyDesign: [{ @id: 'https://myurl.com'}] --}} + {{#if @result.resourceMetadata.hasPreregisteredAnalysisPlan}} +
{{t 'osf-components.search-result-card.associated_analysis_plan'}}
+
+ + {{list.item.[@id]}} + +
+ {{/if}} + {{#if @result.resourceMetadata.hasPreregisteredStudyDesign}} +
{{t 'osf-components.search-result-card.associated_study_design'}}
+
+ + {{list.item.[@id]}} + +
+ {{/if}} +
+ diff --git a/lib/osf-components/addon/components/search-result-card/styles.scss b/lib/osf-components/addon/components/search-result-card/styles.scss index 347f743074..b4eac15932 100644 --- a/lib/osf-components/addon/components/search-result-card/styles.scss +++ b/lib/osf-components/addon/components/search-result-card/styles.scss @@ -1,5 +1,9 @@ .result-card-container { margin: 10px; + + dt:not(:first-child) { + margin-top: 10px; + } } .primary-metadata-container { diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index e203af8075..86de8e8c29 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -21,16 +21,18 @@

{{@result.displayTitle}}

-
- - {{list.item}} - -
+ {{#if @result.affiliatedEntities}} +
+ + {{list.item}} + +
+ {{/if}} {{#if @result.isPartOf}}
{{@result.isPartOf.label}}: {{@result.isPartOf.title}} @@ -50,11 +52,14 @@
- {{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + {{component this.secondaryMetadataComponent result=@result}} + {{!-- {{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} {{else if (or (eq @result.resourceType 'project') (eq @result.resourceType 'project_component'))}} - {{/if}} + {{else if (eq @result.resourceType 'preprint')}} + + {{/if}} --}}
\ No newline at end of file diff --git a/lib/osf-components/app/components/search-result-card/preprint-secondary-metadata/template.js b/lib/osf-components/app/components/search-result-card/preprint-secondary-metadata/template.js new file mode 100644 index 0000000000..6ebd4c9640 --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/preprint-secondary-metadata/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/preprint-secondary-metadata/template'; diff --git a/translations/en-us.yml b/translations/en-us.yml index 45e3e8e828..2a01833f66 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1834,6 +1834,12 @@ osf-components: date_modified: Date modified last_edited: Last edited member_since: Member since + preprint_provider: Preprint provider + conflict_of_interest: Conflict of Interest response + no_conflict_of_interest: 'Author asserted no Conflict of Interest' + associated_data: Associated data + associated_analysis_plan: Associated preregistration + associated_study_design: Associated study design project: Project registration: Registration preprint: Preprint From 55e05f76b3108037ff840d042cc97882feabff91 Mon Sep 17 00:00:00 2001 From: Futa Ikeda Date: Mon, 7 Aug 2023 11:29:48 -0400 Subject: [PATCH 10/24] less verbose comments --- .../preprint-secondary-metadata/template.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs index ba7f69064f..2682132e09 100644 --- a/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/preprint-secondary-metadata/template.hbs @@ -26,7 +26,7 @@ {{/if}} - {{!-- Conflict of interest statement statedConflictOfInterest: [{ @id: 'no-conflict-of-interest' | @value: 'This is my conflict of interest that I input' }] --}} + {{!-- Conflict of interest statement --}} {{#if @result.resourceMetadata.statedConflictOfInterest}}
{{t 'osf-components.search-result-card.conflict_of_interest'}}
@@ -38,7 +38,7 @@
{{/if}} - {{!-- Associated Data hasDataResource: [{ @id: 'https://myurl.com'}] --}} + {{!-- Associated Data --}} {{#if @result.resourceMetadata.hasDataResource}}
{{t 'osf-components.search-result-card.associated_data'}}
@@ -51,7 +51,7 @@
{{/if}} - {{!-- Associated Preregistration hasPreregisteredAnalysisPlan and/or hasPreregisteredStudyDesign: [{ @id: 'https://myurl.com'}] --}} + {{!-- Associated Preregistration: hasPreregisteredAnalysisPlan and/or hasPreregisteredStudyDesign --}} {{#if @result.resourceMetadata.hasPreregisteredAnalysisPlan}}
{{t 'osf-components.search-result-card.associated_analysis_plan'}}
From fe9f2befbc7f27adb2e52c0d2e5b85793b75d0ba Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 31 May 2023 22:53:00 -0400 Subject: [PATCH 11/24] prelim --- app/models/index-card.ts | 1 + app/models/search-result.ts | 42 +++++++++++++++++++++++++++++++++++-- translations/en-us.yml | 3 +++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/models/index-card.ts b/app/models/index-card.ts index 8881f63dc8..175c327654 100644 --- a/app/models/index-card.ts +++ b/app/models/index-card.ts @@ -12,6 +12,7 @@ export default class IndexCardModel extends Model { @attr('array') resourceType!: string[]; @attr('array') resourceIdentifier!: string[]; + // TODO: can we add a type for resourceMetadata? @attr('object') resourceMetadata!: any; @hasMany('index-card', { inverse: null }) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index e97e9001dc..36f88330a5 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -1,4 +1,4 @@ -import Model, { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; +import Model, { attr, belongsTo } from '@ember-data/model'; import IndexCardModel from './index-card'; @@ -19,7 +19,45 @@ export default class SearchResultModel extends Model { @attr('number') recordResultCount!: number; @belongsTo('index-card', { inverse: null }) - indexCard!: AsyncBelongsTo | IndexCardModel; + indexCard!: IndexCardModel; + + // TODO: double check how matchEvidence works + get context() { + return this.matchEvidence.reduce( + (acc, current) => acc.concat( + `${current.propertyPath}: + ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, + ), + '', + ); + } + + get displayTitle() { + if (this.indexCard.resourceType.includes('foaf:person')) { + return this.indexCard.resourceMetadata['foaf:name']; + } else if (this.indexCard.resourceType.includes('osf:File')) { + return this.indexCard.resourceMetadata['osf:fileName']; + } + return this.indexCard.resourceMetadata['dcterms:title']; + } + + // returns list of contributors for osf objects + // returns list of affiliated institutions for osf users + get affiliatedEntities() { + if (this.indexCard.resourceType.includes('foaf:person')) { + // return something + } else { + // return something else + } + } + + get dateFields() { + if (this.indexCard.resourceType.includes('foaf:person')) { + return []; + } else if (this.indexCard.resourceType) { + return []; + } + } } declare module 'ember-data/types/registries/model' { diff --git a/translations/en-us.yml b/translations/en-us.yml index 33799364df..aec5338905 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1847,6 +1847,9 @@ routes: institution: Institution email: Email osf-components: + search-result-card: + date_created: Date created + last_edited: Last edited resources-list: add_instructions: 'Link a DOI from a repository to your registration by clicking the green “+” button.' add_instructions_adhere: 'Contributors affirmed to adhere to the criteria for each badge.' From 61fb79bea8310aaf9d362297446e3ca4525e65dc Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 1 Jun 2023 06:16:42 -0400 Subject: [PATCH 12/24] some more --- .../search-result-card/component.ts | 12 +++++ .../components/search-result-card/styles.scss | 19 ++++++++ .../search-result-card/template.hbs | 46 +++++++++++++++++++ .../search-result-card/component.js | 1 + .../components/search-result-card/template.js | 1 + 5 files changed, 79 insertions(+) create mode 100644 lib/osf-components/addon/components/search-result-card/component.ts create mode 100644 lib/osf-components/addon/components/search-result-card/styles.scss create mode 100644 lib/osf-components/addon/components/search-result-card/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/component.js create mode 100644 lib/osf-components/app/components/search-result-card/template.js diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts new file mode 100644 index 0000000000..0c90fdcde6 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -0,0 +1,12 @@ +import { action } from '@ember/object'; +import Component from '@glimmer/component' +import { tracked } from '@glimmer/tracking' + +export default class SearchResultCard extends Component { + @tracked isOpenSecondaryMetadata = false; + + @action + toggleSecondaryMetadata() { + this.isOpenSecondaryMetadata = !this.isOpenSecondaryMetadata; + } +} diff --git a/lib/osf-components/addon/components/search-result-card/styles.scss b/lib/osf-components/addon/components/search-result-card/styles.scss new file mode 100644 index 0000000000..c8fd315a5c --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/styles.scss @@ -0,0 +1,19 @@ +.result-card-container { + margin: 10px; +} + +.primary-metadata-container { + display: flex; + flex-direction: column; +} + +.header { + display: flex; + justify-content: space-between; +} + +.type-label { + width: fit-content; + padding: 5px; + background-color: $color-gradient-primary; +} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs new file mode 100644 index 0000000000..61c06870e7 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -0,0 +1,46 @@ +
+
+
+
+ Label +
+ +
+

+ This is the title +

+
+ Yeji Huang + Ryujin Shin +
+
+ date | + date +
+
+

Lorem ipsum dolor sit amet, + consectetur adipiscing elit, + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+
+
+ + +
+ This is the body +
+
+
\ No newline at end of file diff --git a/lib/osf-components/app/components/search-result-card/component.js b/lib/osf-components/app/components/search-result-card/component.js new file mode 100644 index 0000000000..9ca7a8b5cf --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/component.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/component'; diff --git a/lib/osf-components/app/components/search-result-card/template.js b/lib/osf-components/app/components/search-result-card/template.js new file mode 100644 index 0000000000..f99efc30de --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/template'; From c4e6fb7f57e4f0d1add1153d7a1329e9e3128148 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Fri, 2 Jun 2023 12:01:13 -0400 Subject: [PATCH 13/24] moar --- .../addon/components/search-result-card/component.ts | 10 +++++++++- .../addon/components/search-result-card/template.hbs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 0c90fdcde6..55f0267be4 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -2,7 +2,15 @@ import { action } from '@ember/object'; import Component from '@glimmer/component' import { tracked } from '@glimmer/tracking' -export default class SearchResultCard extends Component { +interface Args { + displayName: string; + nameFields: string[]; + dateFields: string[]; + context: string; + secondaryMetadata: any; +} + +export default class SearchResultCard extends Component { @tracked isOpenSecondaryMetadata = false; @action diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 61c06870e7..a983be91a0 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -19,7 +19,7 @@

- This is the title + This is the title

Yeji Huang From cb52b0e9e0596c014e46567bad7e6881fb7d62ab Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Tue, 13 Jun 2023 09:07:18 -0400 Subject: [PATCH 14/24] moar --- app/models/search-result.ts | 45 ++++++++++++++----- .../search-result-card/component.ts | 27 ++++++++--- .../search-result-card/template.hbs | 16 ++++--- translations/en-us.yml | 8 ++++ 4 files changed, 76 insertions(+), 20 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 36f88330a5..016731f575 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -33,30 +33,55 @@ export default class SearchResultModel extends Model { } get displayTitle() { - if (this.indexCard.resourceType.includes('foaf:person')) { - return this.indexCard.resourceMetadata['foaf:name']; - } else if (this.indexCard.resourceType.includes('osf:File')) { - return this.indexCard.resourceMetadata['osf:fileName']; + if (this.resourceType === 'user') { + return this.indexCard.get('resourceMetadata')['name'][0]['@value']; + } else if (this.resourceType === 'file') { + return this.indexCard.get('resourceMetadata')['fileName'][0]['@value']; } - return this.indexCard.resourceMetadata['dcterms:title']; + return this.indexCard.get('resourceMetadata')['title'][0]['@value']; + } + + get absoluteUrl() { + return this.indexCard.get('resourceMetadata')['@id']; } // returns list of contributors for osf objects // returns list of affiliated institutions for osf users get affiliatedEntities() { - if (this.indexCard.resourceType.includes('foaf:person')) { + if (this.resourceType === 'user') { // return something } else { - // return something else + return this.indexCard.get('resourceMetadata').creator.map( (item:any) => item.name[0]['@value']); } } get dateFields() { - if (this.indexCard.resourceType.includes('foaf:person')) { - return []; - } else if (this.indexCard.resourceType) { + if (this.resourceType === 'user') { return []; } + return [ + { label: 'Date created', date: this.indexCard.get('resourceMetadata').created }, + { label: 'Last edited', date: this.indexCard.get('resourceMetadata').modified }, + ] + } + + get resourceType() { + const types = this.indexCard.get('resourceMetadata').resourceType.map( (item: any) => item['@id']); + if (types.includes('Project')) { + return 'project'; + } else if (types.includes('Registration')) { + return 'registration'; + } else if (types.includes('Preprint')) { + return 'preprint'; + } else if (types.includes('ProjectComponent')) { + return 'project_component'; + } else if (types.includes('RegistrationComponent')) { + return 'registration_component'; + } else if (types.includes('Person')) { + return 'user'; + } else if(types.includes('File')) { + return 'file'; + } } } diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 55f0267be4..4fda401ace 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -1,20 +1,37 @@ import { action } from '@ember/object'; import Component from '@glimmer/component' import { tracked } from '@glimmer/tracking' +import SearchResultModel from 'ember-osf-web/models/search-result'; +import { inject as service } from '@ember/service'; +import Intl from 'ember-intl/services/intl'; interface Args { - displayName: string; - nameFields: string[]; - dateFields: string[]; - context: string; - secondaryMetadata: any; + result: SearchResultModel; + // displayName: string; + // nameFields: string[]; + // dateFields: string[]; + // context: string; + // secondaryMetadata: any; +} + +const ResourceTypeCardLabelMap = { + 'osf:Registration': 'registration', + 'osf:RegistrationComponent': 'registration_component', + 'osf:Project': 'project', + 'osf:ProjectComponent': 'project_component', + 'osf:File': 'file', } export default class SearchResultCard extends Component { + @service intl!: Intl; @tracked isOpenSecondaryMetadata = false; @action toggleSecondaryMetadata() { this.isOpenSecondaryMetadata = !this.isOpenSecondaryMetadata; } + + get cardTypeLabel() { + return this.intl.t(`osf-components.search-result-card.${this.args.result.resourceType}`); + } } diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index a983be91a0..697411706d 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -2,7 +2,7 @@
- Label + {{this.cardTypeLabel}}
-

- This is the title +

+ {{@result.displayTitle}}

- Yeji Huang - Ryujin Shin + + {{list.item}} +
date | diff --git a/translations/en-us.yml b/translations/en-us.yml index aec5338905..77168386b8 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1850,6 +1850,14 @@ osf-components: search-result-card: date_created: Date created last_edited: Last edited + member_since: Member since + project: Project + registration: Registration + preprint: Preprint + file: File + user: User + project_component: Project component + registration_component: Registration component resources-list: add_instructions: 'Link a DOI from a repository to your registration by clicking the green “+” button.' add_instructions_adhere: 'Contributors affirmed to adhere to the criteria for each badge.' From d9e233ad1eb71bf8dcdf688241deeaf7a4f8c696 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Fri, 16 Jun 2023 08:58:37 -0400 Subject: [PATCH 15/24] moar --- app/models/search-result.ts | 18 +++++++++++------- .../components/search-result-card/template.hbs | 11 +++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 016731f575..1b47c22322 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -23,13 +23,16 @@ export default class SearchResultModel extends Model { // TODO: double check how matchEvidence works get context() { - return this.matchEvidence.reduce( - (acc, current) => acc.concat( - `${current.propertyPath}: - ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, - ), - '', - ); + if (this.matchEvidence) { + return this.matchEvidence.reduce( + (acc, current) => acc.concat( + `${current.propertyPath}: + ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, + ), + '', + ); + } + return null; } get displayTitle() { @@ -82,6 +85,7 @@ export default class SearchResultModel extends Model { } else if(types.includes('File')) { return 'file'; } + return 'unknown'; } } diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 697411706d..65b54fefec 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -32,14 +32,13 @@
- date | - date + {{#each @result.dateFields as |field|}} + {{field.label}}: {{field.date}} + {{/each}}
-

Lorem ipsum dolor sit amet, - consectetur adipiscing elit, - sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. - Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+ {{@result.context}}

From 988004f0cfbf06ccf35325da921082be96735e49 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Sun, 30 Jul 2023 03:12:14 -0400 Subject: [PATCH 16/24] some moar --- app/models/search-result.ts | 62 +++++++++++++++---- .../addon/components/search-page/template.hbs | 3 + .../search-result-card/component.ts | 17 +---- .../components/search-result-card/styles.scss | 8 +++ .../search-result-card/template.hbs | 7 ++- translations/en-us.yml | 3 + 6 files changed, 73 insertions(+), 27 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 1b47c22322..2b40061f46 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -1,4 +1,6 @@ import Model, { attr, belongsTo } from '@ember-data/model'; +import { inject as service } from '@ember/service'; +import IntlService from 'ember-intl/services/intl'; import IndexCardModel from './index-card'; @@ -15,12 +17,18 @@ export interface TextMatchEvidence { } export default class SearchResultModel extends Model { + @service intl!: IntlService; + @attr('array') matchEvidence!: Array; @attr('number') recordResultCount!: number; @belongsTo('index-card', { inverse: null }) indexCard!: IndexCardModel; + get resourceMetadata() { + return this.indexCard.get('resourceMetadata'); + } + // TODO: double check how matchEvidence works get context() { if (this.matchEvidence) { @@ -37,15 +45,15 @@ export default class SearchResultModel extends Model { get displayTitle() { if (this.resourceType === 'user') { - return this.indexCard.get('resourceMetadata')['name'][0]['@value']; + return this.resourceMetadata['name'][0]['@value']; } else if (this.resourceType === 'file') { - return this.indexCard.get('resourceMetadata')['fileName'][0]['@value']; + return this.resourceMetadata['fileName'][0]['@value']; } - return this.indexCard.get('resourceMetadata')['title'][0]['@value']; + return this.resourceMetadata['title'][0]['@value']; } get absoluteUrl() { - return this.indexCard.get('resourceMetadata')['@id']; + return this.resourceMetadata['@id']; } // returns list of contributors for osf objects @@ -54,22 +62,54 @@ export default class SearchResultModel extends Model { if (this.resourceType === 'user') { // return something } else { - return this.indexCard.get('resourceMetadata').creator.map( (item:any) => item.name[0]['@value']); + return this.resourceMetadata.creator.map( (item:any) => item.name[0]['@value']); } } get dateFields() { - if (this.resourceType === 'user') { + switch (this.resourceType) { + case 'user': return []; + case 'registration': + case 'registration_component': + return [ + { + label: this.intl.t('osf-components.search-result-card.date_registered'), + date: this.resourceMetadata.dateCreated[0]['@value'], + }, + { + label: this.intl.t('osf-components.search-result-card.date_modified'), + date: this.resourceMetadata.dateModified[0]['@value'], + }, + ]; + default: + return [ + { + label: this.intl.t('osf-components.search-result-card.date_created'), + date: this.resourceMetadata.dateCreated[0]['@value'], + }, + { + label: this.intl.t('osf-components.search-result-card.date_modified'), + date: this.resourceMetadata.dateModified[0]['@value'], + }, + ]; } - return [ - { label: 'Date created', date: this.indexCard.get('resourceMetadata').created }, - { label: 'Last edited', date: this.indexCard.get('resourceMetadata').modified }, - ] + } + + get isPartOf() { + const isPartOf = this.resourceMetadata.isPartOf; + if (isPartOf) { + return { + label: this.intl.t('osf-components.search-result-card.from'), + title: this.resourceMetadata.isPartOf[0].title[0]['@value'], + absoluteUrl: this.resourceMetadata.isPartOf[0]['@id'], + }; + } + return null; } get resourceType() { - const types = this.indexCard.get('resourceMetadata').resourceType.map( (item: any) => item['@id']); + const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']); if (types.includes('Project')) { return 'project'; } else if (types.includes('Registration')) { diff --git a/lib/osf-components/addon/components/search-page/template.hbs b/lib/osf-components/addon/components/search-page/template.hbs index 0a59a7044e..9ee2c869c5 100644 --- a/lib/osf-components/addon/components/search-page/template.hbs +++ b/lib/osf-components/addon/components/search-page/template.hbs @@ -221,6 +221,9 @@ as |layout|>
{{/unless}} + {{#each this.searchResults as |item|}} + + {{/each}} {{#if this.showTooltip1}} diff --git a/lib/osf-components/addon/components/search-result-card/component.ts b/lib/osf-components/addon/components/search-result-card/component.ts index 4fda401ace..9c9de50ee9 100644 --- a/lib/osf-components/addon/components/search-result-card/component.ts +++ b/lib/osf-components/addon/components/search-result-card/component.ts @@ -1,25 +1,12 @@ import { action } from '@ember/object'; -import Component from '@glimmer/component' -import { tracked } from '@glimmer/tracking' +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; import SearchResultModel from 'ember-osf-web/models/search-result'; import { inject as service } from '@ember/service'; import Intl from 'ember-intl/services/intl'; interface Args { result: SearchResultModel; - // displayName: string; - // nameFields: string[]; - // dateFields: string[]; - // context: string; - // secondaryMetadata: any; -} - -const ResourceTypeCardLabelMap = { - 'osf:Registration': 'registration', - 'osf:RegistrationComponent': 'registration_component', - 'osf:Project': 'project', - 'osf:ProjectComponent': 'project_component', - 'osf:File': 'file', } export default class SearchResultCard extends Component { diff --git a/lib/osf-components/addon/components/search-result-card/styles.scss b/lib/osf-components/addon/components/search-result-card/styles.scss index c8fd315a5c..347f743074 100644 --- a/lib/osf-components/addon/components/search-result-card/styles.scss +++ b/lib/osf-components/addon/components/search-result-card/styles.scss @@ -17,3 +17,11 @@ padding: 5px; background-color: $color-gradient-primary; } + +.date-fields { + span { + &:not(:last-child)::after { + content: ' | '; + } + } +} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 65b54fefec..fe6a9a6abc 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -19,7 +19,7 @@

- {{@result.displayTitle}} + {{@result.displayTitle}}

+ {{#if @result.isPartOf}} +
+ {{@result.isPartOf.label}}: {{@result.isPartOf.title}} +
+ {{/if}}
{{#each @result.dateFields as |field|}} {{field.label}}: {{field.date}} diff --git a/translations/en-us.yml b/translations/en-us.yml index 77168386b8..2a63b905bb 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1848,7 +1848,10 @@ routes: email: Email osf-components: search-result-card: + from: From date_created: Date created + date_registered: Date registered + date_modified: Date modified last_edited: Last edited member_since: Member since project: Project From 9ada49c6df18d34afcc77da8f0020787b941a83d Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Sun, 30 Jul 2023 19:07:24 -0400 Subject: [PATCH 17/24] registration secondary metadata --- app/models/search-result.ts | 18 ++++++++++++ .../template.hbs | 28 +++++++++++++++++++ .../search-result-card/template.hbs | 4 ++- .../template.js | 1 + translations/en-us.yml | 5 ++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 2b40061f46..7c5ee74d97 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -108,6 +108,24 @@ export default class SearchResultModel extends Model { return null; } + get funders() { + return this.resourceMetadata.funder.map( (item: any) => ({ + name: item.name[0]['@value'], + identifier: item.identifier[0]['@value'], + })); + } + + get doi() { + return this.indexCard.get('resourceIdentifier').filter(id => id.includes('https://doi.org')); + } + + get license() { + return { + name: this.resourceMetadata.rights[0].name[0]['@value'], + identifier: this.resourceMetadata.rights[0]['@id'], + }; + } + get resourceType() { const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']); if (types.includes('Project')) { diff --git a/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs new file mode 100644 index 0000000000..d5e2999ea4 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs @@ -0,0 +1,28 @@ +
+ {{t 'osf-components.search-result-card.funder'}}: + + {{list.item.name}} + +
+
+ {{t 'osf-components.search-result-card.registration_template'}}: +
+
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
\ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index fe6a9a6abc..4c15cf10b1 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -50,7 +50,9 @@
- This is the body + {{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + + {{/if}}
\ No newline at end of file diff --git a/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js b/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js new file mode 100644 index 0000000000..f76c747316 --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/registration-secondary-metadata/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/registration-secondary-metadata/template'; diff --git a/translations/en-us.yml b/translations/en-us.yml index 2a63b905bb..ed6383c74c 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1848,6 +1848,11 @@ routes: email: Email osf-components: search-result-card: + funder: Funder + registration_template: Registration template + doi: DOI + description: Description + license: License from: From date_created: Date created date_registered: Date registered From a946c397e92791060a2f2bf3b6b977a7c17e0a29 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 2 Aug 2023 02:38:57 -0400 Subject: [PATCH 18/24] prelim project secondary metadata --- app/models/search-result.ts | 11 ++++--- .../project-secondary-metadata/template.hbs | 30 +++++++++++++++++++ .../search-result-card/template.hbs | 2 ++ .../project-secondary-metadata/template.js | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs create mode 100644 lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 7c5ee74d97..47e78caa07 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -109,10 +109,13 @@ export default class SearchResultModel extends Model { } get funders() { - return this.resourceMetadata.funder.map( (item: any) => ({ - name: item.name[0]['@value'], - identifier: item.identifier[0]['@value'], - })); + if (this.resourceMetadata.funder) { + return this.resourceMetadata.funder.map( (item: any) => ({ + name: item.name[0]['@value'], + identifier: item.identifier[0]['@value'], + })); + } + return null; } get doi() { diff --git a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs new file mode 100644 index 0000000000..cea2044043 --- /dev/null +++ b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs @@ -0,0 +1,30 @@ +{{#if @result.funders}} +
+ {{t 'osf-components.search-result-card.funder'}}: + + {{list.item.name}} + +
+{{/if}} +
+ {{t 'osf-components.search-result-card.description'}}: +
+
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
\ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 4c15cf10b1..e203af8075 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -52,6 +52,8 @@
{{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + {{else if (or (eq @result.resourceType 'project') (eq @result.resourceType 'project_component'))}} + {{/if}} diff --git a/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js b/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js new file mode 100644 index 0000000000..7ab736d92f --- /dev/null +++ b/lib/osf-components/app/components/search-result-card/project-secondary-metadata/template.js @@ -0,0 +1 @@ +export { default } from 'osf-components/components/search-result-card/project-secondary-metadata/template'; From d3ff44f504653cc91b46ed9926c394d755dec898 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Tue, 8 Aug 2023 01:18:19 -0400 Subject: [PATCH 19/24] added a bun of optional chaining to avoid errors --- app/models/search-result.ts | 29 +++++----- .../template.hbs | 56 ++++++++++--------- .../search-result-card/template.hbs | 22 ++++---- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 47e78caa07..449c37cbd0 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -49,7 +49,7 @@ export default class SearchResultModel extends Model { } else if (this.resourceType === 'file') { return this.resourceMetadata['fileName'][0]['@value']; } - return this.resourceMetadata['title'][0]['@value']; + return this.resourceMetadata['title']?.[0]['@value']; } get absoluteUrl() { @@ -62,7 +62,7 @@ export default class SearchResultModel extends Model { if (this.resourceType === 'user') { // return something } else { - return this.resourceMetadata.creator.map( (item:any) => item.name[0]['@value']); + return this.resourceMetadata.creator?.map( (item:any) => item.name[0]['@value']); } } @@ -75,22 +75,22 @@ export default class SearchResultModel extends Model { return [ { label: this.intl.t('osf-components.search-result-card.date_registered'), - date: this.resourceMetadata.dateCreated[0]['@value'], + date: this.resourceMetadata.dateCreated?.[0]['@value'], }, { label: this.intl.t('osf-components.search-result-card.date_modified'), - date: this.resourceMetadata.dateModified[0]['@value'], + date: this.resourceMetadata.dateModified?.[0]['@value'], }, ]; default: return [ { label: this.intl.t('osf-components.search-result-card.date_created'), - date: this.resourceMetadata.dateCreated[0]['@value'], + date: this.resourceMetadata.dateCreated?.[0]['@value'], }, { label: this.intl.t('osf-components.search-result-card.date_modified'), - date: this.resourceMetadata.dateModified[0]['@value'], + date: this.resourceMetadata.dateModified?.[0]['@value'], }, ]; } @@ -101,8 +101,8 @@ export default class SearchResultModel extends Model { if (isPartOf) { return { label: this.intl.t('osf-components.search-result-card.from'), - title: this.resourceMetadata.isPartOf[0].title[0]['@value'], - absoluteUrl: this.resourceMetadata.isPartOf[0]['@id'], + title: this.resourceMetadata.isPartOf?.[0]?.title?.[0]?.['@value'], + absoluteUrl: this.resourceMetadata.isPartOf?.[0]?.['@id'], }; } return null; @@ -112,7 +112,7 @@ export default class SearchResultModel extends Model { if (this.resourceMetadata.funder) { return this.resourceMetadata.funder.map( (item: any) => ({ name: item.name[0]['@value'], - identifier: item.identifier[0]['@value'], + identifier: item.identifier?.[0]['@value'], })); } return null; @@ -123,10 +123,13 @@ export default class SearchResultModel extends Model { } get license() { - return { - name: this.resourceMetadata.rights[0].name[0]['@value'], - identifier: this.resourceMetadata.rights[0]['@id'], - }; + if (this.resourceMetadata.rights) { + return { + name: this.resourceMetadata.rights?.[0].name[0]['@value'], + identifier: this.resourceMetadata.rights?.[0]['@id'], + }; + } + return null; } get resourceType() { diff --git a/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs index d5e2999ea4..eb12ed9358 100644 --- a/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/registration-secondary-metadata/template.hbs @@ -1,28 +1,34 @@ -
- {{t 'osf-components.search-result-card.funder'}}: - - {{list.item.name}} - -
+{{#if @result.funder}} +
+ {{t 'osf-components.search-result-card.funder'}}: + + {{list.item.name}} + +
+{{/if}}
{{t 'osf-components.search-result-card.registration_template'}}:
-
- {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} -
-
- {{t 'osf-components.search-result-card.doi'}}: - - {{list.item}} - -
\ No newline at end of file +{{#if @result.license}} +
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+{{/if}} +{{#if @result.doi}} +
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
+{{/if}} \ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index e203af8075..5e4ece537b 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -21,16 +21,18 @@

{{@result.displayTitle}}

-
- - {{list.item}} - -
+ {{#if @result.affiliatedEntities}} +
+ + {{list.item}} + +
+ {{/if}} {{#if @result.isPartOf}}
{{@result.isPartOf.label}}: {{@result.isPartOf.title}} From 3d76cd5fd4b07ccb5e255bb57bbf59b6b6bbea63 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Tue, 8 Aug 2023 08:27:16 -0400 Subject: [PATCH 20/24] make sure context field works --- app/models/search-result.ts | 19 ++++++++++++------- .../search-result-card/template.hbs | 10 +++++----- translations/en-us.yml | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 7e919b082b..c21f117330 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -1,19 +1,22 @@ import Model, { attr, belongsTo } from '@ember-data/model'; import { inject as service } from '@ember/service'; +import { htmlSafe } from '@ember/template'; import IntlService from 'ember-intl/services/intl'; import IndexCardModel from './index-card'; +const textMatchEvidenceType = 'https://share.osf.io/vocab/2023/trove/TextMatchEvidence'; + export interface IriMatchEvidence { - '@type': 'IriMatchEvidence'; + '@type': [string]; matchingIri: string; - propertyPath: string[]; + osfmapPropertyPath: string[]; } export interface TextMatchEvidence { - '@type': 'TextMatchEvidence'; + '@type': [string]; matchingHighlight: string; - propertyPath: string[]; + osfmapPropertyPath: string[]; } export default class SearchResultModel extends Model { @@ -32,13 +35,15 @@ export default class SearchResultModel extends Model { // TODO: double check how matchEvidence works get context() { if (this.matchEvidence) { - return this.matchEvidence.reduce( + const matchEvidenceString = this.matchEvidence.reduce( (acc, current) => acc.concat( - `${current.propertyPath}: - ${current['@type'] === 'TextMatchEvidence' ? current.matchingHighlight : current.matchingIri}`, + `${current.osfmapPropertyPath[0]}: ${current['@type'][0] === textMatchEvidenceType + ? (current as TextMatchEvidence).matchingHighlight + : (current as IriMatchEvidence).matchingIri}; `, ), '', ); + return htmlSafe(matchEvidenceString); } return null; } diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 86de8e8c29..a1db212720 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -43,11 +43,11 @@ {{field.label}}: {{field.date}} {{/each}}
-
-

- {{@result.context}} -

-
+ {{#if @result.context}} +
+ {{t 'osf-components.search-result-card.context'}}: {{@result.context}} +
+ {{/if}} diff --git a/translations/en-us.yml b/translations/en-us.yml index 556ad2df02..80d2b2dc4d 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1848,6 +1848,7 @@ routes: email: Email osf-components: search-result-card: + context: Context funder: Funder registration_template: Registration template doi: DOI From 80689e9ae2dedb5b73f4a2fcb7a0c20870123f61 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 9 Aug 2023 00:06:10 -0400 Subject: [PATCH 21/24] fix tests --- .../project-secondary-metadata/template.hbs | 40 ++++++----- mirage/views/search.ts | 69 +++++++++++-------- 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs index cea2044043..78a7c50b88 100644 --- a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs @@ -11,20 +11,26 @@ {{/if}} -
- {{t 'osf-components.search-result-card.description'}}: -
-
- {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} -
-
- {{t 'osf-components.search-result-card.doi'}}: - - {{list.item}} - -
\ No newline at end of file +{{#if @result.description}} +
+ {{t 'osf-components.search-result-card.description'}}: {{@result.description}} +
+{{/if}} +{{#if @result.license}} +
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
+{{/if}} +{{#if @result.doi}} +
+ {{t 'osf-components.search-result-card.doi'}}: + + {{list.item}} + +
+{{/if}} \ No newline at end of file diff --git a/mirage/views/search.ts b/mirage/views/search.ts index d8db249102..edab0c7ed3 100644 --- a/mirage/views/search.ts +++ b/mirage/views/search.ts @@ -11,14 +11,14 @@ export function cardSearch(_: Schema, __: Request) { cardSearchText: 'hello', cardSearchFilter: [ { - propertyPath: 'resourceType', + osfmapPropertyPath: 'resourceType', filterType: 'eq', filterValues: [ 'osf:Registration', ], }, { - propertyPath: 'subject', + osfmapPropertyPath: 'subject', filterType: 'eq', filterValues: [ 'https://subjects.org/subjectId', @@ -63,11 +63,13 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'description', + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'description', matchingHighlight: '... say hello!', }, { - propertyPath: 'title', + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'title', matchingHighlight: '... shout hello!', }, ], @@ -90,7 +92,8 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'description', + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'description', matchingHighlight: '... computer said hello world!', }, ], @@ -113,7 +116,8 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'title', + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'title', matchingHighlight: '... you said hello!', }, ], @@ -134,15 +138,15 @@ export function cardSearch(_: Schema, __: Request) { type: 'index-card', id: 'abc', attributes: { - resourceType: [ - 'osf:Registration', - 'dcterms:Dataset', - ], resourceIdentifier: [ 'https://osf.example/abcfoo', 'https://doi.org/10.0000/osf.example/abcfoo', ], resourceMetadata: { + resourceType: [ + 'osf:Registration', + 'dcterms:Dataset', + ], '@id': 'https://osf.example/abcfoo', '@type': 'osf:Registration', title: [ @@ -203,12 +207,12 @@ export function cardSearch(_: Schema, __: Request) { ], }, ], - creator: { + creator: [{ '@id': 'https://osf.example/person', '@type': 'dcterms:Agent', specificType: 'foaf:Person', name: 'person person, prsn', - }, + }], }, }, links: { @@ -220,15 +224,15 @@ export function cardSearch(_: Schema, __: Request) { type: 'index-card', id: 'def', attributes: { - resourceType: [ - 'osf:Registration', - 'dcterms:Dataset', - ], resourceIdentifier: [ 'https://osf.example/abcfoo', 'https://doi.org/10.0000/osf.example/abcfoo', ], resourceMetadata: { + resourceType: [ + 'osf:Registration', + 'dcterms:Dataset', + ], '@id': 'https://osf.example/abcfoo', '@type': 'osf:Registration', title: [ @@ -248,15 +252,15 @@ export function cardSearch(_: Schema, __: Request) { type: 'index-card', id: 'ghi', attributes: { - resourceType: [ - 'osf:Registration', - 'dcterms:Dataset', - ], resourceIdentifier: [ 'https://osf.example/abcfoo', 'https://doi.org/10.0000/osf.example/abcfoo', ], resourceMetadata: { + resourceType: [ + 'osf:Registration', + 'dcterms:Dataset', + ], '@id': 'https://osf.example/abcfoo', '@type': 'osf:Registration', title: [ @@ -340,7 +344,8 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'resourceType', + '@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'], + osfmapPropertyPath: 'resourceType', matchingIri: 'rdf:Property', }, ], @@ -364,7 +369,8 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'resourceType', + '@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'], + osfmapPropertyPath: 'resourceType', matchingIri: 'rdf:Property', }, ], @@ -388,7 +394,8 @@ export function cardSearch(_: Schema, __: Request) { attributes: { matchEvidence: [ { - propertyPath: 'resourceType', + '@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'], + osfmapPropertyPath: 'resourceType', matchingIri: 'rdf:Property', }, ], @@ -517,7 +524,7 @@ export function valueSearch(_: Schema, __: Request) { valueSearchText: 'Institute of Health', valueSearchFilter: [ { - propertyPath: 'resourceType', + osfmapPropertyPath: 'resourceType', filterType: 'eq', filterValues: ['datacite:Funder'], }, @@ -525,7 +532,7 @@ export function valueSearch(_: Schema, __: Request) { cardSearchText: 'influenza', cardSearchFilter: [ { - propertyPath: 'resourceType', + osfmapPropertyPath: 'resourceType', filterType: 'eq', filterValues: ['datacite:Dataset'], }, @@ -554,7 +561,11 @@ export function valueSearch(_: Schema, __: Request) { id: property1Id, attributes: { matchEvidence: [ - {propertyPath: 'title', matchingHighlight: 'National Institute of Health'}, + { + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'title', + matchingHighlight: 'National Institute of Health', + }, ], recordResultCount: 2134, }, @@ -570,7 +581,11 @@ export function valueSearch(_: Schema, __: Request) { id: property2Id, attributes: { matchEvidence: [ - {propertyPath: 'title', matchingHighlight: 'Virginia Institute of Health'}, + { + '@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'], + osfmapPropertyPath: 'title', + matchingHighlight: 'Virginia Institute of Health', + }, ], recordResultCount: 2, }, From f0e604deef75b8ce06c3631d53f9f4c46b286cba Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 9 Aug 2023 01:46:39 -0400 Subject: [PATCH 22/24] add open badges list to registration search results --- app/models/search-result.ts | 20 ++++ .../addon/components/node-card/template.hbs | 1 + .../components/open-badges-list/styles.scss | 5 + .../components/open-badges-list/template.hbs | 112 ++++++++++++------ .../search-result-card/template.hbs | 11 ++ 5 files changed, 112 insertions(+), 37 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index c21f117330..4add043398 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -166,6 +166,26 @@ export default class SearchResultModel extends Model { } return 'unknown'; } + + get hasDataResource() { + return this.resourceMetadata.hasDataResource; + } + + get hasAnalyticCodeResource() { + return this.resourceMetadata.hasAnalyticCodeResource; + } + + get hasMaterialsResource() { + return this.resourceMetadata.hasMaterialsResource; + } + + get hasPapersResource() { + return this.resourceMetadata.hasPapersResource; + } + + get hasSupplementalResource() { + return this.resourceMetadata.hasSupplementalResource; + } } declare module 'ember-data/types/registries/model' { diff --git a/lib/osf-components/addon/components/node-card/template.hbs b/lib/osf-components/addon/components/node-card/template.hbs index 5a1fdef3a7..6abbf9e90b 100644 --- a/lib/osf-components/addon/components/node-card/template.hbs +++ b/lib/osf-components/addon/components/node-card/template.hbs @@ -271,6 +271,7 @@ @hasPapers={{@node.hasPapers}} @hasSupplements={{@node.hasSupplements}} @registration={{@node.id}} + @verticalLayout={{true}} /> {{/if}} diff --git a/lib/osf-components/addon/components/open-badges-list/styles.scss b/lib/osf-components/addon/components/open-badges-list/styles.scss index efe3c52c42..52460f034d 100644 --- a/lib/osf-components/addon/components/open-badges-list/styles.scss +++ b/lib/osf-components/addon/components/open-badges-list/styles.scss @@ -2,3 +2,8 @@ font-weight: 700; margin-top: 0; } + +.horizontal-layout { + display: flex; + gap: 10px; +} diff --git a/lib/osf-components/addon/components/open-badges-list/template.hbs b/lib/osf-components/addon/components/open-badges-list/template.hbs index ae9faebb8f..dbfae49ba4 100644 --- a/lib/osf-components/addon/components/open-badges-list/template.hbs +++ b/lib/osf-components/addon/components/open-badges-list/template.hbs @@ -1,37 +1,75 @@ -
- {{#unless this.isMobile}} -
- {{t 'osf-components.open-badges-list.title'}} -
- {{/unless}} - - - - - -
+{{#if @verticalLayout}} +
+ {{#unless this.isMobile}} +
+ {{t 'osf-components.open-badges-list.title'}} +
+ {{/unless}} + + + + + +
+{{else}} +
+ {{t 'osf-components.open-badges-list.title'}} +
+
+ + + + + +
+{{/if}} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index a1db212720..1e468a01a5 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -48,6 +48,17 @@ {{t 'osf-components.search-result-card.context'}}: {{@result.context}} {{/if}} + {{#if (or (eq @result.resourceType 'registration') (eq @result.resourceType 'registration_component'))}} + + {{/if}} From 4e7695ef78f1fbe08356c55ed56846209a7875b7 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 9 Aug 2023 08:04:49 -0400 Subject: [PATCH 23/24] fix open resource badges routing --- .../open-badges-list/open-badge-card/template.hbs | 5 +++-- .../addon/components/open-badges-list/template.hbs | 10 ++++++++++ .../addon/components/search-result-card/template.hbs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/osf-components/addon/components/open-badges-list/open-badge-card/template.hbs b/lib/osf-components/addon/components/open-badges-list/open-badge-card/template.hbs index e77dd16ce0..26a1822f18 100644 --- a/lib/osf-components/addon/components/open-badges-list/open-badge-card/template.hbs +++ b/lib/osf-components/addon/components/open-badges-list/open-badge-card/template.hbs @@ -2,8 +2,9 @@ {{else}} @@ -46,30 +51,35 @@ @resourceType='data' @isMobile={{this.isMobile}} @registration={{@registration}} + @absoluteUrl={{@absoluteUrl}} /> {{/if}} diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 1e468a01a5..3894b2ba15 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -55,7 +55,7 @@ @hasAnalyticCode={{@result.hasAnalyticCodeResource}} @hasPapers={{@result.hasPapersResource}} @hasSupplements={{@result.hasSupplementsResource}} - @registration={{'abcde'}} + @absoluteUrl={{@result.absoluteUrl}} @verticalLayout={{false}} /> {{/if}} From c4120a5cec0321e2b231d37a68485046ef396411 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 9 Aug 2023 09:17:39 -0400 Subject: [PATCH 24/24] fix misc. stuff --- app/models/search-result.ts | 20 ++++++++++++++++++- .../project-secondary-metadata/template.hbs | 18 +++++++++++++---- .../search-result-card/template.hbs | 6 ++++-- .../addon/branded/discover/controller.ts | 6 +++--- .../open-badges-list/component-test.ts | 6 ++++++ translations/en-us.yml | 1 + 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app/models/search-result.ts b/app/models/search-result.ts index 4add043398..525c4e9872 100644 --- a/app/models/search-result.ts +++ b/app/models/search-result.ts @@ -57,6 +57,10 @@ export default class SearchResultModel extends Model { return this.resourceMetadata['title']?.[0]['@value']; } + get description() { + return this.resourceMetadata.description?.[0]?.['@value']; + } + get absoluteUrl() { return this.resourceMetadata['@id']; } @@ -105,7 +109,6 @@ export default class SearchResultModel extends Model { const isPartOf = this.resourceMetadata.isPartOf; if (isPartOf) { return { - label: this.intl.t('osf-components.search-result-card.from'), title: this.resourceMetadata.isPartOf?.[0]?.title?.[0]?.['@value'], absoluteUrl: this.resourceMetadata.isPartOf?.[0]?.['@id'], }; @@ -113,6 +116,21 @@ export default class SearchResultModel extends Model { return null; } + get isPartOfCollection() { + const isPartOfCollection = this.resourceMetadata.isPartOfCollection; + if (isPartOfCollection) { + return { + title: this.resourceMetadata.isPartOfCollection?.[0]?.title?.[0]?.['@value'], + absoluteUrl: this.resourceMetadata.isPartOfCollection?.[0]?.['@id'], + }; + } + return null; + } + + get language() { + return this.resourceMetadata.language; + } + get funders() { if (this.resourceMetadata.funder) { return this.resourceMetadata.funder.map( (item: any) => ({ diff --git a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs index 78a7c50b88..6208846eb6 100644 --- a/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/project-secondary-metadata/template.hbs @@ -1,3 +1,8 @@ +{{#if @result.description}} +
+ {{t 'osf-components.search-result-card.description'}}: {{@result.description}} +
+{{/if}} {{#if @result.funders}}
{{t 'osf-components.search-result-card.funder'}}: @@ -11,14 +16,14 @@
{{/if}} -{{#if @result.description}} +{{#if @result.isPartOfCollection}}
- {{t 'osf-components.search-result-card.description'}}: {{@result.description}} + {{t 'osf-components.search-result-card.collection'}}: {{@result.isPartOfCollection.title}}
{{/if}} -{{#if @result.license}} +{{#if @resource.language}}
- {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} + {{t 'osf-components.search-result-card.language'}}: {{@resource.language}}
{{/if}} {{#if @result.doi}} @@ -33,4 +38,9 @@ {{list.item}} +{{/if}} +{{#if @result.license}} +
+ {{t 'osf-components.search-result-card.license'}}: {{@result.license.name}} +
{{/if}} \ No newline at end of file diff --git a/lib/osf-components/addon/components/search-result-card/template.hbs b/lib/osf-components/addon/components/search-result-card/template.hbs index 3894b2ba15..5d4e3f3167 100644 --- a/lib/osf-components/addon/components/search-result-card/template.hbs +++ b/lib/osf-components/addon/components/search-result-card/template.hbs @@ -35,12 +35,14 @@ {{/if}} {{#if @result.isPartOf}}
- {{@result.isPartOf.label}}: {{@result.isPartOf.title}} + {{t 'osf-components.search-result-card.from'}}: {{@result.isPartOf.title}}
{{/if}}
{{#each @result.dateFields as |field|}} - {{field.label}}: {{field.date}} + {{#if field.date}} + {{field.label}}: {{field.date}} + {{/if}} {{/each}}
{{#if @result.context}} diff --git a/lib/registries/addon/branded/discover/controller.ts b/lib/registries/addon/branded/discover/controller.ts index 510af36744..c67c24a681 100644 --- a/lib/registries/addon/branded/discover/controller.ts +++ b/lib/registries/addon/branded/discover/controller.ts @@ -15,11 +15,11 @@ export default class BrandedDiscover extends Controller.extend() { @service intl!: Intl; @service store!: Store; - @tracked q? = ''; + @tracked cardSearchText? = ''; @tracked sort? = '-relevance'; @tracked page? = ''; - queryParams = ['q', 'page', 'sort']; + queryParams = ['cardSearchText', 'page', 'sort']; get defaultQueryOptions() { return { @@ -29,7 +29,7 @@ export default class BrandedDiscover extends Controller.extend() { @action onSearch(onSearchParams: OnSearchParams) { - this.q = onSearchParams.q; + this.cardSearchText = onSearchParams.cardSearchText; this.page = onSearchParams.page; this.sort = onSearchParams.sort; } diff --git a/tests/integration/components/open-badges-list/component-test.ts b/tests/integration/components/open-badges-list/component-test.ts index 6d6847cf8a..971bf322ca 100644 --- a/tests/integration/components/open-badges-list/component-test.ts +++ b/tests/integration/components/open-badges-list/component-test.ts @@ -37,6 +37,7 @@ module('Integration | Component | open-badges-list', hooks => { @hasPapers={{true}} @hasSupplements={{true}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-list-title]') .hasText(t('osf-components.open-badges-list.title'), 'Title shows in desktop'); @@ -52,6 +53,7 @@ module('Integration | Component | open-badges-list', hooks => { @hasPapers={{false}} @hasSupplements={{false}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-list-title]') .doesNotExist('Title does not show in mobile'); @@ -65,6 +67,7 @@ module('Integration | Component | open-badges-list', hooks => { @hasAnalyticCode={{true}} @hasMaterials={{true}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-image="data"]').hasAttribute( 'src', @@ -113,6 +116,7 @@ module('Integration | Component | open-badges-list | open-badge-card', hooks => @resourceType='data' @isMobile={{false}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-image="data"]').hasAttribute( 'src', @@ -138,6 +142,7 @@ module('Integration | Component | open-badges-list | open-badge-card', hooks => @resourceType='materials' @isMobile={{true}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-image="materials"]').hasAttribute( 'src', @@ -168,6 +173,7 @@ module('Integration | Component | open-badges-list | open-badge-card', hooks => @resourceType='materials' @isMobile={{true}} @registration='guid1' + @verticalLayout={{true}} />`); assert.dom('[data-test-badge-image="materials"]').hasAttribute( 'src', diff --git a/translations/en-us.yml b/translations/en-us.yml index 80d2b2dc4d..007e1d6fcb 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1848,6 +1848,7 @@ routes: email: Email osf-components: search-result-card: + collection: Collection context: Context funder: Funder registration_template: Registration template