From 4ca1d58bca975dab285fe908d161cfebbee3fdc7 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 19 Dec 2024 09:52:51 -0500 Subject: [PATCH 1/3] implement getFolderItems and getItemInfo in configurated-citiation/storage-addon child classes --- app/models/addon-operation-invocation.ts | 1 + app/models/configured-addon.ts | 32 ++++++------------------ app/models/configured-citation-addon.ts | 28 +++++++++++++++++++++ app/models/configured-storage-addon.ts | 28 +++++++++++++++++++++ 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/app/models/addon-operation-invocation.ts b/app/models/addon-operation-invocation.ts index 656fdf4514..da157eb6ff 100644 --- a/app/models/addon-operation-invocation.ts +++ b/app/models/addon-operation-invocation.ts @@ -14,6 +14,7 @@ export enum ConnectedStorageOperationNames { export enum ConnectedCitationOperationNames { ListRootCollections = 'list_root_collections', ListCollectionItems = 'list_collection_items', + GetItemInfo = 'get_item_info', } export interface OperationKwargs { diff --git a/app/models/configured-addon.ts b/app/models/configured-addon.ts index 215735b35b..daf682601e 100644 --- a/app/models/configured-addon.ts +++ b/app/models/configured-addon.ts @@ -1,10 +1,8 @@ import Model, { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; -import { waitFor } from '@ember/test-waiters'; -import { task } from 'ember-concurrency'; import { ConnectedStorageOperationNames, OperationKwargs } from './addon-operation-invocation'; import UserReferenceModel from './user-reference'; -import { ConnectedCapabilities } from './authorized-account'; +import AuthorizedAccountModel, { ConnectedCapabilities } from './authorized-account'; export interface ConfiguredAddonEditableAttrs { displayName: string; @@ -27,28 +25,14 @@ export default class ConfiguredAddonModel extends Model { @belongsTo('user-reference', { inverse: null }) accountOwner!: AsyncBelongsTo & UserReferenceModel; - @task - @waitFor - async getFolderItems(this: ConfiguredAddonModel, kwargs?: OperationKwargs) { - const operationKwargs = kwargs || {}; - const operationName = operationKwargs.itemId ? ConnectedStorageOperationNames.ListChildItems : - ConnectedStorageOperationNames.ListRootItems; - const newInvocation = this.store.createRecord('addon-operation-invocation', { - operationName, - operationKwargs, - thruAddon: this, - }); - return await newInvocation.save(); + async getFolderItems(this: AuthorizedAccountModel, _kwargs?: OperationKwargs) : Promise { + // To be implemented in child classes + return; } - @task - @waitFor - async getItemInfo(this: ConfiguredAddonModel, itemId: string) { - const newInvocation = this.store.createRecord('addon-operation-invocation', { - operationName: ConnectedStorageOperationNames.GetItemInfo, - operationKwargs: { itemId }, - thruAddon: this, - }); - return await newInvocation.save(); + + async getItemInfo(this: AuthorizedAccountModel, _itemId: string) : Promise { + // To be implemented in child classes + return; } } diff --git a/app/models/configured-citation-addon.ts b/app/models/configured-citation-addon.ts index 388b18ff9b..d6165905a8 100644 --- a/app/models/configured-citation-addon.ts +++ b/app/models/configured-citation-addon.ts @@ -1,6 +1,9 @@ import { AsyncBelongsTo, belongsTo } from '@ember-data/model'; import ResourceReferenceModel from 'ember-osf-web/models/resource-reference'; +import { task } from 'ember-concurrency'; +import { waitFor } from '@ember/test-waiters'; +import { ConnectedCitationOperationNames, OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; import AuthorizedCitationAccountModel from './authorized-citation-account'; import ExternalCitationServiceModel from './external-citation-service'; import ConfiguredAddonModel from './configured-addon'; @@ -18,6 +21,31 @@ export default class ConfiguredCitationAddonModel extends ConfiguredAddonModel { get externalServiceId() { return (this as ConfiguredCitationAddonModel).belongsTo('externalCitationService').id(); } + + @task + @waitFor + async getFolderItems(this: ConfiguredAddonModel, kwargs?: OperationKwargs) { + const operationKwargs = kwargs || {}; + const operationName = operationKwargs.itemId ? ConnectedCitationOperationNames.ListCollectionItems : + ConnectedCitationOperationNames.ListRootCollections; + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName, + operationKwargs, + thruAddon: this, + }); + return await newInvocation.save(); + } + + @task + @waitFor + async getItemInfo(this: ConfiguredAddonModel, itemId: string) { + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName: ConnectedCitationOperationNames.GetItemInfo, + operationKwargs: { itemId }, + thruAddon: this, + }); + return await newInvocation.save(); + } } declare module 'ember-data/types/registries/model' { diff --git a/app/models/configured-storage-addon.ts b/app/models/configured-storage-addon.ts index ed78d8ca16..31defc9bbd 100644 --- a/app/models/configured-storage-addon.ts +++ b/app/models/configured-storage-addon.ts @@ -1,4 +1,7 @@ import { AsyncBelongsTo, attr, belongsTo } from '@ember-data/model'; +import { waitFor } from '@ember/test-waiters'; +import { task } from 'ember-concurrency'; +import { ConnectedStorageOperationNames, OperationKwargs } from 'ember-osf-web/models/addon-operation-invocation'; import ResourceReferenceModel from 'ember-osf-web/models/resource-reference'; import AuthorizedStorageAccountModel from './authorized-storage-account'; @@ -21,6 +24,31 @@ export default class ConfiguredStorageAddonModel extends ConfiguredAddonModel { get externalServiceId() { return (this as ConfiguredStorageAddonModel).belongsTo('externalStorageService').id(); } + + @task + @waitFor + async getFolderItems(this: ConfiguredAddonModel, kwargs?: OperationKwargs) { + const operationKwargs = kwargs || {}; + const operationName = operationKwargs.itemId ? ConnectedStorageOperationNames.ListChildItems : + ConnectedStorageOperationNames.ListRootItems; + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName, + operationKwargs, + thruAddon: this, + }); + return await newInvocation.save(); + } + + @task + @waitFor + async getItemInfo(this: ConfiguredAddonModel, itemId: string) { + const newInvocation = this.store.createRecord('addon-operation-invocation', { + operationName: ConnectedStorageOperationNames.GetItemInfo, + operationKwargs: { itemId }, + thruAddon: this, + }); + return await newInvocation.save(); + } } declare module 'ember-data/types/registries/model' { From 864bb841390ee600fa098b5c74680420a092d8b4 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 19 Dec 2024 10:16:01 -0500 Subject: [PATCH 2/3] fix --- app/models/configured-citation-addon.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/configured-citation-addon.ts b/app/models/configured-citation-addon.ts index d6165905a8..1a66779951 100644 --- a/app/models/configured-citation-addon.ts +++ b/app/models/configured-citation-addon.ts @@ -28,10 +28,14 @@ export default class ConfiguredCitationAddonModel extends ConfiguredAddonModel { const operationKwargs = kwargs || {}; const operationName = operationKwargs.itemId ? ConnectedCitationOperationNames.ListCollectionItems : ConnectedCitationOperationNames.ListRootCollections; + // rename 'itemId' key to 'collectionId' + delete Object.assign(operationKwargs, { ['collectionId']: operationKwargs['itemId'] })['itemId']; + // gravyvalet doesn't like 'itemType' as a parameter + delete operationKwargs.itemType; const newInvocation = this.store.createRecord('addon-operation-invocation', { operationName, operationKwargs, - thruAddon: this, + thruAccount: this, }); return await newInvocation.save(); } From 82cbd83d36dad001f5b60d7a7e473fdf88922447 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 19 Dec 2024 10:26:17 -0500 Subject: [PATCH 3/3] fix again --- app/models/configured-citation-addon.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/configured-citation-addon.ts b/app/models/configured-citation-addon.ts index 1a66779951..0a33d424ac 100644 --- a/app/models/configured-citation-addon.ts +++ b/app/models/configured-citation-addon.ts @@ -35,7 +35,7 @@ export default class ConfiguredCitationAddonModel extends ConfiguredAddonModel { const newInvocation = this.store.createRecord('addon-operation-invocation', { operationName, operationKwargs, - thruAccount: this, + thruAddon: this, }); return await newInvocation.save(); }