Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/configuration/start-stop-panel.tsx
Views: 687
import { Alert, Button, Card, Col, Popconfirm, Row, Space, Spin } from "antd";1import { FormattedMessage, useIntl } from "react-intl";23import { useActions, useRedux } from "@cocalc/frontend/app-framework";4import { Paragraph } from "@cocalc/frontend/components";5import { Icon } from "@cocalc/frontend/components/icon";6import { labels } from "@cocalc/frontend/i18n";7import { capitalize } from "@cocalc/util/misc";8import type { CourseActions } from "../actions";910interface Props {11name: string;12num_running_projects: number;13num_students?: number;14}1516export function StudentProjectsStartStopPanel({17name,18num_running_projects,19num_students,20}: Props) {21const intl = useIntl();22const action_all_projects_state: string = useRedux([23name,24"action_all_projects_state",25]);26const actions: CourseActions = useActions(name);2728function render_in_progress_action() {29let type;30const state_name = action_all_projects_state;31switch (state_name) {32case "stopping":33if (num_running_projects === 0) {34return;35}36type = "warning";37break;38default:39if (num_running_projects === num_students) {40return;41}42type = "info";43}4445return (46<Alert47type={type}48message={49<div>50{capitalize(state_name)} all projects... <Spin />51<br />52<Button53onClick={() =>54actions.student_projects.cancel_action_all_student_projects()55}56>57{intl.formatMessage(labels.cancel)}58</Button>59</div>60}61/>62);63}6465const r = num_running_projects;66const n = num_students;67return (68<Card69title={70<>71<Icon name="bolt" />{" "}72<FormattedMessage73id="course.start-stop-panel.title"74defaultMessage="Start or Stop all Student Projects"75/>76</>77}78>79<Row>80<Col md={18}>81<FormattedMessage82id="course.start-stop-panel.status"83defaultMessage={`{r} of {n} student projects currently running.`}84values={{ r, n }}85/>86</Col>87</Row>88<Row style={{ marginTop: "10px" }}>89<Col md={24}>90<Space>91<Popconfirm92title={93<div style={{ maxWidth: "400px" }}>94<FormattedMessage95id="course.start-stop-panel.confirm"96defaultMessage={`<b>Are you sure you want to start all student projects?</b>97{br}98This will ensure the projects are already running when the students open them,99and can make assigning and collecting homework more robust.`}100values={{ br: <br /> }}101/>102</div>103}104onConfirm={() => {105actions.student_projects.action_all_student_projects("start");106}}107>108<Button109disabled={110n === 0 || n === r || action_all_projects_state === "starting"111}112>113<Icon name="bolt" />{" "}114<FormattedMessage115id="course.start-stop-panel.start-all.button"116defaultMessage="Start all..."117/>118</Button>119</Popconfirm>120<Popconfirm121title={122<div style={{ maxWidth: "400px" }}>123<FormattedMessage124id="course.start-stop-panel.stop-all.confirm"125defaultMessage="Are you sure you want to stop all student projects (this might be disruptive)?"126/>127</div>128}129onConfirm={() => {130actions.student_projects.action_all_student_projects("stop");131}}132>133<Button134disabled={135n === 0 || r === 0 || action_all_projects_state === "stopping"136}137>138<Icon name="PoweroffOutlined" />{" "}139<FormattedMessage140id="course.start-stop-panel.stop-all.button"141defaultMessage="Stop all..."142/>143</Button>144</Popconfirm>145</Space>146</Col>147</Row>148<Row style={{ marginTop: "10px" }}>149<Col md={24}>150{action_all_projects_state !== "any" && render_in_progress_action()}151</Col>152</Row>153<hr />154<Paragraph type="secondary">155<FormattedMessage156id="course.start-stop-panel.info"157defaultMessage={`Start all projects associated with this course,158so they are immediately ready for your students to use.159For example, you might do this before a computer lab.160You can also stop all projects in order to ensure161that they do not waste resources or are properly upgraded when next used by students.`}162/>163</Paragraph>164</Card>165);166}167168169