Advertisement
roynaldoindra

reservasi.ts

Aug 7th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { IonicPage, NavController, NavParams,ActionSheetController, ToastController, Platform, LoadingController, Loading } from 'ionic-angular';
  3. //import { Detilbayar } from '../detilbayar/detilbayar';
  4. import { File } from '@ionic-native/file';
  5. import { Transfer, TransferObject } from '@ionic-native/transfer';
  6. import { FilePath } from '@ionic-native/file-path';
  7. import { Camera } from '@ionic-native/camera';
  8. import { Storage } from '@ionic/storage';
  9. import { SalonDetail } from '../../providers/apisalondetil-service';
  10.  
  11. declare var cordova: any;
  12.  
  13. /**
  14. * Generated class for the Reservasi page.
  15. *
  16. * See http://ionicframework.com/docs/components/#navigation for more info
  17. * on Ionic pages and navigation.
  18. */
  19. @IonicPage({
  20. name : 'reservasi'
  21. })
  22. @Component({
  23. selector: 'page-reservasi',
  24. templateUrl: 'reservasi.html',
  25. })
  26. export class Reservasi {
  27. lastImage: string = null;
  28. loading: Loading;
  29.  
  30. public nama: any;
  31. public alamat: any;
  32. public noTelp: any;
  33.  
  34. public idUser : any;
  35. public dataSalon: any;
  36. public datas: any;
  37. public data: any;
  38. public nama_service: any;
  39. public nama_pelayan: any;
  40.  
  41.  
  42. today
  43.  
  44.  
  45. constructor(public navCtrl: NavController, public navParams: NavParams,
  46. private camera: Camera, private transfer: Transfer, private file: File,
  47. private filePath: FilePath, public actionSheetCtrl: ActionSheetController,
  48. public toastCtrl: ToastController,
  49. public platform: Platform, public loadingCtrl: LoadingController, private storage: Storage,
  50. private salondetailApi: SalonDetail ) {
  51. this.today = new Date().toISOString();
  52. console.log(this.today);
  53.  
  54. }
  55.  
  56. ionViewDidLoad() {
  57. console.log('ionViewDidLoad Reservasi');
  58. this.storage.ready().then(()=>{
  59. this.storage.get('loginAuth').then((loginAuth) => {
  60. console.log(loginAuth, 'Data Reservasi Profil')
  61. this.nama = loginAuth.data["0"].nama_cust;
  62. this.alamat = loginAuth.data['0'].alamat;
  63. this.noTelp = loginAuth.data['0'].no_hp;
  64. })
  65. })
  66. }
  67.  
  68.  
  69. ionViewDidEnter(){
  70.  
  71. this.idUser = this.navParams.get('id_user')
  72. console.log(this.idUser, 'idUser')
  73.  
  74. this.salondetailApi.viewReservasi({ id_user: this.idUser }).then((result) =>{
  75. this.dataSalon = result;
  76. this.datas = this.dataSalon.data;
  77. console.log(JSON.stringify(this.datas));
  78. console.log(this.datas, 'Data Reservasi Salon');
  79. console.log(result, 'Result');
  80. });
  81. }
  82.  
  83. /*detilbayar(){
  84. this.navCtrl.push(Detilbayar);
  85. }*/
  86.  
  87. public presentActionSheet() {
  88. let actionSheet = this.actionSheetCtrl.create({
  89. title: 'Select Image Source',
  90. buttons: [
  91. {
  92. text: 'Load from Library',
  93. handler: () => {
  94. this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY);
  95. }
  96. },
  97. {
  98. text: 'Use Camera',
  99. handler: () => {
  100. this.takePicture(this.camera.PictureSourceType.CAMERA);
  101. }
  102. },
  103. {
  104. text: 'Cancel',
  105. role: 'cancel'
  106. }
  107. ]
  108. });
  109. actionSheet.present();
  110. }
  111.  
  112. public takePicture(sourceType) {
  113. // Create options for the Camera Dialog
  114. var options = {
  115. quality: 100,
  116. sourceType: sourceType,
  117. saveToPhotoAlbum: false,
  118. correctOrientation: true
  119. };
  120.  
  121. // Get the data of an image
  122. this.camera.getPicture(options).then((imagePath) => {
  123. // Special handling for Android library
  124. if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
  125. this.filePath.resolveNativePath(imagePath)
  126. .then(filePath => {
  127. let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
  128. let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
  129. this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
  130. });
  131. } else {
  132. var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
  133. var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
  134. this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
  135. }
  136. }, (err) => {
  137. this.presentToast('Error while selecting image.');
  138. });
  139. }
  140.  
  141. private createFileName() {
  142. var d = new Date(),
  143. n = d.getTime(),
  144. newFileName = n + ".jpg";
  145. return newFileName;
  146. }
  147.  
  148. // Copy the image to a local folder
  149. private copyFileToLocalDir(namePath, currentName, newFileName) {
  150. this.file.copyFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(success => {
  151. this.lastImage = newFileName;
  152. }, error => {
  153. this.presentToast('Error while storing file.');
  154. });
  155. }
  156.  
  157. private presentToast(text) {
  158. let toast = this.toastCtrl.create({
  159. message: text,
  160. duration: 3000,
  161. position: 'top'
  162. });
  163. toast.present();
  164. }
  165.  
  166. // Always get the accurate path to your apps folder
  167. public pathForImage(img) {
  168. if (img === null) {
  169. return '';
  170. } else {
  171. return cordova.file.dataDirectory + img;
  172. }
  173. }
  174.  
  175. public uploadImage() {
  176. // Destination URL
  177. var url = "http://yoururl/upload.php";
  178.  
  179. // File for Upload
  180. var targetPath = this.pathForImage(this.lastImage);
  181.  
  182. // File name only
  183. var filename = this.lastImage;
  184.  
  185. var options = {
  186. fileKey: "file",
  187. fileName: filename,
  188. chunkedMode: false,
  189. mimeType: "multipart/form-data",
  190. params : {'fileName': filename}
  191. };
  192.  
  193. const fileTransfer: TransferObject = this.transfer.create();
  194.  
  195. this.loading = this.loadingCtrl.create({
  196. content: 'Uploading...',
  197. });
  198. this.loading.present();
  199.  
  200. // Use the FileTransfer to upload the image
  201. fileTransfer.upload(targetPath, url, options).then(data => {
  202. this.loading.dismissAll()
  203. this.presentToast('Image succesful uploaded.');
  204. }, err => {
  205. this.loading.dismissAll()
  206. this.presentToast('Error while uploading file.');
  207. });
  208. }
  209.  
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement