Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app2app v2 compatibility #49

Open
wants to merge 1 commit into
base: v1.x/staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions webClient/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="div-input">
<input class="iframe-input input-height input-corner input-text shadowed" type="text" [(ngModel)]="targetAppId"/>
</div>
<div>
<div *ngIf="!asEvent">
<!-- Action types are used to determine what sort of Action is being taken on whatever App instance is the target. Launch simply creates a new instance with the context you provide, but Message can be used to communicate with an already open Instance to drive some action -->

<label class="bold-text" i18n="type of action|choose a type of action to perform@@action-type">Action Type: </label>
Expand All @@ -38,15 +38,25 @@
<label for="actionMessage" i18n="send a message to another app@@message">Message</label>
</div>
<!-- App target modes are used to determine which instance of an App should be communicated with. You can create a new instance to send the Action to, or you could reuse an existing instance that is open. -->
<div>
<div *ngIf="!asEvent">
<label class="bold-text"
i18n="action mode|how to handle launch depending on whether target app has already been launched@@app-target-mode">App Target Mode: </label>
<input type="radio" [(ngModel)]="targetMode" name="targetMode" value="PluginCreate">
<label for="targetCreate" i18n="create new instance@@create-new">Create New</label>

<input type="radio" [(ngModel)]="targetMode" name="targetMode" value="PluginFindAnyOrCreate">
<label for="targetReuse" i18n="reuse any open app@@reuse-any-open">Reuse Any Open</label>
</div>
</div>
<div>
<label class="bold-text" i18n="request v2"> Request V2 </label>
<input type="checkbox" [(ngModel)]="asEvent" name="asEvent" value="asEvent">
</div>
<div *ngIf="asEvent">
<span class="bold-text" i18n="event name">Event Name: </span>
<div class="div-input">
<input class="iframe-input input-height input-corner input-text shadowed" type="text" [(ngModel)]="eventName"/>
</div>
</div>
<span class="bold-text hide-it" i18n="window title for target app@@target-app-window-title">
Target App Window Title (this will become the title for the target window)</span>
<div class="div-input hide-it">
Expand Down
35 changes: 32 additions & 3 deletions webClient/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Copyright Contributors to the Zowe Project.
*/

import { Component, Inject, Optional } from '@angular/core';
import { Component, Inject, Optional} from '@angular/core';
import { Angular2InjectionTokens, ContextMenuItem, Angular2PluginWindowActions } from 'pluginlib/inject-resources';

