Skip to content

Commit

Permalink
Merge branch 'main' into features/issue_57_nomad_helper_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzarzycki21 committed May 29, 2024
2 parents 10c1731 + 1f99b9a commit 584bf88
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package controller
import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

import view.controls.snackbarNomadHelperUrl.SnackbarNomadHelperUrl;
import view.controls.snackbarNomadHelperUrl.SnackbarNomadPopupBlocked;

/**
* This is a workaround to open a Nomad link directly in an existing Nomad tab by using the Nomad service worker.
Expand All @@ -29,7 +30,7 @@ package controller
var loginProxy:ProxyLogin = facade.retrieveProxy(ProxyLogin.NAME) as ProxyLogin;
data = note.getBody();

var link:String = note.getBody().link;
var link:String = data.link;
window["onmessage"] = null;

if (loginProxy.isNomadHelperUrlExists()) // if a nomadhelper.html URL is configured, try to open the URL with nomadhelper.html first
Expand Down Expand Up @@ -65,7 +66,7 @@ package controller
}
catch(error:Error)
{

SnackbarNomadPopupBlocked.show();
}

data = null;
Expand All @@ -74,18 +75,22 @@ package controller

// This triggers on any messages sent by nomadhelper.html
private function onWindowMessage(event:Event):void
{
if (!data) return;
{
// Cancel any later messages - not expected
window["onmessage"] = null;

if (!data)
{
return;
}

// Retrieve the configred nomadhelper.html URL
var loginProxy:ProxyLogin = facade.retrieveProxy(ProxyLogin.NAME) as ProxyLogin;
var nomadHelperUrl:String = loginProxy.config.config.nomad_helper_url;

// Cancel any later messages - not expected
window["onmessage"] = null;
var nomadBaseUrl:String = loginProxy.config.config.nomad_base_url;

// Get the message from the event
var winMessage:String = event["data"];

// Parse the message as an error or success message
var errorPrefix:String = "[Error]";
var successPrefix:String = "[Success]";
Expand All @@ -105,9 +110,9 @@ package controller
{
navigateToURL(new URLRequest(data.link), "_blank");
}
catch(e:Error)
catch(error:Error)
{

SnackbarNomadPopupBlocked.show();
}
}
else if (successIndex > -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ package mediator.bookmarks
import view.applications.ConfigurationAppDetails;
import view.bookmarks.Bookmark;
import view.bookmarks.event.BookmarkEvent;
import org.apache.royale.net.navigateToURL;
import org.apache.royale.net.URLRequest;
import view.controls.LinkWithDescriptionAppButton;

public class MediatorBookmarks extends Mediator implements IMediator
{
Expand Down Expand Up @@ -183,19 +182,43 @@ package mediator.bookmarks
var listCount:int = view.bookmarksList.numElements - 1;
for (var i:int = listCount; i >= 0; i--)
{
var bookmarkItem:Object = view.bookmarksList.getElementAt(i);
bookmarkItem.removeEventListener(BookmarkEvent.EDIT_BOOKMARK, onModifyBookmark);
bookmarkItem.removeEventListener(BookmarkEvent.DELETE_BOOKMARK, onModifyBookmark);
bookmarkItem.removeEventListener("initComplete", onBookmarkInitComplete);

view.bookmarksList.removeElement(bookmarkItem);
var bookmarkView:Bookmark = view.bookmarksList.getElementAt(i);
bookmarkView.removeEventListener(BookmarkEvent.EDIT_BOOKMARK, onModifyBookmark);
bookmarkView.removeEventListener(BookmarkEvent.DELETE_BOOKMARK, onModifyBookmark);
bookmarkView.removeEventListener("initComplete", onBookmarkInitComplete);
if (bookmarkView.linkWithDesc && bookmarkView.bookmark.defaultAction == "nomad")
{
bookmarkView.linkWithDesc.removeEventListener("linkClick", onOpenInNomadLink);
}

if (bookmarkView.configurationDetails)
{
bookmarkView.configurationDetails.openInNomad.removeEventListener(MouseEvent.CLICK, onOpenNomadWeb);
}

view.bookmarksList.removeElement(bookmarkView);
}
}

private function onBookmarkInitComplete(event:Event):void
{
var bookmarkView:Bookmark = event.currentTarget as Bookmark;
bookmarkView.configurationDetails.openInNomad.addEventListener(MouseEvent.CLICK, onOpenNomadWeb);
if (bookmarkView.linkWithDesc && bookmarkView.bookmark.defaultAction == "nomad")
{
bookmarkView.linkWithDesc.addEventListener("linkClick", onOpenInNomadLink);
}

if (bookmarkView.configurationDetails)
{
bookmarkView.configurationDetails.openInNomad.addEventListener(MouseEvent.CLICK, onOpenNomadWeb);
}
}

private function onOpenInNomadLink(event:Event):void
{
var link:LinkWithDescriptionAppButton = event.currentTarget as LinkWithDescriptionAppButton;

sendNotification(ApplicationConstants.COMMAND_LAUNCH_NOMAD_LINK, {name: link.appName, link: link.nomadURL});
}

private function onOpenNomadWeb(event:MouseEvent):void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
<j:Label text="{bookmark.description}" multiline="true" className="bigFont" visible="{bookmark.description != null}"/>
</j:HGroup>
<j:VGroup includeIn="database" itemsVerticalAlign="itemsCenter" itemsHorizontalAlign="itemsLeft" gap="2">
<controls:LinkWithDescriptionAppButton showClick="onShowHideDbConfigClick(event)" linkLabel="{urlOpenDefault}" description="{bookmark.description}"/>
<controls:LinkWithDescriptionAppButton localId="linkWithDesc" showClick="onShowHideDbConfigClick(event)" linkLabel="{urlOpenDefault}" description="{bookmark.description}"
appName="{bookmark.name}" nomadURL="{bookmark.nomadURL}"/>
<applications:ConfigurationAppDetails localId="configurationDetails" data="{bookmark}" server="{bookmark.server}"
database="{bookmark.database}" viewName="{bookmark.view}" nomadOpenLink="{bookmark.nomadURL}"
percentWidth="100" visible="false" editable="{editable}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package view.controls.snackbarNomadHelperUrl
{
import org.apache.royale.jewel.Snackbar;

public class SnackbarNomadPopupBlocked extends Snackbar
{
public function SnackbarNomadPopupBlocked()
{
super();

this.typeNames = "jewel snackbar layout SnackbarNomadPopupBlocked";
}

public static function show(message:String = "", parent:Object = null):SnackbarNomadPopupBlocked
{
var snackbar:SnackbarNomadPopupBlocked = new SnackbarNomadPopupBlocked();
snackbar.message = message;
snackbar.duration = 0;
snackbar.action = "Close";

snackbar.show(parent);
return snackbar;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<j:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:j="library://ns.apache.org/royale/jewel" xmlns:html="library://ns.apache.org/royale/html" xmlns:js="library://ns.apache.org/royale/basic"
percentWidth="100" initComplete="onSnackbarInitComplete(event)">
<fx:Script>
<![CDATA[
private function onSnackbarInitComplete(event:Event):void
{
this.refreshAllowMessage();
}
private function refreshAllowMessage():void
{
var allowUrl:String = window['link'].baseURI;
var domainPattern:RegExp = new RegExp(/^(?:https?:\/\/)?([^\/:?#]+)(?:[\/:?#]|$)/, "i");
var result:Object = domainPattern.exec(allowUrl);
if (result)
{
allowMessage.html = 'Allow popups for <code>' + result.pop() + '</code>';
}
else
{
allowMessage.text = "Always allow pop-ups from this site.";
}
}
]]>
</fx:Script>
<j:Label multiline="true"
text="It looks like your browser has blocked a pop-up window. To proceed, please enable pop-ups for this site in your browser settings. If you need assistance, follow these steps:"/>
<html:Ol percentWidth="100">
<html:Li>
<j:Label multiline="true" text="Click on the pop-up blocker icon in the address bar."/>
</html:Li>
<html:Li>
<j:Label localId="allowMessage" multiline="true" />
</html:Li>
<html:Li>
<j:Label multiline="true" text="Reload the page."/>
</html:Li>
</html:Ol>
</j:VGroup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package view.controls.snackbarNomadHelperUrl.beads
{
import org.apache.royale.core.IStrand;
import org.apache.royale.events.Event;
import org.apache.royale.html.elements.Div;
import org.apache.royale.jewel.Snackbar;
import org.apache.royale.jewel.beads.models.SnackbarModel;
import org.apache.royale.jewel.beads.views.SnackbarView;

import view.controls.snackbarNomadHelperUrl.SnackbarNomadPopupBlockedContent;

public class SnackbarNomadPopupBlockedView extends SnackbarView
{
public function SnackbarNomadPopupBlockedView()
{
super();
}

override public function set strand(value:IStrand):void
{
super.strand = value;

var model:SnackbarNomadHelperUrlModel = host.model as SnackbarNomadHelperUrlModel;
model.addEventListener("messageChange", messageChangeHandler);
model.addEventListener("actionChange", actionChangeHandler);

var content:NodeList = host.element.getElementsByClassName("snackbar-content");
host.element.removeChild(content.item(0));

var snackbarMessage:SnackbarNomadPopupBlockedContent = new SnackbarNomadPopupBlockedContent();
snackbarMessage.className = "jewel snackbar-message";

var snackbarContent:Div = new Div();
snackbarContent.className = "jewel snackbar-content";
snackbarContent.addElement(snackbarMessage);
host.addElement(snackbarContent);

this.actionElement = null;
if (model.action)
{
actionChangeHandler(null);
}
}

/**
* Update the text when message changed.
*/
override protected function messageChangeHandler(event:Event):void {

}

