Skip to content

Commit

Permalink
created bin,racks,aisles section
Browse files Browse the repository at this point in the history
  • Loading branch information
TemuulenBM committed Nov 29, 2023
1 parent 332fc46 commit 97614d2
Show file tree
Hide file tree
Showing 49 changed files with 32,559 additions and 348 deletions.
1 change: 1 addition & 0 deletions addon/adapters/warehouse-aisle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './pallet';
1 change: 1 addition & 0 deletions addon/adapters/warehouse-bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './pallet';
1 change: 1 addition & 0 deletions addon/adapters/warehouse-rack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './pallet';
57 changes: 55 additions & 2 deletions addon/components/warehouse-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,72 @@
<div>{{section.name}}</div>
<div class="flex flex-row items-center justify-end">
<Button @icon="trash" @type="danger" @onClick={{fn this.removeSection section}} />
<Button @text="Add Aisle" @icon="plus" @onClick={{this.addAisle}} />
<Button @text="Add Aisle" @icon="plus" @onClick={{fn this.addAisle section}} />
</div>
</div>
<div class="p-3">
<div class="grid grid-cols-3 gap-2">
<InputGroup @name="Name" @wrapperClass="col-span-2">
<Input @value={{section.name}} @type="text" class="w-full form-input" placeholder="Name"/>
<Input @value={{section.name}} @type="text" class="w-full form-input" placeholder="Name" />
</InputGroup>
<InputGroup @name="Description" @helpText="Additional description text of section." @wrapperClass="col-span-2 mb-2 onChange">
<Textarea @value={{section.description}} type="text" class="w-full form-input" placeholder="Description" />
</InputGroup>
</div>
</div>
{{#each section.aisles as |aisle|}}
<div class="flex flex-row items-center px-4 py-2 border border-gray-700 rounded-md">
<div class="flex flex-row items-center justify-end">
<Button @icon="trash" @type="danger" @onClick={{fn this.removeAisle aisle}} />
<Button @text="Add Racks" @icon="plus" @onClick={{fn this.addRacks aisle}} />
</div>
</div>
<div class="p-3">
<div class="grid grid-cols-3 gap-2">
<InputGroup @name="Aisle Number" @wrapperClass="col-span-2">
<Input @value={{aisle.aisle_number}} @type="text" class="w-full form-input" placeholder="Aisle Number" />
</InputGroup>
</div>
</div>
{{#each aisle.racks as |rack|}}
<div class="flex flex-row items-center px-4 py-2 border border-gray-700 rounded-md">
<div class="flex flex-row items-center justify-end">
<Button @icon="trash" @type="danger" @onClick={{fn this.removeRack rack}} />
<Button @text="Add Bins" @icon="plus" @onClick={{fn this.addBins rack}} />
</div>
</div>
<div class="p-3">
<div class="grid grid-cols-3 gap-2">
<InputGroup @name="Rack Number" @wrapperClass="col-span-2">
<Input @value={{rack.rack_number}} @type="text" class="w-full form-input" placeholder="Rack Number" />
</InputGroup>
<InputGroup @name="Rack Capacity" @wrapperClass="col-span-2">
<Input @value={{rack.capacity}} @type="text" class="w-full form-input" placeholder="Rack Capacity" />
</InputGroup>
</div>
</div>
{{#each rack.bins as |bin|}}
<div class="flex flex-row items-center px-4 py-2 border border-gray-700 rounded-md">
<div class="flex flex-row items-center justify-end">
<Button @icon="trash" @type="danger" @onClick={{fn this.removeBin bin}} />
</div>
</div>
<div class="p-3">
<div class="grid grid-cols-3 gap-2">
<InputGroup @name="Bin Number" @wrapperClass="col-span-2">
<Input @value={{bin.bin_number}} @type="text" class="w-full form-input" placeholder="Bin Number" />
</InputGroup>
<InputGroup @name="Size" @wrapperClass="col-span-2">
<Input @value={{bin.size}} @type="text" class="w-full form-input" placeholder="Size" />
</InputGroup>
<InputGroup @name="Max Weight" @wrapperClass="col-span-2">
<Input @value={{bin.max_weight}} @type="text" class="w-full form-input" placeholder="Max Weight" />
</InputGroup>
</div>
</div>
{{/each}}
{{/each}}
{{/each}}
{{/each}}
</div>
</div>
55 changes: 54 additions & 1 deletion addon/components/warehouse-editor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isBlank } from '@ember/utils';

export default class WarehouseEditorComponent extends Component {
/**
Expand All @@ -28,8 +27,62 @@ export default class WarehouseEditorComponent extends Component {
section.destroyRecord();
}

@action removeAisle(aisle) {
aisle.destroyRecord();
}

@action removeRack(rack) {
rack.destroyRecord();
}

@action removeBin(bin) {
bin.destroyRecord();
}

@action addSection() {
const section = this.store.createRecord('warehouse-section', { warehouse_uuid: this.warehouse.id });
this.warehouse.sections.pushObject(section);
}

@action addAisle(section) {
if (section && section.uuid) {
const aisle = this.store.createRecord('warehouse-aisle', {
section: section,
});

if (!section.aisles) {
section.set('aisles', []);
}

section.aisles.pushObject(aisle);
}
}

@action addRacks(aisle) {
if (aisle && aisle.uuid) {
const rack = this.store.createRecord('warehouse-rack', {
aisle: aisle,
});

if (!aisle.racks) {
aisle.set('racks', []);
}

aisle.racks.pushObject(rack);
}
}

@action addBins(rack) {
if (rack && rack.uuid) {
const bin = this.store.createRecord('warehouse-bin', {
rack: rack,
});

if (!rack.bins) {
rack.set('bins', []);
}

rack.bins.pushObject(bin);
}
}
}
24 changes: 1 addition & 23 deletions addon/controllers/warehouses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,12 @@ export default class WarehousesIndexController extends Controller {
*/
@service crud;

/**
* Inject the `crud` service
*
* @var {Service}
*/
@tracked section;

/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = [
'name',
'page',
'limit',
'sort',
'query',
'public_id',
'country',
'phone',
'created_at',
'updated_at',
'city',
'neighborhood',
'state',
'description',
];
queryParams = ['name', 'page', 'limit', 'sort', 'query', 'public_id', 'country', 'phone', 'created_at', 'updated_at', 'city', 'neighborhood', 'state', 'description'];

/**
* The current page of data being viewed
Expand Down
27 changes: 25 additions & 2 deletions addon/controllers/warehouses/index/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@ export default class WarehousesIndexNewController extends Controller {
*
* @var {PlaceModel}
*/
@tracked warehouse = this.store.createRecord('warehouse', { type: 'pallet-warehouse', status: 'active', meta: {}, sections: []});
@tracked warehouse = this.store.createRecord('warehouse', {
type: 'pallet-warehouse',
status: 'active',
meta: {},
sections: [
this.store.createRecord('warehouse-section', {
aisles: [
this.store.createRecord('warehouse-aisle',
{ racks: [
this.store.createRecord('warehouse-rack',
{ bins: [this.store.createRecord('warehouse-bin')]})]
})],
}),
],
});

/**
* Set the overlay component context object.
Expand Down Expand Up @@ -83,6 +97,15 @@ export default class WarehousesIndexNewController extends Controller {
* @memberof WarehousesIndexNewController
*/
resetForm() {
this.warehouse = this.store.createRecord('warehouse', { type: 'pallet-warehouse', status: 'active', meta: {}, sections: []});
this.warehouse = this.store.createRecord('warehouse', {
type: 'pallet-warehouse',
status: 'active',
meta: {},
sections: [
this.store.createRecord('warehouse-section', {
aisles: [this.store.createRecord('warehouse-aisle', { racks: [this.store.createRecord('warehouse-rack', {bins: [this.store.createRecord('warehouse-bin')]})] })],
}),
],
});
}
}
28 changes: 28 additions & 0 deletions addon/models/warehouse-aisle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,32 @@ export default class WarehouseAisle extends Model {
}
return formatDate(this.updated_at, 'PPP p');
}

@computed('area.coordinates', 'isNew') get locations() {
let coordinates = getWithDefault(this.area, 'coordinates', []);

// hotfix patch when coordinates are wrapped in array
if (isArray(coordinates) && isArray(coordinates[0]) && coordinates[0].length > 2) {
coordinates = first(coordinates);
}

if (this.isNew) {
return coordinates;
}

return coordinates.map((coord) => coord.reverse());
}

@computed('bounds') get firstCoordinatePair() {
return first(this.bounds) ?? [0, 0];
}

@computed('locations') get centerCoordinates() {
const x = this.locations.map((xy) => xy[0]);
const y = this.locations.map((xy) => xy[1]);
const cx = (Math.min(...x) + Math.max(...x)) / 2;
const cy = (Math.min(...y) + Math.max(...y)) / 2;

return [cx, cy];
}
}
2 changes: 1 addition & 1 deletion addon/routes/warehouses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export default class WarehousesIndexRoute extends Route {
};

model(params) {
return this.store.query('warehouse', { ...params, with: ['sections'] });
return this.store.query('warehouse', { ...params, with: ['sections', 'sections.aisles', 'sections.aisles.racks', 'sections.aisles.racks.bins'] });
}
}
15 changes: 15 additions & 0 deletions addon/serializers/warehouse-aisle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class WarehouseAisleSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
/**
* Embedded relationship attributes
*
* @var {Object}
*/
get attrs() {
return {
racks: { embedded: 'always' },
};
}
}
15 changes: 15 additions & 0 deletions addon/serializers/warehouse-rack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class WarehouseRackSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
/**
* Embedded relationship attributes
*
* @var {Object}
*/
get attrs() {
return {
bins: { embedded: 'always' },
};
}
}
15 changes: 15 additions & 0 deletions addon/serializers/warehouse-section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class WarehouseSectionSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
/**
* Embedded relationship attributes
*
* @var {Object}
*/
get attrs() {
return {
aisles: { embedded: 'always' },
};
}
}
3 changes: 3 additions & 0 deletions addon/serializers/warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default class WarehouseSerializer extends ApplicationSerializer.extend(Em
get attrs() {
return {
sections: { embedded: 'always' },
aisles: { embedded: 'always' },
racks: { embedded: 'always' },
bins: { embedded: 'always' },
};
}
}
1 change: 1 addition & 0 deletions app/adapters/warehouse-aisle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/adapters/warehouse-aisle';
1 change: 1 addition & 0 deletions app/adapters/warehouse-bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/adapters/warehouse-bin';
1 change: 1 addition & 0 deletions app/adapters/warehouse-rack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/adapters/warehouse-rack';
1 change: 1 addition & 0 deletions app/serializers/warehouse-aisle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/serializers/warehouse-aisle';
1 change: 1 addition & 0 deletions app/serializers/warehouse-rack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/serializers/warehouse-rack';
1 change: 1 addition & 0 deletions app/serializers/warehouse-section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/serializers/warehouse-section';
13 changes: 13 additions & 0 deletions server/src/Http/Controllers/WarehouseAisleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Fleetbase\Pallet\Http\Controllers;

