Skip to content

Commit 9b3262b

Browse files
committed
Code review
1 parent 276ebd0 commit 9b3262b

File tree

4 files changed

+78
-47
lines changed

4 files changed

+78
-47
lines changed

src/UI/IContexUI.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as vscode from 'vscode';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import {IotResult,StatusResult} from '../IotResult';
4+
import { IotResult,StatusResult } from '../IotResult';
5+
import { IotDevice } from '../IotDevice';
6+
import { IotTemplate } from '../Templates/IotTemplate';
57

68
export interface IContexUI {
79
Output(value:string|IotResult): void;
810
ShowBackgroundNotification(text:string, tooltip?:string | vscode.MarkdownString| undefined):void;
911
HideBackgroundNotification():void;
1012
ShowNotification(value:IotResult):void;
13+
ShowDeviceDialog(devices:Array<IotDevice>,title?:string):Promise<IotDevice | undefined>;
14+
ShowTemplateDialog(templates:Array<IotTemplate>,title?:string):Promise<IotTemplate | undefined>;
1115
}

src/UI/IoTUI.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import * as vscode from 'vscode';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import {StatusBarBackground} from './StatusBarBackground';
5-
import {IContexUI} from './IContexUI';
6-
import {IotResult,StatusResult} from '../IotResult';
4+
import { StatusBarBackground } from './StatusBarBackground';
5+
import { IContexUI } from './IContexUI';
6+
import { IotResult,StatusResult } from '../IotResult';
7+
import { IotDevice } from '../IotDevice';
8+
import { IotTemplate } from '../Templates/IotTemplate';
9+
import { ItemQuickPick } from '../Helper/actionHelper';
710

811
export class IoTUI implements IContexUI {
912
private _outputChannel:vscode.OutputChannel;
@@ -54,4 +57,60 @@ export class IoTUI implements IContexUI {
5457
}
5558
}
5659
}
60+
61+
public async ShowDeviceDialog(devices:Array<IotDevice>,title = 'Choose a device'):Promise<IotDevice | undefined> {
62+
//for next version
63+
/*
64+
//Get all architectures
65+
let architectures:string[]=[];
66+
devices.forEach((device) => {
67+
if(device.Information.Architecture)
68+
architectures.push(device.Information.Architecture);
69+
});
70+
//removing duplicate elements
71+
architectures=Array.from(new Set(architectures));
72+
//Sort
73+
architectures=architectures.sort((a, b)=>{
74+
if(a < b) { return -1; };
75+
if(a > b) { return 1; };
76+
return 0;
77+
});
78+
//create a list
79+
let itemDevices:Array<ItemQuickPick>=[];
80+
architectures.forEach((architecture) => {
81+
const devicesA=devices.filter((e:IotDevice) => e.Information.Architecture==architecture);
82+
//make a separator
83+
84+
//add
85+
86+
});
87+
*/
88+
//create a list
89+
let itemDevices:Array<ItemQuickPick>=[];
90+
devices.forEach((device) => {
91+
const label=`${device.label}`;
92+
const description=`${device.Information.Architecture}`;
93+
const detail=`$(circuit-board) ${device.Information.BoardName} $(terminal-linux) ${device.Information.OsDescription} ${device.Information.OsKernel} $(account) ${device.Account.UserName}`;
94+
const item = new ItemQuickPick(label,description,device,detail);
95+
itemDevices.push(item);
96+
});
97+
//Select
98+
const SELECTED_ITEM = await vscode.window.showQuickPick(itemDevices,{title: title,placeHolder:`Developer board`});
99+
if(SELECTED_ITEM)
100+
return Promise.resolve(<IotDevice>SELECTED_ITEM.value);
101+
else Promise.resolve(undefined);
102+
}
103+
104+
public async ShowTemplateDialog(templates:Array<IotTemplate>,title = 'Choose a template'):Promise<IotTemplate | undefined> {
105+
let itemTemplates:Array<ItemQuickPick>=[];
106+
templates.forEach((template) => {
107+
const item = new ItemQuickPick(<string>template.Attributes.Label,
108+
`Language: ${template.Attributes.Language}`,template,`${template.Attributes.Detail}`);
109+
itemTemplates.push(item);
110+
});
111+
const SELECTED_ITEM = await vscode.window.showQuickPick(itemTemplates,{title: title,placeHolder:`Template`});
112+
if(SELECTED_ITEM)
113+
return Promise.resolve(<IotTemplate>SELECTED_ITEM.value);
114+
else Promise.resolve(undefined);
115+
}
57116
}

