Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
upsmf-examinations-module
Commits
c811bbaf
Commit
c811bbaf
authored
1 year ago
by
Arun Kumar
Browse files
Options
Download
Patches
Plain Diff
csv-data upload success
parent
df6651d8
master
bulk-upload-csv
examcycleValiation
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/modules/shared/components/shared-dialog-overlay/shared-dialog-overlay.component.html
+17
-1
...hared-dialog-overlay/shared-dialog-overlay.component.html
src/app/modules/shared/components/shared-dialog-overlay/shared-dialog-overlay.component.ts
+117
-8
.../shared-dialog-overlay/shared-dialog-overlay.component.ts
with
134 additions
and
9 deletions
+134
-9
src/app/modules/shared/components/shared-dialog-overlay/shared-dialog-overlay.component.html
+
17
−
1
View file @
c811bbaf
<h1
mat-dialog-title
>
Bulk Upload Exam Cycles
</h1>
<div
mat-dialog-content
>
<app-shared-table
<div
*ngIf=
"tableDataReady; else dataNotReady"
>
<app-shared-table
[tableColumns]=
"examsTableColumns"
[tableData]=
"exams"
[isPageable]=
"false"
>
</app-shared-table>
</div>
<ng-template
#dataNotReady
>
<div>
<input
class=
"form-control"
accept=
".csv"
id=
"csv"
type=
"file"
(change)=
"onFileSelect($event.target)"
name=
"myfile"
>
</div>
</ng-template>
</div>
<div
mat-dialog-actions
>
<button
mat-button
(click)=
"onNoClick()"
>
Cancel
</button>
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/shared/components/shared-dialog-overlay/shared-dialog-overlay.component.ts
+
117
−
8
View file @
c811bbaf
import
{
Component
,
Inject
}
from
'
@angular/core
'
;
import
{
MAT_DIALOG_DATA
,
MatDialogRef
}
from
'
@angular/material/dialog
'
;
import
{
MAT_DIALOG_DATA
,
MatDialogRef
}
from
'
@angular/material/dialog
'
;
import
{
TableColumn
}
from
'
../../../shared/components/shared-table/shared-table.component
'
;
import
{
Exams
}
from
'
../../../manage-exams-module/components/exams-table/exams-table.component
'
;
export
interface
DialogData
{
...
...
@@ -13,20 +13,129 @@ export interface DialogData {
styleUrls
:
[
'
./shared-dialog-overlay.component.scss
'
]
})
export
class
SharedDialogOverlayComponent
{
exams
:
Exams
[];
examsTableColumns
:
TableColumn
[];
exams
:
Exams
[]
=
[];
examsTableColumns
:
TableColumn
[]
=
[];
tableDataReady
:
boolean
=
false
;
csvContent
:
any
;
convertedArray
:
Array
<
any
>
=
[];
properties
:
any
=
''
;
constructor
(
public
dialogRef
:
MatDialogRef
<
SharedDialogOverlayComponent
>
,
@
Inject
(
MAT_DIALOG_DATA
)
public
data
:
DialogData
,
)
{}
)
{
}
ngOnInit
():
void
{
this
.
exams
=
this
.
data
.
exams
;
console
.
log
(
this
.
exams
)
this
.
examsTableColumns
=
this
.
data
.
examsTableColumns
;
console
.
log
(
this
.
examsTableColumns
)
/*
this.exams = this.data.exams;
console.log(this.exams)
this.examsTableColumns =this.data.examsTableColumns;
console.log(this.examsTableColumns)
*/
}
onFileSelect
(
input
:
any
)
{
const
files
=
input
.
files
;
var
fileTypes
=
[
'
csv
'
];
//acceptable file types
if
(
files
&&
files
.
length
)
{
var
extension
=
input
.
files
[
0
].
name
.
split
(
'
.
'
).
pop
().
toLowerCase
(),
//file extension from input file
//Validating type of File Uploaded
isSuccess
=
fileTypes
.
indexOf
(
extension
)
>
-
1
;
//is extension in acceptable types
var
that
=
this
;
//Flag to check the Validation Result
if
(
isSuccess
)
{
const
fileToRead
=
files
[
0
];
const
fileReader
=
new
FileReader
();
fileReader
.
onload
=
(
fileLoadedEvent
)
=>
{
const
textFromFileLoaded
=
fileLoadedEvent
?.
target
?.
result
;
that
.
csvContent
=
textFromFileLoaded
;
//Flag is for extracting first line
let
flag
=
false
;
// Main Data
let
objarray
:
Array
<
any
>
=
[];
//Properties
let
prop
:
Array
<
any
>
=
[];
//Total Length
let
size
:
any
=
0
;
for
(
const
line
of
that
.
csvContent
.
split
(
/
[\r\n]
+/
))
{
if
(
flag
)
{
let
obj
:
any
=
{};
for
(
let
k
=
0
;
k
<
size
;
k
++
)
{
//Dynamic Object Properties
obj
[
prop
[
k
]]
=
line
.
split
(
'
,
'
)[
k
];
}
objarray
.
push
(
obj
);
}
else
{
//First Line of CSV will be having Properties
for
(
let
k
=
0
;
k
<
line
.
split
(
'
,
'
).
length
;
k
++
)
{
size
=
line
.
split
(
'
,
'
).
length
;
//Removing all the spaces to make them usefull
prop
.
push
(
line
.
split
(
'
,
'
)[
k
].
replace
(
/ /g
,
''
));
}
flag
=
true
;
}
}
//All the values converted from CSV to JSON Array
that
.
convertedArray
=
objarray
;
that
.
properties
=
[];
//Object Keys of Converted JSON Array
that
.
properties
=
prop
;
this
.
examsTableColumns
=
[
{
columnDef
:
that
.
properties
[
0
],
header
:
'
Exam Cycle
'
,
isSortable
:
true
,
cell
:
(
element
:
Record
<
string
,
any
>
)
=>
`
${
element
[
that
.
properties
[
0
]]}
`
},
{
columnDef
:
that
.
properties
[
1
],
header
:
'
Course Name
'
,
isSortable
:
true
,
cell
:
(
element
:
Record
<
string
,
any
>
)
=>
`
${
element
[
that
.
properties
[
1
]]}
`
},
{
columnDef
:
that
.
properties
[
2
],
header
:
'
Start Date
'
,
isSortable
:
true
,
cell
:
(
element
:
Record
<
string
,
any
>
)
=>
`
${
element
[
that
.
properties
[
2
]]}
`
},
{
columnDef
:
that
.
properties
[
3
],
header
:
'
End Date
'
,
isSortable
:
true
,
cell
:
(
element
:
Record
<
string
,
any
>
)
=>
`
${
element
[
that
.
properties
[
3
]]}
`
},
];
this
.
exams
=
that
.
convertedArray
this
.
tableDataReady
=
true
;
};
fileReader
.
readAsText
(
fileToRead
,
'
UTF-8
'
);
}
else
{
//On Error
console
.
error
(
'
Invalid File Format!
'
);
}
}
}
initializeColumns
()
{
}
onNoClick
():
void
{
this
.
dialogRef
.
close
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets