Skip to content

Commit

Permalink
add UI code
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 24, 2024
1 parent ca37ef2 commit 43f9c6e
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Collections.Generic;
using starsky.foundation.platform.Enums;

namespace starsky.foundation.platform.Models
{
/// <summary>
Expand All @@ -11,5 +14,11 @@ public sealed class AppSettingsTransferObject
public bool? UseSystemTrash { get; set; }

public bool? UseLocalDesktop { get; set; }

public List<AppSettingsDefaultEditorApplication> DefaultDesktopEditor { get; set; } = [];

public CollectionsOpenType.RawJpegMode DesktopCollectionsOpen { get; set; } =
CollectionsOpenType.RawJpegMode.Default;

}
}
2 changes: 2 additions & 0 deletions starsky/starsky/Controllers/AppSettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public AppSettingsController(AppSettings appSettings,
public IActionResult Env()
{
var appSettings = _appSettings.CloneToDisplay();

// For end-to-end testing
if ( Request != null! && Request.Headers.Any(p => p.Key == "x-force-html") )
{
Response.Headers.ContentType = "text/html; charset=utf-8";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,72 @@
import React from "react";
import React, { useState } from "react";
import useFetch from "../../../hooks/use-fetch";
import useGlobalSettings from "../../../hooks/use-global-settings";
import { IAppSettings } from "../../../interfaces/IAppSettings";
import { RawJpegMode } from "../../../interfaces/ICollectionsOpenType";
import localization from "../../../localization/localization.json";
import FetchPost from "../../../shared/fetch/fetch-post";
import { Language } from "../../../shared/language";
import { UrlQuery } from "../../../shared/url-query";
import FormControl from "../../atoms/form-control/form-control";
import SwitchButton from "../../atoms/switch-button/switch-button";

const PreferencesAppSettingsDesktop: React.FunctionComponent = () => {
const appSettings = useFetch(new UrlQuery().UrlApiAppSettings(), "get")
?.data as IAppSettings | null;

const settings = useGlobalSettings();

const language = new Language(settings.language);
const MessageSwitchButtonDesktopCollectionsRawOn = language.key(
localization.MessageSwitchButtonDesktopCollectionsRawOn
);
const MessageSwitchButtonDesktopCollectionsJpegDefaultOff = language.key(
localization.MessageSwitchButtonDesktopCollectionsJpegDefaultOff
);

// appSettings?.desktopCollectionsOpen
// List<AppSettingsDefaultEditorApplication> DefaultDesktopEditor
// CollectionsOpenType.RawJpegMode DesktopCollectionsOpen

async function toggleCollections(value: boolean) {
const desktopCollectionsOpen = value ? RawJpegMode.Raw : RawJpegMode.Jpeg;

const bodyParams = new URLSearchParams();
bodyParams.set("desktopCollectionsOpen", desktopCollectionsOpen.toString());

const result = await FetchPost(new UrlQuery().UrlApiAppSettings(), bodyParams.toString());
if (result.statusCode != 200) {
setIsMessage("FAIL");
return;
}
setIsMessage("OK");
}

// for showing a notification
const [isMessage, setIsMessage] = useState("");

return (
<>
<p>Desktop</p>
Only used when using Starsky as desktop
{isMessage !== "" ? (
<div className="warning-box warning-box--optional">{isMessage}</div>
) : null}
<SwitchButton
isOn={appSettings?.desktopCollectionsOpen === RawJpegMode.Raw}
data-test="desktop-collections-open-toggle"
isEnabled={true}
leftLabel={MessageSwitchButtonDesktopCollectionsJpegDefaultOff}
onToggle={toggleCollections}
rightLabel={MessageSwitchButtonDesktopCollectionsRawOn}
/>
<h4>Tags:</h4>
<FormControl
spellcheck={true}
onInput={handleUpdateChange}
name="tags"
contentEditable={true}
></FormControl>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import FetchPost from "../../../shared/fetch/fetch-post";
import { Language } from "../../../shared/language";
import { UrlQuery } from "../../../shared/url-query";
import FormControl from "../../atoms/form-control/form-control";

/**
* Update Change Settings
* @param value - content
* @param name - key name
* @returns void
*/
export async function ChangeSetting(value: string, name?: string): Promise<number> {
const bodyParams = new URLSearchParams();
bodyParams.set(name ?? "", value);
Expand Down Expand Up @@ -53,10 +60,6 @@ const PreferencesAppSettingsStorageFolder: React.FunctionComponent = () => {

const [storageFolder, setStorageFolder] = useState(appSettings?.storageFolder);

// const [defaultDesktopEditor, setDefaultDesktopEditor] = useState(
// appSettings?.defaultDesktopEditor
// );

useEffect(() => {
setStorageFolder(appSettings?.storageFolder);
}, [appSettings]);
Expand Down
9 changes: 9 additions & 0 deletions starsky/starsky/clientapp/src/localization/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@
"en": "Please update the 'app__storageFolder' environment variable to change the location",
"nl": "Update alsjeblieft de 'app__storageFolder' environment variable om de opslag locatie te veranderen"
},
"MessageSwitchButtonDesktopCollectionsRawOn": {
"en": "Raw first",
"nl": "Raw eerst"
},
"MessageSwitchButtonDesktopCollectionsJpegDefaultOff": {
"en": "Jpeg first",
"nl": "Jpeg eerst"
},

"temp1": {
"en": "",
"nl": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.feature.settings.Services;
using starsky.foundation.platform.Enums;
using starsky.foundation.platform.JsonConverter;
using starsky.foundation.platform.Models;
using starsky.foundation.storage.Helpers;
Expand All @@ -31,7 +32,8 @@ public async Task UpdateAppSettingsAsync_ValidInput_Success()
new UpdateAppSettingsByPath(new AppSettings(), selectorStorage);
var appSettingTransferObject = new AppSettingsTransferObject
{
StorageFolder = testFolderPath, Verbose = true
StorageFolder = testFolderPath,
Verbose = true
};

// Act
Expand Down Expand Up @@ -62,7 +64,9 @@ public async Task UpdateAppSettingsAsync_ValidInput_Success_CompareJson()
var updateAppSettingsByPath = new UpdateAppSettingsByPath(appSettings, selectorStorage);
var appSettingTransferObject = new AppSettingsTransferObject
{
StorageFolder = testFolderPath, Verbose = true, UseLocalDesktop = null
StorageFolder = testFolderPath,
Verbose = true,
UseLocalDesktop = null
};

// Act
Expand Down Expand Up @@ -191,5 +195,28 @@ await StreamToStringHelper.StreamToStringAsync(
Assert.AreEqual(testFolderPath, fileResult2.App.StorageFolder);
Assert.IsTrue(fileResult2.App.Verbose);
}

[TestMethod]
public async Task UpdateAppSettingsAsync_ValidInput_Success1()
{
var storage = new FakeIStorage();
var selectorStorage = new FakeSelectorStorage(storage);
var updateAppSettingsByPath =
new UpdateAppSettingsByPath(new AppSettings(), selectorStorage);
var appSettingTransferObject = new AppSettingsTransferObject
{
DesktopCollectionsOpen = CollectionsOpenType.RawJpegMode.Raw,
Verbose = true
};

// Act
var result =
await updateAppSettingsByPath.UpdateAppSettingsAsync(appSettingTransferObject);


// Assert
Assert.AreEqual(200, result.StatusCode);
Assert.AreEqual("Updated", result.Message);
}
}
}

0 comments on commit 43f9c6e

Please sign in to comment.