-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCICSLibraryDatasets.ts
110 lines (96 loc) · 3.8 KB
/
CICSLibraryDatasets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { TreeItemCollapsibleState, TreeItem, window } from "vscode";
import { CICSRegionTree } from "../CICSRegionTree";
import { getIconFilePathFromName } from "../../utils/iconUtils";
import { getResource } from "@zowe/cics-for-zowe-sdk";
import { CICSProgramTreeItem } from "./CICSProgramTreeItem";
import { toEscapedCriteriaString } from "../../utils/filterUtils";
import { toArray } from "../../utils/commandUtils";
export class CICSLibraryDatasets extends TreeItem {
children: CICSProgramTreeItem[] = [];
dataset: any;
parentRegion: CICSRegionTree;
directParent: any;
activeFilter: string | undefined = undefined;
constructor(
dataset: any,
parentRegion: CICSRegionTree,
directParent: any,
public iconPath = getIconFilePathFromName("library-dataset"),
) {
super(`${dataset.dsname}`, TreeItemCollapsibleState.Collapsed);
this.dataset = dataset;
this.parentRegion = parentRegion;
this.directParent = directParent;
this.contextValue = `cicsdatasets.${this.activeFilter ? "filtered" : "unfiltered"}${dataset.dsname}`;
}
public setLabel(newlabel: string) {
this.label = newlabel;
}
public addProgram(program: CICSProgramTreeItem) {
this.children.push(program);
}
public async loadContents() {
const defaultCriteria = `(librarydsn='${this.dataset.dsname}')`;
let criteria;
if (this.activeFilter) {
criteria = defaultCriteria + " AND " + toEscapedCriteriaString(this.activeFilter, "PROGRAM");
} else {
criteria = defaultCriteria;
}
this.children = [];
try {
const datasetResponse = await getResource(this.parentRegion.parentSession.session, {
name: "CICSProgram",
regionName: this.parentRegion.getRegionName(),
cicsPlex: this.parentRegion.parentPlex ? this.parentRegion.parentPlex.getPlexName() : undefined,
criteria: criteria,
});
const programsArray = toArray(datasetResponse.response.records.cicsprogram);
this.label = `${this.dataset.dsname}${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[${programsArray.length}]`;
for (const program of programsArray) {
const newProgramItem = new CICSProgramTreeItem(program, this.parentRegion, this);
this.addProgram(newProgramItem);
}
} catch (error) {
if (error.mMessage!.includes("exceeded a resource limit")) {
window.showErrorMessage(`Resource Limit Exceeded - Set a program filter to narrow search`);
} else if (this.children.length === 0) {
window.showInformationMessage(`No programs found`);
this.label = `${this.dataset.dsname}${this.activeFilter ? ` (${this.activeFilter}) ` : " "}[0]`;
} else {
window.showErrorMessage(
`Something went wrong when fetching programs - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(
/(\\n\t|\\n|\\t)/gm,
" ",
)}`,
);
}
}
}
public clearFilter() {
this.activeFilter = undefined;
this.contextValue = `cicsdatasets.${this.activeFilter ? "filtered" : "unfiltered"}${this.dataset.dsname}`;
this.collapsibleState = TreeItemCollapsibleState.Expanded;
}
public setFilter(newFilter: string) {
this.activeFilter = newFilter;
this.contextValue = `cicsdatasets.${this.activeFilter ? "filtered" : "unfiltered"}${this.dataset.dsname}`;
this.collapsibleState = TreeItemCollapsibleState.Expanded;
}
public getFilter() {
return this.activeFilter;
}
public getParent() {
return this.directParent;
}
}