Skip to content

Commit

Permalink
provide "Install learnr" link in Tutorial pane
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Feb 20, 2020
1 parent 9b8641f commit dc37910
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/cpp/session/modules/SessionTutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,31 @@ void handleTutorialHomeRequest(const http::Request& request,

if (tutorialIndex().empty())
{
ss << "<p>No tutorials are currently available.</p>";
ss << "<div class=\"rstudio-tutorials-section\">";

if (!module_context::isPackageInstalled("learnr"))
{
ss << "<p>Please install the learnr package to enable tutorials for RStudio.</p>";
// Button for 'click here' action (styled like a link; behaves like button)
std::stringstream clickHere;
clickHere << "<a"
<< " aria-role=\"button\""
<< " aria-label=\"Install learnr\""
<< " class=\"rstudio-tutorials-install-learnr-link\""
<< " href=\"#\""
<< " onclick=\"window.parent.tutorialInstallLearnr(); return false;\""
<< " onkeydown=\"window.parent.tutorialKeydown(event)\">"
<< "click here"
<< "</a>";

ss << "<p>The <code>learnr</code> package is required to run tutorials for RStudio.</p>"
<< "<p>Please " << clickHere.str() << " to install the <code>learnr</code> package.</p>";
}
else
{
ss << "<p>Please wait while RStudio finishes indexing...</p>";
ss << "<p>Please wait while RStudio finishes indexing available tutorials...</p>";
}

ss << "</div>";
}

for (auto entry : tutorialIndex())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@external rstudio-tutorials-sublabel;
@external rstudio-tutorials-footer;
@external rstudio-tutorials-footer-text;
@external rstudio-tutorials-install-learnr-link;

/* Scrollbars */

Expand Down Expand Up @@ -211,4 +212,8 @@

.rstudio-themes-dark-menus .rstudio-tutorials-sublabel {
color: rgb(172, 172, 172);
}
}

.rstudio-themes-dark-menus .rstudio-tutorials-install-learnr-link:link {
color: rgb(118, 171, 221);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
import org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent;
import org.rstudio.studio.client.workbench.views.tutorial.TutorialPresenter.Tutorial;
import org.rstudio.studio.client.workbench.views.tutorial.events.TutorialNavigateEvent;
import org.rstudio.studio.client.workbench.views.tutorial.events.TutorialNavigateEvent.Handler;
Expand Down Expand Up @@ -62,7 +63,8 @@ protected TutorialPane(GlobalDisplay globalDisplay,
super("Tutorial");

globalDisplay_ = globalDisplay;
commands_ = commands;
events_ = events;
commands_ = commands;

indicator_ = globalDisplay_.getProgressIndicator("Error Loading Tutorial");

Expand Down Expand Up @@ -324,14 +326,45 @@ public HandlerRegistration addTutorialNavigateHandler(Handler handler)
return frame_.addHandler(handler, TutorialNavigateEvent.TYPE);
}

private void installLearnr()
{
SendToConsoleEvent event = new SendToConsoleEvent("install.packages(\"learnr\")", true);
events_.fireEvent(event);
}

private final native void initTutorialJsCallbacks()
/*-{
var self = this;
$wnd.tutorialRun = $entry(function(tutorialName, tutorialPackage) {
self.@org.rstudio.studio.client.workbench.views.tutorial.TutorialPane::runTutorial(*)(tutorialName, tutorialPackage);
});
$wnd.tutorialInstallLearnr = $entry(function() {
self.@org.rstudio.studio.client.workbench.views.tutorial.TutorialPane::installLearnr()();
});
$wnd.tutorialKeydown = $entry(function(event) {
var code = event.code;
var button = event.which || event.keyCode;
var handled =
code === "Space" ||
code === "Enter" ||
button === 13 ||
button === 32;
if (handled) {
self.@org.rstudio.studio.client.workbench.views.tutorial.TutorialPane::installLearnr()();
return false;
}
return true;
});
}-*/;

// Resources ----
Expand All @@ -350,6 +383,7 @@ public interface Resources extends ClientBundle

// Injected ----
private final GlobalDisplay globalDisplay_;
private final EventBus events_;
private final Commands commands_;

private static final Resources RES = GWT.create(Resources.class);
Expand Down

0 comments on commit dc37910

Please sign in to comment.