Skip to content

Commit

Permalink
Merge pull request #1454 from Lumieducation/master
Browse files Browse the repository at this point in the history
Release next version
  • Loading branch information
JPSchellenberg authored Apr 17, 2021
2 parents 882f4d5 + c146247 commit ec092a7
Show file tree
Hide file tree
Showing 106 changed files with 15,438 additions and 4,698 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 4

[package.json]
# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ microsoft.gpg
# Dependency directory
node_modules
/h5p

h5p_libs
google_translate.json
.json-autotranslate-cache
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
563 changes: 273 additions & 290 deletions client/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
"@sentry/react": "6.2.5",
"@testing-library/jest-dom": "5.11.10",
"@testing-library/react": "11.2.6",
"@testing-library/user-event": "13.1.1",
"@testing-library/user-event": "13.1.3",
"@types/jest": "26.0.22",
"@types/node": "14.14.37",
"@types/node": "14.14.41",
"@types/react": "17.0.3",
"@types/react-dom": "17.0.3",
"classnames": "2.3.0",
"i18next": "20.1.0",
"classnames": "2.3.1",
"i18next": "20.2.1",
"i18next-http-backend": "1.2.1",
"lodash": "4.17.21",
"notistack": "1.0.5",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-i18next": "11.8.12",
"react-i18next": "11.8.13",
"react-redux": "7.2.3",
"react-redux-i18n": "1.9.3",
"react-router-dom": "5.2.0",
Expand All @@ -34,7 +34,7 @@
"shortid": "2.2.16",
"socket.io-client": "4.0.1",
"superagent": "6.1.0",
"typescript": "4.2.3",
"typescript": "4.2.4",
"web-vitals": "1.1.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion client/src/boot/Sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import store from '../state';
import { track } from '../state/track/actions';

