Skip to content

Commit

Permalink
feat(exports): added more export options
Browse files Browse the repository at this point in the history
  • Loading branch information
sr258 authored Apr 6, 2021
2 parents e249791 + f2b6bf7 commit 1d9c95b
Show file tree
Hide file tree
Showing 43 changed files with 2,976 additions and 595 deletions.
1 change: 1 addition & 0 deletions builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'build/**/*',
'node_modules/**/*',
'reporter-client/build/static/js/**/*',
'scorm-client/**/*',
'package.json',
'h5p/**/*',
'electron/**/*',
Expand Down
33 changes: 31 additions & 2 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions client/src/state/H5PEditor/H5PApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ export function loadPlayerContent(
return superagent.get(`/api/v1/h5p/${contentId}/play`);
}

export function exportAsHtml(
export function exportContent(
contentId: string,
includeReporter: boolean
includeReporter: boolean,
format: 'bundle' | 'external' | 'scorm',
options: { masteryScore?: string }
): Promise<superagent.Response> {
return superagent.get(
`/api/v1/h5p/${contentId}/html?includeReporter=${includeReporter}`
`/api/v1/h5p/${contentId}/export?includeReporter=${includeReporter}&format=${format}${
options.masteryScore ? `&masteryScore=${options.masteryScore}` : ''
}`
);
}

Expand Down
47 changes: 32 additions & 15 deletions client/src/state/H5PEditor/H5PEditorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,53 +116,70 @@ export function blurActiveElement(): IBlurActiveElementAction {
};
}

export function exportH5P(includeReporter: boolean): any {
export function cancelExportH5P(contentId?: string) {
log.info(`canceling export`);
return async (dispatch: any) => {
dispatch({
payload: { contentId },
type: H5PEDITOR_EXPORT_CANCEL
});
};
}

export function exportH5P(
includeReporter: boolean,
format: 'bundle' | 'external' | 'scorm',
options: { masteryScore?: string }
): any {
return async (dispatch: any) => {
try {
await dispatch(updateContentOnServer());

const data = await window.h5peditor.current?.save(); // this dispatches updateContent()
dispatch({
payload: { contentId: data.contentId, includeReporter },
payload: { contentId: data.contentId, includeReporter, format },
type: H5PEDITOR_EXPORT_REQUEST
});

try {
await api.exportAsHtml(data.contentId, includeReporter);
await api.exportContent(
data.contentId,
includeReporter,
format,
options
);

// TOOD: chang tracking
dispatch(
track(
'H5P',
'export_as_single_html',
`${
'export',
`${format}-${
includeReporter
? 'with_reporter'
: 'without_reporter'
}`
)
);
dispatch({
payload: { contentId: data.contentId, includeReporter },
payload: {
contentId: data.contentId,
includeReporter,
format
},
type: H5PEDITOR_EXPORT_SUCCESS
});
} catch (error) {
if (error.status === 499) {
// dispatched if the user cancel the system's save dialog.
dispatch({
payload: {
contentId: data.contentId,
includeReporter
},
type: H5PEDITOR_EXPORT_CANCEL
});
dispatch(cancelExportH5P(data.contentId));
} else {
Sentry.captureException(error);

dispatch({
payload: {
error,
contentId: data.contentId,
includeReporter
contentId: data.contentId
},
type: H5PEDITOR_EXPORT_ERROR
});
Expand Down
3 changes: 2 additions & 1 deletion client/src/state/H5PEditor/H5PEditorReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export default function tabReducer(
}
: tab
),
lockDisplay: false
lockDisplay: false,
showExportDialog: false
};

case H5PEDITOR_EXPORT_ERROR:
Expand Down
2 changes: 2 additions & 0 deletions client/src/state/H5PEditor/H5PEditorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export interface IH5PEditorOpenExportDialogAction {
export interface IH5PEditorExportRequestAction {
payload: {
contentId: string;
includeReporter: boolean;
format: 'bundle' | 'external' | 'scorm';
};
type: typeof H5PEDITOR_EXPORT_REQUEST;
}
Expand Down
Loading

0 comments on commit 1d9c95b

Please sign in to comment.