Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
CHE-11443 and implement the containers plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>

code cleanup

Signed-off-by: root <root@workspaceqi0ng17xncf6eimt.ws-6d45d78c5b-g44fb>

code cleanup

Signed-off-by: root <root@workspaceqi0ng17xncf6eimt.ws-6d45d78c5b-g44fb>
  • Loading branch information
olexii4 committed Jan 9, 2019
1 parent c46138c commit 4abc147
Show file tree
Hide file tree
Showing 10 changed files with 1,594 additions and 2 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"publish:next": "lerna run publish:next"
},
"workspaces": [
"extensions/*",
"plugins/*"
"extensions/*"
]
}
3 changes: 3 additions & 0 deletions plugins/containers-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
node_modules/
*.theia
11 changes: 11 additions & 0 deletions plugins/containers-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# containers-plugin

Containers-tree plugin for Theia.

This plugin provides:

- List of containers with their status, where each container provides:

- List of servers (resource locator) if there is any;

- Ability to open a terminal within a selected container;
54 changes: 54 additions & 0 deletions plugins/containers-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "containers-plugin",
"publisher": "theia",
"keywords": [
"theia-plugin"
],
"version": "0.0.1",
"license": "EPL-2.0",
"files": [
"src"
],
"contributes": {
"viewsContainers": {
"right": [
{
"id": "containers",
"title": "Containers"
}
]
},
"views": {
"containers": [
{
"id": "containers",
"name": "Containers"
}
]
}
},
"devDependencies": {
"@theia/plugin": "next",
"@theia/plugin-packager": "latest",
"@eclipse-che/plugin": "latest",
"rimraf": "2.6.2",
"typescript-formatter": "7.2.2",
"typescript": "2.9.2"
},
"dependencies": {
},
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib",
"format-code": "tsfmt -r",
"watch": "tsc -watch",
"compile": "tsc",
"build": "yarn run format-code && yarn run compile && theia:plugin pack"
},
"engines": {
"theiaPlugin": "next"
},
"theiaPlugin": {
"backend": "lib/containers-plugin.js"
}
}
18 changes: 18 additions & 0 deletions plugins/containers-plugin/src/containers-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*********************************************************************
* Copyright (c) 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { ContainersTree } from './containers-tree';

export function start() {
new ContainersTree();
}

export function stop() {
}
116 changes: 116 additions & 0 deletions plugins/containers-plugin/src/containers-tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*********************************************************************
* Copyright (c) 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as theia from '@theia/plugin';
import { MachinesService } from "./machine-service";

const machines: Map<string, string[]> = new Map<string, string[]>();

export class ContainersTree {

constructor() {
const treeDataProvider = new TreeDataDataProvider();

theia.window.createTreeView('containers', { treeDataProvider });

this.initTreeData().then(() => {
treeDataProvider.sendDataChanged();
});
}

async initTreeData(): Promise<void> {
const machinesService = new MachinesService();

await machinesService.updateMachines();

machinesService.machines.forEach(machine => {
const machineName = machine.machineName;
const machineProp: Array<string> = [];

if (machine.status) {
machineProp.push(machine.status);
}

const commands = ['terminal'];
commands.forEach((command: string) => {
machineProp.push(`${command}__${machineName}`);
});

const servers = machine.servers;
if (servers) {
Object.keys(servers).forEach((serverName: string) => {
const server = servers[serverName];
if (server && server.url) {
machineProp.push(` [${serverName}](${server.url})`);
} else {
machineProp.push(serverName);
}
});
}

machines.set(machineName, machineProp);
});
}

}

export class TreeDataDataProvider implements theia.TreeDataProvider<string> {

private onDidChangeTreeDataEmitter: theia.EventEmitter<undefined> = new theia.EventEmitter<undefined>();
readonly onDidChangeTreeData: theia.Event<undefined> = this.onDidChangeTreeDataEmitter.event;

public sendDataChanged() {
this.onDidChangeTreeDataEmitter.fire();
}

/**
* Get representation of the `element`
*
* @param element The element for which [TreeItem](#TreeItem) representation is asked for.
* @return [TreeItem](#TreeItem) representation of the element
*/
getTreeItem(element: string): theia.TreeItem | PromiseLike<theia.TreeItem> {
const treeItem: theia.TreeItem = {
label: element,
tooltip: element
};
if (machines.has(element)) {
treeItem.iconPath = 'fa-circle medium-green';
treeItem.collapsibleState = theia.TreeItemCollapsibleState.Expanded;
} else {
const [label, machineName] = element.split('__');
if (!machineName || !machines.has(machineName)) {
return treeItem;
}
treeItem.label = label;
treeItem.command = { id: `${label}-for-${machineName}-container:new` };
if (label === 'terminal') {
treeItem.iconPath = 'fa-terminal';
}
}
return treeItem;
}

async getChildren(element?: string): Promise<string[]> {
if (element && machines.has(element)) {
return machines.get(element)!;
} else {
return await this.getRootChildren();
}
}

async getRootChildren(): Promise<string[]> {
const arr: string[] = [];
machines.forEach((value, key) => {
arr.push(key);
});
return arr;
}
}
54 changes: 54 additions & 0 deletions plugins/containers-plugin/src/machine-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*********************************************************************
* Copyright (c) 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as che from '@eclipse-che/plugin';

export interface IWorkspaceMachine {
machineName: string;
servers?: {
[serverRef: string]: {
url?: string;
port?: string;
}
};
status?: 'STARTING' | 'RUNNING' | 'STOPPED' | 'FAILED';
}

export class MachinesService {

private runtimeMachines: Array<IWorkspaceMachine> = [];

constructor() {
}

async updateMachines(): Promise<void> {
const workspace = await che.workspace.getCurrentWorkspace();
if (!workspace) {
return Promise.reject('Failed to get workspace configuration');
}

const workspaceMachines = workspace!.runtime
&& workspace!.runtime!.machines
|| workspace!.config!.environments![workspace.config!.defaultEnv!].machines
|| {};

this.runtimeMachines.length = 0;

Object.keys(workspaceMachines).forEach((machineName: string) => {
const machine = <IWorkspaceMachine>workspaceMachines[machineName];
machine.machineName = machineName;
this.runtimeMachines.push(machine);
});
}

get machines(): Array<IWorkspaceMachine> {
return this.runtimeMachines;
}
}
23 changes: 23 additions & 0 deletions plugins/containers-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
"downlevelIteration": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"lib": [
"es6",
"webworker"
],
"sourceMap": true,
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
19 changes: 19 additions & 0 deletions plugins/containers-plugin/tsfmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"baseIndentSize": 0,
"newLineCharacter": "\n",
"indentSize": 4,
"tabSize": 4,
"indentStyle": 4,
"convertTabsToSpaces": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
}

Loading

0 comments on commit 4abc147

Please sign in to comment.