11// Copyright The Linux Foundation and each contributor to CommunityBridge.
22// SPDX-License-Identifier: MIT
33
4- import { Component , OnInit , Input , EventEmitter , Output } from '@angular/core' ;
4+ import { Component , Input , EventEmitter , Output , ViewChild , TemplateRef , OnInit } from '@angular/core' ;
55import { AlertService } from '../../services/alert.service' ;
66import { ClaContributorService } from 'src/app/core/services/cla-contributor.service' ;
77import { ProjectModel } from 'src/app/core/models/project' ;
88import { UserFromSessionModel , UserFromTokenModel , UserModel } from 'src/app/core/models/user' ;
99import { StorageService } from '../../services/storage.service' ;
1010import { AppSettings } from 'src/app/config/app-settings' ;
11+ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
12+ import { Router } from '@angular/router' ;
1113
1214@Component ( {
1315 selector : 'app-project-title' ,
1416 templateUrl : './project-title.component.html' ,
1517 styleUrls : [ './project-title.component.scss' ]
1618} )
1719export class ProjectTitleComponent implements OnInit {
20+ @ViewChild ( 'warningModal' ) warningModal : TemplateRef < any > ;
21+
1822 @Input ( ) projectId : string ;
1923 @Input ( ) userId : string ;
2024 @Output ( ) errorEmitter : EventEmitter < any > = new EventEmitter < any > ( ) ;
2125 @Output ( ) successEmitter : EventEmitter < any > = new EventEmitter < any > ( ) ;
2226 @Output ( ) setUserIdEmitter : EventEmitter < any > = new EventEmitter < any > ( ) ;
2327
28+ message : string ;
29+ redirectUrl : string ;
2430 project = new ProjectModel ( ) ;
2531 userFromToken = new UserFromTokenModel ( ) ;
2632 user = new UserModel ( ) ;
@@ -29,7 +35,10 @@ export class ProjectTitleComponent implements OnInit {
2935 private alertService : AlertService ,
3036 private storageService : StorageService ,
3137 private claContributorService : ClaContributorService ,
32- ) { }
38+ private router : Router
39+ ) {
40+
41+ }
3342
3443 ngOnInit ( ) : void {
3544 const hasGerrit = JSON . parse ( this . storageService . getItem ( AppSettings . HAS_GERRIT ) ) ;
@@ -41,38 +50,32 @@ export class ProjectTitleComponent implements OnInit {
4150 }
4251
4352 validateGithubFlow ( ) {
53+ console . log ( 'validateGithubFlow' + this . projectId )
4454 if ( this . projectId ) {
4555 this . getProject ( ) ;
4656 if ( this . userId ) {
57+ // get user from user id
4758 this . getUser ( ) ;
4859 } else {
60+ // get user from token if user id is not present in url
4961 this . getUserFromToken ( ) ;
5062 }
5163 } else {
5264 this . errorEmitter . emit ( true ) ;
53- this . alertService . error ( 'Invalid project id and user id in URL' ) ;
65+ this . alertService . error ( 'Invalid project id in URL' ) ;
5466 }
5567 }
5668
5769 getProject ( ) {
58- if ( this . projectId ) {
59- this . claContributorService . getProject ( this . projectId ) . subscribe (
60- ( response ) => {
61- this . project = response ;
62- this . storageService . setItem ( AppSettings . PROJECT_NAME , this . project . project_name ) ;
63- this . storageService . setItem ( AppSettings . PROJECT_ID , this . projectId ) ;
64- this . storageService . setItem ( AppSettings . PROJECT , this . project ) ;
65- this . successEmitter . emit ( 'Project' ) ;
66- } ,
67- ( exception ) => {
68- this . errorEmitter . emit ( true ) ;
69- this . claContributorService . handleError ( exception ) ;
70- }
71- ) ;
72- } else {
73- this . errorEmitter . emit ( true ) ;
74- this . alertService . error ( 'Invalid project id in URL' ) ;
75- }
70+ this . claContributorService . getProject ( this . projectId ) . subscribe (
71+ ( response ) => {
72+ this . project = response ;
73+ this . storageService . setItem ( AppSettings . PROJECT_NAME , this . project . project_name ) ;
74+ this . storageService . setItem ( AppSettings . PROJECT_ID , this . projectId ) ;
75+ this . storageService . setItem ( AppSettings . PROJECT , this . project ) ;
76+ this . successEmitter . emit ( 'Project' ) ;
77+ }
78+ ) ;
7679 }
7780
7881 getUser ( ) {
@@ -105,6 +108,7 @@ export class ProjectTitleComponent implements OnInit {
105108 this . storageService . setItem ( AppSettings . USER , this . userFromToken ) ;
106109 this . successEmitter . emit ( 'User' ) ;
107110 this . setUserIdEmitter . emit ( this . userFromToken . userID ) ;
111+ this . router . navigate ( [ '/cla/project/' + this . projectId + '/user/' + this . userFromToken . userID ] ) ;
108112 } ,
109113 ( ) => {
110114 // If user is not found in token, get user from session
@@ -113,34 +117,30 @@ export class ProjectTitleComponent implements OnInit {
113117 ) ;
114118}
115119
116- getUserFromSession ( ) {
117- this . claContributorService . getUserFromSession ( ) . subscribe (
118- ( response : any ) => {
119- console . log ( 'getUserFromSession response ==>' , response )
120- this . userFromSession = response ;
121- this . storageService . setItem ( AppSettings . USER_ID , this . userFromSession . user_id ) ;
122- this . storageService . setItem ( AppSettings . USER , {
123- dateCreated : this . userFromSession . date_created ,
124- dateModified : this . userFromSession . date_modified ,
125- emails : this . userFromSession . user_emails ,
126- lfEmail : this . userFromSession . lf_email ,
127- lfUsername : this . userFromSession . lf_username ,
128- userID : this . userFromSession . user_id ,
129- username : this . userFromSession . user_name ,
130- version : this . userFromSession . version
131- } ) ;
132- this . successEmitter . emit ( 'User' ) ;
133- } ,
134- ( exception ) => {
135- console . log ( 'getUserFromSession exception ==>' , exception )
136- this . errorEmitter . emit ( true ) ;
137- this . alertService . error ( 'An error occurred while retrieving the GitHub user from the session.' ) ;
138- this . claContributorService . handleError ( exception ) ;
139- }
140- ) ;
141- }
142-
143-
144-
145-
120+ getUserFromSession ( ) {
121+ this . claContributorService . getUserFromSession ( ) . subscribe (
122+ ( response : any ) => {
123+ console . log ( 'getUserFromSession response ==>' , response )
124+ this . userFromSession = response ;
125+ this . storageService . setItem ( AppSettings . USER_ID , this . userFromSession . user_id ) ;
126+ this . storageService . setItem ( AppSettings . USER , {
127+ dateCreated : this . userFromSession . date_created ,
128+ dateModified : this . userFromSession . date_modified ,
129+ emails : this . userFromSession . user_emails ,
130+ lfEmail : this . userFromSession . lf_email ,
131+ lfUsername : this . userFromSession . lf_username ,
132+ userID : this . userFromSession . user_id ,
133+ username : this . userFromSession . user_name ,
134+ version : this . userFromSession . version
135+ } ) ;
136+ this . successEmitter . emit ( 'User' ) ;
137+ } ,
138+ ( exception ) => {
139+ console . log ( 'getUserFromSession exception ==>' , exception )
140+ this . errorEmitter . emit ( true ) ;
141+ this . alertService . error ( 'An error occurred while retrieving the GitHub user from the session.' ) ;
142+ this . claContributorService . handleError ( exception ) ;
143+ }
144+ ) ;
145+ }
146146}
0 commit comments