Skip to content

Commit

Permalink
Remove unused and duplicate code around onInitiativeClicked
Browse files Browse the repository at this point in the history
  • Loading branch information
rogup committed Apr 15, 2024
1 parent 5ba90bd commit 339a23e
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 138 deletions.
57 changes: 33 additions & 24 deletions src/map-app/app/map-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MapUI {
});
};

EventBus.Directory.initiativeClicked.sub(initiative => this.onInitiativeClickedInSidebar(initiative));
EventBus.Map.initiativeClicked.sub(initiative => this.onInitiativeClicked(initiative));
EventBus.Map.resetSearch.sub(() => this.resetSearch());
}

Expand Down Expand Up @@ -143,23 +143,18 @@ export class MapUI {
}

isSelected(initiative: Initiative): boolean {
// Currently unimplemented - I can see an sea-initiative-active class
// being applied if a test was true, but it makes no sense in the current
// context AFAICT. The test was:
// initiative === this.contextStack.current()?.initiatives[0]

// The main thing is seemed to do is highlight an initiative (or
// initiatives) in the directory pop-out list of initiatives in a
// category.

// For now, just return false always. We may re-implement this later.
return false;
const selectedInitiatives = this.mapPresenter?.getSelectedInitiatives() ?? [];
return selectedInitiatives.includes(initiative);
}

toggleSelectInitiative(initiative: Initiative) {
// Currently unimplemented.
const selectedInitiatives = this.mapPresenter?.getSelectedInitiatives() ?? [];

// EventBus.Markers.needToShowLatestSelection.pub(lastContent.initiatives);
if (selectedInitiatives.includes(initiative)) {
EventBus.Markers.needToShowLatestSelection.pub(selectedInitiatives.filter(i => i !== initiative));
} else {
EventBus.Markers.needToShowLatestSelection.pub([...selectedInitiatives, initiative]);
}
}

performSearch(text: string) {
Expand Down Expand Up @@ -195,21 +190,35 @@ export class MapUI {
});
}

