Skip to content

Commit

Permalink
fixed inventory,sales-order,purchase-order, and product small issues
Browse files Browse the repository at this point in the history
created basic structure for product category page
  • Loading branch information
TemuulenBM committed Dec 7, 2023
1 parent 2a959e9 commit ab42a92
Show file tree
Hide file tree
Showing 36 changed files with 421 additions and 119 deletions.
1 change: 1 addition & 0 deletions addon/components/admin/product-category.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
3 changes: 3 additions & 0 deletions addon/components/admin/product-category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Component from '@glimmer/component';

export default class AdminProductCategoryComponent extends Component {}
12 changes: 12 additions & 0 deletions addon/components/admin/visibility-controls.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ContentPanel @title="Visibility Controls" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<p class="mb-4 dark:text-white text-gray-800">Visibility controls allow you to disable sections of Pallet. Toggle the checkbox to enable or disable sections to hide in Pallet</p>
{{#each this.visibilitySettings as |visibilityControl|}}
<InputGroup @wrapperClass="mb-1i">
<Checkbox @value={{visibilityControl.visible}} @label={{concat visibilityControl.name " Visible"}} @onToggle={{fn (mut visibilityControl.visible)}} @helpText="Enable or disable visibility for this section in Pallet." />
</InputGroup>
{{/each}}
</ContentPanel>

<div class="mt-3 flex items-center justify-end">
<Button @type="primary" @size="lg" @icon="save" @text="Save Changes" @onClick={{this.saveVisibilitySettings}} @disabled={{this.isLoading}} @isLoading={{this.isLoading}} />
</div>
81 changes: 81 additions & 0 deletions addon/components/admin/visibility-controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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';

export default class AdminVisibilityControlsComponent extends Component {
@service fetch;
@tracked visibilitySettings = [
// { name: 'Dashboard', route: 'operations.orders', visible: true },
{ name: 'Products', route: 'products', visible: true },
{ name: 'Warehouses', route: 'warehouses', visible: true },
{ name: 'Suppliers', route: 'suppliers', visible: true },
{ name: 'Inventory', route: 'inventory', visible: true },
{ name: 'Sales Orders', route: 'sales-orders', visible: true },
{ name: 'Purchase Orders', route: 'purchase-orders', visible: true },
{ name: 'Audits', route: 'audits', visible: true },
{ name: 'Reports', route: 'reports', visible: true },
];
@tracked isLoading = false;

constructor() {
super(...arguments);
this.loadVisibilitySettings();
}

@action mutateVisibility(route, visible) {
this.visibilitySettings = [...this.visibilitySettings].map((visibilityControl) => {
if (visibilityControl.route === route) {
return {
...visibilityControl,
visible,
};
}

return visibilityControl;
});
}

@action loadVisibilitySettings() {
this.isLoading = true;

this.fetch
.get('pallet/settings/visibility')
.then(({ visibilitySettings }) => {
if (isArray(visibilitySettings)) {
for (let i = 0; i < visibilitySettings.length; i++) {
const visibilityControl = visibilitySettings.objectAt(i);
this.mutateVisibility(visibilityControl.route, visibilityControl.visible);
}
}
})
.catch((error) => {
this.notifications.serverError(error);
})
.finally(() => {
this.isLoading = false;
});
}

@action saveVisibilitySettings() {
this.isLoading = true;

this.fetch
.post('pallet/settings/visibility', { visibilitySettings: this.visibilitySettings })
.then(({ visibilitySettings }) => {
if (isArray(visibilitySettings)) {
for (let i = 0; i < visibilitySettings.length; i++) {
const visibilityControl = visibilitySettings.objectAt(i);
this.mutateVisibility(visibilityControl.route, visibilityControl.visible);
}
}
})
.catch((error) => {
this.notifications.serverError(error);
})
.finally(() => {
this.isLoading = false;
});
}
}
4 changes: 2 additions & 2 deletions addon/components/inventory-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{this.inventory.supplier.name}}
@onChangeId={{fn (mut this.inventory.product_uuid)}}
@onChangeId={{fn (mut this.inventory.supplier_uuid)}}
as |model|
>
{{model.name}}
Expand Down Expand Up @@ -96,7 +96,7 @@
<ContentPanel @title="Batch" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<InputGroup @name="Batch Number" @type="text" @value={{this.inventory.batch.batch_number}} />
<InputGroup @name="Expiry Date">
<input value={{this.inventory.expiryDate}} type="date" class="form-input w-full" {{on "change" this.setExpiryDate}} />
<input value={{this.inventory.batch.expiryDate}} type="date" class="form-input w-full" {{on "change" this.setExpiryDate}} />
</InputGroup>
</ContentPanel>
</div>
Expand Down
4 changes: 4 additions & 0 deletions addon/components/inventory-panel/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<div class="field-name">Batch</div>
<div class="field-value">{{n-a @inventory.batch.batch_number}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Supplier</div>
<div class="field-value">{{n-a @inventory.supplier.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Expiry Date</div>
<div class="field-value">{{n-a @inventory.expiry_date_at}}</div>
Expand Down
2 changes: 1 addition & 1 deletion addon/components/purchase-order-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class PurchaseOrderFormPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.purchaseOrder);
}

@action setExpectedDeliveryDate(event) {
const {
target: { value },
Expand Down
3 changes: 2 additions & 1 deletion addon/components/supplier-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
@triggerClass="form-select form-input"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{this.supplier.place.address}}
@onChange={{fn (mut this.supplier.place)}}
@onChangeId={{fn (mut this.supplier.place_uuid)}}
as |model|
>
<div class="flex items-center flex-row justify-between">
Expand Down
3 changes: 3 additions & 0 deletions addon/controllers/admin/product-category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Controller from '@ember/controller';

export default class AdminProductCategoryController extends Controller {}
23 changes: 2 additions & 21 deletions addon/controllers/inventory/expired-stock.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class InventoryExpiredStockController extends Controller {
*/
@tracked page = 1;

@tracked view = 'expired_stock'
@tracked view = 'expired_stock';

/**
* The maximum number of items to show per page
Expand Down Expand Up @@ -136,6 +136,7 @@ export default class InventoryExpiredStockController extends Controller {
{
label: 'Product',
valuePath: 'product.name',
action: this.viewInventory,
width: '170px',
cellComponent: 'cell/product-info',
modelPath: 'product',
Expand All @@ -159,16 +160,6 @@ export default class InventoryExpiredStockController extends Controller {
valuePath: 'quantity',
width: '120px',
},
{
label: 'Warehouse',
valuePath: 'warehouse.address',
width: '120px',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: 'Batch',
valuePath: 'batch.name',
Expand Down Expand Up @@ -199,16 +190,6 @@ export default class InventoryExpiredStockController extends Controller {
filterable: true,
filterComponent: 'filter/date',
},
{
label: 'Expiry Date',
valuePath: 'expiredAt',
sortParam: 'expiry_date_at',
width: '10%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: 'Updated At',
valuePath: 'updatedAt',
Expand Down
52 changes: 3 additions & 49 deletions addon/controllers/inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class InventoryIndexController extends Controller {
{
label: 'Product',
valuePath: 'product.name',
action: this.viewInventory,
width: '170px',
cellComponent: 'cell/product-info',
modelPath: 'product',
Expand All @@ -157,16 +158,6 @@ export default class InventoryIndexController extends Controller {
valuePath: 'quantity',
width: '120px',
},
{
label: 'Warehouse',
valuePath: 'warehouse.address',
width: '120px',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: 'Batch',
valuePath: 'batch.batch_number',
Expand Down Expand Up @@ -199,7 +190,7 @@ export default class InventoryIndexController extends Controller {
},
{
label: 'Expiry Date',
valuePath: 'expiredAt',
valuePath: 'expiryDate',
sortParam: 'expiry_date_at',
width: '10%',
resizable: true,
Expand Down Expand Up @@ -286,7 +277,7 @@ export default class InventoryIndexController extends Controller {
* @void
*/
@action viewInventory(inventory) {
return this.transitionToRoute('inventory.index.details', inventory);
return this.transitionToRoute('inventory.index.details', inventory.public_id);
}

/**
Expand All @@ -313,41 +304,4 @@ export default class InventoryIndexController extends Controller {
@action async editInventory(inventory) {
return this.transitionToRoute('inventory.index.edit', inventory);
}

/**
* Delete a `inventory` via confirm prompt
*
* @param {InventoryModel} inventory
* @param {Object} options
* @void
*/
@action deleteInventory(inventory, options = {}) {
this.crud.delete(inventory, {
onConfirm: () => {
return this.hostRouter.refresh();
},
...options,
});
}

/**
* Bulk deletes selected `inventory` via confirm prompt
*
* @param {Array} selected an array of selected models
* @void
*/
@action bulkDeleteInventorys() {
const selected = this.table.selectedRows;

this.crud.bulkDelete(selected, {
modelNamePath: `public_id`,
acceptButtonText: 'Delete Inventories',
fetchOptions: {
namespace: 'pallet/int/v1',
},
onSuccess: () => {
return this.hostRouter.refresh();
},
});
}
}
20 changes: 0 additions & 20 deletions addon/controllers/inventory/low-stock.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,6 @@ export default class InventoryLowStockController extends Controller {
valuePath: 'quantity',
width: '120px',
},
{
label: 'Warehouse',
valuePath: 'warehouse.address',
width: '120px',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: 'Batch',
valuePath: 'batch.name',
Expand Down Expand Up @@ -199,16 +189,6 @@ export default class InventoryLowStockController extends Controller {
filterable: true,
filterComponent: 'filter/date',
},
{
label: 'Expiry Date',
valuePath: 'expiredAt',
sortParam: 'expiry_date_at',
width: '10%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: 'Updated At',
valuePath: 'updatedAt',
Expand Down
3 changes: 1 addition & 2 deletions addon/controllers/sales-orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default class SalesOrdersIndexController extends Controller {
*/
@tracked page = 1;


/**
* The maximum number of items to show per page
*
Expand Down Expand Up @@ -291,7 +290,7 @@ export default class SalesOrdersIndexController extends Controller {

this.crud.bulkDelete(selected, {
modelNamePath: 'public_id',
acceptButtonText: "Delete Sales Orders",
acceptButtonText: 'Delete Sales Orders',
fetchOptions: {
namespace: 'pallet/int/v1',
},
Expand Down
33 changes: 32 additions & 1 deletion addon/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 AdminVisibilityControlsComponent from './components/admin/visibility-controls';

const { modulePrefix } = config;
const externalRoutes = ['console', 'extensions'];
Expand All @@ -16,7 +17,37 @@ export default class PalletEngine extends Engine {
};
setupExtension = function (app, engine, universe) {
// register menu item in header
universe.registerHeaderMenuItem('Pallet', 'console.pallet', { icon: 'pallet', priority: 1 });
universe.registerHeaderMenuItem('Pallet', 'console.pallet', { icon: 'pallet', priority: 0 });

// register admin settings -- create a pallet menu panel with it's own setting options
universe.registerAdminMenuPanel(
'Pallet Config',
[
{
title: 'Visibility Controls',
icon: 'eye',
component: AdminVisibilityControlsComponent,
},
],
{
slug: 'pallet',
}
);

// create primary registry for engine
universe.createRegistry('engine:pallet');

// register the product panel
universe.createRegistry('component:product-panel');

// register the inventory panel
universe.createRegistry('component:inventory-panel');

// register the supplier panel
universe.createRegistry('component:supplier-panel');

// register the warehouse panel
universe.createRegistry('component:warehouse-panel');
};
}

Expand Down
Loading

0 comments on commit ab42a92

Please sign in to comment.