-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from fleetbase/component-context
Remove unused context component utilities and imported from ember-core
- Loading branch information
Showing
45 changed files
with
413 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.