private notifyMapNeedsToNeedsToBeZoomedAndPannedOneInitiative(initiative: Initiative) {
const data = EventBus.Map.mkSelectAndZoomData([initiative]);
EventBus.Map.needsToBeZoomedAndPanned.pub(data);
private notifyMapNeedsToNeedsToSelectAndZoomOnInitiative(initiative: Initiative) {
const maxZoom = this.config.getMaxZoomOnOne();
const defaultPos = this.config.getDefaultLatLng();

const data = EventBus.Map.mkSelectAndZoomData([initiative], { maxZoom, defaultPos });
EventBus.Map.selectAndZoomOnInitiative.pub(data);
}

private onInitiativeClickedInSidebar(initiative?: Initiative) {
if (!initiative)
return;
private onInitiativeClicked(initiative?: Initiative) {
console.log('Clicked', initiative);

//this.parent.mapui.stateManager.append(new SearchResults([initiative]));
//console.log(this.parent.mapui.stateManager.current());
if (initiative) {
// Move the window to the right position first
this.notifyMapNeedsToNeedsToSelectAndZoomOnInitiative(initiative);
this.refreshSidebar();
// Populate the sidebar and highlight the intiative in the directory
this.getSidebarPresenter(this).then((presenter) => {
presenter.populateInitiativeSidebar(
initiative,
this.markers.getInitiativeContent(initiative) ?? ''
);
});
}
else {
// User has deselected
EventBus.Markers.needToShowLatestSelection.pub([]);
}

this.notifyMapNeedsToNeedsToBeZoomedAndPannedOneInitiative(initiative);
this.refreshSidebar();
EventBus.Initiative.searchedInitiativeClicked.pub(initiative);
}

currentItem() {
Expand Down
11 changes: 7 additions & 4 deletions src/map-app/app/presenter/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MapUI } from '../map-ui';

export class MapPresenter extends BasePresenter {
readonly view: MapView;
private previouslySelected: Initiative[] = [];
private currentlySelected: Initiative[] = [];

constructor(readonly mapUI: MapUI) {
super();
Expand Down Expand Up @@ -49,7 +49,7 @@ export class MapPresenter extends BasePresenter {
}

onInitiativeClicked() {
EventBus.Directory.initiativeClicked.pub(undefined);
EventBus.Map.initiativeClicked.pub(undefined);
}

onLoad() {
Expand Down Expand Up @@ -96,11 +96,11 @@ export class MapPresenter extends BasePresenter {
}

onMarkersNeedToShowLatestSelection(selected: Initiative[]) {
this.previouslySelected.forEach((initiative) => {
this.currentlySelected.forEach((initiative) => {
this.mapUI.markers.setUnselected(initiative);
});

this.previouslySelected = selected;
this.currentlySelected = selected;

//zoom in and then select
selected.forEach((initiative) => {
Expand Down Expand Up @@ -144,4 +144,7 @@ export class MapPresenter extends BasePresenter {
this.view.selectAndZoomOnInitiative(data);
}

getSelectedInitiatives(): Initiative[] {
return this.currentlySelected;
}
}
5 changes: 5 additions & 0 deletions src/map-app/app/presenter/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Dictionary } from '../../common-types';
import { EventBus } from '../../eventbus';
import { MapUI } from '../map-ui';
import { Initiative } from '../model/initiative';
import { SidebarView } from '../view/sidebar';
import { BasePresenter } from './base';
import { AboutSidebarPresenter } from './sidebar/about';
Expand Down Expand Up @@ -97,6 +98,10 @@ export class SidebarPresenter extends BasePresenter {
this.view.hideInitiativeSidebar();
}

populateInitiativeSidebar(initiative: Initiative, initiativeContent: string) {
this.view.populateInitiativeSidebar(initiative, initiativeContent);
}

showInitiativeList() {
this.view.showInitiativeList();
}
Expand Down
2 changes: 1 addition & 1 deletion src/map-app/app/presenter/sidebar/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export abstract class BaseSidebarPresenter extends BasePresenter {
}

onInitiativeClicked(initiative: Initiative): void {
EventBus.Directory.initiativeClicked.pub(initiative);
EventBus.Map.initiativeClicked.pub(initiative);
}

onInitiativeMouseoverInSidebar(initiative: Initiative): void {
Expand Down
36 changes: 0 additions & 36 deletions src/map-app/app/presenter/sidebar/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ export class DirectorySidebarPresenter extends BaseSidebarPresenter {
//todo reload new ones inside instead (without closing)
EventBus.Sidebar.hideInitiativeList.pub();
});
EventBus.Directory.initiativeClicked.sub(initiative => this.initiativeClicked(initiative));
}

notifyMapNeedsToNeedsToSelectInitiative(initiatives: Initiative[]): void {
if (initiatives.length == 0)
return;

const maxZoom = initiatives.length === 1? this.parent.mapui.config.getMaxZoomOnGroup() : undefined;
const defaultPos = this.parent.mapui.config.getDefaultLatLng();

const data = EventBus.Map.mkSelectAndZoomData(initiatives, { maxZoom, defaultPos });
EventBus.Map.selectAndZoomOnInitiative.pub(data);
}

onInitiativeMouseoverInSidebar(initiative: Initiative): void {
Expand All @@ -39,30 +27,6 @@ export class DirectorySidebarPresenter extends BaseSidebarPresenter {
EventBus.Map.needToHideInitiativeTooltip.pub(initiative);
}

initiativeClicked(initiative?: Initiative): void {
if (initiative) {
//this.parent.contentStack.append(new SearchResults([initiative]));
// Move the window to the right position first
this.notifyMapNeedsToNeedsToSelectInitiative([initiative]);

// Populate the sidebar and highlight the intiative in the directory
this.view.populateInitiativeSidebar(
initiative,
this.parent.mapui.markers.getInitiativeContent(initiative) ?? ''
);

}
else {
// User has deselected
// TODO: This probably shouldn\t be here
EventBus.Markers.needToShowLatestSelection.pub([]);
// Deselect the sidebar and hoghlight the iitiative in the directory
this.view.deselectInitiativeSidebar();

//doesn't do much?
}
}

// This gets the localised 'allEntries' label in all cases.
//
// It used to facilitate a hack as per issue #177. Leaving here as a
Expand Down
5 changes: 0 additions & 5 deletions src/map-app/app/presenter/sidebar/initiatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class InitiativesSidebarPresenter extends BaseSidebarPresenter {

_eventbusRegister(): void {
EventBus.Marker.selectionToggled.sub(initiative => this.onMarkerSelectionToggled(initiative));
EventBus.Initiative.searchedInitiativeClicked.sub(initiative => this.searchedInitiativeClicked(_toString(initiative.uri, undefined)));
}

constructor(readonly parent: SidebarPresenter) {
Expand Down Expand Up @@ -54,10 +53,6 @@ export class InitiativesSidebarPresenter extends BaseSidebarPresenter {
this.view.refresh();
}

searchedInitiativeClicked(uri?: string) {
if (uri) this.view.onInitiativeClicked(uri);
}

performSearch(text: string) {
this.parent.mapui.performSearch(text);
}
Expand Down
4 changes: 2 additions & 2 deletions src/map-app/app/view/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class MapView extends BaseView {

this.map.zoomControl.setPosition("bottomright");

this.map.on('click', (e) => this.onInitiativeClicked(e));
this.map.on('click', (e) => this.onMapClicked(e));
this.map.on('load', (e) => this.onLoad(e));
this.map.on('resize', (e) => this.onResize(e));

Expand Down Expand Up @@ -221,7 +221,7 @@ export class MapView extends BaseView {
}
}

private onInitiativeClicked(me: leaflet.LeafletMouseEvent): void {
private onMapClicked(me: leaflet.LeafletMouseEvent): void {
// Deselect any selected markers
if (me.originalEvent.ctrlKey && me.latlng) {
MapView.copyTextToClipboard(me.latlng.lat + "," + me.latlng.lng);
Expand Down
6 changes: 2 additions & 4 deletions src/map-app/app/view/map/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ export class MapMarkerView extends BaseView {
this.presenter.notifySelectionToggled(this.presenter.initiative);
} else {
console.log(this.presenter.initiative);
EventBus.Directory.initiativeClicked.pub(this.presenter.initiative);
EventBus.Map.initiativeClicked.pub(this.presenter.initiative);
}
}

setUnselected(initiative: Initiative) {
//close pop-up
this.presenter.mapUI.map?.closePopup();
//close information on the left hand side (for smaller screens)
EventBus.Sidebar.hideInitiative.pub();
//reset the map vars and stop the zoom event from triggering selectInitiative ({target}) method

//change the color of an initiative with a location
Expand Down Expand Up @@ -209,7 +207,7 @@ export class MapMarkerView extends BaseView {
let deselectInitiative = (e: leaflet.LeafletEvent) => {
if (factory.geoClusterGroup.getVisibleParent(marker) !== marker) {
this.setUnselected(initiative);
EventBus.Directory.initiativeClicked.pub(undefined); // deselects
EventBus.Map.initiativeClicked.pub(undefined); // deselects
factory.geoClusterGroup.off("animationend", deselectInitiative);
}
}
Expand Down
35 changes: 34 additions & 1 deletion src/map-app/app/view/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as d3 from 'd3';
import { SidebarPresenter } from '../presenter/sidebar';
import { BaseView } from './base';
import { getViewportWidth } from '../../utils';
import { Initiative } from '../model/initiative';

export class SidebarView extends BaseView {

Expand Down Expand Up @@ -231,5 +232,37 @@ export class SidebarView extends BaseView {
.classed("sea-sidebar-list-initiatives", false);

d3.select(".w3-btn").attr("title", this.presenter.mapui.labels.hideDirectory);
}
}

populateInitiativeSidebar(initiative: Initiative, initiativeContent: string) {
// Highlight the correct initiative in the directory
// d3.select(".sea-initiative-active").classed("sea-initiative-active", false);
// d3.select('[data-uid="' + initiative.uri + '"]').classed(
// "sea-initiative-active",
// true
// );
let initiativeSidebar = d3.select("#sea-initiative-sidebar");
let initiativeContentElement = this.d3selectAndClear(
"#sea-initiative-sidebar-content"
);
initiativeContentElement
.append("button")
.attr("class", "w3-button w3-border-0 ml-auto sidebar-button")
.attr("title", `${this.presenter.mapui.labels.close} ${initiative.name}`)
.on("click", () => EventBus.Map.initiativeClicked.pub(undefined))
.append("i")
.attr("class", "fa " + "fa-times");
initiativeContentElement
.append("div")
.html(initiativeContent);
initiativeSidebar.classed("sea-initiative-sidebar-open", true);

if (getViewportWidth() <= 800)
EventBus.Sidebar.showSidebar.pub();
}

// deselectInitiativeSidebar() {
// d3.select(".sea-initiative-active").classed("sea-initiative-active", false);
// d3.select("#sea-initiative-sidebar").classed("sea-initiative-sidebar-open", false);
// }
}
39 changes: 0 additions & 39 deletions src/map-app/app/view/sidebar/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DirectorySidebarPresenter } from "../../presenter/sidebar/directory";
import { d3Selection } from "../d3-utils";
import { BaseSidebarView } from "./base";
import { propDefToVocabUri } from "../../model/data-services";
import { getViewportWidth } from "../../../utils";

function uriToTag(uri: string) {
return uri.toLowerCase().replace(/^.*[:\/]/, "");
Expand Down Expand Up @@ -165,42 +164,4 @@ export class DirectorySidebarView extends BaseSidebarView {
if (values)
addItems(directoryPropName, values);
}

populateInitiativeSidebar(initiative: Initiative, initiativeContent: string) {
// Highlight the correct initiative in the directory
d3.select(".sea-initiative-active").classed("sea-initiative-active", false);
d3.select('[data-uid="' + initiative.uri + '"]').classed(
"sea-initiative-active",
true
);
let initiativeSidebar = d3.select("#sea-initiative-sidebar");
let initiativeContentElement = this.d3selectAndClear(
"#sea-initiative-sidebar-content"
);
initiativeContentElement
.append("button")
.attr("class", "w3-button w3-border-0 ml-auto sidebar-button")
.attr("title", `${this.presenter.parent.mapui.labels.close} ${initiative.name}`)
.on("click", () => EventBus.Directory.initiativeClicked.pub(undefined))
.append("i")
.attr("class", "fa " + "fa-times");
initiativeContentElement
.append("div")
.html(initiativeContent);
initiativeSidebar.classed("sea-initiative-sidebar-open", true);

if (getViewportWidth() <= 800)
EventBus.Sidebar.showSidebar.pub();
}

deselectInitiativeSidebar() {
d3.select(".sea-initiative-active").classed("sea-initiative-active", false);
let initiativeSidebar = d3.select("#sea-initiative-sidebar");
// let initiativeContentElement = d3.select("#sea-initiative-sidebar-content");
// initiativeContentElement.html(initiativeContent);
initiativeSidebar.classed("sea-initiative-sidebar-open", false);
d3.select(".sea-search-initiative-active")
.classed("sea-search-initiative-active", false);
}

}
11 changes: 0 additions & 11 deletions src/map-app/app/view/sidebar/initiatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ export class InitiativesSidebarView extends BaseSidebarView {
this.createApplyFiltersButton(container);
}

onInitiativeClicked(id: string) {
d3.select(".sea-search-initiative-active")
.classed("sea-search-initiative-active", false);

d3.select('[data-uid="' + id + '"]')
.classed(
"sea-search-initiative-active",
true
);
}

getSearchText(): string {
return d3.select("#search-box").property("value");
}
Expand Down
Loading

0 comments on commit 339a23e

Please sign in to comment.