Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sfcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush
sfcode
Commits
a09fde7b
Commit
a09fde7b
authored
Dec 04, 2020
by
Adarsh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file-upload
parent
edf892eb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
3 deletions
+116
-3
src/app/file.service.ts
src/app/file.service.ts
+10
-1
src/app/file/file.component.html
src/app/file/file.component.html
+33
-1
src/app/file/file.component.scss
src/app/file/file.component.scss
+39
-1
src/app/file/file.component.ts
src/app/file/file.component.ts
+34
-0
No files found.
src/app/file.service.ts
View file @
a09fde7b
...
@@ -9,7 +9,9 @@ import { HttpClient } from '@angular/common/http';
...
@@ -9,7 +9,9 @@ import { HttpClient } from '@angular/common/http';
})
})
export
class
FileService
{
export
class
FileService
{
constructor
(
private
httpClient
:
HttpClient
)
{
}
baseApiUrl
=
"
https://file.io
"
;
constructor
(
private
http
:
HttpClient
)
{
}
getFiles
():
Observable
<
File
[]
>
{
getFiles
():
Observable
<
File
[]
>
{
...
@@ -29,4 +31,11 @@ export class FileService {
...
@@ -29,4 +31,11 @@ export class FileService {
return
of
(
ret
);
return
of
(
ret
);
}
}
upload
(
file
):
Observable
<
any
>
{
const
formData
=
new
FormData
();
formData
.
append
(
"
file
"
,
file
,
file
.
name
);
return
this
.
http
.
post
(
this
.
baseApiUrl
,
formData
)
}
}
}
src/app/file/file.component.html
View file @
a09fde7b
<div
id=
"tray"
>
<div
id=
"tray"
>
<button
style=
"margin-right: 10px;"
routerLink=
"/arena"
routerLinkActive=
"active"
>
Create A File
</button>
<button
style=
"margin-right: 10px;"
routerLink=
"/arena"
routerLinkActive=
"active"
>
Create A File
</button>
<button
style=
"margin-left: 10px;"
>
Upload A File
</button>
<button
(click)=
"onClick()"
id=
"myBtn"
style=
"margin-left: 10px;"
>
Upload A File
</button>
</div>
</div>
<div>
<div>
...
@@ -18,3 +18,35 @@
...
@@ -18,3 +18,35 @@
<!-- <button [routerLink]="['/arena', problem.id]" class="attempt">Attempt</button> -->
<!-- <button [routerLink]="['/arena', problem.id]" class="attempt">Attempt</button> -->
</div>
</div>
<div
id=
"myModal"
class=
"modal"
>
<!-- Modal content -->
<div
class=
"modal-content"
>
<span
(click)=
"onClick2()"
class=
"close"
>
×
</span>
<div
class=
"text-center"
>
<input
class=
"form-control"
type=
"file"
(change)=
"onChange($event)"
>
<button
(click)=
"onUpload()"
class=
"btn btn-success"
>
Upload
</button>
</div>
<!-- Shareable short link of uoloaded file -->
<div
class=
"container text-center jumbotron"
*ngIf=
"shortLink"
>
<h2>
Visit Here
</h2>
<a
href=
"{{shortLink}}"
>
{{shortLink}}
</a>
</div>
<!--Flag variable is used here-->
<div
class=
"container"
*ngIf=
"loading"
>
<h3>
Loading ...
</h3>
</div>
</div>
</div>
\ No newline at end of file
src/app/file/file.component.scss
View file @
a09fde7b
...
@@ -34,3 +34,41 @@
...
@@ -34,3 +34,41 @@
margin
:
10px
;
margin
:
10px
;
}
}
}
}
.modal
{
display
:
none
;
/* Hidden by default */
position
:
fixed
;
/* Stay in place */
z-index
:
100
;
/* Sit on top */
padding-top
:
100px
;
/* Location of the box */
left
:
0
;
top
:
0
;
width
:
100%
;
/* Full width */
height
:
100%
;
/* Full height */
overflow
:
auto
;
/* Enable scroll if needed */
background-color
:
rgb
(
0
,
0
,
0
);
/* Fallback color */
background-color
:
rgba
(
0
,
0
,
0
,
0
.4
);
/* Black w/ opacity */
}
/* Modal Content */
.modal-content
{
background-color
:
#fefefe
;
margin
:
auto
;
padding
:
20px
;
border
:
1px
solid
#888
;
width
:
80%
;
}
/* The Close Button */
.close
{
color
:
#aaaaaa
;
float
:
right
;
font-size
:
28px
;
font-weight
:
bold
;
}
.close
:hover
,
.close
:focus
{
color
:
#000
;
text-decoration
:
none
;
cursor
:
pointer
;
}
src/app/file/file.component.ts
View file @
a09fde7b
...
@@ -11,6 +11,10 @@ export class FileComponent implements OnInit {
...
@@ -11,6 +11,10 @@ export class FileComponent implements OnInit {
constructor
(
private
fileService
:
FileService
)
{
}
constructor
(
private
fileService
:
FileService
)
{
}
files
:
File
[];
files
:
File
[];
// File upload variables
shortLink
:
string
=
""
;
loading
:
boolean
=
false
;
// Flag variable
fileToUpload
:
File
=
null
;
fileToUpload
:
File
=
null
;
ngOnInit
():
void
{
ngOnInit
():
void
{
...
@@ -21,4 +25,34 @@ export class FileComponent implements OnInit {
...
@@ -21,4 +25,34 @@ export class FileComponent implements OnInit {
this
.
fileService
.
getFiles
()
this
.
fileService
.
getFiles
()
.
subscribe
(
files
=>
this
.
files
=
files
);
.
subscribe
(
files
=>
this
.
files
=
files
);
}
}
onClick
():
void
{
var
modal
=
document
.
getElementById
(
"
myModal
"
);
modal
.
style
.
display
=
"
block
"
;
}
onClick2
():
void
{
var
modal
=
document
.
getElementById
(
"
myModal
"
);
modal
.
style
.
display
=
"
none
"
;
}
onChange
(
event
)
{
this
.
fileToUpload
=
event
.
target
.
files
[
0
];
}
onUpload
()
{
this
.
loading
=
!
this
.
loading
;
console
.
log
(
this
.
fileToUpload
);
this
.
fileService
.
upload
(
this
.
fileToUpload
).
subscribe
(
(
event
:
any
)
=>
{
if
(
typeof
(
event
)
===
'
object
'
)
{
this
.
shortLink
=
event
.
link
;
this
.
loading
=
false
;
}
}
);
}
}
}
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