-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab42a92
commit c18c349
Showing
16 changed files
with
166 additions
and
212 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 |
---|---|---|
@@ -1 +1,29 @@ | ||
{{yield}} | ||
<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> | ||
{{#each this.categories as |subCategory|}} | ||
{{#if (and (eq subCategory.parent.id category.id) (not (eq subCategory.id category.id)))}} | ||
<div class="ml-4 flex justify-between items-center border-b border-gray-700 py-2"> | ||
<span>{{subCategory.name}}</span> | ||
<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> | ||
{{/if}} | ||
{{/each}} | ||
{{/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 |
---|---|---|
@@ -1,3 +1,134 @@ | ||
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; | ||
|
||
export default class AdminProductCategoryComponent extends Component {} | ||
constructor() { | ||
super(...arguments); | ||
this.category = this.args.category; | ||
this.fetchCategories(); | ||
} | ||
|
||
@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.fetchCategories(); | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
@action async fetchCategories() { | ||
this.categories = await this.store.query('category', { | ||
for: 'pallet_product', | ||
}); | ||
} | ||
|
||
@action async addSubCategory(category) { | ||
const subCategory = this.store.createRecord('category', { | ||
for: 'pallet_product', | ||
parent: category, | ||
}); | ||
|
||
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/${subCategory.company_uuid}/product-category-icon/${dasherize(subCategory.name ?? this.currentUser.companyId)}`, | ||
subject_uuid: subCategory.id, | ||
subject_type: `category`, | ||
type: `category_icon`, | ||
}, | ||
(uploadedFile) => { | ||
subCategory.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.fetchCategories(); | ||
} catch (error) { | ||
this.notifications.error('Error creating subcategory.'); | ||
console.error('Error creating subcategory:', error); | ||
} finally { | ||
modal.stopLoading(); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
@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.fetchCategories(); | ||
} catch (error) { | ||
this.notifications.error('Error deleting category.'); | ||
console.error('Error deleting category:', error); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.