Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed May 7, 2017
1 parent 5d671a2 commit 1549924
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export class DiagramEditorController {
return this.getNodeType(type);
};
this.diagramEditor = new DiagramEditor();
this.sceneController = new SceneController(this, this.diagramEditor.getScene(), selectorService.scene);
this.sceneController = new SceneController(
this,
this.diagramEditor.getScene(),
selectorService.scene,
selectorService.gestures);

this.elementsTypeLoader = new ElementsTypeLoader();

$scope.undo = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export class SceneController {
private paperCommandFactory: SceneCommandFactory;
private contextMenuId;
private selectorService : any;
private gestures : any;

constructor(diagramEditorController: DiagramEditorController, paper: DiagramScene, selectorService: any) {
constructor(diagramEditorController: DiagramEditorController, paper: DiagramScene, selectorService: any, gestures: any) {
this.diagramEditorController = diagramEditorController;
this.undoRedoController = diagramEditorController.getUndoRedoController();
this.scene = paper;
Expand All @@ -44,6 +45,7 @@ export class SceneController {
this.lastCellScrollPosition = { x: 0, y: 0 };
this.contextMenuId = selectorService.contextMenu.id;
this.selectorService = selectorService;
this.gestures = gestures;

this.scene.on('cell:pointerdown', (cellView, event, x, y): void => {
this.cellPointerdownListener(cellView, event, x, y);
Expand Down Expand Up @@ -172,7 +174,7 @@ export class SceneController {

var contextMenu = new ContextMenu();
var menuDiv = document.createElement("div");
menuDiv.id = this.selectorService.gestures.gesturesMenu.id;
menuDiv.id = this.gestures.gesturesMenu.id;
menuDiv.className = "gestures-menu";
menuDiv.style.left = event.x + "px";
menuDiv.style.top = event.y + "px";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<%JSONObject headerPanelSelector = selectors.getJSONObject("editorHeaderPanel"); %>

<!-- Context menu in File->'Open diagram' window -->
<ul id="<%=headerPanelSelector.getJSONObject("contextMenu").getString("id")%>" class='custom-menu'>
<li id="<%=headerPanelSelector.getJSONObject("contextMenu").getJSONObject("deleteItem").getString("id")%>"
<%JSONObject contextMenuSelector = headerPanelSelector.getJSONObject("folderArea").getJSONObject("contextMenu"); %>
<ul id="<%=contextMenuSelector.getString("id")%>" class='custom-menu'>
<li id="<%=contextMenuSelector.getJSONObject("deleteItem").getString("id")%>"
data-action="delete">Delete</li>
<li data-action="share" >Share</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
Expand All @@ -18,27 +16,20 @@
@PropertySource("classpath:application.properties")
public class ConfigsMerger {

private static final Logger logger = LoggerFactory.getLogger(ConfigsMerger.class);

private final JsonParser parser = new JsonParser();

@Value("${selectorConfig}")
private String configFile;

/** Generates one config file from all which are used. */
public JsonObject generateCommonConfig() {
public JsonObject generateCommonConfig() throws FileNotFoundException {
String path = getClass().getClassLoader().getResource(configFile).getPath();
try {
JsonElement jsonElement = parser.parse(new FileReader(path));
JsonObject initialConfig = jsonElement.getAsJsonObject();
return merge(initialConfig, path);
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
throw new RuntimeException("There are no files on path: " + path);
}
JsonElement jsonElement = parser.parse(new FileReader(path));
JsonObject initialConfig = jsonElement.getAsJsonObject();
return merge(initialConfig, path);
}

private JsonObject merge(JsonObject parent, String path) {
private JsonObject merge(JsonObject parent, String path) throws FileNotFoundException {
JsonObject result = new JsonObject();
for (Map.Entry<String, JsonElement> childEntry: parent.entrySet()) {
if (childEntry.getValue().isJsonPrimitive()) {
Expand All @@ -51,12 +42,7 @@ private JsonObject merge(JsonObject parent, String path) {
+ stringValue.substring(pathLink.length(), stringValue.length());

JsonObject parsedChild;
try {
parsedChild = parser.parse(new FileReader(newPath)).getAsJsonObject();
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
throw new RuntimeException("There are no files on path: " + path);
}
parsedChild = parser.parse(new FileReader(newPath)).getAsJsonObject();
result.add(childEntry.getKey(), merge(parsedChild, newPath));
} else {
result.add(childEntry.getKey(), childEntry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;

@Controller
public class RestController {

Expand All @@ -17,37 +19,37 @@ public RestController(ConfigsMerger merger) {

@GetMapping("/all")
@ResponseBody
public String getAllConfig() {
public String getAllConfig() throws FileNotFoundException {
return merger.generateCommonConfig().toString();
}

@GetMapping("/editor/robots")
@ResponseBody
public String getRobotEditor() {
public String getRobotEditor() throws FileNotFoundException {
return merger.generateCommonConfig().get("robotEditor").toString();
}

@GetMapping("/editor/bpmn")
@ResponseBody
public String getBPMNEditor() {
public String getBPMNEditor() throws FileNotFoundException {
return merger.generateCommonConfig().get("bpmnEditor").toString();
}

@GetMapping("/dashboard")
@ResponseBody
public String getDashboard() {
public String getDashboard() throws FileNotFoundException {
return merger.generateCommonConfig().get("dashboard").toString();
}

@GetMapping("/authform")
@ResponseBody
public String getAuthform() {
public String getAuthform() throws FileNotFoundException {
return merger.generateCommonConfig().get("authform").toString();
}

@GetMapping("/auth")
@ResponseBody
public String getAuth() {
public String getAuth() throws FileNotFoundException {
return merger.generateCommonConfig().get("authService").toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id" : "diagramArea",//"#diagrams .modal-content",
"id" : "diagramArea",
"createItem" : {
"id" : "creating-menu"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ public DiagramStoreService(EditorPageFacade facade, SelectorService selectorServ

/** Saves diagram. */
public void saveDiagram(String key) {
SelenideElement element =
$(By.id(selectorService.getId("savingMenu.savingInput")));
SelenideElement element = $(By.id(selectorService.getId("savingMenu.savingInput")));
element.setValue(getFilename(key));
diagrams.put(key, prepareElement(Jsoup.parseBodyFragment($(sceneSelector).innerHtml()).body()));
$(By.id(selectorService.getId("savingMenu.savingItem"))).click();
$(By.id(selectorService.getId("savingMenu.savingItem")))
.shouldBe(Condition.disappear);
$(By.id(selectorService.getId("savingMenu.savingItem"))).waitUntil(Condition.disappear, 5000);
lastKnownKey = key;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.qreal.wmp.uitesting.headerpanel;

import com.codeborne.selenide.Condition;
import com.google.common.base.Predicate;
import com.qreal.wmp.uitesting.PageFactory;
import com.qreal.wmp.uitesting.headerpanel.folderwindow.FileItem;
import com.qreal.wmp.uitesting.headerpanel.folderwindow.FolderArea;
Expand All @@ -9,6 +9,8 @@
import com.qreal.wmp.uitesting.services.SelectorService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,6 +33,8 @@ public class EditorHeaderPanelImpl implements EditorHeaderPanel {

private final SelectorService selectorService;

private final WebDriver webDriver;

private EditorHeaderPanelImpl(
PageFactory pageFactory,
WebDriver webDriver,
Expand All @@ -42,6 +46,7 @@ private EditorHeaderPanelImpl(
this.pageFactory = pageFactory;
this.editorPageFacade = editorPageFacade;
this.selectorService = selectorService;
this.webDriver = webDriver;
}

@Override
Expand Down Expand Up @@ -103,8 +108,15 @@ public static EditorHeaderPanel getEditorHeaderPanel(PageFactory pageFactory,
}

private FileItem clickFile() {
$(By.id(selectorService.getId("fileItem"))).waitUntil(Condition.visible, 5000);
$(By.id(selectorService.getId("fileItem"))).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
new Actions(webDriver).click($(By.id(selectorService.getId("fileItem")))).perform();
(new WebDriverWait(webDriver, 10))
.until((Predicate<WebDriver>) webDriver ->
$(By.id(selectorService.getId("fileItem"))).attr("class").contains("open"));
return fileItem;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.qreal.wmp.uitesting.headerpanel.folderwindow;

import com.codeborne.selenide.Condition;
import com.qreal.wmp.uitesting.services.SelectorService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/** Describes file item on the header menu. */
public class FileItem {

private static final Logger logger = LoggerFactory.getLogger(FileItem.class);

private final FolderArea folderArea;

private final WebDriver driver;
Expand All @@ -24,28 +27,49 @@ public FileItem(WebDriver driver, SelectorService selectorService) {

/** Corresponds 'New' button. */
public void newDiagram() {
$(By.id(selectorService.getId("fileItem.newDiagramItem"))).click();
$(By.id(selectorService.getId("saveDiagramConfirmWindow")))
.waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.newDiagramItem")))).perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
SaveDiagramConfirm.getSaveDiagramConfirm(driver, selectorService.create("saveDiagramConfirmWindow")).notSave();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
}

/** Returns folder window by clicking 'SaveAs'. */
public FolderArea getSaveItem() {
$(By.id(selectorService.getId("fileItem.saveAsItem"))).click();
$(By.id(selectorService.getId("folderArea"))).waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.saveAsItem")))).perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
return folderArea;
}

/** Returns folder window by clicking 'Open'. */
public FolderArea getOpenItem() {
$(By.id(selectorService.getId("fileItem.OpenItem"))).click();
$(By.id(selectorService.getId("folderArea"))).waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.openItem")))).perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
return folderArea;
}

/** Corresponds 'Save' button. */
public void saveDiagram() {
$(By.id(selectorService.getId("fileItem.SaveItem"))).click();
new Actions(driver).click($(By.id(selectorService.getId("fileItem.saveItem")))).perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
}
}
Loading

0 comments on commit 1549924

Please sign in to comment.