Shifts - Make the cbtn.io work with angularjs #2546
This commit is contained in:
parent
71be79da05
commit
0da5a11e51
@ -67,7 +67,5 @@ class Controller_api_driverorders extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
echo json_encode($exports);
|
||||
}
|
||||
|
||||
// if( !$justMineOrders || ( $justMineOrders && $order->lastStatus[ 'id_admin' ] == c::admin()->id_admin ) ){
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class Controller_api_drivershifts extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
public function init() {
|
||||
$communities = c::admin()->communitiesHeDeliveriesFor();
|
||||
$_communities = [];
|
||||
foreach( $communities as $community ){
|
||||
$_communities[] = $community->id_community;
|
||||
}
|
||||
// get the shifts for the next 7 days
|
||||
$shifts = Crunchbutton_Community_Shift::nextShiftsByCommunities( $_communities );
|
||||
$export = [];
|
||||
foreach ( $shifts as $shift ) {
|
||||
$drivers = $shift->getDrivers();
|
||||
$mine = 0;
|
||||
$_drivers = [];
|
||||
foreach ( $drivers as $driver ) {
|
||||
if( $driver->id_admin == c::admin()->id_admin ){
|
||||
$mine = 1;
|
||||
}
|
||||
$_drivers[] = [ 'name' => $driver->name, 'phone' => $driver->phone() ];
|
||||
}
|
||||
$export[] = Model::toModel( [
|
||||
'id_community_shift' => $shift->id_community_shift,
|
||||
'community' => $shift->community()->name,
|
||||
'date' => [ 'day' => $shift->dateStart()->format( 'D, M jS' ), 'start_end' => $shift->startEndToString(), 'timezone' => $shift->timezoneAbbr() ],
|
||||
'drivers' => $_drivers,
|
||||
'mine' => $mine
|
||||
] );
|
||||
}
|
||||
echo json_encode( $export );
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,6 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
||||
}
|
||||
|
||||
public function getOrdersList( $all = false ){
|
||||
|
||||
$hours = 12;
|
||||
$orders = Order::deliveryOrders( $hours );
|
||||
|
||||
|
||||
@ -64,9 +64,14 @@ class Crunchbutton_Community_Shift extends Cana_Table {
|
||||
public function nextShiftsByCommunities( $communities ){
|
||||
if( count( $communities ) > 0 ){
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
$now_formated = $now->format( 'Y-m-d' );
|
||||
$now->modify( '+ 7 days' );
|
||||
$next_days_formated = $now->format( 'Y-m-d' );
|
||||
$query = 'SELECT cs.* FROM community_shift cs
|
||||
WHERE cs.id_community IN( ' . join( ',', $communities ) . ' ) AND
|
||||
DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) >= "' . $now->format( 'Y-m-d' ) . '" ORDER BY cs.date_start ASC LIMIT 20';
|
||||
DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) >= "' . $now_formated . '" AND
|
||||
DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) <= "' . $next_days_formated . '"
|
||||
ORDER BY cs.date_start ASC';
|
||||
return Crunchbutton_Community_Shift::q( $query );
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -40,3 +40,4 @@
|
||||
<script src="/assets/cockpit/js/service.navigation.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/cockpit/js/service.account.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/cockpit/js/service.driverorders.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/cockpit/js/service.drivershifts.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
@ -9,7 +9,7 @@
|
||||
<? /* @todo: make this a diff date. write date diff in js */ ?>
|
||||
<div class="last-updated">Last Updated: <span class="last-updated-time">{{newDriverOrders.time.getTime() | date: 'hh:mm a'}}</span></div>
|
||||
|
||||
<div class="drivers-order-list-filter">
|
||||
<div class="list-filter">
|
||||
<button class="button orange" ng-class="{ 'inactive' : !show.all }" ng-click="show.all = true">All</button>
|
||||
<button class="button orange" ng-class="{ 'inactive' : show.all }" ng-click="show.all = false">Mine</button>
|
||||
<div class="divider"></div>
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
<div ng-if="driverorders">
|
||||
|
||||
<div class="box-with-shadown item" ng-repeat="order in driverorders | filter:filterOrders" ng-class="order.lastStatus.status">
|
||||
<div class="list-box item" ng-repeat="order in driverorders | filter:filterOrders" ng-class="order.lastStatus.status">
|
||||
|
||||
<!-- action -->
|
||||
<div class="action">
|
||||
|
||||
@ -1,4 +1,45 @@
|
||||
<div class="top-pad"></div>
|
||||
|
||||
<div class="content-padding">
|
||||
|
||||
<div class="list-filter">
|
||||
<button class="button orange" ng-class="{ 'inactive' : !show.all }" ng-click="show.all = true">All</button>
|
||||
<button class="button orange" ng-class="{ 'inactive' : show.all }" ng-click="show.all = false">Mine</button>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
|
||||
shifts
|
||||
<div class="drivers-shifts-list">
|
||||
|
||||
<div ng-if="drivershifts">
|
||||
|
||||
<div class="list-box item" ng-repeat="shift in drivershifts | filter:filterShifts">
|
||||
|
||||
<div class="day">{{shift.date.day}}</div>
|
||||
<div class="start_end">{{shift.date.start_end}}</div>
|
||||
<div class="timezone">{{shift.date.timezone}}</div>
|
||||
<div class="community">{{shift.community}}</div>
|
||||
|
||||
<div nf-if="shift.drivers">
|
||||
<div class="drivers">
|
||||
<div class="driver" ng-repeat="driver in shift.drivers">
|
||||
<div class="name">{{driver.name}}</div>
|
||||
<div class="phone">{{driver.phone}}</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="!shift.drivers">
|
||||
No drivers
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-if="!drivershifts">
|
||||
You currently have no orders to deliver.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@ -4,14 +4,10 @@ NGApp.controller('DefaultCtrl', function ($scope, $http, $location, MainNavigati
|
||||
}
|
||||
});
|
||||
|
||||
NGApp.controller('MainHeaderCtrl', function ( $scope, $rootScope) {
|
||||
|
||||
});
|
||||
NGApp.controller('MainHeaderCtrl', function ( $scope, $rootScope) {} );
|
||||
|
||||
NGApp.controller('SideMenuCtrl', function ($scope) {
|
||||
$scope.setupPermissions = function() {
|
||||
|
||||
}
|
||||
$scope.setupPermissions = function() {}
|
||||
});
|
||||
|
||||
NGApp.controller('LoginCtrl', function($scope, AccountService) {
|
||||
@ -24,12 +20,10 @@ NGApp.controller('LoginCtrl', function($scope, AccountService) {
|
||||
}
|
||||
});
|
||||
|
||||
NGApp.controller('DriversOrderCtrl', function ($http, $scope, $rootScope, DriverOrders) {
|
||||
|
||||
});
|
||||
NGApp.controller('DriversOrderCtrl', function ( $http, $scope, $rootScope, DriverOrders ) {} );
|
||||
|
||||
|
||||
NGApp.controller('DriversOrdersCtrl', function ($http, $scope, $rootScope, DriverOrdersService, AccountService ) {
|
||||
NGApp.controller('DriversOrdersCtrl', function ( $scope, $rootScope, DriverOrdersService, AccountService ) {
|
||||
|
||||
// The scope just need the account's user object
|
||||
$scope.account = { user : AccountService.user } ;
|
||||
@ -87,6 +81,28 @@ NGApp.controller('DriversOrdersCtrl', function ($http, $scope, $rootScope, Drive
|
||||
|
||||
} );
|
||||
|
||||
NGApp.controller('DriversShiftsCtrl', function ($http, $scope, $rootScope) {
|
||||
NGApp.controller( 'DriversShiftsCtrl', function ( $scope, $rootScope, DriverShiftsService ) {
|
||||
|
||||
});
|
||||
$scope.show = { all : true };
|
||||
|
||||
$scope.filterShifts = function( shift ){
|
||||
if( $scope.show.all ){
|
||||
return true;
|
||||
} else {
|
||||
if( shift.mine ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// List
|
||||
$scope.list = function(){
|
||||
DriverShiftsService.list( function( data ){
|
||||
$scope.drivershifts = data;
|
||||
} );
|
||||
}
|
||||
|
||||
// Load the shifts
|
||||
$scope.list();
|
||||
|
||||
} );
|
||||
@ -1,4 +1,3 @@
|
||||
// DriverOrdersService service
|
||||
NGApp.factory( 'DriverOrdersService', function( $rootScope, $resource ) {
|
||||
|
||||
var service = {};
|
||||
@ -47,4 +46,4 @@ NGApp.factory( 'DriverOrdersService', function( $rootScope, $resource ) {
|
||||
}
|
||||
|
||||
return service;
|
||||
} );
|
||||
} );
|
||||
13
www/assets/cockpit/js/service.drivershifts.js
Normal file
13
www/assets/cockpit/js/service.drivershifts.js
Normal file
@ -0,0 +1,13 @@
|
||||
NGApp.factory( 'DriverShiftsService', function( $rootScope, $resource ) {
|
||||
|
||||
var service = {};
|
||||
|
||||
// Create a private resource 'shifts'
|
||||
var shifts = $resource( App.service + 'drivershifts', {}, {} );
|
||||
|
||||
service.list = function( callback ){
|
||||
shifts.query( {}, function( data ){ callback( data ); } );
|
||||
}
|
||||
|
||||
return service;
|
||||
} );
|
||||
@ -693,11 +693,10 @@ input {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.box-with-shadown{
|
||||
.list-box{
|
||||
background: #FFF;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
box-shadow: 0px 3px 2px #AAB2BD;
|
||||
}
|
||||
|
||||
/* drivers order list page */
|
||||
@ -755,15 +754,16 @@ input {
|
||||
.drivers-order-list .item .info .customer{
|
||||
font-size:1em;
|
||||
}
|
||||
.drivers-order-list-filter{
|
||||
|
||||
.list-filter{
|
||||
margin: 0 0 1em 0;
|
||||
}
|
||||
.drivers-order-list-filter .button{
|
||||
.list-filter .button{
|
||||
display: table;
|
||||
float: left;
|
||||
width: 100px;
|
||||
margin-right: 1em;
|
||||
}
|
||||
.drivers-order-list-filter .button.inactive{
|
||||
.list-filter .button.inactive{
|
||||
opacity: 0.5;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user