Skip to content

Commit

Permalink
Merge pull request #3 from fleetbase/component-context
Browse files Browse the repository at this point in the history
Remove unused context component utilities and imported from ember-core
  • Loading branch information
roncodes authored Jul 5, 2024
2 parents 75c8808 + 47ac23a commit 9249692
Show file tree
Hide file tree
Showing 45 changed files with 413 additions and 218 deletions.
32 changes: 32 additions & 0 deletions addon/components/admin/product-category.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<ContentPanel @title="Categories" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<div class="mt-3 flex items-center justify-end">
<Button @type="primary" @size="sm" @icon="plus" @text="Add category" @onClick={{this.addCategory}} @disabled={{this.isLoading}} @isLoading={{this.isLoading}} />
</div>
<div class="mt-3">
<ul>
{{#each this.categories as |category|}}
<div class="flex justify-between items-center border-b border-gray-700 py-2">
<span>{{category.name}}</span>
<div class="flex items-center space-x-2">
<Button @type="info" @size="sm" @icon="eye" @text="Add subcategories" @onClick={{fn this.addSubCategory category}} />
<Button @type="danger" @size="sm" @icon="trash" @text="Delete" @onClick={{fn this.deleteCategory category}} />
</div>
</div>

{{#if category.subcategories}}
<ul class="ml-4">
{{#each category.subcategories as |subCategory|}}
<div class="flex justify-between items-center border-b border-gray-700 py-2">
<li>{{subCategory.name}}</li>
<div class="flex items-center space-x-2">
<Button @type="info" @size="sm" @icon="eye" @text="Add subcategories" @onClick={{fn this.addSubCategory subCategory}} />
<Button @type="danger" @size="sm" @icon="trash" @text="Delete" @onClick={{fn this.deleteCategory subCategory}} />
</div>
</div>
{{/each}}
</ul>
{{/if}}
{{/each}}
</ul>
</div>
</ContentPanel>
139 changes: 139 additions & 0 deletions addon/components/admin/product-category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { dasherize } from '@ember/string';

export default class AdminProductCategoryComponent extends Component {
@service store;
@service modalsManager;
@service currentUser;
@service modalsManager;
@service notifications;
@service fetch;
@service hostRouter;
@tracked categories = [];
@tracked selectedCategory;
@tracked isLoading = false;
@tracked buttonTitle = null;

constructor() {
super(...arguments);
this.category = this.args.category;
this.fetchCategoryHierarchy();
}

@action async addCategory() {
const category = this.store.createRecord('category', {
for: 'pallet_product',
});

this.modalsManager.show('modals/create-product-category', {
title: 'Create a new product category',
acceptButtonIcon: 'check',
acceptButtonIconPrefix: 'fas',
declineButtonIcon: 'times',
declineButtonIconPrefix: 'fas',
category,
uploadNewPhoto: (file) => {
this.fetch.uploadFile.perform(
file,
{
path: `uploads/${category.company_uuid}/product-category-icon/${dasherize(category.name ?? this.currentUser.companyId)}`,
subject_uuid: category.id,
subject_type: `category`,
type: `category_icon`,
},
(uploadedFile) => {
category.setProperties({
icon_file_uuid: uploadedFile.id,
icon_url: uploadedFile.url,
icon: uploadedFile,
});
}
);
},
confirm: (modal) => {
modal.startLoading();

return category.save().then(() => {
this.notifications.success('New product category created.');
return this.fetchCategoryHierarchy();
});
},
});
}

@action async fetchCategoryHierarchy() {
const allCategories = await this.store.query('category', {
for: 'pallet_product',
with_subcategories: true,
});

this.categories = allCategories.filter((category) => !category.parent);
this.categories.forEach((parentCategory) => {
parentCategory.subcategories = allCategories.filter((subcategory) => subcategory.parent?.id === parentCategory.id);
});
}

@action async addSubCategory(parentCategory) {
const subCategory = this.store.createRecord('category', {
parent: parentCategory,
for: 'pallet_product',
});

this.modalsManager.show('modals/create-product-category', {
title: 'Create a new subcategory',
acceptButtonIcon: 'check',
acceptButtonIconPrefix: 'fas',
declineButtonIcon: 'times',
declineButtonIconPrefix: 'fas',
category: subCategory,
uploadNewPhoto: (file) => {
this.fetch.uploadFile.perform(
file,
{
path: `uploads/${category.company_uuid}/product-category-icon/${dasherize(category.name ?? this.currentUser.companyId)}`,
subject_uuid: category.id,
subject_type: `category`,
type: `category_icon`,
},
(uploadedFile) => {
category.setProperties({
icon_file_uuid: uploadedFile.id,
icon_url: uploadedFile.url,
icon: uploadedFile,
});
}
);
},
confirm: async (modal) => {
modal.startLoading();

try {
await subCategory.save();
this.notifications.success('New subcategory created.');
await this.fetchCategoryHierarchy();
} catch (error) {
this.notifications.error('Error creating subcategory.');
console.error('Error creating subcategory:', error);
}
},
});
}

@action async deleteCategory(category) {
const confirmation = confirm(`Are you sure you want to delete the category "${category.name}"?`);

if (confirmation) {
try {
await category.destroyRecord();
this.notifications.success('Category deleted successfully.');
await this.fetchCategoryHierarchy();
} catch (error) {
this.notifications.error('Error deleting category.');
console.error('Error deleting category:', error);
}
}
}
}
4 changes: 2 additions & 2 deletions addon/components/batch-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class BatchFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/batch-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import BatchPanelDetailsComponent from './batch-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class BatchPanelComponent extends Component {
/**
Expand Down
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: 2 additions & 2 deletions addon/components/inventory-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class InventoryFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/inventory-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import InventoryPanelDetailsComponent from './inventory-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class InventoryPanelComponent extends Component {
/**
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
4 changes: 2 additions & 2 deletions addon/components/product-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import getWithDefault from '@fleetbase/ember-core/utils/get-with-default';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class ProductFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/product-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { isArray } from '@ember/array';
import ProductPanelDetailComponent from './product-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class ProductPanelComponent extends Component {
/**
Expand Down
6 changes: 3 additions & 3 deletions addon/components/purchase-order-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class PurchaseOrderFormPanelComponent extends Component {
/**
Expand Down 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
4 changes: 2 additions & 2 deletions addon/components/purchase-order-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import PurchaseOrderPanelDetailsComponent from './purchase-order-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class PurchaseOrderPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/sales-order-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isValid as isValidDate } from 'date-fns';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class SalesOrderFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/sales-order-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import SalesOrderPanelDetailsComponent from './sales-order-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class SalesOrderPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/stock-adjustment-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class StockAdjustmentFormPanelComponent extends Component {
/**
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
4 changes: 2 additions & 2 deletions addon/components/supplier-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class SupplierFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/supplier-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
import SupplierPanelDetailsComponent from './supplier-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class SupplierPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/warehouse-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { action } from '@ember/object';
import { isBlank } from '@ember/utils';
import { all } from 'rsvp';
import Point from '@fleetbase/fleetops-data/utils/geojson/point';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class WarehouseFormPanelComponent extends Component {
/**
Expand Down
4 changes: 2 additions & 2 deletions addon/components/warehouse-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { isArray } from '@ember/array';
import WarehousePanelDetailComponent from './warehouse-panel/details';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';

export default class WarehousePanelComponent extends Component {
/**
Expand Down
Loading

0 comments on commit 9249692

Please sign in to comment.