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

initial jobs frontend #4

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
97 changes: 46 additions & 51 deletions invenio_jobs/administration/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
AdminResourceDetailView,
AdminResourceListView,
)
from invenio_i18n import lazy_gettext as _
from invenio_search_ui.searchconfig import search_app_config


class JobListView(AdminResourceListView):
"""Search admin view for jobs."""
class JobsListView(AdminResourceListView):
"""Configuration for Jobs list view."""

api_endpoint = "/jobs"
name = "jobs"
Expand All @@ -29,73 +30,67 @@ class JobListView(AdminResourceListView):
menu_label = "Jobs"
category = "System"
pid_path = "id"
icon = "cogs"
icon = "settings"
template = "invenio_administration/search.html"

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

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

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

actions = {
# TODO: Define actions
# "delete": {
# "text": "Delete",
# "payload_schema": None,
# "order": 2,
# },
"settings": {
"text": "Settings",
"payload_schema": None,
"order": 1,
"icon": "star",
},
"schedule": {
"text": "Schedule",
"payload_schema": None,
"order": 2,
},
"run": {
"text": "Run Now",
"payload_schema": None,
"order": 2,
},
}
# TODO: Define search config for jobs
# search_config_name = "JOBS_SEARCH"
# search_facets_config_name = "JOBS_FACETS"
# search_sort_config_name = "JOBS_SORT_OPTIONS"

# def init_search_config(self):
# """Build search view config."""
# return partial(
# search_app_config,
# config_name=self.get_search_app_name(),
# available_facets=current_app.config.get(self.search_facets_config_name),
# sort_options=current_app.config[self.search_sort_config_name],
# endpoint=self.get_api_endpoint(),
# headers=self.get_search_request_headers(),
# initial_filters=[["status", "P"]],
# hidden_params=[
# ["include_deleted", "1"],
# ],
# page=1,
# size=30,
# )

@staticmethod
def disabled():
"""Disable the view on demand."""
return current_app.config["JOBS_ADMINISTRATION_DISABLED"]


class JobDetailView(AdminResourceDetailView):
"""Admin job detail view."""


class JobsDetailView(AdminResourceDetailView):
"""Configuration for Jobs detail view."""

url = "/jobs/<pid_value>"
api_endpoint = "/jobs"
name = "job-details"
search_request_headers = {"Accept": "application/json"}
name = "Job Details"
resource_config = "jobs_resource"
title = "Job"
title = "Job Details"

template = "invenio_administration/details.html"
display_delete = True
display_edit = True
display_delete = False
display_edit = False
display_search = False

list_view_name = "jobs"
pid_path = "id"
request_headers = {"Accept": "application/vnd.inveniordm.v1+json"}

actions = {}

item_field_list = {
"title": {"text": "Title", "order": 1},
"run": {"text": _("Runs"), "order": 1},
"duration": {"text": _("Duration"), "order": 2},
"message": {"text": _("Message"), "order": 3},
"user": {"text": _("Started by"), "order": 4},
}
28 changes: 28 additions & 0 deletions invenio_jobs/administration/runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# Invenio-Jobs is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Invenio administration Runs view module."""
from invenio_administration.views.base import AdminResourceListView
from invenio_i18n import lazy_gettext as _


class RunsListView(AdminResourceListView):
"""Configuration for System Runs sets list view."""

api_endpoint = "/runs"
name = "Runs"
search_request_headers = {"Accept": "application/vnd.inveniordm.v1+json"}
title = "Runs"
category = "System"
resource_config = "jobs_resource"
icon = "signal"
extension_name = "invenio-rdm-records"
display_search = False
display_delete = False
display_edit = False
display_create = False
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of Invenio.
* Copyright (C) 2024 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import React, { Component } from "react";
import { Button, Icon } from "semantic-ui-react";
import { i18next } from "@translations/invenio_app_rdm/i18next";

export class SystemJobActions extends Component {
handleAction = async (action) => {
const actionConfig = {
restore: {
label: i18next.t("Settings"),
icon: "cogwheel",
notificationTitle: i18next.t("Settings"),
},
block: {
label: i18next.t("Schedule"),
icon: "calendar",
notificationTitle: i18next.t("Schedule"),
},
deactivate: {
label: i18next.t("Run now"),
icon: "pause",
notificationTitle: i18next.t("Run now"),
},
}[action];

return actionConfig;
};

render() {
const actionItems = [
{ key: "settings", label: "Settings", icon: "cog" },
{ key: "schedule", label: "Schedule", icon: "calendar" },
{ key: "run", label: "Run now", icon: "play" },
];

const generateActions = () => {
return (
<>
{actionItems.map((actionItem) => (
<Button key={actionItem.key} icon fluid basic labelPosition="left">
<Icon name={actionItem.icon} />
{i18next.t(actionItem.label)}
</Button>
))}
</>
);
};

return (
<div>
<Button.Group basic widths={5} compact className="margined">
{generateActions()}
</Button.Group>
</div>
);
}
}

