Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add web page to crud warehouse #158

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions web/public/images/warehouse-pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import Dashboard from "./routes/backOffice/dashboard/Dashboard.svelte";
import Map from "./routes/backOffice/map/Map.svelte";
import Routes from "./routes/backOffice/routes/Routes.svelte";
import Warehouses from "./routes/backOffice/warehouses/Warehouses.svelte";
import Trucks from "./routes/backOffice/trucks/Trucks.svelte";
import Reports from "./routes/backOffice/reports/Reports.svelte";
import Employees from "./routes/backOffice/employees/Employees.svelte";
Expand All @@ -20,6 +19,7 @@
import url from "./lib/stores/url";
import ContainersRouter from "./routes/backOffice/containers/ContainersRouter.svelte";
import Toast from "./lib/components/Toast.svelte";
import WarehousesRouter from "./routes/backOffice/warehouses/WarehousesRouter.svelte";

onMount(() => {
if ($url.pathname === "/") {
Expand All @@ -36,10 +36,9 @@
<Route path={BackOfficeRouterPaths.EMPLOYEES} component={Employees} />
<Route path={BackOfficeRouterPaths.REPORTS} component={Reports} />
<Route path={BackOfficeRouterPaths.TRUCKS} component={Trucks} />
<Route
path={BackOfficeRouterPaths.WAREHOUSES}
component={Warehouses}
/>
<Route path={`${BackOfficeRouterPaths.WAREHOUSES}/*`}>
<WarehousesRouter />
</Route>
<Route path={`${BackOfficeRouterPaths.CONTAINERS}/*`}>
<ContainersRouter />
</Route>
Expand Down
19 changes: 19 additions & 0 deletions web/src/domain/warehouse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { components } from "../../api/ecomap/http";

/**
* Warehouse.
*/
export type Warehouse = components["schemas"]["Warehouse"];

/**
* Paginated warehouses.
*/
export type PaginatedWarehouses = components["schemas"]["WarehousesPaginated"];

/**
* Filters of warehouses.
*/
export interface WarehousesFilters {
pageIndex: number;
location: string;
}
2 changes: 1 addition & 1 deletion web/src/lib/components/Field.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* The value of the field.
* @default null
*/
export let value: string | null = null;
export let value: number | string | null = null;
</script>

<div>
Expand Down
38 changes: 37 additions & 1 deletion web/src/lib/components/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type {
ChangeEventHandler,
HTMLInputAttributes,
KeyboardEventHandler,
MouseEventHandler,
} from "svelte/elements";
import Icon from "./Icon.svelte";
Expand Down Expand Up @@ -30,6 +31,18 @@
*/
export let id: HTMLInputAttributes["id"] = null;

/**
* Defines the maximum value that is acceptable and valid for the input.
* @default null
*/
export let max: HTMLInputAttributes["max"] = null;

/**
* Defines the minimum value that is acceptable and valid for the input.
* @default null
*/
export let min: HTMLInputAttributes["min"] = null;

/**
* The name of the form control. Submitted with the form as part of a name/value pair.
* @default null
Expand All @@ -48,6 +61,12 @@
*/
export let onInput: ChangeEventHandler<HTMLInputElement> | null = null;

/**
* Callback fired when a key is pressed.
* @default null
*/
export let onKeyDown: KeyboardEventHandler<HTMLInputElement> | null = null;

/**
* The text that appears in the form control when it has no value set.
* @default null
Expand All @@ -60,6 +79,18 @@
*/
export let readonly: boolean = false;

/**
* Indicates that the user must specify a value for the input before the owning form can be submitted.
* @default false
*/
export let required: boolean = false;

/**
* CSS styling declarations to be applied to the element.
* @default null
*/
export let style: string | null = null;

/**
* The type of control to render.
* @default null
Expand All @@ -70,7 +101,7 @@
* The value of the input.
* @default null
*/
export let value: string | null = null;
export let value: number | string | null = null;
</script>

<div class="input-container">
Expand All @@ -83,6 +114,11 @@
{type}
{value}
{readonly}
{required}
{max}
{min}
{style}
on:keydown={onKeyDown}
on:input={onInput}
on:click={onClick}
data-endIcon={endIcon}
Expand Down
72 changes: 72 additions & 0 deletions web/src/lib/components/LocationInput.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script lang="ts">
import Input from "./Input.svelte";

/**
* Indicates if the input contains an error.
* @default false
*/
export let error: boolean = false;

/**
* The name of the form control. Submitted with the form as part of a name/value pair.
* @default null
*/
export let name: string | null = null;

/**
* Callback fired when input element is clicked.
* @default null
*/
export let onClick: (() => void) | null = null;

/**
* The text that appears in the form control when it has no value set.
* @default null
*/
export let placeholder: string | null = null;

/**
* Indicates that the user must specify a value for the input before the owning form can be submitted.
* @default false
*/
export let required: boolean = false;

/**
* The value of the input.
* @default null
*/
export let value: string | null = null;

/**
* Handle the keyboard event of the input by preventing typing a value inside the input.
* @param e Keyboard event.
*/
function handleKeyDown(e: KeyboardEvent) {
switch (e.key) {
// Ignore Tab key since it's used to interact with the HTML form element.
case "Tab":
break;

case "Enter":
onClick?.();
e.preventDefault();
break;

default:
e.preventDefault();
break;
}
}
</script>

<Input
{required}
{name}
{value}
{placeholder}
{error}
{onClick}
style="cursor: pointer; caret-color: transparent;"
endIcon="location_on"
onKeyDown={handleKeyDown}
/>
7 changes: 7 additions & 0 deletions web/src/lib/components/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
*/
export let placeholder: string | null = null;

/**
* Indicates that the user must specify a value for the input before the owning form can be submitted.
* @default false
*/
export let required: boolean = false;

/**
* The value of the select.
* @default ""
Expand All @@ -50,6 +56,7 @@
{name}
{value}
{placeholder}
{required}
on:change={onChange}
class={`${className} ${error ? "error" : ""}`}
>
Expand Down
9 changes: 8 additions & 1 deletion web/src/lib/components/SelectLocation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import {
DEFAULT_ANIMATION_DURATION,
DEFAULT_MAX_ZOOM,
DEFAULT_PIN_ICON_SRC,
} from "../constants/map";

/**
Expand Down Expand Up @@ -51,6 +52,12 @@
*/
export let onCancel: (() => void) | null = null;

/**
* Map layer style.
* @default "/images/pin.svg"
*/
export let iconSrc: string = DEFAULT_PIN_ICON_SRC;

/**
* Open Layers map.
*/
Expand All @@ -67,7 +74,7 @@
const layer = new VectorLayer({
source: new VectorSource<Feature<Point>>({ features: [] }),
style: {
"icon-src": "/images/pin.svg",
"icon-src": iconSrc,
},
});

Expand Down
5 changes: 3 additions & 2 deletions web/src/lib/components/map/mapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
colorLayerKey,
nameLayerKey,
DEFAULT_MAX_ZOOM,
CONTAINER_ICON_SRC,
} from "../../constants/map";
import type { Geometry } from "ol/geom";
import type Feature from "ol/Feature";
Expand Down Expand Up @@ -53,15 +54,15 @@ const defaultVectorStyle: VectorStyle = {
* Default style for WebGl point layer.
*/
const defaultIconStyle: WebGLStyle = {
"icon-src": "/images/logo.svg",
"icon-src": CONTAINER_ICON_SRC,
};

/**
* Default style for cluster point layer.
*/
const defaultClusterIcon = new Style({
image: new Icon({
src: "/images/logo.svg",
src: CONTAINER_ICON_SRC,
}),
});

Expand Down
15 changes: 15 additions & 0 deletions web/src/lib/constants/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,18 @@ export const OL_PROJECTION = "EPSG:3857";
* Resource geometry projection.
*/
export const RESOURCE_PROJECTION = "EPSG:4326";

/**
* Source location of the default pin icon.
*/
export const DEFAULT_PIN_ICON_SRC = "/images/pin.svg";

/**
* Source location of the container pin icon.
*/
export const CONTAINER_ICON_SRC = "/images/logo.svg";

/**
* Source location of the warehouse pin icon.
*/
export const WAREHOUSE_ICON_SRC = "/images/warehouse-pin.svg";
9 changes: 9 additions & 0 deletions web/src/lib/utils/i8n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function _locale(): Writable<string> {

localStorage.setItem("locale", supportedLocale);

// Set the supported locale in the lang attribute of the HTML element.
document.documentElement.setAttribute("lang", supportedLocale);

const store = writable(supportedLocale);
const { subscribe, set } = store;

Expand All @@ -82,6 +85,9 @@ function _locale(): Writable<string> {
const supportedLocale = getSupportedLocale(locale);
localStorage.setItem("locale", supportedLocale);

// Set the supported locale in the lang attribute of the HTML element.
document.documentElement.setAttribute("lang", supportedLocale);

// Refresh current page when switching locales.
location.reload();

Expand All @@ -93,6 +99,9 @@ function _locale(): Writable<string> {
const supportedLocale = getSupportedLocale(updatedLocale);
localStorage.setItem("locale", supportedLocale);

// Set the supported locale in the lang attribute of the HTML element.
document.documentElement.setAttribute("lang", supportedLocale);

// Refresh current page when switching locales.
location.reload();

Expand Down
Loading