Skip to content

Commit

Permalink
Merge branch 'aiccra-tip-migrations' into aiccra-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed Mar 22, 2024
2 parents 99ca26a + 2e74b7e commit 4cf99f4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public String execute() throws Exception {
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);

String requestBody = "{private_key:" + privateKey + "}";
String requestBody = "{\"private_key\":\"" + privateKey.replace("\"", "\\\"") + "\"}";

// String requestBody = "{private_key:" + privateKey + "}";

// Get the output stream to send data
try (OutputStream os = connection.getOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import org.cgiar.ccafs.marlo.utils.AESConvert;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,6 +38,7 @@ public class TipDinamicUrlGenerationAction extends BaseAction {

// Front-end
private String dinamicTipURL;
private String tokenParameter;

@Inject
private TipParametersManager tipParametersManager;
Expand All @@ -50,6 +54,9 @@ public String createDinamicURL() {

try {
String userEmail = "", token = "", loginService = "";
if (tokenParameter != null && !tokenParameter.isEmpty()) {
token = tokenParameter;
}
if (this.getCurrentUser() != null && this.getCurrentUser().getEmail() != null) {
userEmail = this.getCurrentUser().getEmail();
if (this.getCurrentUser().isCgiarUser() == true) {
Expand Down Expand Up @@ -93,9 +100,15 @@ public String createDinamicURL() {

@Override
public String execute() throws Exception {
Map<String, Parameter> parameters = this.getParameters();
try {
tokenParameter = StringUtils.trim(parameters.get(APConstants.FIELD_ID).getMultipleValues()[0]);
} catch (Exception e) {
LOG.error("Error reading token parameter: " + e);
}

if (this.createDinamicURL() != null) {
this.dinamicTipURL = this.createDinamicURL();
this.dinamicTipURL = this.createDinamicURL();
if (this.dinamicTipURL != null) {
return SUCCESS;
}
return ERROR;
Expand Down
81 changes: 49 additions & 32 deletions marlo-web/src/main/webapp/crp/js/tip/tipEmbedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,58 @@ $(document).ready(function() {
var iframeInitialWidth = '100%';
var iframeInitialHeight = '800px';
var fullscreenButton = null;
var token = null;

$.ajax({
url: baseURL + '/tipGenerateUrlAction.do',
type: 'GET',
dataType: 'json',
success: function(response) {

var embeddedPageUrl = response.dinamicTipURL;
console.log("embeddedPageUrl " + embeddedPageUrl);
iframe = document.createElement('iframe');
iframe.src = embeddedPageUrl;
iframe.style.width = iframeInitialWidth;
iframe.style.height = iframeInitialHeight;

/****************/
iframe.setAttribute('allow', 'autoplay');
iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-top-navigation');
$.ajax({
url: baseURL + '/tipTokenService.do',
type: 'POST',
dataType: 'json',
success: function(response) {
token = response.token;

// Add iframe to the element with ID 'embeddedPage'
document.getElementById('embeddedPage').appendChild(iframe);
$.ajax({
url: baseURL + '/tipGenerateUrlAction.do',
data: {
fieldID: token
},
type: 'GET',
dataType: 'json',
success: function(response) {

var embeddedPageUrl = response.dinamicTipURL;
console.log("embeddedPageUrl " + embeddedPageUrl);
iframe = document.createElement('iframe');
iframe.src = embeddedPageUrl;
iframe.style.width = iframeInitialWidth;
iframe.style.height = iframeInitialHeight;

/****************/
iframe.setAttribute('allow', 'autoplay');
iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-top-navigation');

// Add iframe to the element with ID 'embeddedPage'
document.getElementById('embeddedPage').appendChild(iframe);

// Create and add fullscreen button
fullscreenButton = document.createElement('button');
fullscreenButton.classList.add('fullscreen-button');
fullscreenButton.innerHTML = '<i class="fas fa-expand"></i> Fullscreen';

fullscreenButton.addEventListener('click', toggleFullscreen);

// Add button to the 'embeddedPage' container
document.getElementById('embeddedPage').appendChild(fullscreenButton);
},
error: function(xhr, status, error) {
console.error('Error getting embedded URL:', error);
}
});

// Create and add fullscreen button
fullscreenButton = document.createElement('button');
fullscreenButton.classList.add('fullscreen-button');
fullscreenButton.innerHTML = '<i class="fas fa-expand"></i> Fullscreen';

fullscreenButton.addEventListener('click', toggleFullscreen);

// Add button to the 'embeddedPage' container
document.getElementById('embeddedPage').appendChild(fullscreenButton);
},
error: function(xhr, status, error) {
console.error('Error getting embedded URL:', error);
}
});
},
error: function(error) {
console.error('Error getting embedded URL:', error);
}
});

function toggleFullscreen() {
var elem = document.getElementById('embeddedPage');
Expand Down

0 comments on commit 4cf99f4

Please sign in to comment.