-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(library-management): add h5p-library-management to settings (#1416)
* fix(settings): overhaul settings layout * test(lint): make ESLint happy * fix(settings): add locales for settings * fix(settings): remove deprecated components&hide unimplemented features * test(lint): make eslint happy * feat(library-management): add first experimental draft * fix(settings): scrollable main-area * fix(settings): highlight the current selected listitem * fix(settings): rework general listitem * feat(library-management): add library details * fix(library-management): display errors * refactor(style): prettier style * fix(settings): main content overlaps with list * fix(settings): color of upload-button to primary-color * fix(settings): remove deleted libraries from list * fix(settings): display tooltip why library can not be deleted * test(lint): make ESLint happy * fix(settings): plural locale * fix(library-settings): make header position relative * fix(library-management): increase margin between delete&details button * fix(settings): hide account-option for now * fix(settings): make linter happy Co-authored-by: Sebastian Rettig <serettig@posteo.de>
- Loading branch information
1 parent
0228646
commit 1e83648
Showing
5 changed files
with
842 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.