import { ZluxPopupManagerService, ZluxErrorSeverity } from '@zlux/widgets';
Expand Down Expand Up @@ -55,17 +55,21 @@ export class AppComponent {
helloText = '';
serverResponseMessage: string;
private menuItems: ContextMenuItem[];
public asEvent: boolean;
public eventName: string;

constructor(
public locale: LocaleService,
public translation: TranslationService,
@Inject(Angular2InjectionTokens.PLUGIN_DEFINITION) private pluginDefinition: ZLUX.ContainerPluginDefinition,
@Inject(Angular2InjectionTokens.LOGGER) private log: ZLUX.ComponentLogger,
@Inject(Angular2InjectionTokens.LAUNCH_METADATA) private launchMetadata: any,
@Inject(Angular2InjectionTokens.INSTANCE_ID) private instanceId: string,
@Optional() @Inject(Angular2InjectionTokens.WINDOW_ACTIONS) private windowActions: Angular2PluginWindowActions,
private popupManager: ZluxPopupManagerService,
private helloService: HelloService,
private settingsService: SettingsService) {

//is there a better way so that I can get this info into the HelloService constructor instead of calling a set method directly after creation???
this.helloService.setDestination(ZoweZLUX.uriBroker.pluginRESTUri(this.pluginDefinition.getBasePlugin(), 'hello',""));
this.settingsService.setPlugin(this.pluginDefinition.getBasePlugin());
Expand All @@ -75,6 +79,15 @@ export class AppComponent {
}
}

ngAfterContentInit() {
//INSTANCE_ID
ZoweZLUX.dispatcher.registerEventListener('hello', (event:any)=> {
console.log('got event detail=',event.detail);
event.detail.return = 'hello';
},this.instanceId);
ZoweZLUX.dispatcher.callAny('hello', this.pluginDefinition.getBasePlugin().getIdentifier(), {a:'b', c: false});
}

handleLaunchOrMessageObject(data: any) {
switch (data.type) {
case 'setAppRequest':
Expand Down Expand Up @@ -134,6 +147,8 @@ export class AppComponent {
this.actionType = paramData.actionType;
this.targetMode = paramData.appTarget;
this.targetAppId = res.contents.appid.data.appId;
this.asEvent = !!paramData.asEvent;
this.eventName = paramData.eventName ? paramData.eventName : '';
} else {
this.log.warn(`Incomplete data. AppID or Parameters missing.`);
}
Expand All @@ -145,7 +160,7 @@ export class AppComponent {

saveToServer(): void {
zip(
this.settingsService.saveAppRequest(this.actionType, this.targetMode, this.parameters)
this.settingsService.saveAppRequest(this.actionType, this.targetMode, this.parameters, this.asEvent, this.eventName)
.pipe(catchError(err => {
this.log.warn(`Error on saving parameters, e=${err}`);
this.callStatus = 'Error saving parameters';
Expand Down Expand Up @@ -207,20 +222,34 @@ export class AppComponent {
let type = dispatcher.constants.ActionType[this.actionType];
let mode = dispatcher.constants.ActionTargetMode[this.targetMode];

if (type != undefined && mode != undefined) {
if (!this.asEvent && type != undefined && mode != undefined) {
let actionTitle = 'Launch app from sample app';
let actionID = 'org.zowe.zlux.sample.launch';
let argumentFormatter = {data: {op:'deref',source:'event',path:['data']}};
/*Actions can be made ahead of time, stored and registered at startup, but for example purposes we are making one on-the-fly.
Actions are also typically associated with Recognizers, which execute an Action when a certain pattern is seen in the running App.
*/
let action = dispatcher.makeAction(actionID, actionTitle, mode,type,this.targetAppId,argumentFormatter);
// console.log('forgetting params=',parameters);
// let argumentData = {'data':{'type':'get','callback':(d:any)=> {console.log('i got called back with d=',d);}}};
let argumentData = {'data':(parameters ? parameters : this.parameters)};
this.log.info((message = this.translation.translate('request_succeeded'))); // App request succeeded
this.callStatus = message;
/*Just because the Action is invoked does not mean the target App will accept it. We've made an Action on the fly,
So the data could be in any shape under the "data" attribute and it is up to the target App to take action or ignore this request*/
dispatcher.invokeAction(action,argumentData);
} else if (this.asEvent) {
let retVal = ZoweZLUX.dispatcher.callAny(this.eventName, this.targetAppId, parameters);
if (!!retVal.then) {
retVal.then((response)=> {
if (typeof response == 'object' || typeof response == 'function') {
this.callStatus = JSON.stringify(response);
} else {
this.callStatus = response;
}
});
}
this.log.info('callAny returned with val=',retVal);
} else {
this.log.warn((message = 'Invalid target mode or action type specified'));
}
Expand Down
8 changes: 5 additions & 3 deletions webClient/src/app/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export class SettingsService {
return this.http.get<any>(ZoweZLUX.uriBroker.pluginConfigUri(this.plugin, 'requests/app', undefined));
}

saveAppRequest(actionType: string, targetMode: string, parameters: string) {
saveAppRequest(actionType: string, targetMode: string, parameters: string, asEvent: boolean, eventName: string) {
const requestBody = {
"_objectType": "org.zowe.zlux.sample.setting.request.app.parameters",
"_metaDataVersion": "1.0.0",
"_metaDataVersion": "1.1.0",
"actionType": actionType,
"appTarget": targetMode,
"parameters": parameters
"parameters": parameters,
"asEvent": asEvent,
"eventName": eventName
}
return this.http.put(ZoweZLUX.uriBroker.pluginConfigUri(this.plugin, 'requests/app', 'parameters'), requestBody);
}
Expand Down