class WarehouseAisleController extends PalletResourceController
{
/**
* The resource to query.
*
* @var string
*/
public $resource = 'warehouse-aisle';
}
13 changes: 13 additions & 0 deletions server/src/Http/Controllers/WarehouseBinController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Fleetbase\Pallet\Http\Controllers;

class WarehouseBinController extends PalletResourceController
{
/**
* The resource to query.
*
* @var string
*/
public $resource = 'warehouse-bin';
}
16 changes: 14 additions & 2 deletions server/src/Http/Controllers/WarehouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Fleetbase\Exceptions\FleetbaseRequestValidationException;
use Fleetbase\Pallet\Models\WarehouseSection;
use Fleetbase\Pallet\Models\WarehouseAisle;
use Fleetbase\Pallet\Models\WarehouseBin;
use Fleetbase\Pallet\Models\WarehouseRack;
use Fleetbase\Support\Http;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
Expand All @@ -27,10 +30,19 @@ public function updateRecord(Request $request, string $id)
foreach ($sections as $section) {
WarehouseSection::updateOrCreate(['uuid' => data_get($section, 'uuid')], array_merge($section, ['warehouse_uuid' => $warehouse->uuid, 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));

// get aisles
$aisles = data_get($section, 'aisles', []);
foreach ($aisles as $aisle) {
# code...
WarehouseAisle::updateOrCreate(['uuid' => data_get($aisle, 'uuid')], array_merge($aisle, ['section_uuid' => data_get($section, 'uuid'), 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));

$racks = data_get($aisle, 'racks', []);
foreach ($racks as $rack) {
WarehouseRack::updateOrCreate(['uuid' => data_get($rack, 'uuid')], array_merge($rack, ['aisle_uuid' => data_get($aisle, 'uuid'), 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));

$bins = data_get($rack, 'bins', []);
foreach ($bins as $bin) {
WarehouseBin::updateOrCreate(['uuid' => data_get($bin, 'uuid')], array_merge($bin, ['rack_uuid' => data_get($rack, 'uuid'), 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));
}
}
}
}
});
Expand Down
Loading

0 comments on commit 97614d2

Please sign in to comment.