CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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