Skip to content

Commit

Permalink
App2app to open files and folders. Removed lsp websocket for now. Rem…
Browse files Browse the repository at this point in the history
…oved broken font ref

Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Mar 11, 2019
1 parent e0222b7 commit ed6d14e
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 32 deletions.
91 changes: 90 additions & 1 deletion webClient/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*/
import { Component, Inject } from '@angular/core';
import { Angular2InjectionTokens } from 'pluginlib/inject-resources';
import { EditorControlService } from './shared/editor-control/editor-control.service';
import { HttpService } from './shared/http/http.service';
import { DataAdapterService } from './shared/http/http.data.adapter.service';
import { UtilsService } from './shared/utils.service';

@Component({
selector: 'app-root',
Expand All @@ -19,9 +23,94 @@ import { Angular2InjectionTokens } from 'pluginlib/inject-resources';
export class AppComponent {
title = 'app';

constructor(@Inject(Angular2InjectionTokens.LOGGER) private log: ZLUX.ComponentLogger) {
constructor(@Inject(Angular2InjectionTokens.LOGGER) private log: ZLUX.ComponentLogger,
@Inject(Angular2InjectionTokens.LAUNCH_METADATA) private launchMetadata: any,
private dataAdapter: DataAdapterService,
private httpService: HttpService,
private utils: UtilsService,
private editorControl: EditorControlService) {
this.log.debug(`Monaco object=`,(<any>window).monaco);
}

ngOnInit() {
if (this.launchMetadata && this.launchMetadata.data && this.launchMetadata.data.type) {
this.handleLaunchOrMessageObject(this.launchMetadata.data);
}
}

handleLaunchOrMessageObject(data: any) {
switch (data.type) {
case 'openFile':
//TODO should this or must this also load the directory at the time that the file is
let lastSlash = data.name.lastIndexOf("/");
let firstSlash = data.name.indexOf("/");
if (lastSlash == data.name.length-1) {
this.log.warn(`Ignoring opening invalid file or dataset name=${data.name}`);
return;
}
let parenIsLast = data.name.lastIndexOf(")") == data.name.length-1;
let openParen = data.name.indexOf("(");
let hasSlash = lastSlash != -1;
let isDataset = false;
if (hasSlash && parenIsLast && openParen != -1 && firstSlash > openParen) {
isDataset = true;
}
let nodeData;
if (!isDataset) {
let uri = ZoweZLUX.uriBroker.unixFileUri('contents', data.name.substring(0,lastSlash));
this.log.info(`I will be executing uri=${uri}, and looking for filename=${data.name.substring(lastSlash+1)}`);
this.httpService.get(uri)
.subscribe((response: any) => {
let nodes = this.dataAdapter.convertDirectoryList(response);
this.editorControl.setProjectNode(nodes);
let fileName = data.name.substring(lastSlash+1);
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].fileName == fileName) {
this.editorControl.openFile('', nodes[i]).subscribe(x => {
this.log.debug(`file loaded through app2app.`);
});
}
}
}, e => {
let error = e.json().error;
// this.snackBarService.open(`Directory ${dirName} does not exist!`, 'Close', { duration: 2000, panelClass: 'center' });
});
}
break;
case 'openDir':
this.editorControl.loadDirectory(data.name);
break;
case 'openDSList':
this.editorControl.loadDirectory(data.name);
break;
default:
this.log.warn(`Unknown command (${data.type}) given in launch metadata.`);
}
}


/* I expect a JSON here*/
zluxOnMessage(eventContext: any): Promise<any> {
return new Promise((resolve,reject)=> {
if (eventContext != null && eventContext.data != null && eventContext.data.type != null) {
resolve(this.handleLaunchOrMessageObject(eventContext.data));
} else {
let msg = 'Event context missing or malformed';
this.log.warn('onMessage '+msg);
return reject(msg);
}
});
}


provideZLUXDispatcherCallbacks(): ZLUX.ApplicationCallbacks {
return {
onMessage: (eventContext: any): Promise<any> => {
return this.zluxOnMessage(eventContext);
}
}
}

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<p class="welcome">Welcome to the Zowe Editor!</p>
<p>Please open a file from
<span class="high-light">File Explorer</span> to start your journey!
<!--<br/> Save All Files [Ctrl + S]-->
</p>
<p></p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class CodeEditorComponent implements OnInit {
lightbulb: {
enabled: true
},
theme: 'vs-dark',
fontFamily: 'monaco'
theme: 'vs-dark'
};

public editorFile: { context: ProjectContext, reload: boolean, line?: number };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class MonacoComponent implements OnInit, OnChanges {
onMonacoInit(editor) {
this.editorControl.editor.next(editor);
this.keyBinds(editor);
/* disable for now...
this.editorControl.connToLS.subscribe((lang) => {
this.connectToLanguageServer(lang);
});
Expand All @@ -61,6 +62,7 @@ export class MonacoComponent implements OnInit, OnChanges {
});
this.connectToLanguageServer();
*/
}

keyBinds(editor: any) {
Expand Down
64 changes: 37 additions & 27 deletions webClient/src/app/editor/project-tree/project-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,46 @@ export class ProjectTreeComponent implements OnInit {
});

this.editorControl.openDirectory.subscribe(dirName => {
this.log.debug(`Open Dir=${dirName}`);
if (dirName != null && dirName !== '') {
if (dirName[0] == '/') {
// start get project structure
dirName = ['/', '\\'].indexOf(dirName.substring(0, 1)) > -1 ? dirName.substring(1) : dirName;
let requestUrl = ZoweZLUX.uriBroker.unixFileUri('contents', dirName);
this.httpService.get(requestUrl)
.subscribe((response: any) => {
// TODO: nodes should check project context once the component is loaded.
this.nodes = this.dataAdapter.convertDirectoryList(response);
this.editorControl.setProjectNode(this.nodes);
this.editorControl.initProjectContext(this.utils.getFolderName(dirName), this.nodes);
}, e => {
this.loadDirectoryIntoTree(dirName);
});
}

public loadDirectoryIntoTree(dirName:string) {
this.log.debug(`Open Dir=${dirName}`);
if (dirName != null && dirName !== '') {
if (dirName[0] == '/') {
// start get project structure
dirName = ['/', '\\'].indexOf(dirName.substring(0, 1)) > -1 ? dirName.substring(1) : dirName;
let requestUrl = ZoweZLUX.uriBroker.unixFileUri('contents', dirName);
this.httpService.get(requestUrl)
.subscribe((response: any) => {
// TODO: nodes should check project context once the component is loaded.
this.nodes = this.dataAdapter.convertDirectoryList(response);
this.editorControl.setProjectNode(this.nodes);
this.editorControl.initProjectContext(this.utils.getFolderName(dirName), this.nodes);
}, e => {
try {
let error = e.json().error;
this.snackBarService.open(`Directory ${dirName} does not exist!`, 'Close', { duration: 2000, panelClass: 'center' });
});
} else {
// dataset
let requestUrl = ZoweZLUX.uriBroker.datasetMetadataUri(dirName, 'true');
this.httpService.get(requestUrl)
.subscribe((response: any) => {
this.nodes = this.dataAdapter.convertDatasetList(response);
this.editorControl.setProjectNode(this.nodes);
this.editorControl.initProjectContext(dirName, this.nodes);
}, e => {
// TODO
});
}
} catch (err) {
this.snackBarService.open(`${dirName} is not a directory.`, 'Close', { duration: 2000, panelClass: 'center' });
}
});
} else {
// dataset
let requestUrl = ZoweZLUX.uriBroker.datasetMetadataUri(dirName, 'true');
this.httpService.get(requestUrl)
.subscribe((response: any) => {
this.nodes = this.dataAdapter.convertDatasetList(response);
this.editorControl.setProjectNode(this.nodes);
this.editorControl.initProjectContext(dirName, this.nodes);
}, e => {
// TODO
});
}
});
}
}

ngOnInit() {
}

Expand Down Expand Up @@ -179,6 +188,7 @@ export class ProjectTreeComponent implements OnInit {
if (!$event.node.data.children && !$event.node.data.hasChildren) {
const nodeData: ProjectStructure = $event.node.data;
this.editorControl.openFile('', nodeData).subscribe(x => {
this.log.debug(`NodeData=`,nodeData);
this.log.debug(`file loaded through project explorer.`);
});
// this.editorControl.openFileEmitter.emit(nodeData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export let EditorServiceInstance: BehaviorSubject<any> = new BehaviorSubject(und
* @export
* @class EditorControlService
*/
@Injectable()
@Injectable({
providedIn: 'root',
})
export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuffer, ZLUX.IEditorSyntaxHighlighting {
public createFileEmitter: EventEmitter<string> = new EventEmitter();
public openProject: EventEmitter<string> = new EventEmitter();
Expand Down Expand Up @@ -635,6 +637,11 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
this.openFileEmitter.emit(targetBuffer);
return resultOpenObs;
}

loadDirectory(path: string) {
this.log.debug('Loading directory=',path);
this.openDirectory.next(path);
}
/**
* Save a buffer into a file.
*
Expand Down

0 comments on commit ed6d14e

Please sign in to comment.