File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/order-rating/order-rating.ts
import { Component, OnInit } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { AlertController, NavParams, LoadingController, ToastController, ModalController } from "@ionic/angular";
import { StorageService } from '../../services/storage.service';
import { OrderService } from "../../services/order.service";
import { UtilsService } from "../../services/utils.service";
@Component({
selector: "page-order-rating",
templateUrl: "order-rating.html",
styleUrls: ["./order-rating.scss"],
})
export class OrderRatingPage implements OnInit {
messageText: any;
order_id: any;
rating: any;
commentaryRating: any;
constructor(
private translateService: TranslateService,
public alertCtrl: AlertController,
public loadingCtrl: LoadingController,
private storage: StorageService,
public orderProvider: OrderService,
public toastCtrl: ToastController,
private utilsService: UtilsService,
private navParams: NavParams,
public modalCtrl: ModalController
) {
this.translateService
.get([
"TITLE_ALERT_CONFIRM_ORDER",
"TEXT_ALERT_RAKING",
"RATING_SUCCESS",
"TEXT1_APPRATE",
"TEXT2_APPRATE",
"TEXT3_APPRATE",
"TEXT4_APPRATE",
"TEXT5_APPRATE",
"TEXT6_APPRATE",
"TEXT7_APPRATE",
"TEXT8_APPRATE",
"TEXT9_APPRATE",
])
.subscribe((values) => {
this.messageText = {
titleAlert: values.TITLE_ALERT_CONFIRM_ORDER,
textAlert: values.TEXT_ALERT_RAKING,
sendRating: values.RATING_SUCCESS,
text1AppRate: values.TEXT1_APPRATE,
text2AppRate: values.TEXT2_APPRATE,
text3AppRate: values.TEXT3_APPRATE,
text4AppRate: values.TEXT4_APPRATE,
text5AppRate: values.TEXT5_APPRATE,
text6AppRate: values.TEXT6_APPRATE,
text7AppRate: values.TEXT7_APPRATE,
text8AppRate: values.TEXT8_APPRATE,
text9AppRate: values.TEXT9_APPRATE,
};
});
this.order_id = this.navParams.get("order_id");
}
ngOnInit() {
}
logRatingChange(rating: any) {
this.rating = rating;
}
ionViewDidLoad() { }
cancel() {
this.modalCtrl.dismiss();
}
async sendRating(commentary) {
if (!this.rating) {
const alert = await this.alertCtrl.create({
header: this.messageText.titleAlert,
subHeader: this.messageText.textAlert,
buttons: ["OK"],
});
await alert.present();
return;
}
this.storage.get("token").then(async (token) => {
if (token) {
this.utilsService.presentLoading(this.translateService.instant("all.loading"));
(await this.orderProvider.ratingOrder(this.rating, commentary, this.order_id, token.access_token)).subscribe(
(resp) => {
this.utilsService.dismissLoading();
if (resp["status"] == "success") {
this.utilsService.presentToast(3000, "sucess", "top", this.messageText.sendRating);
this.cancel();
setTimeout(() => {
if (this.rating == 5) {
this.storage.get("parametersMain").then((parameters) => {
if (parameters) {
// this.appRate.preferences = {
// simpleMode: true,
// usesUntilPrompt: 0,
// promptAgainForEachNewVersion: true,
// storeAppURL: {
// ios: parameters.ios_app_store,
// android: "market://details?id=" + parameters.android_play_store,
// },
// customLocale: {
// title: this.messageText.text1AppRate,
// message: this.messageText.text2AppRate,
// cancelButtonLabel: this.messageText.text3AppRate,
// laterButtonLabel: this.messageText.text4AppRate,
// rateButtonLabel: this.messageText.text5AppRate,
// yesButtonLabel: this.messageText.text6AppRate,
// noButtonLabel: this.messageText.text7AppRate,
// appRatePromptTitle: this.messageText.text8AppRate,
// feedbackPromptTitle: this.messageText.text9AppRate,
// },
// callbacks: {
// handleNegativeFeedback: function () {
// console.log("handleNegativeFeedback");
// },
// onRateDialogShow: function (callback) {
// console.log(callback);
// },
// onButtonClicked: function (buttonIndex) {
// console.log("onButtonClicked -> " + buttonIndex);
// },
// },
// };
// this.appRate.promptForRating(false);
}
});
}
}, 500);
}
},
(error) => {
console.log("error generateOrder", error);
this.utilsService.dismissLoading();
}
);
}
});
}
}