|
@@ -27,6 +27,7 @@ export class AddNewsComponent implements OnInit {
|
|
typeLink: string = '';
|
|
typeLink: string = '';
|
|
checkSaveClick: boolean = false;
|
|
checkSaveClick: boolean = false;
|
|
photoEdit:boolean = true;
|
|
photoEdit:boolean = true;
|
|
|
|
+ checkAddMode: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -45,15 +46,18 @@ export class AddNewsComponent implements OnInit {
|
|
images = [{
|
|
images = [{
|
|
base64: '',
|
|
base64: '',
|
|
photoType: '',
|
|
photoType: '',
|
|
- urlImg: '../../assets/image/avatar.png'
|
|
|
|
|
|
+ urlImg: '../../assets/image/avatar.png',
|
|
|
|
+ id: '',
|
|
}];
|
|
}];
|
|
|
|
|
|
//add more div photo
|
|
//add more div photo
|
|
plusImage() {
|
|
plusImage() {
|
|
|
|
+ this.checkAddMode = true;
|
|
this.images.push({
|
|
this.images.push({
|
|
base64: '',
|
|
base64: '',
|
|
photoType: '',
|
|
photoType: '',
|
|
urlImg: '../../assets/image/avatar.png',
|
|
urlImg: '../../assets/image/avatar.png',
|
|
|
|
+ id: '',
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,18 +107,12 @@ export class AddNewsComponent implements OnInit {
|
|
this.new.description_en = newData.description_en;
|
|
this.new.description_en = newData.description_en;
|
|
if(responce['report'].photos) {
|
|
if(responce['report'].photos) {
|
|
this.checkValidImg = false;
|
|
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({
|
|
this.images.push({
|
|
base64: '',//this.onFileChanges(newData.photos[i].photo,i),
|
|
base64: '',//this.onFileChanges(newData.photos[i].photo,i),
|
|
photoType: '',
|
|
photoType: '',
|
|
urlImg : this.authSer.pathImg + newData.photos[i].photo,
|
|
urlImg : this.authSer.pathImg + newData.photos[i].photo,
|
|
|
|
+ id: newData.photos[i].id,
|
|
});
|
|
});
|
|
console.log('imageeeees' , this.images);
|
|
console.log('imageeeees' , this.images);
|
|
}
|
|
}
|
|
@@ -140,11 +138,21 @@ export class AddNewsComponent implements OnInit {
|
|
let dateEditUplad = {};
|
|
let dateEditUplad = {};
|
|
|
|
|
|
if(this.typeMode) {
|
|
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(
|
|
this.http.post(this.authSer.pathApi + '/upload_report_photo', dateEditUplad).subscribe(
|
|
(responce) => {
|
|
(responce) => {
|
|
console.log(responce);
|
|
console.log(responce);
|
|
@@ -184,11 +192,6 @@ export class AddNewsComponent implements OnInit {
|
|
const formData = this.newForm.value;
|
|
const formData = this.newForm.value;
|
|
|
|
|
|
if(this.typeMode){
|
|
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
|
|
//to remove photo from object not has edit on it
|
|
const images = [];
|
|
const images = [];
|
|
for(let i = 0; i < this.images.length; i++) {
|
|
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);
|
|
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 {
|
|
} else {
|
|
if(this.images[0].base64 == ''){
|
|
if(this.images[0].base64 == ''){
|
|
this.toastr.warning('قم باختيار صوره !');
|
|
this.toastr.warning('قم باختيار صوره !');
|