Skip to content

Commit

Permalink
Merge pull request #3 from fleetbase/feature-livemap-vehicles-context
Browse files Browse the repository at this point in the history
Add vehicles to livemap with contextmenu and universe registration to…
  • Loading branch information
roncodes authored Oct 13, 2023
2 parents 8d9e775 + a139733 commit 49cbcd5
Show file tree
Hide file tree
Showing 55 changed files with 2,255 additions and 556 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

#server
/server
/server_vendor
5 changes: 5 additions & 0 deletions addon/components/context-panel.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if this.contextPanel.currentContextRegistry}}
{{#let this.contextPanel.currentContext this.contextPanel.currentContextRegistry this.contextPanel.currentContextComponentArguments as |model registry dynamicArgs|}}
{{component registry.component context=model dynamicArgs=dynamicArgs onPressCancel=this.contextPanel.clear}}
{{/let}}
{{/if}}
6 changes: 6 additions & 0 deletions addon/components/context-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

export default class ContextPanelComponent extends Component {
@service contextPanel;
}
44 changes: 22 additions & 22 deletions addon/components/driver-form-panel.hbs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @width="700">
<Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
<Overlay::Header @hideLeftSection={{true}} @actionsWrapperClass="flex-1 flex-col py-3" class="h-auto-i min-h-[127px]">
<div class="flex flex-row items-center justify-between w-full mb-4">
<div class="flex flex-1 space-x-2">
{{#if @driver.id}}
{{#if this.driver.id}}
<Button @type="default" @icon="id-card" @helpText="View driver details" @onClick={{this.viewDetails}} />
{{/if}}
</div>
<div class="flex flex-1 justify-end">
<div class="mr-2">
<Button @icon={{if @driver.id "save" "check"}} @type="primary" @text={{if @driver.id "Save Driver" "Create Driver"}} @onClick={{this.save}} />
<Button @icon={{if this.driver.id "save" "check"}} @type="primary" @text={{if this.driver.id "Save Driver" "Create Driver"}} @onClick={{this.save}} />
</div>
<Button @type="default" @icon="times" @helpText={{if @driver.id "Cancel edit driver" "Cancel new driver"}} @onClick={{@onPressCancel}} />
<Button @type="default" @icon="times" @helpText={{if this.driver.id "Cancel edit driver" "Cancel new driver"}} @onClick={{@onPressCancel}} />
</div>
</div>
<div class="flex flex-row justify-between w-full">
<div class="flex flex-col flex-1 w-3/4">
<div class="flex flex-row">
<div class="w-14 flex items-center justify-start">
<Image src={{@driver.photo_url}} @fallbackSrc={{config "defaultValues.driverImage"}} alt={{@driver.name}} height="48" width="48" class="h-12 w-12 rounded-lg shadow-sm" />
<Image src={{this.driver.photo_url}} @fallbackSrc={{config "defaultValues.driverImage"}} alt={{this.driver.name}} height="48" width="48" class="h-12 w-12 rounded-lg shadow-sm" />
<Attach::Tooltip @class="clean" @animation="scale" @placement={{"top"}}>
<InputInfo @text={{@driver.public_id}} />
<InputInfo @text={{this.driver.public_id}} />
</Attach::Tooltip>
</div>
<div class="flex flex-col pt-2">
<h1 class="text-gray-900 dark:text-white text-2xl">
{{#if @driver.id}}
{{@driver.name}}
{{#if this.driver.id}}
{{this.driver.name}}
{{else}}
{{#if @driver.name}}
{{@driver.name}}
{{#if this.driver.name}}
{{this.driver.name}}
{{else}}
<span>New Driver</span>
{{/if}}
{{/if}}
</h1>
<div class="-mt-1">
{{#if @driver.vehicle}}
{{#if this.driver.vehicle}}
<div class="flex flex-row items-center">
<span class="text-sm dark:text-gray-500 text-gray-700 mr-3">{{@driver.vehicle.displayName}}</span>
<span class="text-sm dark:text-gray-500 text-gray-700 mr-3">{{this.driver.vehicle.displayName}}</span>
</div>
{{else}}
<div class="flex flex-row items-center">
Expand All @@ -49,7 +49,7 @@
</div>
</div>
<div class="flex justify-end w-1/4">
<Badge @status={{@driver.status}} />
<Badge @status={{this.driver.status}} />
</div>
</div>
</Overlay::Header>
Expand All @@ -61,7 +61,7 @@
<label>
Name
</label>
<Input @value={{@driver.name}} @type="text" class="w-full form-input" placeholder="Name" />
<Input @value={{this.driver.name}} @type="text" class="w-full form-input" placeholder="Name" />
</div>
</div>

Expand All @@ -70,35 +70,35 @@
<label>
Internal ID
</label>
<Input @value={{@driver.internal_id}} @type="text" class="w-full form-input" placeholder="Internal ID" />
<Input @value={{this.driver.internal_id}} @type="text" class="w-full form-input" placeholder="Internal ID" />
</div>

<div class="input-group">
<label>
Drivers License
</label>
<Input @value={{@driver.drivers_license_number}} @type="text" class="w-full form-input" placeholder="Drivers License" />
<Input @value={{this.driver.drivers_license_number}} @type="text" class="w-full form-input" placeholder="Drivers License" />
</div>

<div class="input-group">
<label>
Email
</label>
<Input @value={{@driver.email}} @type="text" class="w-full form-input" placeholder="Email" />
<Input @value={{this.driver.email}} @type="text" class="w-full form-input" placeholder="Email" />
</div>

<div class="input-group">
<label>
Phone
</label>
<PhoneInput @value={{@driver.phone}} @onInput={{fn (mut @driver.phone)}} class="form-input w-full" />
<PhoneInput @value={{this.driver.phone}} @onInput={{fn (mut this.driver.phone)}} class="form-input w-full" />
</div>

<div class="input-group">
<label>
Vendor
</label>
<ModelSelect @modelName="vendor" @selectedModel={{@driver.vendor}} @placeholder="Select Vendor" @triggerClass="form-select form-input" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{fn (mut @driver.vendor)}} as |model|>
<ModelSelect @modelName="vendor" @selectedModel={{this.driver.vendor}} @placeholder="Select Vendor" @triggerClass="form-select form-input" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{fn (mut this.driver.vendor)}} as |model|>
{{model.name}}
</ModelSelect>
</div>
Expand All @@ -107,7 +107,7 @@
<label>
Vehicle
</label>
<ModelSelect @modelName="vehicle" @selectedModel={{@driver.vehicle}} @placeholder="Select Vehicle" @triggerClass="form-select form-input" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{fn (mut @driver.vehicle)}} as |model|>
<ModelSelect @modelName="vehicle" @selectedModel={{this.driver.vehicle}} @placeholder="Select Vehicle" @triggerClass="form-select form-input" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{fn (mut this.driver.vehicle)}} as |model|>
{{model.display_name}}
</ModelSelect>
</div>
Expand All @@ -116,14 +116,14 @@
<label>
City
</label>
<Input @value={{@driver.city}} @type="text" class="w-full form-input" placeholder="City" />
<Input @value={{this.driver.city}} @type="text" class="w-full form-input" placeholder="City" />
</div>

<div class="input-group">
<label>
Country
</label>
<CountrySelect class="w-full form-input form-select form-datalist" @value={{@driver.country}} @onChange={{fn (mut @driver.country)}} placeholder="Country" />
<CountrySelect class="w-full form-input form-select form-datalist" @value={{this.driver.country}} @onChange={{fn (mut this.driver.country)}} placeholder="Country" />
</div>
</div>
</div>
Expand Down
31 changes: 28 additions & 3 deletions addon/components/driver-form-panel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class DriverFormPanelComponent extends Component {
@service store;
@service notifications;
@service hostRouter;
@service contextPanel;
@service loader;
@tracked driver;

constructor() {
super(...arguments);
this.driver = this.args.driver;
this.applyDynamicArguments();
}

applyDynamicArguments() {
// Apply context if available
if (this.args.context) {
this.driver = this.args.context;
}

// Apply dynamic arguments if available
if (this.args.dynamicArgs) {
const keys = Object.keys(this.args.dynamicArgs);

keys.forEach((key) => {
this[key] = this.args.dynamicArgs[key];
});
}
}

@action save() {
const { driver, onAfterSave } = this.args;
const { driver } = this;
const { onAfterSave } = this.args;

this.loader.showLoader('.overlay-inner-content', 'Saving driver...');

Expand All @@ -33,7 +59,6 @@ export default class DriverFormPanelComponent extends Component {
}

@action viewDetails() {
const { driver } = this.args;
return this.hostRouter.transitionTo('console.fleet-ops.management.drivers.index.details', driver.public_id);
this.contextPanel.focus(this.driver, 'viewing');
}
}
16 changes: 8 additions & 8 deletions addon/components/driver-panel.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @width="700">
<Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
<Overlay::Header @hideLeftSection={{true}} @actionsWrapperClass="flex-1 flex-col py-3" class="h-auto-i min-h-[127px]">
<div class="flex flex-row items-center justify-between w-full mb-4">
<div class="flex flex-1 space-x-2">
Expand All @@ -13,17 +13,17 @@
<div class="flex flex-col flex-1 w-3/4">
<div class="flex flex-row">
<div class="w-14 flex items-center justify-start">
<Image src={{@driver.photo_url}} @fallbackSrc={{config "defaultValues.driverImage"}} alt={{@driver.name}} height="48" width="48" class="h-12 w-12 rounded-lg shadow-sm" />
<Image src={{this.driver.photo_url}} @fallbackSrc={{config "defaultValues.driverImage"}} alt={{this.driver.name}} height="48" width="48" class="h-12 w-12 rounded-lg shadow-sm" />
<Attach::Tooltip @class="clean" @animation="scale" @placement={{"top"}}>
<InputInfo @text={{@driver.public_id}} />
<InputInfo @text={{this.driver.public_id}} />
</Attach::Tooltip>
</div>
<div class="flex flex-col">
<h1 class="text-gray-900 dark:text-white text-2xl">{{@driver.name}}</h1>
<h1 class="text-gray-900 dark:text-white text-2xl">{{this.driver.name}}</h1>
<div class="-mt-1">
{{#if @driver.vehicle}}
{{#if this.driver.vehicle}}
<div class="flex flex-row items-center">
<span class="text-sm dark:text-gray-500 text-gray-700 mr-3">{{@driver.vehicle.displayName}}</span>
<span class="text-sm dark:text-gray-500 text-gray-700 mr-3">{{this.driver.vehicle.displayName}}</span>
</div>
{{else}}
<div class="flex flex-row items-center">
Expand All @@ -36,7 +36,7 @@
</div>
</div>
<div class="flex justify-end w-1/4">
<Badge @status={{@driver.status}} />
<Badge @status={{this.driver.status}} />
</div>
</div>
</Overlay::Header>
Expand All @@ -54,7 +54,7 @@
</div>
</div>
<div class="tab-content tab-{{this.currentTab}}">
{{component this.tab.component driver=@driver tabOptions=this.tab params=this.tab.componentParams}}
{{component this.tab.component driver=this.driver tabOptions=this.tab params=this.tab.componentParams}}
</div>
</Overlay::Body>
</Overlay>
29 changes: 23 additions & 6 deletions addon/components/driver-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export default class DriverPanelComponent extends Component {
@service universe;
@service store;
@service hostRouter;
@service contextPanel;
@tracked currentTab;
@tracked devices = [];
@tracked deviceApi = {};
@tracked vehicle;
@tracked driver;

get tabs() {
const registeredTabs = this.universe.getMenuItemsFromRegistry('component:driver-panel');
Expand All @@ -38,11 +39,28 @@ export default class DriverPanelComponent extends Component {

constructor() {
super(...arguments);
this.vehicle = this.args.vehicle;
this.changeTab(this.args.tab || 'details');
this.driver = this.args.driver;
this.changeTab(this.args.tab);
this.applyDynamicArguments();
}

@action async changeTab(tab) {
applyDynamicArguments() {
// Apply context if available
if (this.args.context) {
this.driver = this.args.context;
}

// Apply dynamic arguments if available
if (this.args.dynamicArgs) {
const keys = Object.keys(this.args.dynamicArgs);

keys.forEach((key) => {
this[key] = this.args.dynamicArgs[key];
});
}
}

@action async changeTab(tab = 'details') {
this.currentTab = tab;

if (typeof this.args.onTabChanged === 'function') {
Expand All @@ -51,7 +69,6 @@ export default class DriverPanelComponent extends Component {
}

@action editDriver() {
const { driver } = this.args;
return this.hostRouter.transitionTo('console.fleet-ops.management.drivers.index.edit', driver.public_id);
this.contextPanel.focus(this.driver, 'editing');
}
}
2 changes: 1 addition & 1 deletion addon/components/fleet-vehicle-listing.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<div class="w-56">
{{#if @onAddVehicle}}
<ModelSelect @modelName="vehicle" @selectedModel={{@options.selectedVehicle}} @placeholder="Add vehicle to fleet" @triggerClass="form-select form-input form-select-sm form-input-sm" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{this.onAdd}} as |model|>
<ModelSelect @modelName="vehicle" @query={{hash assignedFleet=false}} @selectedModel={{@options.selectedVehicle}} @placeholder="Add vehicle to fleet" @triggerClass="form-select form-input form-select-sm form-input-sm" @infiniteScroll={{false}} @renderInPlace={{true}} @onChange={{this.onAdd}} as |model|>
{{model.display_name}}
</ModelSelect>
{{/if}}
Expand Down
Loading

0 comments on commit 49cbcd5

Please sign in to comment.