Skip to content

Commit

Permalink
Merge pull request #102 from fleetbase/dev-v0.4.24
Browse files Browse the repository at this point in the history
v0.4.24
  • Loading branch information
roncodes authored Apr 2, 2024
2 parents 12f92d8 + 817b967 commit ece7edf
Show file tree
Hide file tree
Showing 38 changed files with 600 additions and 164 deletions.
76 changes: 0 additions & 76 deletions addon/components/admin/navigator-app.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,4 @@
<InputInfo>{{t "fleet-ops.component.admin.navigator-app.message" htmlSafe=true companyName=@app.name}}</InputInfo>
</Attach::Tooltip>
</InputGroup>
</ContentPanel>

<ContentPanel @title={{t "fleet-ops.component.admin.navigator-app.settings"}} @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<InputGroup>
<div class="flex items-center">
<Toggle @isToggled={{this.isEntityFieldsEditable}} @onToggle={{this.enableEditableEntityFields}} />
<div class="ml-2">{{t "fleet-ops.component.admin.navigator-app.select-input"}}</div>
</div>
</InputGroup>
{{#if this.isEntityFieldsEditable}}
<OrderConfigManager @onConfigChanged={{this.onConfigChanged}} as |Action Context|>
<div class="mt-2">
<InputGroup @name="Select order config" @helpText="Apply entity editing settings for an order config.">
<DropdownButton
class="order-config-select-button mr-2"
@disabled={{not Context.configs}}
@text={{if Context.currentConfig.name Context.currentConfig.name (t "fleet-ops.component.order-config-manager.select-order-config")}}
@textClass="text-sm mr-2"
@buttonClass="flex-row-reverse w-44 justify-between"
@icon="caret-down"
@iconClass="mr-0i"
@size="sm"
@iconPrefix="fas"
@triggerClass="hidden md:flex"
as |dd|
>
<div class="next-dd-menu mt-1 mx-0" aria-labelledby="user-menu">
<div class="p-1">
{{#each Context.configs as |orderConfig|}}
<a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd Context.selectConfig orderConfig)}}>
<div class="flex-1 flex flex-row items-center">
<div class="w-6">
<FaIcon @icon="cogs" />
</div>
<span>{{orderConfig.name}}</span>
</div>
<div>
{{#if (eq Context.currentConfig.id orderConfig.id)}}
<FaIcon @icon="check" class="text-green-500" />
{{/if}}
</div>
</a>
{{/each}}
</div>
</div>
</DropdownButton>
</InputGroup>
</div>
</OrderConfigManager>
{{#if this.selectedOrderConfig}}
<div class="bg-gray-400 border-gray-600 rounded-lg px-4 py-2 dark:bg-gray-700 dark:border-gray-800">
{{#let (get (get this.entityEditingSettings this.selectedOrderConfig.id) "editable_entity_fields") as |editableEntityFields|}}
{{#each this.entityFields as |entityField|}}
<div class="mt-1">
<Checkbox
@value={{includes entityField editableEntityFields}}
@label={{smart-humanize entityField}}
@onToggle={{fn this.toggleFieldEditable entityField}}
@helpText={{t "fleet-ops.component.admin.visibility-controls.checkbox-text"}}
/>
</div>
{{/each}}
{{/let}}
</div>
<div class="mt-3 flex items-center">
<Button
@type="primary"
@size="lg"
@icon="save"
@text={{t "fleet-ops.common.save-changes"}}
@onClick={{perform this.saveEntityEditingSettings}}
@isLoading={{not this.saveEntityEditingSettings.isIdle}}
/>
</div>
{{/if}}
{{/if}}
</ContentPanel>
58 changes: 0 additions & 58 deletions addon/components/admin/navigator-app.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,15 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import { task } from 'ember-concurrency-decorators';

export default class NavigatorAppControlsComponent extends Component {
@service fetch;
@tracked isLoading = false;
@tracked url;
@tracked selectedOrderConfig;
@tracked entityFields = ['name', 'description', 'sku', 'height', 'width', 'length', 'weight', 'declared_value', 'sale_price'];
@tracked entityEditingSettings = {};
@tracked isEntityFieldsEditable = false;

constructor() {
super(...arguments);
this.getAppLinkUrl.perform();
this.getEntityEditableSettings.perform();
}

@action enableEditableEntityFields(isEntityFieldsEditable) {
this.isEntityFieldsEditable = isEntityFieldsEditable;
}

@action onConfigChanged(orderConfig) {
this.selectedOrderConfig = orderConfig;
}

@action toggleFieldEditable(fieldName, isEditable) {
const editableFields = this.entityEditingSettings[this.selectedOrderConfig.id]?.editable_entity_fields;
if (isArray(editableFields)) {
if (isEditable) {
editableFields.pushObject(fieldName);
} else {
editableFields.removeObject(fieldName);
}
} else {
this.entityEditingSettings = {
...this.entityEditingSettings,
[this.selectedOrderConfig.id]: {
editable_entity_fields: [],
},
};
return this.toggleFieldEditable(...arguments);
}

this.updateEditableEntityFieldsForOrderConfig(editableFields);
}

updateEditableEntityFieldsForOrderConfig(editableFields = [], orderConfig = null) {
orderConfig = orderConfig === null ? this.selectedOrderConfig : orderConfig;
this.entityEditingSettings = {
...this.entityEditingSettings,
[orderConfig.id]: {
editable_entity_fields: editableFields,
},
};
}

@task *getAppLinkUrl() {
Expand All @@ -66,15 +19,4 @@ export default class NavigatorAppControlsComponent extends Component {
this.url = linkUrl;
}
}

@task *getEntityEditableSettings() {
const { entityEditingSettings, isEntityFieldsEditable } = yield this.fetch.get('fleet-ops/settings/entity-editing-settings');
this.entityEditingSettings = entityEditingSettings;
this.isEntityFieldsEditable = isEntityFieldsEditable;
}

@task *saveEntityEditingSettings() {
const { entityEditingSettings, isEntityFieldsEditable } = this;
yield this.fetch.post('fleet-ops/settings/entity-editing-settings', { entityEditingSettings, isEntityFieldsEditable });
}
}
29 changes: 29 additions & 0 deletions addon/components/driver-onboard-settings.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<ContentPanel @title={{t "fleet-ops.component.driver-onboard-settings.driver-onboard-settings"}} @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800 mb-4">
{{#if this.driverOnboardSettingsLoaded}}
<InputGroup>
<div class="flex items-center">
<Toggle @isToggled={{this.driverOnboardSettings.enableDriverOnboardFromApp}} @onToggle={{this.enableDriverOnboard}} @label={{t "fleet-ops.component.driver-onboard-settings.enable-driver-onboard-from-app"}} @helpText={{t "fleet-ops.component.driver-onboard-settings.enable-driver-onboard-from-app-help-text"}} />
</div>
</InputGroup>
{{#if this.driverOnboardSettings.enableDriverOnboardFromApp}}
<InputGroup @name={{t "fleet-ops.component.driver-onboard-settings.select-onboard-method"}} @helpText={{t "fleet-ops.component.driver-onboard-settings.select-onboard-method-help-text"}}>
<Select class="w-full flex-1" @value={{this.driverOnboardSettings.driverOnboardAppMethod}} @options={{this.driverOnboardMethods}} @placeholder={{t "fleet-ops.component.driver-onboard-settings.select-onboard-method"}} @onSelect={{this.selectDriverOnboardMethod}} />
</InputGroup>
<InputGroup>
<div class="flex items-center">
<Toggle @isToggled={{this.driverOnboardSettings.driverMustProvideOnboardDocuments}} @onToggle={{this.enableDriverOnboardDocuments}} @label={{t "fleet-ops.component.driver-onboard-settings.require-driver-to-upload-onboard-documents"}} @helpText={{t "fleet-ops.component.driver-onboard-settings.require-driver-to-upload-onboard-documents-help-text"}} />
</div>
</InputGroup>
{{#if this.driverOnboardSettings.driverMustProvideOnboardDocuments}}
<InputGroup>
<ArrayInput @data={{this.driverOnboardSettings.requiredOnboardDocuments}} @placeholder={{t "fleet-ops.component.driver-onboard-settings.enter-document-name"}} @onDataChanged={{this.onOnboardDocumentsChanged}} @addButtonText={{t "fleet-ops.component.driver-onboard-settings.add-onboard-document"}}>
<InputLabel @labelText={{t "fleet-ops.component.driver-onboard-settings.required-onboard-documents"}} @helpText={{t "fleet-ops.component.driver-onboard-settings.required-onboard-documents-help-text"}} />
</ArrayInput>
</InputGroup>
{{/if}}
{{/if}}
<div class="mt-3 flex items-center mb-4">
<Button @type="primary" @size="lg" @icon="save" @text={{t "fleet-ops.common.save-changes"}} @onClick={{perform this.saveDriverOnboardSettings}} @isLoading={{not this.saveDriverOnboardSettings.isIdle}} />
</div>
{{/if}}
</ContentPanel>
75 changes: 75 additions & 0 deletions addon/components/driver-onboard-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { task } from 'ember-concurrency-decorators';

export default class DriverOnboardSettingsComponent extends Component {
@service fetch;
@service currentUser;
@tracked companyId;
@tracked driverOnboardSettingsLoaded = false;
@tracked driverOnboardSettings = {};
@tracked driverOnboardMethods = ['invite', 'button'];

constructor() {
super(...arguments);
this.companyId = this.currentUser.companyId;
this.getDriverOnboardSettings.perform();
}

@action enableDriverOnboard(enableDriverOnboardFromApp) {
this.updateDriverOnboardSettings({ enableDriverOnboardFromApp });
}

@action enableDriverOnboardDocuments(driverMustProvideOnboardDocuments) {
this.updateDriverOnboardSettings({ driverMustProvideOnboardDocuments });
}

@action selectDriverOnboardMethod(driverOnboardAppMethod) {
this.updateDriverOnboardSettings({ driverOnboardAppMethod });
}

@action onOnboardDocumentsChanged(requiredOnboardDocuments) {
requiredOnboardDocuments = requiredOnboardDocuments.filter((documentName) => typeof documentName === 'string');
this.updateDriverOnboardSettings({ requiredOnboardDocuments });
}

@task *saveDriverOnboardSettings() {
const { driverOnboardSettings } = this;
const driverOnboardSettingsResponse = yield this.fetch.post('fleet-ops/settings/driver-onboard-settings', { driverOnboardSettings });
if (driverOnboardSettings?.enableDriverOnboardFromApp == false) this.driverOnboardSettings = driverOnboardSettingsResponse?.driverOnboardSettings;
}

@task *getDriverOnboardSettings() {
const companyId = this.currentUser.companyId;
const { driverOnboardSettings } = yield this.fetch.get(`fleet-ops/settings/driver-onboard-settings/${companyId}`);
this.driverOnboardSettings = driverOnboardSettings;

if (this.companyDoesntHaveDriverOnboardSettings()) {
this.updateDriverOnboardSettings({
enableDriverOnboardFromApp: false,
driverOnboardAppMethod: 'invite',
driverMustProvideOnboardDocuments: false,
requiredOnboardDocuments: [],
});
}

this.driverOnboardSettingsLoaded = true;
}

companyDoesntHaveDriverOnboardSettings() {
const companyId = this.driverOnboardSettings.companyId;
return companyId === undefined;
}

updateDriverOnboardSettings(props = {}) {
const companyId = this.currentUser.companyId;
const driverOnboardSettings = this.driverOnboardSettings ?? {};
this.driverOnboardSettings = {
companyId: companyId,
...driverOnboardSettings,
...props,
};
}
}
79 changes: 79 additions & 0 deletions addon/components/entity-field-editing-settings.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<ContentPanel @title={{t "fleet-ops.component.entity-field-editing-settings.entitiy-field-editing-settings"}} @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800 mb-4">
<OrderConfigManager @onConfigChanged={{this.onConfigChanged}} as |Action Context|>
<div>
<InputGroup
@name={{t "fleet-ops.component.entity-field-editing-settings.select-order-config"}}
@helpText={{t "fleet-ops.component.entity-field-editing-settings.select-order-config-help-text"}}
>
<DropdownButton
class="order-config-select-button mr-2"
@disabled={{not Context.configs}}
@text={{if Context.currentConfig.name Context.currentConfig.name (t "fleet-ops.component.entity-field-editing-settings.select-order-config")}}
@textClass="text-sm mr-2"
@buttonClass="flex-row-reverse w-44 justify-between"
@icon="caret-down"
@iconClass="mr-0i"
@size="sm"
@iconPrefix="fas"
@triggerClass="hidden md:flex"
as |dd|
>
<div class="next-dd-menu mt-1 mx-0" aria-labelledby="user-menu">
<div class="p-1">
{{#each Context.configs as |orderConfig|}}
<a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd Context.selectConfig orderConfig)}}>
<div class="flex-1 flex flex-row items-center">
<div class="w-6">
<FaIcon @icon="cogs" />
</div>
<span>{{orderConfig.name}}</span>
</div>
<div>
{{#if (eq Context.currentConfig.id orderConfig.id)}}
<FaIcon @icon="check" class="text-green-500" />
{{/if}}
</div>
</a>
{{/each}}
</div>
</div>
</DropdownButton>
</InputGroup>
</div>
</OrderConfigManager>
{{#if this.selectedOrderConfig}}
{{#let (get this.entityEditingSettings this.selectedOrderConfig.id) as |orderConfigEntityEditingSettings|}}
<InputGroup>
<div class="flex items-center">
<Toggle
@isToggled={{orderConfigEntityEditingSettings.is_editable}}
@onToggle={{this.enableEditableEntityFields}}
@label={{t "fleet-ops.component.entity-field-editing-settings.enable-driver-to-edit-entity-fields"}}
@helpText={{t "fleet-ops.component.entity-field-editing-settings.enable-driver-to-edit-entity-fields-help-text"}}
/>
</div>
</InputGroup>
{{#if orderConfigEntityEditingSettings.is_editable}}
<div class="bg-gray-400 border-gray-600 rounded-lg px-4 py-2 dark:bg-gray-700 dark:border-gray-800">
{{#let (get (get this.entityEditingSettings this.selectedOrderConfig.id) "editable_entity_fields") as |editableEntityFields|}}
{{#each this.entityFields as |entityField|}}
<div class="mt-1">
<Checkbox @value={{includes entityField editableEntityFields}} @label={{smart-humanize entityField}} @onToggle={{fn this.toggleFieldEditable entityField}} />
</div>
{{/each}}
{{/let}}
</div>
{{/if}}
<div class="mt-4 flex items-center">
<Button
@type="primary"
@size="lg"
@icon="save"
@text={{t "fleet-ops.common.save-changes"}}
@onClick={{perform this.saveEntityEditingSettings}}
@isLoading={{not this.saveEntityEditingSettings.isIdle}}
/>
</div>
{{/let}}
{{/if}}
</ContentPanel>
Loading

0 comments on commit ece7edf

Please sign in to comment.