Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement getFolderItems and getItemInfo in configurated-citiation/storage-addon child classes #2434

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
32 changes: 32 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,35 @@ 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;
// 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,
});
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
Loading