Skip to content

Commit 8e6c31e

Browse files
committed
- Patched custom field form panel meta value input
- Added notification settings to fleet ops - Patched custom field rendering and reset in order viewing and creation - Added "notification-settings" permissions
1 parent 7e6d3ba commit 8e6c31e

23 files changed

Lines changed: 3568 additions & 3085 deletions

File tree

addon/components/custom-field-form-panel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export default class CustomFieldFormPanelComponent extends Component {
124124
this.customField.set('meta', {});
125125
}
126126

127-
this.customField.meta[key] = value;
127+
const currentMeta = this.customField.meta ?? {};
128+
this.customField.set('meta', { ...currentMeta, [key]: value });
128129
}
129130

130131
/**

addon/components/fuel-report-form-panel.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ export default class FuelReportFormPanelComponent extends Component {
7878
@task *save() {
7979
contextComponentCallback(this, 'onBeforeSave', this.fuelReport);
8080

81-
console.log(this.fuelReport);
82-
8381
try {
8482
this.fuelReport = yield this.fuelReport.save();
8583
} catch (error) {

addon/components/layout/fleet-ops-sidebar.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
154154
permission: 'fleet-ops view payments',
155155
visible: this.abilities.can('fleet-ops see payments'),
156156
},
157+
{
158+
intl: 'fleet-ops.component.layout.fleet-ops-sidebar.notifications',
159+
title: this.intl.t('fleet-ops.component.layout.fleet-ops-sidebar.notifications'),
160+
icon: 'bell',
161+
route: 'settings.notifications',
162+
permission: 'fleet-ops view notification-settings',
163+
visible: this.abilities.can('fleet-ops see notification-settings'),
164+
},
157165
];
158166

159167
const createPanel = (intl, routePrefix, items = []) => ({

addon/controllers/operations/orders/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,11 @@ export default class OperationsOrdersIndexController extends BaseController {
710710
// Listed on company channel
711711
const channel = socket.subscribe(channelId);
712712

713+
// Disconnect when transitioning
714+
this.hostRouter.on('routeWillChange', () => {
715+
channel.close();
716+
});
717+
713718
// Listen for channel subscription
714719
(async () => {
715720
for await (let output of channel) {
@@ -724,17 +729,8 @@ export default class OperationsOrdersIndexController extends BaseController {
724729
order.set('driver_assigned', driver);
725730
}
726731
}
727-
728-
if (event === 'order.ready') {
729-
this.hostRouter.refresh();
730-
}
731732
}
732733
})();
733-
734-
// disconnect when transitioning
735-
this.hostRouter.on('routeWillChange', () => {
736-
channel.close();
737-
});
738734
});
739735
}
740736

addon/controllers/operations/orders/index/new.js

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { not, equal, alias } from '@ember/object/computed';
77
import { isArray } from '@ember/array';
88
import { isBlank } from '@ember/utils';
99
import { dasherize } from '@ember/string';
10-
import { later, next } from '@ember/runloop';
10+
import { next } from '@ember/runloop';
1111
import { task } from 'ember-concurrency-decorators';
1212
import { OSRMv1, Control as RoutingControl } from '@fleetbase/leaflet-routing-machine';
1313
import { debug } from '@ember/debug';
@@ -295,7 +295,7 @@ export default class OperationsOrdersIndexNewController extends BaseController {
295295
});
296296
}
297297

298-
@action createOrder() {
298+
@action async createOrder() {
299299
if (!this.isValid) {
300300
return;
301301
}
@@ -347,34 +347,24 @@ export default class OperationsOrdersIndexNewController extends BaseController {
347347
this.isCreatingOrder = true;
348348

349349
try {
350-
return order
351-
.save()
352-
.then((order) => {
353-
// trigger event that fleet-ops created an order
354-
this.universe.trigger('fleet-ops.order.created', order);
355-
356-
// transition to order view
357-
return this.hostRouter.transitionTo(`console.fleet-ops.operations.orders.index.view`, order).then(() => {
358-
this.notifications.success(this.intl.t('fleet-ops.operations.orders.index.new.success-message', { orderId: order.public_id }));
359-
this.loader.removeLoader();
360-
this.resetForm();
361-
later(
362-
this,
363-
() => {
364-
this.hostRouter.refresh();
365-
},
366-
100
367-
);
368-
});
369-
})
370-
.catch((error) => {
371-
this.isCreatingOrder = false;
372-
this.notifications.serverError(error);
373-
this.loader.removeLoader();
374-
});
350+
const createdOrder = await order.save();
351+
352+
// trigger event that fleet-ops created an order
353+
this.universe.trigger('fleet-ops.order.created', createdOrder);
354+
355+
// transition to order view
356+
await this.hostRouter.transitionTo('console.fleet-ops.operations.orders.index.view', createdOrder);
357+
358+
// order created successfully
359+
this.notifications.success(this.intl.t('fleet-ops.operations.orders.index.new.success-message', { orderId: createdOrder.public_id }));
360+
this.loader.removeLoader();
361+
this.resetForm();
375362
} catch (error) {
376-
this.notifications.error(error.message);
363+
debug(`Error Creating Order : ${error.message}`);
364+
this.notifications.serverError(error);
377365
this.loader.removeLoader();
366+
} finally {
367+
this.isCreatingOrder = false;
378368
}
379369
}
380370

@@ -601,8 +591,8 @@ export default class OperationsOrdersIndexNewController extends BaseController {
601591
setProperties(payload, { type: this.order.type });
602592
}
603593

604-
this.fetch
605-
.post('service-quotes/preliminary', {
594+
try {
595+
const serviceQuotes = await this.fetch.post('service-quotes/preliminary', {
606596
payload: this._getSerializedPayload(payload),
607597
distance,
608598
time,
@@ -611,20 +601,18 @@ export default class OperationsOrdersIndexNewController extends BaseController {
611601
facilitator,
612602
scheduled_at,
613603
is_route_optimized,
614-
})
615-
.then((serviceQuotes) => {
616-
set(this, 'serviceQuotes', isArray(serviceQuotes) ? serviceQuotes : []);
617-
618-
if (this.serviceQuotes.length && this.isUsingIntegratedVendor) {
619-
set(this, 'selectedServiceQuote', this.serviceQuotes.firstObject?.uuid);
620-
}
621-
})
622-
.catch(() => {
623-
this.notifications.warning(this.intl.t('fleet-ops.operations.orders.index.new.service-warning'));
624-
})
625-
.finally(() => {
626-
this.isFetchingQuotes = false;
627604
});
605+
606+
set(this, 'serviceQuotes', isArray(serviceQuotes) ? serviceQuotes : []);
607+
608+
if (this.serviceQuotes.length && this.isUsingIntegratedVendor) {
609+
set(this, 'selectedServiceQuote', this.serviceQuotes.firstObject?.uuid);
610+
}
611+
} catch {
612+
this.notifications.warning(this.intl.t('fleet-ops.operations.orders.index.new.service-warning'));
613+
} finally {
614+
this.isFetchingQuotes = false;
615+
}
628616
}
629617

630618
_getSerializedPayload(payload) {
@@ -1096,6 +1084,9 @@ export default class OperationsOrdersIndexNewController extends BaseController {
10961084
const selectedServiceRate = undefined;
10971085
const selectedServiceQuote = undefined;
10981086
const servicable = false;
1087+
const customFieldGroups = [];
1088+
const customFields = [];
1089+
const customFieldValues = {};
10991090

11001091
this.removeRoutingControlPreview();
11011092
this.removeOptimizedRoute();
@@ -1115,6 +1106,9 @@ export default class OperationsOrdersIndexNewController extends BaseController {
11151106
selectedServiceQuote,
11161107
selectedServiceRate,
11171108
servicable,
1109+
customFieldGroups,
1110+
customFields,
1111+
customFieldValues,
11181112
});
11191113
this.resetInterface();
11201114
}
@@ -1139,6 +1133,8 @@ export default class OperationsOrdersIndexNewController extends BaseController {
11391133
* @task
11401134
*/
11411135
@task *loadCustomFields(orderConfig) {
1136+
this.store.unloadAll('custom-field');
1137+
11421138
this.customFieldGroups = yield this.store.query('category', { owner_uuid: orderConfig.id, for: 'custom_field_group' });
11431139
this.customFields = yield this.store.query('custom-field', { subject_uuid: orderConfig.id });
11441140
this.groupCustomFields();
@@ -1149,15 +1145,20 @@ export default class OperationsOrdersIndexNewController extends BaseController {
11491145
* Organizes custom fields into their respective groups.
11501146
*/
11511147
groupCustomFields() {
1148+
const customFieldGroups = [];
11521149
for (let i = 0; i < this.customFieldGroups.length; i++) {
11531150
const group = this.customFieldGroups[i];
11541151
group.set(
11551152
'customFields',
11561153
this.customFields.filter((customField) => {
1154+
customField.set('value', null);
11571155
return customField.category_uuid === group.id;
11581156
})
11591157
);
1158+
customFieldGroups.push(group);
11601159
}
1160+
1161+
this.customFieldGroups = customFieldGroups;
11611162
}
11621163

11631164
@action setCustomFieldValue(value, customField) {
@@ -1192,19 +1193,21 @@ export default class OperationsOrdersIndexNewController extends BaseController {
11921193
// this.order.set('facilitator_type', `fleet-ops:${model.facilitator_type}`);
11931194
this.order.set('driver', null);
11941195

1195-
this.isUsingIntegratedVendor = model.isIntegratedVendor;
1196-
this.servicable = model.isIntegratedVendor;
1196+
this.isUsingIntegratedVendor = model?.isIntegratedVendor;
1197+
this.servicable = model?.isIntegratedVendor;
11971198

1198-
if (model.service_types?.length) {
1199+
if (model?.service_types?.length) {
11991200
this.integratedVendorServiceType = model.service_types.firstObject.key;
12001201
}
12011202

1202-
if (model.isIntegratedVendor) {
1203+
if (model?.isIntegratedVendor) {
12031204
this.getQuotes();
12041205
}
12051206

12061207
if (model) {
12071208
this.driversQuery = { facilitator: model.id };
1209+
} else {
1210+
this.driversQuery = {};
12081211
}
12091212
}
12101213

@@ -1525,12 +1528,17 @@ export default class OperationsOrdersIndexNewController extends BaseController {
15251528
confirm: async (modal) => {
15261529
modal.startLoading();
15271530

1528-
const pendingFileUpload = modal.getOption('pendingFileUpload');
1529-
return entity.save().then(() => {
1531+
try {
1532+
const pendingFileUpload = modal.getOption('pendingFileUpload');
1533+
const savedEntity = await entity.save();
15301534
if (pendingFileUpload) {
15311535
return modal.invoke('uploadNewPhoto', pendingFileUpload);
15321536
}
1533-
});
1537+
1538+
return savedEntity;
1539+
} catch (error) {
1540+
this.notifications.serverError(error);
1541+
}
15341542
},
15351543
});
15361544
}

addon/controllers/operations/orders/index/view.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export default class OperationsOrdersIndexViewController extends BaseController
187187
*/
188188
@task *loadCustomFields(order) {
189189
if (order.order_config_uuid) {
190+
this.store.unloadAll('custom-field');
191+
190192
this.customFieldGroups = yield this.store.query('category', { owner_uuid: order.order_config_uuid, for: 'custom_field_group' });
191193
this.customFields = yield this.store.query('custom-field', { subject_uuid: order.order_config_uuid });
192194
this.groupCustomFields(order);
@@ -227,16 +229,18 @@ export default class OperationsOrdersIndexViewController extends BaseController
227229
this.customFields = customFieldsWithValues;
228230

229231
// group and update custom fields
230-
this.customFieldGroups = this.customFieldGroups.map((group) => {
232+
const customFieldGroups = [];
233+
for (let i = 0; i < this.customFieldGroups.length; i++) {
234+
const group = this.customFieldGroups[i];
231235
group.set(
232236
'customFields',
233237
customFieldsWithValues.filter((customField) => {
234238
return customField.category_uuid === group.id;
235239
})
236240
);
237-
238-
return group;
239-
});
241+
customFieldGroups.push(group);
242+
}
243+
this.customFieldGroups = customFieldGroups;
240244
}
241245

242246
@action resetView() {

0 commit comments

Comments
 (0)