Sentry.init({
dsn: 'http://[email protected]/3',
dsn: 'https://[email protected]/3',
release: process.env.VERSION,
environment: process.env.NODE_ENV,
beforeSend: (event: Sentry.Event, hint: Sentry.EventHint) => {
Expand Down
113 changes: 113 additions & 0 deletions client/src/services/LibraryAdministrationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import type {
IInstalledLibrary,
ILibraryAdministrationOverviewItem
} from '@lumieducation/h5p-server';

/**
* The data model used to display the library list.
*/
export interface ILibraryViewModel extends ILibraryAdministrationOverviewItem {
details?: IInstalledLibrary & {
dependentsCount: number;
instancesAsDependencyCount: number;
instancesCount: number;
isAddon: boolean;
};
isDeleting?: boolean;
isShowingDetails?: boolean;
}

/**
*
*/
export class LibraryAdministrationService {
constructor(private baseUrl: string) {}

public async deleteLibrary(library: ILibraryViewModel): Promise<void> {
const response = await fetch(
`${this.baseUrl}/${library.machineName}-${library.majorVersion}.${library.minorVersion}`,
{
method: 'DELETE'
}
);

if (response.ok) {
return;
}
throw new Error(
`Could not delete library: ${response.status} - ${response.text}`
);
}

public async getLibraries(): Promise<ILibraryViewModel[]> {
const response = await fetch(this.baseUrl);
if (response.ok) {
return response.json();
}
throw new Error(
`Could not get library list: ${response.status} - ${response.statusText}`
);
}

public async getLibrary(
library: ILibraryViewModel
): Promise<
IInstalledLibrary & {
dependentsCount: number;
instancesAsDependencyCount: number;
instancesCount: number;
isAddon: boolean;
}
> {
const response = await fetch(
`${this.baseUrl}/${library.machineName}-${library.majorVersion}.${library.minorVersion}`
);
if (response.ok) {
return response.json();
}
throw new Error(
`Could not get library details: ${response.status} - ${response.statusText}`
);
}

public async patchLibrary(
library: ILibraryViewModel,
changes: Partial<ILibraryViewModel>
): Promise<ILibraryViewModel> {
const response = await fetch(
`${this.baseUrl}/${library.machineName}-${library.majorVersion}.${library.minorVersion}`,
{
method: 'PATCH',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
body: JSON.stringify(changes)
}
);
if (response.ok) {
return { ...library, ...changes };
}
throw new Error(
`Could not patch library: ${response.status} - ${response.statusText}`
);
}

public async postPackage(
file: File
): Promise<{ installed: number; updated: number }> {
const formData = new FormData();
formData.append('file', file);

const response = await fetch(this.baseUrl, {
method: 'POST',
body: formData
});
if (response.ok) {
const result = await response.json();
return { installed: result.installed, updated: result.updated };
}
throw new Error(
`Could not upload package with libraries: ${response.status} - ${response.statusText}`
);
}
}
8 changes: 4 additions & 4 deletions client/src/state/Analytics/AnalyticsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import superagent from 'superagent';

import { IFile } from './AnalyticsTypes';

export async function importAnalytics(): Promise<{
users: any[];
interactions: any[];
files: IFile[];
}> {
const response = await superagent.get('/api/v1/analytics');

return {
users: response.body.users,
interactions: response.body.interactions
files: response.body
};
}
28 changes: 8 additions & 20 deletions client/src/state/Analytics/AnalyticsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,23 @@ export function importAnalytics(): any {

dispatch(track('Analytics', 'import'));
try {
const { users, interactions } = await API.importAnalytics();
const { files } = await API.importAnalytics();
dispatch(
track(
'Analytics',
'import',
`content-types`,
interactions.length
)
track('Analytics', 'import', `content-types`, files.length)
);

dispatch({
payload: { users, interactions },
payload: { files },
type: ANALYTICS_IMPORT_SUCCESS
});
} catch (error) {
Sentry.captureException(error);
try {
dispatch({
payload: { message: error.response.body.message },
type: ANALYTICS_IMPORT_ERROR
});
} catch (error) {
Sentry.captureException(error);

dispatch({
payload: { message: 'no valid data' },
type: ANALYTICS_IMPORT_ERROR
});
}
console.log(error);
dispatch({
payload: { message: JSON.stringify(error) },
type: ANALYTICS_IMPORT_ERROR
});
}
};
}
7 changes: 3 additions & 4 deletions client/src/state/Analytics/AnalyticsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
} from './AnalyticsTypes';

export const initialState: IAnalyticsState = {
users: [],
interactions: []
files: []
};

const log = new Logger('reducer:analytics');
Expand All @@ -23,8 +22,8 @@ export default function analyticsReducer(
switch (action.type) {
case ANALYTICS_IMPORT_SUCCESS:
return {
users: action.payload.users,
interactions: action.payload.interactions
...state,
files: action.payload.files
};

default:
Expand Down
14 changes: 8 additions & 6 deletions client/src/state/Analytics/AnalyticsTypes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { IInteraction } from '@lumieducation/xapi-aggregator';

interface IUser {
id: string;
export interface IFile {
file: string;
name: string;
contentHash: string;
interactions: IInteraction[];
results: number[];
error?: boolean;
code?: string;
}
// state

export interface IAnalyticsState {
users: IUser[];
interactions: IInteraction[];
files: IFile[];
}

export interface IState {
Expand All @@ -27,8 +30,7 @@ export interface IAnalyticsImportRequestAction {

export interface IAnalyticsImportSuccessAction {
payload: {
users: IUser[];
interactions: IInteraction[];
files: IFile[];
};
type: typeof ANALYTICS_IMPORT_SUCCESS;
}
Expand Down
25 changes: 22 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 Expand Up @@ -70,3 +74,18 @@ export function updateH5P(
export function openFiles(): Promise<superagent.Response> {
return superagent.get('/api/v1/lumi/open_files');
}

/**
* Gets the core H5P overview for a single library from the H5P API endpoint.
* @param ubernameWithWhitespace The ubername with whitespace as separator (e.g.
* H5P.Example 1.0")
* @returns a superagent response with the answer in the body. (answer = array
* of structures)
*/
export function getLibraryOverview(
ubernameWithWhitespace: string
): Promise<superagent.Response> {
return superagent
.post('/api/v1/h5p/ajax?action=libraries')
.send({ libraries: [ubernameWithWhitespace] });
}
Loading

0 comments on commit ec092a7

Please sign in to comment.