Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add carrier orders list #1218

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/carrier-mobile-ionic/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { AppRoutingModule } from './app-routing.module';
import { RouteReuseStrategy } from '@angular/router';
import { AppComponent } from './app.component';
import { MenuModule } from 'components/menu/menu.module';
import { OrdersListModule } from 'components/orders-list/orders-list.module';

@NgModule({
schemas: [NO_ERRORS_SCHEMA],
Expand All @@ -49,6 +50,7 @@ import { MenuModule } from 'components/menu/menu.module';
}),
HttpClientModule,
PipesModule,
OrdersListModule,
],
bootstrap: [AppComponent],
entryComponents: [AppComponent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ <h1 class="title header-bar-big-title">
{{ 'MENU.MAIN' | translate }}
</ion-label>
</ion-item>

<ion-item button (click)="openOrdersListModal()">
<ion-icon name="bicycle"></ion-icon>
<ion-label>
Orders List
</ion-label>
</ion-item>
<ion-item
routerLink="/deliveries"
routerDirection="root"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component } from '@angular/core';
import { Store } from 'services/store.service';
import { environment } from 'environments/environment';
import { ModalController } from '@ionic/angular';
import { OrdersListComponent } from '../orders-list/orders-list.component';

@Component({
selector: 'e-cu-menu',
Expand All @@ -10,7 +12,7 @@ import { environment } from 'environments/environment';
export class MenuComponent {
companyName: string;

constructor(private store: Store) {
constructor(private store: Store, private modalCtrl: ModalController) {
this.companyName = environment.APP_NAME;
}

Expand All @@ -19,4 +21,12 @@ export class MenuComponent {
}

menuOpened() {}

async openOrdersListModal() {
const modal = await this.modalCtrl.create({
component: OrdersListComponent,
cssClass: 'orders-list-modal',
});
await modal.present();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<ion-header>
<ion-toolbar color="primary">
<ion-title>Select Order for Delivery ...</ion-title>
</ion-toolbar>
</ion-header>

<ion-content fullscreen color="light">
<ion-card button *ngFor="let order of filteredList">
<ion-card-content (click)="selectNewOrder(order.id)">
<ion-item>
<ion-avatar slot="start">
<img [src]="order.warehouse.logo" />
</ion-avatar>
<ion-label>
<p>name: {{ order.warehouse.name }}</p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valiopld why "name", but "Phone", where is consistency (even if it's ugly, things should be consistently ugly)

<p>Phone: {{ order.warehouse.contactPhone }}</p>
<p>Email: {{ order.warehouse.cantactEmail }}</p>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valiopld did you tested this? Is it not a typo .cantactEmail???

</ion-label>
</ion-item>

<ion-item>
<ion-avatar slot="start">
<img [src]="order.user.image" />
</ion-avatar>
<ion-label>
<p>
name: {{ order.user.firstName }}
{{ order.user.lastName }}
</p>
<p>Phone: {{ order.user.phone }}</p>
<p>Email:</p>
<p>Adress: {{ order.user.fullAddress }}</p>
</ion-label>
</ion-item>
Tital Price: {{ order.totalPrice }}
</ion-card-content>
</ion-card>
</ion-content>

<ion-tab-bar slot="bottom" color="primary">
<ion-tab-button (click)="closeOrderListModal()" tab="schedule">
<ion-label>BACK</ion-label>
</ion-tab-button>
</ion-tab-bar>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ion-header {
background: red;
}
ion-toolbar {
background-color: green;
}
ion-buttons {
color: blue;
}
ion-content {
background: blue;
}
h1 {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Component, OnInit, NgZone } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { GeoLocationOrdersService } from '../../services/geo-location-order.service';
import { CarrierRouter } from '@modules/client.common.angular2/routers/carrier-router.service';
import { Store } from 'services/store.service';
import { GeoLocationService } from '../../services/geo-location.service';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import { OrderRouter } from '@modules/client.common.angular2/routers/order-router.service';
import IOrder from '@modules/server.common/interfaces/IOrder';
import { CarrierOrdersRouter } from '@modules/client.common.angular2/routers/carrier-orders-router.service';
import { Router } from '@angular/router';

@Component({
selector: 'orders-list-modal',
templateUrl: './orders-list.component.html',
styleUrls: ['./orders-list.component.scss'],
})
export class OrdersListComponent implements OnInit {
filteredList = [];
private carrier;
private carrier$;
private orders$;

constructor(
private modalCtrl: ModalController,
private geoLocationOrdersService: GeoLocationOrdersService,
private carrierRouter: CarrierRouter,
private store: Store,
private geolocation: Geolocation,
private geoLocationService: GeoLocationService,
private orderRouter: OrderRouter,
private carrierOrdersRouter: CarrierOrdersRouter,

private ngZone: NgZone,
private router: Router
) {}

ngOnInit() {
this.loadOrderslist();
}

filterOrdersList(orders) {
this.filteredList = [].concat(orders);
}

async loadOrderslist() {
this.carrier$ = this.carrierRouter
.get(this.store.carrierId)
.subscribe(async (carrier) => {
this.carrier = carrier;
const position = this.geoLocationService.defaultLocation()
? this.geoLocationService.defaultLocation()
: await this.geolocation.getCurrentPosition();

let dbGeoInput = {
loc: {
type: 'Point',
coordinates: [
position.coords.longitude,
position.coords.latitude,
],
},
} as IGeoLocation;

this.orders$ = this.geoLocationOrdersService
.getOrdersForWork(
dbGeoInput,
carrier.skippedOrderIds,
{
limit: 10,
},
{
isCancelled: false,
}
)
.subscribe((list) => {
this.filterOrdersList(list);
});
});
}

selectNewOrder(id) {
//checking if selected order is started
//its not possible to take 2 orders a the same time for now

const status = this.store.selectedOrder.carrierStatus;
if (status !== 0) {
//todo add message popup error
alert('You are already in delivery ...');
} else {
this.store.orderId = id;
}
this.closeOrderListModal();
}

async closeOrderListModal() {
this.destroyAll();
await this.modalCtrl.dismiss();
}

destroyAll() {
this.carrier$ ? this.carrier$.unsubscribe() : null;
this.orders$ ? this.orders$.unsubscribe() : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { OrdersListComponent } from './orders-list.component';
import { GeoLocationOrdersService } from '../../services/geo-location-order.service';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { GeoLocationService } from '../../services/geo-location.service';

@NgModule({
imports: [CommonModule, IonicModule],
declarations: [OrdersListComponent],
entryComponents: [OrdersListComponent],
exports: [OrdersListComponent],
providers: [GeoLocationOrdersService, Geolocation, GeoLocationService],
})
export class OrdersListModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ export class DriveToWarehousePage implements OnInit {
await this.order$.unsubscribe();
}

const orderId = localStorage.getItem('orderId');
if (orderId) {
this.store.orderId$.subscribe((orderId) => {
this.order$ = this.orderRouter
.get(orderId, {
populateWarehouse: true,
Expand Down Expand Up @@ -112,7 +111,7 @@ export class DriveToWarehousePage implements OnInit {
this.carrierMap.setCenter(origin);
this.carrierMap.drawRoute(origin, destination);
});
}
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,95 @@ export class GeoLocationOrdersService {
share()
);
}

getOrdersForWork(
geoLocation: IGeoLocation,
skippedOrderIds: string[] = [],
options: { sort?: string; skip?: number; limit?: number } = {
sort: 'asc',
},
searchObj?: {
isCancelled?: boolean;
byRegex?: Array<{ key: string; value: string }>;
}
) {
return this.apollo
.watchQuery<{ getOrdersForWork: Order[] }>({
query: gql`
query GetOrdersForWork(
$geoLocation: GeoLocationFindInput!
$skippedOrderIds: [String!]!
$options: GeoLocationOrdersOptions
$searchObj: SearchOrdersForWork
) {
getOrdersForWork(
geoLocation: $geoLocation
skippedOrderIds: $skippedOrderIds
options: $options
searchObj: $searchObj
) {
id
carrierStatus
carrierStatusText
warehouseStatusText
createdAt
isConfirmed
isCancelled
isPaid
isCompleted
totalPrice
orderType
deliveryTime
finishedProcessingTime
startDeliveryTime
deliveryTimeEstimate
orderNumber

products {
count
}

user {
id
firstName
lastName
image
phone
fullAddress
geoLocation {
loc {
type
coordinates
}
streetAddress
house
postcode
countryName
city
}
}
warehouse {
id
name
logo
contactPhone
contactEmail
geoLocation {
house
postcode
countryName
city
}
}
}
}
`,
variables: { geoLocation, skippedOrderIds, options, searchObj },
pollInterval: 1000,
})
.valueChanges.pipe(
map((res) => res.data.getOrdersForWork),
share()
);
}
}
2 changes: 2 additions & 0 deletions packages/carrier-mobile-ionic/src/services/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Store {
selectedOrder$: BehaviorSubject<IOrder> = new BehaviorSubject(
this.selectedOrder
);
orderId$: BehaviorSubject<string> = new BehaviorSubject(this.orderId);

set selectedOrder(order: IOrder) {
this.selectedOrder$.next(order);
Expand Down Expand Up @@ -68,6 +69,7 @@ export class Store {
localStorage.removeItem('orderId');
} else {
localStorage.setItem('orderId', id);
this.orderId$.next(id);
}
}

Expand Down