cockpit.la: restaurant editing #7180

This commit is contained in:
Daniel Camargo 2015-11-27 22:32:22 -02:00
parent 9a1e157f72
commit 4415036668
13 changed files with 293 additions and 9 deletions

View File

@ -28,6 +28,9 @@ class Controller_api_restaurant_edit extends Crunchbutton_Controller_RestAccount
case 'notifications':
$this->_notifications();
break;
case 'menu':
$this->_menu();
break;
}
}
@ -86,6 +89,17 @@ class Controller_api_restaurant_edit extends Crunchbutton_Controller_RestAccount
}
}
private function _menu(){
switch ( $this->method() ) {
case 'post':
// $this->_menuSave();
break;
case 'get':
$this->_menuExport();
break;
}
}
private function _basicExport(){
$community = $this->restaurant->community()->get( 0 );
@ -165,6 +179,15 @@ class Controller_api_restaurant_edit extends Crunchbutton_Controller_RestAccount
$this->_return( $out );
}
private function _menuExport(){
$out = [ 'id_restaurant' => $this->restaurant->id_restaurant, 'permalink' => $this->restaurant->permalink ];
$out['categories'] = [];
foreach ( $this->restaurant->categories( ) as $category ) {
$out['categories'][] = $category->exports();
}
$this->_return( $out );
}
private function _return( $out ){
foreach( $out as $key => $val ){
if( is_numeric( $val ) ){

View File

@ -0,0 +1,5 @@
<?php
class Cockpit_Category extends Crunchbutton_Category {
}

View File

@ -0,0 +1,13 @@
<?php
class Cockpit_Dish extends Crunchbutton_Dish {
public function exports() {
$out = parent::exports();
foreach ( $out as $key => $value ) {
if( is_numeric( $value ) ){
$out[ $key ] = floatval( $value );
}
}
return $out;
}
}

View File

@ -0,0 +1,13 @@
<?php
class Cockpit_Option extends Crunchbutton_Option {
public function exports() {
$out = $this->properties();
$out['price'] = floatval( $out['price'] );
$out['prices'] = [];
foreach ($this->prices() as $price) {
$out['prices'][$price->id_option_price] = $price->exports();
}
return $out;
}
}

View File

@ -46,7 +46,7 @@ class Cockpit_Restaurant extends Crunchbutton_Restaurant {
WHERE o.id_restaurant = ? ' . $interval . ' )';
$keys[] = $this->id_restaurant;
$keys[] = $this->id_restaurant;
} else {
$query = 'SELECT COUNT(*) AS total
FROM `order` o
@ -61,7 +61,7 @@ class Cockpit_Restaurant extends Crunchbutton_Restaurant {
ORDER BY oa.id_order_action) actions ON actions.id_order = o.id_order
AND actions.id_order_action = oa.id_order_action
WHERE o.id_restaurant = ? ' . $interval;
$keys[] = $status;
$keys[] = $this->id_restaurant;
}

View File

@ -9,7 +9,7 @@ class Crunchbutton_Dish extends Cana_Table_Trackchange {
if( floatval( $option->price ) > 0 ){
$out['changeable_price'] = true;
}
$opts = $option->exports();
$opts['default'] = $opts['default'] ? true : false;
$out['_options'][] = $opts;

View File

@ -68,11 +68,11 @@
</div> <button class="button button-small button-empty button-green" title="Edit notes to driver" ng-click="notes_to_driver_edit(restaurant.id_restaurant);"><i class="fa fa-pencil"></i></button>
</td>
<td nowrap class="tb-v-center">
<a href="/restaurant/edit/{{restaurant.permalink}}">edit</a>
<a href="http://old.cockpit.crunchbutton.com/restaurants/{{restaurant.id_restaurant}}" target="_system"><button class="button button-small button-empty button-green"><i class="fa fa-pencil"></i>&nbsp;&nbsp;Edit</button></a>
<a href="/restaurant/payment-info/{{restaurant.permalink}}"><button class="button button-small button-empty button-green"><i class="fa fa-money"></i>&nbsp;&nbsp;Pay Info</button></a>
<a href="/restaurant/{{restaurant.permalink}}"><button class="button button-small button-empty button-green"><i class="fa fa-eye"></i>&nbsp;&nbsp;View</button></a>
<br>
<a href="/restaurant/edit/{{restaurant.permalink}}">edit (working in progress)</a>
</td>
</tr>
</table>

View File

@ -0,0 +1,175 @@
<div ng-controller="RestaurantEditMenuCtrl" class="tab-content">
<form name="form" novalidate ng-show="!loading">
<div class="support-box-wrap box-content2">
<div class="support-box-wrap-header">
<h1>Menu</h1>
<div class="support-box-header-actions-wrap">
<div class="support-box-header-actions">
<button ng-click="addCategory()" class="button button-small button-empty button-green"><i class="fa fa-plus"></i>&nbsp;&nbsp;Add Category</button>
</div>
</div>
<div class="divider"></div>
</div>
</div>
<div ng-repeat="category in restaurant.categories">
<div class="support-box-wrap box-content2">
<div class="support-box-wrap-header">
<h1>
<span ng-if="category.name">{{category.name}}</span>
<span ng-if="!category.name"><i>New Category</i></span>
</h1>
<div class="support-box-header-actions-wrap">
<div class="support-box-header-actions">
<button ng-click="addCategory()" class="button button-small button-empty button-green"><i class="fa fa-trash"></i>&nbsp;&nbsp;Delete Category</button>
<button ng-click="addDish()" class="button button-small button-empty button-green"><i class="fa fa-plus"></i>&nbsp;&nbsp;Add Dish</button>
<button ng-click="addCategory()" class="button button-small button-empty button-green"><i class="fa fa-arrow-up"></i></button>
<button ng-click="addCategory()" class="button button-small button-empty button-green"><i class="fa fa-arrow-down"></i></button>
</div>
</div>
<div class="divider"></div>
</div>
<div class="no-box-content-color" ng-repeat="dish in category._dishes">
<ng-form name="innerFormDish">
<ul ng-class="{'submitted':submitted}" class="ul-inputs inputs-group-dish divider">
<li class="li-input li-input-dish" ng-class="{'error':innerFormDish.dishName.$invalid}">
<div class="input"><input type="text" name="dishName" ng-model="dish.name" placeholder="Dish name"></div>
<div class="box-error">
<small ng-show="innerFormDish.dishName.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish" ng-class="{'error':innerFormDish.dishPrice.$invalid}">
<div class="input"><input type="number" step="any" name="dishPrice" ng-model="dish.price" ignore-mouse-wheel placeholder="Dish price"></div>
<div class="box-error">
<small ng-show="innerFormDish.dishPrice.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish" ng-class="{'error':innerFormDish.dishActive.$invalid}">
<div class="input">
<select name="dishActive" required ng-model="dish.active" ng-options="opt.value as opt.label for opt in active" ></select>
</div>
<div class="box-error">
<small ng-show="innerFormDish.dishActive.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish">
<button title="Delete dish" class="button button-small button-empty button-green"><i class="fa fa-trash"></i></button>
<button title="Move this dish up" class="button button-small button-empty button-green"><i class="fa fa-arrow-up"></i></button>
<button title="Move this dish down" class="button button-small button-empty button-green"><i class="fa fa-arrow-down"></i></button>
<button ng-if="!dish.expanded" ng-click="dish.expanded = true" title="Expand details" class="button button-small button-empty button-green"><i class="fa fa-expand"></i></button>
<button ng-if="dish.expanded" ng-click="dish.expanded = false" title="Collapse details" class="button button-small button-empty button-green"><i class="fa fa-compress"></i></button>
<button title="Copy this dish or its options" class="button button-small button-empty button-green"><i class="fa fa-gear"></i></button>
</li>
</ul>
<div ng-if="dish.expanded" class="dish-option-group">
<ul ng-class="{'submitted':submitted}" class="ul-inputs">
<li class="li-input li-input-dish" ng-class="{'error':innerFormDish.dishDescription.$invalid}">
<div class="input"><input type="text" name="dishDescription" ng-model="dish.description" placeholder="Dish description"></div>
<div class="box-error">
<small ng-show="innerFormDish.dishDescription.$error.required">Required.</small>
</div>
<div class="notes">60 characters</div>
</li>
<li class="li-input" ng-class="{'error':innerFormDish.expandedView.$invalid}">
<div class="label">Expanded view when added to cart</div>
<div class="input">
<select name="expandedView" required ng-model="dish.expand_view" ng-options="opt.value as opt.label for opt in yesNo" ></select>
</div>
<div class="box-error">
<small ng-show="innerFormDish.expandedView.$error.required">Required.</small>
</div>
<div class="notes">
For when you want the user to see options, like sizes and pizza toppings
</div>
</li>
<li class="li-input" ng-class="{'error':innerFormDish.showStar.$invalid}">
<div class="label">Show star</div>
<div class="input">
<select name="showStar" required ng-model="dish.top" ng-options="opt.value as opt.label for opt in yesNo" ></select>
</div>
<div class="box-error">
<small ng-show="innerFormDish.showStar.$error.required">Required.</small>
</div>
<div class="notes">
Usually just for items in the first category on the menu
</div>
</li>
</ul>
<div class="divider"></div>
<div ng-repeat="option in dish._options" class="divider">
<ng-form name="innerFormOption">
<ul ng-class="{'submitted':submitted}" class="ul-inputs inputs-group-dish">
<li class="li-input li-input-dish" ng-class="{'error':innerFormOption.optionName.$invalid}">
<div class="input"><input type="text" name="optionName" ng-model="option.name" placeholder="Option name"></div>
<div class="box-error">
<small ng-show="innerFormOption.optionName.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish" ng-class="{'error':innerFormOption.optionPrice.$invalid}">
<div class="input"><input type="number" step="any" name="optionPrice" ng-model="option.price" ignore-mouse-wheel placeholder="Additonal amount"></div>
<div class="box-error">
<small ng-show="innerFormOption.optionPrice.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish" ng-class="{'error':innerFormOption.dishActive.$invalid}">
<div class="input">
<select name="dishActive" required ng-model="dish.active" ng-options="opt.value as opt.label for opt in active" ></select>
</div>
<div class="box-error">
<small ng-show="innerFormOption.dishActive.$error.required">Required.</small>
</div>
</li>
<li class="li-input li-input-dish">
<button ng-if="!option.default" ng-click="option.default = true" title="Default" class="button button-small button-empty button-green"><i class="fa fa-check-square"></i></button>
<button ng-if="option.default" ng-click="option.default = false" title="Default" class="button button-small button-empty button-green"><i class="fa fa-square"></i></button>
<button title="Delete dish" class="button button-small button-empty button-green"><i class="fa fa-trash"></i></button>
<button title="Move this dish up" class="button button-small button-empty button-green"><i class="fa fa-arrow-up"></i></button>
<button title="Move this dish down" class="button button-small button-empty button-green"><i class="fa fa-arrow-down"></i></button>
<button title="Copy this dish or its options" class="button button-small button-empty button-green"><i class="fa fa-gear"></i></button>
</li>
</ul>
</ng-form>
</div>
<div class="divider"></div>
</div>
</ng-form>
</div>
</div>
</div>
</form>
<div class="support-box-wrap box-content2">
<div class="no-box-content-color">
<ul class="ul-inputs">
<li class="li-input" ng-show="!isSaving">
<button class="button save" ng-click="save();">Save</button>
</li>
<li class="li-input" ng-show="isSaving">
<i class="fa fa-circle-o-notch fa-spin"></i>
</li>
</ul>
</div>
</div>
</div>

View File

@ -4,8 +4,6 @@
<div class="support-boxes">
<div class="support-box-wrap box-content2">
<div class="support-box-wrap-header">
<h1>Notifications</h1>
@ -29,7 +27,6 @@
<small ng-show="form.restaurantSendOrderNotifications.$error.required">Required.</small>
</div>
</li>
</ul>
</div>
</div>

View File

@ -9,11 +9,12 @@
<div ng-if="!loading">
<ui-tabs>
<ui-tab title="Basic Information" icon="info" default="true" id="editBasic" path="assets/view/restaurants-edit-basic.html" method="editBasic"></ui-tab>
<ui-tab title="Basic Information" default="true" icon="info" id="editBasic" path="assets/view/restaurants-edit-basic.html" method="editBasic"></ui-tab>
<ui-tab title="Delivery / Logistics" icon="truck" id="editDelivery" path="assets/view/restaurants-edit-delivery.html" method="editDelivery"></ui-tab>
<ui-tab title="Hours" icon="clock-o" id="editHours" path="assets/view/restaurants-edit-hours.html" method="editHours"></ui-tab>
<ui-tab title="Notes" icon="sticky-note-o" id="editNotes" path="assets/view/restaurants-edit-notes.html" method="editNotes"></ui-tab>
<ui-tab title="Notifications" icon="volume-up" id="editNotifications" path="assets/view/restaurants-edit-notifications.html" method="editNotifications"></ui-tab>
<ui-tab title="Menu" icon="volume-up" id="editMenu" path="assets/view/restaurants-edit-menu.html" method="editMenu"></ui-tab>
</ui-tabs>
</div>

View File

@ -456,6 +456,7 @@ NGApp.controller('RestaurantEditCtrl', function ( $scope, $rootScope, $routePara
$scope.editDelivery = function(){};
$scope.editNotes = function(){};
$scope.editNotifications = function(){};
$scope.editMenu = function(){};
reset();
@ -517,6 +518,39 @@ NGApp.controller('RestaurantEditNotificationsCtrl', function ( $scope, Restauran
});
NGApp.controller('RestaurantEditMenuCtrl', function ( $scope, RestaurantEditService ) {
$scope.yesNo = RestaurantEditService.yesNo();
$scope.active = RestaurantEditService.active();
var load = function(){
RestaurantEditService.load.menu( RestaurantEditService.permalink, function( json ) {
$scope.restaurant = json;
$scope.loading = false;
} );
}
$scope.save = function(){
if( $scope.restaurant.id_restaurant ){
} else {
App.alert( 'Something wrong!' );
}
}
$scope.addNotification = function(){
if( $scope.restaurant.id_restaurant ){
if( !$scope.restaurant.menu ){
$scope.restaurant.menu = [];
}
$scope.restaurant.menu.push( { type: 'sms', value: null, active: true } );
}
}
load();
});
NGApp.controller('RestaurantEditDeliveryCtrl', function ( $scope, RestaurantEditService ) {

View File

@ -369,6 +369,11 @@ NGApp.factory( 'RestaurantEditService', function( $rootScope, $resource, $routeP
load.get( { 'permalink': permalink, 'action': 'notifications' }, function( data ){
callback( data );
} );
},
menu : function( permalink, callback ){
load.get( { 'permalink': permalink, 'action': 'menu' }, function( data ){
callback( data );
} );
}
}
@ -379,6 +384,13 @@ NGApp.factory( 'RestaurantEditService', function( $rootScope, $resource, $routeP
return options;
}
service.active = function(){
var options = [];
options.push( { value: true, label: 'Active' } );
options.push( { value: false, label: 'Inactive' } );
return options;
}
service.timezones = function(){
var timezones = [];
timezones.push( { value: 'America/New_York', label: 'Eastern' } );

View File

@ -1089,6 +1089,17 @@ input {
color: #5d5f63;
margin-top: 1em;
}
.inputs-group-dish .li-input-dish{
width:22%;
float:left;
margin-right:1em;
}
.dish-option-group{
margin-left:2em;
border-left: 3px solid #CCC;
padding-left:1em;
}
.li-input-disabled input[type="checkbox"].switch + div {
background: #CCC !important;