Merge pull request #19822 from Mangesh-Khairnar/edit-item-details

feat(marketplace): edit item details
This commit is contained in:
Deepesh Garg 2019-12-24 13:02:20 +05:30 committed by GitHub
commit 58408217f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 157 additions and 66 deletions

View File

@ -115,6 +115,16 @@ def get_valid_items(search_value=''):
return valid_items return valid_items
@frappe.whitelist()
def update_item(ref_doc, data):
data = json.loads(data)
data.update(dict(doctype='Hub Item', name=ref_doc))
try:
connection = get_hub_connection()
connection.update(data)
except Exception as e:
frappe.log_error(message=e, title='Hub Sync Error')
@frappe.whitelist() @frappe.whitelist()
def publish_selected_items(items_to_publish): def publish_selected_items(items_to_publish):

View File

@ -0,0 +1,41 @@
function edit_details_dialog(params) {
let dialog = new frappe.ui.Dialog({
title: __('Update Details'),
fields: [
{
label: 'Item Name',
fieldname: 'item_name',
fieldtype: 'Data',
default: params.defaults.item_name,
reqd: 1
},
{
label: 'Hub Category',
fieldname: 'hub_category',
fieldtype: 'Autocomplete',
default: params.defaults.hub_category,
options: [],
reqd: 1
},
{
label: 'Description',
fieldname: 'description',
fieldtype: 'Text',
default: params.defaults.description,
options: [],
reqd: 1
}
],
primary_action_label: params.primary_action.label || __('Update Details'),
primary_action: params.primary_action.fn
});
hub.call('get_categories').then(categories => {
categories = categories.map(d => d.name);
dialog.fields_dict.hub_category.set_data(categories);
});
return dialog;
}
export { edit_details_dialog };

View File

