Skip to content

Commit

Permalink
Refactor opening nomad links using iFrame
Browse files Browse the repository at this point in the history
(reference #53)
  • Loading branch information
piotrzarzycki21 committed Apr 5, 2024
1 parent 89799d8 commit 8d6fd2c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
package controller
{
import model.proxy.login.ProxyLogin;
import mediator.MediatorMainContentView;

import org.apache.royale.html.elements.Iframe;
import org.puremvc.as3.multicore.interfaces.INotification;
import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
import org.apache.royale.utils.js.loadJavascript;
import org.apache.royale.net.HTTPService;
import org.apache.royale.net.beads.CORSCredentialsBead;
import org.apache.royale.net.events.FaultEvent;
import org.apache.royale.net.HTTPHeader;
import mediator.MediatorMainContentView;
import org.apache.royale.jewel.Group;
import org.apache.royale.core.IChild;

public class CommandLaunchNomadLink extends SimpleCommand
{
override public function execute(note:INotification):void
{
var mainMediator:MediatorMainContentView = facade.retrieveMediator(MediatorMainContentView.NAME) as MediatorMainContentView;

var nomadHelper:Group = mainMediator.view.viewNomadHelper as Group;

if (nomadHelper.numElements > 0)
{
for (var i:int = nomadHelper.numElements - 1; i >= 0; i--)
{
var element:IChild = nomadHelper.getElementAt(i);
nomadHelper.removeElement(element);
}
}

var nomadHelperContent:Group = new Group();
nomadHelper.addElement(nomadHelperContent);

var nomadHelper:Iframe = mainMediator.view.viewNomadHelper as Iframe;
var link:String = String(note.getBody());
window["$"](nomadHelperContent.element).load("https://nomadweb.venus.startcloud.com/nomad/nomadhelper.html?link='"+link+"'", function(responseText:String, textStatus:String, jqXHR:Object):void {
var status:String = textStatus;
});
var encodedLink:String = encodeURIComponent(link);
nomadHelper.src = "https://nomadweb.venus.startcloud.com/nomad/nomadhelper.html?link=" + encodedLink;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ package mediator.bookmarks

private function onOpenNomadWeb(event:MouseEvent):void
{
event.preventDefault();

sendNotification(ApplicationConstants.COMMAND_LAUNCH_NOMAD_LINK, view.selectedItem.nomadURL);
}

Expand All @@ -174,6 +176,7 @@ package mediator.bookmarks

private function refreshButtonLinks():void
{

if (view.selectedItem)
{
view.openClient.html = "<a target='_blank' href='" + view.selectedItem.url + "'>Open in Client</a>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,5 @@
<bookmarks:EditBookmarkView localId="editBookmarkView"/>
</j:ScrollableSectionContent>
</j:ApplicationMainContent>
<j:Group id="nomadHelper" visible="false"/>
<html:Iframe id="nomadHelper" visible="false"></html:Iframe>
</j:ResponsiveView>
73 changes: 40 additions & 33 deletions Super.Human.Portal_Royale/src/resources/nomadhelper.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>Test Links Scoped to Nomad</title>
<script type="text/javascript">
const HASH_PREFIX = '#/';
<!-- <meta http-equiv="Content-Security-Policy" content="frame-ancestors 'self' domino.venus.startcloud.com;">-->
</head>
<body>
<script type="text/javascript">
window.onload = () => {
var link = GetURLParameter("link");
if (link)
{
const hrefUrl = new URL(link);
if (navigator?.serviceWorker?.controller) {
navigator.serviceWorker.controller.postMessage({
type: 'openNotesUri',
payload: {
notesUri: decodeURIComponent(
hrefUrl.hash.substring(
hrefUrl.hash.indexOf(HASH_PREFIX) + HASH_PREFIX.length
),
),
},
});
} else {
console.error('no service worker registered');
}
}
var link = GetURLParameter("link");

link = decodeURIComponent(link);
openLink(link);
};

function openLink(link)
{
const HASH_PREFIX = '#/';
const hrefUrl = new URL(link);
if (navigator?.serviceWorker?.controller) {
navigator.serviceWorker.controller.postMessage({
type: 'openNotesUri',
payload: {
notesUri: decodeURIComponent(
hrefUrl.hash.substring(
hrefUrl.hash.indexOf(HASH_PREFIX) + HASH_PREFIX.length
),
),
},
});
} else {
console.error('no service worker registered');
}
}

function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var urlParam = sURLVariables[i];

var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
return sParameterName[1];
}
}
}
</script>
</head>
<body>
</script>
</body>
</html>

0 comments on commit 8d6fd2c

Please sign in to comment.