Skip to content
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
29 changes: 1 addition & 28 deletions addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,16 @@ import Engine from '@ember/engine';
import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';
import config from './config/environment';
import services from '@fleetbase/ember-core/exports/services';
import { RoutingControl } from '@fleetbase/fleetops-engine/services/leaflet-routing-control';
import { services, externalRoutes } from '@fleetbase/ember-core/exports';

const { modulePrefix } = config;
const externalRoutes = ['console', 'extensions'];
const FLEETOPS_ENGINE_NAME = '@fleetbase/fleetops-engine';
const L = window.L ?? {};

export default class ValhallaEngine extends Engine {
modulePrefix = modulePrefix;
Resolver = Resolver;
dependencies = {
services,
externalRoutes,
};
engineDependencies = [FLEETOPS_ENGINE_NAME];
/* eslint no-unused-vars: "off" */
setupExtension = function (app, engine, universe) {
const routeOptimization = app.lookup('service:route-optimization');
const valhalla = app.lookup('service:valhalla');
if (routeOptimization && valhalla) {
routeOptimization.register('valhalla', valhalla);
}

// Register Valhalla Routing Control
const leafletRoutingControl = app.lookup('service:leaflet-routing-control');
if (leafletRoutingControl) {
leafletRoutingControl.register(
'valhalla',
new RoutingControl({
name: 'Valhalla',
router: new L.Routing.Valhalla(),
formatter: new L.Routing.Valhalla.Formatter(),
})
);
}
};
}

loadInitializers(ValhallaEngine, modulePrefix);
15 changes: 15 additions & 0 deletions addon/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
setupExtension(app, universe) {
// Register Valhalla Route Optimization
universe.whenEngineLoaded('@fleetbase/fleetops-engine', this.registerValhalla);
},

async registerValhalla(fleetopsEngine, universe) {
const valhallaEngine = await universe.extensionManager.ensureEngineLoaded('@fleetbase/valhalla-engine');
const routeOptimization = fleetopsEngine.lookup('service:route-optimization');
const valhalla = valhallaEngine.lookup('service:valhalla');
if (routeOptimization && valhalla) {
routeOptimization.register('valhalla', valhalla);
}
},
};
22 changes: 22 additions & 0 deletions addon/instance-initializers/register-valhalla-routing-control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { RoutingControl } from '@fleetbase/fleetops-engine/services/leaflet-routing-control';

const L = window.L ?? {};
export function initialize(owner) {
const universe = owner.lookup('service:universe');
const app = universe.getApplicationInstance();
const leafletRoutingControl = app.lookup('service:leaflet-routing-control');
if (leafletRoutingControl) {
leafletRoutingControl.register(
'valhalla',
new RoutingControl({
name: 'Valhalla',
router: new L.Routing.Valhalla(),
formatter: new L.Routing.Valhalla.Formatter(),
})
);
}
}

export default {
initialize,
};
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/valhalla-api",
"version": "0.0.1",
"version": "0.0.2",
"description": "Valhalla routing engine extension for Fleetbase",
"keywords": [
"fleetbase",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "valhalla",
"version": "0.0.1",
"version": "0.0.2",
"description": "Valhalla routing engine integration extension",
"repository": "https://github.com/fleetbase/valhalla",
"license": "AGPL-3.0-or-later",
Expand Down
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,48 @@ const { buildEngine } = require('ember-engines/lib/engine-addon');
const { name } = require('./package');
const Funnel = require('broccoli-funnel');

function isDevServe() {
// env checks
const env = process.env.EMBER_ENV || process.env.NODE_ENV || 'development';
const isProd = env === 'production' || process.env.CI === 'true';

// command-line checks (serve/watch only)
const argv = process.argv.join(' ');
const isServeCmd = /\b(ember|node).* (serve|server)\b/.test(argv) || process.argv.includes('serve') || process.argv.includes('server');
const isWatch = process.argv.includes('--watch') || process.env.BROCCOLI_WATCHER;

return !isProd && (isServeCmd || isWatch);
}

module.exports = buildEngine({
name,

init() {
if (this._super.init) this._super.init.apply(this, arguments);

if (isDevServe()) {
for (let addon of this.addons || []) {
if (['@fleetbase/ember-core', '@fleetbase/ember-ui'].includes(addon.name)) {
let origTreeFor = addon.treeFor?.bind(addon);
addon.treeFor = function (type) {
if (type === 'styles') {
return undefined;
}
return origTreeFor ? origTreeFor(type) : undefined;
};
}
}

const origNonDup = this.nonDuplicatedAddonInvoke?.bind(this);
this.nonDuplicatedAddonInvoke = (hook, args = []) => {
if (hook === 'treeFor' && args[0] === 'styles') {
return []; // prevents dependency style relocation funnel (dev-only)
}
return origNonDup ? origNonDup(hook, args) : [];
};
}
},

postprocessTree(type, tree) {
if (type === 'css') {
tree = new Funnel(tree, {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/valhalla-engine",
"version": "0.0.1",
"version": "0.0.2",
"description": "Valhalla routing engine extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand Down Expand Up @@ -42,8 +42,8 @@
},
"dependencies": {
"@babel/core": "^7.23.2",
"@fleetbase/ember-core": "latest",
"@fleetbase/ember-ui": "latest",
"@fleetbase/ember-core": "^0.3.7",
"@fleetbase/ember-ui": "^0.3.12",
"@fleetbase/leaflet-routing-machine": "^3.2.17",
"@fortawesome/ember-fontawesome": "^2.0.0",
"@fortawesome/fontawesome-svg-core": "6.4.0",
Expand Down
Loading
Loading