Skip to content

Commit

Permalink
Merge pull request #3 from mmuzikar/side-by-side
Browse files Browse the repository at this point in the history
Implemented side by side view, added logging feature
  • Loading branch information
mmuzikar authored Mar 18, 2020
2 parents 29f0380 + a875c07 commit 004b030
Show file tree
Hide file tree
Showing 42 changed files with 1,482 additions and 218 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ dist
# TernJS port file
.tern-port
ui/old/
.vscode/
.vscode/

ui/lib/*
backendprovider/.factorypath
testsuite/.factorypath
*.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum Handlers {
RUN_STEP(new RunStepHandler()),
LIST_STEPS(new ListStepsHandler()),
ADD_STEP(new AddStepHandler()),
SUGGEST(new SuggestionHandler());
SUGGEST(new SuggestionHandler()),
LOG(new LogHandler());

@Getter
Handler handler;
Expand Down
85 changes: 85 additions & 0 deletions backendprovider/src/main/java/mmuzikar/handlers/LogHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package mmuzikar.handlers;

import com.sun.net.httpserver.HttpExchange;
import gherkin.deps.com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.extern.java.Log;
import org.apache.commons.io.output.TeeOutputStream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

@Log
public class LogHandler implements Handler {

private ByteArrayOutputStream outputCopyStream;
private ByteArrayOutputStream outputErrorStream;
private List<LogRecord> records;

private void setupStdOutput(){
outputCopyStream = new ByteArrayOutputStream(1000);
outputErrorStream = new ByteArrayOutputStream(1000);
OutputStream outputTee = new TeeOutputStream(System.out, outputCopyStream);
OutputStream errorTee = new TeeOutputStream(System.err, outputErrorStream);
PrintStream outputPrint = new PrintStream(outputTee);
PrintStream errorPrint = new PrintStream(errorTee);
System.setOut(outputPrint);
System.setErr(errorPrint);
}

private void setupLoggers(){
Logger global = Logger.getGlobal();
while (global.getParent() != null){
global = global.getParent();
}
global.addHandler(new java.util.logging.Handler() {
@Override
public void publish(LogRecord record) {
records.add(record);
}

@Override
public void flush() {

}

@Override
public void close() throws SecurityException {

}
});
}

public LogHandler() {
records = new ArrayList<>(20);
setupLoggers();
setupStdOutput();
}

@AllArgsConstructor
private class LogPojo {
public Object json;
public String stdout;
public String stderr;
}

@Override
public void handle(HttpExchange exchange) throws IOException {
try {
LogPojo log = new LogPojo(records, outputCopyStream.toString(), outputErrorStream.toString());
Handler.sendResponse(exchange, new Gson().toJson(log));
records.clear();
outputCopyStream.reset();
outputErrorStream.reset();
} catch (Exception e) {
e.printStackTrace();
Handler.sendResponse(exchange, e.getMessage(), 500);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import lombok.extern.java.Log;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.This;
import org.apache.commons.io.output.TeeOutputStream;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import mmuzikar.AgentConfiguration;
import mmuzikar.handlers.Handlers;
import mmuzikar.processors.StepDefProcessor;

import java.io.IOException;
import java.io.*;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
annotatedElements.forEach(o ->{
switch (o.getKind()){
case METHOD:
ExecutableType exec = ((ExecutableType) o);
// ExecutableType exec = ((ExecutableType) o);

break;
case CLASS:
Expand Down
12 changes: 12 additions & 0 deletions testsuite/src/test/java/mmuzikar/Stepdefs.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mmuzikar;

import com.codeborne.selenide.Selenide;

import cucumber.api.DataTable;
import cucumber.api.java.en.When;
import lombok.extern.java.Log;
import org.junit.Assert;
Expand All @@ -11,6 +13,8 @@

import static com.codeborne.selenide.Selenide.$;

import java.util.Map;

@Log
public class Stepdefs {

Expand All @@ -36,4 +40,12 @@ public void verifyInputValue(@Suggestion(InputSuggestion.class) String selector,
public void clickOnLink(@Suggestion(LinkTextSuggestion.class) String linkText){
$(By.linkText(linkText)).click();
}

@When("fill form named \"([^\"]*)\"")
public void tableUsage(String str, DataTable table){
Map<String, String> formData = table.asMap(String.class, String.class);
formData.entrySet().forEach(entry -> {
$(By.id(str)).$(By.name(entry.getKey())).setValue(entry.getValue());
});
}
}
25 changes: 0 additions & 25 deletions ui/.gitignore

This file was deleted.

24 changes: 24 additions & 0 deletions ui/gherkin.monarch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Create your own language definition here
// You can safely look at other samples without losing modifications.
// Modifications are not saved on browser refresh/close though -- copy often!
return {
// Set defaultToken to invalid to see what you do not tokenize yet
// defaultToken: 'invalid',

keywords: [
'Feature', 'Scenario', 'Background', 'Then', 'When', 'And', 'Given', 'But'
],

// The main tokenizer for our languages
tokenizer: {
root: [
[/#.*$/, 'comment'],
[/@[\w\-]*/, 'annotation'],
[/[A-Z][a-z]*/, {cases: {
'@keywords': 'keyword'
}}],
[/"[^\"]*"/, 'string'],
[/\|/, 'delimiter']
],
},
};
23 changes: 16 additions & 7 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
"@types/flux": "^3.1.9",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-grid-layout": "^0.17.0",
"babel-plugin-react-css-modules": "^5.2.6",
"flux": "^3.1.3",
"fuse.js": "^3.4.6",
"monaco-editor": "^0.19.3",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-grid-layout": "^0.17.1",
"react-monaco-editor": "^0.33.0",
"react-resize-panel": "^0.3.5",
"react-scripts": "3.3.1",
"typescript": "~3.7.2"
"react-scripts": "3.4.0"
},
"scripts": {
"start": "react-scripts start",
"start": "npx webpack-dev-server --open --mode development",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand All @@ -44,5 +41,17 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/react": "^16.9.23",
"@types/react-dom": "^16.9.5",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"monaco-editor-webpack-plugin": "^1.9.0",
"source-map-loader": "^0.2.4",
"ts-loader": "^6.2.1",
"typescript": "^3.7.5",
"webpack-cli": "^3.3.11",
"webpack-serve": "^3.2.0"
}
}
8 changes: 8 additions & 0 deletions ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<style>
.marginGlyphStatus-success{
background: '00ff00'
}
.marginGlyphStatus-failure{
background: 'ff0000'
}
</style>
<title>React App</title>
</head>
<body>
Expand Down
8 changes: 8 additions & 0 deletions ui/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@
content: ">";
color: blue;
}


