Skip to content

Commit

Permalink
Merge pull request #76 from ui5-community/fix/smaller_issues
Browse files Browse the repository at this point in the history
Fix/smaller issues
  • Loading branch information
tabris87 authored Jan 21, 2025
2 parents 9afb553 + 2abc2c3 commit 57204a7
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 91 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.3.5](https://ui5-community///compare/v0.3.4...v0.3.5) (2025-01-21)


### Features

* **no-record:** automatic nav to main if no steps were recorded ([b433e54](https://ui5-community///commit/b433e54c47cef4aa758b907bdd13407d8653f02d))


### Bug Fixes

* **chrome-130:** fixed the issue with dynamically loaded scripts ([0a1c18b](https://ui5-community///commit/0a1c18b73f719d7ee49b1fab9e166520a456a3af))
* **code-gen:** fixed wrong indentation within generated sources ([446f72c](https://ui5-community///commit/446f72c6b2c56b93cf56b38fc303c74c786f2bf7))
* **content-inject:** fixed src type within content-inject ([76107ca](https://ui5-community///commit/76107cad4514df1ec3e494b878f6a8977cb26f71))
* **settings:** changed structure of settings dialog ([d5d0c6f](https://ui5-community///commit/d5d0c6f59c0327e70ae2d305b0c61d049e0643c3))
* **ui5:** fixed Typos and misspellings after version upgrade ([5f25d78](https://ui5-community///commit/5f25d788833c2dc6c3099f320824c679febf9d06))
* **unnecessary:** removed unnecessary type from style ([9afb553](https://ui5-community///commit/9afb553d3f5919ddaf5c3d70f777040ec853a9e9))

### [0.3.4](https://ui5-community///compare/v0.3.1...v0.3.4) (2024-12-20)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.ui5.journeyrecorder",
"version": "0.3.4",
"version": "0.3.5",
"description": "UI5 Application: com.ui5.journeyrecorder",
"author": "Adrian Marten",
"license": "Apache-2.0",
Expand All @@ -15,6 +15,7 @@
"test": "npm run lint && npm run karma-ci-cov",
"wdi5": "wdio run ./webapp/test/e2e/\\wdio.conf.ts",
"deployBuild": "node ./utils/deployBuild.js",
"deployBuild-keep": "node ./utils/deployBuild.js --keep",
"prepare": "husky",
"commit": "npx commit",
"changelog": "standard-version"
Expand Down
167 changes: 92 additions & 75 deletions webapp/controller/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import Router from "sap/ui/core/routing/Router";
import History from "sap/ui/core/routing/History";
import UI5Element from "sap/ui/core/Element";
import Dialog from "sap/m/Dialog";
import Fragment from "sap/ui/core/Fragment";
import Event from "sap/ui/base/Event";
import JSONModel from "sap/ui/model/json/JSONModel";
import SettingsStorageService, { AppSettings } from "../service/SettingsStorage.service";
import { TestFrameworks } from "../model/enum/TestFrameworks";
import { Themes } from "../model/enum/Themes";
import Theming from "sap/ui/core/Theming";
import { ConnectionStatus } from "../model/enum/ConnectionStatus";
import { IconColor, ValueState } from "sap/ui/core/library";
import { ButtonType, DialogType } from "sap/m/library";
Expand All @@ -22,6 +21,7 @@ import Text from "sap/m/Text";
import BusyIndicator from "sap/ui/core/BusyIndicator";
import { ChromeExtensionService } from "../service/ChromeExtension.service";
import MessageToast from "sap/m/MessageToast";
import XMLView from "sap/ui/core/mvc/XMLView";

/**
* @namespace com.ui5.journeyrecorder.controller
Expand All @@ -30,6 +30,14 @@ export default abstract class BaseController extends Controller {
protected settingsDialog: UI5Element;
protected _unsafeDialog: Dialog;

private _dialogs: Record<string, {
dialog: Dialog,
view: XMLView,
controller: Controller & { settings?: { initialHeight?: string, initialWidth?: string } }
}>;

private _fragments: Record<string, Dialog>;

/**
* Convenience method for accessing the component of the controller's view.
* @returns The component of the controller's view
Expand Down Expand Up @@ -101,79 +109,7 @@ export default abstract class BaseController extends Controller {
}

async onOpenSettingsDialog() {
if (!this.settingsDialog) {
this.settingsDialog = await this.loadFragment({
name: "com.ui5.journeyrecorder.fragment.SettingsDialog"
}) as UI5Element;
this.getView().addDependent(this.settingsDialog);
}
(this.settingsDialog as Dialog).open();
}

onCloseDialog(oEvent: Event) {
const closeReason = (oEvent.getSource() as unknown as { data: (s: string) => string }).data("settingsDialogClose");
if (closeReason === 'save') {
(this.getModel("settings") as JSONModel).getData();
void SettingsStorageService.save((this.getModel("settings") as JSONModel).getData() as AppSettings);
} else {
void SettingsStorageService.getSettings().then((settings: AppSettings) => {
(this.getModel("settings") as JSONModel).setData(settings);
})
}
(this.settingsDialog as Dialog).close();
}

onDelaySelect(oEvent: Event) {
const index = oEvent.getParameter("selectedIndex" as never);
switch (index) {
case 0:
(this.getModel("settings") as JSONModel).setProperty('/replayDelay', 0.5);
break;
case 1:
(this.getModel("settings") as JSONModel).setProperty('/replayDelay', 1.0);
break;
case 2:
(this.getModel("settings") as JSONModel).setProperty('/replayDelay', 2.0);
break;
default:
(this.getModel("settings") as JSONModel).setProperty('/replayDelay', 0.5);
}
}

onFrameworkSelect(oEvent: Event) {
const index = oEvent.getParameter("selectedIndex" as never);
switch (index) {
case 0:
(this.getModel("settings") as JSONModel).setProperty('/testFramework', TestFrameworks.OPA5);
break;
case 1:
(this.getModel("settings") as JSONModel).setProperty('/testFramework', TestFrameworks.WDI5);
break;
default:
(this.getModel("settings") as JSONModel).setProperty('/testFramework', TestFrameworks.OPA5);
}
}

onThemeSelect(oEvent: Event) {
const index = oEvent.getParameter("selectedIndex" as never);
switch (index) {
case 1:
(this.getModel("settings") as JSONModel).setProperty('/theme', Themes.EVENING_HORIZON);
break;
case 2:
(this.getModel("settings") as JSONModel).setProperty('/theme', Themes.QUARTZ_LIGHT);
break;
case 3:
(this.getModel("settings") as JSONModel).setProperty('/theme', Themes.QUARTZ_DARK);
break;
default:
(this.getModel("settings") as JSONModel).setProperty('/theme', Themes.MORNING_HORIZON);
}
Theming.setTheme((this.getModel("settings") as JSONModel).getProperty('/theme') as string);
}

compareProps(args: unknown[]) {
return args[0] === args[1];
await this.openDialog("Settings");
}

setConnecting() {
Expand Down Expand Up @@ -266,4 +202,85 @@ export default abstract class BaseController extends Controller {
MessageToast.show('Disconnected', { duration: 500 });
}
}

protected openDialog(sDialogName: string, oData?: Record<string, unknown>): Promise<Record<string, unknown> | void> {
if (!this._dialogs) {
this._dialogs = {};
}

return new Promise(async (resolve, reject) => {
if (!this._dialogs[sDialogName]) {
const oDialog = new Dialog({
showHeader: false
});
this.getView().addDependent(oDialog);
const oView = await this.getOwnerComponent().runAsOwner(async () => {
return await XMLView.create({
viewName: `com.ui5.journeyrecorder.view.dialogs.${sDialogName}`
});
});
const oController = oView.getController();
oDialog.addContent(oView);

this._dialogs[sDialogName] = {
dialog: oDialog,
view: oView,
controller: oController
}
}
const oDialogCompound = this._dialogs[sDialogName];
if (oData) {
oDialogCompound.view.setModel(new JSONModel(oData), "importData");
}

if (oDialogCompound.controller.settings.initialHeight) {
oDialogCompound.dialog.setContentHeight(oDialogCompound.controller.settings.initialHeight);
}

if (oDialogCompound.controller.settings.initialWidth) {
oDialogCompound.dialog.setContentWidth(oDialogCompound.controller.settings.initialWidth);
}

const beforeClose = (oEvent: Event) => {
oDialogCompound.dialog.detachBeforeClose(beforeClose);
const pars = oEvent.getParameters() as Record<string, unknown>;
oDialogCompound.dialog.close();

if (pars.status === "Success") {
if (pars.data) {
resolve(pars.data as Record<string, unknown>);
} else {
resolve();
}
} else {
reject();
}
};

oDialogCompound.dialog.attachBeforeClose(beforeClose);

oDialogCompound.dialog.open();
})
}

protected async openFragment(sFragmentName: string, sFragmentId?: string): Promise<void> {
if (!sFragmentName) {
throw new Error("At least the Fragment-Name is needed!");
}

if (!this._fragments) {
this._fragments = {};
}

if (!this._fragments[sFragmentName]) {
const oFragmentDialog = await Fragment.load({
id: sFragmentId || `${sFragmentName}_id`,
name: `com.ui5.journeyrecorder.view.dialogs.${sFragmentName}`,
controller: this
})
this.getView().addDependent(oFragmentDialog as UI5Element);
}

this._fragments[sFragmentName].open();
}
}
34 changes: 22 additions & 12 deletions webapp/controller/JourneyPage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,23 @@ export default class JourneyPage extends BaseController {
const ui5Version = await this._requestUI5Version();
const data = this.model.getData() as Partial<Journey>;
data.ui5Version = ui5Version;
const journey = JourneyStorageService.createJourneyFromRecording(data);
ChromeExtensionService.getInstance().unregisterRecordingWebsocket(
// eslint-disable-next-line @typescript-eslint/unbound-method
this._onStepRecord,
this
);
await ChromeExtensionService.getInstance().disableRecording();
BusyIndicator.hide();
this.model.setData(journey);
(this.getModel('journeyControl') as JSONModel).setProperty('/unsafed', true);
this._generateCode(journey);
if (data.steps && data.steps.length > 0) {
const journey = JourneyStorageService.createJourneyFromRecording(data);
ChromeExtensionService.getInstance().unregisterRecordingWebsocket(
// eslint-disable-next-line @typescript-eslint/unbound-method
this._onStepRecord,
this
);
await ChromeExtensionService.getInstance().disableRecording();
BusyIndicator.hide();
this.model.setData(journey);
(this.getModel('journeyControl') as JSONModel).setProperty('/unsafed', true);
this._generateCode(journey);
} else {
await ChromeExtensionService.getInstance().disableRecording();
BusyIndicator.hide();
this.getRouter().navTo("main");
}
}

private _generateCode(journey: Journey) {
Expand Down Expand Up @@ -483,8 +489,12 @@ export default class JourneyPage extends BaseController {
this.setConnected();
void ChromeExtensionService.getInstance().focusTab(tab);
BusyIndicator.hide();
await this._openRecordingDialog();
MessageToast.show('Connected');
try {
await this._openRecordingDialog();
} catch (oError) {

}
}).catch(() => {
BusyIndicator.hide();
});
Expand Down
30 changes: 30 additions & 0 deletions webapp/controller/dialogs/BaseDialogController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Event from "sap/ui/base/Event";
import BaseController from "../BaseController";
import Dialog from "sap/m/Dialog";

/**
* @namespace com.ui5.journeyrecorder.controller.dialogs
*/
export default class BaseDialogController extends BaseController {
closeBySuccess(oPressEvent: Event, data?: Record<string, unknown>) {
const oResult: {
origin: unknown,
result: "Confirm" | "Abort",
data?: Record<string, unknown>
} = {
origin: oPressEvent.getSource(),
result: "Confirm",
};
if (data) {
oResult.data = data;
}
(this.getView().getParent() as Dialog).fireBeforeClose(oResult)
}

closeByAbort(oPressEvent: Event) {
(this.getView().getParent() as Dialog).fireBeforeClose({
origin: oPressEvent.getSource(),
result: "Abort"
})
}
}
35 changes: 35 additions & 0 deletions webapp/controller/dialogs/Settings.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import BaseDialogController from "./BaseDialogController";
import { Themes } from "../../model/enum/Themes";
import Theming from "sap/ui/core/Theming";
import JSONModel from "sap/ui/model/json/JSONModel";
import SettingsStorageService, { AppSettings } from "../../service/SettingsStorage.service";
import ListItem from "sap/ui/core/ListItem";
import Event from "sap/ui/base/Event";
import Dialog from "sap/m/Dialog";

/**
* @namespace com.ui5.journeyrecorder.controller.dialogs
*/
export default class Settings extends BaseDialogController {
settings = {
initialHeight: '91vh',
initialWidth: '30rem'
}

onThemeSelect(oEvent: Event) {
const oItem = oEvent.getParameter("selectedItem" as never) as ListItem;
const oModel = this.getModel("settings") as JSONModel;
oModel.setProperty('/theme', oItem.getKey());
Theming.setTheme(oItem.getKey());
}

onCloseDialog(oEvent: Event, bSave: boolean) {
if (bSave) {
void SettingsStorageService.save((this.getModel("settings") as JSONModel).getData() as AppSettings);
}
(this.getView().getParent() as Dialog).fireBeforeClose({
origin: oEvent.getSource(),
result: bSave ? 'Confirm' : 'Reject'
});
}
}
4 changes: 3 additions & 1 deletion webapp/service/SettingsStorage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export default class SettingsStorageService {

public static async getSettings(): Promise<AppSettings> {
const values = await chrome.storage.local.get('settings');
if (values['settings']) {
if (values['settings'] && typeof values['settings'] === 'string') {
return JSON.parse(values.settings as string) as AppSettings;
} else if (values['settings'] && typeof values['settings'] === 'object') {
return values.settings as AppSettings;
} else {
return SettingsStorageService.getDefaults();
}
Expand Down
Loading

0 comments on commit 57204a7

Please sign in to comment.