-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fee686
commit ae0c0d1
Showing
16 changed files
with
485 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import annotations | ||
|
||
from fastapi import APIRouter | ||
|
||
from ocrdmonitor.protocols import Environment | ||
|
||
from .routers import workspaces | ||
from .routers import jobs | ||
|
||
def create_api( | ||
environment: Environment | ||
) -> APIRouter: | ||
router = APIRouter(prefix="/api") | ||
|
||
router.include_router(workspaces.router(browser_settings=environment.settings.ocrd_browser)) | ||
router.include_router(jobs.router(environment)) | ||
return router |
File renamed without changes.
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,45 @@ | ||
from fastapi import APIRouter, Response, Depends | ||
|
||
from ocrdmonitor.protocols import Environment, OcrdJob, Repositories | ||
|
||
from typing import List | ||
|
||
from ocrdmonitor.ocrdcontroller import OcrdController | ||
|
||
class ResultList: | ||
def __init__(self, results: List[OcrdJob]): | ||
self.results = results | ||
|
||
|
||
def router(environment: Environment) -> None: | ||
router = APIRouter(prefix="/jobs") | ||
|
||
@router.get("/", name="api.jobs") | ||
async def jobs( | ||
repositories: Repositories = Depends(environment.repositories), | ||
) -> Response: | ||
job_repository = repositories.ocrd_jobs | ||
jobs = await job_repository.find_all() | ||
|
||
return ResultList(jobs) | ||
|
||
@router.get("/{job_id}", name="api.job") | ||
async def job( | ||
repositories: Repositories = Depends(environment.repositories), | ||
) -> Response: | ||
job_repository = repositories.ocrd_jobs | ||
jobs = await job_repository.find_all() | ||
|
||
return ResultList(jobs) | ||
|
||
@router.get("/{job_id}/processstatus", name="api.job.processstatus") | ||
async def job_processstatus( | ||
job_id: str, repositories: Repositories = Depends(environment.repositories) | ||
) -> Response: | ||
controller = OcrdController(environment.controller_server()) | ||
|
||
job_repository = repositories.ocrd_jobs | ||
job = await job_repository.get(job_id) | ||
return await controller.status_for(job) | ||
|
||
return router |
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,30 @@ | ||
from pathlib import Path | ||
|
||
from fastapi import APIRouter, Response | ||
from ocrdbrowser import workspace | ||
from ocrdmonitor.server.settings import OcrdBrowserSettings | ||
|
||
from typing import List | ||
|
||
class ResultList(): | ||
def __init__(self, results: List[Path]): | ||
self.results = results | ||
|
||
def router( | ||
browser_settings: OcrdBrowserSettings | ||
) -> None: | ||
router = APIRouter(prefix="/workspaces") | ||
|
||
@router.get("/", name="api.list.workspaces") | ||
def list_workspaces(search: str | None = None) -> Response: | ||
spaces = [ | ||
Path(space).relative_to(browser_settings.workspace_dir) | ||
for space in workspace.list_all(browser_settings.workspace_dir) | ||
] | ||
|
||
if search: | ||
spaces = list(filter(lambda workspace: search in str(workspace), spaces)) | ||
|
||
return ResultList(spaces) | ||
|
||
return router |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#loader { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
opacity: 0; | ||
z-index: -1; | ||
transition: opacity .3s; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#loader.is-active { | ||
opacity: 1; | ||
z-index: 1; | ||
} | ||
|
||
#loader .is-loading { | ||
position: relative; | ||
} | ||
|
||
#loader .loader { | ||
height: 40px; | ||
width: 40px; | ||
} | ||
|
||
.ocrd-status { | ||
width: 40px; | ||
border: 0px; | ||
} |
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,73 @@ | ||
class ResultsView { | ||
constructor( container, renderResultCallback, afterRenderCallback = false ) { | ||
this.container = container; | ||
this.renderResultCallback = renderResultCallback; | ||
this.loader = this.initLoader() | ||
this.afterRenderCallback = afterRenderCallback | ||
} | ||
|
||
async render(url) { | ||
this.showLoader(); | ||
// Storing response | ||
const response = await fetch(url); | ||
|
||
// Storing data in form of JSON | ||
let data = await response.json(); | ||
console.log(data); | ||
|
||
this.show(data); | ||
|
||
if( this.afterRenderCallback ) { | ||
this.afterRenderCallback() | ||
} | ||
|
||
this.hideLoader(); | ||
} | ||
|
||
show(data) { | ||
let content = "" | ||
|
||
if(!data.results || data.results.length == 0) { | ||
content = "No results were found" | ||
} else { | ||
for (let result of data.results) { | ||
content += this.renderResultCallback(result) | ||
} | ||
} | ||
|
||
this.container.innerHTML = content; | ||
} | ||
|
||
hideLoader() { | ||
this.loader.classList.remove("is-active"); | ||
} | ||
|
||
showLoader() { | ||
this.loader.classList.add("is-active"); | ||
} | ||
|
||
initLoader() { | ||
let loader = document.createElement('div'); | ||
loader.id = 'loader'; | ||
loader.innerHTML = '<div class="loader is-loading"></div>' | ||
let loaderContainer = this.container | ||
if(loaderContainer.tagName == 'TBODY') { | ||
loaderContainer = loaderContainer.parentNode | ||
} | ||
|
||
loaderContainer.parentNode.insertBefore( loader, loaderContainer); | ||
return document.getElementById('loader'); | ||
} | ||
|
||
} | ||
|
||
|
||
function diff(time_created, time_terminated) { | ||
let from = moment.utc(time_created) | ||
let to = moment.utc() | ||
if( time_terminated ) { | ||
to = moment.utc(time_terminated) | ||
} | ||
|
||
return moment.utc(to.diff(from)).format('HH:mm:ss') | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,10 @@ | |
{% block meta %}{% endblock %} | ||
<title>{% block title %}{% endblock %} - OCR-D Monitor</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"> | ||
<link rel="stylesheet" href="{{ url_for('static', path='style.css') }}"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | ||
<link rel="stylesheet" href="{{ url_for('static', path='main.css') }}"> | ||
<script src="https://momentjs.com/downloads/moment.js"></script> | ||
<script language="javascript" type="text/javascript" src="{{ url_for('static', path='main.js') }}"></script> | ||
</head> | ||
<body> | ||
<nav class="navbar" role="navigation" aria-label="main navigation"> | ||
|
@@ -49,14 +52,14 @@ | |
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
<section class="section"> | ||
<div id="main-content" class="container"> | ||
<h1 class="title"> | ||
{% block headline %}{% endblock %} | ||
</h1> | ||
{% block content %}{% endblock %} | ||
</div> | ||
</section> | ||
</nav> | ||
<section id="main-content" class="section"> | ||
<div class="container"> | ||
<h1 class="title"> | ||
{% block headline %}{% endblock %} | ||
</h1> | ||
{% block content %}{% endblock %} | ||
</div> | ||
</section> | ||
</body> | ||
</html> |
Oops, something went wrong.