...
/[WIP]Editing and Deleting Products in Firebase Updated
[WIP]Editing and Deleting Products in Firebase Updated
Learn to edit and delete products from the Firebase Realtime Database.
We'll cover the following...
The admin/edit route is responsible for editing and deleting the products. First, we need to update our edit route template user can update the image as well.
Setting up edit template
Let’s open app/templates/edit.hbs and make the required changes:
- Lines 39-47: We created a
divto implement image changing functionality:- Line # 42: We created an
imgtag to load the selected image. - Line # 45: We used the
x-file-inputcomponent to input the image.x-file-inputis used to input files by triggering the file selector. We attached thechangeImageaction to it.
- Line # 42: We created an
- Line # 49: We used a bootstrap spinner to notify users when image uploading starts. We set its visibility to hidden in CSS.
- Line # 50: We displayed the uploading progress to the user.
Let’s now implement editProduct() and deleteProduct actions in the edit controller.
Deleting the product
Let’s see how we can delete products. In order to delete a product, we have to perform two tasks. First, we need to delete the product from Realtime Database, and then we need to delete that product image from Firebase storage. Let’s open app/controllers/admin/edit.js and add the required code:
-
Lines 22–34: We search the product based on the product
idand delete it using thedeleteRecord()method of the Ember Data store and then we delete the image from Firebase storage.-
Line 22: We receive the
idof the clicked product. -
Line 23: We use the
findRecord()method to search our product based on theid. ThefindRecord()method returns a promise. -
Line 25: We delete the ...
-