-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for showing the progress of content entry import jobs tha…
…t are running on the server.
- Loading branch information
1 parent
1822632
commit 186493b
Showing
13 changed files
with
194 additions
and
50 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
33 changes: 33 additions & 0 deletions
33
.../com/ustadmobile/lib/rest/domain/contententry/importcontent/ImportContentEntryJobRoute.kt
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,33 @@ | ||
package com.ustadmobile.lib.rest.domain.contententry.importcontent | ||
|
||
import com.ustadmobile.core.db.UmAppDatabase | ||
import com.ustadmobile.lib.db.composites.ContentEntryImportJobProgress | ||
import io.ktor.http.ContentType | ||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respondText | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import kotlinx.serialization.builtins.ListSerializer | ||
import kotlinx.serialization.json.Json | ||
|
||
fun Route.ImportContentEntryJobStatus( | ||
json: Json, | ||
dbFn: (ApplicationCall) -> UmAppDatabase, | ||
) { | ||
get("importjobs") { | ||
val contentEntryUid = call.request.queryParameters["contententryuid"]?.toLong() ?: 0 | ||
val db = dbFn(call) | ||
val inProgressJobs = db.contentEntryImportJobDao.findInProgressJobsByContentEntryUidAsync( | ||
contentEntryUid | ||
) | ||
|
||
call.respondText( | ||
contentType = ContentType.Application.Json, | ||
text = json.encodeToString( | ||
ListSerializer(ContentEntryImportJobProgress.serializer()), | ||
inProgressJobs | ||
), | ||
) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app-react/src/jsMain/kotlin/com/ustadmobile/mui/components/UstadLinearProgressListItem.kt
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,62 @@ | ||
package com.ustadmobile.mui.components | ||
|
||
import com.ustadmobile.core.hooks.useStringProvider | ||
import mui.material.ListItem | ||
import mui.material.ListItemText | ||
import react.FC | ||
import react.Props | ||
import react.ReactNode | ||
import com.ustadmobile.core.MR | ||
import js.objects.jso | ||
import mui.material.LinearProgress | ||
import mui.material.LinearProgressVariant | ||
import react.create | ||
import react.dom.html.ReactHTML.div | ||
|
||
|
||
external interface UstadLinearProgressListItemProps: Props { | ||
var progress: Float? | ||
var secondaryContent: ReactNode | ||
var onCancel: () -> Unit | ||
var error: String? | ||
var onDismissError: () -> Unit | ||
} | ||
|
||
val UstadLinearProgressListItem = FC<UstadLinearProgressListItemProps> {props -> | ||
val strings = useStringProvider() | ||
val errorVal = props.error | ||
val progressVal = props.progress | ||
|
||
ListItem { | ||
if(errorVal != null) { | ||
ListItemText { | ||
primary = ReactNode(strings[MR.strings.import_error]) | ||
secondary = ReactNode(errorVal) | ||
} | ||
}else { | ||
ListItemText { | ||
primary = LinearProgress.create { | ||
if(progressVal != null) { | ||
variant = LinearProgressVariant.determinate | ||
this.value = progressVal * 100 | ||
}else { | ||
variant = LinearProgressVariant.indeterminate | ||
} | ||
} | ||
secondary = props.secondaryContent | ||
|
||
primaryTypographyProps = jso { | ||
component = div | ||
} | ||
secondaryTypographyProps = jso { | ||
component = div | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
|
||
|
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
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
2 changes: 1 addition & 1 deletion
2
...ewtab/ContentEntryImportJobProgressExt.kt → ...ewtab/ContentEntryImportJobProgressExt.kt
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
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
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
19 changes: 19 additions & 0 deletions
19
...abase/src/commonMain/kotlin/com/ustadmobile/core/db/dao/ContentEntryImportJobDaoCommon.kt
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,19 @@ | ||
package com.ustadmobile.core.db.dao | ||
|
||
import com.ustadmobile.core.db.JobStatus | ||
|
||
object ContentEntryImportJobDaoCommon { | ||
|
||
const val FIND_IN_PROGRESS_JOBS_BY_CONTENT_ENTRY_UID = """ | ||
SELECT ContentEntryImportJob.cjiUid, | ||
ContentEntryImportJob.cjiItemProgress, | ||
ContentEntryImportJob.cjiItemTotal, | ||
ContentEntryImportJob.cjiStatus, | ||
ContentEntryImportJob.cjiError | ||
FROM ContentEntryImportJob | ||
WHERE ContentEntryImportJob.cjiContentEntryUid = :contentEntryUid | ||
AND ( ContentEntryImportJob.cjiStatus BETWEEN ${JobStatus.QUEUED} AND ${JobStatus.RUNNING_MAX} | ||
OR (ContentEntryImportJob.cjiStatus = ${JobStatus.FAILED} AND NOT ContentEntryImportJob.cjiErrorDismissed)) | ||
""" | ||
|
||
} |
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.