src/actionsLaunch/addLaunch.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,8 @@ export async function addLaunch(treeData:TreeDataLaunchsProvider,devices:Array<I
3535
return;
3636
}
3737
//Select Device
38-
let itemDevices:Array<ItemQuickPick>=[];
39-
devices.forEach((device) => {
40-
const label=`${device.label}`;
41-
const description=`${device.Information.Architecture}`;
42-
const detail=`$(circuit-board) ${device.Information.BoardName} $(terminal-linux) ${device.Information.OsDescription} ${device.Information.OsKernel} $(account) ${device.Account.UserName}`;
43-
const item = new ItemQuickPick(label,description,device,detail);
44-
itemDevices.push(item);
45-
});
46-
let SELECTED_ITEM = await vscode.window.showQuickPick(itemDevices,{title: 'Choose a device (1/4)',placeHolder:`Developer board`});
47-
if(!SELECTED_ITEM) return;
48-
const selectDevice= <IotDevice>SELECTED_ITEM.value;
38+
const selectDevice = await contextUI.ShowDeviceDialog(devices,'Choose a device (1/4)');
39+
if(!selectDevice) return;
4940
//Select template
5041
//get id template
5142
let idTemplate=new IotTemplateAttribute().ForceGetID(workspaceDirectory+"\\template.fastiot.yaml");
@@ -65,7 +56,7 @@ export async function addLaunch(treeData:TreeDataLaunchsProvider,devices:Array<I
6556
items.push(item);
6657
item = new ItemQuickPick("2. Choose another template from the collection","",undefined);
6758
items.push(item);
68-
SELECTED_ITEM = await vscode.window.showQuickPick(items,{title: 'Select an action (2/4)'});
59+
let SELECTED_ITEM = await vscode.window.showQuickPick(items,{title: 'Select an action (2/4)'});
6960
if(!SELECTED_ITEM) return;
7061
selectTemplate=SELECTED_ITEM.value;
7162
}
@@ -77,15 +68,8 @@ export async function addLaunch(treeData:TreeDataLaunchsProvider,devices:Array<I
7768
contextUI.ShowNotification(result);
7869
return;
7970
}
80-
let itemTemplates:Array<ItemQuickPick>=[];
81-
listTemplates.forEach((template) => {
82-
const item = new ItemQuickPick(<string>template.Attributes.Label,
83-
`Language: ${template.Attributes.Language}`,template,`${template.Attributes.Detail}`);
84-
itemTemplates.push(item);
85-
});
86-
SELECTED_ITEM = await vscode.window.showQuickPick(itemTemplates,{title: 'Choose a template (3/4)',placeHolder:`Template`});
87-
if(!SELECTED_ITEM) return;
88-
selectTemplate= <IotTemplate>SELECTED_ITEM.value;
71+
selectTemplate = await contextUI.ShowTemplateDialog(listTemplates,'Choose a template (3/4)');
72+
if(!selectTemplate) return;
8973
}
9074
//Find projects
9175
const projects=selectTemplate.FindProjects(workspaceDirectory);
@@ -104,7 +88,7 @@ export async function addLaunch(treeData:TreeDataLaunchsProvider,devices:Array<I
10488
const item = new ItemQuickPick(label,description,fileName);
10589
itemProjects.push(item);
10690
});
107-
SELECTED_ITEM = await vscode.window.showQuickPick(itemProjects,{title: 'Choose a project (4/4)',placeHolder:`Project`});
91+
let SELECTED_ITEM = await vscode.window.showQuickPick(itemProjects,{title: 'Choose a project (4/4)',placeHolder:`Project`});
10892
if(!SELECTED_ITEM) return;
10993
selectProject=SELECTED_ITEM.value;
11094
//Preparing values

src/actionsTemplates/createProject.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,17 @@ export async function createProject(config:IotConfiguration,devices:Array<IotDev
3030
return;
3131
}
3232
//Select Device
33-
let itemDevices:Array<ItemQuickPick>=[];
34-
devices.forEach((device) => {
35-
const label=`${device.label}`;
36-
const description=`${device.Information.Architecture}`;
37-
const detail=`$(circuit-board) ${device.Information.BoardName} $(terminal-linux) ${device.Information.OsDescription} ${device.Information.OsKernel} $(account) ${device.Account.UserName}`;
38-
const item = new ItemQuickPick(label,description,device,detail);
39-
itemDevices.push(item);
40-
});
41-
let SELECTED_ITEM = await vscode.window.showQuickPick(itemDevices,{title: 'Choose a device (1/4)',placeHolder:`Developer board`});
42-
if(!SELECTED_ITEM) return;
43-
const selectDevice= <IotDevice>SELECTED_ITEM.value;
33+
const selectDevice = await contextUI.ShowDeviceDialog(devices,'Choose a device (1/4)');
34+
if(!selectDevice) return;
4435
//Select template
4536
const listTemplates= config.Templates.Select(selectDevice.Information.Architecture);
4637
if(listTemplates.length==0) {
4738
result=new IotResult(StatusResult.No,`No templates for device ${selectDevice.label} ${selectDevice.Information.Architecture}`);
4839
contextUI.ShowNotification(result);
4940
return;
5041
}
51-
let itemTemplates:Array<ItemQuickPick>=[];
52-
listTemplates.forEach((template) => {
53-
const item = new ItemQuickPick(<string>template.Attributes.Label,
54-
`Language: ${template.Attributes.Language}`,template,`${template.Attributes.Detail}`);
55-
itemTemplates.push(item);
56-
});
57-
SELECTED_ITEM = await vscode.window.showQuickPick(itemTemplates,{title: 'Choose a template (2/5)',placeHolder:`Template`});
58-
if(!SELECTED_ITEM) return;
59-
const selectTemplate= <IotTemplate>SELECTED_ITEM.value;
42+
const selectTemplate = await contextUI.ShowTemplateDialog(listTemplates,'Choose a template (2/5)');
43+
if(!selectTemplate) return;
6044
//Select name project
6145
let nameProject = await vscode.window.showInputBox({
6246
prompt: 'Enter the name of your application',
@@ -117,7 +101,7 @@ export async function createProject(config:IotConfiguration,devices:Array<IotDev
117101
const item = new ItemQuickPick(value[1],"",value[0]);
118102
itemTarget.push(item);
119103
});
120-
SELECTED_ITEM = await vscode.window.showQuickPick(itemTarget,{title: 'Choose a .NET framework',placeHolder:`.NET framework`});
104+
let SELECTED_ITEM = await vscode.window.showQuickPick(itemTarget,{title: 'Choose a .NET framework',placeHolder:`.NET framework`});
121105
if(!SELECTED_ITEM) return;
122106
//
123107
values.set("%{project.dotnet.targetframework}",<string>SELECTED_ITEM.value);

0 commit comments

Comments
 (0)