|
1 | 1 | import * as vscode from 'vscode'; |
2 | 2 | import * as fs from 'fs'; |
3 | 3 | 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'; |
7 | 10 |
|
8 | 11 | export class IoTUI implements IContexUI { |
9 | 12 | private _outputChannel:vscode.OutputChannel; |
@@ -54,4 +57,60 @@ export class IoTUI implements IContexUI { |
54 | 57 | } |
55 | 58 | } |
56 | 59 | } |
| 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 | + } |
57 | 116 | } |
0 commit comments