236 lines
8.1 KiB
TypeScript
236 lines
8.1 KiB
TypeScript
import {Component, OnInit, ViewChild} from '@angular/core';
|
|
import {LoadingController, NavController, ToastController} from "@ionic/angular";
|
|
import {Router} from "@angular/router";
|
|
import {SessionDataProviderService} from "../../store/session-data-provider.service";
|
|
import {WrenchService} from "../../services/wrench.service";
|
|
import {Camera, CameraResultType, CameraSource} from "@capacitor/camera";
|
|
import {SocketToolsService} from "../../services/socket-tools.service";
|
|
import {FilePicker} from "@capawesome/capacitor-file-picker";
|
|
import {MediaConnectService} from "../../services/media-connect.service";
|
|
|
|
@Component({
|
|
selector: 'app-jobactive',
|
|
templateUrl: './jobactive.page.html',
|
|
styleUrls: ['./jobactive.page.scss'],
|
|
})
|
|
export class JobactivePage implements OnInit {
|
|
@ViewChild('yourmessage') yourmessage;
|
|
|
|
jobData: any;
|
|
tabs = 'message';
|
|
item_banner: string = 'default.jpg';
|
|
session_image_server: string = '';
|
|
curr_session: string = '';
|
|
socket_room: string = '';
|
|
|
|
constructor(
|
|
private navctr: NavController,
|
|
private router: Router,
|
|
public sessionDataProviderService: SessionDataProviderService,
|
|
private wrenchService: WrenchService,
|
|
private socketToolsService: SocketToolsService,
|
|
private toastController: ToastController,
|
|
private loadingCtrl: LoadingController,
|
|
private mediaConnectService: MediaConnectService
|
|
) {
|
|
this.jobData = this.router.getCurrentNavigation().extras.state;
|
|
this.item_banner = this.jobData.banner;
|
|
|
|
if (this.jobData == undefined) {
|
|
this.onBack();
|
|
}
|
|
// debugger;
|
|
this.socket_room = `${this.jobData.contract}-${this.jobData.contract_uid}`;
|
|
this.socketToolsService.joinSocketRoom(this.socket_room);
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
this.curr_session = this.sessionDataProviderService.session;
|
|
this.session_image_server = this.sessionDataProviderService.session_image_server;
|
|
//this.activeJobMsgList();
|
|
}
|
|
|
|
onBack() {
|
|
this.navctr.back();
|
|
}
|
|
|
|
|
|
reqData: {
|
|
action: number, member_id: number, uid: string, sessionid: string, msg_type: string,
|
|
contract: string,
|
|
message: string
|
|
};
|
|
|
|
interest_status: string = "";
|
|
interest_msg_status: string = "";
|
|
|
|
msgReqResult: any;
|
|
|
|
async presentToast(amessage, position: 'top' | 'middle' | 'bottom', duration: number = 2500) {
|
|
const toast = await this.toastController.create({
|
|
message: amessage,
|
|
duration: duration,
|
|
position: position,
|
|
});
|
|
|
|
await toast.present();
|
|
}
|
|
|
|
async sendActiveJobMessage() {
|
|
if (this.yourmessage == undefined || this.yourmessage?.length < 5) {
|
|
await this.presentToast("Please enter the message to send", "middle");
|
|
return;
|
|
}
|
|
|
|
const loading = await this.loadingCtrl.create({
|
|
message: 'Sending...',
|
|
duration: 2500,
|
|
});
|
|
this.reqData = {
|
|
action: 14010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
sessionid: this.sessionDataProviderService.session,
|
|
msg_type: "TEXT",
|
|
contract: this.jobData.contract,
|
|
message: this.yourmessage
|
|
}
|
|
|
|
loading.present();
|
|
this.wrenchService.sendTaskMessage(this.reqData).subscribe(
|
|
reqResult => {
|
|
this.msgReqResult = reqResult;
|
|
console.log("msgReqResult RETURN->", this.msgReqResult);
|
|
this.interest_msg_status = this.msgReqResult?.status;
|
|
this.yourmessage = '';
|
|
//this.activeJobMsgList();
|
|
const event = new Event("app-taskactivities-refresh");
|
|
// Dispatch the event.
|
|
dispatchEvent(event);
|
|
//alert(this.socket_room);
|
|
// debugger;
|
|
this.socketToolsService.emmitSocketEvent("send_message", this.yourmessage, this.socket_room);
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
uploadData: {
|
|
action: number,
|
|
member_id: number,
|
|
uid: string,
|
|
contract: string,
|
|
sessionid: string,
|
|
msg_type: 'FILE',
|
|
file_name: string,
|
|
file_size: number,
|
|
file_type: string,
|
|
file_data: string
|
|
};
|
|
|
|
uploadResult: any;
|
|
|
|
async startCamera(cameraMode) {
|
|
const image = await Camera.getPhoto({
|
|
quality: 50,
|
|
width: 600,
|
|
height: 300,
|
|
allowEditing: false,
|
|
resultType: CameraResultType.Base64,
|
|
source: (cameraMode == 100) ? CameraSource.Camera : CameraSource.Prompt // Camera, Photos or Prompt!
|
|
});
|
|
|
|
if (image) {
|
|
const loading = await this.loadingCtrl.create({
|
|
message: 'Uploading updates',
|
|
duration: 5000,
|
|
});
|
|
var file_size = parseInt(String(image.base64String.toString().length / 1.3224954));
|
|
// this.saveImage(image)
|
|
//debugger;
|
|
//image.base64String
|
|
this.uploadData = {
|
|
action: 14010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
contract: this.jobData.contract,
|
|
sessionid: this.sessionDataProviderService.session,
|
|
msg_type: 'FILE',
|
|
file_name: `${this.jobData.contract}-job.${image.format}`,
|
|
file_size: file_size,
|
|
file_type: `image/${image.format}`,
|
|
file_data: image.base64String
|
|
};
|
|
// console.log(this.uploadData);
|
|
loading.present();
|
|
this.wrenchService.uploadFile(this.uploadData).subscribe(
|
|
uploadResult => {
|
|
this.uploadResult = uploadResult;
|
|
console.log("this.wrenchService.uploadFile RETURN DATA->", this.uploadResult);
|
|
const event = new Event("app-taskactivities-refresh");
|
|
// Dispatch the event.
|
|
dispatchEvent(event);
|
|
}
|
|
);
|
|
|
|
// console.log( this.uploadData);
|
|
}
|
|
}
|
|
|
|
uploadFormData: {
|
|
action: number,
|
|
member_id: number,
|
|
uid: string,
|
|
contract: string,
|
|
sessionid: string,
|
|
msg_type: 'FILE'
|
|
};
|
|
|
|
async pickFiles(fileMode) {
|
|
const result = await FilePicker.pickFiles({
|
|
types: ['image/png', 'image/jpeg', 'video/mp4'],
|
|
multiple: false,
|
|
readData: true
|
|
});
|
|
|
|
const loading = await this.loadingCtrl.create({
|
|
message: 'Uploading...',
|
|
duration: 5000,
|
|
});
|
|
|
|
if (result) {
|
|
console.log(result);
|
|
// debugger;
|
|
this.uploadFormData = {
|
|
action: 14010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
contract: this.jobData.contract,
|
|
sessionid: this.sessionDataProviderService.session,
|
|
msg_type: 'FILE'
|
|
};
|
|
|
|
console.log(this.uploadFormData);
|
|
for (const [key, value] of Object.entries(this.uploadFormData)) {
|
|
console.log(`${key}: ${value}`);
|
|
}
|
|
|
|
var blob = new Blob([result.files[0].data], {type: result.files[0].mimeType});
|
|
var file = new File([blob], result.files[0].name, {type: result.files[0].mimeType});
|
|
//return;
|
|
await loading.present();
|
|
this.mediaConnectService.uploadtaskFile(this.uploadFormData, file).subscribe(
|
|
uploadResult => {
|
|
loading.dismiss();
|
|
this.uploadResult = uploadResult;
|
|
console.log("this.mediaConnectService.uploadFile RETURN DATA->", this.uploadFormData);
|
|
const event = new Event("app-taskactivities-refresh");
|
|
// Dispatch the event.
|
|
dispatchEvent(event);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|