private void setPreviousDeployments(JsArray<RSConnectDeploymentRecord> recs) { // clear existing deployment menu, if any publishMenu_.clearItems(); defaultRec_ = null; // if there are existing deployments, make the UI reflect that this is a // republish if (recs != null && recs.length() > 0) { applyCaption("Republish"); // find the default (last deployed record)--this needs to be done as // a first pass so we can identify the associated menu item in one // pass for (int i = 0; i < recs.length(); i++) { final RSConnectDeploymentRecord rec = recs.get(i); if (rec == null) continue; if (defaultRec_ == null || defaultRec_.getWhen() < rec.getWhen()) { defaultRec_ = rec; } } // build the deployment menu for (int i = 0; i < recs.length(); i++) { final RSConnectDeploymentRecord rec = recs.get(i); final DeploymentMenuItem menuItem = new DeploymentMenuItem( rec, rec == defaultRec_, new Command() { @Override public void execute() { onPublishRecordClick(rec); } }); publishMenu_.addItem(menuItem); } publishMenu_.addSeparator(); publishMenu_.addItem( new MenuItem( AppCommand.formatMenuLabel( commands_.rsconnectDeploy().getImageResource(), "Other Destination...", null), true, new Scheduler.ScheduledCommand() { @Override public void execute() { onPublishRecordClick(null); } })); } else { // show first-time publish button caption applyCaption("Publish"); // no existing deployments to redeploy to, so just offer to make a new // one publishMenu_.addItem( new MenuItem( AppCommand.formatMenuLabel( commands_.rsconnectDeploy().getImageResource(), "Publish " + RSConnect.contentTypeDesc(contentType_) + "...", null), true, new Scheduler.ScheduledCommand() { @Override public void execute() { onPublishRecordClick(defaultRec_); } })); } // if it's a plot, show an MRU of recently deployed plot "names" if (contentType_ == RSConnect.CONTENT_TYPE_PLOT) { plotMru_.addPlotMruEntries( publishMenu_, new OperationWithInput<PlotPublishMRUList.Entry>() { @Override public void execute(Entry plot) { republishPlot(plot); } }); } publishMenu_.addSeparator(); publishMenu_.addItem(commands_.rsconnectManageAccounts().createMenuItem(false)); }
private void onPublishRecordClick(final RSConnectDeploymentRecord previous) { switch (contentType_) { case RSConnect.CONTENT_TYPE_HTML: case RSConnect.CONTENT_TYPE_PRES: if (publishHtmlSource_ == null) { display_.showErrorMessage( "Content Publish Failed", "No HTML could be generated for the content."); return; } publishHtmlSource_.generatePublishHtml( new CommandWithArg<String>() { @Override public void execute(String arg) { events_.fireEvent( RSConnectActionEvent.DeployHtmlEvent( contentType_, contentPath_, arg, publishHtmlSource_.getTitle(), previous)); } }); break; case RSConnect.CONTENT_TYPE_PLOT: // for plots, we need to generate the hosting HTML prior to publishing if (publishHtmlSource_ != null) { publishHtmlSource_.generatePublishHtml( new CommandWithArg<String>() { @Override public void execute(String htmlFile) { events_.fireEvent(RSConnectActionEvent.DeployPlotEvent(htmlFile, previous)); } }); } break; case RSConnect.CONTENT_TYPE_APP: case RSConnect.CONTENT_TYPE_APP_SINGLE: // Shiny application events_.fireEvent( RSConnectActionEvent.DeployAppEvent(contentPath_, contentType_, previous)); break; case RSConnect.CONTENT_TYPE_DOCUMENT: if (docPreview_ == null || (docPreview_.isStatic() && StringUtil.isNullOrEmpty(docPreview_.getOutputFile()) && docPreview_.getSourceFile() != null)) { // if the doc has been saved but not been rendered, go render it and // come back when we're finished renderThenPublish(contentPath_, previous); } else { // All R Markdown variants (single/multiple and static/Shiny) if (docPreview_.getSourceFile() == null) { display_.showErrorMessage( "Unsaved Document", "Unsaved documents cannot be published. Save the document " + "before publishing it."); break; } events_.fireEvent( RSConnectActionEvent.DeployDocEvent( docPreview_, RSConnect.CONTENT_TYPE_DOCUMENT, previous)); } break; case RSConnect.CONTENT_TYPE_WEBSITE: events_.fireEvent( RSConnectActionEvent.DeployDocEvent( docPreview_, RSConnect.CONTENT_TYPE_WEBSITE, previous)); break; default: // should never happen display_.showErrorMessage( "Can't Publish " + RSConnect.contentTypeDesc(contentType_), "The content type '" + RSConnect.contentTypeDesc(contentType_) + "' is not currently supported for publishing."); } }