Skip to content

Commit

Permalink
refactor: move options interfaces to same file
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin committed Mar 5, 2025
1 parent 1f55d00 commit 5ca8478
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 42 deletions.
14 changes: 7 additions & 7 deletions source/js/load.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SaveData } from "./types";
import { LoadOptionDataInterface } from "./options/optionFeature";
import { SaveData, SavedImageOverlayData, SavedLayerGroup, SavedMarkerData, SavedStartPosition } from "./types";

class LoadHiddenField {
data: SaveData|undefined;
data: SaveData;

constructor(
private hiddenField: HTMLInputElement,
Expand All @@ -16,11 +17,10 @@ class LoadHiddenField {
return;
}

this.loadLayerGroupsInstance.load(this.data?.layerGroups);
this.loadMarkersInstance.load(this.data?.markers);
this.loadImageOverlaysInstance.load(this.data?.imageOverlays);
this.loadStartPositionInstance.load(this.data?.startPosition);

this.loadLayerGroupsInstance.load(this.data.layerGroups as SavedLayerGroup);
this.loadMarkersInstance.load(this.data.markers as SavedMarkerData);
this.loadImageOverlaysInstance.load(this.data.imageOverlays as SavedImageOverlayData);
this.loadStartPositionInstance.load(this.data.startPosition as SavedStartPosition);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/js/options/createImageOverlay/loadImageOverlays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SavedImageOverlayData } from "../../types";
import { LoadOptionDataInterface } from "../optionFeature";

class LoadImageOverlays implements LoadOptionDataInterface {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OptionFeature } from "../optionFeature";

class OptionCreateImageOverlay implements OptionFeature {
protected condition: string = 'create_image_overlay';

Expand Down
2 changes: 1 addition & 1 deletion source/js/options/createImageOverlay/saveImageOverlays.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SavedImageOverlayData } from "../../types";
import { SaveOptionDataInterface } from "../saveOptionData";
import { SaveOptionDataInterface } from "../optionFeature";
import ImageOverlayData from "./imageOverlayData";

class SaveImageOverlays implements SaveOptionDataInterface {
Expand Down
1 change: 1 addition & 0 deletions source/js/options/createLayerGroup/loadLayerGroups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SavedLayerGroup } from "../../types";
import { LoadOptionDataInterface } from "../optionFeature";
import { LayerGroupFactoryInterface } from "./layerGroupFactoryInterface";

class LoadLayerGroups implements LoadOptionDataInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OptionFeature } from "../optionFeature";
import { LayerGroupFactoryInterface } from "./layerGroupFactoryInterface";

class OptionCreateLayerGroup implements OptionFeature {
Expand Down
2 changes: 1 addition & 1 deletion source/js/options/createLayerGroup/saveLayerGroups.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SavedLayerGroup } from "../../types";
import { SaveOptionDataInterface } from "../saveOptionData";
import { SaveOptionDataInterface } from "../optionFeature";
import LayerGroupData from "./layerGroupData";

class SaveLayerGroups implements SaveOptionDataInterface {
Expand Down
1 change: 1 addition & 0 deletions source/js/options/createMarker/loadMarkers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SavedMarkerData } from "../../types";
import { LoadOptionDataInterface } from "../optionFeature";
import { MarkerFactoryInterface } from "./markerFactoryInterface";

class LoadMarkers implements LoadOptionDataInterface {
Expand Down
1 change: 1 addition & 0 deletions source/js/options/createMarker/optionCreateMarker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MapInterface } from "@helsingborg-stad/openstreetmap";
import { MarkerFactoryInterface } from "./markerFactoryInterface";
import { OptionFeature } from "../optionFeature";

class OptionCreateMarker implements OptionFeature {
protected condition: string = 'create_marker';
Expand Down
2 changes: 1 addition & 1 deletion source/js/options/createMarker/saveMarkers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SavedMarkerData } from "../../types";
import { SaveOptionDataInterface } from "../saveOptionData";
import { SaveOptionDataInterface } from "../optionFeature";
import MarkerData from "./markerData";

class SaveMarkers implements SaveOptionDataInterface {
Expand Down
3 changes: 0 additions & 3 deletions source/js/options/loadOptionData.d.ts

This file was deleted.

11 changes: 11 additions & 0 deletions source/js/options/optionFeature.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { SavedImageOverlayData, SavedLayerGroup, SavedMarkerData, SavedStartPosition } from "../types";
import SaveLayerGroups from "./createLayerGroup/saveLayerGroups";

interface OptionFeature {
checkCondition(value: string): boolean;
}

interface SaveOptionDataInterface {
save(): SavedMarkerData|SavedStartPosition|SavedImageOverlayData|SavedLayerGroup;
}

interface LoadOptionDataInterface {
load(data: SavedMarkerData|SavedStartPosition|SavedImageOverlayData|SavedLayerGroup): void;
}
6 changes: 0 additions & 6 deletions source/js/options/saveOptionData.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions source/js/options/startPosition/loadStartPosition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SavedStartPosition } from "../../types";
import { LoadOptionDataInterface } from "../optionFeature";
import { OptionSetStartPositionInterface } from "./optionSetStartPositionInterface";

class LoadStartPosition implements LoadOptionDataInterface {
Expand Down
1 change: 1 addition & 0 deletions source/js/options/startPosition/optionSetStartPosition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MapInterface, CreateMarkerInterface, MarkerInterface, LatLngObject } from "@helsingborg-stad/openstreetmap";
import { OptionSetStartPositionInterface } from "./optionSetStartPositionInterface";
import { OptionFeature } from "../optionFeature";

class OptionSetStartPosition implements OptionFeature, OptionSetStartPositionInterface {
protected condition: string = 'set_start_position';
Expand Down
2 changes: 1 addition & 1 deletion source/js/options/startPosition/saveStartPosition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SavedStartPosition } from "../../types";
import { SaveOptionDataInterface } from "../saveOptionData";
import { SaveOptionDataInterface } from "../optionFeature";
import { OptionSetStartPositionInterface } from "./optionSetStartPositionInterface";

class SaveStartPostion implements SaveOptionDataInterface {
Expand Down
23 changes: 1 addition & 22 deletions source/js/save.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SaveOptionDataInterface } from "./options/saveOptionData";
import { SaveOptionDataInterface } from "./options/optionFeature";
import { SaveData, SavedImageOverlayData, SavedLayerGroup, SavedMarkerData, SavedStartPosition } from "./types";

declare const acf: any;
Expand All @@ -18,27 +18,6 @@ class SaveHiddenField {
private saveImageOverlays: SaveOptionDataInterface,
private saveStartPosition: SaveOptionDataInterface
) {
document.querySelector('[data-js-value="set_start_position"]')?.addEventListener('click', () => {
const layerGroups = this.saveLayerGroups.save() as SavedLayerGroup;
const markers = this.saveMarkers.save() as SavedMarkerData;
const imageOverlays = this.saveImageOverlays.save() as SavedImageOverlayData;
const startPosition = this.saveStartPosition.save() as SavedStartPosition;
const data: SaveData = {
markers: markers,
layerGroups: layerGroups,
imageOverlays: imageOverlays,
startPosition: startPosition
};

markers?.forEach((marker) => {
console.log("HELLO")
});
const json = JSON.stringify(this.data);
this.hiddenField.value = json;

// console.log(json);
});

acf.add_filter('validation_complete', (values: any, form: any) => {
this.data.layerGroups = this.saveLayerGroups.save() as SavedLayerGroup;
this.data.markers = this.saveMarkers.save() as SavedMarkerData;
Expand Down

0 comments on commit 5ca8478

Please sign in to comment.