/**
* Show the action element or remove it, based on action text.
*/
override protected function actionChangeHandler(event:Event):void {
var model:SnackbarModel = host.model as SnackbarModel;

if (model.action) {
if (!actionElement) {
actionElement = document.createElement("div");
actionElement.className = "jewel snackbar-action";
actionElement.addEventListener("click", actionClickHandler);
host.element.firstChild.appendChild(actionElement);
}
actionElement.innerText = model.action;
} else {
if (actionElement) {
actionElement.removeEventListener("click", actionClickHandler);
host.element.firstChild.removeChild(actionElement);
actionElement = null;
}
}
}

/**
* Trigger event and dismiss the host when action clicked.
*/
override protected function actionClickHandler(event:Event):void {
actionElement.removeEventListener("click", actionClickHandler);
host.dispatchEvent(new Event(Snackbar.ACTION));
SnackbarModel(host.model).duration = -1; // set -1 to dismiss
}
}
}
6 changes: 6 additions & 0 deletions Super.Human.Portal_Royale/src/resources/app-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ controlsSnackbarNomad|SnackbarNomadHelperUrl {
IBeadView: ClassReference("view.controls.snackbarNomadHelperUrl.beads.SnackbarNomadHelperUrlView");
}

controlsSnackbarNomad|SnackbarNomadPopupBlocked {
IBeadModel: ClassReference("view.controls.snackbarNomadHelperUrl.beads.SnackbarNomadHelperUrlModel");
IBeadController: ClassReference("org.apache.royale.jewel.beads.controllers.SnackbarController");
IBeadView: ClassReference("view.controls.snackbarNomadHelperUrl.beads.SnackbarNomadPopupBlockedView");
}

.jewel.slider.noSliderInput input {
visibility: hidden;
margin: 0px !important;
Expand Down

0 comments on commit 584bf88

Please sign in to comment.