Skip to content

Commit

Permalink
updated tree with do examples (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Gordon <[email protected]>
  • Loading branch information
DumpySquare and DumpySquare authored Jun 22, 2020
1 parent ef6e603 commit 0231e8b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 104 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
"when": "f5.as3Installed"
},
{
"id": "tsExamples",
"name": "TS Examples",
"id": "decExamples",
"name": "Declaration Examples",
"when": "f5.tsInstalled"
}
]
Expand Down Expand Up @@ -380,11 +380,6 @@
"title": "Post Declaration",
"category": "F5-TS"
},
{
"command": "f5-ts.enableTsExamples",
"title": "Populate Examples Tree",
"category": "F5-TS"
},
{
"command": "writeMemento",
"title": "writeMemento",
Expand All @@ -395,11 +390,6 @@
"title": "readMemento",
"category": "F5"
},
{
"command": "f5-ts.enableTsExamples",
"title": "Example TS Declarations",
"category": "F5"
},
{
"command": "f5.editHost",
"title": "Edit Host",
Expand Down Expand Up @@ -451,11 +441,6 @@
"command": "f5-fast.refreshTemplates",
"when": "view == fastView",
"group": "navigation"
},
{
"command": "f5-ts.enableTsExamples",
"when": "view == tsExamples",
"group": "navigation"
}
],
"commandPalette": [
Expand Down Expand Up @@ -567,10 +552,6 @@
"command": "f5-ts.getDec",
"when": "f5.tsInstalled"
},
{
"command": "f5-ts.enableTsExamples",
"when": "none"
},
{
"command": "f5-ts.postDec",
"when": "f5.tsInstalled"
Expand Down
27 changes: 11 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,21 +950,6 @@ export function activate(context: vscode.ExtensionContext) {
*
*/

const tsDecTree = new ExampleDecsProvider('testDataInput');
context.subscriptions.push(vscode.commands.registerCommand('f5-ts.enableTsExamples', () => {
// chuckJoke();
// setting up example TS dec tree
vscode.window.registerTreeDataProvider('tsExamples', tsDecTree);
// no need for refresh since we get a fresh tree every "enable" or window/workspace reload
vscode.commands.registerCommand('refreshTsExamleTree', () => tsDecTree.refresh()); // never wired up to get called...
}));

context.subscriptions.push(vscode.commands.registerCommand('f5-ts.disableTsExamples', () => {
vscode.window.showInformationMessage(`Wire up clearing ts example view!`);
// I was thinking the following dispose would dispose of the registration and clear the tree, but that doesn't work
// I figure just leave it for now, at least it only loads when user "enables" it,
tsDecTree.dispose();
}));



Expand Down Expand Up @@ -1040,7 +1025,13 @@ export function activate(context: vscode.ExtensionContext) {
}
}));

