Skip to content

Commit

Permalink
implement getFolderItems and getItemInfo in configurated-citiation/st…
Browse files Browse the repository at this point in the history
…orage-addon child classes
  • Loading branch information
adlius committed Dec 19, 2024
1 parent 43f6d94 commit 4ca1d58
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/models/addon-operation-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 8 additions & 24 deletions app/models/configured-addon.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,28 +25,14 @@ export default class ConfiguredAddonModel extends Model {
@belongsTo('user-reference', { inverse: null })
accountOwner!: AsyncBelongsTo<UserReferenceModel> & 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<any> {
// 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<any> {
// To be implemented in child classes
return;
}
}
28 changes: 28 additions & 0 deletions app/models/configured-citation-addon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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' {
Expand Down
28 changes: 28 additions & 0 deletions app/models/configured-storage-addon.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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' {
Expand Down

0 comments on commit 4ca1d58

Please sign in to comment.