@ -1,10 +1,5 @@
<template> <template>
<div <div class="marketplace-page" :data-page-name="page_name" v-if="init || item">
class="marketplace-page"
:data-page-name="page_name"
v-if="init || item"
>
<detail-view <detail-view
:title="title" :title="title"
:image="image" :image="image"
@ -12,20 +7,15 @@
:menu_items="menu_items" :menu_items="menu_items"
:show_skeleton="init" :show_skeleton="init"
> >
<detail-header-item slot="detail-header-item" <detail-header-item slot="detail-header-item" :value="item_subtitle"></detail-header-item>
:value="item_subtitle" <detail-header-item slot="detail-header-item" :value="item_views_and_ratings"></detail-header-item>
></detail-header-item>
<detail-header-item slot="detail-header-item"
:value="item_views_and_ratings"
></detail-header-item>
<button v-if="primary_action" slot="detail-header-item" <button
v-if="primary_action"
slot="detail-header-item"
class="btn btn-primary btn-sm margin-top" class="btn btn-primary btn-sm margin-top"
@click="primary_action.action" @click="primary_action.action"
> >{{ primary_action.label }}</button>
{{ primary_action.label }}
</button>
</detail-view> </detail-view>
<review-area v-if="!init" :hub_item_name="hub_item_name"></review-area> <review-area v-if="!init" :hub_item_name="hub_item_name"></review-area>
@ -35,6 +25,7 @@
<script> <script>
import ReviewArea from '../components/ReviewArea.vue'; import ReviewArea from '../components/ReviewArea.vue';
import { get_rating_html } from '../components/reviews'; import { get_rating_html } from '../components/reviews';
import { edit_details_dialog } from '../components/edit_details_dialog';
export default { export default {
name: 'item-page', name: 'item-page',
@ -51,8 +42,7 @@ export default {
item: null, item: null,
title: null, title: null,
image: null, image: null,
sections: [], sections: []
}; };
}, },
computed: { computed: {
@ -92,7 +82,7 @@ export default {
condition: hub.is_user_registered() && this.is_own_item, condition: hub.is_user_registered() && this.is_own_item,
action: this.unpublish_item action: this.unpublish_item
} }
] ];
}, },
item_subtitle() { item_subtitle() {
@ -105,10 +95,13 @@ export default {
const rating = this.item.average_rating; const rating = this.item.average_rating;
if (rating > 0) { if (rating > 0) {
subtitle_items.push(rating + `<i class='fa fa-fw fa-star-o'></i>`) subtitle_items.push(rating + `<i class='fa fa-fw fa-star-o'></i>`);
} }
subtitle_items.push({value:this.item.company,on_click:this.go_to_seller_profile_page}); subtitle_items.push({
value: this.item.company,
on_click: this.go_to_seller_profile_page
});
return subtitle_items; return subtitle_items;
}, },
@ -123,7 +116,10 @@ export default {
const views_message = __(`${this.item.view_count} Views`); const views_message = __(`${this.item.view_count} Views`);
const rating_html = get_rating_html(this.item.average_rating); const rating_html = get_rating_html(this.item.average_rating);
const rating_count = this.item.no_of_ratings > 0 ? `${this.item.no_of_ratings} reviews` : __('No reviews yet'); const rating_count =
this.item.no_of_ratings > 0
? `${this.item.no_of_ratings} reviews`
: __('No reviews yet');
stats = [views_message, rating_html, rating_count]; stats = [views_message, rating_html, rating_count];
} }
@ -136,7 +132,7 @@ export default {
return { return {
label: __('Contact Seller'), label: __('Contact Seller'),
action: this.contact_seller.bind(this) action: this.contact_seller.bind(this)
} };
} else { } else {
return undefined; return undefined;
} }
@ -156,7 +152,7 @@ export default {
setTimeout(() => { setTimeout(() => {
hub.call('add_item_view', { hub.call('add_item_view', {
hub_item_name: this.hub_item_name hub_item_name: this.hub_item_name
}) });
// .then(() => { // .then(() => {
// erpnext.hub.item_view_cache.push(this.hub_item_name); // erpnext.hub.item_view_cache.push(this.hub_item_name);
// }); // });
@ -200,6 +196,7 @@ export default {
make_dialogs() { make_dialogs() {
this.make_contact_seller_dialog(); this.make_contact_seller_dialog();
this.make_report_item_dialog(); this.make_report_item_dialog();
this.make_editing_dialog();
}, },
add_to_saved_items() { add_to_saved_items() {
@ -208,7 +205,9 @@ export default {
hub_user: frappe.session.user hub_user: frappe.session.user
}) })
.then(() => { .then(() => {
const saved_items_link = `<b><a href="#marketplace/saved-items">${__('Saved')}</a></b>` const saved_items_link = `<b><a href="#marketplace/saved-items">${__(
'Saved'
)}</a></b>`;
frappe.show_alert(saved_items_link); frappe.show_alert(saved_items_link);
erpnext.hub.trigger('action:item_save'); erpnext.hub.trigger('action:item_save');
}) })
@ -221,9 +220,11 @@ export default {
hub.call('add_item_to_seller_featured_items', { hub.call('add_item_to_seller_featured_items', {
hub_item_name: this.hub_item_name, hub_item_name: this.hub_item_name,
hub_user: frappe.session.user hub_user: frappe.session.user
},) })
.then(() => { .then(() => {
const featured_items_link = `<b><a href="#marketplace/featured-items">${__('Added to Featured Items')}</a></b>` const featured_items_link = `<b><a href="#marketplace/featured-items">${__(
'Added to Featured Items'
)}</a></b>`;
frappe.show_alert(featured_items_link); frappe.show_alert(featured_items_link);
erpnext.hub.trigger('action:item_feature'); erpnext.hub.trigger('action:item_feature');
}) })
@ -258,7 +259,7 @@ export default {
.then(() => { .then(() => {
this.contact_seller_dialog.hide(); this.contact_seller_dialog.hide();
frappe.set_route('marketplace', 'buying', this.item.name); frappe.set_route('marketplace', 'buying', this.item.name);
erpnext.hub.trigger('action:send_message') erpnext.hub.trigger('action:send_message');
}); });
} }
}); });
@ -275,7 +276,10 @@ export default {
} }
], ],
primary_action: ({ message }) => { primary_action: ({ message }) => {
hub.call('add_reported_item', { hub_item_name: this.item.name, message }) hub.call('add_reported_item', {
hub_item_name: this.item.name,
message
})
.then(() => { .then(() => {
d.hide(); d.hide();
frappe.show_alert(__('Item Reported')); frappe.show_alert(__('Item Reported'));
@ -284,26 +288,62 @@ export default {
}); });
}, },
make_editing_dialog() {
this.edit_dialog = edit_details_dialog({
primary_action: {
fn: values => {
this.update_details(values);
this.edit_dialog.hide();
}
},
defaults: {
item_name: this.item.item_name,
hub_category: this.item.hub_category,
description: this.item.description
}
});
},
update_details(values) {
frappe.call('erpnext.hub_node.api.update_item', {
ref_doc: this.item.name,
data: values
})
.then(r => {
return this.get_item_details();
})
.then(() => {
frappe.show_alert(__(`${this.item.item_name} Updated`));
});
},
contact_seller() { contact_seller() {
this.contact_seller_dialog.show(); this.contact_seller_dialog.show();
}, },
report_item() { report_item() {
if (!hub.is_seller_registered()) { if (!hub.is_seller_registered()) {
frappe.throw(__('Please login as a Marketplace User to report this item.')); frappe.throw(
__('Please login as a Marketplace User to report this item.')
);
} }
this.report_item_dialog.show(); this.report_item_dialog.show();
}, },
edit_details() { edit_details() {
frappe.msgprint(__('This feature is under development...')); if (!hub.is_seller_registered()) {
frappe.throw(
__('Please login as a Marketplace User to edit this item.')
);
}
this.edit_dialog.show();
}, },
unpublish_item() { unpublish_item() {
frappe.msgprint(__('This feature is under development...')); frappe.msgprint(__('This feature is under development...'));
} }
} }
} };
</script> </script>
<style scoped></style> <style scoped></style>