").dxList( {
items : executiveSummary,
height : "100%",
itemTemplate : function( item ) {
let container = $("
");
container.append( $("
").text( item.heading ))
container.append( $("
").text( item.detail ));
container.append( $("
").append( $("").text( "Action:" ) ).append( $("").text( item.recommendedAction ) ));
return container;
}
}).addClass( "executive-summary" );
}
TastewiseMenuInsightsPopup.prototype._createTastewiseOpportunityGrid = function( tastewiseOpportunities ) {
return $("").dxDataGrid( {
dataSource : tastewiseOpportunities,
rowAlternationEnabled : true,
scrolling : { mode : "virtual" },
height : "100%",
columns : [
{ dataField : "image_url", cellTemplate : function( container, options ) {
let img = $("
![]()
").attr( {
src : options.data.image_url,
width : "100%"
});
container.append( img );
}},
// "restaurant_name",
"name",
"description",
"ingredients",
"price"
// "tw_id",
]
}).dxDataGrid( "instance" );
}
TastewiseMenuInsightsPopup.prototype.bestSellingOpsTemplate = function () {
let instance = this;
let menuInsights = instance.menuInsights;
if( ! menuInsights || ! menuInsights.bestselling_opportunities ) return $("
" );
return instance._createTastewiseOpportunityGrid( menuInsights.bestselling_opportunities ).element();
}
TastewiseMenuInsightsPopup.prototype.ltoOpsTemplate = function () {
let instance = this;
let menuInsights = instance.menuInsights;
if( ! menuInsights || ! menuInsights.lto_opportunities ) return $("
" );
return instance._createTastewiseOpportunityGrid( menuInsights.lto_opportunities ).element();
}
TastewiseMenuInsightsPopup.prototype.ingredientComparisonTemplate = function () {
let instance = this;
let menuInsights = instance.menuInsights;
if( ! menuInsights || ! menuInsights.ingredient_comparison ) return $("
" );
return $("
").dxDataGrid( {
height : "100%",
scrolling : { mode : "virtual" },
dataSource : {
sort : [{ getter : "market_share", desc : true }],
store : {
type : "array",
data : menuInsights.ingredient_comparison,
key : "name"
}
},
columns : [
{ dataField : "name", caption : "Ingredient" },
{ dataField : "market_share", format : { type : "percent", precision : 1 }, dataType : "number",
calculateCellValue : function( rowData ) {
if( rowData.market_share ) {
return rowData.market_share / 100.0;
} else {
return null;
}
} },
{ dataField : "market_yoy", caption : "Market YoY", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.market_yoy ) {
return rowData.market_yoy / 100.0;
} else {
return null;
} }
},
{ dataField : "market_index", dataType : "number", format : { type : "fixedPoint", precision : 0 }},
{ dataField : "restaurant_share", caption : "Rest. Share", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.restaurant_share ) {
return rowData.restaurant_share / 100.0;
} else {
return null;
} }
},
{ dataField : "restaurant_yoy", caption : "Rest. YoY", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.restaurant_yoy ) {
return rowData.restaurant_yoy / 100.0;
} else {
return null;
} }
},
{ dataField : "restaurant_index", caption : "Rest. Index", dataType : "number", format : { type : "fixedPoint", precision : 0 }},
{ dataField : "index_signal" }
],
rowAlternationEnabled : true,
scrolling : { mode : "virtual" }
})
}
TastewiseMenuInsightsPopup.prototype.dishComparisonTemplate = function () {
let instance = this;
let menuInsights = instance.menuInsights;
if( ! menuInsights || ! menuInsights.dish_comparison ) return $("
" );
return $("
").dxDataGrid( {
height : "100%",
scrolling : { mode : "virtual" },
dataSource : {
sort : [{ getter : "market_share", desc : true }],
store : {
type : "array",
data : menuInsights.dish_comparison,
key : "name"
}
},
columns : [
{ dataField : "name", caption : "Dish" },
{ dataField : "market_share", format : { type : "percent", precision : 1 }, dataType : "number",
calculateCellValue : function( rowData ) {
if( rowData.market_share ) {
return rowData.market_share / 100.0;
} else {
return null;
}
} },
{ dataField : "market_yoy", caption : "Market YoY", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.market_yoy ) {
return rowData.market_yoy / 100.0;
} else {
return null;
} }
},
{ dataField : "market_index", dataType : "number", format : { type : "fixedPoint", precision : 0 }},
{ dataField : "restaurant_share", caption : "Rest. Share", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.restaurant_share ) {
return rowData.restaurant_share / 100.0;
} else {
return null;
} }
},
{ dataField : "restaurant_yoy", caption : "Rest. YoY", dataType : "number", format : { type : "percent", precision : 1 },
calculateCellValue : function( rowData ) {
if( rowData.restaurant_yoy ) {
return rowData.restaurant_yoy / 100.0;
} else {
return null;
} }
},
{ dataField : "restaurant_index", caption : "Rest. Index", dataType : "number", format : { type : "fixedPoint", precision : 0 }},
{ dataField : "index_signal" }
],
rowAlternationEnabled : true,
scrolling : { mode : "virtual" }
})
}
TastewiseMenuInsightsPopup.prototype.show = function() {
let instance = this;
instance.skuSelect = $("
").dxSelectBox( {
width : 300,
placeholder : "Select a SKU",
dataSource : Fse.Data.newDataSource( { object : "CRM.tastewiseSKUs", paginate : true, pageSize : 50, key : "sku" } ),
displayExpr : "skuFull",
valueExpr : "sku",
showClearButton : true,
searchEnabled : true,
searchExpr : "skuFull",
searchMode : "contains",
onSelectionChanged : function( e ) {
instance.getMenuInsights();
}
}).dxSelectBox( "instance" )
instance.categoryTextBox = $("
").dxTextBox( {
showClearButton : true,
width : 200,
placeholder : "Enter a category, keyword, or ingredient",
onValueChanged : function( e ) {
instance.getMenuInsights();
}
}).dxTextBox( "instance" );
let popup = $("
").dxPopup( {
title : "Menu Insights powered by Tastewise",
width : "80vw",
height : "80vh",
contentTemplate : function( ){
let box = $("
").dxBox( {
height : "100%",
direction : "col",
items : [
{ baseSize : 30,
template : function() {
return $("
").dxToolbar( {
items : [
{ location : "before",
template : function() {
return instance.skuSelect.element();
}
},
{ location : "before",
template : function() {
return instance.categoryTextBox.element();
}
}
]
})
}
},
{ ratio : 1,
template : function() {
instance.tabPanel = $("
").dxTabPanel( {
height : "100%",
items : [
{ title : "Summary",
template : function() {
return $("
").css( { "height" : "100%" }).append( instance.executiveSummaryTemplate() )
}
},
{ title : "Best Selling",
template : function() {
return $("
").css( { "height" : "100%" }).append( instance.bestSellingOpsTemplate() )
}
},
{ title : "LTO",
template : function() {
return $("
").css( { "height" : "100%" }).append( instance.ltoOpsTemplate() )
}
},
{ title : "Dish Comparison",
template : function() {
return $("
").css( { "height" : "100%" }).append( instance.dishComparisonTemplate() )
}
},
{ title : "Ingredient Comparison",
template : function() {
return $("
").css( { "height" : "100%" }).append( instance.ingredientComparisonTemplate() )
}
},
]
}).dxTabPanel( "instance" );
return instance.tabPanel.element();
}
}
]
})
return box;
}
}).appendTo( $("body") ).dxPopup( "show" )
}