Skip to content

Commit

Permalink
UI: Added Create and Edit View
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed May 29, 2024
1 parent f3cf1fb commit d126509
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 15 deletions.
71 changes: 62 additions & 9 deletions invenio_jobs/administration/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""Invenio administration view module."""

from invenio_administration.views.base import AdminResourceListView
from invenio_administration.views.base import AdminResourceListView, AdminResourceEditView, AdminResourceDetailView, AdminResourceCreateView
from invenio_i18n import lazy_gettext as _


Expand All @@ -25,26 +25,26 @@ class JobsListView(AdminResourceListView):
pid_path = "id"
icon = "settings"
template = "invenio_jobs/system/jobs/jobs-search.html"
create_view_name = "jobs-create"

display_search = False
display_delete = False
display_create = False
display_edit = False
display_create = True
display_edit = True

item_field_list = {
"job": {"text": _("Jobs"), "order": 1, "width": 3},
"last_run_start_time": {"text": _("Last run"), "order": 2, "width": 3},
"user": {"text": _("Started by"), "order": 3, "width": 3},
"next_run": {"text": _("Next run"), "order": 4, "width": 3},
"action": {"text": _("Action"), "order": 5, "width": 2},
}

search_config_name = "JOBS_SEARCH"
search_sort_config_name = "JOBS_SORT_OPTIONS"
search_facets_config_name = "JOBS_FACETS"


class JobsDetailsView(AdminResourceListView):
class JobsDetailsView(AdminResourceDetailView):
"""Configuration for Jobs detail view which shows runs."""

def get_api_endpoint(self, pid_value=None):
Expand All @@ -59,10 +59,10 @@ def get_api_endpoint(self, pid_value=None):
disabled = lambda _: True

template = "invenio_jobs/system/jobs/jobs-details.html"
display_delete = False
display_edit = False
display_delete = True
display_search = False
display_create = False
display_edit = True
display_create = True

list_view_name = "jobs"
pid_path = "id"
Expand All @@ -73,9 +73,62 @@ def get_api_endpoint(self, pid_value=None):
"duration": {"text": _("Duration"), "order": 2, "width": 2},
"message": {"text": _("Message"), "order": 3, "width": 10},
"user": {"text": _("Started by"), "order": 4, "width": 2},
"action": {"text": _("Action"), "order": 5, "width": 2},
}

search_config_name = "JOBS_SEARCH"
search_sort_config_name = "JOBS_SORT_OPTIONS"
search_facets_config_name = "JOBS_FACETS"

class JobsEditView(AdminResourceEditView):
"""Configuration for job edit view."""

name = "job-edit"
url = "/jobs/<pid_value>/edit"
resource_config = "jobs_resource"
title = "Job Edit"
pid_path = "id"
api_endpoint = "/jobs"
list_view_name = "jobs"

form_fields = {
"title": {
"order": 1,
"text": _("Title"),
"description": _("A title of the job."),
},
"description": {
"order": 2,
"text": _("Description"),
"description": _("A short description about the job."),
},
"created": {"order": 5},
"updated": {"order": 6},
}


class JobsCreateView(AdminResourceCreateView):
"""Configuration for Jobs create view."""

name = "jobs-create"
url = "/jobs/create"
resource_config = "jobs_resource"
pid_path = "id"
api_endpoint = "/jobs"
title = "Create Job"
list_view_name = "jobs"

form_fields = {
"title": {
"order": 1,
"text": _("Title"),
"description": _("A title of the job."),
},
"description": {
"order": 2,
"text": _("Description"),
"description": _("A short description about the job."),
},
"created": {"order": 3},
"updated": {"order": 4},
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ import React, { Component } from "react";
import { UserListItemCompact, toRelativeTime } from "react-invenio-forms";
import { withState } from "react-searchkit";
import { Popup, Table, Button, Icon } from "semantic-ui-react";
// import { RunButton } from "./RunButton";
import { RunButton } from "./RunButton";

Check warning on line 16 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'RunButton' is defined but never used

Check warning on line 16 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'RunButton' is defined but never used

Check warning on line 16 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'RunButton' is defined but never used

Check warning on line 16 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'RunButton' is defined but never used
import { Actions } from "@js/invenio_administration";
import { StatusFormatter } from "./StatusFormatter";
import { AdminUIRoutes } from "@js/invenio_administration/src/routes";
import { http } from "react-invenio-forms";

class SearchResultItemComponent extends Component {
render() {
const { result } = this.props;
const {

Check failure on line 24 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

Delete `·`

Check failure on line 24 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

Delete `·`

Check failure on line 24 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

Delete `·`

Check failure on line 24 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

Delete `·`
title,

Check failure on line 25 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'title' is missing in props validation

Check failure on line 25 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'title' is missing in props validation

Check failure on line 25 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'title' is missing in props validation

Check failure on line 25 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'title' is missing in props validation
actions,

Check failure on line 26 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'actions' is missing in props validation

Check failure on line 26 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'actions' is missing in props validation

Check failure on line 26 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'actions' is missing in props validation

Check failure on line 26 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'actions' is missing in props validation
apiEndpoint,

Check failure on line 27 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'apiEndpoint' is missing in props validation

Check failure on line 27 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'apiEndpoint' is missing in props validation

Check failure on line 27 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'apiEndpoint' is missing in props validation

Check failure on line 27 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'apiEndpoint' is missing in props validation
idKeyPath,

Check failure on line 28 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'idKeyPath' is missing in props validation

Check failure on line 28 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'idKeyPath' is missing in props validation

Check failure on line 28 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'idKeyPath' is missing in props validation

Check failure on line 28 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'idKeyPath' is missing in props validation
listUIEndpoint,

Check failure on line 29 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'listUIEndpoint' is missing in props validation

Check failure on line 29 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'listUIEndpoint' is missing in props validation

Check failure on line 29 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'listUIEndpoint' is missing in props validation

Check failure on line 29 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'listUIEndpoint' is missing in props validation
resourceName,

Check failure on line 30 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'resourceName' is missing in props validation

Check failure on line 30 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'resourceName' is missing in props validation

Check failure on line 30 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'resourceName' is missing in props validation

Check failure on line 30 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'resourceName' is missing in props validation
displayDelete,

Check failure on line 31 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'displayDelete' is missing in props validation

Check failure on line 31 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'displayDelete' is missing in props validation

Check failure on line 31 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'displayDelete' is missing in props validation

Check failure on line 31 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'displayDelete' is missing in props validation
displayEdit,

Check failure on line 32 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

'displayEdit' is missing in props validation

Check failure on line 32 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

'displayEdit' is missing in props validation

Check failure on line 32 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

'displayEdit' is missing in props validation

Check failure on line 32 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

'displayEdit' is missing in props validation
result } = this.props;

Check failure on line 33 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 18.x)

Insert `,⏎···`

Check failure on line 33 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, postgresql14, opensearch2, 20.x)

Insert `,⏎···`

Check failure on line 33 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 18.x)

Insert `,⏎···`

Check failure on line 33 in invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js

View workflow job for this annotation

GitHub Actions / Tests (3.12, postgresql14, opensearch2, 20.x)

Insert `,⏎···`

return (
<Table.Row>
Expand Down Expand Up @@ -93,10 +104,10 @@ class SearchResultItemComponent extends Component {
: toRelativeTime(result.next_run, i18next.language) ?? "−"}
</Table.Cell>
<Table.Cell collapsing>
<Button
<Button.Group size="tiny" className="relaxed">
{/* <RunButton config={result.default_args} /> */}
<Button
icon
fluid
basic
labelPosition="left"
onClick={() => {
http.post("/api/jobs/" + result.id + "/runs");
Expand All @@ -105,7 +116,19 @@ class SearchResultItemComponent extends Component {
<Icon name="play" />
Run
</Button>
{/* <RunButton jobId={result.id} config={result.default_args ?? {}} /> */}
<Actions
title={title}
resourceName={resourceName}
apiEndpoint={apiEndpoint}
editUrl={AdminUIRoutes.editView(listUIEndpoint, result, idKeyPath)}
actions={actions}
displayEdit={displayEdit}
displayDelete={displayDelete}
resource={result}
idKeyPath={idKeyPath}
listUIEndpoint={listUIEndpoint}
/>
</Button.Group>
</Table.Cell>
</Table.Row>
);
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ invenio_assets.webpack =
invenio_administration.views =
jobs_list = invenio_jobs.administration.jobs:JobsListView
jobs_details = invenio_jobs.administration.jobs:JobsDetailsView
jobs_edit = invenio_jobs.administration.jobs:JobsEditView
jobs_create = invenio_jobs.administration.jobs:JobsCreateView
invenio_base.api_apps =
jobs = invenio_jobs:InvenioJobs
invenio_base.api_blueprints =
Expand Down

0 comments on commit d126509

Please sign in to comment.