Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Next v1 compatibility #180

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/commands/deleteSessionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ export function getDeleteSessionCommand(tree: CICSTree, treeview: TreeView<any>)
return;
}
try {
const profilesCache = ProfileManagement.getProfilesCache();
const currentProfile: IProfAttrs = profilesCache.getProfileFromConfig(allSelectedNodes[allSelectedNodes.length-1].label);
if (currentProfile) {
//@ts-ignore
const filePath = currentProfile.profLoc.osLoc[0];
await openConfigFile(filePath);
const configInstance = await ProfileManagement.getConfigInstance();
if (configInstance.usingTeamConfig) {
const profilesCache = ProfileManagement.getProfilesCache();
const currentProfile: IProfAttrs = profilesCache.getProfileFromConfig(allSelectedNodes[allSelectedNodes.length-1].label);
if (currentProfile) {
const filePath = currentProfile.profLoc.osLoc ? currentProfile.profLoc.osLoc[0] : "";
await openConfigFile(filePath);
}
} else {
const selectedNodes = treeview.selection.filter((selectedNode) => selectedNode !== node);
await tree.deleteSession(selectedNodes);
}
// OLD METHOD:
// const selectedNodes = treeview.selection.filter((selectedNode) => selectedNode !== node);
// await tree.deleteSession(selectedNodes);
} catch (error) {
window.showErrorMessage(`Something went wrong when deleting the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(/(\\n\t|\\n|\\t)/gm," ")}`);
}
Expand Down
38 changes: 21 additions & 17 deletions src/commands/updateSessionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,29 @@ export function getUpdateSessionCommand(tree: CICSTree, treeview: TreeView<any>)
window.showErrorMessage("No profile selected to update");
return;
}
try {
const profilesCache = ProfileManagement.getProfilesCache();
const currentProfile: IProfAttrs = profilesCache.getProfileFromConfig(allSelectedNodes[allSelectedNodes.length-1].label);
if (currentProfile) {
//@ts-ignore
const filePath = currentProfile.profLoc.osLoc[0];
await openConfigFile(filePath);
const configInstance = await ProfileManagement.getConfigInstance();
if (configInstance.usingTeamConfig) {
try {
const profilesCache = ProfileManagement.getProfilesCache();
const currentProfile: IProfAttrs = profilesCache.getProfileFromConfig(allSelectedNodes[allSelectedNodes.length-1].label);
if (currentProfile) {
const filePath = currentProfile.profLoc.osLoc ? currentProfile.profLoc.osLoc[0] : "";
await openConfigFile(filePath);
}
} catch (error) {
window.showErrorMessage(`Something went wrong when updating the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(/(\\n\t|\\n|\\t)/gm," ")}`);
return;
}
} else {
for (const sessionTree of allSelectedNodes) {
try {
await tree.updateSession(sessionTree);
} catch (error) {
window.showErrorMessage(`Something went wrong when updating the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(/(\\n\t|\\n|\\t)/gm," ")}`);
return;
}
}
} catch (error) {
window.showErrorMessage(`Something went wrong when updating the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(/(\\n\t|\\n|\\t)/gm," ")}`);
}
// // Previous Method:
// for (const sessionTree of allSelectedNodes) {
// try {
// await tree.updateSession(sessionTree);
// } catch (error) {
// window.showErrorMessage(`Something went wrong when updating the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(/(\\n\t|\\n|\\t)/gm," ")}`);
// }
// }
}
);
}
25 changes: 7 additions & 18 deletions src/trees/CICSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { getResource } from "@zowe/cics-for-zowe-cli";
import { IProfileLoaded, IUpdateProfile, Session } from "@zowe/imperative";
import { Event, EventEmitter, ProgressLocation, ProviderResult, TreeDataProvider, TreeItem, WebviewPanel, window } from "vscode";
import { Event, EventEmitter, ProgressLocation, ProviderResult, RelativePattern, TreeDataProvider, TreeItem, WebviewPanel, window, workspace } from "vscode";
import { PersistentStorage } from "../utils/PersistentStorage";
import { ProfileManagement } from "../utils/profileManagement";
import { isTheia } from "../utils/workspaceUtils";
Expand Down Expand Up @@ -80,23 +80,12 @@ export class CICSTree

if (profileNameToLoad) {
if (profileNameToLoad.label.includes("\uFF0B")) {
// const configName = ProfilesCache.getConfigInstance().getTeamConfig().configName;
// let configDir = ProfilesCache.getConfigInstance().getTeamConfig().mHomeDir;
// if (workspace.workspaceFolders) {
// // Check if config file is present in the workspace
// const uri = await workspace.findFiles(
// new RelativePattern(workspace.workspaceFolders[0], configName)
// );
// if (uri.length > 0) {
// configDir = ProfilesCache.getConfigInstance().getTeamConfig().mProjectDir;
// }
// }
// const filePath = path.join(configDir, configName);
// await openConfigFile(filePath);
window.showInformationMessage("Open and edit your config file to create a new profile");
// // Old method: Create New Profile Form should appear
//this.createNewProfile();

const configInstance = await ProfileManagement.getConfigInstance();
if (configInstance.usingTeamConfig) {
window.showInformationMessage("Open and edit your config file to create a new profile");
} else {
this.createNewProfile();
}
} else {
const profileToLoad = ProfileManagement.getProfilesCache().loadNamedProfile(profileNameToLoad.label, 'cics');
const missingParamters = missingSessionParameters(profileToLoad.profile);
Expand Down
15 changes: 13 additions & 2 deletions src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
*
*/

import { IDeleteProfile, IProfileLoaded, ISaveProfile, IUpdateProfile } from "@zowe/imperative";
import { ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { IDeleteProfile, IProfileLoaded, ISaveProfile, IUpdateProfile, ProfileInfo } from "@zowe/imperative";
import { getSecurityModules, ProfilesCache, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import axios, { AxiosRequestConfig } from "axios";
import { window } from "vscode";
import { xml2json } from "xml-js";
import cicsProfileMeta from "./profileDefinition";
import * as https from "https";
import { CICSPlexTree } from "../trees/CICSPlexTree";
import { isTheia } from "./workspaceUtils";

export class ProfileManagement {
private static zoweExplorerAPI = ZoweVsCodeExtension.getZoweExplorerApi("2.0.0-next.202202221200");
Expand Down Expand Up @@ -58,6 +59,16 @@ export class ProfileManagement {
await ProfileManagement.getExplorerApis().getExplorerExtenderApi().reloadProfiles();
}

public static async getConfigInstance() : Promise<ProfileInfo> {
const mProfileInfo = new ProfileInfo("zowe", {
requireKeytar: () => getSecurityModules("keytar", isTheia())!,
});
await mProfileInfo.readProfilesFromDisk();
ProfilesCache.createConfigInstance(mProfileInfo);
const configInstance = ProfilesCache.getConfigInstance();
return configInstance;
}

public static async makeRequest(path:string, config:AxiosRequestConfig) {
const response = await axios.get(path, config);
return response;
Expand Down