2018-08-23 12:22:20 +05:30
< template >
< div
class = "marketplace-page"
: data - page - name = "page_name"
>
2018-08-23 22:42:41 +05:30
< notification-message
v - if = "last_sync_message"
: message = "last_sync_message"
@ remove - message = "clear_last_sync_message"
> < / notification-message >
2018-08-27 20:37:06 +05:30
< div class = "flex justify-between align-flex-end margin-bottom" >
2018-08-23 21:25:53 +05:30
< h5 > { { page _title } } < / h5 >
< button class = "btn btn-primary btn-sm publish-items"
2018-08-24 16:38:34 +05:30
: disabled = "no_selected_items"
@ click = "publish_selected_items"
>
2018-08-23 21:25:53 +05:30
< span > { { publish _button _text } } < / span >
< / button >
< / div >
< item-cards-container
2018-08-25 21:54:49 +05:30
: container _name = "page_title"
2018-08-23 21:25:53 +05:30
: items = "selected_items"
2018-08-24 16:38:34 +05:30
: item _id _fieldname = "item_id_fieldname"
2018-08-25 13:18:30 +05:30
: is _local = "true"
2018-08-24 16:38:34 +05:30
: editable = "true"
@ remove - item = "remove_item_from_selection"
2018-08-23 21:25:53 +05:30
: empty _state _message = "empty_state_message"
: empty _state _bordered = "true"
: empty _state _height = "80"
>
< / item-cards-container >
2018-08-30 15:35:06 +05:30
< p class = "text-muted" > { { valid _items _instruction } } < / p >
2018-08-23 21:25:53 +05:30
2018-08-23 13:52:41 +05:30
< search-input
2018-08-23 21:25:53 +05:30
: placeholder = "search_placeholder"
2018-08-23 13:52:41 +05:30
: on _search = "get_valid_items"
v - model = "search_value"
>
< / search-input >
2018-08-23 21:25:53 +05:30
2018-08-23 12:22:20 +05:30
< item-cards-container
: items = "valid_items"
2018-08-24 16:38:34 +05:30
: item _id _fieldname = "item_id_fieldname"
2018-08-25 13:18:30 +05:30
: is _local = "true"
2018-08-24 16:38:34 +05:30
: on _click = "show_publishing_dialog_for_item"
2018-08-23 12:22:20 +05:30
>
< / item-cards-container >
< / div >
< / template >
< script >
2018-08-25 14:09:01 +05:30
import NotificationMessage from '../components/NotificationMessage.vue' ;
import { ItemPublishDialog } from '../components/item_publish_dialog' ;
2018-08-23 12:22:20 +05:30
export default {
name : 'publish-page' ,
2018-08-27 10:12:45 +05:30
components : {
NotificationMessage
} ,
2018-08-23 12:22:20 +05:30
data ( ) {
return {
page _name : frappe . get _route ( ) [ 1 ] ,
valid _items : [ ] ,
2018-08-23 21:25:53 +05:30
selected _items : [ ] ,
2018-08-24 16:38:34 +05:30
items _data _to _publish : { } ,
2018-08-23 21:25:53 +05:30
search _value : '' ,
2018-08-24 16:38:34 +05:30
item _id _fieldname : 'item_code' ,
2018-08-23 21:25:53 +05:30
// Constants
2018-08-30 12:01:04 +05:30
// TODO: multiline translations don't work
2018-08-30 15:35:06 +05:30
page _title : _ _ ( 'Publish Items' ) ,
2018-08-23 21:25:53 +05:30
search _placeholder : _ _ ( 'Search Items ...' ) ,
2020-11-25 04:41:51 +01:00
empty _state _message : _ _ ( 'No Items selected yet. Browse and click on items below to publish.' ) ,
valid _items _instruction : _ _ ( 'Only items with an image and description can be published. Please update them if an item in your inventory does not appear.' ) ,
2018-08-23 22:42:41 +05:30
last _sync _message : ( hub . settings . last _sync _datetime )
2021-08-19 13:41:10 +05:30
? _ _ ( 'Last sync was {0}.' , [ ` <a href="#marketplace/profile"> ${ comment _when ( hub . settings . last _sync _datetime ) } </a> ` ] ) +
2020-11-25 04:41:51 +01:00
` <a href="#marketplace/published-items"> ${ _ _ ( 'See your Published Items.' ) } </a> `
2018-08-23 22:42:41 +05:30
: ''
2018-08-23 12:22:20 +05:30
} ;
} ,
2018-08-23 21:25:53 +05:30
computed : {
no _selected _items ( ) {
return this . selected _items . length === 0 ;
} ,
publish _button _text ( ) {
const number = this . selected _items . length ;
2018-08-30 15:35:06 +05:30
let text = _ _ ( 'Publish' ) ;
2018-08-23 21:25:53 +05:30
if ( number === 1 ) {
2018-08-30 15:35:06 +05:30
text = _ _ ( 'Publish 1 Item' ) ;
2018-08-23 21:25:53 +05:30
}
if ( number > 1 ) {
2018-08-30 15:35:06 +05:30
text = _ _ ( 'Publish {0} Items' , [ number ] ) ;
2018-08-23 21:25:53 +05:30
}
2018-08-30 15:35:06 +05:30
return text ;
2018-08-24 16:38:34 +05:30
} ,
items _dict ( ) {
let items _dict = { } ;
this . valid _items . map ( item => {
items _dict [ item [ this . item _id _fieldname ] ] = item
} )
return items _dict ;
} ,
2018-08-23 21:25:53 +05:30
} ,
2018-08-23 12:22:20 +05:30
created ( ) {
this . get _valid _items ( ) ;
2018-08-24 16:38:34 +05:30
this . make _publishing _dialog ( ) ;
2018-08-23 12:22:20 +05:30
} ,
methods : {
get _valid _items ( ) {
frappe . call (
'erpnext.hub_node.api.get_valid_items' ,
{
search _value : this . search _value
}
)
2018-08-23 13:52:41 +05:30
. then ( ( r ) => {
this . valid _items = r . message ;
2018-08-23 12:22:20 +05:30
} )
2018-08-23 22:42:41 +05:30
} ,
2018-08-24 16:38:34 +05:30
publish _selected _items ( ) {
frappe . call (
'erpnext.hub_node.api.publish_selected_items' ,
{
items _to _publish : this . selected _items
}
)
. then ( ( r ) => {
this . selected _items = [ ] ;
2018-08-31 16:15:06 +05:30
return frappe . db . get _doc ( 'Marketplace Settings' ) ;
2018-08-24 16:38:34 +05:30
} )
. then ( doc => {
hub . settings = doc ;
this . add _last _sync _message ( ) ;
} ) ;
} ,
add _last _sync _message ( ) {
2020-11-25 04:41:51 +01:00
this . last _sync _message = _ _ ( 'Last sync was {0}.' ,
[ ` <a href="#marketplace/profile"> ${ comment _when ( hub . settings . last _sync _datetime ) } </a> ` ]
) + ` <a href="#marketplace/published-items"> ${ _ _ ( 'See your Published Items' ) } </a>. ` ;
2018-08-24 16:38:34 +05:30
} ,
2018-08-23 22:42:41 +05:30
clear _last _sync _message ( ) {
this . last _sync _message = '' ;
2018-08-24 16:38:34 +05:30
} ,
remove _item _from _selection ( item _code ) {
this . selected _items = this . selected _items
. filter ( item => item . item _code !== item _code ) ;
} ,
make _publishing _dialog ( ) {
this . item _publish _dialog = ItemPublishDialog (
{
fn : ( values ) => {
this . add _item _to _publish ( values ) ;
this . item _publish _dialog . hide ( ) ;
}
} ,
{
fn : ( ) => {
const values = this . item _publish _dialog . get _values ( true ) ;
this . update _items _data _to _publish ( values ) ;
}
}
) ;
} ,
add _item _to _publish ( values ) {
this . update _items _data _to _publish ( values ) ;
const item _code = values . item _code ;
let item _doc = this . items _dict [ item _code ] ;
const item _to _publish = Object . assign ( { } , item _doc , values ) ;
this . selected _items . push ( item _to _publish ) ;
} ,
update _items _data _to _publish ( values ) {
this . items _data _to _publish [ values . item _code ] = values ;
} ,
show _publishing _dialog _for _item ( item _code ) {
let item _data = this . items _data _to _publish [ item _code ] ;
if ( ! item _data ) { item _data = { item _code } ; } ;
this . item _publish _dialog . clear ( ) ;
const item _doc = this . items _dict [ item _code ] ;
if ( item _doc ) {
this . item _publish _dialog . fields _dict . image _list . set _data (
item _doc . attachments . map ( attachment => attachment . file _url )
) ;
}
this . item _publish _dialog . set _values ( item _data ) ;
this . item _publish _dialog . show ( ) ;
2018-08-23 12:22:20 +05:30
}
}
}
< / script >
< style scoped > < / style >