|
@@ -27,6 +27,7 @@ export class AddNewsComponent implements OnInit {
|
|
|
typeLink: string = '';
|
|
|
checkSaveClick: boolean = false;
|
|
|
photoEdit:boolean = true;
|
|
|
+ checkAddMode: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
@@ -45,15 +46,18 @@ export class AddNewsComponent implements OnInit {
|
|
|
images = [{
|
|
|
base64: '',
|
|
|
photoType: '',
|
|
|
- urlImg: '../../assets/image/avatar.png'
|
|
|
+ urlImg: '../../assets/image/avatar.png',
|
|
|
+ id: '',
|
|
|
}];
|
|
|
|
|
|
//add more div photo
|
|
|
plusImage() {
|
|
|
+ this.checkAddMode = true;
|
|
|
this.images.push({
|
|
|
base64: '',
|
|
|
photoType: '',
|
|
|
urlImg: '../../assets/image/avatar.png',
|
|
|
+ id: '',
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -103,18 +107,12 @@ export class AddNewsComponent implements OnInit {
|
|
|
this.new.description_en = newData.description_en;
|
|
|
if(responce['report'].photos) {
|
|
|
this.checkValidImg = false;
|
|
|
- for(let i = 0 ; i < newData.photos.length; i++) {
|
|
|
- // this.images[i] = {
|
|
|
- // base64: '',
|
|
|
- // photoType: '',
|
|
|
- // urlImg: this.authSer.pathImg + newData.photos[i].photo,
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
+ for(let i = 0 ; i < newData.photos.length; i++) {
|
|
|
this.images.push({
|
|
|
base64: '',//this.onFileChanges(newData.photos[i].photo,i),
|
|
|
photoType: '',
|
|
|
urlImg : this.authSer.pathImg + newData.photos[i].photo,
|
|
|
+ id: newData.photos[i].id,
|
|
|
});
|
|
|
console.log('imageeeees' , this.images);
|
|
|
}
|
|
@@ -140,11 +138,21 @@ export class AddNewsComponent implements OnInit {
|
|
|
let dateEditUplad = {};
|
|
|
|
|
|
if(this.typeMode) {
|
|
|
- dateEditUplad = {
|
|
|
- 'photo': event[0].base64,
|
|
|
- 'photo_type': event[0].type.split('/')[1],
|
|
|
- report_id: this.newId,
|
|
|
+ if(this.checkAddMode) {
|
|
|
+ dateEditUplad = {
|
|
|
+ 'photo': event[0].base64,
|
|
|
+ 'photo_type': event[0].type.split('/')[1],
|
|
|
+ 'report_id': this.newId,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dateEditUplad = {
|
|
|
+ 'photo': event[0].base64,
|
|
|
+ 'photo_type': event[0].type.split('/')[1],
|
|
|
+ 'photo_id': this.images[index].id,
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ console.log(dateEditUplad);
|
|
|
this.http.post(this.authSer.pathApi + '/upload_report_photo', dateEditUplad).subscribe(
|
|
|
(responce) => {
|
|
|
console.log(responce);
|
|
@@ -184,11 +192,6 @@ export class AddNewsComponent implements OnInit {
|
|
|
const formData = this.newForm.value;
|
|
|
|
|
|
if(this.typeMode){
|
|
|
- if(this.photoType[1] != 'png' && this.photoEdit == true) {
|
|
|
- this.toastr.warning('الصوره يجب أن تكون بصيغه Png');
|
|
|
- } else if(this.imageBase64 == '' && this.photoEdit == true){
|
|
|
- this.toastr.warning('قم باختيار صوره !');
|
|
|
- } else {
|
|
|
//to remove photo from object not has edit on it
|
|
|
const images = [];
|
|
|
for(let i = 0; i < this.images.length; i++) {
|
|
@@ -202,22 +205,21 @@ export class AddNewsComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- formData['images'] = images;
|
|
|
+ //formData['images'] = images;
|
|
|
|
|
|
console.log(formData);
|
|
|
|
|
|
- // this.newService.editNew(formData, this.newId).subscribe(
|
|
|
- // (responce) => {
|
|
|
- // console.log(responce);
|
|
|
- // this.toastr.success('تمت التعديل بنجاح');
|
|
|
- // this.location.back();
|
|
|
- // },
|
|
|
- // (error) => {
|
|
|
- // console.log(error);
|
|
|
- // this.toastr.error('خطأ في التعديل !');
|
|
|
- // }
|
|
|
- // );
|
|
|
- }
|
|
|
+ this.newService.editNew(formData, this.newId).subscribe(
|
|
|
+ (responce) => {
|
|
|
+ console.log(responce);
|
|
|
+ this.toastr.success('تمت التعديل بنجاح');
|
|
|
+ this.location.back();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.log(error);
|
|
|
+ this.toastr.error('خطأ في التعديل !');
|
|
|
+ }
|
|
|
+ );
|
|
|
} else {
|
|
|
if(this.images[0].base64 == ''){
|
|
|
this.toastr.warning('قم باختيار صوره !');
|