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

feat(library-management): add h5p-library-management to settings #1416

Merged
merged 30 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
330dfd7
fix(settings): overhaul settings layout
JPSchellenberg Apr 4, 2021
ff6e006
test(lint): make ESLint happy
JPSchellenberg Apr 4, 2021
f8638e6
fix(settings): add locales for settings
JPSchellenberg Apr 5, 2021
091cede
fix(settings): remove deprecated components&hide unimplemented features
JPSchellenberg Apr 5, 2021
6a33b54
test(lint): make eslint happy
JPSchellenberg Apr 5, 2021
c167231
feat(library-management): add first experimental draft
JPSchellenberg Apr 5, 2021
ba898e7
Merge branch 'master' into fix/settings
JPSchellenberg Apr 6, 2021
035de07
fix(settings): scrollable main-area
JPSchellenberg Apr 6, 2021
db364e9
fix(settings): highlight the current selected listitem
JPSchellenberg Apr 6, 2021
b82401d
fix(settings): rework general listitem
JPSchellenberg Apr 6, 2021
82f7943
Merge branch 'fix/settings' into feat/library-management
JPSchellenberg Apr 6, 2021
48f9df4
feat(library-management): add library details
JPSchellenberg Apr 8, 2021
eaec904
Merge branch 'master' into feat/library-management
JPSchellenberg Apr 10, 2021
92622f3
Merge branch 'master' into feat/library-management
JPSchellenberg Apr 10, 2021
64e1965
fix(library-management): display errors
JPSchellenberg Apr 10, 2021
d77fe80
Merge remote-tracking branch 'origin/master' into feat/library-manage…
sr258 Apr 11, 2021
6208d03
refactor(style): prettier style
sr258 Apr 11, 2021
43e1c6b
Merge branch 'master' into feat/library-management
JPSchellenberg Apr 11, 2021
ded82d1
fix(settings): main content overlaps with list
JPSchellenberg Apr 11, 2021
b6f7dc6
fix(settings): color of upload-button to primary-color
JPSchellenberg Apr 11, 2021
3b42550
fix(settings): remove deleted libraries from list
JPSchellenberg Apr 11, 2021
8eeae23
fix(settings): display tooltip why library can not be deleted
JPSchellenberg Apr 11, 2021
f0c57f2
test(lint): make ESLint happy
JPSchellenberg Apr 14, 2021
bda0b34
fix(settings): plural locale
sr258 Apr 15, 2021
eb24e22
fix(library-settings): make header position relative
JPSchellenberg Apr 15, 2021
2bd95a2
fix(library-management): increase margin between delete&details button
JPSchellenberg Apr 15, 2021
1419f0d
Merge remote-tracking branch 'origin/feat/library-management' into fe…
JPSchellenberg Apr 15, 2021
6f63d01
Merge branch 'master' into feat/library-management
JPSchellenberg Apr 15, 2021
cd37855
fix(settings): hide account-option for now
JPSchellenberg Apr 15, 2021
b385bb2
fix(settings): make linter happy
JPSchellenberg Apr 15, 2021
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
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}`
);
}
}
41 changes: 22 additions & 19 deletions client/src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import ListItemText from '@material-ui/core/ListItemText';

import CloseIcon from '@material-ui/icons/Close';
import SettingsIcon from '@material-ui/icons/Settings';
import LibraryBooksIcon from '@material-ui/icons/LibraryBooks';
// import LibraryBooksIcon from '@material-ui/icons/LibraryBooks';
import AccountBoxIcon from '@material-ui/icons/AccountBox';
// import AccountBoxIcon from '@material-ui/icons/AccountBox';
import UpdateIcon from '@material-ui/icons/Update';

import SettingsList from './components/Settings/GeneralSettingsList';
Expand All @@ -49,7 +50,7 @@ const useStyles = makeStyles((theme: Theme) =>
},
root: {
display: 'flex',
marginLeft: '100px'
paddingLeft: drawerWidth
},
heading: {
fontSize: theme.typography.pxToRem(15),
Expand All @@ -72,6 +73,7 @@ const useStyles = makeStyles((theme: Theme) =>
},
drawer: {
width: drawerWidth,
marginRight: '20px',
flexShrink: 0
},
drawerPaper: {
Expand Down Expand Up @@ -138,7 +140,8 @@ export default function FullScreenDialog() {
</AppBar>
<Drawer
className={classes.drawer}
variant="permanent"
variant="persistent"
open={true}
classes={{
paper: classes.drawerPaper
}}
Expand Down Expand Up @@ -176,27 +179,27 @@ export default function FullScreenDialog() {
primary={t('settings.menu.updates')}
/>
</ListItem>
{/* <ListItem
<ListItem
button
key="h5p-libraries"
onClick={() => setSection('h5p-libraries')}
style={{
backgroundColor:
section === 'general'
? '#EFEFEF'
: '#FFFFFF',
color: '#3498db'
}}
key="h5p-library-administration"
onClick={() =>
setSection('h5p-library-administration')
}
className={classnames({
[classes.selected]:
section === 'h5p-library-administration'
})}
>
<ListItemIcon>
<LibraryBooksIcon />
</ListItemIcon>
<ListItemText
primary={t('settings.menu.h5p-libraries')}
primary={t(
'settings.menu.h5p-library-administration'
)}
/>
</ListItem>
*/}
<ListItem
{/* <ListItem
button
key="account"
onClick={() => setSection('account')}
Expand All @@ -210,7 +213,7 @@ export default function FullScreenDialog() {
<ListItemText
primary={t('settings.menu.account')}
/>
</ListItem>
</ListItem> */}
</List>
</Drawer>
<DialogContent className={classes.bg}>
Expand All @@ -226,9 +229,9 @@ export default function FullScreenDialog() {
case 'updates':
return <UpdateSettings />;

case 'h5p-libraries':
case 'h5p-library-administration':
return (
<SettingsLibraryManagement />
<SettingsLibraryManagement endpointUrl="/api/v1/h5p/libraries" />
);

case 'account':
Expand Down
Loading