|
@@ -1,5 +1,5 @@
|
|
|
import { NgxSpinnerService } from 'ngx-spinner';
|
|
|
-import { ActivatedRoute, Params } from '@angular/router';
|
|
|
+import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
|
import { DashboardService } from './../../../shared/dashboard.service';
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
import { UserService } from './../../../shared/user.service';
|
|
@@ -20,6 +20,7 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
private toastr: ToastrService,
|
|
|
private route: ActivatedRoute,
|
|
|
private dashBoardSer: DashboardService,
|
|
|
+ private router: Router,
|
|
|
private spinner: NgxSpinnerService,
|
|
|
private location: Location,
|
|
|
private authSer: AuthServiceService) { }
|
|
@@ -33,11 +34,14 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
reportId: number;
|
|
|
stoppedShow: boolean = false;
|
|
|
endedShow: boolean = false;
|
|
|
+ userLoginId: number;
|
|
|
+ serviceId: number;
|
|
|
countries: any[] = [];
|
|
|
identities: any[] = [];
|
|
|
trainees:any[] = [];
|
|
|
departments:any[] = [];
|
|
|
departmentsId:any[] = [];
|
|
|
+ attachments_ids: any[] =[];
|
|
|
|
|
|
@ViewChild('f') traineeForm: NgForm;
|
|
|
|
|
@@ -56,9 +60,7 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
contract_type: '',
|
|
|
status: '',
|
|
|
organization_affiliated_with: '',
|
|
|
- department1: '',
|
|
|
- department2: '',
|
|
|
- department3: '',
|
|
|
+ department: '',
|
|
|
}
|
|
|
|
|
|
//user data object
|
|
@@ -106,6 +108,22 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
this.authSer.showHeaderDashBoard = true;
|
|
|
this.authSer.showDashboardHeader = true;
|
|
|
this.authSer.internalHeader = false;
|
|
|
+
|
|
|
+ //catch params id from activated route
|
|
|
+ this.route.params.subscribe(
|
|
|
+ (params: Params) => {
|
|
|
+ this.reportId = +params['finalAccerditationEdit'];
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ //catch parent params id from activated route
|
|
|
+ this.route.parent.params.subscribe(
|
|
|
+ (params:Params) => {
|
|
|
+ this.userLoginId = +params['userID'];
|
|
|
+ this.serviceId = +params['serviceID'];
|
|
|
+ }
|
|
|
+
|
|
|
+ );
|
|
|
|
|
|
//get nationality data
|
|
|
this.userSer.getNationality().subscribe(
|
|
@@ -150,12 +168,7 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
console.log(error);
|
|
|
}
|
|
|
);
|
|
|
-
|
|
|
- this.route.params.subscribe(
|
|
|
- (params: Params) => {
|
|
|
- this.reportId = params['finalAccerditationEdit'];
|
|
|
- }
|
|
|
- );
|
|
|
+
|
|
|
|
|
|
if(this.reportId) {
|
|
|
|
|
@@ -190,22 +203,16 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
this.userData.nationality_id = responce['data']['user'].nationality_id;
|
|
|
this.userId = responce['data']['user'].id;
|
|
|
this.userData['id'] = this.userId;
|
|
|
-
|
|
|
- //add departmrnts ids
|
|
|
- if(responce['data']['request'].departments.length > 0) {
|
|
|
- for(let i = 0; i < responce['data']['request'].departments.length; i++) {
|
|
|
- if(i == 0) {
|
|
|
- this.formData.department1 = responce['data']['request'].departments[0].department_id;
|
|
|
- this.departmentsId[i] = responce['data']['request'].departments[i].department_id;
|
|
|
- } else if(i == 1) {
|
|
|
- this.formData.department2 = responce['data']['request'].departments[i].department_id;
|
|
|
- this.departmentsId[i] = responce['data']['request'].departments[i].department_id;
|
|
|
- } else if(i == 2) {
|
|
|
- this.formData.department3 = responce['data']['request'].departments[i].department_id;
|
|
|
- this.departmentsId[i] = responce['data']['request'].departments[i].department_id;
|
|
|
- }
|
|
|
+ for(let i = 0; i < responce['data']['request'].attachments.length; i++) {
|
|
|
+ this.attachments_ids.push(responce['data']['request'].attachments[i].id);
|
|
|
+ }
|
|
|
+ console.log('attachemnts ids ', this.attachments_ids);
|
|
|
+ for(let i = 0; i < responce['data']['request'].departments.length; i++) {
|
|
|
+ if(responce['data']['request'].departments[i].is_confirmed == 1) {
|
|
|
+ this.formData.department = responce['data']['request'].departments[i].department_id;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -228,6 +235,7 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
console.log(error);
|
|
|
}
|
|
|
);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -237,20 +245,123 @@ export class FinalAccerditationAddComponent implements OnInit {
|
|
|
this.actionForm.card_received = 1
|
|
|
}
|
|
|
|
|
|
+ printCard() {
|
|
|
+ this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/finalAccerditationReprot']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //delete row of files
|
|
|
+ onDeleteRow(rowIndex: number) {
|
|
|
+ this.files.splice(rowIndex , 1);
|
|
|
+ if(this.attachments_ids.length > 0) {
|
|
|
+ this.attachments_ids.splice(rowIndex, 1);
|
|
|
+ }
|
|
|
+ console.log('files after delete ',this.files);
|
|
|
+ console.log('attachements ids', this.attachments_ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ //add attachements
|
|
|
+ plusImage() {
|
|
|
+ this.files.push({
|
|
|
+ title: '',
|
|
|
+ file: '',
|
|
|
+ file_type: '',
|
|
|
+ nameFile: '',
|
|
|
+ id: null,
|
|
|
+ });
|
|
|
+ console.log('files after plus ', this.files);
|
|
|
+ }
|
|
|
+//finalAccerditationReprot
|
|
|
+ //on file change
|
|
|
+ //change file
|
|
|
+ onFileChanges(event, index:number) {
|
|
|
+ console.log(event);
|
|
|
+ console.log(index);
|
|
|
+ this.files[index].nameFile = event[0].name.substring(0,20) + '....';
|
|
|
+ this.files[index].file = event[0].base64;
|
|
|
+ this.files[index].file_type = event[0].type.split('/')[1];
|
|
|
+ //validate in pdf type file in edit mode
|
|
|
+ if(this.files[index].file_type != '') {
|
|
|
+ if(this.files[index].file_type != 'pdf') {
|
|
|
+ this.toastr.warning('يجب أن تكون صيغه الملف pdf !');
|
|
|
+ this.checkSaveClick = true;
|
|
|
+ } else {
|
|
|
+ this.checkSaveClick = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(this.files);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //submitted form
|
|
|
onSubmittedForm() {
|
|
|
+
|
|
|
console.log(this.actionForm);
|
|
|
+
|
|
|
+ //get the attchiements edit
|
|
|
+ const editAttachements = [];
|
|
|
+ for(let i = 0; i < this.files.length; i++) {
|
|
|
+ for(let j = 0; j < this.attachments_ids.length; j++) {
|
|
|
+ if(this.files[i].id == this.attachments_ids[j]) {
|
|
|
+ editAttachements[i] = this.files[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //delete file & file type if not change it in old file
|
|
|
+ for(let i = 0; i < editAttachements.length; i++) {
|
|
|
+ if(editAttachements[i].file_type == '') {
|
|
|
+ delete editAttachements[i].file;
|
|
|
+ delete editAttachements[i].file_type;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //delete the extera key file name
|
|
|
+ for(let i = 0; i < editAttachements.length; i++) {
|
|
|
+ delete editAttachements[i].nameFile;
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ //remove old file from files object
|
|
|
+ for(let i = 0; i < editAttachements.length; i++) {
|
|
|
+ for(let j = 0; j < this.files.length; j++) {
|
|
|
+ if(editAttachements[i].id == this.files[j].id) {
|
|
|
+ this.files.splice(j , 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //remove nameFile and id from object
|
|
|
+ for(let i = 0; i < this.files.length; i++) {
|
|
|
+ delete this.files[i].nameFile;
|
|
|
+ delete this.files[i].id;
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log('files after update ', this.files);
|
|
|
+ console.log('edit files after update ', editAttachements);
|
|
|
+
|
|
|
+ this.actionForm['attachments_ids'] = this.attachments_ids;
|
|
|
+ this.actionForm['editable_attachments'] = editAttachements;
|
|
|
+ this.actionForm['attachments'] = this.files;
|
|
|
+
|
|
|
+ this.checkSaveClick = true;
|
|
|
+
|
|
|
this.http.post(this.authSer.pathApi + '/final_accreditation_of_trainees', this.actionForm).subscribe(
|
|
|
(responce) => {
|
|
|
console.log(responce),
|
|
|
this.toastr.success('تم بنجاح');
|
|
|
+ this.checkSaveClick = false;
|
|
|
this.location.back();
|
|
|
},
|
|
|
(error) => {
|
|
|
console.log(error);
|
|
|
- this.toastr.error('يوجد خطأ في السيرفر ، حاول لاحقاَ');
|
|
|
+ this.checkSaveClick = false;
|
|
|
+ this.toastr.error('يوجد خطأ ، حاول لاحقاَ');
|
|
|
this.location.back();
|
|
|
}
|
|
|
- )
|
|
|
+ );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|