Commit f28ccdfc by Ooh-Ao

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

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