SystemJobActions.propTypes = {};

SystemJobActions.defaultProps = {};
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
// This file is part of InvenioCommunities
// Copyright (C) 2022 CERN.
// Copyright (C) 2024 CERN.
//
// Invenio-Jobs is free software; you can redistribute it and/or modify it
// Invenio RDM is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

console.log("jobs administration");
import { initDefaultSearchComponents } from "@js/invenio_administration";
import { createSearchAppInit } from "@js/invenio_search_ui";
import { NotificationController } from "@js/invenio_administration";
import { SearchResultItemLayout, JobSearchLayout } from "./search";

const domContainer = document.getElementById("invenio-search-config");

const defaultComponents = initDefaultSearchComponents(domContainer);

const overridenComponents = {
...defaultComponents,
"InvenioAdministration.SearchResultItem.layout": SearchResultItemLayout,
"SearchApp.layout": JobSearchLayout,
};

createSearchAppInit(
overridenComponents,
true,
"invenio-search-config",
false,
NotificationController
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* // This file is part of Invenio-Requests
* // Copyright (C) 2024 CERN.
* //
* // Invenio-Requests is free software; you can redistribute it and/or modify it
* // under the terms of the MIT License; see LICENSE file for more details.
*/

import { SearchAppResultsPane } from "@js/invenio_search_ui/components";
import PropTypes from "prop-types";
import React, { Component } from "react";

export class JobSearchLayout extends Component {
render() {
const { config, appName } = this.props;
return (
<SearchAppResultsPane
layoutOptions={config.layoutOptions}
appName={appName}
/>
);
}
}

JobSearchLayout.propTypes = {
config: PropTypes.object.isRequired,
appName: PropTypes.string,
};

JobSearchLayout.defaultProps = {
appName: "",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of Invenio.
* Copyright (C) 2022-2024 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import { BoolFormatter } from "@js/invenio_administration";
import { SystemJobActions } from "../SystemJobActions";
import PropTypes from "prop-types";
import React, { Component } from "react";
import { Table } from "semantic-ui-react";
import { withState } from "react-searchkit";
import { i18next } from "@translations/invenio_app_rdm/i18next";
import { UserListItemCompact } from "react-invenio-forms";

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

return (
<Table.Row>
<Table.Cell
key={`job-name-${result.name}`}
data-label={i18next.t("Name")}
collapsing
className="word-break-all"
>
<a href={result.links.admin_self_html}>{result.name}</a>
</Table.Cell>
<Table.Cell
key={`job-last-run-${result.last_run_start_time}`}
data-label={i18next.t("Last run")}
collapsing
className=""
>
{result.last_run_start_time}
</Table.Cell>
<Table.Cell
collapsing
key={`job-status${result.status}`}
data-label={i18next.t("Next run")}
className="word-break-all"
>
<BoolFormatter
tooltip={i18next.t("Status")}
icon="check"
color="green"
value={result.last_run_status === "Success"}
/>
<BoolFormatter
tooltip={i18next.t("Status")}
icon="ban"
color="red"
value={result.last_run_status === "Failed"}
/>
</Table.Cell>
<Table.Cell
key={`job-user-${result.user.id}`}
data-label={i18next.t("Started by")}
collapsing
className="word-break-all"
>
<UserListItemCompact user={result.user} id={result.user.id} />
</Table.Cell>
<Table.Cell
collapsing
key={`job-next-run${result.next_run}`}
data-label={i18next.t("Next run")}
className="word-break-all"
>
{result.next_run}
</Table.Cell>
<Table.Cell collapsing>
<SystemJobActions />
</Table.Cell>
</Table.Row>
);
}
}

SearchResultItemComponent.propTypes = {
result: PropTypes.object.isRequired,
};

SearchResultItemComponent.defaultProps = {};

export const SearchResultItemLayout = withState(SearchResultItemComponent);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* This file is part of Invenio.
* Copyright (C) 2024 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

export { SearchResultItemLayout } from "./SearchResultItemLayout";
export { JobSearchLayout } from "./JobSearchLayout.js";
Loading