Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #117 from leaphy-robotics/refactoring
Browse files Browse the repository at this point in the history
chore: clean up code
  • Loading branch information
koen1711 authored Jan 27, 2024
2 parents 407ac64 + 3d807ec commit 75cae3d
Show file tree
Hide file tree
Showing 23 changed files with 1,725 additions and 1,819 deletions.
7 changes: 0 additions & 7 deletions src/app/domain/connection.status.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/domain/language.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export class Language {
constructor(public code: string, public name: string) {}
}
}
7 changes: 0 additions & 7 deletions src/app/domain/robot.connection.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/app/effects/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AppEffects {
.subscribe(language => this.translate.use(language.code));


// When the editor change has been confirmed, toggle the codeeditor
// When the editor change has been confirmed, toggle the code-editor
this.appState.isCodeEditorToggleConfirmed$
.pipe(filter(isToggled => !!isToggled), withLatestFrom(this.appState.codeEditor$))
.subscribe(([, codeEditorType]) => {
Expand All @@ -53,7 +53,6 @@ export class AppEffects {
await this.router.navigate(['/pythonEditor'], { skipLocationChange: true });
break;
default:
//await this.router.navigate(['']);
break;
}
this.appState.setIsCodeEditorToggleConfirmed(false);
Expand Down
5 changes: 1 addition & 4 deletions src/app/effects/backend.wired.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BlocklyEditorState } from '../state/blockly-editor.state';
import { filter, withLatestFrom } from 'rxjs/operators';
import { BackEndState } from '../state/backend.state';
import { SketchStatus } from '../domain/sketch.status';
import { ConnectionStatus } from '../domain/connection.status';
import { AppState } from '../state/app.state';
import { WorkspaceStatus } from '../domain/workspace.status';
import { CodeEditorType } from '../domain/code-editor.type';
Expand Down Expand Up @@ -67,9 +66,6 @@ export class BackendWiredEffects {
throw e;
}

// If that worked, set the backend Connection status
this.backEndState.setConnectionStatus(ConnectionStatus.ConnectedToBackend);

// When the sketch status is set to sending, send a compile request to backend
this.blocklyEditorState.sketchStatus$
.pipe(withLatestFrom(this.blocklyEditorState.code$, this.appState.selectedRobotType$))
Expand Down Expand Up @@ -102,6 +98,7 @@ export class BackendWiredEffects {
}
}
});
break;
default:
break;
}
Expand Down
67 changes: 25 additions & 42 deletions src/app/effects/blockly-editor.effects.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { Injectable } from '@angular/core';
import { BlocklyEditorState } from '../state/blockly-editor.state';
import { SketchStatus } from '../domain/sketch.status';
import { BackEndState } from '../state/backend.state';
import { ConnectionStatus } from '../domain/connection.status';
import { filter, pairwise, withLatestFrom } from 'rxjs/operators';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { combineLatest, Observable } from 'rxjs';
import { WorkspaceStatus } from '../domain/workspace.status';
import { AppState } from '../state/app.state';
import { CodeEditorType } from '../domain/code-editor.type';
import {Injectable} from '@angular/core';
import {BlocklyEditorState} from '../state/blockly-editor.state';
import {SketchStatus} from '../domain/sketch.status';
import {BackEndState} from '../state/backend.state';
import {filter, pairwise, withLatestFrom} from 'rxjs/operators';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {combineLatest, Observable} from 'rxjs';
import {WorkspaceStatus} from '../domain/workspace.status';
import {AppState} from '../state/app.state';
import {CodeEditorType} from '../domain/code-editor.type';
import {BackendWiredEffects} from "./backend.wired.effects";
import * as Blockly from 'blockly/core';
import Arduino from '@leaphy-robotics/leaphy-blocks/generators/arduino';
import getBlocks from "@leaphy-robotics/leaphy-blocks/blocks/blocks";
import {CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN,
LIST_MODES_MUTATOR_MIXIN,
LIST_MODES_MUTATOR_EXTENSION,
IS_DIVISIBLEBY_MUTATOR_MIXIN,
IS_DIVISIBLE_MUTATOR_EXTENSION,
MATH_TOOLTIPS_BY_OP,
LOGIC_TOOLTIPS_BY_OP,
LOGIC_COMPARE_EXTENSION,
TEXT_QUOTES_EXTENSION,
import {
APPEND_STATEMENT_INPUT_STACK,
CONTROLS_IF_MUTATOR_MIXIN,
CONTROLS_IF_TOOLTIP_EXTENSION,
CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN,
IS_DIVISIBLE_MUTATOR_EXTENSION,
IS_DIVISIBLEBY_MUTATOR_MIXIN,
LIST_MODES_MUTATOR_EXTENSION,
LIST_MODES_MUTATOR_MIXIN,
LOGIC_COMPARE_EXTENSION,
LOGIC_TOOLTIPS_BY_OP,
MATH_TOOLTIPS_BY_OP,
TEXT_QUOTES_EXTENSION,
WHILE_UNTIL_TOOLTIPS
} from "@leaphy-robotics/leaphy-blocks/blocks/extensions";
import {defaultBlockStyles, categoryStyles, componentStyles} from "@leaphy-robotics/leaphy-blocks/theme/theme";
import {LeaphyCategory} from "../services/Toolbox/Category";
import {LeaphyToolbox} from "../services/Toolbox/Toolbox";
import {categoryStyles, componentStyles, defaultBlockStyles} from "@leaphy-robotics/leaphy-blocks/theme/theme";
import {LeaphyCategory} from "../services/toolbox/category";
import {LeaphyToolbox} from "../services/toolbox/toolbox";

const Extensions = Blockly.Extensions;

Expand Down Expand Up @@ -118,13 +118,12 @@ export class BlocklyEditorEffects {
for (const [name, block] of Object.entries(leaphyBlocks.blockJs)) {
Blockly.Blocks[name] = block;
}
const LeaphyTheme = Blockly.Theme.defineTheme('leaphy', {
config.theme = Blockly.Theme.defineTheme('leaphy', {
'blockStyles': defaultBlockStyles,
'categoryStyles': categoryStyles,
'componentStyles': componentStyles,
name: 'leaphy',
})
config.theme = LeaphyTheme;
});
const parser = new DOMParser();
const toolboxXmlDoc = parser.parseFromString(baseToolboxXml, 'text/xml');
const toolboxElement = toolboxXmlDoc.getElementById('easyBloqsToolbox');
Expand Down Expand Up @@ -222,22 +221,6 @@ export class BlocklyEditorEffects {
.pipe(filter(([, workspace]) => !!workspace))
.subscribe(([redo, workspace]) => workspace.undo(redo));

// Changes in ConnectionStatus result in changes in SketchStatus
this.backEndState.connectionStatus$
.subscribe(connectionStatus => {
switch (connectionStatus) {
case ConnectionStatus.Disconnected:
case ConnectionStatus.ConnectedToBackend:
case ConnectionStatus.WaitForRobot:
this.blocklyState.setSketchStatus(SketchStatus.UnableToSend);
break;
case ConnectionStatus.PairedWithRobot:
this.blocklyState.setSketchStatus(SketchStatus.ReadyToSend);
break;
default:
break;
}
});

// When Advanced CodeEditor is Selected, set the workspace status to SavingTemp and hide the sideNav
this.appState.codeEditor$
Expand Down
4 changes: 1 addition & 3 deletions src/app/effects/dialog.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export class DialogEffects {
});

const language = localStorage.getItem('currentLanguage');
if (language) {
//console.log('Language is set to ' + language);
} else {
if (!language) {
const languageDialogRef = this.dialog.open(LanguageSelectDialog, {
width: '450px',
disableClose: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class DebugInformationDialog {
// @ts-ignore
this.os = navigator.userAgentData?.platform ?? translate.instant("UNKNOWN");
// @ts-ignore
this.browser = navigator.userAgentData?.brands[0].brand ?? translate.instant("UNKNOWN");
this.browser = navigator.userAgentData?.brands[1].brand ?? translate.instant("UNKNOWN");
// @ts-ignore
this.browserVersion = navigator.userAgentData?.brands[0].version ?? translate.instant("UNKNOWN");
this.browserVersion = navigator.userAgentData?.brands[1].version ?? translate.instant("UNKNOWN");
this.serialPort = this.robotWiredState.getSerialPort();
if (!('serial' in navigator)) {
this.webSerialSupported = translate.instant("WEB_SERIAL_NOT_SUPPORTED");
Expand Down
11 changes: 2 additions & 9 deletions src/app/modules/driver-issues-dutch/driver-issues.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'driver-issues-dutch-page',
Expand All @@ -7,12 +7,5 @@ import { Component, ElementRef } from '@angular/core';
})
export class DriverIssuesDutchPage {

constructor(private elementRef: ElementRef) { }

scrollTo(targetId: string): void {
const targetElement = this.elementRef.nativeElement.querySelector(`#${targetId}`);
if (targetElement) {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
}
constructor() { }
}
11 changes: 2 additions & 9 deletions src/app/modules/driver-issues-english/driver-issues.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'driver-issues-english-page',
Expand All @@ -7,12 +7,5 @@ import { Component, ElementRef } from '@angular/core';
})
export class DriverIssuesEnglishPage {

constructor(private elementRef: ElementRef) { }

scrollTo(targetId: string): void {
const targetElement = this.elementRef.nativeElement.querySelector(`#${targetId}`);
if (targetElement) {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
}
constructor() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { MatDialog } from "@angular/material/dialog";
import { BlocklyEditorState } from "src/app/state/blockly-editor.state";
import { AppState } from "src/app/state/app.state";
import { DialogState } from "src/app/state/dialog.state";
import { RobotWiredState } from "src/app/state/robot.wired.state";
import {AppComponent} from "../../../../app.component";
import {CodeEditorType} from "../../../../domain/code-editor.type";

@Component({
Expand All @@ -24,10 +22,6 @@ export class ButtonBarComponent {
this.blocklyState.setIsSideNavOpenToggled();
}

public isSerialMonitorAvailable() {
return this.appState.getSelectedRobotType() !== AppState.microPythonRobotType;
}

public onShowSerialOutputClicked() {
this.dialogState.setIsSerialOutputWindowOpen(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { ComponentPortal, DomPortalOutlet } from '@angular/cdk/portal';
import { AfterViewInit, ApplicationRef, Component, ComponentFactoryResolver, ComponentRef, Injector, OnInit } from '@angular/core';
import { DialogState } from 'src/app/state/dialog.state';
import { SerialOutputComponent } from '../serial-output/serial-output.component';
import { Component } from '@angular/core';

@Component({
selector: 'app-serial-window',
Expand All @@ -10,12 +7,5 @@ import { SerialOutputComponent } from '../serial-output/serial-output.component'
})
export class SerialWindowComponent {

constructor(
private injector: Injector,
private componentFactoryResolver: ComponentFactoryResolver,
private applicationRef: ApplicationRef,
private dialogState: DialogState,
) { }

styleSheetElement: any = null;
constructor() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core';
import {FunctionsUsingCSI, NgTerminal} from "ng-terminal";
import {RobotWiredState} from "../../../../state/robot.wired.state";
import {PythonUploaderService} from "../../../../services/python-uploader/PythonUploader.service";
import {DialogState} from "../../../../state/dialog.state";

@Component({
selector: 'app-terminal',
Expand All @@ -18,7 +17,6 @@ export class TerminalComponent implements AfterViewInit {
constructor(
private robotWireState: RobotWiredState,
private pythonUploader: PythonUploaderService,
private dialogState: DialogState
) {}


Expand Down
Loading

0 comments on commit 75cae3d

Please sign in to comment.