Commit f28ccdfc by Ooh-Ao

ให้ group ไม่ใส่ได้ เอาเงื่อนไขสร้างเสร็จออก เพราะ if ไม่เข้า

parent 3fc8fd7a
...@@ -19,16 +19,16 @@ const FileSaver = require('file-saver'); ...@@ -19,16 +19,16 @@ const FileSaver = require('file-saver');
export class ListDocComponent implements OnInit { export class ListDocComponent implements OnInit {
page = 1; page = 1;
pageSize = 10; pageSize = 10;
listDoc:DocumentModel[]=[] listDoc: DocumentModel[] = []
modelDoc:DocumentModel = new DocumentModel({}); modelDoc: DocumentModel = new DocumentModel({});
checkEdit:boolean = false checkEdit: boolean = false
search:string = '' search: string = ''
listTag:TagModel[]=[] listTag: TagModel[] = []
listGroup:GroupModel[]=[] listGroup: GroupModel[] = []
constructor(private modalService: NgbModal,private documentService:DocumentService, private uploadService:UploadService,private tagService:TagService,private groupService:GroupService) { constructor(private modalService: NgbModal, private documentService: DocumentService, private uploadService: UploadService, private tagService: TagService, private groupService: GroupService) {
} }
async onUploadImage(event:any){ async onUploadImage(event: any) {
try{ try {
if (event.target.files.length > 0) { if (event.target.files.length > 0) {
let fileData = event.target.files[0]; let fileData = event.target.files[0];
const formData = new FormData(); const formData = new FormData();
...@@ -38,7 +38,7 @@ export class ListDocComponent implements OnInit { ...@@ -38,7 +38,7 @@ export class ListDocComponent implements OnInit {
this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.jpeg, *.jpg, *.png เท่านั้น') this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.jpeg, *.jpg, *.png เท่านั้น')
} else { } else {
const data = await this.uploadService.uploadImage(formData).toPromise(); const data = await this.uploadService.uploadImage(formData).toPromise();
if(data){ if (data) {
this.modelDoc.thumbnail = data.body.fileId this.modelDoc.thumbnail = data.body.fileId
} }
} }
...@@ -47,39 +47,39 @@ export class ListDocComponent implements OnInit { ...@@ -47,39 +47,39 @@ export class ListDocComponent implements OnInit {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
onSelectFile(event:any,lang:string) { onSelectFile(event: any, lang: string) {
if (event.target.files && event.target.files[0]) { if (event.target.files && event.target.files[0]) {
const reader = new FileReader(); const reader = new FileReader();
const file: File = event.target.files[0]; const file: File = event.target.files[0];
reader.readAsDataURL(event.target.files[0]); // read file as data url reader.readAsDataURL(event.target.files[0]); // read file as data url
reader.onload = (event) => { // called once readAsDataURL is completed reader.onload = (event) => { // called once readAsDataURL is completed
if(event){ if (event) {
const allowedTypes = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/msword']; const allowedTypes = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/msword'];
if (!allowedTypes.includes(file.type)) { if (!allowedTypes.includes(file.type)) {
this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.doc เท่านั้น') this.openAlertModal('อัพโหลดได้เฉพาะไฟล์ *.doc เท่านั้น')
} else { } else {
let base64 = event.target!.result as string let base64 = event.target!.result as string
if(lang == 'th'){ if (lang == 'th') {
this.modelDoc.thDocObj = base64.split(',')[1]; this.modelDoc.thDocObj = base64.split(',')[1];
}else { } else {
this.modelDoc.engDocObj = base64.split(',')[1]; this.modelDoc.engDocObj = base64.split(',')[1];
} }
} }
} }
} }
} }
} }
async downloadFile(logId:string,lang:string){ async downloadFile(logId: string, lang: string) {
try { try {
const data = await this.documentService.downloadFile(logId,lang).toPromise(); const data = await this.documentService.downloadFile(logId, lang).toPromise();
if(data){ if (data) {
FileSaver.saveAs(new Blob([data]), "file_download.doc"); FileSaver.saveAs(new Blob([data]), "file_download.doc");
} }
} catch (error) { } catch (error) {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
deleteFile(item:DocumentModel){ deleteFile(item: DocumentModel) {
const modalRef = this.modalService.open(ConfirmModalComponent, { const modalRef = this.modalService.open(ConfirmModalComponent, {
centered: true, centered: true,
backdrop: 'static', backdrop: 'static',
...@@ -91,7 +91,7 @@ export class ListDocComponent implements OnInit { ...@@ -91,7 +91,7 @@ export class ListDocComponent implements OnInit {
this.openAlertModal('ลบข้อมูลสำเร็จ') this.openAlertModal('ลบข้อมูลสำเร็จ')
this.getListDoc(); this.getListDoc();
} else { } else {
this.openAlertModal('ไม่สามารถลบข้อมูลได้') this.openAlertModal('ไม่สามารถลบข้อมูลได้')
} }
}, error => { }, error => {
this.openAlertModal(error.message) this.openAlertModal(error.message)
...@@ -111,7 +111,7 @@ export class ListDocComponent implements OnInit { ...@@ -111,7 +111,7 @@ export class ListDocComponent implements OnInit {
}) })
} }
onUpdate(){ onUpdate() {
const modalRef = this.modalService.open(ConfirmModalComponent, { const modalRef = this.modalService.open(ConfirmModalComponent, {
centered: true, centered: true,
backdrop: 'static', backdrop: 'static',
...@@ -119,19 +119,22 @@ export class ListDocComponent implements OnInit { ...@@ -119,19 +119,22 @@ export class ListDocComponent implements OnInit {
modalRef.componentInstance.message = 'คุณต้องการอัพเดทข้อมูลหรือไม่' modalRef.componentInstance.message = 'คุณต้องการอัพเดทข้อมูลหรือไม่'
modalRef.result.then(result => { modalRef.result.then(result => {
this.documentService.createDoc(this.modelDoc).subscribe(result => { this.documentService.createDoc(this.modelDoc).subscribe(result => {
if (result) { this.modalService.dismissAll()
this.modalService.dismissAll() this.openAlertModal('อัพเดทข้อมูลสำเร็จ')
this.openAlertModal('อัพเดทข้อมูลสำเร็จ') this.getListDoc();
this.getListDoc(); // if (result) {
} else { // this.modalService.dismissAll()
this.openAlertModal('ไม่สามารถอัพเดทข้อมูลได้') // this.openAlertModal('อัพเดทข้อมูลสำเร็จ')
} // this.getListDoc();
// } else {
// this.openAlertModal('ไม่สามารถอัพเดทข้อมูลได้')
// }
}, error => { }, error => {
this.openAlertModal(error.message) this.openAlertModal(error.message)
}) })
}, reject => { }) }, reject => { })
} }
onCreate(){ onCreate() {
const modalRef = this.modalService.open(ConfirmModalComponent, { const modalRef = this.modalService.open(ConfirmModalComponent, {
centered: true, centered: true,
backdrop: 'static', backdrop: 'static',
...@@ -144,7 +147,7 @@ export class ListDocComponent implements OnInit { ...@@ -144,7 +147,7 @@ export class ListDocComponent implements OnInit {
this.openAlertModal('บันทึกข้อมูลสำเร็จ') this.openAlertModal('บันทึกข้อมูลสำเร็จ')
this.getListDoc(); this.getListDoc();
} else { } else {
this.openAlertModal('ไม่สามารถสร้างเอกสารได้') this.openAlertModal('ไม่สามารถสร้างเอกสารได้')
} }
}, error => { }, error => {
this.openAlertModal(error.message) this.openAlertModal(error.message)
...@@ -152,17 +155,17 @@ export class ListDocComponent implements OnInit { ...@@ -152,17 +155,17 @@ export class ListDocComponent implements OnInit {
}, reject => { }) }, reject => { })
} }
onSumit() { onSumit() {
if(this.checkEdit){ if (this.checkEdit) {
this.onUpdate(); this.onUpdate();
}else{ } else {
this.onCreate(); this.onCreate();
} }
} }
async getExcelById(targetModal: NgbModal,id:string){ async getExcelById(targetModal: NgbModal, id: string) {
try { try {
const data = await this.documentService.getDocById(id).toPromise(); const data = await this.documentService.getDocById(id).toPromise();
this.modelDoc = new DocumentModel(data) this.modelDoc = new DocumentModel(data)
if(data){ if (data) {
this.modalService.open(targetModal, { this.modalService.open(targetModal, {
centered: true, centered: true,
backdrop: 'static', backdrop: 'static',
...@@ -173,11 +176,11 @@ export class ListDocComponent implements OnInit { ...@@ -173,11 +176,11 @@ export class ListDocComponent implements OnInit {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
openModal(targetModal: NgbModal,item?:DocumentModel) { openModal(targetModal: NgbModal, item?: DocumentModel) {
if(item){ if (item) {
this.getExcelById(targetModal,item.logId) this.getExcelById(targetModal, item.logId)
this.checkEdit = true this.checkEdit = true
}else{ } else {
this.modelDoc = new DocumentModel({}); this.modelDoc = new DocumentModel({});
this.checkEdit = false this.checkEdit = false
this.modalService.open(targetModal, { this.modalService.open(targetModal, {
...@@ -186,18 +189,18 @@ export class ListDocComponent implements OnInit { ...@@ -186,18 +189,18 @@ export class ListDocComponent implements OnInit {
size: 'lg' size: 'lg'
}); });
} }
} }
getStatus(status:string){ getStatus(status: string) {
if(status == '0'){ if (status == '0') {
return 'รออนุมัติ' return 'รออนุมัติ'
} else if(status == '1'){ } else if (status == '1') {
return 'เปิดใช้งาน' return 'เปิดใช้งาน'
} else if(status == '2'){ } else if (status == '2') {
return 'ไม่อนุมัติ' return 'ไม่อนุมัติ'
} }
} }
async getListDoc(){ async getListDoc() {
try { try {
const data = await this.documentService.getListDoc().toPromise(); const data = await this.documentService.getListDoc().toPromise();
this.listDoc = data.map(x => new DocumentModel(x)) this.listDoc = data.map(x => new DocumentModel(x))
...@@ -205,39 +208,39 @@ export class ListDocComponent implements OnInit { ...@@ -205,39 +208,39 @@ export class ListDocComponent implements OnInit {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
filterListDoc(){ filterListDoc() {
return this.listDoc.filter(x => x.thName.toLowerCase().includes(this.search.toLowerCase())||x.engName.toLowerCase().includes(this.search.toLowerCase())) return this.listDoc.filter(x => x.thName.toLowerCase().includes(this.search.toLowerCase()) || x.engName.toLowerCase().includes(this.search.toLowerCase()))
} }
ngOnInit() { ngOnInit() {
this.getListDoc(); this.getListDoc();
this.getListTag(); this.getListTag();
this.getListGroup(); this.getListGroup();
} }
async getListGroup(){ async getListGroup() {
try{ try {
const data = await this.groupService.getList().toPromise(); const data = await this.groupService.getList().toPromise();
this.listGroup = data.map(x => new GroupModel(x)) this.listGroup = data.map(x => new GroupModel(x))
}catch(error){ } catch (error) {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
selectGroup(){ selectGroup() {
let findData = this.listGroup.find(x => x.groupId == this.modelDoc.group.groupId) let findData = this.listGroup.find(x => x.groupId == this.modelDoc.group.groupId)
this.modelDoc.group = findData?new GroupModel(findData):new GroupModel({}) this.modelDoc.group = findData ? new GroupModel(findData) : new GroupModel({})
} }
async getListTag(){ async getListTag() {
try{ try {
const data = await this.tagService.getList().toPromise(); const data = await this.tagService.getList().toPromise();
this.listTag = data.map(x => new TagModel(x)) this.listTag = data.map(x => new TagModel(x))
}catch(error){ } catch (error) {
console.error('Error loading data:', error); console.error('Error loading data:', error);
} }
} }
closeBtnClick() { closeBtnClick() {
this.modalService.dismissAll(); this.modalService.dismissAll();
} }
openLink(url:string){ openLink(url: string) {
window.open(url, "_blank"); window.open(url, "_blank");
} }
} }
...@@ -33,17 +33,12 @@ export class CourseService { ...@@ -33,17 +33,12 @@ export class CourseService {
downloadFileContent(logId:string):Observable<any>{ downloadFileContent(logId:string):Observable<any>{
return this.http.get(this.url + "course-center/files/download/content/"+logId, { responseType: 'blob' }); return this.http.get(this.url + "course-center/files/download/content/"+logId, { responseType: 'blob' });
} }
createCourse(model: CourseModel): Observable<boolean> { createCourse(model: CourseModel): Observable<any> {
if (this.createStatus) { let body : any = model
this.createStatus = false if (body.group.groupId=='') {
return this.http.post(this.url + 'course-center', model, { observe: 'response' }) body.group = undefined
.pipe(
tap(x => this.createStatus = true),
map(r => r.status == 200)
);
} else {
return of(false)
} }
return this.http.post(this.url + 'course-center', body)
} }
deleteCourse(model: CourseModel): Observable<any> { deleteCourse(model: CourseModel): Observable<any> {
let body = { let body = {
......
...@@ -13,37 +13,32 @@ export class DocumentService { ...@@ -13,37 +13,32 @@ export class DocumentService {
url = environment.url url = environment.url
createStatus: boolean = true createStatus: boolean = true
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
getListDoc(status?:string): Observable<DocumentModel[]> { getListDoc(status?: string): Observable<DocumentModel[]> {
if(status){ if (status) {
return this.http.get<DocumentModel[]>(this.url + "document-center/upload/lists?status="+status) return this.http.get<DocumentModel[]>(this.url + "document-center/upload/lists?status=" + status)
}else{ } else {
return this.http.get<DocumentModel[]>(this.url + "document-center/upload/lists") return this.http.get<DocumentModel[]>(this.url + "document-center/upload/lists")
} }
} }
getListExcelContent(status?: string): Observable<DocumentContentModel[]> { getListExcelContent(status?: string): Observable<DocumentContentModel[]> {
return this.http.get<DocumentContentModel[]>(this.url + "document-center/content/lists") return this.http.get<DocumentContentModel[]>(this.url + "document-center/content/lists")
} }
getDocById(logId:string): Observable<DocumentModel> { getDocById(logId: string): Observable<DocumentModel> {
return this.http.get<DocumentModel>(this.url + "document-center/upload/"+logId) return this.http.get<DocumentModel>(this.url + "document-center/upload/" + logId)
}
downloadFile(logId:string,lang:string):Observable<any>{
return this.http.get(this.url + "document-center/files/download/"+logId+'?lang='+lang, { responseType: 'blob' })
} }
downloadFile(logId: string, lang: string): Observable<any> {
downloadFileContent(logId:string,lang:string):Observable<any>{ return this.http.get(this.url + "document-center/files/download/" + logId + '?lang=' + lang, { responseType: 'blob' })
return this.http.get(this.url + "document-center/files/download/content/"+logId+'?lang='+lang, { responseType: 'blob' });
} }
createDoc(model: DocumentModel): Observable<boolean> {
if (this.createStatus) { downloadFileContent(logId: string, lang: string): Observable<any> {
this.createStatus = false return this.http.get(this.url + "document-center/files/download/content/" + logId + '?lang=' + lang, { responseType: 'blob' });
return this.http.post(this.url + 'document-center', model, { observe: 'response' }) }
.pipe( createDoc(model: DocumentModel): Observable<any> {
tap(x => this.createStatus = true), let body : any = model
map(r => r.status == 200) if (body.group.groupId=='') {
); body.group = undefined
} else {
return of(false)
} }
return this.http.post(this.url + 'document-center', body)
} }
deleteExcel(model: DocumentModel): Observable<any> { deleteExcel(model: DocumentModel): Observable<any> {
let body = { let body = {
...@@ -74,9 +69,9 @@ export class DocumentService { ...@@ -74,9 +69,9 @@ export class DocumentService {
logId: model.logId, logId: model.logId,
status: model.status status: model.status
} }
return this.http.put<any>(this.url + "document-center/approve",body) return this.http.put<any>(this.url + "document-center/approve", body)
} }
getCount(status?: string): Observable<number> { getCount(status?: string): Observable<number> {
return this.http.get<number>(this.url + "document-center/upload/count") return this.http.get<number>(this.url + "document-center/upload/count")
} }
......
...@@ -34,17 +34,12 @@ export class ExcelService { ...@@ -34,17 +34,12 @@ export class ExcelService {
return this.http.get(this.url + "excel-center/files/download/content/"+logId, { responseType: 'blob' }); return this.http.get(this.url + "excel-center/files/download/content/"+logId, { responseType: 'blob' });
} }
createExcel(model: ExcelModel): Observable<boolean> { createExcel(model: ExcelModel): Observable<any> {
if (this.createStatus) { let body : any = model
this.createStatus = false if (body.group.groupId=='') {
return this.http.post(this.url + 'excel-center', model, { observe: 'response' }) body.group = undefined
.pipe(
tap(x => this.createStatus = true),
map(r => r.status == 200)
);
} else {
return of(false)
} }
return this.http.post(this.url + 'excel-center', body)
} }
deleteExcel(model: ExcelModel): Observable<any> { deleteExcel(model: ExcelModel): Observable<any> {
let body = { let body = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment