Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
myhr-portal
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angular
myhr-portal
Commits
f28ccdfc
Commit
f28ccdfc
authored
Jun 28, 2024
by
Ooh-Ao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ให้ group ไม่ใส่ได้ เอาเงื่อนไขสร้างเสร็จออก เพราะ if ไม่เข้า
parent
3fc8fd7a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
106 deletions
+94
-106
list-doc.component.ts
src/app/apps/list-doc/list-doc.component.ts
+65
-62
course.service.ts
src/app/service/course.service.ts
+5
-10
document.service.ts
src/app/service/document.service.ts
+19
-24
excel.service.ts
src/app/service/excel.service.ts
+5
-10
No files found.
src/app/apps/list-doc/list-doc.component.ts
View file @
f28ccdfc
...
...
@@ -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"
);
}
}
src/app/service/course.service.ts
View file @
f28ccdfc
...
...
@@ -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
=
{
...
...
src/app/service/document.service.ts
View file @
f28ccdfc
...
...
@@ -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"
)
}
...
...
src/app/service/excel.service.ts
View file @
f28ccdfc
...
...
@@ -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
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment