Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
svmon-web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jie Yuan
svmon-web
Commits
c8cde83c
Commit
c8cde83c
authored
Oct 02, 2019
by
Jie Yuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add profile dialog comp
parent
3786f17f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
282 additions
and
0 deletions
+282
-0
src/app/dashboard/profile-dialog/profile-dialog.component.css
...app/dashboard/profile-dialog/profile-dialog.component.css
+0
-0
src/app/dashboard/profile-dialog/profile-dialog.component.html
...pp/dashboard/profile-dialog/profile-dialog.component.html
+22
-0
src/app/dashboard/profile-dialog/profile-dialog.component.spec.ts
...dashboard/profile-dialog/profile-dialog.component.spec.ts
+25
-0
src/app/dashboard/profile-dialog/profile-dialog.component.ts
src/app/dashboard/profile-dialog/profile-dialog.component.ts
+235
-0
No files found.
src/app/dashboard/profile-dialog/profile-dialog.component.css
0 → 100644
View file @
c8cde83c
src/app/dashboard/profile-dialog/profile-dialog.component.html
0 → 100644
View file @
c8cde83c
<h2
mat-dialog-title
><B>
Hi, {{user}}
</B></h2>
<div
mat-dialog-content
>
<mat-list
*ngIf=
"hasToken"
>
<p
mat-line
>
<B>
Your Id:
</B>
{{apitoken.id}}
</p>
<p
mat-line
matTooltip=
"{{this.apitoken.token}}"
><B>
Your Token:
</B>
{{shortToken}}
<button
(click)=
"copyToken(this.apitoken.token)"
value=
"click to copy"
mat-raised-button
>
<mat-icon>
format_align_justify
</mat-icon>
</button>
<button
(click)=
"onDeleteClick()"
mat-raised-button
>
<mat-icon>
delete
</mat-icon>
</button>
</p>
<p
mat-line
>
<B>
Validate till:
</B>
{{eDate}}
</p>
</mat-list>
<button
*ngIf =
"hasToken === false"
mat-button
(click)=
"onCreationClick()"
>
Create an API
</button>
</div>
<div
mat-dialog-actions
>
<button
mat-button
(click)=
"onNoClick()"
>
OK
</button>
</div>
src/app/dashboard/profile-dialog/profile-dialog.component.spec.ts
0 → 100644
View file @
c8cde83c
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ProfileDialogComponent
}
from
'
./profile-dialog.component
'
;
describe
(
'
ProfileDialogComponent
'
,
()
=>
{
let
component
:
ProfileDialogComponent
;
let
fixture
:
ComponentFixture
<
ProfileDialogComponent
>
;
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
ProfileDialogComponent
]
})
.
compileComponents
();
}));
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
ProfileDialogComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
src/app/dashboard/profile-dialog/profile-dialog.component.ts
0 → 100644
View file @
c8cde83c
import
{
Component
,
OnInit
,
Inject
}
from
'
@angular/core
'
;
import
{
MatDialog
,
MatDialogRef
,
MAT_DIALOG_DATA
,
throwMatDialogContentAlreadyAttachedError
}
from
'
@angular/material/dialog
'
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
HttpHeaders
}
from
'
@angular/common/http
'
;
import
{
TableComponent
}
from
'
../table/table.component
'
;
import
{
SharedService
}
from
'
../../shared-service
'
;
import
{
TokenInfo
}
from
'
src/app/model/tokenInfo
'
;
import
{
resolve
}
from
'
url
'
;
@
Component
({
selector
:
'
app-profile-dialog
'
,
templateUrl
:
'
./profile-dialog.component.html
'
,
styleUrls
:
[
'
./profile-dialog.component.css
'
]
})
export
class
ProfileDialogComponent
implements
OnInit
{
user
:
string
=
""
;
hasToken
:
boolean
;
apitoken
:
TokenInfo
;
eDate
:
Date
;
shortToken
:
string
;
constructor
(
public
dialogRef
:
MatDialogRef
<
ProfileDialogComponent
>
,
public
sharedService
:
SharedService
,
private
httpClient
:
HttpClient
)
{
const
tmp
=
sessionStorage
.
getItem
(
'
currentUser
'
);
console
.
log
(
"
opened the dialog by
"
+
tmp
);
this
.
user
=
tmp
;
}
onNoClick
():
void
{
this
.
dialogRef
.
close
();
}
ngOnInit
()
{
this
.
getApiToken
()
.
then
(
(
atoken
:
TokenInfo
)
=>
{
this
.
apitoken
=
atoken
;
if
(
this
.
apitoken
===
undefined
||
this
.
apitoken
===
null
)
{
this
.
hasToken
=
false
;
}
else
{
this
.
hasToken
=
true
;
this
.
shortToken
=
this
.
apitoken
.
token
.
slice
(
0
,
20
)
+
"
... ...
"
;
this
.
eDate
=
new
Date
(
this
.
apitoken
.
validationDate
);
console
.
log
(
new
Date
(
this
.
apitoken
.
validationDate
));
}
}
).
catch
(
error
=>
{
console
.
log
(
'
No token
'
);
console
.
log
(
error
);
}
);
// console.log(this.apitoken);
// this.dialogRef.updatePosition({ top: `200px`, right: `400px`});
}
getApiToken
()
{
console
.
log
(
'
Fetching api token
'
);
const
promise
=
new
Promise
(
(
resolve
,
reject
)
=>
{
/** Gets the sites from the source specified (GOCDB or DPMT) **/
const
getUrl
=
this
.
sharedService
.
apiTokenURL
;
if
(
sessionStorage
.
getItem
(
'
authHeader
'
)
!==
''
)
{
const
headers
=
new
HttpHeaders
(
sessionStorage
.
getItem
(
'
authHeader
'
)
?
{
'
Authorization
'
:
sessionStorage
.
getItem
(
'
authHeader
'
),
'
Content-Type
'
:
'
application/json
'
}
:
{}
);
this
.
httpClient
.
get
<
TokenInfo
>
(
getUrl
,
{
headers
:
headers
})
.
subscribe
(
(
tokeninfo
:
TokenInfo
)
=>
{
// this.apitoken = tokeninfo;
resolve
(
tokeninfo
);
//return new TokenInfo(tokeninfo.id,tokeninfo.token,tokeninfo.validationDate);
// this.apitoken = tokeninfo;
//resolve(tokeninfo);
//console.log(this.token);
},
(
error
)
=>
{
reject
(
error
);
}
);
}
});
return
promise
;
}
postApiToken
()
{
console
.
log
(
'
Creating api token
'
);
const
promise
=
new
Promise
(
(
resolve
,
reject
)
=>
{
/** Gets the sites from the source specified (GOCDB or DPMT) **/
const
Url
=
this
.
sharedService
.
apiTokenURL
;
if
(
sessionStorage
.
getItem
(
'
authHeader
'
)
!==
''
)
{
const
headers
=
new
HttpHeaders
(
sessionStorage
.
getItem
(
'
authHeader
'
)
?
{
'
Authorization
'
:
sessionStorage
.
getItem
(
'
authHeader
'
),
'
Content-Type
'
:
'
application/json
'
}
:
{}
);
//console.log("post header");
//console.log(headers);
this
.
httpClient
.
post
<
TokenInfo
>
(
Url
,
null
,{
headers
:
headers
})
.
subscribe
(
(
tokeninfo
:
TokenInfo
)
=>
{
// this.apitoken = tokeninfo;
resolve
(
tokeninfo
);
// return new TokenInfo(tokeninfo.id,tokeninfo.token,tokeninfo.validationDate);
// this.apitoken = tokeninfo;
//resolve(tokeninfo);
//console.log(this.token);
},
(
error
)
=>
{
reject
(
error
);
}
);
}
});
return
promise
;
}
deleteApiToken
()
{
console
.
log
(
'
deleting api token
'
);
const
promise
=
new
Promise
(
(
resolve
,
reject
)
=>
{
/** Gets the sites from the source specified (GOCDB or DPMT) **/
const
Url
=
this
.
sharedService
.
apiTokenURL
;
if
(
sessionStorage
.
getItem
(
'
authHeader
'
)
!==
''
)
{
const
headers
=
new
HttpHeaders
(
sessionStorage
.
getItem
(
'
authHeader
'
)
?
{
'
Authorization
'
:
sessionStorage
.
getItem
(
'
authHeader
'
),
'
Content-Type
'
:
'
application/json
'
}
:
{}
);
console
.
log
(
"
post header
"
);
console
.
log
(
headers
);
this
.
httpClient
.
delete
(
Url
,{
headers
:
headers
})
.
subscribe
(
(
info
:
string
)
=>
{
// this.apitoken = tokeninfo;
resolve
(
info
);
//return new TokenInfo(tokeninfo.id,tokeninfo.token,tokeninfo.validationDate);
// this.apitoken = tokeninfo;
//resolve(tokeninfo);
//console.log(this.token);
},
(
error
)
=>
{
reject
(
error
);
}
);
}
});
return
promise
;
}
copyToken
(
val
:
string
){
let
selBox
=
document
.
createElement
(
'
textarea
'
);
selBox
.
style
.
position
=
'
fixed
'
;
selBox
.
style
.
left
=
'
0
'
;
selBox
.
style
.
top
=
'
0
'
;
selBox
.
style
.
opacity
=
'
0
'
;
selBox
.
value
=
val
;
document
.
body
.
appendChild
(
selBox
);
selBox
.
focus
();
selBox
.
select
();
document
.
execCommand
(
'
copy
'
);
document
.
body
.
removeChild
(
selBox
);
}
onCreationClick
(){
console
.
log
(
"
on creation clicked
"
);
this
.
postApiToken
()
.
then
(
(
atoken
:
TokenInfo
)
=>
{
this
.
apitoken
=
atoken
;
if
(
this
.
apitoken
===
undefined
||
this
.
apitoken
===
null
)
{
this
.
hasToken
=
false
;
}
else
{
this
.
hasToken
=
true
;
this
.
shortToken
=
this
.
apitoken
.
token
.
slice
(
0
,
20
)
+
"
... ...
"
;
this
.
eDate
=
new
Date
(
this
.
apitoken
.
validationDate
);
console
.
log
(
new
Date
(
this
.
apitoken
.
validationDate
));
}
}
).
catch
(
error
=>
{
console
.
log
(
'
No token created
'
);
console
.
log
(
error
);
}
);
}
onDeleteClick
(){
console
.
log
(
"
on creation clicked
"
);
this
.
deleteApiToken
()
.
then
(
(
info
:
string
)
=>
{
this
.
hasToken
=
false
;
this
.
shortToken
=
""
;
this
.
apitoken
=
null
}
).
catch
(
error
=>
{
console
.
log
(
'
No token deleted
'
);
console
.
log
(
error
);
}
);
}
}
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