.marginGlyphStatus-success{
background: '00ff00'
}
.marginGlyphStatus-failure{
background: 'ff0000'
}
27 changes: 15 additions & 12 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import React, { Component } from 'react';
import './App.css';
import '../node_modules/react-grid-layout/css/styles.css';
import '../node_modules/react-resizable/css/styles.css';
import { } from "react-grid-layout";
import RGL, { WidthProvider, Layout } from "react-grid-layout";
import { StepList } from './components/StepList';
import { TerminalInput } from './components/TerminalInput';
import { History } from './components/History';
import { Editor } from './components/Editor';
import { InputEditor } from './components/InputEditor';
import { OutputEditor } from './components/OutputEditor';
import { Logger } from './components/Log';
import { Toolbox } from './components/Toolbox';

const ReactGridLayout = WidthProvider(RGL);
const layout : Layout[] = [
{i: "history", x: 0, y: 0, w: 8, h: 8},
{i: "input-editor", x: 0, y: 0, w: 4, h: 6},
{i: "output-editor", x: 4, y: 0, w: 4, h: 6},
{i: "step-list", x: 8, y:0, w: 2, h: 5},
{i: "terminal", x: 0, y: 8, w: 8, h: 1},
{i: "toolbox", x:8, y:5, w: 2, h:4}
{i: "toolbox", x:8, y:5, w: 2, h:4},
{i: "log", x:0, y: 6, w: 8, h: 3}
]

type State = {
Expand All @@ -29,14 +30,16 @@ class App extends Component<{}, State> {
}

render(){
const rowHeight = (window.innerHeight-5)/10;
const colWidth = (window.innerWidth)/10;
return (
<div className="App">
<ReactGridLayout autoSize={true} isDraggable={false} className="layout" layout={layout} cols={10} rowHeight={(window.innerHeight-5)/10}>
<div key="history"><a href="#" onClick={() => this.setState({editor: !this.state.editor})}>Edit</a>
{this.state.editor?<Editor/>:<History />}</div>
<div key="terminal"><TerminalInput /></div>
<ReactGridLayout autoSize={true} isDraggable={false} className="layout" layout={layout} cols={10} rowHeight={rowHeight}>
<div key="input-editor"><InputEditor rowHeight={rowHeight} colWidth={colWidth}/></div>
<div key="output-editor"><OutputEditor rowHeight={rowHeight} colWidth={colWidth}/></div>
<div key="step-list"><StepList /></div>
<div key="toolbox">TODO: add toolbox (favorites {"&"} macros)</div>
<div key="toolbox"><Toolbox /></div>
<div key="log" style={{marginTop: "10px"}}><Logger/></div>
</ReactGridLayout>
</div>
);
Expand Down
24 changes: 0 additions & 24 deletions ui/src/components/Editor.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions ui/src/components/History.tsx

This file was deleted.

Loading

0 comments on commit 004b030

Please sign in to comment.