Skip to content

Commit

Permalink
[ENG-6419] Update SHARE getters (#2384)
Browse files Browse the repository at this point in the history
* Update getters in institution dashboard controllers

* Update getters in search-result model
  • Loading branch information
futa-ikeda authored Nov 7, 2024
1 parent 3931250 commit 0efac04
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
5 changes: 3 additions & 2 deletions app/institutions/dashboard/preprints/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import { getSingleOsfmapValue } from 'ember-osf-web/packages/osfmap/jsonld';

import { ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import { ObjectListColumn } from '../-components/object-list/component';
Expand All @@ -21,12 +22,12 @@ export default class InstitutionDashboardPreprints extends Controller {
},
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateCreated'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateModified'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
},
{ // DOI
Expand Down
9 changes: 5 additions & 4 deletions app/institutions/dashboard/projects/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import { getSingleOsfmapValue } from 'ember-osf-web/packages/osfmap/jsonld';


import humanFileSize from 'ember-osf-web/utils/human-file-size';
Expand All @@ -23,12 +24,12 @@ export default class InstitutionDashboardProjects extends Controller {
},
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateCreated'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateModified'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
},
{ // DOI
Expand All @@ -42,7 +43,7 @@ export default class InstitutionDashboardProjects extends Controller {
{ // Total data stored
name: this.intl.t('institutions.dashboard.object-list.table-headers.total_data_stored'),
getValue: searchResult => {
const byteCount = searchResult.getResourceMetadataField('storageByteCount');
const byteCount = getSingleOsfmapValue(searchResult.resourceMetadata, ['storageByteCount']);
return byteCount ? humanFileSize(byteCount) :
this.intl.t('institutions.dashboard.object-list.table-items.no-storage-info');
},
Expand Down Expand Up @@ -76,7 +77,7 @@ export default class InstitutionDashboardProjects extends Controller {
name: this.intl.t('institutions.dashboard.object-list.table-headers.addons'),
getValue: searchResult => {
const field = this.intl.t('institutions.dashboard.object-list.table-headers.addons');
return searchResult.configuredAddonNames ||
return searchResult.configuredAddonNames.length ? searchResult.configuredAddonNames :
this.intl.t('institutions.dashboard.object-list.table-items.no-info', { field });
},
},
Expand Down
7 changes: 4 additions & 3 deletions app/institutions/dashboard/registrations/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import { getSingleOsfmapValue } from 'ember-osf-web/packages/osfmap/jsonld';

import humanFileSize from 'ember-osf-web/utils/human-file-size';
import { ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
Expand All @@ -22,12 +23,12 @@ export default class InstitutionDashboardRegistrations extends Controller {
},
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateCreated'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => searchResult.getResourceMetadataField('dateModified'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
},
{ // DOI
Expand All @@ -41,7 +42,7 @@ export default class InstitutionDashboardRegistrations extends Controller {
{ // Total data stored
name: this.intl.t('institutions.dashboard.object-list.table-headers.total_data_stored'),
getValue: searchResult => {
const byteCount = searchResult.getResourceMetadataField('storageByteCount');
const byteCount = getSingleOsfmapValue(searchResult.resourceMetadata, ['storageByteCount']);
return byteCount ? humanFileSize(byteCount) :
this.intl.t('institutions.dashboard.object-list.table-items.no-storage-info');
},
Expand Down
78 changes: 37 additions & 41 deletions app/models/search-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 { getOsfmapValues, getSingleOsfmapObject, getSingleOsfmapValue } from 'ember-osf-web/packages/osfmap/jsonld';
import { languageFromLanguageCode } from 'osf-components/components/file-metadata-manager/component';

import IndexCardModel from './index-card';
Expand Down Expand Up @@ -62,22 +63,22 @@ export default class SearchResultModel extends Model {

get displayTitle() {
if (this.resourceType === 'user') {
return this.resourceMetadata['name'][0]['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['name']);
} else if (this.resourceType === 'file') {
return this.resourceMetadata['fileName'][0]['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['fileName']);
}
return this.resourceMetadata['title']?.[0]['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['title']);
}

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

get description() {
return this.resourceMetadata.description?.[0]?.['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['description']);
}

get absoluteUrl() {
Expand All @@ -90,14 +91,14 @@ export default class SearchResultModel extends Model {
if (this.resourceType === 'user') {
if (this.resourceMetadata.affiliation) {
return this.resourceMetadata.affiliation.map((item: any) =>
({ name: item.name[0]['@value'], absoluteUrl: item['@id'] }));
({ name: getSingleOsfmapValue(item, ['name']), absoluteUrl: item['@id'] }));
}
} else if (this.resourceMetadata.creator) {
return this.resourceMetadata.creator?.map((item: any) =>
({ name: item.name[0]['@value'], absoluteUrl: item['@id'] }));
({ name: getSingleOsfmapValue(item, ['name']), absoluteUrl: item['@id'] }));
} else if (this.isContainedBy?.[0]?.creator) {
return this.isContainedBy[0].creator.map((item: any) =>
({ name: item.name?.[0]?.['@value'], absoluteUrl: item['@id'] }));
({ name: getSingleOsfmapValue(item, ['name']), absoluteUrl: item['@id'] }));
}
}

Expand All @@ -110,22 +111,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: getSingleOsfmapValue(this.resourceMetadata, ['dateCreated']),
},
{
label: this.intl.t('osf-components.search-result-card.date_modified'),
date: this.resourceMetadata.dateModified?.[0]['@value'],
date: getSingleOsfmapValue(this.resourceMetadata, ['dateModified']),
},
];
default:
return [
{
label: this.intl.t('osf-components.search-result-card.date_created'),
date: this.resourceMetadata.dateCreated?.[0]['@value'],
date: getSingleOsfmapValue(this.resourceMetadata, ['dateCreated']),
},
{
label: this.intl.t('osf-components.search-result-card.date_modified'),
date: this.resourceMetadata.dateModified?.[0]['@value'],
date: getSingleOsfmapValue(this.resourceMetadata, ['dateModified']),
},
];
}
Expand Down Expand Up @@ -163,25 +164,26 @@ export default class SearchResultModel extends Model {
const isPartOfCollection = this.resourceMetadata.isPartOfCollection;
if (isPartOfCollection) {
return {
title: this.resourceMetadata.isPartOfCollection?.[0]?.title?.[0]?.['@value'],
absoluteUrl: this.resourceMetadata.isPartOfCollection?.[0]?.['@id'],
title: getSingleOsfmapValue(this.resourceMetadata, ['isPartOfCollection', 'title']),
absoluteUrl: getSingleOsfmapValue(this.resourceMetadata, ['isPartOfCollection']),
};
}
return null;
}

get languageFromCode() {
if (this.resourceMetadata.language) {
return languageFromLanguageCode(this.resourceMetadata.language[0]['@value']);
const language = getSingleOsfmapValue(this.resourceMetadata, ['language']);
return languageFromLanguageCode(language);
}
return null;
}

get funders() {
if (this.resourceMetadata.funder) {
return this.resourceMetadata.funder.map( (item: any) => ({
name: item.name[0]['@value'],
identifier: item.identifier?.[0]['@value'],
name: getSingleOsfmapValue(item, ['name']),
identifier: getSingleOsfmapValue(item, ['identifier']),
}));
}
return null;
Expand All @@ -190,8 +192,8 @@ export default class SearchResultModel extends Model {
get nodeFunders() {
if (this.resourceMetadata.isContainedBy?.[0]?.funder) {
return this.resourceMetadata.isContainedBy[0].funder.map( (item: any) => ({
name: item.name[0]['@value'],
identifier: item.identifier?.[0]['@value'],
name: getSingleOsfmapValue(item, ['name']),
identifier: getSingleOsfmapValue(item, ['identifier']),
}));
}
return null;
Expand All @@ -200,8 +202,8 @@ export default class SearchResultModel extends Model {
get provider() {
if (this.resourceMetadata.publisher) {
return {
name: this.resourceMetadata.publisher[0]?.name?.[0]['@value'],
identifier: this.resourceMetadata.publisher[0]['@id'],
name: getSingleOsfmapValue(this.resourceMetadata, ['publisher', 'name']),
identifier: getSingleOsfmapValue(this.resourceMetadata, ['publisher']),
};
}
return null;
Expand All @@ -214,8 +216,8 @@ export default class SearchResultModel extends Model {
get license() {
if (this.resourceMetadata.rights) {
return {
name: this.resourceMetadata.rights?.[0]?.name?.[0]?.['@value'],
identifier: this.resourceMetadata.rights?.[0]?.['@id'],
name: getSingleOsfmapValue(this.resourceMetadata, ['rights', 'name']),
identifier: getSingleOsfmapValue(this.resourceMetadata, ['rights']),
};
}
return null;
Expand All @@ -224,9 +226,9 @@ export default class SearchResultModel extends Model {
get nodeLicense() {
if (this.resourceMetadata.isContainedBy?.[0]?.rights) {
return {
name: this.resourceMetadata.isContainedBy[0].rights?.[0]?.name?.[0]?.['@value'],
identifier: this.resourceMetadata.rights?.[0]?.['@id'] ||
this.resourceMetadata.isContainedBy[0].rights[0]?.['@id'],
name: getSingleOsfmapValue(this.resourceMetadata, ['isContainedBy', 'rights', 'name']),
identifier: getSingleOsfmapValue(this.resourceMetadata, ['rights']) ||
getSingleOsfmapValue(this.resourceMetadata, ['isContainedBy', 'rights']),
};
}
return null;
Expand Down Expand Up @@ -267,7 +269,7 @@ export default class SearchResultModel extends Model {
}

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

get hasDataResource() {
Expand All @@ -291,38 +293,32 @@ export default class SearchResultModel extends Model {
}

get registrationTemplate() {
return this.resourceMetadata.conformsTo?.[0]?.title?.[0]?.['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['conformsTo', 'title']);
}

get isWithdrawn() {
return this.resourceMetadata.dateWithdrawn || this.resourceMetadata['https://osf.io/vocab/2022/withdrawal'];
}

get configuredAddonNames() {
return this.resourceMetadata.hasOsfAddon?.map((item: any) => item.prefLabel[0]['@value']);
return getOsfmapValues(this.resourceMetadata, ['hasOsfAddon', 'prefLabel']);
}

get storageRegion() {
return this.resourceMetadata.storageRegion?.[0]?.prefLabel[0]['@value'];
return getSingleOsfmapValue(this.resourceMetadata, ['storageRegion', 'prefLabel']);
}

get usageMetrics() {
if (!this.resourceMetadata.usage) {
const usage = getSingleOsfmapObject(this.resourceMetadata, ['usage']);
if (!usage) {
return null;
}
const temporalCoverage = this.resourceMetadata.usage[0]['temporalCoverage'];
const viewCount = this.resourceMetadata.usage[0]['viewCount'];
const downloadCount = this.resourceMetadata.usage[0]['downloadCount'];
return {
period: temporalCoverage ? temporalCoverage[0]['@value'] : null,
viewCount: viewCount ? viewCount[0]['@value'] : null,
downloadCount: downloadCount ? downloadCount[0]['@value'] : null,
period: getSingleOsfmapValue(usage, ['temporalCoverage']),
viewCount: getSingleOsfmapValue(usage, ['viewCount']),
downloadCount: getSingleOsfmapValue(usage, ['downloadCount']),
};
}

getResourceMetadataField(field: string) {
return this.resourceMetadata[field]?.[0]?.['@value'];
}
}

declare module 'ember-data/types/registries/model' {
Expand Down

0 comments on commit 0efac04

Please sign in to comment.