context.subscriptions.push(vscode.commands.registerCommand('f5-ts.getGitHubExampleTs', async (decUrl) => {
context.subscriptions.push(vscode.commands.registerCommand('f5.getGitHubExample', async (decUrl) => {

if(decUrl === 'tempAS3') {
// remove once as3 examples are available
return vscode.env.openExternal(vscode.Uri.parse('https://github.com/F5Networks/f5-appsvcs-extension/issues/280'));
}

decUrl = vscode.Uri.parse(decUrl);
const decCall = await callHTTPS({
method: 'GET',
Expand Down Expand Up @@ -1186,6 +1177,10 @@ export function activate(context: vscode.ExtensionContext) {
*/


// register example delarations tree
vscode.window.registerTreeDataProvider('decExamples', new ExampleDecsProvider());


context.subscriptions.push(vscode.commands.registerCommand('writeMemento', () => {
// console.log('placeholder for testing commands');

Expand Down
4 changes: 1 addition & 3 deletions src/treeViewsProviders/as3TenantTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ export class AS3TenantTreeProvider implements vscode.TreeDataProvider<AS3TenantI

return Promise.resolve(treeItems);
}


}

function isObject(obj: object) {
return obj === Object(obj);
}
}

export class AS3TenantItem extends vscode.TreeItem {
constructor(
Expand Down
137 changes: 74 additions & 63 deletions src/treeViewsProviders/githubDecExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ExampleDecsProvider implements vscode.TreeDataProvider<ExampleDec>
private _onDidChangeTreeData: vscode.EventEmitter<ExampleDec | undefined> = new vscode.EventEmitter<ExampleDec | undefined>();
readonly onDidChangeTreeData: vscode.Event<ExampleDec | undefined> = this._onDidChangeTreeData.event;

constructor(private inCommingData: string) {
constructor() {
}

refresh(): void {
Expand All @@ -22,57 +22,84 @@ export class ExampleDecsProvider implements vscode.TreeDataProvider<ExampleDec>
}

async getChildren(element?: ExampleDec): Promise<ExampleDec[]> {

const decCall = await callHTTPS({
method: 'GET',
host: 'api.github.com',
path: '/repos/F5Networks/f5-telemetry-streaming/contents/examples/declarations',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'nodejs native HTTPS'
}
}).then( resp => {
return resp;
});

console.log(`decCall: ${JSON.stringify(decCall)}`);

const treeItems = decCall.body.map((item:any): ExampleDec => {
return (new ExampleDec(
item.name,
vscode.TreeItemCollapsibleState.None,
{
command: 'f5-ts.getGitHubExampleTs',
title: 'hostTitle',
arguments: [item.download_url]
}));
});

// if ( bigipHosts === undefined) {
// throw new Error('No configured hosts - from hostTreeProvider');
// }

// // takes individual host item and creates a tree item
// const treeHosts = (name: string): exampleTsDec => {
// const treeItem = new exampleTsDec(name, vscode.TreeItemCollapsibleState.None, {
// command: 'f5.connectDevice',
// title: 'hostTitle',
// arguments: [name]
// });
// console.log(`treeItem: ${JSON.stringify(treeItem)}`);
// return treeItem;
// }
// const treeItems = decCall.map(host => treeHosts(host));

console.log(`treeItems full: ${JSON.stringify(treeItems)}`);

var treeItems = [];
if(element) {
// get example dec list for atc service
if(element.label === 'AS3 Examples - Coming soon!') {
// const examples = await getAS3examples();

// treeItems = examples.body.map((item: any) => {
// return new ExampleDec(item.name, vscode.TreeItemCollapsibleState.None,
// {command: 'f5.getGitHubExample', title: '', arguments: [item.download_url]});
// });

} else if (element.label === 'DO Examples') {
const examples = await getDOexamples();

treeItems = examples.body.map((item: any) => {
return new ExampleDec(item.name, vscode.TreeItemCollapsibleState.None,
{command: 'f5.getGitHubExample', title: '', arguments: [item.download_url]});
});

} else if (element.label === 'TS Examples') {
const examples = await getTSexamples();

treeItems = examples.body.map((item: any) => {
return new ExampleDec(item.name, vscode.TreeItemCollapsibleState.None,
{command: 'f5.getGitHubExample', title: '', arguments: [item.download_url]});
});
}

} else {
//top level items
treeItems.push(new ExampleDec('AS3 Examples - Coming soon!', vscode.TreeItemCollapsibleState.None,
{command: 'f5.getGitHubExample', title: '', arguments: ['tempAS3']}));

treeItems.push(new ExampleDec('DO Examples', vscode.TreeItemCollapsibleState.Collapsed));

treeItems.push(new ExampleDec('TS Examples', vscode.TreeItemCollapsibleState.Collapsed));
}
return Promise.resolve(treeItems);
}
}

async function getAS3examples(){
return await callHTTPS({
method: 'GET',
host: 'api.github.com',
path: '/repos/F5Networks/f5-telemetry-streaming/contents/examples/declarations',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'F5 VScode FAST extension'
}
});
}



}

async function getDOexamples(){
return await callHTTPS({
method: 'GET',
host: 'api.github.com',
path: '/repos/F5Networks/f5-declarative-onboarding/contents/examples',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'F5 VScode FAST extension'
}
});
}


async function getTSexamples(){
return await callHTTPS({
method: 'GET',
host: 'api.github.com',
path: '/repos/F5Networks/f5-telemetry-streaming/contents/examples/declarations',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'F5 VScode FAST extension'
}
});
}

export class ExampleDec extends vscode.TreeItem {
Expand All @@ -84,20 +111,4 @@ export class ExampleDec extends vscode.TreeItem {
) {
super(label, collapsibleState);
}

get tooltip(): string {
return `Connect`;
}

// get description(): string {
// return 'descLoc';
// }

// iconPath = {
// light: path.join(__filename, '..', '..', 'resources', 'light', 'dependency.svg'),
// dark: path.join(__filename, '..', '..', 'resources', 'dark', 'dependency.svg')
// };

// contextValue = 'dependency';

}

0 comments on commit 0231e8b

Please sign in to comment.