Actually log a session from client instead of pinging
This commit is contained in:
parent
d2a479f691
commit
09f0648138
@ -1,7 +1,10 @@
|
|||||||
namespace StudySystemClient {
|
namespace StudySystemClient {
|
||||||
public class ActivitiesView : Gtk.Box {
|
public class ActivitiesView : Gtk.Box {
|
||||||
|
private Client client;
|
||||||
|
|
||||||
public ActivitiesView(Client client) {
|
public ActivitiesView(Client client) {
|
||||||
margin_top = margin_bottom = margin_start = margin_end = 0;
|
margin_top = margin_bottom = margin_start = margin_end = 0;
|
||||||
|
this.client = client;
|
||||||
|
|
||||||
var scrolled_window = new Gtk.ScrolledWindow();
|
var scrolled_window = new Gtk.ScrolledWindow();
|
||||||
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
||||||
@ -24,17 +27,31 @@ namespace StudySystemClient {
|
|||||||
{ "Physics", ActivityType.EXERCISES },
|
{ "Physics", ActivityType.EXERCISES },
|
||||||
};
|
};
|
||||||
foreach (var activity in activities) {
|
foreach (var activity in activities) {
|
||||||
var card = new ActivityCard(client, activity);
|
var card = new ActivityCard(activity);
|
||||||
|
card.session_logged.connect(log_session);
|
||||||
card_container.append(card);
|
card_container.append(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
scrolled_window.set_child(card_container);
|
scrolled_window.set_child(card_container);
|
||||||
this.append(scrolled_window);
|
this.append(scrolled_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void log_session(string subject, ActivityType type,
|
||||||
|
int minutes) {
|
||||||
|
try {
|
||||||
|
yield client.log_session(subject, type, minutes);
|
||||||
|
stderr.printf("Successfully logged session\n");
|
||||||
|
} catch (ClientError e) {
|
||||||
|
stderr.printf("Error logging session: %s\n", e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ActivityCard : Gtk.Frame {
|
private class ActivityCard : Gtk.Frame {
|
||||||
public ActivityCard(Client client, Activity activity) {
|
public signal void session_logged(string subject, ActivityType type,
|
||||||
|
int minutes);
|
||||||
|
|
||||||
|
public ActivityCard(Activity activity) {
|
||||||
add_css_class("card");
|
add_css_class("card");
|
||||||
|
|
||||||
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
|
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
|
||||||
@ -63,21 +80,23 @@ namespace StudySystemClient {
|
|||||||
|
|
||||||
set_child(content);
|
set_child(content);
|
||||||
|
|
||||||
var log_session_popover = new LogSessionPopover(client);
|
var log_session_popover = new LogSessionPopover();
|
||||||
log_session_popover.set_parent(button);
|
log_session_popover.set_parent(button);
|
||||||
button.clicked.connect(() => log_session_popover.popup());
|
button.clicked.connect(() => log_session_popover.popup());
|
||||||
|
log_session_popover.session_logged.connect((minutes) => {
|
||||||
|
session_logged(activity.subject, activity.type, minutes);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LogSessionPopover : Gtk.Popover {
|
private class LogSessionPopover : Gtk.Popover {
|
||||||
|
public signal void session_logged(int minutes);
|
||||||
|
|
||||||
private const int DEFAULT_LENGTH = 30;
|
private const int DEFAULT_LENGTH = 30;
|
||||||
|
|
||||||
private Gtk.SpinButton input;
|
private Gtk.SpinButton input;
|
||||||
private Client client;
|
|
||||||
|
|
||||||
public LogSessionPopover(Client client) {
|
|
||||||
this.client = client;
|
|
||||||
|
|
||||||
|
public LogSessionPopover() {
|
||||||
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
|
var content = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
|
||||||
|
|
||||||
var label = new Gtk.Label("Minutes");
|
var label = new Gtk.Label("Minutes");
|
||||||
@ -102,16 +121,10 @@ namespace StudySystemClient {
|
|||||||
closed.connect(reset);
|
closed.connect(reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void submit() {
|
private void submit() {
|
||||||
|
session_logged((int)input.value);
|
||||||
reset();
|
reset();
|
||||||
popdown();
|
popdown();
|
||||||
|
|
||||||
try {
|
|
||||||
yield client.ping();
|
|
||||||
stderr.printf("Successfully pinged server\n");
|
|
||||||
} catch (ClientError e) {
|
|
||||||
stderr.printf("Error pinging server: %s\n", e.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user